/* ============================================================================
   OpenGov Mesh — spec reader · "Sovereign Night", tuned for long-form reading
   ========================================================================== */
:root {
  --bg:        #0A0E1A;
  --bg-2:      #0d1324;
  --bg-3:      #11182c;
  --fg:        #E6EAF4;
  --fg-read:   #D4DAE8;                      /* body prose — a touch softer than pure fg */
  --fg-muted:  rgba(230, 234, 244, 0.62);
  --fg-faint:  rgba(230, 234, 244, 0.50);
  --fg-decor:  rgba(230, 234, 244, 0.28);

  --ember:  #E8915B;
  --teal:   #3DD8C4;
  --indigo: #6E8CFF;
  --gold:   #F2C879;

  --hair:        rgba(230, 234, 244, 0.10);
  --hair-strong: rgba(230, 234, 244, 0.18);

  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-body:    "Inter", system-ui, -apple-system, sans-serif;
  --font-mono:    "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;

  --ease: cubic-bezier(0.16, 1, 0.30, 1);
  --topbar-h: 60px;
  --sidebar-w: 300px;
  --measure: 74ch;
  --progress: 0;
}

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--fg-read);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "ss01";
  /* a calm, static atmosphere — no animated canvas on a reading page */
  background-image:
    radial-gradient(900px 500px at 78% -8%, rgba(110, 140, 255, 0.10), transparent 60%),
    radial-gradient(700px 480px at -6% 8%, rgba(232, 145, 91, 0.06), transparent 55%);
  background-attachment: fixed;
}
::selection { background: rgba(232, 145, 91, 0.28); color: #fff; }
a { color: inherit; }

:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; border-radius: 5px; }
.btn:focus-visible, .toc-toggle:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
:focus:not(:focus-visible) { outline: none; }

.skip {
  position: fixed; top: -100px; left: 1rem; z-index: 100;
  padding: 0.6rem 1rem; background: var(--ember); color: #14110c;
  font: 500 0.85rem/1 var(--font-mono); border-radius: 6px; transition: top 0.2s ease;
}
.skip:focus { top: 1rem; }

/* ---- progress rail ----------------------------------------------------- */
.scroll-rail {
  position: fixed; top: 0; left: 0; z-index: 60;
  width: 100%; height: 2px; background: var(--hair); pointer-events: none;
}
.scroll-rail__fill {
  display: block; height: 100%; width: 100%;
  transform: scaleX(var(--progress)); transform-origin: 0 50%;
  background: linear-gradient(90deg, var(--ember), var(--gold));
  box-shadow: 0 0 12px rgba(232, 145, 91, 0.6);
}

/* ---- topbar ------------------------------------------------------------ */
.topbar {
  position: fixed; top: 0; left: 0; z-index: 50;
  width: 100%; height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 clamp(1rem, 3vw, 2rem);
  font-family: var(--font-mono); font-size: 0.8rem;
  background: rgba(10, 14, 26, 0.82);
  border-bottom: 1px solid var(--hair);
}
@supports ((backdrop-filter: blur(8px)) or (-webkit-backdrop-filter: blur(8px))) {
  .topbar { background: rgba(10, 14, 26, 0.55); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
}
.wordmark { display: inline-flex; align-items: center; gap: 0.6rem; font-weight: 500; letter-spacing: -0.01em; min-width: 0; }
.wordmark__mark {
  width: 16px; height: 16px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 30% 30%, var(--ember), transparent 60%),
              conic-gradient(from 200deg, var(--indigo), var(--teal), var(--indigo));
  box-shadow: 0 0 10px rgba(110, 140, 255, 0.6);
}
.wordmark__sep { color: var(--fg-decor); }
.wordmark__doc { color: var(--ember); }
.topbar__right { display: flex; align-items: center; gap: 1.1rem; }
.tag {
  padding: 0.3rem 0.6rem; border: 1px solid rgba(242, 200, 121, 0.3); border-radius: 100px;
  color: var(--gold); font-size: 0.66rem; letter-spacing: 0.12em; white-space: nowrap;
}
.topbar__link { position: relative; color: var(--fg); padding: 0.4rem 0; }
.topbar__link::after {
  content: ""; position: absolute; left: 0; bottom: 0; width: 100%; height: 1px;
  background: var(--ember); transform: scaleX(0); transform-origin: 0 50%; transition: transform 0.4s var(--ease);
}
.topbar__link:hover::after { transform: scaleX(1); }
@media (max-width: 560px) { .tag--status { display: none; } }

/* ---- layout ------------------------------------------------------------ */
.layout {
  max-width: 1320px; margin: 0 auto;
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: clamp(2rem, 5vw, 5rem);
  padding: 0 clamp(1.25rem, 4vw, 3rem);
}

/* ---- sidebar TOC ------------------------------------------------------- */
.toc {
  position: sticky; top: var(--topbar-h); align-self: start;
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto; overscroll-behavior: contain;
  padding: 2.4rem 0.5rem 3rem 0;
  font-size: 0.86rem;
  mask-image: linear-gradient(180deg, transparent, #000 3%, #000 96%, transparent);
}
.toc-title {
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ember); margin-bottom: 1rem; padding-left: 0.9rem;
}
.toc-list { list-style: none; padding: 0; }
.toc-group { margin-top: 1.4rem; }
.toc-group:first-child { margin-top: 0; }
.toc-group > a {
  display: block; font-family: var(--font-display); font-size: 1rem; font-weight: 500;
  color: var(--fg); padding: 0.3rem 0.9rem; letter-spacing: -0.01em; line-height: 1.25;
}
.toc-item > a {
  display: block; color: var(--fg-muted); padding: 0.32rem 0.9rem;
  border-left: 2px solid transparent; line-height: 1.35; transition: color 0.2s ease, border-color 0.2s ease;
}
.toc-item > a:hover { color: var(--fg); }
.toc a.is-current {
  color: var(--ember); border-left-color: var(--ember);
}
.toc-group > a.is-current { color: var(--ember); border-left: 0; }
.toc-foot {
  margin-top: 2rem; padding: 0 0.9rem; font-size: 0.74rem; line-height: 1.5; color: var(--fg-faint);
}
.toc-foot code { font-size: 0.92em; color: var(--teal); }

/* ---- main / prose ------------------------------------------------------ */
.doc { padding-top: calc(var(--topbar-h) + 2.4rem); padding-bottom: 6rem; min-width: 0; }
.prose { max-width: var(--measure); }

.prose h1, .prose h2, .prose h3, .prose h4 {
  font-family: var(--font-display); font-weight: 500; letter-spacing: -0.02em;
  line-height: 1.12; scroll-margin-top: calc(var(--topbar-h) + 1.5rem);
  position: relative;
}
/* Part headers (document H1s) */
.prose h1 {
  font-size: clamp(2rem, 1.4rem + 2.4vw, 3.1rem); font-weight: 400;
  margin: 4.5rem 0 1.6rem; padding-top: 2.6rem; letter-spacing: -0.03em;
  border-top: 1px solid var(--hair-strong);
}
.prose > h1:first-child {
  border-top: 0; padding-top: 0; margin-top: 0.5rem;
  font-size: clamp(2.4rem, 1.6rem + 3vw, 3.8rem);
}
.prose h2 {
  font-size: clamp(1.5rem, 1.2rem + 1.1vw, 2.1rem); margin: 3rem 0 1.1rem; color: var(--fg);
}
.prose h3 { font-size: 1.28rem; margin: 2.2rem 0 0.8rem; color: var(--fg); }
.prose h4 { font-size: 1.08rem; margin: 1.8rem 0 0.6rem; color: var(--fg-muted); font-family: var(--font-body); font-weight: 600; }

.anchor {
  position: absolute; left: -1.4rem; top: 0.1em;
  color: var(--ember); opacity: 0; text-decoration: none; font-weight: 400;
  font-family: var(--font-mono); transition: opacity 0.2s ease;
}
.prose h1:hover .anchor, .prose h2:hover .anchor, .prose h3:hover .anchor { opacity: 0.7; }
@media (max-width: 640px) { .anchor { display: none; } }

.prose p { margin: 1.1rem 0; color: var(--fg-read); }
.prose strong { color: var(--fg); font-weight: 600; }
.prose em { color: var(--fg); }
.prose a:not(.anchor) {
  color: var(--ember); text-decoration: underline; text-decoration-color: rgba(232, 145, 91, 0.4);
  text-underline-offset: 3px; transition: text-decoration-color 0.2s ease;
}
.prose a:not(.anchor):hover { text-decoration-color: var(--ember); }

.prose ul, .prose ol { margin: 1.1rem 0; padding-left: 1.4rem; }
.prose li { margin: 0.4rem 0; color: var(--fg-read); }
.prose li::marker { color: var(--ember); }

.prose blockquote {
  margin: 1.6rem 0; padding: 0.4rem 0 0.4rem 1.4rem;
  border-left: 2px solid var(--ember); color: var(--fg-muted);
  font-family: var(--font-display); font-size: 1.12rem; font-style: italic;
}
.prose hr { border: 0; height: 1px; background: var(--hair); margin: 3rem 0; }

/* inline + block code */
.prose code {
  font-family: var(--font-mono); font-size: 0.86em;
  color: var(--teal); background: rgba(61, 216, 196, 0.08);
  padding: 0.12em 0.4em; border-radius: 4px; border: 1px solid rgba(61, 216, 196, 0.16);
  overflow-wrap: anywhere;
}
.prose pre {
  margin: 1.6rem 0; padding: 1.2rem 1.4rem; overflow-x: auto;
  background: var(--bg-2); border: 1px solid var(--hair); border-left: 2px solid var(--ember);
  border-radius: 8px; font-size: 0.86rem; line-height: 1.6;
}
.prose pre code { color: var(--fg-read); background: none; border: 0; padding: 0; }

/* tables */
.table-wrap { margin: 1.8rem 0; overflow-x: auto; border: 1px solid var(--hair); border-radius: 10px; }
.prose table { width: 100%; border-collapse: collapse; font-size: 0.94rem; min-width: 32rem; }
.prose thead th {
  text-align: left; font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--fg-muted); font-weight: 500;
  padding: 0.85rem 1.1rem; background: var(--bg-3); border-bottom: 1px solid var(--hair-strong);
}
.prose tbody td { padding: 0.8rem 1.1rem; border-bottom: 1px solid var(--hair); vertical-align: top; }
.prose tbody tr:last-child td { border-bottom: 0; }
.prose tbody tr:nth-child(even) { background: rgba(255, 255, 255, 0.012); }
.prose td strong { color: var(--gold); font-weight: 500; }

/* the front-matter metadata table (first table) reads as a card */
.prose > .table-wrap:first-of-type table { min-width: 0; }
.prose > .table-wrap:first-of-type td:first-child { color: var(--fg-muted); font-family: var(--font-mono); font-size: 0.82rem; }

/* ---- doc footer -------------------------------------------------------- */
.doc-foot { max-width: var(--measure); margin-top: 4rem; padding-top: 2rem; border-top: 1px solid var(--hair); color: var(--fg-muted); font-size: 0.92rem; }
.doc-foot p { margin: 0.8rem 0; }
.doc-foot code { font-family: var(--font-mono); color: var(--teal); font-size: 0.88em; }
.doc-foot__legal { font-size: 0.78rem; color: var(--fg-faint); }
.back { color: var(--ember); font-family: var(--font-mono); font-size: 0.85rem; }

/* ---- mobile TOC -------------------------------------------------------- */
.toc-toggle {
  display: none;
  position: fixed; z-index: 55; right: 1rem; top: calc(var(--topbar-h) + 0.75rem);
  font-family: var(--font-mono); font-size: 0.78rem; color: var(--fg);
  background: var(--bg-2); border: 1px solid var(--hair-strong); border-radius: 100px;
  padding: 0.5rem 1rem; cursor: pointer;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .toc-toggle { display: inline-flex; align-items: center; gap: 0.4rem; }
  .toc {
    position: fixed; top: var(--topbar-h); left: 0; width: min(86vw, 340px);
    height: calc(100vh - var(--topbar-h)); background: var(--bg-2);
    border-right: 1px solid var(--hair); padding: 2rem 1.2rem 3rem; z-index: 54;
    transform: translateX(-102%); transition: transform 0.32s var(--ease);
    mask-image: none;
  }
  .toc.is-open { transform: translateX(0); box-shadow: 30px 0 80px rgba(0,0,0,0.5); }
  .doc { padding-top: calc(var(--topbar-h) + 3.4rem); }
}

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