/* ============================================================================
   KAIRO — Legal · design system
   Concept: the reference manual of an "AI Fitness OS". Editorial, precise,
   instrument-like. Space Grotesk (display) + Space Mono (index/labels/numbers)
   + Inter (body). Violet = structure/brand · Amber = health/caution.
   Theme-aware: dark "void" default, light "paper" for long-form reading.
   ========================================================================== */

/* ── Tokens ──────────────────────────────────────────────────────────────*/
:root {
  --void:     #06060a;
  --ink-950:  #0a0a10;
  --ink-900:  #0e0e16;
  --ink-850:  #12121c;
  --ink-800:  #171722;
  --line:     rgba(150,140,215,0.11);
  --line-2:   rgba(150,140,215,0.20);
  --violet:   #8677ff;
  --violet-b: #a99cff;
  --violet-d: rgba(134,119,255,0.14);
  --violet-g: rgba(134,119,255,0.30);
  --amber:    #f0b24b;
  --amber-d:  rgba(240,178,75,0.13);
  --heading:  #ffffff;
  --text:     #e7e6f1;
  --dim:      #a4a2bb;
  --faint:    #706e88;
  --grid:     rgba(150,140,215,0.05);

  --f-display: "Space Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono:    "Space Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --f-body:    "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --measure: 68ch;
  --shell:   1140px;
}

:root[data-theme="light"] {
  --void:     #f2f1f6;
  --ink-950:  #f6f5f9;
  --ink-900:  #ffffff;
  --ink-850:  #ffffff;
  --ink-800:  #eeecf4;
  --line:     rgba(40,32,80,0.12);
  --line-2:   rgba(40,32,80,0.20);
  --violet:   #6a54ef;
  --violet-b: #5a44df;
  --violet-d: rgba(106,84,239,0.10);
  --violet-g: rgba(106,84,239,0.28);
  --amber:    #b6771a;
  --amber-d:  rgba(182,119,26,0.10);
  --heading:  #100e1a;
  --text:     #2c2a3a;
  --dim:      #56536b;
  --faint:    #8b8aa0;
  --grid:     rgba(40,32,80,0.045);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--f-body);
  font-size: 17px;
  line-height: 1.75;
  color: var(--text);
  background: var(--void);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

a { color: var(--violet-b); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--violet); outline-offset: 3px; border-radius: 4px; }
::selection { background: var(--violet-g); color: #fff; }

.mono { font-family: var(--f-mono); }

/* ── Reading progress bar ───────────────────────────────────────────────*/
.progress {
  position: fixed; inset: 0 0 auto 0; height: 2px; z-index: 60;
  transform: scaleX(0); transform-origin: 0 50%;
  background: linear-gradient(90deg, var(--violet), var(--violet-b));
  transition: transform .1s linear;
}

/* ── Header ─────────────────────────────────────────────────────────────*/
.site-header {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 14px;
  padding: 13px clamp(16px, 5vw, 40px);
  background: color-mix(in srgb, var(--void) 80%, transparent);
  backdrop-filter: saturate(150%) blur(16px);
  -webkit-backdrop-filter: saturate(150%) blur(16px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--heading); }
.brand:hover { text-decoration: none; }
.brand svg { width: 25px; height: 25px; display: block; }
.brand img.glyph { width: 25px; height: 25px; display: block; object-fit: contain; border-radius: 6px; }
.brand b { font-family: var(--f-display); font-weight: 600; font-size: 18px; letter-spacing: -0.01em; }
.brand .slash { font-family: var(--f-mono); font-size: 12px; color: var(--faint); letter-spacing: 0.04em; }
.header-spacer { flex: 1 1 auto; }
.header-tools { display: flex; align-items: center; gap: 6px; }

.lang-switch { display: inline-flex; gap: 1px; }
.lang-switch button {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  font-family: var(--f-mono); font-size: 12px; font-weight: 400;
  color: var(--faint); padding: 6px 7px; border-radius: 6px; line-height: 1;
  transition: color .14s, background .14s;
}
.lang-switch button:hover { color: var(--text); background: var(--violet-d); }
.lang-switch button[aria-pressed="true"] { color: var(--violet-b); font-weight: 700; }
.theme-toggle {
  appearance: none; cursor: pointer; width: 34px; height: 32px; margin-left: 4px; padding: 0;
  display: inline-grid; place-items: center; color: var(--text);
  background: transparent; border: 1px solid var(--line); border-radius: 8px;
  transition: background .14s, border-color .14s;
}
.theme-toggle:hover { background: var(--violet-d); border-color: var(--line-2); }
.theme-toggle svg { width: 17px; height: 17px; }
.theme-toggle .sun { display: none; }
:root[data-theme="light"] .theme-toggle .sun { display: block; }
:root[data-theme="light"] .theme-toggle .moon { display: none; }

/* ── Shared eyebrow / masthead type ─────────────────────────────────────*/
.eyebrow {
  font-family: var(--f-mono); font-size: 12px; font-weight: 400;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--violet-b);
}

/* ── Masthead grid backdrop (index + doc head) ──────────────────────────*/
.masthead {
  position: relative;
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(120% 140% at 85% -30%, var(--violet-d), transparent 55%),
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 100% 34px,
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 34px 100%;
}
.masthead-inner { max-width: var(--shell); margin: 0 auto; padding: clamp(46px,9vw,92px) clamp(20px,5vw,40px) clamp(30px,5vw,48px); }

/* ── INDEX ──────────────────────────────────────────────────────────────*/
.idx-lead { max-width: 640px; }
.idx-lead .eyebrow { display: block; margin-bottom: 18px; }
.idx-lead h1 {
  font-family: var(--f-display); font-weight: 700;
  font-size: clamp(38px, 8vw, 76px); line-height: 0.98; letter-spacing: -0.035em;
  color: var(--heading); margin: 0;
}
.idx-lead h1 .fu { display: block; color: transparent; -webkit-background-clip: text; background-clip: text;
  background-image: linear-gradient(96deg, var(--violet) 8%, var(--violet-b)); }
.idx-lead .lede { color: var(--dim); font-size: clamp(16px,2.4vw,19px); margin: 20px 0 0; max-width: 30em; }

.idx-list { max-width: var(--shell); margin: 0 auto; padding: clamp(8px,3vw,26px) clamp(20px,5vw,40px) clamp(48px,8vw,90px); }
.idx-row {
  position: relative; display: grid; grid-template-columns: 54px 1fr auto; align-items: center;
  gap: 4px 22px; padding: 26px 12px 26px 10px; border-top: 1px solid var(--line);
  text-decoration: none; color: inherit; transition: background .18s;
}
.idx-list .idx-row:last-child { border-bottom: 1px solid var(--line); }
.idx-row::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 2px;
  background: var(--violet); transform: scaleY(0); transform-origin: 50% 0; transition: transform .22s ease;
}
.idx-row:hover { background: linear-gradient(90deg, var(--violet-d), transparent 80%); text-decoration: none; }
.idx-row:hover::before { transform: scaleY(1); }
.idx-num { grid-row: 1 / span 2; font-family: var(--f-mono); font-size: 13px; color: var(--faint); padding-top: 3px; }
.idx-row:hover .idx-num { color: var(--violet-b); }
.idx-title { font-family: var(--f-display); font-weight: 600; font-size: clamp(20px,3vw,26px); letter-spacing: -0.015em; color: var(--heading); }
.idx-desc { grid-column: 2; color: var(--dim); font-size: 15px; line-height: 1.5; max-width: 52ch; }
.idx-meta { grid-column: 3; grid-row: 1 / span 2; display: flex; align-items: center; gap: 18px; justify-self: end; }
.idx-meta .m { font-family: var(--f-mono); font-size: 11.5px; color: var(--faint); text-align: right; white-space: nowrap; line-height: 1.5; }
.idx-arrow { color: var(--faint); transition: transform .2s, color .2s; }
.idx-row:hover .idx-arrow { color: var(--violet-b); transform: translateX(4px); }

.idx-foot { max-width: var(--shell); margin: 0 auto; padding: 0 clamp(20px,5vw,40px) 70px; }
.idx-foot .card {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px;
  padding: 22px 24px; border: 1px solid var(--line); border-radius: 14px; background: var(--ink-900);
  font-size: 15px; color: var(--dim);
}
.idx-foot .card b { color: var(--heading); font-weight: 600; font-family: var(--f-display); }

/* ── DOC layout ─────────────────────────────────────────────────────────*/
.doc-head-inner { max-width: var(--shell); margin: 0 auto; padding: clamp(40px,7vw,74px) clamp(20px,5vw,40px) clamp(26px,4vw,40px); }
.doc-head .eyebrow { display: block; margin-bottom: 16px; }
.doc-head h1 {
  font-family: var(--f-display); font-weight: 700; font-size: clamp(32px,6.5vw,58px);
  line-height: 1.02; letter-spacing: -0.03em; color: var(--heading); margin: 0; max-width: 15ch;
}
.doc-meta { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-top: 20px; }
.doc-meta span { font-family: var(--f-mono); font-size: 12.5px; color: var(--faint); display: inline-flex; align-items: center; gap: 8px; }
.doc-meta span::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--violet); opacity: .8; }

.doc-shell { max-width: var(--shell); margin: 0 auto; padding: 4px clamp(20px,5vw,40px) 20px; }
.doc-layout { display: grid; grid-template-columns: 1fr; gap: 0; }

/* ── Section rail ───────────────────────────────────────────────────────*/
.rail { min-width: 0; }
.rail-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-family: var(--f-mono); font-size: 11.5px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--faint); padding: 14px 0;
}
.rail-toggle {
  appearance: none; background: transparent; border: 1px solid var(--line); border-radius: 7px;
  color: var(--text); cursor: pointer; width: 30px; height: 28px; display: inline-grid; place-items: center;
}
.rail-toggle svg { width: 16px; height: 16px; transition: transform .2s; }
.rail.open .rail-toggle svg { transform: rotate(180deg); }
.rail-list { list-style: none; margin: 0 0 26px; padding: 0; border-left: 1px solid var(--line); }
.rail-list a {
  display: grid; grid-template-columns: 26px 1fr; gap: 8px; align-items: baseline;
  padding: 7px 10px; margin-left: -1px; border-left: 2px solid transparent;
  color: var(--dim); font-size: 13.5px; line-height: 1.4; transition: color .15s, border-color .15s, background .15s;
}
.rail-list a:hover { color: var(--text); text-decoration: none; background: var(--violet-d); }
.rail-list a.active { color: var(--violet-b); border-left-color: var(--violet); font-weight: 500; }
.rail-list a .rn { font-family: var(--f-mono); font-size: 11px; color: var(--faint); }
.rail-list a.active .rn { color: var(--violet-b); }

/* ── Prose ──────────────────────────────────────────────────────────────*/
.doc-col { min-width: 0; }
.prose { max-width: var(--measure); }
.prose article { counter-reset: sec; }
html.js .prose article[data-lang] { display: none; }

.prose h2 {
  font-family: var(--f-display); font-weight: 600;
  font-size: clamp(21px,3.2vw,27px); letter-spacing: -0.015em; color: var(--heading);
  margin: 2.6em 0 0.7em; scroll-margin-top: 92px; position: relative;
}
.prose h2:first-child { margin-top: 0.5em; }
.prose h2::before {
  counter-increment: sec; content: counter(sec, decimal-leading-zero);
  display: block; font-family: var(--f-mono); font-size: 12px; font-weight: 700;
  letter-spacing: 0.08em; color: var(--violet); margin-bottom: 10px;
}
.prose h2 .anchor {
  position: absolute; left: -1.1em; top: auto; bottom: .12em; opacity: 0;
  color: var(--faint); font-family: var(--f-mono); font-weight: 400; font-size: .7em;
  text-decoration: none; transition: opacity .15s;
}
.prose h2:hover .anchor { opacity: 1; }
.prose h3 { font-family: var(--f-display); font-weight: 600; font-size: 18px; color: var(--heading); margin: 1.9em 0 0.5em; letter-spacing: -0.01em; }
.prose h4 { font-weight: 700; font-size: 15px; color: var(--text); margin: 1.5em 0 0.4em; }
.prose p { margin: 0 0 1.1em; }
.prose ul, .prose ol { margin: 0 0 1.2em; padding-left: 1.5em; }
.prose li { margin: 0.45em 0; padding-left: 0.2em; }
.prose ul li::marker { color: var(--violet); content: "—  "; }
.prose ol li::marker { color: var(--violet); font-family: var(--f-mono); font-size: .85em; }
.prose strong { color: var(--heading); font-weight: 600; }
.prose a { color: var(--violet-b); border-bottom: 1px solid var(--violet-g); }
.prose a:hover { text-decoration: none; border-bottom-color: var(--violet-b); }

.prose blockquote {
  margin: 1.5em 0; padding: 16px 20px; border-radius: 0 14px 14px 0;
  border-left: 3px solid var(--amber); background: var(--amber-d); color: var(--text);
}
.prose blockquote p:last-child { margin-bottom: 0; }

.prose table { width: 100%; border-collapse: collapse; margin: 1.3em 0 1.6em; font-size: 14.5px; display: block; overflow-x: auto; }
.prose th, .prose td { text-align: left; padding: 11px 15px; border-bottom: 1px solid var(--line); vertical-align: top; }
.prose thead th { font-family: var(--f-mono); font-size: 11.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--heading); border-bottom-color: var(--line-2); }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2.4em 0; }

/* ── Prev/Next pager ────────────────────────────────────────────────────*/
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 46px 0 8px; max-width: var(--measure); }
.pager a {
  display: flex; flex-direction: column; gap: 5px; padding: 18px 20px; text-decoration: none;
  border: 1px solid var(--line); border-radius: 13px; background: var(--ink-900); color: var(--text);
  transition: border-color .18s, background .18s, transform .18s;
}
.pager a:hover { border-color: var(--violet-g); background: var(--ink-850); text-decoration: none; transform: translateY(-2px); }
.pager a.next { text-align: right; align-items: flex-end; }
.pager .k { font-family: var(--f-mono); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint); }
.pager .t { font-family: var(--f-display); font-weight: 600; font-size: 16px; color: var(--heading); letter-spacing: -0.01em; }
.pager a:only-child { grid-column: 1 / -1; }
.pager .ph { visibility: hidden; }

/* ── Footer ─────────────────────────────────────────────────────────────*/
.site-footer { border-top: 1px solid var(--line); background: var(--ink-950); margin-top: 40px; }
.footer-inner { max-width: var(--shell); margin: 0 auto; padding: 46px clamp(20px,5vw,40px) 54px;
  display: grid; grid-template-columns: 1.2fr 1fr; gap: 34px 40px; }
.footer-brand .brand { margin-bottom: 12px; }
.footer-brand p { color: var(--faint); font-size: 13.5px; max-width: 34ch; margin: 0; }
.footer-col h4 { font-family: var(--f-mono); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--faint); margin: 0 0 14px; font-weight: 400; }
.footer-docs { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }
.footer-docs a { color: var(--dim); font-size: 14.5px; display: inline-flex; gap: 9px; align-items: baseline; }
.footer-docs a:hover { color: var(--text); text-decoration: none; }
.footer-docs a[aria-current="page"] { color: var(--violet-b); }
.footer-docs .n { font-family: var(--f-mono); font-size: 11px; color: var(--faint); }
.footer-bar { border-top: 1px solid var(--line); }
.footer-bar-inner { max-width: var(--shell); margin: 0 auto; padding: 18px clamp(20px,5vw,40px);
  display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: baseline; justify-content: space-between;
  font-family: var(--f-mono); font-size: 12px; color: var(--faint); }
.footer-bar-inner a { color: var(--dim); }

/* ── Back to top ────────────────────────────────────────────────────────*/
.to-top {
  position: fixed; right: 20px; bottom: 20px; z-index: 40; width: 44px; height: 44px; border-radius: 50%;
  cursor: pointer; display: grid; place-items: center; border: 1px solid var(--line-2);
  background: var(--ink-850); color: var(--text); box-shadow: 0 18px 40px -22px rgba(0,0,0,.8);
  opacity: 0; transform: translateY(10px); pointer-events: none; transition: opacity .2s, transform .2s, background .15s;
}
.to-top.show { opacity: 1; transform: none; pointer-events: auto; }
.to-top:hover { background: var(--violet); color: #fff; border-color: transparent; }
.to-top svg { width: 19px; height: 19px; }

/* ── Desktop split ──────────────────────────────────────────────────────*/
@media (min-width: 1000px) {
  .doc-layout { grid-template-columns: 236px minmax(0, 1fr); gap: 60px; align-items: start; }
  .rail { position: sticky; top: 84px; align-self: start; max-height: calc(100vh - 100px); overflow-y: auto; }
  .rail-toggle { display: none; }
  .rail-list { display: block !important; }
}

/* ── Mobile rail collapse ───────────────────────────────────────────────*/
@media (max-width: 999px) {
  .rail { border: 1px solid var(--line); border-radius: 13px; background: var(--ink-900); padding: 4px 14px; margin: 8px 0 26px; }
  .rail-head { padding: 12px 0; }
  .rail-list { border-left: 0; margin-bottom: 14px; display: none; }
  .rail.open .rail-list { display: block; }
}

@media (max-width: 720px) {
  body { font-size: 16px; }
  .brand .slash { display: none; }
  .idx-row { grid-template-columns: 40px 1fr; }
  .idx-meta { grid-column: 2; grid-row: auto; justify-self: start; margin-top: 6px; }
  .idx-arrow { display: none; }
  .footer-inner { grid-template-columns: 1fr; }
}

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

/* ── Waitlist (early access) ─────────────────────────────────────────────*/
.waitlist { max-width: var(--shell); margin: 0 auto; padding: clamp(28px,5vw,52px) clamp(20px,5vw,40px) clamp(8px,2vw,20px); }
.wl-inner {
  position: relative; overflow: hidden;
  border: 1px solid var(--line-2); border-radius: 18px; background: var(--ink-900);
  padding: clamp(24px,4vw,40px);
  background-image: radial-gradient(120% 140% at 90% -20%, var(--violet-d), transparent 55%);
}
.wl-inner .eyebrow { display: block; margin-bottom: 14px; }
.wl-title { font-family: var(--f-display); font-weight: 700; font-size: clamp(24px,4vw,36px); line-height: 1.1; margin: 0 0 10px; color: var(--heading); letter-spacing: -0.01em; }
.wl-lede { max-width: 52ch; margin: 0 0 22px; color: var(--dim); }
.wl-form { display: flex; flex-direction: column; gap: 12px; max-width: 520px; }
.wl-row { display: flex; gap: 12px; }
.wl-input {
  flex: 1 1 auto; min-width: 0; font-family: var(--f-body); font-size: 16px; color: var(--text);
  background: var(--ink-850); border: 1px solid var(--line-2); border-radius: 12px; padding: 14px 16px;
}
.wl-input::placeholder { color: var(--faint); }
.wl-input:focus-visible { outline: 2px solid var(--violet); outline-offset: 1px; border-color: transparent; }
.wl-btn {
  flex: 0 0 auto; font-family: var(--f-display); font-weight: 700; font-size: 16px; cursor: pointer;
  color: #fff; border: 0; border-radius: 12px; padding: 14px 24px; white-space: nowrap;
  background: linear-gradient(90deg, var(--violet), var(--violet-b));
}
.wl-btn:hover { filter: brightness(1.06); }
.wl-btn:disabled { opacity: 0.6; cursor: default; }
.wl-hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.wl-status { min-height: 1.2em; margin-top: 12px; font-size: 14px; font-weight: 600; }
.wl-status.ok { color: #22a67a; }
.wl-status.err { color: var(--amber); }
.wl-fine { margin: 14px 0 0; font-size: 12.5px; color: var(--faint); max-width: 52ch; }
@media (max-width: 560px) { .wl-row { flex-direction: column; } .wl-btn { width: 100%; } }
