/* Kings By Dawn website, new design: building, unit and guide pages (wiki/buildings|units|guides/<id>/).
   Shared parts (tokens, toy buttons, chrome, prose, tables, chips, callouts, badges) are in site.css.
   The pages keep the live Wiki markup (div.reader > div.sidebar + article.article + nav.toc); this sheet gives it the
   chosen home page's look ("Phone first"): the sea as page ground, white sheets with an Aegean header band and white
   Vollkorn SC titles outlined in Ink, toy cards and buttons with an Ink lip, numbers in Sofia Sans Condensed.
   wiki.js toggles: .sidebar.is-open + .sidebar-scrim (phones, below 921 px), .toc a.is-active, .table-frame
   .is-overflowing / .at-end, tr.is-target / .is-range (the level calculator). kbd.js adds .is-in to .stat-bars.
   Phones first (390 px), then 600, 700, 921 (Wiki navigation becomes a side panel) and 1240 (on-page contents). */

.page--wiki-article { padding-top: 14px; }

/* ---------- the reader: one column on phones; navigation panel + article (+ contents) on desktop ---------- */
.reader {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px; align-items: start;
  width: min(var(--wrap), calc(100% - 32px)); margin: 0 auto;
}
.article { min-width: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 10px; row-gap: 16px; align-items: center; }
.article > * { grid-column: 1 / -1; min-width: 0; }
.article > .sidebar-toggle { grid-column: 1; justify-self: start; }
.article > .breadcrumbs { grid-column: 2; }

/* "Browse the Wiki": a white toy button on the sea (48 px tall, the phone tap size) */
.article > .sidebar-toggle { min-height: 48px; padding: 0 12px; }
.sidebar-toggle { --focus: #FFFFFF; }
.sidebar-toggle svg { width: 20px; height: 20px; stroke-width: 2.6; }

/* breadcrumbs: a white name plate on the sea (the current page is the title just below, so phones show its parents).
   Each link fills the plate's height (47 px) and is at least 44 px wide; the link padding does the spacing. */
.article > .breadcrumbs {
  justify-self: start; flex-wrap: nowrap; gap: 0; max-width: 100%; min-height: 52px; margin: 0 0 4px; padding: 0 5px;
  background: var(--paper); color: var(--ink-3); border: 2.5px solid var(--ink); border-radius: var(--r-pill);
  box-shadow: var(--sh-chip); font: 800 14px/1.2 var(--font-label); --focus: #167D8C;
}
.article > .breadcrumbs li { flex: none; gap: 0; align-self: stretch; white-space: nowrap; }
.article > .breadcrumbs li:last-child { flex: 0 1 auto; min-width: 0; }
.article > .breadcrumbs li:last-child span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 9px 0 6px; color: var(--ink); }
.article > .breadcrumbs a {
  display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 47px; padding: 0 6px;
  border-radius: var(--r-pill); color: var(--link);
}
.article > .breadcrumbs a:focus-visible { outline-offset: -3px; }
.article > .breadcrumbs li + li::before { margin: 0 2px 0 0; border-color: var(--ink-3); }
/* very narrow phones: the 'Wiki' crumb repeats the 'Browse the Wiki' button beside it */
@media (max-width: 359px) {
  .article > .breadcrumbs li:first-child { display: none; }
  .article > .breadcrumbs li:nth-child(2)::before { display: none; }
}
@media (max-width: 599px) {
  .article > .breadcrumbs li:last-child { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

/* ---------- the article head: a white sheet with an Aegean header band, the art, the lead and the quick facts ---------- */
.article-head {
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr); align-items: start;
  background: var(--paper); color: var(--ink);
  border: 3px solid var(--ink); border-radius: var(--r-panel); box-shadow: var(--sh-float);
  overflow: hidden; --focus: #167D8C;
}
.article-head::before { content: ""; grid-column: 1 / -1; grid-row: 1 / 3; align-self: stretch; background: var(--aegean); border-bottom: 3px solid var(--ink); }
.article-head > div:not(.article-head__art) { display: contents; }
.article-head h1 {
  grid-column: 1 / -1; grid-row: 1; position: relative; margin: 0; padding: 14px 16px 4px;
  color: #fff; text-shadow: var(--ts-title); font: 900 clamp(30px, 8.6vw, 38px)/1.06 var(--font-display); letter-spacing: .01em;
  text-wrap: balance; overflow-wrap: break-word;
}
.head-badges { grid-column: 1 / -1; grid-row: 2; position: relative; display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 16px 16px; }
.head-badges .badge { height: 28px; padding: 0 12px; background: var(--paper); color: var(--ink); border-color: var(--ink); font-size: 13px; letter-spacing: .02em; }
.head-badges .badge--soon { background: var(--role-chip); }
.article-head .lead { grid-column: 1 / -1; grid-row: 4; max-width: none; padding: 16px 16px 0; color: var(--ink-2); font-size: 17px; line-height: 1.5; }
.article-head .lead:last-child { padding-bottom: 20px; }
.article-head > div > .quickfacts, .article-head > div > .unit-panel { grid-column: 1 / -1; grid-row: 5; margin: 14px 16px 18px; }

/* the art: the building on a grass plot (an island tile with soil sides), the unit portrait on a marble podium */
.article-head__art {
  grid-column: 1 / -1; grid-row: 3; position: relative; isolation: isolate;
  display: grid; place-items: end center; height: 248px; padding: 12px 16px 30px; overflow: hidden;
  background: var(--thumb-bg); border-bottom: 3px solid var(--ink);
}
.article-head__art::before, .article-head__art::after {
  content: ""; position: absolute; left: 50%; z-index: -1; width: min(300px, 84%); aspect-ratio: 2 / 1; transform: translateX(-50%);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}
.article-head__art::before { bottom: 6px; background: linear-gradient(90deg, #B9794B 50%, #93603D 50%); }
.article-head__art::after { bottom: 22px; background: var(--grass); box-shadow: inset 0 -4px 0 var(--grass-edge); }
.article-head__art img {
  position: relative; width: auto; max-width: min(250px, 72%); max-height: 100%; object-fit: contain;
  filter: drop-shadow(0 6px 0 rgba(22,46,112,.22));
}
.wiki-article--buildings .article-head__art img { margin-bottom: 4px; }

/* units: a round portrait on a two-step marble podium (objects keep their Ink outline) */
.wiki-article--units .article-head__art { place-items: center; padding: 14px 16px 44px; }
.wiki-article--units .article-head__art::before {
  bottom: 18px; width: 200px; height: 34px; aspect-ratio: auto; clip-path: none; border-radius: 10px;
  background: var(--marble); border: 2.5px solid var(--ink); box-shadow: inset 0 6px 0 var(--marble-lit), inset 0 -5px 0 var(--marble-shade);
}
.wiki-article--units .article-head__art::after {
  bottom: 6px; width: 240px; height: 18px; aspect-ratio: auto; clip-path: none; border-radius: 8px;
  background: var(--marble-shade); border: 2.5px solid var(--ink); box-shadow: none;
}
.wiki-article--units .article-head__art img { width: 176px; max-width: 176px; height: 176px; border-radius: 50%; filter: drop-shadow(0 5px 0 rgba(22,46,112,.24)); }

/* guides: the banner across the sheet under the band */
.article-head--guide > figure { grid-column: 1 / -1; grid-row: 3; margin: 0; }
.article-head__banner { aspect-ratio: 16 / 9; overflow: hidden; background: var(--sea); border-bottom: 3px solid var(--ink); }
.article-head__banner img { width: 100%; height: 100%; object-fit: cover; }
.article-head--guide figcaption { padding: 8px 16px 0; color: var(--ink-3); font: 600 12px/1.4 var(--font-label); }
.article-head--guide .lead { padding-top: 10px; }

/* quick facts and unit facts: read-only rows on a pale panel, the value on the right */
.quickfacts, .facts { padding: 2px 14px; background: var(--paper-2); border-radius: var(--r-card); }
.quickfacts > div, .facts > div { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 14px; min-height: 42px; padding: 8px 0; }
.quickfacts > div + div, .facts > div + div { border-top: 1.5px dashed var(--paper-line); }
.quickfacts dt, .facts dt { color: var(--ink-2); font: 700 14px/1.35 var(--font-label); }
.quickfacts dd, .facts dd { margin-left: auto; text-align: right; color: var(--ink); font: 800 15px/1.4 var(--font-label); }
.quickfacts .res-list { justify-content: flex-end; gap: 4px 12px; }
.quickfacts .res, .facts .res { font-size: 16px; }
.article .res { vertical-align: middle; }
.facts { margin: 16px 0; }

/* unit stat bars: Health olive, Armor lagoon, Damage gold; the value on a white pill */
.unit-panel { display: grid; gap: 12px; }
.unit-panel .quickfacts { margin: 0; }
.stat-bars { display: grid; gap: 10px; padding: 12px 14px; background: var(--paper-2); border-radius: var(--r-card); }
.stat-bar { display: grid; grid-template-columns: 68px minmax(0, 1fr); align-items: center; gap: 10px; }
.stat-bar dt { color: var(--ink); font: 800 14px/1.2 var(--font-label); }
.stat-bar dd { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; margin: 0; }
.stat-bar .track { display: block; height: 20px; overflow: hidden; background: var(--track); border: 2px solid var(--ink); border-radius: 10px; }
.stat-bar .fill {
  display: block; height: 100%; width: max(10px, calc(var(--v, 0) * 100%)); background: var(--c, var(--olive));
  border-right: 2px solid var(--ink); box-shadow: inset 0 4px 0 rgba(255,255,255,.35); transform-origin: 0 50%;
}
/* the bars fill once when kbd.js marks them seen (.is-in); without the script they simply show full */
@keyframes wiki-bar-fill { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.stat-bars.is-in .fill { animation: wiki-bar-fill .6s ease-out both; }
.stat-bar .val {
  min-width: 52px; padding: 3px 10px; text-align: center; background: var(--paper); border: 2px solid var(--ink); border-radius: var(--r-pill);
  font: 800 16px/1.1 var(--font-num); font-variant-numeric: tabular-nums lining-nums;
}
/* one shared set of columns for the panel (label | track | value), so the three tracks are the same length even when one
   value needs a wider pill ("3,000"); without subgrid the value pills simply share a width wide enough for 5 characters */
.stat-bar .val { min-width: 64px; }
@supports (grid-template-columns: subgrid) {
  .stat-bars { grid-template-columns: 68px minmax(0, 1fr) auto; column-gap: 10px; }
  .stat-bar { grid-column: 1 / -1; grid-template-columns: subgrid; }
  .stat-bar dd { grid-column: 2 / -1; grid-template-columns: subgrid; }
  .stat-bar .val { min-width: 52px; }
}
.stat-bar--hp { --c: var(--olive); }
.stat-bar--armor { --c: var(--lagoon); }
.stat-bar--damage { --c: var(--gold); }

/* ---------- "On this page" (phones, tablets, and unit pages): a white panel that opens ---------- */
.mobile-toc {
  background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: var(--r-panel);
  box-shadow: var(--sh-float); overflow: hidden; --focus: #167D8C;
}
.mobile-toc > summary {
  display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 8px 14px 8px 10px;
  cursor: pointer; list-style: none; font: 900 21px/1.1 var(--font-display); letter-spacing: .01em;
}
.mobile-toc > summary::-webkit-details-marker { display: none; }
.mobile-toc > summary::before {
  content: ""; width: 40px; height: 40px; flex: none; border: 2px solid var(--ink); border-radius: var(--r-thumb);
  background: var(--thumb-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23143F8F' stroke-width='2.6' stroke-linecap='round'%3E%3Cpath d='M9 6.5h11M9 12h11M9 17.5h11'/%3E%3Ccircle cx='4.5' cy='6.5' r='.6' fill='%23143F8F'/%3E%3Ccircle cx='4.5' cy='12' r='.6' fill='%23143F8F'/%3E%3Ccircle cx='4.5' cy='17.5' r='.6' fill='%23143F8F'/%3E%3C/svg%3E") center / 24px no-repeat;
}
.mobile-toc > summary::after {
  content: ""; width: 32px; height: 32px; margin-left: auto; flex: none; border: 2.5px solid var(--ink); border-radius: 50%;
  background: var(--paper) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23143F8F' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9.5l6 6 6-6'/%3E%3C/svg%3E") center / 18px no-repeat;
  box-shadow: 0 2px 0 var(--ink); transition: transform .12s ease;
}
.mobile-toc[open] > summary { border-bottom: 1.5px dashed var(--paper-line); }
.mobile-toc[open] > summary::after { transform: rotate(180deg); box-shadow: 0 -2px 0 var(--ink); }
.mobile-toc ol { padding: 4px 14px 10px; counter-reset: toc; }
.mobile-toc li { counter-increment: toc; }
.mobile-toc li + li a { border-top: 1.5px dashed var(--paper-line); }
.mobile-toc a { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 6px 2px; color: var(--ink); text-decoration: none; font: 800 16px/1.25 var(--font-label); }
.mobile-toc a::before {
  content: counter(toc); display: grid; place-items: center; min-width: 26px; height: 26px; padding: 0 6px; flex: none;
  background: var(--paper); color: var(--aegean-shade); border: 2px solid var(--ink); border-radius: var(--r-pill); box-shadow: inset 0 -3px 0 var(--paper-line);
  font: 800 14px/1 var(--font-num); font-variant-numeric: tabular-nums lining-nums;
}
@media (hover: hover) { .mobile-toc a:hover { color: var(--aegean-shade); text-decoration: underline; text-underline-offset: 3px; } .mobile-toc > summary:hover { background: #F7FAFD; } }

/* ---------- the article body: each section is its own white sheet on the sea, titled on an Aegean band ---------- */
.article > .prose { display: flex; flex-direction: column; gap: 18px; }
.article > .prose > * { margin: 0; }
.prose > section {
  min-width: 0; padding: 0 16px 20px; background: var(--paper); color: var(--ink);
  border: 3px solid var(--ink); border-radius: var(--r-panel); box-shadow: var(--sh-float); --focus: #167D8C;
}
.prose > section > h2 {
  display: flex; align-items: center; gap: 10px; min-height: 60px; margin: 0 -16px 16px; padding: 10px 16px 12px;
  background: var(--aegean); border-bottom: 3px solid var(--ink); border-radius: 19px 19px 0 0;
  color: #fff; text-shadow: var(--ts-title); font: 900 24px/1.1 var(--font-display); letter-spacing: .01em; text-wrap: balance;
}
.prose > section > h2 a.anchor { color: var(--on-head-2); text-shadow: none; font: 800 15px/1 var(--font-num); text-decoration: none; }
.prose > section > h2 a.anchor:focus-visible { opacity: 1; outline-color: #fff; }
.prose > section > :last-child { margin-bottom: 0; }
.prose h3 { font: 900 20px/1.15 var(--font-display); letter-spacing: .01em; }
.prose p.note svg { display: inline-block; width: 18px; height: 18px; margin: 0 6px 0 0; vertical-align: -3px; color: var(--aegean-shade); stroke-width: 2.2; }
.prose .callout { margin-top: 0; }
.prose > section > .callout + p { margin-top: 16px; }

/* ---------- the level calculator: two sliders with gold thumbs (the active control), the levels and totals in white ---------- */
.calc {
  margin: 18px 0 18px; padding: 14px 14px 16px; background: var(--paper-2); border: 2px solid var(--paper-line); border-radius: var(--r-card);
}
.calc__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 14px; margin-bottom: 8px; }
.prose .calc__head h3 { margin: 0; font: 900 22px/1.1 var(--font-display); }
.res-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--ink-2); font: 700 13px/1.2 var(--font-label); }
.res-legend .res { font-family: var(--font-label); font-weight: 700; }
.res-legend .res + .res { margin-left: 0; }
.res-legend .res img { width: 18px; height: 18px; }
.calc__controls { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px 20px; }
.calc label { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--ink-2); font: 800 15px/1.2 var(--font-label); }
.calc label output {
  display: inline-grid; place-items: center; min-width: 38px; height: 28px; padding: 0 8px; flex: none;
  background: var(--paper); color: var(--ink); border: 2px solid var(--ink); border-radius: var(--r-pill); box-shadow: inset 0 -3px 0 var(--paper-line);
  font: 800 16px/1 var(--font-num); font-variant-numeric: tabular-nums lining-nums;
}
.calc input[type="range"] {
  display: block; width: 100%; height: 44px; margin: 0; background: transparent; cursor: pointer; -webkit-appearance: none; appearance: none;
}
.calc input[type="range"]::-webkit-slider-runnable-track { height: 14px; border-radius: 7px; background: var(--track); border: 2px solid var(--ink); }
.calc input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 30px; height: 30px; margin-top: -10px; border-radius: 50%;
  background: linear-gradient(180deg, var(--gold-lit), var(--gold)); border: 3px solid var(--ink); box-shadow: inset 0 -3px 0 rgba(217,144,26,.6), 0 3px 0 var(--ink);
}
.calc input[type="range"]::-moz-range-track { height: 10px; border-radius: 7px; background: var(--track); border: 2px solid var(--ink); }
.calc input[type="range"]::-moz-range-thumb { width: 24px; height: 24px; border-radius: 50%; background: var(--gold); border: 3px solid var(--ink); box-shadow: 0 3px 0 var(--ink); }
.calc input[type="range"]:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 8px; }
.calc__result { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.calc__result > div { min-width: 0; padding: 9px 12px 10px; background: var(--paper); border: 2px solid var(--paper-line); border-radius: var(--r-card); }
.calc__result > div:first-child, .calc__result > div:last-child { grid-column: 1 / -1; }
.calc__result dt { color: var(--ink-3); font: 800 12px/1.2 var(--font-label); letter-spacing: .04em; text-transform: uppercase; }
.calc__result dd { margin-top: 3px; color: var(--ink); font: 800 16px/1.35 var(--font-label); overflow-wrap: break-word; }
.calc__result dd[data-calc-time] { color: var(--aegean-shade); font: 800 20px/1.2 var(--font-num); font-variant-numeric: tabular-nums lining-nums; }
.calc__result .res-list { gap: 4px 14px; }
.calc__result .res { font-size: 17px; }
.prose .calc__note { margin-top: 10px; color: var(--ink-3); font: 600 13px/1.45 var(--font-label); }

/* ---------- tables: they scroll sideways inside their own frame; a fade and a hint say there is more ----------
   Every row shows in the page (no height limit, so a long table never looks complete while rows hide inside it). */
.table-frame { position: relative; margin: 18px 0; }
.table-frame .table-wrap { margin: 0; max-height: none; }
.table-frame .data-table caption { text-transform: none; }
.table-more { display: none; height: 20px; margin: 6px 2px 0; color: var(--ink-3); font: 700 13px/20px var(--font-label); text-align: right; }
.table-frame.is-overflowing .table-more { display: block; }
.table-frame.is-overflowing::after {
  content: ""; position: absolute; top: 3px; right: 3px; bottom: 29px; width: 30px; border-radius: 0 9px 9px 0; pointer-events: none;
  background: linear-gradient(270deg, rgba(255,255,255,.96), rgba(255,255,255,0)); transition: opacity .2s ease;
}
.table-frame.is-overflowing.at-end::after { opacity: 0; }
.data-table .res img { width: 18px; height: 18px; }
.data-table tr[data-errata] > th:first-child { box-shadow: inset 4px 0 0 var(--lagoon), 2px 0 0 var(--paper-line); }
.upd-mark {
  display: inline-block; width: 12px; height: 12px; margin-left: 6px; vertical-align: -1px;
  background: var(--lagoon); border: 2px solid var(--ink); border-radius: 50%;
}
/* the calculator's levels: a cool whitewash for the levels in the range (striped like the rest), gold only for the target */
.data-table tr.is-range, .data-table tr.is-range th { background: #E3EEFB !important; }
.data-table tbody tr.is-range:nth-child(2n), .data-table tbody tr.is-range:nth-child(2n) th { background: #D8E7F8 !important; }
@media (hover: hover) { .data-table tbody tr.is-range:hover, .data-table tbody tr.is-range:hover th { background: #CDE0F6 !important; } }
@media (max-width: 759px) {
  .table-frame .data-table th, .table-frame .data-table td { padding: 8px 10px; }
  .table-frame .data-table thead th { white-space: normal; min-width: 4.5rem; vertical-align: bottom; }
  /* the row names (the first column, which stays put) wrap and take at most about 40% of the frame, so the columns
     beside them always have room; the other cells stay one line high and the table scrolls sideways in its frame */
  .table-frame .data-table tbody th { white-space: normal; max-width: 40vw; overflow-wrap: break-word; }
  .table-frame .data-table thead th:first-child { max-width: 40vw; }
  .table-frame .data-table td:not(.wide) { min-width: 0; white-space: nowrap; }
  .table-frame .data-table td .res { margin-right: 6px; }
}

/* ---------- related pages: toy link rows (thumbnail, name, kind, chevron) ---------- */
.related { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px 12px; margin: 16px 0 4px; }
.prose .related a {
  position: relative; display: flex; align-items: center; gap: 12px; min-height: 62px; padding: 7px 40px 7px 7px; margin-bottom: 4px;
  background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: var(--r-btn);
  box-shadow: inset 0 -4px 0 var(--paper-line), 0 4px 0 var(--ink);
  text-decoration: none; font: 800 16px/1.2 var(--font-label); transition: transform .08s ease, box-shadow .08s ease;
}
.prose .related a::after {
  content: ""; position: absolute; right: 16px; top: 50%; width: 9px; height: 9px; margin-top: -6px;
  border-top: 3px solid var(--aegean-shade); border-right: 3px solid var(--aegean-shade); transform: rotate(45deg);
}
.related img { width: 44px; height: 44px; flex: none; padding: 3px; object-fit: contain; background: var(--paper-2); border-radius: 10px; }
.related img[src*="/units/"] { padding: 0; background: none; border-radius: 50%; }
.related img[src*="/guides/"] { padding: 0; object-fit: cover; border: 2px solid var(--ink); }
.related a > span { min-width: 0; }
.related small { display: block; margin-top: 3px; color: var(--ink-3); font: 800 12px/1.2 var(--font-label); letter-spacing: .04em; text-transform: uppercase; }
.prose .related a:active { transform: translateY(3px); box-shadow: inset 0 -2px 0 var(--paper-line), 0 1px 0 var(--ink); }
@media (hover: hover) { .prose .related a:hover { background: #F7FAFD; color: var(--ink); } }

/* ---------- on the sea after the sections: the Army Planner callout, previous / next, the rules note ---------- */
.prose > .callout { box-shadow: var(--sh-float); --focus: #167D8C; }
.pager { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 4px; }
.pager a {
  display: flex; flex-direction: column; justify-content: center; gap: 3px; min-height: 68px; min-width: 0; padding: 8px 14px; margin-bottom: 4px;
  background: linear-gradient(180deg, #FFFFFF, #E3EEF9); color: var(--ink); border: 3px solid var(--ink); border-radius: var(--r-btn);
  box-shadow: inset 0 3px 0 var(--highlight), inset 0 -4px 0 var(--paper-line), 0 4px 0 var(--ink);
  text-decoration: none; transition: transform .08s ease, box-shadow .08s ease;
}
.pager a.prev { grid-column: 1; }
.pager a.next {
  grid-column: 2; align-items: stretch; text-align: right; /* stretch: a long title wraps inside the card */
  background: linear-gradient(180deg, #FFE48A, var(--gold-deep)); box-shadow: inset 0 3px 0 var(--highlight), inset 0 -4px 0 rgba(217,144,26,.55), 0 4px 0 var(--ink);
}
.pager small { color: var(--ink-2); font: 800 13px/1.2 var(--font-label); white-space: nowrap; }
.pager a.next small { color: var(--ink); }
.pager strong { font: 900 19px/1.12 var(--font-display); letter-spacing: .01em; overflow-wrap: break-word; }
.pager a:active { transform: translateY(3px); box-shadow: inset 0 3px 0 var(--highlight), inset 0 -2px 0 var(--paper-line), 0 1px 0 var(--ink); }
/* phones up to 429 px (412 px is a common Android width): one card per row, so long Vollkorn titles fit */
@media (max-width: 429px) { .pager { grid-template-columns: minmax(0, 1fr); } .pager a.next { grid-column: 1; } }
@media (hover: hover) { .pager a.prev:hover { background: linear-gradient(180deg, #FFFFFF, #D9E7F6); } .pager a.next:hover { background: linear-gradient(180deg, #FFEDA6, var(--gold-deep)); } }

.prose > .edition {
  position: relative; padding: 11px 14px 12px 50px; background: var(--paper); color: var(--ink-2);
  border: 2.5px solid var(--ink); border-radius: var(--r-card); box-shadow: var(--sh-chip); font: 600 14px/1.5 var(--font-label);
}
.prose > .edition::before {
  content: ""; position: absolute; left: 12px; top: 11px; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--ink);
  background: var(--lagoon) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.4' stroke-linecap='round'%3E%3Cpath d='M12 11v7'/%3E%3Cpath d='M12 6.5v.5'/%3E%3C/svg%3E") center / 16px no-repeat;
}
.edition strong { color: var(--ink); }

/* ---------- Wiki navigation: a bottom sheet on phones (opened by "Browse the Wiki"), a white side panel on desktop ---------- */
.sidebar { display: none; background: var(--paper); color: var(--ink); --focus: #167D8C; }
.sidebar > nav { padding-bottom: 12px; }
.sidebar-close {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 64px; padding: 10px 12px 10px 16px; background: var(--aegean); border-bottom: 3px solid var(--ink);
}
.sidebar-close > span { padding: 2px 2px 4px; color: #fff; text-shadow: var(--ts-title); font: 900 23px/1.05 var(--font-display); letter-spacing: .01em; }
.sidebar-close .icon-btn { --focus: #FFFFFF; }
.sidebar-top { display: grid; gap: 2px; padding: 12px 12px 10px; }
.sidebar-top a, .sidebar li a {
  display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 4px 10px 4px 4px;
  border: 2px solid transparent; border-radius: 12px; color: var(--ink); text-decoration: none; font: 800 15px/1.2 var(--font-label);
}
.sidebar-top svg {
  width: 34px; height: 34px; padding: 6px; flex: none; background: var(--thumb-bg); color: var(--aegean-shade);
  border: 2px solid var(--ink); border-radius: 10px; stroke-width: 2.2;
}
.sidebar details { margin: 0 12px; border-top: 1.5px dashed var(--paper-line); }
.sidebar summary {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 52px; padding: 4px 4px 4px 6px;
  cursor: pointer; list-style: none; color: var(--ink); font: 900 20px/1.1 var(--font-display); letter-spacing: .01em; border-radius: 12px;
}
.sidebar summary::-webkit-details-marker { display: none; }
.sidebar summary::after {
  content: ""; width: 30px; height: 30px; flex: none; border: 2.5px solid var(--ink); border-radius: 50%; box-shadow: 0 2px 0 var(--ink);
  background: var(--paper) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23143F8F' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9.5l6 6 6-6'/%3E%3C/svg%3E") center / 17px no-repeat;
  transition: transform .12s ease;
}
.sidebar details[open] > summary::after { transform: rotate(180deg); box-shadow: 0 -2px 0 var(--ink); }
.sidebar .sidebar__group { margin: 6px 6px 4px; color: var(--ink-3); font: 800 12px/1.2 var(--font-label); letter-spacing: .06em; text-transform: uppercase; }
.sidebar ul { display: grid; gap: 2px; padding-bottom: 8px; }
.sidebar li a { color: var(--ink-2); font-weight: 700; }
.sidebar li a img { width: 34px; height: 34px; flex: none; object-fit: contain; }
.sidebar li a:not(:has(img)) { padding-left: 12px; }
.sidebar li a:not(:has(img))::before { content: ""; width: 10px; height: 10px; flex: none; margin-right: 4px; border-radius: 50%; background: var(--aegean); border: 2px solid var(--ink); }
.sidebar li a[aria-current="page"], .sidebar-top a[aria-current="page"] {
  background: linear-gradient(180deg, var(--gold-lit), var(--gold)); border-color: var(--ink); color: var(--ink); font-weight: 800;
  box-shadow: inset 0 -3px 0 rgba(217,144,26,.6);
}
@media (hover: hover) {
  .sidebar-top a:hover, .sidebar li a:not([aria-current]):hover { background: var(--paper-2); color: var(--ink); }
  .sidebar summary:hover { background: #F7FAFD; }
}

@keyframes wiki-sheet-rise { 0% { transform: translateY(24px); } 70% { transform: translateY(-4px); } 100% { transform: translateY(0); } }
@keyframes wiki-scrim-in { from { opacity: 0; } to { opacity: 1; } }
@media (max-width: 920px) {
  .sidebar.is-open {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
    width: min(100%, 560px); max-height: calc(100% - 40px); margin: 0 auto; overflow-y: auto; overscroll-behavior: contain;
    border: 3px solid var(--ink); border-bottom: 0; border-radius: 26px 26px 0 0; box-shadow: 0 -6px 0 rgba(22,46,112,.25), var(--sh-float);
    padding-bottom: env(safe-area-inset-bottom); animation: wiki-sheet-rise .22s ease-out;
  }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 65; background: rgba(20,63,143,.5); animation: wiki-scrim-in .16s ease-out; }
}

/* ---------- on-page contents on wide screens ---------- */
.reader > .toc { display: none; }

/* ---------- tablets ---------- */
@media (min-width: 600px) {
  .page--wiki-article { padding-top: 20px; }
  .prose > section { padding: 0 24px 26px; }
  .prose > section > h2 { margin: 0 -24px 20px; padding: 12px 22px 14px; font-size: 27px; }
  .article-head h1 { padding: 18px 22px 4px; font-size: 40px; }
  .head-badges { padding: 6px 22px 18px; }
  .article-head .lead { padding: 18px 22px 0; }
  .article-head > div > .quickfacts, .article-head > div > .unit-panel { margin: 16px 22px 22px; }
  .article-head--guide figcaption { padding: 8px 22px 0; }
  .related { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .calc { padding: 16px 18px 18px; }
  .calc__controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .calc__result > div:first-child, .calc__result > div:last-child { grid-column: auto; }
  .pager strong { font-size: 22px; }
}

/* ---------- wider: the art beside the facts ---------- */
@media (min-width: 700px) {
  .article-head:not(.article-head--guide) { grid-template-columns: minmax(250px, 37%) minmax(0, 1fr); grid-template-rows: auto auto auto auto 1fr; }
  .article-head:not(.article-head--guide) .article-head__art {
    grid-column: 1; grid-row: 3 / 6; align-self: stretch; place-items: center; height: auto; min-height: 320px; padding: 0 12px;
    border-bottom: 0; border-right: 3px solid var(--ink);
  }
  .article-head:not(.article-head--guide) .lead { grid-column: 2; grid-row: 3; }
  .article-head:not(.article-head--guide) > div > .quickfacts, .article-head:not(.article-head--guide) > div > .unit-panel { grid-column: 2; grid-row: 4; }
  /* the art is centred (raised 14 px so the art and its plot sit in the middle together) with a fixed height; the
     plot is wider than the building's footprint and is placed by its own bottom tip (translate -100%), 12 px below
     the art's base, with the soil 16 px lower: a rim of grass all round and soil sides, as on phones */
  .wiki-article--buildings .article-head__art img {
    top: -14px; height: 170px; width: auto; max-width: 84%; margin: 0; object-fit: contain; object-position: 50% 100%;
  }
  .wiki-article--buildings .article-head__art::before, .wiki-article--buildings .article-head__art::after {
    width: min(256px, 96%); bottom: auto; transform: translate(-50%, -100%);
  }
  .wiki-article--buildings .article-head__art::after { top: calc(50% - 14px + 85px + 12px); }
  .wiki-article--buildings .article-head__art::before { top: calc(50% - 14px + 85px + 28px); }
  .wiki-article--units .article-head__art img { width: 196px; max-width: 196px; height: 196px; margin: -40px 0 0; }
  .wiki-article--units .article-head__art::before { bottom: auto; top: calc(50% + 46px); width: 196px; }
  .wiki-article--units .article-head__art::after { bottom: auto; top: calc(50% + 76px); width: 232px; }
  .article-head__banner { aspect-ratio: 2 / 1; }
  .facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 28px; }
  .facts > div:nth-child(2) { border-top: 0; }
}

/* ---------- desktop: the Wiki navigation as a panel beside the article ---------- */
@media (min-width: 921px) {
  .page--wiki-article { padding-top: 26px; }
  .reader { grid-template-columns: 252px minmax(0, 1fr); gap: 26px; }
  .article > .sidebar-toggle { display: none; }
  .article > .breadcrumbs { grid-column: 1 / -1; }
  .sidebar {
    display: block; position: sticky; top: calc(var(--topbar-h) + 3px + 22px); max-height: calc(100vh - var(--topbar-h) - 3px - 44px);
    overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--paper-line) transparent;
    border: 3px solid var(--ink); border-radius: var(--r-panel); box-shadow: var(--sh-float);
  }
  .sidebar-close { min-height: 58px; padding: 10px 16px; }
  .sidebar-close > span { font-size: 18px; }
  .sidebar-close .icon-btn { display: none; }
  .sidebar-top a, .sidebar li a { min-height: 40px; font-size: 14.5px; }
  .sidebar li a img { width: 30px; height: 30px; }
  .sidebar-top svg { width: 30px; height: 30px; padding: 5px; }
  .sidebar summary { min-height: 48px; font-size: 19px; }
  .article { row-gap: 20px; }
  .article > .prose { gap: 22px; }
  .article-head h1 { font-size: 44px; padding: 20px 26px 4px; }
  .head-badges { padding: 6px 26px 20px; }
  .article-head .lead { padding: 22px 26px 0; }
  .article-head > div > .quickfacts, .article-head > div > .unit-panel { margin: 16px 26px 26px; }
  .article-head--guide .lead { padding-top: 12px; }
  .article-head--guide figcaption { padding: 8px 26px 0; }
  .prose > section { padding: 0 28px 30px; }
  .prose > section > h2 { margin: 0 -28px 22px; padding: 14px 26px 16px; min-height: 72px; font-size: 30px; }
  .prose > section > h2, .prose > section { scroll-margin-top: calc(var(--topbar-h) + 20px); }
}

/* ---------- wide desktop: on-page contents on the right (buildings and guides; unit pages keep the panel above) ---------- */
@media (min-width: 1240px) {
  .reader:not(.reader--wide) { grid-template-columns: 236px minmax(0, 1fr) 200px; gap: 24px; }
  .reader:not(.reader--wide) .mobile-toc { display: none; }
  .reader:not(.reader--wide) > .toc {
    display: block; position: sticky; top: calc(var(--topbar-h) + 3px + 22px); max-height: calc(100vh - var(--topbar-h) - 3px - 44px); overflow-y: auto;
    padding: 0 0 12px; background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: var(--r-panel);
    box-shadow: var(--sh-float); scrollbar-width: thin; scrollbar-color: var(--paper-line) transparent; --focus: #167D8C;
  }
  .toc > p {
    margin: 0 0 8px; padding: 12px 14px 14px; background: var(--aegean); border-bottom: 3px solid var(--ink);
    color: #fff; text-shadow: var(--ts-title); font: 900 20px/1.1 var(--font-display); letter-spacing: .01em; text-transform: none;
  }
  .toc ol { padding: 0 8px; }
  .toc a { padding: 8px 10px; font: 700 14px/1.3 var(--font-label); }
  .toc a.is-active { font-weight: 800; }
  .toc .toc-extra { display: grid; gap: 2px; margin: 10px 8px 0; padding-top: 8px; border-top: 1.5px dashed var(--paper-line); }
  .toc .toc-extra a { display: flex; align-items: center; gap: 8px; border-left: 0; color: var(--link); font-weight: 800; }
  .toc .toc-extra svg { width: 18px; height: 18px; stroke-width: 2.4; }
}

/* ---------- print: plain pages without the navigation ---------- */
@media print {
  .sidebar, .sidebar-toggle, .toc, .mobile-toc, .pager { display: none !important; }
  .reader { display: block; width: auto; }
  .article-head, .prose > section { box-shadow: none; }
}
