/* ==========================================================================
   ALL CITY — DOCUMENT SHELL (phase 6)
   Used by guide.html and changelog.html. These two pages are documents, not
   scenes: native scroll, no wipe, no dot nav, readable measure, sticky rail.
   Loaded after night.css so the token file stays the single source of type.
   ========================================================================== */

html { scroll-behavior: smooth; }
html, body { height: auto; min-height: 100%; overflow-x: hidden; overflow-y: auto; }

body.doc {
  --doc-pad: clamp(16px, 4vw, 40px);
  --rail-w: 232px;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: var(--leading-body);
  color: #cfc9b8;
  cursor: auto;
}
body.doc ::selection { background: var(--yellow); color: #12100c; }
body.doc::after { opacity: .62; }

/* ---------- skip link + focus ---------- */
.skip {
  position: fixed; left: 14px; top: -72px; z-index: 300;
  display: inline-flex; align-items: center; min-height: 44px;
  padding: 0 18px; background: var(--yellow); color: #12100c;
  font-family: var(--font-ui); font-size: 12px; font-weight: 700;
  letter-spacing: .14em; text-decoration: none; text-transform: uppercase;
  border: 2px solid #12100c; box-shadow: 4px 4px 0 var(--hot);
  transition: top .16s ease;
}
.skip:focus, .skip:focus-visible { top: 12px; outline: 2px solid var(--paper); outline-offset: 2px; }

.doc a:focus-visible,
.doc button:focus-visible,
.doc input:focus-visible,
.doc summary:focus-visible,
.doc-top a:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

/* ---------- sticky header ---------- */
.doc-top {
  position: sticky; top: 0; z-index: 90;
  background: linear-gradient(180deg, rgba(18,18,16,.98), rgba(8,8,10,.94));
  border-bottom: 1px solid rgba(232,226,208,.16);
  backdrop-filter: blur(8px);
}
.doc-top-in {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  max-width: 1280px; margin: 0 auto; padding: 10px var(--doc-pad);
}
.doc-brand {
  display: inline-flex; flex-direction: column; justify-content: center; align-items: flex-start;
  min-width: 44px; min-height: 44px; font-family: var(--font-display); font-size: 17px; letter-spacing: .12em;
  color: var(--paper); text-decoration: none; line-height: 1;
}
.doc-brand b { color: var(--hot); }
.doc-brand .doc-word { display: block; line-height: 1; }
.doc-brand .brand-year { margin-left: 5px; padding: 1px 3px; font-size: 7px; vertical-align: top; }
.doc-brand small {
  display: block; margin-top: 4px; font-family: var(--font-ui);
  font-size: 9px; letter-spacing: .24em; color: var(--dim);
}
.doc-nav { display: flex; flex-wrap: wrap; gap: 2px; margin-left: auto; align-items: center; }
.doc-nav a {
  display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; padding: 0 12px;
  font-family: var(--font-ui); font-size: 11px; letter-spacing: .16em;
  color: #b7b1a2; text-decoration: none; border: 1px solid transparent;
  transition: color .16s, border-color .16s, background .16s;
}
.doc-nav a:hover { color: var(--paper); border-color: rgba(232,226,208,.3); }
.doc-nav a[aria-current="page"] {
  background: var(--yellow); border-color: var(--yellow); color: #12100c; font-weight: 700;
}
.doc-nav a.doc-play {
  background: var(--hot); border-color: var(--hot); color: var(--ink);
  font-weight: 700; padding: 0 14px;
}
.doc-nav a.doc-play:hover { background: var(--paper); border-color: var(--paper); color: #12100c; }

.progress { height: 3px; background: rgba(232,226,208,.1); }
.progress b { display: block; height: 100%; width: 0; background: var(--hot); transition: width .1s linear; }

/* ---------- page shell ---------- */
.doc-main {
  position: relative; z-index: 2;
  max-width: 1280px; margin: 0 auto;
  padding: clamp(26px, 5vw, 54px) var(--doc-pad) clamp(40px, 6vw, 80px);
}

.doc-hero {
  border-left: 3px solid var(--hot);
  padding-left: clamp(16px, 2.6vw, 30px);
  margin-bottom: clamp(28px, 4vw, 44px);
}
.doc-kicker {
  font-family: var(--font-ui); font-size: 11px; letter-spacing: .3em;
  text-transform: uppercase; color: var(--hot); margin-bottom: 10px;
}
.doc-hero h1 {
  font-family: var(--font-display);
  font-size: clamp(38px, 6.2vw, 76px);
  line-height: .9; letter-spacing: .012em; text-transform: uppercase;
  margin-bottom: 16px;
}
.doc-hero h1 em { font-style: normal; color: var(--hot); }
.doc-lede {
  font-family: var(--font-body); font-size: clamp(16px, 1.45vw, 20px);
  line-height: 1.62; color: #dad4c3; max-width: 58ch;
}
.doc-meta { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 20px; }
.doc-meta span {
  font-family: var(--font-ui); font-size: 10px; letter-spacing: .14em;
  border: 1px solid rgba(232,226,208,.2); background: rgba(0,0,0,.34);
  padding: 6px 9px; color: var(--dim);
}
.doc-meta b { color: var(--paper); font-weight: 400; }
.doc-cta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
.doc-cta .btn { font-size: 12px; }
.doc-cta .btn.ghost { background: none; color: var(--paper); border: 1px solid rgba(232,226,208,.34); box-shadow: none; }
.doc-cta .btn.ghost:hover { background: rgba(232,226,208,.08); box-shadow: none; }

/* ---------- content grid + rail ---------- */
.doc-grid {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  gap: clamp(24px, 4vw, 52px);
  align-items: start;
}
.doc-grid--right { grid-template-columns: minmax(0, 1fr) 218px; }

.doc-rail {
  position: sticky; top: 86px;
  max-height: calc(100vh - 110px); overflow-y: auto;
  border: 1px solid rgba(232,226,208,.16);
  background: rgba(10,10,12,.82);
  padding: 14px 12px;
}
.doc-rail-title {
  font-family: var(--font-ui); font-size: 10px; letter-spacing: .26em;
  text-transform: uppercase; color: var(--hot); margin-bottom: 10px;
  display: flex; justify-content: space-between; gap: 8px;
}
.doc-rail nav { display: grid; gap: 1px; }
.doc-rail a {
  display: flex; align-items: center; gap: 8px; min-height: 38px;
  padding: 6px 8px; font-family: var(--font-ui); font-size: 11px;
  letter-spacing: .05em; line-height: 1.3; color: #bab4a4;
  text-decoration: none; border-left: 2px solid transparent;
}
.doc-rail a:hover { color: var(--paper); background: rgba(232,226,208,.06); border-left-color: var(--hot); }
.doc-rail a[aria-current="true"] {
  color: var(--paper); background: rgba(240,180,41,.1);
  border-left-color: var(--yellow); font-weight: 600;
}
.doc-rail .rail-num {
  font-family: var(--font-ui); font-size: 9px; color: var(--dim); letter-spacing: .1em;
  min-width: 18px;
}
.doc-rail-foot {
  display: block; margin-top: 12px; padding-top: 10px;
  border-top: 1px solid rgba(232,226,208,.14);
  font-family: var(--font-ui); font-size: 10px; letter-spacing: .12em;
  color: var(--yellow); text-decoration: none;
}
.doc-rail-foot:hover { color: var(--paper); }

/* the rail scrollbar is a thin version of the page bar, not a slab */
.doc-rail::-webkit-scrollbar { width: 7px; }
.doc-rail::-webkit-scrollbar-track { background: rgba(0,0,0,.45); border-left: 0; }
.doc-rail::-webkit-scrollbar-thumb { border: 1px solid #0c0c0a; }
@supports not selector(::-webkit-scrollbar) {
  .doc-rail { scrollbar-width: thin; scrollbar-color: rgba(194,59,46,.9) rgba(0,0,0,.5); }
}

/* mobile contents */
.doc-toc-mobile {
  display: none; margin: 0 0 22px;
  border: 1px solid rgba(232,226,208,.18); background: rgba(10,10,12,.85);
}
.doc-toc-mobile summary {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 48px; padding: 0 14px; cursor: pointer;
  font-family: var(--font-ui); font-size: 11px; letter-spacing: .24em;
  color: var(--yellow); text-transform: uppercase; list-style: none;
}
.doc-toc-mobile summary::-webkit-details-marker { display: none; }
.doc-toc-mobile summary::after { content: "+"; font-size: 16px; color: var(--paper); }
.doc-toc-mobile[open] summary::after { content: "–"; }
.doc-toc-mobile nav { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; padding: 0 8px 10px; }
.doc-toc-mobile a {
  display: flex; align-items: center; min-height: 44px; padding: 4px 8px;
  font-family: var(--font-ui); font-size: 12px; color: #c3bdad;
  text-decoration: none; border-bottom: 1px solid rgba(232,226,208,.08);
}
.doc-toc-mobile a:active { color: var(--paper); }

/* ---------- body copy ---------- */
.doc-body { min-width: 0; font-family: var(--font-body); }
.doc-body section {
  scroll-margin-top: 96px;
  padding-bottom: clamp(22px, 3vw, 34px);
  margin-bottom: clamp(22px, 3vw, 34px);
  border-bottom: 1px dashed rgba(232,226,208,.13);
}
.doc-body section:last-of-type { border-bottom: 0; }
.doc-body h2 {
  font-family: var(--font-display);
  font-size: clamp(26px, 3.2vw, 40px);
  line-height: 1; letter-spacing: .01em; text-transform: uppercase;
  color: var(--paper); margin-bottom: 14px;
  scroll-margin-top: 96px;
}
.doc-body h2 .h-count {
  display: inline-block; margin-right: 10px;
  font-family: var(--font-ui); font-size: 12px; letter-spacing: .16em;
  color: var(--hot); vertical-align: middle; transform: translateY(-.45em);
}
.doc-body h3 {
  font-family: var(--font-ui); font-size: 14px; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase; color: var(--paper);
  margin: 1.3em 0 .3em;
}
.doc-body h4 {
  font-family: var(--font-body); font-size: 17px; font-weight: 700;
  color: var(--paper); margin: 1.1em 0 .3em;
}
.doc-body p {
  font-family: var(--font-body); font-size: clamp(15.5px, 1.1vw + 10px, 17px);
  line-height: var(--leading-body); color: #cfc9b8;
  margin: 0 0 .85em; max-width: var(--measure);
}
.doc-body p:last-child { margin-bottom: 0; }
.doc-body b, .doc-body strong { color: var(--paper); font-weight: 700; }
.doc-body a { color: var(--cyan); text-decoration: underline; text-underline-offset: 3px; }
.doc-body a:hover { color: var(--paper); }
.doc-body a.btn { color: var(--ink); text-decoration: none; }
.doc-body a.btn:hover { color: var(--ink); }
.doc-body a.btn.ghost { background: none; border: 1px solid rgba(232,226,208,.34); box-shadow: none; color: var(--paper); }
.doc-body a.btn.ghost:hover { color: var(--paper); }
.doc-body code {
  font-family: var(--font-typewriter); font-size: .9em;
  background: rgba(240,180,41,.1); color: var(--yellow);
  padding: 1px 5px; border-radius: 2px;
}

.doc-body ul, .doc-body ol { max-width: var(--measure); margin: 0 0 1em; padding: 0; list-style: none; display: grid; gap: 9px; }
.doc-body li {
  position: relative; padding-left: 20px;
  font-family: var(--font-body); font-size: clamp(15px, 1vw + 10px, 16.5px);
  line-height: 1.65; color: #c9c3b3;
}
.doc-body li::before {
  content: ""; position: absolute; left: 2px; top: .68em;
  width: 7px; height: 7px; background: var(--hot); transform: rotate(45deg);
}
.doc-body ol { counter-reset: docol; }
.doc-body ol li { counter-increment: docol; padding-left: 30px; }
.doc-body ol li::before {
  content: counter(docol, decimal-leading-zero);
  width: auto; height: auto; background: none; transform: none;
  font-family: var(--font-ui); font-size: 11px; letter-spacing: .1em;
  color: var(--yellow); top: .28em; left: 0;
}
.doc-body li b { color: var(--paper); }

/* callout */
.callout {
  border-left: 3px solid var(--yellow);
  background: rgba(240,180,41,.08);
  padding: 12px 15px; margin: 6px 0 18px; max-width: var(--measure);
  font-family: var(--font-body); font-size: 15px; line-height: 1.62; color: #ded8c6;
}
.callout b { color: var(--yellow); }

/* figures / diagrams */
.figure {
  margin: 8px 0 20px; padding: 14px;
  border: 1px solid rgba(232,226,208,.14);
  background: rgba(0,0,0,.3); max-width: 640px;
}
.figure svg { display: block; width: 100%; height: auto; }
.figure figcaption {
  margin-top: 10px; font-family: var(--font-ui); font-size: 11px;
  letter-spacing: .06em; line-height: 1.5; color: var(--dim);
}

/* ---------- changelog ---------- */
.log-tools {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 12px 0 16px; margin-bottom: 6px;
  border-bottom: 1px solid rgba(232,226,208,.14);
}
.log-search {
  display: flex; align-items: center; gap: 8px; flex: 1 1 240px;
  border: 1px solid rgba(232,226,208,.22); background: rgba(0,0,0,.45);
  padding: 0 10px; min-height: 44px;
}
.log-search label {
  font-family: var(--font-ui); font-size: 10px; letter-spacing: .16em;
  color: var(--dim); white-space: nowrap;
}
.log-search input {
  flex: 1; min-width: 0; min-height: 44px; background: none; border: 0; color: var(--paper);
  font-family: var(--font-body); font-size: 15px; padding: 10px 0; outline: none;
}
.log-search input::placeholder { color: #7d786c; }
.log-filters { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  min-width: 44px; min-height: 44px; padding: 0 11px; cursor: pointer;
  font-family: var(--font-ui); font-size: 10px; letter-spacing: .14em;
  color: #bab4a4; background: rgba(0,0,0,.35);
  border: 1px solid rgba(232,226,208,.2); transition: .16s;
}
.chip:hover { color: var(--paper); border-color: rgba(232,226,208,.45); }
.chip[aria-pressed="true"] { background: var(--yellow); border-color: var(--yellow); color: #12100c; font-weight: 700; }
.log-count {
  font-family: var(--font-ui); font-size: 10px; letter-spacing: .12em;
  color: var(--dim); margin-left: auto;
}
.log-empty {
  display: none; padding: 22px; border: 1px dashed rgba(232,226,208,.25);
  font-family: var(--font-body); font-size: 15px; color: var(--dim);
}
.log-empty.on { display: block; }

.rel {
  position: relative; margin-bottom: 16px; padding: clamp(16px, 2.3vw, 24px);
  border: 1px solid rgba(232,226,208,.16);
  background: linear-gradient(160deg, rgba(255,255,255,.04), rgba(0,0,0,.4));
  scroll-margin-top: 96px;
}
.rel::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--hot); }
.rel.is-current::before { background: var(--yellow); }
.rel-head { margin-bottom: 12px; }
.rel-ver { display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px; }
.rel-ver h2 {
  font-family: var(--font-graffiti); font-size: clamp(24px, 2.6vw, 32px);
  line-height: 1; letter-spacing: .01em; margin: 0;
}
.rel-ver h2 a { color: var(--yellow); text-decoration: none; }
.rel-ver h2 a:hover { color: var(--paper); }
.rel-date { font-family: var(--font-ui); font-size: 11px; letter-spacing: .18em; color: var(--dim); }
.rel-badge {
  font-family: var(--font-ui); font-size: 9px; font-weight: 700; letter-spacing: .16em;
  background: var(--yellow); color: #12100c; padding: 3px 7px;
}
.rel-name {
  font-family: var(--font-display); font-size: clamp(19px, 2.2vw, 26px);
  letter-spacing: .02em; text-transform: uppercase; color: var(--paper);
  margin: 6px 0 6px;
}
.rel-sum {
  font-family: var(--font-body); font-size: 15.5px; line-height: 1.6;
  color: #beb8a7; max-width: 62ch; margin-bottom: 14px;
}
.rel-list { display: grid; gap: 11px; max-width: none; }
.rel-list li {
  display: grid; grid-template-columns: 62px minmax(0, 1fr); gap: 12px;
  align-items: start; padding-left: 0;
  font-family: var(--font-body); font-size: 15px; line-height: 1.62; color: #cbc5b5;
}
.rel-list li::before { display: none; }
.rel-list li p { margin: 0; font-size: 15px; line-height: 1.62; max-width: 66ch; }
.rel-list li b { color: var(--paper); }
.cat {
  font-family: var(--font-ui); font-size: 9px; font-weight: 700;
  letter-spacing: .12em; line-height: 1.9; color: var(--dim); white-space: nowrap;
}
.cat-feature { color: var(--yellow); }
.cat-fix { color: var(--cyan); }
.cat-balance { color: #8fc98f; }
.cat-ux { color: #cbb0f0; }
.cat-art { color: #ef8b7e; }

/* version rail */
.ver-rail a { font-size: 10px; }
.ver-rail .ver-name {
  display: block; font-family: var(--font-display); font-size: 14px;
  letter-spacing: .06em; color: var(--paper); line-height: 1.1;
}
.ver-rail a[aria-current="true"] .ver-name { color: var(--yellow); }
.ver-rail small { display: block; font-size: 9px; letter-spacing: .1em; color: var(--dim); margin-top: 2px; }

.log-summary {
  border: 1px solid rgba(232,226,208,.18);
  background: rgba(240,180,41,.05);
  padding: 16px; margin-bottom: 18px;
}
.log-summary b {
  display: block; font-family: var(--font-ui); font-size: 10px;
  letter-spacing: .2em; color: var(--yellow); margin-bottom: 8px;
}
.log-summary p { font-size: 15px; line-height: 1.6; margin: 0 0 8px; max-width: 60ch; }
.log-summary p:last-child { margin-bottom: 0; }

/* ---------- back to top + footer ---------- */
.to-top {
  position: fixed; right: 16px; bottom: 16px; z-index: 95;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 46px; min-height: 46px; padding: 0 14px;
  background: var(--paper); color: #12100c; border: 2px solid #12100c;
  box-shadow: 4px 4px 0 var(--hot); cursor: pointer;
  font-family: var(--font-ui); font-size: 10px; font-weight: 700; letter-spacing: .14em;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
}
.to-top.on { opacity: 1; pointer-events: auto; }
.to-top:hover { transform: translate(-1px, -1px); box-shadow: 6px 6px 0 var(--hot); }

.doc-foot {
  position: relative; z-index: 2;
  border-top: 1px solid rgba(232,226,208,.16);
  margin-top: 20px; padding: 24px var(--doc-pad) 46px;
  max-width: 1280px; margin-left: auto; margin-right: auto;
  display: flex; flex-wrap: wrap; gap: 14px; align-items: center;
  font-family: var(--font-ui); font-size: 10px; letter-spacing: .12em; color: var(--dim);
}
.doc-foot a { display: inline-flex; align-items: center; min-height: 44px; color: var(--cyan); text-decoration: none; }
.doc-foot a:hover { color: var(--paper); }
.doc-foot .doc-share { min-height: 44px; padding: 0 6px; border: 0; background: none; color: var(--cyan);
  font-family: var(--font-ui); font-size: 10px; letter-spacing: .12em; cursor: pointer; }
.doc-foot .doc-share:hover, .doc-foot .doc-share:focus-visible { color: var(--paper); text-decoration: underline; text-underline-offset: 3px; }
.doc-foot .spacer { flex: 1 1 120px; }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .doc-grid, .doc-grid--right { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .doc-rail { display: none; }
  .doc-toc-mobile { display: block; }
  .doc-top-in { padding: 8px var(--doc-pad); gap: 8px; }
  .doc-brand small { display: none; }
  .doc-nav a { padding: 0 9px; font-size: 10px; letter-spacing: .12em; }
}

@media (max-width: 560px) {
  .doc-nav { width: 100%; margin-left: 0; flex-wrap: wrap; gap: 2px; }
  .doc-nav a { flex: none; min-height: 44px; }
  .doc-top-in { padding-bottom: 0; }
  .doc-hero { padding-left: 14px; }
  .doc-body h2 .h-count { display: block; margin: 0 0 4px; transform: none; }
  .rel-list li { grid-template-columns: 1fr; gap: 3px; }
  .doc-toc-mobile nav { grid-template-columns: 1fr; }
  .doc-cta .btn { width: 100%; justify-content: space-between; }
}

/* ---------- motion ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .doc * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
  .progress b { transition: none; }
}

/* ---------- print ---------- */
@media print {
  @page { margin: 16mm; }
  html, body { background: #fff !important; color: #111 !important; }
  body::before, body::after, .wall-tag, .glow, .grid, .skyline, .train, .scan, .grain, .vignette,
  .doc-top, .doc-rail, .doc-toc-mobile, .to-top, .progress, .skip,
  .doc-cta, .log-tools, .doc-foot { display: none !important; }
  .doc-main { max-width: none; padding: 0; }
  .doc-hero { border-left-color: #333; margin-bottom: 18px; }
  .doc-hero h1, .doc-body h2, .doc-body h3, .rel-name, .rel-ver h2 a { color: #000 !important; }
  .doc-lede, .doc-body p, .doc-body li, .rel-sum, .rel-list li, .rel-list li p { color: #1a1a1a !important; }
  .doc-body section { border-bottom: 1px solid #ccc; padding-bottom: 12px; margin-bottom: 16px; }
  .rel, .callout, .figure, .log-summary { border-color: #bbb !important; background: none !important; box-shadow: none; }
  .rel { break-inside: avoid; }
  .rel-list li { break-inside: avoid; }
  .figure svg { max-width: 100%; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 10px; color: #555; }

}
/* Document pages fade rather than take the marketing curtain wipe. */
body { animation: docFade .3s ease-out both; }
@keyframes docFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Phase 9.3: document pages keep 44px controls and reflow at 200%. */
@media (max-width: 900px) {
  .mainnav a, .hud-play, .hud-right button, .hud-right a, .btn, .toc a, .rel-tools button,
  .chip, .link { min-height: 44px; }
  .mainnav a, .toc a, .link { display: inline-flex; align-items: center; }
  .doc, .wrap, .doc-grid, .prose { min-width: 0; max-width: 100%; }
  .prose table { display: block; overflow-x: auto; }
}
