/* 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: #f1f0ec;
  --surface: #ffffff;
  --ink: #1d2233;
  --ink-soft: #575d6b;
  --rule: #cfcdc6;
  --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: 420px;
  --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(0, 1fr) auto;
  grid-template-areas:
    "map head"
    "map console"
    "map lines"
    "map foot";
  height: 100dvh;
}

.masthead { grid-area: head; padding: 14px var(--gutter) 0; }
.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; }
}

/* 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: 150px;
  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-bottom: 10px; 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; }

.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; height: 4px; 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 ---------- */
.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); }

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