/* docs.chatspaces.dev — Terminal Elegance, documentation edition.
   Shares the tokens, fonts and accent of chatspaces.dev; adds a docs layout. */

:root {
  --bg: #0a0a0a;
  --surface: #111111;
  --surface-2: #1a1a1a;
  --surface-3: #161616;
  --border: #222222;
  --border-2: #2a2a2a;

  --text: #f8f8f8;
  --text-muted: #aaaaaa;
  --text-subtle: #666666;

  --primary: #10f0a0;
  --primary-hover: #00e08a;
  --primary-dim: #0bbd80;
  --primary-glow: 0 0 25px -5px rgb(16 240 160 / 0.7);

  --cyan: #22d3ee;
  --indigo: #6366f1;
  --amber: #fbbf24;
  --error: #f87171;

  --claude: #cc6b43;
  --codex: #6d5df6;

  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;

  --ease: cubic-bezier(0.23, 1, 0.32, 1);
  --r-card: 12px;
  --r-btn: 6px;

  --nav-h: 64px;
  --sidebar-w: 280px;
  --toc-w: 230px;
  --content-max: 800px;
}

* { box-sizing: border-box; }
html { color-scheme: dark; scroll-behavior: smooth; scroll-padding-top: calc(var(--nav-h) + 16px); }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body {
  background:
    radial-gradient(1100px 520px at 88% -10%, rgba(16, 240, 160, 0.06), transparent 60%),
    radial-gradient(820px 460px at -10% 4%, rgba(34, 211, 238, 0.04), transparent 60%),
    var(--bg);
  min-height: 100vh;
}
body.nav-locked { overflow: hidden; }

img, svg, video, canvas, table, pre { max-width: 100%; }

::selection { background: rgba(16, 240, 160, 0.25); color: var(--text); }

a { color: var(--primary); text-decoration: none; transition: color 160ms var(--ease); }
a:hover { color: var(--primary-hover); }
.ext { font-size: 0.8em; color: var(--text-subtle); }

.skip {
  position: absolute; left: -1000px; top: 0; padding: 12px 16px;
  background: var(--primary); color: #000;
  font-family: var(--font-mono); font-weight: 600; z-index: 100;
}
.skip:focus { left: 12px; top: 12px; outline: none; }

/* ── top nav ──────────────────────────────────────────────────── */
.nav {
  position: sticky; top: 0; z-index: 50; height: var(--nav-h);
  background: rgba(17, 17, 17, 0.82);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  height: 100%; padding: 0 1.5rem; display: flex; align-items: center; gap: 1rem;
}
.logo {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-family: var(--font-mono); font-weight: 600; font-size: 1.05rem;
  color: var(--text); letter-spacing: -0.01em;
}
.logo:hover { color: var(--text); }
.logo-mark { width: 22px; height: 22px; flex: 0 0 auto; color: var(--primary); }
.logo-spark { fill: #aff5de; transform-box: fill-box; transform-origin: center; }
.logo-spark-1 { animation: glimmer 5s ease-in-out infinite; }
.logo-spark-2 { animation: glimmer 5s ease-in-out 0.45s infinite; }
@keyframes glimmer {
  0%, 60%, 100% { opacity: 0.5; transform: scale(0.8); }
  74% { opacity: 1; transform: scale(1.15); }
  88% { opacity: 0.7; transform: scale(0.95); }
}
.logo-badge {
  font-family: var(--font-mono); font-size: 0.6rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--primary); border: 1px solid rgba(16, 240, 160, 0.4);
  border-radius: 4px; padding: 2px 5px; margin-left: 2px;
}
.nav-links {
  display: none; gap: 1.5rem; margin-left: 1rem;
  font-family: var(--font-mono); font-size: 0.85rem;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.nav-links a { color: var(--text-muted); }
.nav-links a:hover { color: var(--text); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  height: 40px; padding: 0 1rem; border-radius: var(--r-btn); white-space: nowrap;
  font-family: var(--font-mono); font-weight: 600; font-size: 0.85rem;
  cursor: pointer; border: 1px solid transparent;
  transition: transform 160ms var(--ease), box-shadow 160ms var(--ease), background 160ms var(--ease);
}
.btn-primary { background: var(--primary); color: #000; }
.btn-primary:hover { background: var(--primary-hover); color: #000; transform: translateY(-1px); box-shadow: var(--primary-glow); }
.nav-cta { margin-left: auto; }

.menu-btn, .search-trigger { background: none; border: none; cursor: pointer; color: var(--text-muted); }
.menu-btn { display: inline-flex; padding: 6px; margin-left: -4px; border-radius: 6px; }
.menu-btn svg { width: 22px; height: 22px; }
.menu-btn:hover { color: var(--text); background: var(--surface-2); }

.search-trigger {
  display: inline-flex; align-items: center; gap: 0.55rem; margin-left: auto;
  height: 38px; padding: 0 0.7rem 0 0.6rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-btn); color: var(--text-subtle);
  font-family: var(--font-sans); font-size: 0.85rem;
  transition: border-color 160ms var(--ease), color 160ms var(--ease);
}
.search-trigger:hover { border-color: var(--border-2); color: var(--text-muted); }
.search-trigger svg { width: 15px; height: 15px; }
.search-trigger kbd, .search-field kbd {
  font-family: var(--font-mono); font-size: 0.72rem;
  background: var(--surface-2); border: 1px solid var(--border-2);
  border-radius: 4px; padding: 1px 6px; color: var(--text-subtle);
}

/* ── shell: sidebar | content | toc ───────────────────────────── */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  max-width: 1400px; margin: 0 auto;
}
.sidebar {
  position: sticky; top: var(--nav-h); align-self: start;
  height: calc(100vh - var(--nav-h));
  height: calc(100dvh - var(--nav-h));
  overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  border-right: 1px solid var(--border);
  padding: 1.75rem 1rem 3rem 1.5rem;
}
.sidebar-inner { display: flex; flex-direction: column; gap: 1.6rem; }
.side-group .side-title {
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.09em; color: var(--text-subtle);
  margin-bottom: 0.6rem; padding-left: 0.75rem;
}
.side-group ul { list-style: none; margin: 0; padding: 0; }
.side-group li a {
  display: block; padding: 0.4rem 0.75rem; border-radius: var(--r-btn);
  font-size: 0.9rem; color: var(--text-muted); line-height: 1.45;
  border-left: 2px solid transparent; transition: color 140ms var(--ease), background 140ms var(--ease);
}
.side-group li a:hover { color: var(--text); background: var(--surface); }
.side-group li a.active {
  color: var(--primary); background: rgba(16, 240, 160, 0.07);
  border-left-color: var(--primary); font-weight: 500;
}

.sidebar-scrim {
  position: fixed; inset: 0; z-index: 39;
  background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(2px);
}

/* ── content ──────────────────────────────────────────────────── */
.content {
  display: grid; grid-template-columns: minmax(0, 1fr) var(--toc-w);
  gap: 2.5rem; padding: 2.5rem 2.5rem 4rem; align-items: start;
}
.doc { max-width: var(--content-max); min-width: 0; }

.doc h1 {
  font-family: var(--font-mono); font-weight: 600; font-size: 2.3rem;
  line-height: 1.15; letter-spacing: -0.02em; margin: 0 0 0.4rem;
}
.doc h2 {
  font-family: var(--font-mono); font-weight: 600; font-size: 1.5rem;
  letter-spacing: -0.01em; margin: 2.75rem 0 1rem;
  padding-top: 1.25rem; border-top: 1px solid var(--border);
}
.doc h3 {
  font-family: var(--font-mono); font-weight: 600; font-size: 1.15rem;
  margin: 2rem 0 0.75rem;
}
.doc h4 { font-family: var(--font-mono); font-weight: 600; font-size: 1rem; margin: 1.5rem 0 0.5rem; }
.doc p { margin: 0 0 1.1rem; color: var(--text-muted); }
.doc > p:first-of-type, .doc .lede { font-size: 1.08rem; color: var(--text); }
.doc strong { color: var(--text); font-weight: 600; }
.doc a { border-bottom: 1px solid rgba(16, 240, 160, 0.28); }
.doc a:hover { border-bottom-color: var(--primary); }

.anchor {
  margin-left: -1.1em; padding-right: 0.35em; color: var(--text-subtle);
  opacity: 0; border: none !important; font-weight: 400;
}
.doc h2:hover .anchor, .doc h3:hover .anchor { opacity: 1; }
.anchor:hover { color: var(--primary); }

.doc ul, .doc ol { margin: 0 0 1.2rem; padding-left: 1.4rem; color: var(--text-muted); }
.doc li { margin: 0.35rem 0; }
.doc li::marker { color: var(--text-subtle); }
.doc ul li::marker { color: var(--primary-dim); }

.doc code {
  font-family: var(--font-mono); font-size: 0.86em;
  background: #121212; border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 6px; color: var(--text);
}
.doc pre {
  position: relative; background: #0c0c0c; border: 1px solid var(--border);
  border-radius: var(--r-card); padding: 1rem 1.1rem; margin: 0 0 1.4rem;
  overflow-x: auto; font-size: 0.86rem; line-height: 1.6;
}
.doc pre code { background: none; border: none; padding: 0; color: #d6f7ea; font-size: inherit; }
.copy-btn {
  position: absolute; top: 0.55rem; right: 0.55rem;
  font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-subtle);
  background: var(--surface-2); border: 1px solid var(--border-2);
  border-radius: 5px; padding: 3px 8px; cursor: pointer; opacity: 0;
  transition: opacity 140ms var(--ease), color 140ms var(--ease);
}
.doc pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--primary); border-color: var(--primary-dim); }

.doc blockquote {
  margin: 0 0 1.3rem; padding: 0.2rem 0 0.2rem 1.1rem;
  border-left: 3px solid var(--border-2); color: var(--text-muted);
}

/* tables */
.doc table {
  width: 100%; border-collapse: collapse; margin: 0 0 1.5rem;
  font-size: 0.9rem; display: block; overflow-x: auto;
}
.doc thead { background: var(--surface); }
.doc th, .doc td { border: 1px solid var(--border); padding: 0.6rem 0.85rem; text-align: left; vertical-align: top; }
.doc th { font-family: var(--font-mono); font-weight: 600; font-size: 0.82rem; color: var(--text); white-space: nowrap; }
.doc td { color: var(--text-muted); }
.doc tbody tr:nth-child(even) { background: rgba(255, 255, 255, 0.012); }

.doc hr { border: none; border-top: 1px solid var(--border); margin: 2.5rem 0; }

/* callouts */
.callout {
  margin: 0 0 1.4rem; padding: 0.9rem 1.1rem; border-radius: var(--r-card);
  border: 1px solid var(--border-2); background: var(--surface-3);
  border-left-width: 3px;
}
.callout p { margin: 0 0 0.5rem; color: var(--text-muted); }
.callout p:last-child { margin: 0; }
.callout-label {
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 0.35rem;
}
.callout-note { border-left-color: var(--cyan); }
.callout-note .callout-label { color: var(--cyan); }
.callout-tip { border-left-color: var(--primary); }
.callout-tip .callout-label { color: var(--primary); }
.callout-warning { border-left-color: var(--amber); }
.callout-warning .callout-label { color: var(--amber); }
.callout-important { border-left-color: var(--indigo); }
.callout-important .callout-label { color: #a5a0ff; }

/* lede card under the H1 (use blockquote-free) */

/* prev / next */
.prevnext { display: flex; gap: 1rem; margin: 3rem 0 0; }
.pn {
  flex: 1; display: flex; flex-direction: column; gap: 0.25rem;
  padding: 0.9rem 1.1rem; border: 1px solid var(--border); border-radius: var(--r-card);
  background: var(--surface); transition: border-color 160ms var(--ease), transform 160ms var(--ease);
  border-bottom: 1px solid var(--border);
}
.pn:hover { border-color: var(--primary-dim); transform: translateY(-1px); }
.pn-next { text-align: right; }
.pn-dir { font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-subtle); text-transform: uppercase; letter-spacing: 0.05em; }
.pn-label { color: var(--text); font-weight: 500; font-size: 0.95rem; }

.doc-foot { margin-top: 2.5rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }
.doc-foot p { font-size: 0.85rem; color: var(--text-subtle); margin: 0; }

/* ── on this page (toc) ───────────────────────────────────────── */
.toc {
  position: sticky; top: calc(var(--nav-h) + 2.5rem); align-self: start;
  max-height: calc(100vh - var(--nav-h) - 4rem); overflow-y: auto; min-width: 0;
}
.toc-title {
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-subtle);
  margin-bottom: 0.7rem;
}
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }
.toc li a {
  display: block; padding: 0.28rem 0 0.28rem 0.85rem; margin-left: -1px;
  border-left: 2px solid transparent; font-size: 0.82rem; color: var(--text-subtle);
  line-height: 1.4; transition: color 140ms var(--ease);
}
.toc li.toc-l3 a { padding-left: 1.6rem; font-size: 0.78rem; }
.toc li a:hover { color: var(--text-muted); }
.toc li a.active { color: var(--primary); border-left-color: var(--primary); }

/* ── search modal ─────────────────────────────────────────────── */
.search-modal {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 12vh 1rem 1rem;
}
.search-modal[hidden] { display: none; }
.sidebar-scrim[hidden] { display: none; }
.search-box {
  width: 100%; max-width: 580px; background: var(--surface);
  border: 1px solid var(--border-2); border-radius: var(--r-card);
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.8); overflow: hidden;
}
.search-field { display: flex; align-items: center; gap: 0.7rem; padding: 0.85rem 1rem; border-bottom: 1px solid var(--border); }
.search-field svg { width: 18px; height: 18px; color: var(--text-subtle); flex: 0 0 auto; }
.search-field input {
  flex: 1; background: none; border: none; outline: none; color: var(--text);
  font-family: var(--font-sans); font-size: 1rem;
}
.search-results { list-style: none; margin: 0; padding: 0.4rem; max-height: 56vh; overflow-y: auto; }
.search-results li { margin: 0; }
.search-hint { padding: 1rem; color: var(--text-subtle); font-size: 0.88rem; }
.search-results > li > a {
  display: block; padding: 0.6rem 0.7rem; border-radius: var(--r-btn); border: none;
}
.search-results > li > a.active, .search-results > li > a:hover { background: var(--surface-2); }
.sr-section { display: block; font-family: var(--font-mono); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-subtle); }
.sr-title { display: block; color: var(--text); font-weight: 500; font-size: 0.95rem; }
.sr-snip { display: block; color: var(--text-subtle); font-size: 0.82rem; line-height: 1.4; margin-top: 1px; }

/* ── pills / helpers usable from markdown ─────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-family: var(--font-mono); font-size: 0.78rem; font-weight: 500;
  padding: 2px 9px; border-radius: 999px; border: 1px solid var(--border-2);
}
.pill-claude { color: var(--claude); border-color: rgba(204, 107, 67, 0.4); }
.pill-codex { color: #9a8fff; border-color: rgba(109, 93, 246, 0.45); }

/* cards grid (home page) */
.grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem; margin: 1.5rem 0 2rem;
}
.grid .tile {
  display: block; padding: 1.1rem 1.2rem; border: 1px solid var(--border);
  border-radius: var(--r-card); background: var(--surface);
  transition: border-color 160ms var(--ease), transform 160ms var(--ease);
}
.grid .tile:hover { border-color: var(--primary-dim); transform: translateY(-2px); }
.grid .tile h3 { margin: 0 0 0.3rem; font-size: 1rem; color: var(--text); }
.grid .tile p { margin: 0; font-size: 0.86rem; color: var(--text-muted); }

/* ── responsive ───────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .content { grid-template-columns: minmax(0, 1fr); }
  .toc { display: none; }
}
@media (min-width: 880px) {
  .nav-links { display: inline-flex; }
}
/* Below 880px: collapse search to an icon-only button so it's still reachable. */
@media (max-width: 879px) {
  .search-trigger { padding: 0; width: 38px; justify-content: center; gap: 0; margin-left: auto; }
  .search-trigger .st-text, .search-trigger kbd { display: none; }
}
@media (max-width: 980px) {
  :root { --sidebar-w: 0px; }
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: var(--nav-h); left: 0; z-index: 40;
    width: 290px; max-width: 85vw;
    height: calc(100vh - var(--nav-h));
    height: calc(100dvh - var(--nav-h));
    background: var(--surface); border-right: 1px solid var(--border-2);
    transform: translateX(-105%); transition: transform 220ms var(--ease);
    padding: 1.5rem 1.25rem calc(4rem + env(safe-area-inset-bottom));
  }
  .sidebar.open { transform: translateX(0); box-shadow: 20px 0 60px -20px rgba(0,0,0,0.8); }
  .content { padding: 1.75rem 1.25rem 3.5rem; }
}
@media (min-width: 981px) {
  .menu-btn { display: none; }
  .sidebar-scrim { display: none !important; }
}
@media (max-width: 620px) {
  .nav-inner { padding: 0 0.85rem; gap: 0.5rem; }
  .nav-cta { height: 34px; padding: 0 0.75rem; font-size: 0.74rem; }
  .logo { font-size: 0.98rem; }
}
@media (max-width: 560px) {
  .nav-links { display: none; }
  .doc h1 { font-size: 1.8rem; }
  .prevnext { flex-direction: column; }
}
@media (max-width: 400px) {
  .logo-badge { display: none; }
  .logo-name { font-size: 0.92rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; scroll-behavior: auto; }
}

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 3px; }
