:root {
  color-scheme: dark;
  --bg: #09090b;
  --panel: #101012;
  --panel-raised: #151518;
  --line: #2a2a2f;
  --line-soft: #1e1e22;
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --faint: #71717a;
  --accent: #5ee3b3;
  --accent-soft: rgba(94, 227, 179, .11);
  --amber: #f6c76f;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 6rem; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); }
a { color: inherit; text-underline-offset: .2em; }
button { font: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  min-height: 3.75rem;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line-soft);
  padding: .75rem clamp(1rem, 3vw, 2.5rem);
  background: rgba(9, 9, 11, .88);
  backdrop-filter: blur(18px);
}

.brand { display: inline-flex; align-items: center; gap: .65rem; color: var(--text); font-size: .85rem; font-weight: 700; text-decoration: none; }
.brand-mark { display: grid; width: 1.75rem; height: 1.75rem; place-items: center; border: 1px solid rgba(94, 227, 179, .28); border-radius: .55rem; color: var(--accent); background: var(--accent-soft); font-size: 1rem; }
.top-actions { display: flex; align-items: center; gap: .8rem; color: var(--muted); font-size: .72rem; }
.top-actions a { text-decoration: none; }
.top-actions a:hover { color: var(--text); }
.top-actions button { border: 1px solid var(--line); border-radius: .5rem; padding: .35rem .65rem; color: var(--muted); background: transparent; cursor: pointer; }
.top-actions button:hover { border-color: var(--faint); color: var(--text); }
.draft-badge { border: 1px solid rgba(246, 199, 111, .28); border-radius: 999px; padding: .28rem .55rem; color: var(--amber); background: rgba(246, 199, 111, .07); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; text-transform: uppercase; letter-spacing: .06em; }

.page-shell { display: grid; grid-template-columns: 17rem minmax(0, 1fr); width: min(92rem, 100%); margin: 0 auto; }
.toc-shell { position: sticky; top: 3.75rem; align-self: start; height: calc(100vh - 3.75rem); overflow-y: auto; border-right: 1px solid var(--line-soft); padding: 2rem 1.25rem 3rem; }
.toc-heading { display: grid; gap: .3rem; margin: 0 .6rem 1.4rem; }
.toc-heading strong { font-size: .92rem; }
.eyebrow { color: var(--accent); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .64rem; text-transform: uppercase; letter-spacing: .12em; }
#table-of-contents { display: grid; gap: .12rem; }
#table-of-contents a { border-left: 1px solid var(--line); padding: .42rem .6rem; color: var(--faint); font-size: .74rem; line-height: 1.35; text-decoration: none; transition: color .15s ease, border-color .15s ease, background .15s ease; }
#table-of-contents a:hover { color: var(--text); }
#table-of-contents a.active { border-left-color: var(--accent); color: var(--accent); background: linear-gradient(90deg, var(--accent-soft), transparent); }
#table-of-contents .toc-subsection { padding-left: 1.15rem; font-size: .68rem; }

main { min-width: 0; padding: clamp(1.5rem, 5vw, 4.5rem) clamp(1.25rem, 6vw, 6.5rem) 8rem; }
.mental-model { width: min(66rem, 100%); margin: 0 auto 4.5rem; }
.model-heading h1 { max-width: 44rem; margin: .55rem 0 1.7rem; font-size: clamp(1.7rem, 4vw, 3rem); line-height: 1.08; letter-spacing: -.035em; }
.model-flow { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr auto 1fr; align-items: stretch; gap: .55rem; }
.model-flow article { position: relative; min-height: 10rem; overflow: hidden; border: 1px solid var(--line); border-radius: .9rem; padding: 1.2rem; background: linear-gradient(145deg, var(--panel-raised), var(--panel)); }
.model-flow article::after { position: absolute; right: -2.2rem; bottom: -3.2rem; width: 8rem; height: 8rem; border-radius: 50%; background: var(--accent-soft); content: ""; filter: blur(1px); }
.model-flow strong { display: block; margin-top: 1.5rem; font-size: .95rem; }
.model-flow p { position: relative; z-index: 1; margin: .55rem 0 0; color: var(--muted); font-size: .76rem; line-height: 1.55; }
.model-index { color: var(--accent); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .62rem; }
.model-arrow { align-self: center; color: var(--faint); font-size: 1.1rem; }

.spec-content { width: min(53rem, 100%); margin: 0 auto; }
.spec-content > h1 { margin: 0 0 1rem; font-size: clamp(2.2rem, 5vw, 4rem); line-height: 1.02; letter-spacing: -.045em; }
.spec-content > h1 + p { display: inline-flex; margin: 0 0 3.5rem; border: 1px solid var(--line); border-radius: .65rem; padding: .75rem 1rem; color: var(--muted); background: var(--panel); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .72rem; }
.spec-content h2 { margin: 4.8rem 0 1.2rem; border-top: 1px solid var(--line); padding-top: 1.5rem; font-size: clamp(1.35rem, 2.5vw, 1.8rem); letter-spacing: -.025em; }
.spec-content h3 { margin: 2.8rem 0 1rem; color: #d4d4d8; font-size: 1rem; }
.spec-content p { margin: 0 0 1.15rem; color: #c6c6cc; font-size: .95rem; line-height: 1.78; }
.spec-content ul, .spec-content ol { display: grid; gap: .7rem; margin: 1.2rem 0 1.8rem; padding-left: 1.35rem; color: #c6c6cc; }
.spec-content li { padding-left: .3rem; font-size: .92rem; line-height: 1.65; }
.spec-content li::marker { color: var(--accent); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.spec-content code { border: 1px solid rgba(94, 227, 179, .14); border-radius: .3rem; padding: .08rem .3rem; color: #a7f3d0; background: rgba(94, 227, 179, .07); font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: .84em; }
.spec-content pre { overflow-x: auto; margin: 1.5rem 0 2rem; border: 1px solid var(--line); border-radius: .8rem; padding: 1.2rem 1.35rem; background: #0c0c0f; box-shadow: inset 3px 0 var(--accent); }
.spec-content pre code { border: 0; padding: 0; color: #d4d4d8; background: transparent; font-size: .78rem; line-height: 1.72; }
.decision-heading { color: var(--amber); }
.decision-heading + ol { border: 1px solid rgba(246, 199, 111, .24); border-radius: .85rem; padding: 1.2rem 1.2rem 1.2rem 2.6rem; background: rgba(246, 199, 111, .045); }
.loading, .error { border: 1px solid var(--line); border-radius: .8rem; padding: 1.2rem; background: var(--panel); }
.error { color: #fda4af !important; }

@media (max-width: 900px) {
  .page-shell { display: block; }
  .toc-shell { position: relative; top: 0; width: 100%; height: auto; border-right: 0; border-bottom: 1px solid var(--line-soft); padding: 1rem; }
  .toc-heading { margin: 0 0 .7rem; }
  #table-of-contents { display: flex; overflow-x: auto; padding-bottom: .25rem; }
  #table-of-contents a { min-width: max-content; border-left: 0; border-bottom: 1px solid var(--line); }
  #table-of-contents a.active { border-bottom-color: var(--accent); }
  #table-of-contents .toc-subsection { display: none; }
  .model-flow { grid-template-columns: 1fr; }
  .model-arrow { justify-self: center; transform: rotate(90deg); }
}

@media (max-width: 620px) {
  .topbar { align-items: flex-start; }
  .top-actions { justify-content: flex-end; flex-wrap: wrap; }
  .draft-badge { display: none; }
  main { padding-top: 2.5rem; }
  .mental-model { margin-bottom: 3rem; }
}

@media print {
  :root { color-scheme: light; --bg: #fff; --text: #111; --muted: #444; --faint: #666; --line: #ccc; --line-soft: #ddd; --panel: #f7f7f7; --panel-raised: #fafafa; --accent: #087f5b; --accent-soft: #e8f8f2; }
  .topbar, .toc-shell { display: none; }
  .page-shell { display: block; }
  main { padding: 0; }
  .mental-model { break-after: page; }
  .spec-content h2, .spec-content h3 { break-after: avoid; }
  .spec-content pre, .model-flow article { break-inside: avoid; }
  .spec-content p, .spec-content li { color: #222; }
}
