/* City Builder Tools: parchment planner by day, blueprint by night. Mobile-first; 16px gutters. */
:root {
  --paper: #f4ecd8;
  --paper-2: #ebe0c4;
  --card: #fbf6e9;
  --ink: #23303d;
  --ink-soft: #55606b;
  --line: #cdbf9c;
  --grid: rgba(29, 59, 92, 0.07);
  --blue: #1d3b5c;
  --blue-2: #2c5a86;
  --accent: #c0582b;
  --good: #3f7d4e;
  --shadow: 0 1px 0 rgba(35, 48, 61, 0.08), 0 6px 18px -10px rgba(35, 48, 61, 0.35);
  --display: "Fraunces", Georgia, serif;
  --sans: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f1c2b;
    --paper-2: #13253a;
    --card: #162a41;
    --ink: #e4ecf4;
    --ink-soft: #9db0c3;
    --line: #2a4562;
    --grid: rgba(140, 190, 240, 0.06);
    --blue: #8cc2f0;
    --blue-2: #b5d8f6;
    --accent: #f08a5d;
    --good: #7cc58e;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 8px 20px -12px rgba(0, 0, 0, 0.7);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 400 17px/1.6 var(--sans);
  color: var(--ink);
  background-color: var(--paper);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  overflow-x: hidden;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--blue-2); text-underline-offset: 3px; }
a:hover { color: var(--accent); }
h1, h2, h3 { font-family: var(--display); line-height: 1.15; color: var(--ink); margin: 1.4em 0 0.5em; }
h1 { font-size: clamp(1.9rem, 6vw, 3rem); font-weight: 800; letter-spacing: -0.01em; margin-top: 0.4em; }
h2 { font-size: clamp(1.35rem, 4vw, 1.75rem); font-weight: 600; }
h3 { font-size: 1.15rem; font-weight: 600; }
code, kbd, .num { font-family: var(--mono); font-size: 0.92em; }
.wrap { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 16px; top: 8px; background: var(--card); padding: 8px 12px; z-index: 10; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Header + footer */
.top { background: var(--blue); color: #f4ecd8; border-bottom: 3px solid var(--accent); }
@media (prefers-color-scheme: dark) { .top { background: #0a1520; } }
.top .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 58px; flex-wrap: wrap; }
.brand { font: 800 1.2rem/1 var(--display); color: #f4ecd8; text-decoration: none; display: inline-flex; align-items: center; gap: 10px; }
.brand span { color: var(--accent); }
.brand-mark { width: 26px; height: 26px; background: url("/favicon.svg") center/contain no-repeat; }
.top nav { display: flex; gap: 4px; }
.top nav a { color: #f4ecd8; text-decoration: none; font-weight: 600; font-size: 0.95rem; padding: 8px 10px; border-radius: 6px; }
.top nav a:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.foot { margin-top: 64px; padding: 32px 0 40px; border-top: 1px dashed var(--line); background: var(--paper-2); color: var(--ink-soft); font-size: 0.95rem; }
.foot-brand { font: 800 1.1rem var(--display); color: var(--ink); margin: 0 0 6px; }
.foot .small { font-size: 0.82rem; }

/* Heroes */
.home-hero { background: var(--blue); color: #f4ecd8; padding: 40px 0 44px; position: relative; overflow: hidden;
  background-image: linear-gradient(rgba(255,255,255,0.07) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.07) 1px, transparent 1px);
  background-size: 32px 32px; }
@media (prefers-color-scheme: dark) { .home-hero { background-color: #0a1520; } }
.home-hero h1 { color: #fff; max-width: 18ch; }
.home-hero .lede { color: #dbe6f0; max-width: 46ch; }
.kicker { font: 700 0.78rem/1.2 var(--mono); text-transform: uppercase; letter-spacing: 0.12em; color: var(--accent); margin: 0; }
.lede { font-size: 1.12rem; color: var(--ink-soft); margin: 0.4em 0 0; }
.game-hero { min-height: 220px; display: flex; align-items: flex-end; background: var(--blue) var(--hero) center/cover no-repeat; position: relative; }
.game-hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(10, 21, 32, 0) 30%, rgba(10, 21, 32, 0.75)); }
.game-hero-in { position: relative; z-index: 1; padding-bottom: 18px; }
.game-hero .kicker { color: #fff; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7); }
.game-logo { max-width: min(320px, 70vw); max-height: 120px; width: auto; margin-bottom: 8px; filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.6)); }
.tool-strip { height: 64px; background: var(--blue) var(--strip) center 30%/cover no-repeat; position: relative; display: flex; align-items: flex-end; }
.tool-strip::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(10, 21, 32, 0.8), rgba(10, 21, 32, 0.2)); }
.tool-strip .wrap { position: relative; z-index: 1; padding-bottom: 10px; }
.tool-strip a { color: #fff; font: 700 0.95rem var(--display); text-decoration: none; }

/* Page furniture */
.crumbs { font-size: 0.85rem; color: var(--ink-soft); margin: 18px 0 0; overflow-wrap: anywhere; }
.crumbs a { color: var(--ink-soft); }
.page-head { margin: 8px 0 18px; padding-bottom: 14px; border-bottom: 2px solid var(--ink); }
.page-head .kicker { color: var(--accent); }
.prose { max-width: 72ch; }
.prose p, .prose li { overflow-wrap: break-word; }
.note { background: var(--card); border-left: 4px solid var(--accent); padding: 12px 14px; border-radius: 0 var(--radius) var(--radius) 0; }
.art-credit { font-size: 0.8rem; color: var(--ink-soft); margin-top: 28px; }

/* Shelves + cards */
.shelf h2 { margin-top: 32px; }
.game-shelf, .tool-grid { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 620px) { .game-shelf, .tool-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 940px) { .game-shelf { grid-template-columns: repeat(3, 1fr); } }
.game-card a, .tool-card a { display: flex; flex-direction: column; height: 100%; text-decoration: none; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); transition: transform 0.15s, border-color 0.15s; }
.game-card a:hover, .tool-card a:hover { transform: translateY(-2px); border-color: var(--accent); }
.game-card img { aspect-ratio: 460 / 215; object-fit: cover; width: 100%; border-bottom: 3px solid var(--accent); }
.game-card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 4px; }
.game-card strong, .tool-card strong { font: 600 1.15rem/1.25 var(--display); }
.game-card-body span, .tool-card span { color: var(--ink-soft); font-size: 0.93rem; }
.game-card .count { font: 700 0.75rem var(--mono); text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); margin-top: auto; }
.tool-card a { padding: 14px; gap: 6px; border-left: 4px solid var(--accent); }
.tag { align-self: flex-start; font: 700 0.7rem/1 var(--mono); text-transform: uppercase; letter-spacing: 0.1em; padding: 4px 7px; border-radius: 4px; background: var(--paper-2); color: var(--blue-2) !important; }
.tag-calculator { background: var(--blue); color: #f4ecd8 !important; }
.more-tools { margin-top: 36px; }

/* Calculator mount: the shared shell lanes render inside */
.calc { background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--accent); border-radius: var(--radius); padding: 16px; margin: 20px 0 28px; box-shadow: var(--shadow); max-width: 100%; overflow-x: auto; }
.calc label { display: block; font-weight: 600; font-size: 0.92rem; margin: 10px 0 4px; }
.calc input, .calc select, .calc button { font: inherit; font-size: 16px; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; max-width: 100%; }
.calc input[type="number"] { width: 7.5em; font-family: var(--mono); }
.calc button { background: var(--blue); color: #f4ecd8; border-color: var(--blue); font-weight: 700; cursor: pointer; }
@media (prefers-color-scheme: dark) { .calc button { color: #0f1c2b; } }
.calc .row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.calc .result { font: 700 1.6rem var(--mono); color: var(--good); }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; margin: 12px 0 20px; background: var(--card); }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font: 700 0.78rem var(--mono); text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); background: var(--paper-2); }
td.n, th.n { text-align: right; font-family: var(--mono); white-space: nowrap; }
tbody tr:nth-child(even) { background: color-mix(in srgb, var(--paper-2) 45%, transparent); }
.table-scroll { overflow-x: auto; max-width: 100%; }

/* Sources */
.sources { margin-top: 32px; padding: 14px 16px; border: 1px dashed var(--line); border-radius: var(--radius); font-size: 0.9rem; max-width: 72ch; }
.sources h2 { font-size: 1.05rem; margin: 0 0 4px; }
.sources ul { margin: 6px 0 0; padding-left: 18px; }
.sources li { overflow-wrap: anywhere; }

/* QA 2026-10-02: flex children in calc rows may shrink (long <select> labels overflowed at 412px),
   and on phones each calc table scrolls on its own instead of the whole calc card. */
.calc .row > * { min-width: 0; max-width: 100%; }
.calc select { width: 100%; }
.calc .row select { width: auto; }
@media (max-width: 600px) {
  .calc table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ---- Depth kit (2026-10-02): icons, figures, gallery, chain diagrams, TOC, FAQ, reference tables, hub icon strip.
   All colors come from the theme variables above, so light + dark both work. Lane contract: CONTRIBUTING.md. */
img.ico { display: inline-block; object-fit: contain; vertical-align: -0.4em; margin-right: 6px; max-width: none; }
img.ico-inline { vertical-align: middle; margin: 0 4px 0 0; }

/* Figures: any <figure> in content; .shot = framed screenshot card. */
.prose figure { margin: 20px 0; }
.prose figure img { width: 100%; height: auto; border-radius: 6px; border: 1px solid var(--line); }
figcaption { font-size: 0.88rem; color: var(--ink-soft); margin-top: 6px; line-height: 1.45; }
figure.shot { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; box-shadow: var(--shadow); }
figure.shot img { border: 0; border-radius: 6px; width: 100%; height: auto; }
figure.shot figcaption { margin: 6px 2px 0; }
.gallery { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); margin: 16px 0 24px; }
.gallery figure.shot { margin: 0; }
.gallery-wrap { margin-top: 32px; }

/* Chain diagrams (inline SVG from tools/lib/chain-diagram.mjs, same classes in the browser). */
.chain { margin: 20px 0 24px; max-width: 100%; }
.chain-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; box-shadow: var(--shadow); }
.chain-svg { display: block; max-width: none; height: auto; }
.chain-node rect { fill: var(--card); stroke: var(--line); stroke-width: 1.5; }
.chain-src rect { fill: var(--paper-2); }
.chain-end rect { stroke: var(--accent); stroke-width: 2; }
a.chain-node:hover rect, a.chain-node:focus rect { stroke: var(--accent); stroke-width: 2.5; }
.chain-label { font: 600 13px var(--sans); fill: var(--ink); }
.chain-note { font: 400 11px var(--mono); fill: var(--ink-soft); }
.chain-edge { fill: none; stroke: var(--ink-soft); stroke-width: 1.6; }
.chain-back { stroke-dasharray: 5 4; }
.chain-arrow { fill: var(--ink-soft); }
.chain-elabel rect { fill: var(--paper); stroke: var(--line); }
.chain-elabel text { font: 400 11px var(--mono); fill: var(--ink); }

/* Table of contents: collapsed card on phones, sticky side rail on wide screens (/js/toc.js opens it there). */
.toc { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 10px 14px; margin: 8px 0 18px; max-width: 72ch; }
.toc summary { cursor: pointer; font: 700 0.78rem/1.4 var(--mono); text-transform: uppercase; letter-spacing: 0.1em; color: var(--accent); }
.toc ol { margin: 8px 0 2px; padding-left: 20px; font-size: 0.93rem; }
.toc li { margin: 3px 0; }
@media (min-width: 1000px) {
  .has-toc { display: grid; grid-template-columns: minmax(0, 72ch) 230px; gap: 36px; align-items: start; }
  .has-toc .toc { order: 2; position: sticky; top: 16px; margin-top: 24px; max-height: calc(100vh - 32px); overflow-y: auto; }
}

/* FAQ blocks (<section class="faq"> with h3/p pairs also emit FAQPage JSON-LD). */
.faq h3 { margin-top: 1.1em; }

/* Hub icon strip ("featured" icons). */
.icon-strip-wrap { margin-top: 28px; }
.icon-strip { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); }
.icon-strip li { display: flex; min-width: 0; }
.icon-chip { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); text-decoration: none; font-weight: 600; font-size: 0.9rem; line-height: 1.25; }
a.icon-chip:hover { border-color: var(--accent); color: var(--ink); }
.icon-strip .ico-strip { margin: 0; flex: none; }

/* Reference tables (page kind "reference"; /js/ref-table.js adds sort + filter). */
.ref { margin: 16px 0 24px; }
.ref-tools { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; margin: 0 0 10px; font-size: 0.9rem; }
.ref-tools[hidden] { display: none; }
.ref-tools label { display: flex; flex-direction: column; gap: 3px; font-weight: 600; min-width: 0; max-width: 100%; }
.ref-tools input, .ref-tools select { font: inherit; font-size: 16px; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; max-width: 100%; }
.ref-count { font: 400 0.85rem var(--mono); color: var(--ink-soft); padding-bottom: 8px; }
.ref-table caption { caption-side: top; text-align: left; font-size: 0.88rem; color: var(--ink-soft); padding: 0 0 6px; }
.ref-sort { all: unset; cursor: pointer; display: inline-block; }
.ref-sort:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
th[aria-sort="ascending"] .ref-sort::after { content: " ▲"; }
th[aria-sort="descending"] .ref-sort::after { content: " ▼"; }
.ref-name { display: inline-flex; align-items: center; }
.ref-chip { display: inline-flex; align-items: center; gap: 2px; white-space: nowrap; margin: 0 8px 2px 0; }
.ref-chip .ico { margin-right: 3px; }
.ref-chip b { font: 700 0.85em var(--mono); }
.ref-empty { color: var(--ink-soft); }
.ref-table tr:target { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Reference pages (2026-10-03): many-column tables were cramped beside the TOC rail at ~1280px. When the article
   holds a reference table, the TOC stays a card ABOVE the content (no side rail) and the table uses the full
   content width; the hand-written text around it keeps its 72ch reading measure. Phones unchanged (.table-scroll). */
.prose:has(> .ref), .prose:has(> .chain) { max-width: none; }
.prose:has(> .ref) > :not(.ref):not(.chain), .prose:has(> .chain) > :not(.ref):not(.chain) { max-width: 72ch; }
@media (min-width: 1000px) {
  .has-toc:has(.ref), .has-toc:has(.prose > .chain) { display: block; }
  .has-toc:has(.ref) .toc, .has-toc:has(.prose > .chain) .toc { position: static; max-height: none; margin: 8px 0 18px; max-width: none; }
  .has-toc:has(.ref) .toc ol, .has-toc:has(.prose > .chain) .toc ol { columns: 3 220px; column-gap: 28px; }
  .has-toc:has(.ref) .toc li, .has-toc:has(.prose > .chain) .toc li { break-inside: avoid; }
}

/* Chain fit (2026-10-03): on wider screens a long chain shrinks to the column, but never below 72% of its drawn
   size (labels stay readable); past that it scrolls, with an edge fade that shows there is more to the right. */
@media (min-width: 700px) {
  .chain-svg { width: 100%; min-width: calc(var(--cw, 600) * 0.72px); max-width: calc(var(--cw, 600) * 1px); }
}
.chain-scroll {
  background:
    linear-gradient(to right, var(--card) 30%, transparent) left / 32px 100% no-repeat local,
    linear-gradient(to left, var(--card) 30%, transparent) right / 32px 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, rgba(0,0,0,.45), transparent) left / 14px 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,.45), transparent) right / 14px 100% no-repeat scroll,
    var(--card);
}
