/*
 * Shared reader chrome and visual system for publication maps.
 *
 * The map bodies remain authored in their own source files because their
 * ontologies and layouts differ. This file owns the things a reader should
 * experience as one site: the palette, type roles, page rhythm, masthead,
 * navigation, controls, contents surfaces and footer.
 */
:root {
  --maps-ground: #fbfaf8;
  --maps-panel: #ffffff;
  --maps-panel-2: #ffffff;
  --maps-ink-1: #17181a;
  --maps-ink-2: #3d4046;
  --maps-ink-3: #6c7079;
  --maps-rule: #e3e0da;
  --maps-rule-2: #e3e0da;
  --maps-accent: #8a4b2a;
  --maps-accent-soft: #f0e6df;
  --maps-sans: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --maps-display: Bahnschrift, "DIN Alternate", "DIN Condensed", "Arial Narrow", system-ui, sans-serif;
  --maps-mono: Consolas, "Cascadia Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Common aliases used by the authored AI and Physical AI styles. */
  --ground: var(--maps-ground);
  --ground-2: var(--maps-panel);
  --ground-3: var(--maps-panel-2);
  --panel: var(--maps-panel);
  --panel-2: var(--maps-panel-2);
  --paper: var(--maps-ground);
  --paper2: var(--maps-panel-2);
  --white: var(--maps-panel);
  --ink: var(--maps-ink-1);
  --ink-1: var(--maps-ink-1);
  --ink-2: var(--maps-ink-2);
  --ink2: var(--maps-ink-2);
  --ink-3: var(--maps-ink-3);
  --muted: var(--maps-ink-3);
  --faint: var(--maps-ink-3);
  --rule: var(--maps-rule);
  --rule-2: var(--maps-rule-2);
  --rule-strong: var(--maps-rule);
  --accent: var(--maps-accent);
  --accent-soft: var(--maps-accent-soft);
  --accent-bg: var(--maps-accent-soft);
  --blue: var(--maps-accent);
  --blue2: var(--maps-accent-soft);

  /* Shared semantic colors; state remains local to the map's explanation. */
  --bind: #a62518;
  --bind-bg: #f4dfdb;
  --tight: #8a5b10;
  --tight-bg: #f4ead6;
  --decay: #4c6a8a;
  --decay-bg: #dce6f0;
  --rent: #116b51;
  --rent-bg: #d6ebe3;
  --open: #697484;
  --open-bg: #e4e9ef;
  --rock: #2e3846;
  --rock-bg: #d2d8e0;
  --teal: #157d83;
  --green: #277753;
  --amber: #8a5b10;
  --plum: #76518e;
  --red: #a62518;

  --mono: var(--maps-mono);
  --sans: var(--maps-sans);
  --display: var(--maps-display);
  --f-body: var(--maps-sans);
  --f-data: var(--maps-mono);
  --f-disp: var(--maps-display);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --maps-ground: #141517;
    --maps-panel: #191b1e;
    --maps-panel-2: #191b1e;
    --maps-ink-1: #ece9e4;
    --maps-ink-2: #c2c0bb;
    --maps-ink-3: #8b8f97;
    --maps-rule: #2c2f34;
    --maps-rule-2: #2c2f34;
    --maps-accent: #e0a17a;
    --maps-accent-soft: #2a221d;
    --bind: #f0907f;
    --bind-bg: #3a1d18;
    --tight: #e0b268;
    --tight-bg: #32270f;
    --decay: #92b4d6;
    --decay-bg: #17293a;
    --rent: #5fc6a4;
    --rent-bg: #0f3128;
    --open: #96a2b4;
    --open-bg: #1c2530;
    --rock: #c3ccd9;
    --rock-bg: #262f3b;
  }
}

:root[data-theme="dark"] {
  --maps-ground: #141517;
  --maps-panel: #191b1e;
  --maps-panel-2: #191b1e;
  --maps-ink-1: #ece9e4;
  --maps-ink-2: #c2c0bb;
  --maps-ink-3: #8b8f97;
  --maps-rule: #2c2f34;
  --maps-rule-2: #2c2f34;
  --maps-accent: #e0a17a;
  --maps-accent-soft: #2a221d;
  --bind: #f0907f;
  --bind-bg: #3a1d18;
  --tight: #e0b268;
  --tight-bg: #32270f;
  --decay: #92b4d6;
  --decay-bg: #17293a;
  --rent: #5fc6a4;
  --rent-bg: #0f3128;
  --open: #96a2b4;
  --open-bg: #1c2530;
  --rock: #c3ccd9;
  --rock-bg: #262f3b;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  background: var(--maps-ground);
}

body {
  margin: 0;
  background: var(--maps-ground);
  color: var(--maps-ink-1);
  font-family: var(--maps-sans);
  font-size: 17px;
  line-height: 1.62;
  font-synthesis-weight: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--maps-accent);
}

p {
  margin: 0 0 1.05em;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  color: var(--maps-ink-1);
  font-family: var(--maps-display);
  font-weight: 650;
  line-height: 1.12;
  letter-spacing: -0.02em;
}

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

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

/* Shared masthead. Keep it aligned to the 1120px reader column on every map. */
.map-shell-header {
  border-bottom: 1px solid var(--maps-rule);
  background: var(--maps-panel);
}

.map-shell-header-in {
  width: min(calc(100% - 56px), 1120px);
  max-width: 1120px;
  margin: 0 auto;
  padding: 18px 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
}

.map-wordmark {
  color: var(--maps-ink-1);
  font-family: var(--maps-sans);
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.02em;
  text-decoration: none;
}

.map-shell-header nav {
  display: flex;
  gap: 18px;
  font-family: var(--maps-sans);
  font-size: 13.5px;
}

.map-shell-header nav a {
  color: var(--maps-ink-2);
  text-decoration: none;
}

.map-shell-header nav a:hover,
.map-shell-header nav a:focus-visible {
  color: var(--maps-accent);
}

/* The AI landing uses its body as the wide two-column layout. Keep the site
 * masthead across the full grid; otherwise CSS grid treats the header as the
 * first narrow column and pushes the contents and report into separate rows. */
body.theme-home > .map-shell-header {
  grid-column: 1 / -1;
  grid-row: 1;
}

body.theme-home > .toc {
  grid-column: 1;
  grid-row: 2;
}

body.theme-home > .wrap {
  grid-column: 2;
  grid-row: 2;
}

@media (max-width: 1400px) {
  body.theme-home {
    display: block;
    padding: 0;
  }

  body.theme-home > .wrap {
    max-width: 1240px;
    margin: 0 auto;
    padding-left: 28px;
    padding-right: 28px;
  }
}

/* Canonical Contents contract. Every map reader uses the same button, drawer,
 * wide-screen rail and accessible open/close behaviour. Page-specific styles
 * may add hierarchy to the list, but they do not change its surface or
 * placement. */
body.theme-home,
body.home-page,
body.detail-page.with-toc,
body.branch-page.with-toc,
body.focus-page.with-toc {
  display: block;
  padding: 0;
}

.tocbtn,
.toc-toggle {
  position: fixed;
  z-index: 900;
  top: 76px;
  left: 16px;
  display: block;
  padding: 9px 12px;
  border: 1px solid var(--maps-rule);
  background: color-mix(in srgb, var(--maps-panel) 96%, transparent);
  color: var(--maps-ink-2);
  font: 700 10px/1 var(--maps-mono);
  letter-spacing: .12em;
  text-transform: uppercase;
  cursor: pointer;
  writing-mode: horizontal-tb;
  transform: none;
  box-shadow: 0 5px 18px rgba(31, 35, 40, .08);
}

@media (max-width: 700px) {
  .tocbtn, .toc-toggle {
    top: 50%;
    left: 0;
    padding: 10px 7px;
    writing-mode: vertical-rl;
    transform: translateY(-50%);
  }
  .tocbtn[aria-expanded="true"], .toc-toggle[aria-expanded="true"] {
    left: min(344px, calc(100vw - 46px));
  }
}

.toc {
  position: fixed;
  z-index: 899;
  /* Keep the drawer below the shared masthead rather than covering it. */
  inset: 76px auto 14px 14px;
  width: min(330px, calc(100vw - 28px));
  max-height: none;
  margin: 0;
  padding: 18px 16px 22px;
  overflow: auto;
  border: 1px solid var(--maps-rule);
  background: color-mix(in srgb, var(--maps-panel) 98%, transparent);
  color: var(--maps-ink-1);
  box-shadow: 15px 0 45px rgba(23, 26, 30, .14);
  transform: translateX(calc(-100% - 24px));
  transition: transform .2s ease;
}

.toc.open { transform: none; }
.toc h2,
.toc-title {
  margin: 0 0 12px;
  color: var(--maps-ink-1);
  font: 700 11px/1.2 var(--maps-mono);
  letter-spacing: .12em;
  text-transform: uppercase;
}
.toc a {
  display: block;
  padding: 7px 6px;
  color: var(--maps-ink-2);
  font-size: 13px;
  line-height: 1.35;
  text-decoration: none;
  border-left: 2px solid transparent;
  border-bottom: 1px solid var(--maps-rule-2);
}
.toc a:hover,
.toc a:focus-visible { color: var(--maps-accent); border-left-color: var(--maps-accent); }
.toc > ul > li > a { font-weight: 750; }
.toc a[aria-current="location"] {
  color: var(--maps-accent);
  font-weight: 750;
  background: var(--maps-accent-soft);
  border-left-color: var(--maps-accent);
}
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li > ul { padding-left: 16px; }
.toc li > ul a { font-size: 12px; }
/* Deeper report outlines keep every node visible. Indentation and weight
 * carry the hierarchy; another level does not mean smaller type. */
.toc[data-toc-depth="3"] a {
  font-size: 13px;
  line-height: 1.4;
  padding: 5px 8px;
  border-bottom: 0;
}
.toc[data-toc-depth="3"] > ul > li + li {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--maps-rule);
}
.toc[data-toc-depth="3"] li > ul {
  margin: 4px 0 2px 10px;
  padding-left: 11px;
  border-left: 0;
}
.toc[data-toc-depth="3"] li li > ul {
  margin-left: 0;
  padding-left: 0;
  border-left: 0;
}
.toc[data-toc-depth="3"] li li.toc-group > a { font-weight: 620; }
.toc[data-toc-depth="3"] li li.toc-leaf > a { font-weight: 400; }
.toc[data-toc-depth="3"] li li + li.toc-group { margin-top: 9px; }
.toc[data-toc-depth="3"] a[aria-current="location"] { font-weight: 750; }
.toc summary {
  padding: 7px 6px;
  color: var(--maps-ink-1);
  font: 700 10px/1.2 var(--maps-mono);
  letter-spacing: .1em;
  text-transform: uppercase;
  cursor: pointer;
}

@media (min-width: 1400px) {
  .tocbtn,
  .toc-toggle { display: none; }

  body.theme-home > .toc,
  body.home-page > .toc,
  body.detail-page.with-toc > .toc,
  body.branch-page.with-toc > .toc,
  body.focus-page.with-toc > .toc {
    /* The masthead is about 56px tall; leave a clear breathing band below it. */
    inset: 76px auto auto calc(50% - 680px);
    width: 280px;
    max-height: calc(100vh - 96px);
    padding: 18px 14px;
    box-shadow: none;
    transform: none;
  }

  body.theme-home > .wrap,
  body.home-page > .wrap,
  body.detail-page.with-toc > .wrap,
  body.branch-page.with-toc > .wrap,
  body.focus-page.with-toc > .wrap {
    /* 280px rail + 30px breathing room, with a viewport-safe fallback near
     * the breakpoint where the rail and reader would otherwise collide. */
    width: min(1120px, calc(100vw - (50% - 370px) - 30px));
    max-width: 1120px;
    margin-left: calc(50% - 370px);
    margin-right: 0;
  }

  body.branch-page.with-toc > .wrap { max-width: 1020px; }
}

@media (max-width: 1399px) {
  .tocbtn,
  .toc-toggle { display: block; }
}

/* The landing and family pages use a second, map-specific navigation surface. */
.home-page .tocbtn,
.detail-page .tocbtn {
  border-color: var(--maps-rule);
  background: var(--maps-panel);
  color: var(--maps-ink-2);
  box-shadow: 0 5px 18px rgba(31, 44, 67, 0.08);
}

.home-page .toc,
.detail-page .toc {
  border-color: var(--maps-rule);
  background: var(--maps-panel);
  color: var(--maps-ink-1);
  box-shadow: 15px 0 45px rgba(23, 35, 56, 0.14);
}

.home-page .toc a,
.detail-page .toc a {
  color: var(--maps-ink-2);
  border-bottom-color: var(--maps-rule-2);
}

.home-page .toc a:hover,
.home-page .toc a:focus-visible,
.detail-page .toc a:hover,
.detail-page .toc a:focus-visible {
  color: var(--maps-accent);
}

/* Shared node reading: narrative labels are headings, not tiny metadata. */
.branch-page .nodesec .node-subheading,
.detail-page .nodesec .node-subheading {
  font: 600 16px/1.4 var(--maps-display);
  color: var(--maps-ink-1);
  letter-spacing: 0;
  text-transform: none;
  margin: 22px 0 8px;
}
.branch-page .nodesec .node-players {
  max-width: 68ch;
  margin: 0 0 18px;
  padding-left: 21px;
  color: var(--maps-ink-2);
  font: 400 16px/1.65 var(--maps-sans);
  columns: 2;
  column-gap: 30px;
}
.branch-page .nodesec .node-players li {
  margin: 5px 0;
  padding-left: 2px;
  break-inside: avoid;
}
.branch-page .nsmeta .loc {
  font: inherit;
  letter-spacing: 0;
}
.branch-page .nsmeta div { min-width: 0; flex-wrap: wrap; }
.detail-page .node-heading {
  display: flex;
  align-items: baseline;
  gap: 10px 14px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.detail-page .nodesec .node-heading .node-title { margin: 0; }
.detail-page .node-status {
  display: inline-block;
  padding: 3px 7px;
  border: 1px solid var(--maps-rule);
  background: var(--maps-panel);
  color: var(--maps-ink-3);
  font: 600 12px/1.4 var(--maps-mono);
}
.detail-page .node-status-note {
  max-width: 790px;
  margin: 20px 0 0;
  font: 400 14px/1.6 var(--maps-sans);
  color: var(--maps-ink-3);
}
.detail-page .node-status[data-supply-state="mixed"] {
  color: var(--maps-accent);
  background: var(--maps-accent-soft);
}
.detail-page .node-economics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  margin: 16px 0 22px;
  padding: 12px 0;
  border-block: 1px solid var(--maps-rule);
  font: 400 12px/1.6 var(--maps-mono);
  color: var(--maps-ink-2);
}
.detail-page .node-economics > div { flex: 1 1 180px; min-width: 0; }
.detail-page .node-economics dt {
  color: var(--maps-ink-3);
  font-size: 11px;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.detail-page .node-economics dd { margin: 2px 0 0; overflow-wrap: anywhere; }
.detail-page .nodesec a:not(.backmap) { color: var(--maps-accent); }
.nodesec .backmap,
.detail-page .nodesec .backmap {
  display: inline-block;
  margin-top: 14px;
  padding: 4px 0;
  color: var(--maps-ink-3);
  font: 400 12px/1.5 var(--maps-mono);
  letter-spacing: .06em;
  text-transform: uppercase;
  text-decoration: none;
}
.nodesec .backmap:hover,
.nodesec .backmap:focus-visible { color: var(--maps-accent); }
@media (max-width: 700px) {
  .branch-page .nodesec .node-players { columns: 1; }
}

/* Shared controls and quiet surfaces. */
.mapbtn,
.home-page .mapbtn,
.detail-page .mapbtn {
  border-color: var(--maps-rule);
  background: var(--maps-panel);
  color: var(--maps-ink-2);
}

.mapbtn:hover,
.mapbtn:focus-visible,
.home-page .mapbtn:hover,
.home-page .mapbtn:focus-visible,
.detail-page .mapbtn:hover,
.detail-page .mapbtn:focus-visible {
  border-color: var(--maps-accent);
  color: var(--maps-accent);
}

.home-page .boundary-card,
.home-page .claim-card,
.home-page .report-card,
.home-page .method-note,
.home-page .synth-card,
.home-page .nodesec,
.home-page .family-map-lane {
  background: var(--maps-panel);
}

.home-page .family-map-wrap,
.detail-page .family-map-wrap {
  border-color: var(--maps-rule);
  background: var(--maps-ground);
}

.home-page .route-strip,
.detail-page .route-strip {
  border-color: var(--maps-rule);
  background: var(--maps-panel);
  color: var(--maps-ink-2);
}

.foot {
  border-top-color: var(--maps-rule);
  color: var(--maps-ink-3);
}

/* Landing-page hierarchy: the theme title is the one large display element;
 * primary report sections should read as sections, not competing page titles.
 * Physical AI's authored baseline was larger than the AI landing's, so bring
 * the shared landing treatment into one range without touching map-specific
 * node headings or compact method cards. */
.home-page .report-section > h2,
.home-page .enabling-markets h2,
.home-page .section-head > h2 {
  width: 100%;
  max-width: 850px;
  /* One clear report-section tier beneath the theme title. */
  font-size: clamp(32px, 3vw, 36px);
  font-weight: 680;
  text-wrap: balance;
}

.home-page .market-branch h3 {
  /* Enabling-market subheads remain visibly subordinate to report sections. */
  font-size: clamp(24px, 2.2vw, 28px);
  font-weight: 620;
}

.home-page .kicker {
  /* Section kickers stay legible in flow and in the sticky report label. */
  font-size: 12px;
}

.home-page .report-section#why-now > h2,
.home-page .report-section#misunderstandings > h2,
.home-page .report-section#future-view > h2 {
  /* These are subsections of the theme overview, not competing report titles. */
  font-size: clamp(24px, 2.2vw, 28px);
  font-weight: 620;
}

/* Keep only the landing page's report-level headings visible while their
 * section is being read. This is a visual orientation aid; the authored H2
 * remains the semantic heading and the copy is aria-hidden. */
.home-page .report-sticky-heading {
  position: fixed;
  z-index: 850;
  top: 0;
  left: max(28px, calc((100vw - 1120px) / 2));
  width: min(850px, calc(100vw - 56px));
  display: none;
  padding: 10px 0 11px;
  border-bottom: 1px solid var(--maps-rule);
  background: var(--maps-ground);
  color: var(--maps-ink-1);
}
.home-page .report-sticky-kicker {
  display: block;
  margin-bottom: 4px;
  color: var(--maps-accent);
  font: 750 12px/1.25 var(--maps-mono);
  letter-spacing: .15em;
  text-transform: uppercase;
}
.home-page .report-sticky-title {
  display: block;
  font-family: var(--maps-display);
  font-size: clamp(28px, 2.8vw, 36px);
  font-weight: 680;
  line-height: 1.08;
  letter-spacing: -.025em;
  text-wrap: balance;
}
.home-page .report-sticky-heading.is-visible { display: block; }

@media (min-width: 1400px) {
  .home-page .report-sticky-heading {
    left: calc(50% - 370px);
    width: min(850px, calc(100vw - (50% - 370px) - 30px));
  }
}

@media (max-width: 700px) {
  .home-page .report-sticky-heading {
    left: 42px;
    width: calc(100vw - 57px);
    padding: 8px 0 9px;
  }
  .home-page .report-sticky-title {
    font-size: 24px;
  }
}

@media print {
  .home-page .report-sticky-heading { display: none !important; }
}

/* A legend may wrap; it must not widen the document around a scrollable map. */
.process-key .state-scale {
  max-width: 100%;
  flex-wrap: wrap;
}

@media (max-width: 640px) {
  .map-shell-header-in {
    width: min(calc(100% - 30px), 1120px);
    flex-wrap: wrap;
    gap: 10px;
    padding: 16px 0;
  }

  body {
    font-size: 16px;
  }
}
