/* Tokens, page layout, masthead, buttons.
   Colour follows the logic of Japanese landscape (景観) colour rules and station signage:
   large surfaces stay low-chroma (tile white, sign white, sumi ink); saturated colour —
   line colours, stamp red, exit-sign yellow — only ever covers small areas.
   Texture is manga screentone (halftone dots), always drawn in screen pixels. */
:root {
  color-scheme: light;
  --ground: #f5f1e7;
  --surface: #fffdf7;
  --ink: #1d2233;
  --ink-soft: #575d6b;
  --rule: #cdc9bc;
  --rail-off: #c9c8c2;
  --stamp: #c53d43;
  --signal: #f6c700; /* exit-sign yellow: keyboard focus only */
  --ok: #17693c;
  --warn: #8a5800;
  --ticket: #e4ece8;

  --font-body: "Signika", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --font-station: "BIZ UDPGothic", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", sans-serif;
  --font-display: "Dela Gothic One", "BIZ UDPGothic", "PingFang TC", sans-serif;
  --font-num: "Signika", system-ui, sans-serif;
  --font-dot: "DotGothic16", "Signika", monospace;

  /* screentone: a 45° dot lattice, 5px pitch */
  --tone-color: rgb(29 34 51 / 0.16);
  --tone:
    radial-gradient(circle, var(--tone-color) 0 0.85px, transparent 1.25px) 0 0 / 5px 5px,
    radial-gradient(circle, var(--tone-color) 0 0.85px, transparent 1.25px) 2.5px 2.5px / 5px 5px;

  --panel-w: 440px;
  --gutter: clamp(16px, 2.2vw, 28px);
  --ease-stamp: cubic-bezier(0.2, 0.9, 0.25, 1.25);
}

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

/* A class that sets display must never beat the hidden attribute. */
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  background: var(--ground);
  color: var(--ink);
  font: 400 1rem/1.6 var(--font-body);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

:lang(ja) body, body:lang(ja) { line-height: 1.7; }

[lang="ja"] { font-family: var(--font-station); }
/* In the Japanese UI, Latin-first text must not fall back to a Traditional Chinese face. */
:root:lang(ja) { --font-body: "Signika", "BIZ UDPGothic", "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif; }
:root:lang(ja) body { font-family: var(--font-station); }

p, h1, h2, h3 { text-wrap: pretty; }
:lang(ja) p { word-break: auto-phrase; line-break: strict; }

a { color: inherit; text-underline-offset: 0.18em; }

.defs { position: absolute; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--signal);
}

/* ---------- layout: map on the left, everything you touch on the right ---------- */
.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel-w);
  grid-template-rows: auto auto minmax(150px, 1fr) auto;
  grid-template-areas:
    "map head"
    "map console"
    "map lines"
    "map foot";
  height: 100dvh;
}

.masthead { grid-area: head; padding: 16px var(--gutter) 0; border-top: 6px solid var(--ink); }
.console { grid-area: console; padding: 14px var(--gutter) 0; }
.mapwrap { grid-area: map; }
.lines { grid-area: lines; overflow-y: auto; padding: 18px var(--gutter) 8px; }
.foot { grid-area: foot; padding: 10px var(--gutter) 16px; }

/* Phones: the map sits right above the answer field, so it stays in view while typing. */
@media (max-width: 900px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-template-areas: "head" "map" "console" "lines" "foot";
    height: auto;
  }
  .mapwrap { height: clamp(260px, 82vw, 46svh); margin-top: 10px; border-block: 1px solid var(--rule); }
  .lines { overflow: visible; }
  .console { display: flex; flex-direction: column; padding-top: 12px; }
  .console .answer { order: 1; margin-top: 0; }
  .console .scoreline { order: 2; }
  .console .board { order: 3; margin-top: 12px; }
  .title { font-size: clamp(1.6rem, 1.1rem + 3vw, 2.2rem); }
  :lang(ja) .title { font-size: clamp(1.45rem, 0.9rem + 3vw, 2.1rem); }
  .lede { font-size: 0.85rem; }
}

/* Wide screens: at least one screen tall. On short ones (a 1440×900 laptop) the panel needs a
   little more, so the grid grows rather than spilling onto the guide below it. The map and the
   line list only take the room that is left: contain: size keeps their content from sizing rows. */
@media (min-width: 901px) {
  .app { height: auto; min-height: 100dvh; }
  .mapwrap, .lines { contain: size; }
}

/* Once playing, the intro folds away so the board, map and line list get the room. */
.app.started .lede, .app.started .players, .app.started .linestrip { display: none; }


/* ---------- masthead ---------- */
.masthead { position: relative; isolation: isolate; }

/* Gradient screentone fading down from the top edge, like a manga panel's sky. */
.masthead::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 180px;
  z-index: -1;
  background: var(--tone);
  -webkit-mask-image: linear-gradient(to bottom, #000, transparent);
  mask-image: linear-gradient(to bottom, #000, transparent);
}

.langs { display: flex; justify-content: flex-end; margin: -36px 0 22px; font-size: 0.78rem; }
.langs a {
  padding: 3px 9px;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink-soft);
  text-decoration: none;
}
.langs a + a { border-left: 0; }
.langs a:first-child { border-radius: 2px 0 0 2px; }
.langs a:last-child { border-radius: 0 2px 2px 0; }
.langs a:hover { color: var(--ink); }
.langs a[aria-current] { background: var(--ink); border-color: var(--ink); color: var(--surface); font-weight: 700; }

/* About link and the updates notice share one row under the language switch. */
.masthead-tools { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 12px; }
.masthead-tools .updates { margin: 0 0 0 auto; }
.about-link { font-size: 0.78rem; font-weight: 700; color: var(--ink-soft); text-underline-offset: 3px; }
.about-link:hover { color: var(--ink); }

/* Game switcher: one button naming the current game and its kind; it opens a panel listing every
   game, grouped by kind, each with its station count. Closed, the links stay in the page for
   crawlers and players without JavaScript. styles/city-*.css still theme the current game. */
.switcher { position: relative; margin: 0 0 14px; }
.switcher > summary {
  display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 6px 12px 6px 14px;
  border: 1.5px solid var(--ink); border-radius: 4px; background: var(--surface); color: var(--ink);
  box-shadow: 3px 3px 0 rgb(29 34 51 / 0.12); cursor: pointer; list-style: none;
}
.switcher > summary::-webkit-details-marker { display: none; }
.switcher > summary:hover, .switcher[open] > summary { background: var(--ground); }
.switcher > summary:focus-visible { outline: 3px solid var(--signal); outline-offset: 2px; }
.switch-group { flex: none; padding: 1px 7px; border: 1px solid var(--rule); border-radius: 3px; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.06em; color: var(--ink-soft); }
.switch-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 700 1.02rem/1.2 var(--font-station); }
.switch-all { display: flex; flex: none; align-items: center; gap: 6px; margin-left: auto; font-size: 0.76rem; font-weight: 700; color: var(--ink-soft); }
.switch-count { min-width: 1.7em; padding: 1px 6px; border-radius: 999px; background: var(--ink); color: var(--surface); font: 700 0.7rem/1.4 var(--font-num); text-align: center; }
/* A game newer than this one is waiting in the panel (NEW_CITIES, marked by main.js). */
.switcher[data-has-new] .switch-all::before {
  content: "NEW"; padding: 1px 5px; border-radius: 3px;
  background: var(--stamp); color: #fff; font: 700 0.6rem/1.3 var(--font-num); letter-spacing: 0.05em;
}
.switch-chevron { transition: transform 0.15s; }
.switcher[open] .switch-chevron { transform: rotate(180deg); }
.switch-panel {
  position: absolute; z-index: 12; top: calc(100% + 6px); left: 0; right: 0;
  max-height: min(700px, calc(100dvh - 32px)); overflow-y: auto; overscroll-behavior: contain;
  padding: 12px 16px 18px; border: 1px solid var(--ink); border-top: 4px solid var(--ink);
  background: var(--surface); box-shadow: 5px 5px 0 rgb(29 34 51 / 0.14);
}
.masthead:has(.switcher[open]) { z-index: 50; }
.switch-head { display: flex; align-items: center; gap: 10px; }
.switch-title { margin: 0; font: 700 0.95rem var(--font-station); }
.switch-hint { margin: 0; font-size: 0.7rem; color: var(--ink-soft); }
.switch-close { flex: none; width: 36px; height: 36px; margin-left: auto; border: 1px solid var(--rule); border-radius: 50%; background: var(--surface); color: var(--ink); font-size: 0.85rem; cursor: pointer; }
.switch-close:hover { border-color: var(--ink); }
.switch-close:focus-visible { outline: 3px solid var(--signal); outline-offset: 2px; }
.cities { display: grid; gap: 4px; }
.city-group { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.city-group-label { grid-column: 1 / -1; margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--rule); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; color: var(--ink-soft); }
.cities a {
  display: flex; align-items: center; gap: 6px; min-height: 36px; padding: 3px 10px 3px 12px;
  border: 1.5px solid var(--ink); border-radius: 4px; background: var(--surface); color: var(--ink);
  font: 700 0.86rem/1.2 var(--font-station); text-decoration: none;
}
/* The station count, from the registry (scripts/build-pages.mjs fills data-total). */
.cities a::before { content: attr(data-total); order: 2; margin-left: auto; font: 600 0.72rem var(--font-num); color: var(--ink-soft); }
.cities a:hover { background: var(--ground); }
.cities a[aria-current] { background: var(--ink); color: var(--surface); }
.cities a[aria-current]::before { color: inherit; opacity: 0.75; }
/* The newest editions (NEW_CITIES in src/config.js). */
.cities a[data-new]::after {
  content: "NEW"; order: 1; padding: 1px 5px; border-radius: 3px;
  background: var(--stamp); color: #fff; font: 700 0.6rem/1.3 var(--font-num); letter-spacing: 0.05em;
}
.cities a:focus-visible { outline: 3px solid var(--signal); outline-offset: -1px; }
/* Stays while playing: a returning player (who has a save) must still be able to switch games. */
.app.started .switcher { margin-bottom: 10px; }

/* Phones: the panel is a sheet rising from the bottom over a dimmed page, two games a row. */
@media (max-width: 900px) {
  .switch-panel {
    position: fixed; z-index: 41; top: auto; bottom: 0;
    max-height: 86dvh; padding: 14px var(--gutter) calc(20px + env(safe-area-inset-bottom));
    border: 0; border-top: 4px solid var(--ink); border-radius: 14px 14px 0 0;
    box-shadow: 0 -10px 30px rgb(29 34 51 / 0.22);
  }
  /* Only while open: a closed <details> is not rendered, so an animation set there never ends. */
  .switcher[open] .switch-panel { animation: switch-sheet 0.2s ease-out; }
  .switcher[open]::before { content: ""; position: fixed; inset: 0; z-index: 40; background: rgb(29 34 51 / 0.42); }
  html:has(.switcher[open]) { overflow: hidden; }
  .city-group { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cities a { position: relative; min-height: 42px; }
  /* Narrow cells: NEW sits on the top edge like a stamp, so long English names keep their line. */
  .cities a[data-new]::after { position: absolute; top: -6px; right: 8px; }
}
@keyframes switch-sheet { from { transform: translateY(28px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .switcher[open] .switch-panel { animation: none; } }

.other-game {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 390px;
  min-height: 56px;
  margin: 0 0 16px;
  padding: 8px 12px;
  border: 1.5px solid #3b594c;
  border-radius: 3px;
  background: #f5f1e8;
  color: #254236;
  text-decoration: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.other-game:hover { transform: translateY(-2px); box-shadow: 3px 3px 0 #b7c6b1; }
.other-game:focus-visible { outline: 3px solid var(--signal); outline-offset: 3px; }
.other-game-seal {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 50%;
  background: #aa473a;
  color: #fff9ed;
  font: 700 1.1rem/1 var(--font-station);
}
.other-game-copy { display: grid; gap: 1px; }
.other-game-copy small { font: 600 0.68rem/1.2 var(--font-num); letter-spacing: 0.03em; }
.other-game-copy strong { font: 700 0.92rem/1.2 var(--font-station); }
.other-game-arrow { margin-left: auto; font-size: 1.25rem; }
/* The Paris game: navy enamel and Guimard-lamp amber, the colours of its station plaques. */
.other-game-paris { border-color: #1c2b5a; background: #f3f1ea; color: #1c2b5a; }
.other-game-paris:hover { box-shadow: 3px 3px 0 #c3c8d8; }
.other-game-paris .other-game-seal { background: #1c2b5a; color: #f0a73a; box-shadow: inset 0 0 0 2px #1c2b5a, inset 0 0 0 3px #f4f1e8;
  font: italic 700 1.3rem/1 "Bodoni 72", Didot, "Bodoni MT", Georgia, serif; } /* the Paris game's Didone */

.title {
  position: relative;
  isolation: isolate;
  margin: 0;
  font: 400 clamp(1.9rem, 1.3rem + 1.5vw, 2.6rem)/1.08 var(--font-display);
  letter-spacing: 0.03em;
  font-feature-settings: "palt";
  text-wrap: balance;
  word-break: auto-phrase; /* breaks 東京地下鉄｜チャレンジ, never チャレ｜ンジ */
}
/* Ten characters: sized to sit on one line in the side panel. */
:lang(ja) .title { font-size: clamp(1.55rem, 1.15rem + 1vw, 2.1rem); }

/* The title again, filled with red halftone and offset: a screentone drop shadow. */
.title::before {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  z-index: -1;
  transform: translate(0.09em, 0.1em);
  background:
    radial-gradient(circle, var(--stamp) 0 1px, transparent 1.4px) 0 0 / 5px 5px,
    radial-gradient(circle, var(--stamp) 0 1px, transparent 1.4px) 2.5px 2.5px / 5px 5px;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.lede { margin: 10px 0 0; max-width: 34em; color: var(--ink-soft); font-size: 0.92rem; }

.linestrip { display: flex; gap: 3px; height: 6px; margin-top: 14px; }
.linestrip span { flex: 1; background: var(--c); }

.players { margin: 8px 0 0; font-size: 0.82rem; color: var(--ink-soft); }
.players b { font-family: var(--font-num); color: var(--ink); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4em;
  min-height: 44px;
  padding: 0.5rem 1.05rem;
  border: 1.5px solid var(--ink);
  border-radius: 2px;
  background: var(--surface);
  color: var(--ink);
  font: 700 0.95rem/1.15 var(--font-body);
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  transition: transform 0.08s ease, background-color 0.15s ease;
}
:lang(ja) .btn { font-family: var(--font-station); }
.btn:hover { background: #f7f7f4; }
.btn:active { transform: translateY(1px); }
.btn-ink { background: var(--ink); color: var(--surface); }
.btn-ink:hover { background: #2d3450; }
.btn-quiet { border-color: var(--rule); font-weight: 600; min-height: 36px; padding: 0.35rem 0.8rem; }

/* ---------- footer ---------- */
.info-links { display: flex; flex-wrap: wrap; gap: 2px 18px; flex: 1 1 100%; font-size: .78rem; }
.info-links a { display: inline-flex; align-items: center; min-height: 36px; }
.foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; border-top: 1px solid var(--rule); }
.foot p { margin: 0; flex: 1 1 14em; font-size: 0.76rem; color: var(--ink-soft); }
/* The author's other game: a full-width card in the footer, after the game rather than before it. */
.other-game-foot { flex: 1 1 100%; max-width: none; margin: 4px 0 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Printed station-guide identity: solid signage paired with halftone paper. */
.edition { display: flex; align-items: center; gap: 9px; margin-bottom: 14px; padding-right: 150px; min-height: 42px; font: 700 0.56rem/1.3 var(--font-num); letter-spacing: 0.09em; }
.edition-code { display: grid; place-content: center; flex: none; width: 40px; height: 40px; border: 4px solid var(--stamp); border-radius: 50%; background: var(--surface); text-align: center; font: 700 0.8rem/0.95 var(--font-num); letter-spacing: 0; }
.edition-code span { font-size: 0.68rem; }
.maker { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; flex: 1 1 auto; font-size: 0.78rem; font-weight: 600; }
.maker a { display: inline-flex; align-items: center; gap: 5px; min-height: 32px; }
.maker-mark { display: grid; place-items: center; width: 22px; height: 22px; background: var(--ink); color: var(--surface); font-size: 1rem; }
.foot { border-top: 1px dashed var(--ink-soft); background: var(--surface); }
.app.started .edition { display: none; }
.app.started .langs { margin-top: 0; margin-bottom: 10px; }
@media (max-width: 360px) {
  .edition { padding-right: 140px; }
  .edition > span:nth-child(2) { font-size: 0.49rem; letter-spacing: 0; }
  .langs a { padding-inline: 7px; }
}

.maker .support-author { margin-left: auto; color: var(--stamp); }

/* A friend's score from a shared link: a small stamp-red note, the one thing to beat. */
.challenge {
  margin: 12px 0 0;
  padding: 8px 12px;
  border: 1.5px solid var(--stamp);
  border-radius: 2px;
  background: #fbf3f2;
  color: var(--stamp);
  font-weight: 700;
  font-size: 0.92rem;
}
:lang(ja) .challenge { font-family: var(--font-station); }

/* Streamers for a completed line or a full clear (motion.js confetti()). */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.confetti i { position: absolute; width: 8px; height: 4px; border-radius: 1px; }

/* Hanging straps on a handrail along the top of the page (straps.js; widths match its RAIL and
   SIZES: big straps by default, .is-small where only a small one fits). straps.js sets each band's
   length and its ring's top, since a small strap's band grows to pass down a narrow gap. Only the
   rings take the pointer; the rail and bands let clicks through. */
.straps { position: absolute; z-index: 20; top: 0; left: 0; width: 100%; height: 0; overflow-x: clip; pointer-events: none; }
.straps::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 8px; background: var(--ink); transition: opacity 0.3s; }
.straps.is-bare::before { opacity: 0; }
.strap { position: absolute; top: 4px; left: 0; width: 44px; margin-left: -22px; transform-origin: 50% 0; }
.strap::before { content: ""; position: absolute; top: -4px; left: 50%; width: 20px; height: 12px; margin-left: -10px; border-radius: 0 0 4px 4px; background: var(--ink); }
.strap-band { position: absolute; top: 0; left: 50%; width: 12px; margin-left: -6px; border-radius: 0 0 4px 4px; background: var(--ink-soft); transform-origin: 50% 0; }
.strap-ring { position: absolute; left: 0; width: 44px; height: 44px; color: var(--ink); pointer-events: auto; cursor: grab; touch-action: none; }
.strap.is-small { width: 28px; margin-left: -14px; }
.strap.is-small::before { width: 14px; height: 10px; margin-left: -7px; border-radius: 0 0 3px 3px; }
.strap.is-small .strap-band { width: 8px; margin-left: -4px; border-radius: 0 0 3px 3px; }
.strap.is-small .strap-ring { width: 28px; height: 28px; }
.strap.is-small .strap-ring::before { content: ""; position: absolute; inset: -4px; } /* as far as its clearance, no further */
.strap-ring svg { display: block; width: 100%; height: 100%; overflow: visible; }
/* The buckle where the band wraps the ring; it moves with the ring, so pulling never squashes it. */
.strap-ring::after { content: ""; position: absolute; top: -4px; left: 50%; width: 16px; height: 8px; margin-left: -8px; border-radius: 3px; background: var(--ink); }
.strap.is-small .strap-ring::after { top: -3px; width: 12px; height: 6px; margin-left: -6px; border-radius: 2px; }
.strap-ring:hover, .strap.is-held .strap-ring { color: var(--stamp); }
.strap.is-held .strap-ring { cursor: grabbing; }
