/* The Jade Road — styles. Three painted themes: silk (default), dusk, night. */

/* The display font is Noto Serif JP (SIL OFL 1.1, see fonts/OFL.txt), served from this site
   cut down to Latin text and the game's own glyphs: about 40 KB per weight. Google's copy
   loads ~950 KB of slices for the map's seal glyphs alone; it is still used for Japanese and
   Chinese text (main.js adds it for those languages), and falls in after "Jade Serif". */
@font-face {
  font-family: "Jade Serif";
  src: url("../fonts/jade-serif-500.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0020-007E, U+00A0-00FF, U+2010, U+2013-2014, U+2018-201A, U+201C-201E, U+2020, U+2022, U+2026, U+2039-203A, U+20AC, U+2116, U+2122, U+2192, U+2212, U+4E09, U+4E2D, U+4F53, U+4F7F, U+5178, U+51A0, U+5203, U+523B, U+5317, U+53F0, U+57CE, U+57F7, U+5830, U+5929, U+5B66, U+5B88, U+5BAE, U+5CF0, U+5E02, U+5E2B, U+5E33, U+5EA7, U+63DB, U+6587, U+65D7, U+65E5, U+661F, U+66F8, U+6708, U+672C, U+6749, U+677E, U+67F3, U+68AF, U+6A4B, U+6BB5, U+6CB3, U+6D25, U+6E21, U+6F6E, U+706F-7070, U+708E, U+70AD, U+7389, U+738B, U+73BB, U+76E4, U+773C, U+7802, U+7B46, U+7D19, U+7D79, U+7E54, U+821F, U+82D1, U+8466, U+885B, U+8A9E, U+8CFD, U+9234, U+92AD, U+93E1, U+9418, U+9470, U+9580, U+96A0, U+96BC, U+96EA, U+96F2, U+971E, U+98A8, U+9DB4, U+9F13;
}
@font-face {
  font-family: "Jade Serif";
  src: url("../fonts/jade-serif-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0020-007E, U+00A0-00FF, U+2010, U+2013-2014, U+2018-201A, U+201C-201E, U+2020, U+2022, U+2026, U+2039-203A, U+20AC, U+2116, U+2122, U+2192, U+2212, U+4E09, U+4E2D, U+4F53, U+4F7F, U+5178, U+51A0, U+5203, U+523B, U+5317, U+53F0, U+57CE, U+57F7, U+5830, U+5929, U+5B66, U+5B88, U+5BAE, U+5CF0, U+5E02, U+5E2B, U+5E33, U+5EA7, U+63DB, U+6587, U+65D7, U+65E5, U+661F, U+66F8, U+6708, U+672C, U+6749, U+677E, U+67F3, U+68AF, U+6A4B, U+6BB5, U+6CB3, U+6D25, U+6E21, U+6F6E, U+706F-7070, U+708E, U+70AD, U+7389, U+738B, U+73BB, U+76E4, U+773C, U+7802, U+7B46, U+7D19, U+7D79, U+7E54, U+821F, U+82D1, U+8466, U+885B, U+8A9E, U+8CFD, U+9234, U+92AD, U+93E1, U+9418, U+9470, U+9580, U+96A0, U+96BC, U+96EA, U+96F2, U+971E, U+98A8, U+9DB4, U+9F13;
}

:root {
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Apple SD Gothic Neo", "Malgun Gothic",
    "PingFang SC", "Hiragino Sans", "Microsoft YaHei", sans-serif;
  --font-display: "Jade Serif", "Noto Serif JP", "Songti SC", "Nanum Myeongjo", "Noto Serif KR", Georgia, serif;

  /* map paint */
  --paper: #efe4ca;
  --wash-a: #b8c592;
  --wash-b: #d7b97f;
  --wash-c: #a9c9ad;
  --sea: #9dbcb3;
  --sea-ink: #557f78;
  --river: #8db8ae;
  --mtn-top: #2f3b37;
  --mtn-mid: rgba(55, 72, 66, 0.55);
  --mtn-bottom: rgba(80, 96, 82, 0);
  --mtn-line: #1d2522;
  --snow: #f7f2e6;
  --forest: #557552;
  --forest-dark: #36513a;
  --trunk: #5c4630;
  --terrace: #9b7a52;
  --cloud: #fbf7ec;
  --cloud-line: rgba(130, 110, 80, 0.45);
  --road: #8a6a3f;
  --road-bed: rgba(250, 244, 228, 0.75);
  --vig: rgba(90, 62, 26, 0.32);
  --lantern: rgba(255, 196, 92, 0);

  /* brand */
  --jade: #2f8f72;
  --jade-deep: #1d6a56;
  --gold: #c39233;
  --cinnabar: #b13f2c;

  /* UI */
  --bg: #e8dcc0;
  --text: #201d18;
  --muted: #6b6253;
  --surface: rgba(252, 248, 238, 0.88);
  --surface-solid: #fbf7ec;
  --surface-sunk: #f1e9d6;
  --line: rgba(70, 52, 28, 0.14);
  --line-strong: rgba(70, 52, 28, 0.24);
  --accent: var(--jade-deep);
  --accent-hover: #175747;
  --accent-text: #ffffff;
  --focus: #2b7de9;
  --shadow: 0 12px 36px rgba(48, 34, 14, 0.18), 0 2px 6px rgba(48, 34, 14, 0.08);
  --veil: rgba(239, 228, 202, 0.72);
  --board-wood: #ddb46c;
  --board-wood-2: #c8964c;
  --board-line: #3b2a14;
  --radius: 18px;
}

:root[data-bg="dusk"] {
  --paper: #ecd6c8;
  --wash-a: #d7a99a;
  --wash-b: #c7a7c4;
  --wash-c: #e2c08f;
  --sea: #8ea5bd;
  --sea-ink: #4f6683;
  --river: #93a9c4;
  --mtn-top: #3a3150;
  --mtn-mid: rgba(70, 58, 96, 0.5);
  --mtn-bottom: rgba(110, 80, 120, 0);
  --mtn-line: #241d33;
  --forest: #6c6a5a;
  --forest-dark: #4b4558;
  --terrace: #a2715d;
  --cloud: #fbeee6;
  --road: #8d5a46;
  --vig: rgba(90, 40, 60, 0.35);
  --jade: #3a8f7c;
  --jade-deep: #2a6b5e;
  --bg: #e6cfc2;
  --surface: rgba(252, 244, 240, 0.88);
  --surface-solid: #fcf3ee;
  --surface-sunk: #f3e3db;
  --veil: rgba(236, 214, 200, 0.72);
}

:root[data-bg="night"] {
  --paper: #1b2232;
  --wash-a: #223a3b;
  --wash-b: #2d2c46;
  --wash-c: #1f3a33;
  --sea: #0f1828;
  --sea-ink: #3c5a7c;
  --river: #2c4c6b;
  --mtn-top: #a9b6c9;
  --mtn-mid: rgba(130, 148, 176, 0.32);
  --mtn-bottom: rgba(60, 74, 100, 0);
  --mtn-line: #cfd8e6;
  --snow: #e6ecf5;
  --forest: #2f4a43;
  --forest-dark: #1f332f;
  --trunk: #3e3528;
  --terrace: #6f6a5a;
  --cloud: rgba(210, 220, 240, 0.4);
  --cloud-line: rgba(210, 220, 240, 0.35);
  --road: #d7b46a;
  --road-bed: rgba(20, 26, 40, 0.7);
  --vig: rgba(0, 0, 0, 0.55);
  --lantern: rgba(255, 190, 90, 0.42);
  --jade: #4fc0a0;
  --jade-deep: #2f9a7e;
  --bg: #141a26;
  --text: #ece6d8;
  --muted: #a8a294;
  --surface: rgba(24, 30, 44, 0.88);
  --surface-solid: #1d2434;
  --surface-sunk: #252e42;
  --line: rgba(220, 210, 190, 0.14);
  --line-strong: rgba(220, 210, 190, 0.26);
  --accent: #2f9a7e;
  --accent-hover: #38ad8e;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3);
  --veil: rgba(20, 26, 38, 0.74);
  --focus: #7fb4ff;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  line-height: 1.45;
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; left: 12px; top: -60px; z-index: 100; background: var(--surface-solid); padding: 8px 14px; border-radius: 10px; }
.skip-link:focus { top: 12px; }
.muted { color: var(--muted); }
.icon { flex: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.display, .match-title, .results-headline, .town-panel h2, .intro h2, .modal h2 { font-family: var(--font-display); font-weight: 700; }
.eyebrow { margin: 0 0 4px; font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.fine-print { font-size: 0.82rem; color: var(--muted); margin: 8px 0 0; }

/* ---------- boot ---------- */
.boot-splash { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 200; transition: opacity 0.15s; }
.boot-seal { font-family: var(--font-display); font-size: 48px; color: #fff; background: var(--jade-deep); width: 84px; height: 84px; border-radius: 24px; display: grid; place-items: center; animation: breathe 1.6s ease-in-out infinite; }
body.ready .boot-splash { opacity: 0; pointer-events: none; }
body.ready .boot-seal { animation: none; } /* hidden splash: stop its loop */
@keyframes breathe { 50% { transform: scale(1.06); } }

/* ---------- map ---------- */
#map-root { position: fixed; inset: 0; }
.map-scroll { position: absolute; inset: 0; overflow: auto; scrollbar-width: none; cursor: grab; overscroll-behavior: contain; }
.map-scroll::-webkit-scrollbar { display: none; }
.map-scroll.panning { cursor: grabbing; }
.map-canvas { position: relative; }
/* Painted in stages behind the landing screen (map.js), then shown at once. */
.map-canvas.map-painting { visibility: hidden; }
.map-canvas.map-revealed { animation: fade 0.35s ease-out; }
.reduce-motion .map-canvas.map-revealed { animation: none; }
/* Three stacked layers (see map.js): paint (filtered, still), fx (moving, unfiltered), towns.
   Each is composited on its own so an animation frame never repaints the watercolour. */
.map-layer { position: absolute; inset: 0; display: block; width: 100%; height: 100%; user-select: none; will-change: transform; }
.map-paint, .map-fx { pointer-events: none; }
/* The river current and the next road are drawn as still dashes: animating a dash repainted the
   map every frame, which on phones took most of the main thread (also behind the board). The
   clouds, lanterns, halos and courier still move; they wait while the map is only a backdrop. */
/* The lanterns and halos live on the towns layer, not .map-fx: they need pausing too, or they
   repaint the map on every frame behind a match (competing with board pinch and pan). */
body:not([data-view="map"]) :is(.map-fx *, .player-token, .lantern-glow, .lm-lantern, .halo) { animation-play-state: paused !important; }
.map-overlay { position: absolute; inset: 0; pointer-events: none; }

.map-paper { fill: var(--paper); }
.wash { opacity: 0.55; }
.wash-a { fill: var(--wash-a); }
.wash-b { fill: var(--wash-b); }
.wash-c { fill: var(--wash-c); }
.sea { fill: var(--sea); }
.lake { fill: var(--sea); opacity: 0.9; }
.coast-shadow { fill: none; stroke: var(--sea-ink); stroke-width: 9; opacity: 0.35; }
.coast-line { fill: none; stroke: var(--sea-ink); stroke-width: 2.2; opacity: 0.8; }
.wave { fill: none; stroke: var(--sea-ink); stroke-width: 2; opacity: 0.45; stroke-linecap: round; }
.reed { fill: none; stroke: var(--forest-dark); stroke-width: 1.6; stroke-linecap: round; opacity: 0.8; }
.reed-head { fill: var(--trunk); opacity: 0.8; }
.river { fill: none; stroke-linecap: round; }
.river-outer { stroke: var(--river); stroke-width: 15; opacity: 0.75; }
.river-inner { stroke: var(--sea-ink); stroke-width: 2; opacity: 0.45; }
.fall { stroke: var(--cloud); stroke-width: 2.4; stroke-linecap: round; opacity: 0.9; }
.mtn-stop-top { stop-color: var(--mtn-top); stop-opacity: 0.92; }
.mtn-stop-mid { stop-color: var(--mtn-top); stop-opacity: 0.35; }
.mtn-stop-bottom { stop-color: var(--mtn-top); stop-opacity: 0; }
.mtn-body { fill: url(#mtn-grad); }
.mtn.depth-0 { opacity: 0.38; }
.mtn.depth-1 { opacity: 0.62; }
.mtn.depth-2 { opacity: 0.85; }
.mtn-ridge { fill: none; stroke: var(--mtn-line); stroke-width: 3.2; stroke-linecap: round; opacity: 0.75; }
.mtn-cun { fill: none; stroke: var(--mtn-line); stroke-width: 1.6; stroke-linecap: round; opacity: 0.4; }
.mtn-snow { fill: var(--snow); opacity: 0.85; }
.pine { fill: var(--forest); }
.canopy { fill: var(--forest); opacity: 0.92; }
.canopy-dark { fill: var(--forest-dark); }
.trunk { stroke: var(--trunk); stroke-width: 2; }
.terrace { fill: none; stroke: var(--terrace); stroke-width: 2.4; opacity: 0.55; stroke-linecap: round; }
.cloud-fill { fill: var(--cloud); opacity: 0.82; }
.cloud-curl { fill: none; stroke: var(--cloud-line); stroke-width: 2; stroke-linecap: round; }
.cloud-body { animation: drift 38s ease-in-out infinite alternate; }
.cloud-1 .cloud-body { animation-duration: 46s; animation-delay: -8s; }
.cloud-2 .cloud-body { animation-duration: 52s; animation-delay: -20s; }
.cloud-3 .cloud-body { animation-duration: 40s; animation-delay: -12s; }
@keyframes drift { from { transform: translateX(-30px); } to { transform: translateX(40px); } }
.compass-ring { fill: none; stroke: var(--sea-ink); stroke-width: 2; opacity: 0.7; }
.compass-ring.thin { stroke-width: 1; stroke-dasharray: 2 5; }
.compass-needle { fill: var(--cinnabar); opacity: 0.85; }
.compass-needle.minor { fill: var(--sea-ink); opacity: 0.6; }
.compass-n { font-family: var(--font-display); font-size: 22px; text-anchor: middle; fill: var(--cinnabar); }
.cartouche-bg { fill: var(--surface-solid); stroke: var(--cinnabar); stroke-width: 2.5; opacity: 0.92; }
.cartouche-title { font-family: var(--font-display); font-size: 28px; font-weight: 700; text-anchor: middle; fill: var(--text); }
.cartouche-sub { font-size: 14px; text-anchor: middle; fill: var(--muted); letter-spacing: 0.06em; }
.paper-fibers, .paper-grain { pointer-events: none; }
:root[data-bg="night"] .paper-fibers { opacity: 0.35; }
.vig-in { stop-color: var(--vig); stop-opacity: 0; }
.vig-out { stop-color: var(--vig); stop-opacity: 1; }
.lantern-in { stop-color: rgb(255, 190, 90); stop-opacity: 1; }
.lantern-out { stop-color: rgb(255, 190, 90); stop-opacity: 0; }
.lantern-glow { opacity: 0; pointer-events: none; }
:root[data-bg="night"] .town:not(.town-locked) .lantern-glow { opacity: 0.38; }

.road-bed { fill: none; stroke: var(--road-bed); stroke-width: 11; stroke-linecap: round; }
.road { fill: none; stroke: var(--road); stroke-width: 3.5; stroke-dasharray: 1 11; stroke-linecap: round; opacity: 0.85; }
.road-travelled { fill: none; stroke: var(--jade); stroke-width: 6; stroke-linecap: round; opacity: 0.9; }
.road-next { fill: none; stroke: var(--jade); stroke-width: 4; stroke-dasharray: 10 12; stroke-linecap: round; opacity: 0.85; }

.town { cursor: pointer; outline: none; }
.town .halo { fill: var(--jade); opacity: 0; }
.town .seal-shadow { fill: rgba(30, 20, 5, 0.22); transform: translate(2px, 4px); }
.town .seal-bg { fill: #8c8578; }
.town .seal-ring { fill: none; stroke: rgba(255, 250, 235, 0.55); stroke-width: 2; }
.town .seal-text { font-family: var(--font-display); font-size: 30px; font-weight: 700; text-anchor: middle; fill: #f8f2e2; pointer-events: none; }
.town.finale .seal-text { font-size: 36px; }
.town-open .seal-bg, .town-soon .seal-bg { fill: var(--jade-deep); }
.town-complete .seal-bg { fill: var(--gold); }
.town-locked .seal-bg { fill: #9c958a; }
.town-locked .seal-text { fill: rgba(250, 246, 236, 0.75); }
:root[data-bg="night"] .town-locked .seal-bg { fill: #4a5162; }
.town.finale .seal-ring { stroke: var(--gold); stroke-width: 3; }
.town-open .halo { opacity: 0.28; animation: halo 2.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes halo { 0%, 100% { transform: scale(0.85); opacity: 0.32; } 50% { transform: scale(1.12); opacity: 0.08; } }
.town:hover .seal-bg, .town:focus-visible .seal-bg { filter: brightness(1.12); }
.town:focus-visible .seal-ring, .town.selected .seal-ring { stroke: #fff; stroke-width: 3.5; }
.town.selected .halo { opacity: 0.35; }
.badge circle { fill: var(--surface-solid); stroke: var(--line-strong); }
.badge path { fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.badge-done circle { fill: var(--jade-deep); stroke: none; }
.badge-done path { stroke: #fff; stroke-width: 2.4; }
.tier-pips .pip { fill: var(--surface-solid); stroke: var(--line-strong); stroke-width: 1.2; }
.tier-pips .pip.done { fill: var(--gold); stroke: none; }
.town-label rect { fill: var(--surface-solid); opacity: 0.94; stroke: var(--line-strong); }
.town-label text { font-size: 16px; font-weight: 650; text-anchor: middle; fill: var(--text); pointer-events: none; }
.town-locked .town-label text { fill: var(--muted); }
.soon-tag rect { fill: var(--surface-sunk); stroke: var(--line); }
.soon-tag text { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-anchor: middle; fill: var(--muted); text-transform: uppercase; }

.player-token { position: absolute; transform: translate(-50%, calc(-100% - 46px)); display: flex; flex-direction: column; align-items: center; gap: 2px; animation: bob 3s ease-in-out infinite; filter: drop-shadow(0 6px 10px rgba(30, 20, 5, 0.3)); }
.player-token .avatar { border: 3px solid var(--surface-solid); }
.player-token-name { background: var(--surface-solid); color: var(--text); font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line-strong); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@keyframes bob { 50% { transform: translate(-50%, calc(-100% - 52px)); } }

/* ---------- avatars & seals ---------- */
.avatar { width: var(--size); height: var(--size); flex: none; display: inline-grid; place-items: center; }
.avatar-photo { border-radius: 50%; overflow: hidden; background: var(--surface-sunk); }
.avatar-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.seal {
  border-radius: 28%;
  background: radial-gradient(circle at 30% 25%, hsl(var(--seal-h) 48% 50%), hsl(var(--seal-h) 52% 30%));
  box-shadow: inset 0 0 0 2px rgba(255, 250, 235, 0.35), 0 2px 6px rgba(30, 20, 5, 0.2);
  color: #fbf5e4;
}
.seal-glyph { font-family: var(--font-display); font-weight: 700; font-size: calc(var(--size) * 0.54); line-height: 1; transform: translateY(-2%); }
.seal-jade { background: radial-gradient(circle at 30% 25%, #3aa585, #175747); }
.seal-muted { background: radial-gradient(circle at 30% 25%, #a8a194, #77705f); }

/* ---------- panels, buttons ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(10px) saturate(1.1); -webkit-backdrop-filter: blur(10px) saturate(1.1); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 18px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--surface-solid);
  font-weight: 650; cursor: pointer; white-space: nowrap;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
}
.btn:hover:not(:disabled) { background: var(--surface-sunk); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--accent-text); box-shadow: 0 4px 14px rgba(29, 106, 86, 0.3); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--muted); }
/* An action under way (main.js once()): the button keeps its pressed look at once, and if the
   action takes a moment its label gives way to a turning ring of the same size, so nothing
   moves. Further taps are ignored until the action finishes. */
.btn.is-busy, .journey.is-busy { cursor: progress; }
.btn.is-busy { position: relative; transform: translateY(1px); animation: busy-label 0s 0.15s both; }
.btn.is-busy::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--text); border-right-color: transparent;
  animation: spin 0.8s linear infinite, busy-show 0s 0.15s both;
}
.btn-primary.is-busy::after { border-color: var(--accent-text); border-right-color: transparent; }
@keyframes busy-label { to { color: transparent; } }
@keyframes busy-show { from { opacity: 0; } to { opacity: 1; } }
.btn-quiet:hover:not(:disabled) { color: var(--text); }
.btn-ghost { background: var(--surface); }
.btn-lg { min-height: 50px; padding: 0 26px; font-size: 1.05rem; }
.icon-btn { display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line-strong); background: var(--surface); cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--surface-sunk); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; background: var(--surface-sunk); border: 1px solid var(--line); font-size: 0.85rem; font-weight: 600; }
.chip-button { cursor: pointer; }
.chip-button:hover { background: var(--surface-solid); }
.notice { display: flex; gap: 8px; align-items: flex-start; background: var(--surface-sunk); border-radius: 12px; padding: 10px 12px; font-size: 0.92rem; margin: 0 0 12px; }
.notice-soon { border-left: 4px solid var(--gold); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }
.topbar { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: max(14px, env(safe-area-inset-top)) 16px 0; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 6px 16px 6px 6px; box-shadow: var(--shadow); backdrop-filter: blur(10px); }
.brand strong { display: block; font-family: var(--font-display); font-size: 1.05rem; line-height: 1.1; }
.brand-sub { font-size: 0.78rem; }
.brand-seal { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 11px; background: var(--jade-deep); color: #fff; font-family: var(--font-display); font-weight: 700; font-size: 20px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.player-chip { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 14px 4px 4px; cursor: pointer; box-shadow: var(--shadow); backdrop-filter: blur(10px); max-width: 230px; }
.player-chip:hover { background: var(--surface-solid); }
.player-chip-text { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; text-align: left; }
.player-chip-text strong { font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.player-chip-text .muted { font-size: 0.75rem; }
.hud-bottom { position: absolute; left: 16px; bottom: max(16px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: flex-start; gap: 10px; max-width: min(460px, calc(100vw - 32px)); pointer-events: none; }
.hud-bottom > * { pointer-events: auto; }
.journey { text-align: left; padding: 12px 16px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; color: inherit; }
.journey strong { font-family: var(--font-display); font-size: 1.2rem; }
.tier-minis { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.tier-mini { font-size: 0.78rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-sunk); border: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.tier-mini.done { background: var(--gold); color: #fff; border-color: transparent; }
.resume { display: flex; align-items: center; gap: 12px; padding: 10px 12px; flex-wrap: wrap; }
.resume p { margin: 0; font-size: 0.85rem; }
.resume > div { flex: 1; min-width: 140px; }

.town-panel { position: absolute; right: 16px; top: 84px; bottom: 16px; width: min(400px, calc(100vw - 32px)); overflow: auto; padding: 20px; animation: slide-in 0.22s ease-out; }
.town-panel.closing { animation: slide-out 0.2s ease-in forwards; }
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }
@keyframes slide-out { to { transform: translateX(24px); opacity: 0; } }
.town-head { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.town-head > div { flex: 1; min-width: 0; }
.town-head h2 { font-size: 1.5rem; }
.town-blurb { margin: 0 0 16px; color: var(--muted); }
.tier-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.tier-card { display: grid; grid-template-columns: auto auto 1fr; grid-template-areas: "code seal info" "btn btn btn"; gap: 10px 12px; align-items: center; padding: 12px; border-radius: 14px; background: var(--surface-solid); border: 1px solid var(--line); }
.tier-card.complete { border-color: color-mix(in srgb, var(--gold) 60%, transparent); }
.tier-card.unavailable { opacity: 0.82; }
.tier-code { grid-area: code; font-family: var(--font-display); font-weight: 700; font-size: 1.1rem; width: 34px; text-align: center; color: var(--jade-deep); }
.tier-card .seal { grid-area: seal; }
.tier-info { grid-area: info; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tier-info .muted { font-size: 0.85rem; }
.tier-status { font-size: 0.82rem; color: var(--muted); }
.tier-card .btn { grid-area: btn; width: 100%; }
.pips { display: flex; gap: 6px; margin: 6px 0 2px; }
.pip { width: 14px; height: 14px; border-radius: 50%; background: var(--surface-sunk); border: 1.5px solid var(--line-strong); display: inline-block; }
.pip.filled { background: var(--jade); border-color: var(--jade-deep); }
.pips.small .pip { width: 11px; height: 11px; }
.pip.new { animation: pip-pop 0.7s 0.4s cubic-bezier(.3, 1.6, .5, 1) both; }
@keyframes pip-pop { from { transform: scale(0.2); background: var(--gold); } 60% { transform: scale(1.4); } }

/* ---------- screens ---------- */
#screen-root { position: fixed; inset: 0; z-index: 5; pointer-events: none; outline: none; }
#screen-root > * { pointer-events: auto; }
body[data-view="match"] #screen-root, body[data-view="results"] #screen-root { background: radial-gradient(ellipse at center, var(--veil), color-mix(in srgb, var(--veil) 70%, var(--bg)) 80%); }
body[data-view="match"] .map-scroll, body[data-view="results"] .map-scroll, body[data-view="landing"] .map-scroll { pointer-events: none; }

.landing-wrap { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: linear-gradient(180deg, transparent, var(--veil) 70%); overflow: auto; }
.landing { width: min(460px, 100%); padding: 32px 28px 22px; text-align: center; animation: rise 0.25s ease-out; }
@keyframes rise { from { transform: translateY(16px); opacity: 0; } }
.landing .display { font-size: clamp(2.2rem, 7vw, 3.1rem); margin: 4px 0 10px; letter-spacing: 0.01em; }
.landing-lede { color: var(--muted); margin: 0 0 22px; }
.landing-actions { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.landing-actions .btn-lg { width: 100%; max-width: 300px; }
.google-slot { min-height: 44px; display: flex; justify-content: center; }
.divider { display: flex; align-items: center; gap: 12px; width: 100%; max-width: 300px; color: var(--muted); font-size: 0.85rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line-strong); }
.landing-foot { margin-top: 18px; display: flex; justify-content: center; }
.lang-select, select { border: 1px solid var(--line-strong); background: var(--surface-solid); border-radius: 999px; padding: 8px 14px; min-height: 40px; }

/* ---------- match ---------- */
.match-screen, .results-screen { position: absolute; inset: 0; padding: 76px 16px 16px; overflow: auto; }
.match-layout, .results-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: center; max-width: 1180px; margin: 0 auto; min-height: 100%; }
.board-wrap { display: flex; justify-content: center; align-items: center; }
.board-svg { width: min(100%, calc(100dvh - 110px)); max-width: 760px; height: auto; display: block; border-radius: 14px; box-shadow: 0 22px 50px rgba(40, 24, 6, 0.35), 0 3px 8px rgba(40, 24, 6, 0.25); touch-action: manipulation; outline: none; }
.board-frame { width: min(100%, calc(100dvh - 110px)); max-width: 760px; } /* zoomable boards: sized like .board-svg (more under board zoom) */
.board-svg:focus-visible { box-shadow: 0 0 0 4px var(--focus), 0 22px 50px rgba(40, 24, 6, 0.35); }
.board-wood { fill: var(--board-wood); }
.board-grain { fill: var(--board-wood-2); opacity: var(--grain-strength, 0.7); }
.board-figure { fill: var(--board-wood-2); opacity: var(--figure-strength, 0.35); }
.board-sheen { pointer-events: none; }
.board-bevel { fill: none; stroke: #fff6e0; stroke-opacity: 0.38; stroke-width: 3; }
.board-rim { fill: none; stroke: #3a2208; stroke-opacity: 0.35; stroke-width: 1.5; }
.board-grain, .board-figure, .board-bevel, .board-rim { pointer-events: none; }
.grid line { stroke: var(--board-line); stroke-width: 2.6; opacity: 0.85; }
.grid line.edge { stroke-width: 4.2; }
.grid .star { fill: var(--board-line); }
.grid .coord { font-size: 26px; font-weight: 650; text-anchor: middle; fill: rgba(59, 42, 20, 0.62); font-family: var(--font-ui); }
.board-svg.interactive { cursor: pointer; }
.stone-body { transform-box: fill-box; transform-origin: center; }
.stone.placed .stone-body { animation: place 0.2s cubic-bezier(.2, 1.4, .5, 1); }
.shell-lines { fill: none; stroke: #b3a382; stroke-linecap: round; }
.stone-shell { opacity: 0.4; }
@keyframes place { from { transform: scale(1.25); opacity: 0.4; } }
.stone.captured { pointer-events: none; }
.stone.captured .stone-body { animation: vanish 0.42s ease-in forwards; }
@keyframes vanish { to { transform: scale(0.6); opacity: 0; } }
.stone.ghost { opacity: 0.42; pointer-events: none; }
.stone.ghost .stone-shadow { display: none; }
.last-move { fill: none; stroke-width: 5; }
.last-move.on-black { stroke: #f3efe4; }
.last-move.on-white { stroke: #1a1a1a; }
.hint-ring { fill: rgba(195, 146, 51, 0.18); stroke: var(--gold); stroke-width: 7; stroke-dasharray: 16 10; animation: spin 6s linear infinite; transform-box: fill-box; transform-origin: center; }
@keyframes spin { to { transform: rotate(360deg); } }
.kb-cursor { fill: none; stroke: var(--focus); stroke-width: 6; }
.kb-cursor.illegal { stroke: var(--cinnabar); stroke-dasharray: 10 8; }
.terr-black { fill: #15130f; opacity: 0.78; }
.terr-white { fill: #fbf8f1; stroke: #3b2a14; stroke-width: 2; }

.match-panel { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.match-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.match-title { font-size: 1.3rem; }
.player-card { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 14px; background: var(--surface-solid); border: 2px solid transparent; transition: border-color 0.2s; }
.player-card.to-play { border-color: var(--jade); }
.player-card-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.player-card-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-card-text .muted { font-size: 0.85rem; }
.player-card-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.player-card.thinking .seal { animation: think 1s ease-in-out infinite; }
@keyframes think { 50% { transform: translateY(-3px); } }
.stone-dot { width: 18px; height: 18px; border-radius: 50%; display: inline-block; vertical-align: middle; }
.stone-dot.black { background: radial-gradient(circle at 36% 30%, #5c5e63, #1d1e21 55%, #050506); box-shadow: 0 1px 2px rgba(30, 17, 4, 0.45); }
.stone-dot.white { background: radial-gradient(circle at 36% 30%, #fff, #f3efe6 45%, #d6cdbb 90%, #c2b8a4); box-shadow: 0 1px 2px rgba(30, 17, 4, 0.35), inset 0 0 0 1px rgba(0, 0, 0, 0.08); }
.match-status { margin: 0; font-weight: 650; min-height: 1.45em; }
.match-meta { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.save-status::before { content: "●"; margin-right: 6px; color: var(--jade); }
.save-status[data-state="saving"]::before { color: var(--gold); }
.save-status[data-state="retrying"]::before { color: var(--cinnabar); }
.match-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.match-actions .btn { min-height: 48px; }
/* Pass is a real move (it ends the game when both players pass): give it the first, full-width slot. */
.match-actions .btn-pass { grid-column: 1 / -1; font-weight: 700; border-color: color-mix(in srgb, var(--jade) 55%, var(--line)); }
.match-panel > .btn-primary { width: 100%; }

/* ---------- results ---------- */
.results-card { padding: 22px; display: flex; flex-direction: column; gap: 12px; animation: rise 0.4s ease-out; }
.results-headline { font-size: 2.4rem; }
.result-win .results-headline { color: var(--jade-deep); }
:root[data-bg="night"] .result-win .results-headline { color: var(--jade); }
.result-loss .results-headline { color: var(--cinnabar); }
.results-how { margin: 0; font-weight: 600; }
.score-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 0.92rem; }
.score-table th, .score-table td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--line); }
.score-table th:first-child { text-align: left; display: flex; align-items: center; gap: 8px; }
.score-table thead th { font-size: 0.75rem; color: var(--muted); font-weight: 600; }
.score-table .total { font-weight: 800; }
.quote { display: flex; gap: 12px; align-items: flex-start; margin: 0; padding: 12px; background: var(--surface-solid); border-radius: 14px; border: 1px solid var(--line); }
.quote p { margin: 0 0 4px; font-style: italic; }
.quote cite { font-size: 0.85rem; color: var(--muted); font-style: normal; }
.tier-progress p { margin: 0; }
.unlocks { display: flex; flex-direction: column; gap: 8px; }
.unlock { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 14px; background: linear-gradient(120deg, color-mix(in srgb, var(--gold) 22%, var(--surface-solid)), var(--surface-solid)); border: 1px solid color-mix(in srgb, var(--gold) 55%, transparent); animation: unlock-in 0.6s 0.6s cubic-bezier(.2, 1.3, .5, 1) both; }
.unlock p { margin: 0; }
.unlock strong { font-family: var(--font-display); font-size: 1.1rem; }
.unlock-town { background: linear-gradient(120deg, color-mix(in srgb, var(--jade) 26%, var(--surface-solid)), var(--surface-solid)); border-color: color-mix(in srgb, var(--jade) 55%, transparent); }
@keyframes unlock-in { from { transform: translateY(10px) scale(0.96); opacity: 0; } }
.results-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }

/* ---------- modals ---------- */
#modal-layer { position: relative; z-index: 50; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(18, 14, 8, 0.48); display: grid; place-items: center; padding: 16px; animation: fade 0.16s ease-out; overflow: auto; }
.modal-backdrop.closing { animation: fade 0.16s ease-in reverse forwards; pointer-events: none; }
@keyframes fade { from { opacity: 0; } }
.modal { width: min(520px, 100%); max-height: calc(100dvh - 32px); overflow: auto; background: var(--surface-solid); border-radius: 22px; padding: 24px; box-shadow: var(--shadow); border: 1px solid var(--line); animation: pop 0.2s cubic-bezier(.2, 1.2, .5, 1); }
.modal-wide { width: min(680px, 100%); }
@keyframes pop { from { transform: scale(0.96) translateY(8px); opacity: 0; } }
.modal h2 { font-size: 1.45rem; margin-bottom: 8px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.modal-head h2 { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.confirm p { color: var(--muted); }
.confirm input[type="text"] { width: 100%; }
input[type="text"] { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 12px; padding: 10px 12px; min-height: 44px; }

.intro { text-align: center; }
.intro-portrait { display: flex; justify-content: center; margin: 4px 0 12px; }
.intro h2 { display: flex; flex-direction: column; gap: 2px; }
.intro-title { font-family: var(--font-ui); font-size: 0.95rem; font-weight: 500; }
.speech { position: relative; margin: 16px 0; padding: 16px 18px; background: var(--surface-sunk); border-radius: 16px; font-size: 1.05rem; text-align: left; }
.speech::before { content: ""; position: absolute; top: -9px; left: 50%; margin-left: -9px; border: 9px solid transparent; border-top: 0; border-bottom-color: var(--surface-sunk); }
.intro-facts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.intro .modal-actions { justify-content: center; }

.rules-list { padding-left: 18px; display: flex; flex-direction: column; gap: 8px; }
.rules-list li::marker { color: var(--jade); }

.settings { display: flex; flex-direction: column; gap: 6px; }
.settings-section { padding: 14px 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.settings-section:first-of-type { border-top: 0; }
.settings-section h3 { font-size: 0.8rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.field-label { font-size: 0.88rem; font-weight: 650; margin: 2px 0 0; }
.field-row { display: flex; gap: 8px; }
.field-row input { flex: 1; min-width: 0; }
.avatar-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.avatar-choice { padding: 3px; border-radius: 16px; border: 2px solid transparent; background: none; cursor: pointer; }
.avatar-choice.selected { border-color: var(--jade); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; position: relative; }
.switch-row input { position: absolute; opacity: 0; right: 0; width: 46px; height: 26px; margin: 0; cursor: pointer; }
.switch { width: 46px; height: 26px; border-radius: 999px; background: var(--line-strong); position: relative; transition: background 0.15s; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.15s; }
.switch-row input:checked + .switch { background: var(--jade); }
.switch-row input:checked + .switch::after { transform: translateX(20px); }
.switch-row input:focus-visible + .switch { outline: 3px solid var(--focus); outline-offset: 2px; }
.slider-row { display: grid; grid-template-columns: 1fr 160px; align-items: center; gap: 12px; font-size: 0.92rem; color: var(--muted); }
.slider-row input { accent-color: var(--jade); }
.swatches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.swatch { display: flex; flex-direction: column; gap: 6px; align-items: stretch; padding: 6px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface); cursor: pointer; font-size: 0.85rem; font-weight: 600; }
.swatch.selected { border-color: var(--jade); }
.swatch-art { height: 46px; border-radius: 9px; }
.swatch-silk .swatch-art { background: linear-gradient(135deg, #efe4ca 40%, #b8c592 70%, #9dbcb3); }
.swatch-dusk .swatch-art { background: linear-gradient(135deg, #ecd6c8 40%, #c7a7c4 70%, #8ea5bd); }
.swatch-night .swatch-art { background: radial-gradient(circle at 70% 40%, #ffbe5a 0 6%, transparent 18%), linear-gradient(135deg, #1b2232 45%, #2d2c46 70%, #0f1828); }
.segmented { display: inline-flex; background: var(--surface-sunk); border-radius: 999px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented button { border: 0; background: transparent; border-radius: 999px; padding: 7px 14px; cursor: pointer; font-weight: 600; font-size: 0.9rem; }
.segmented button.selected { background: var(--surface-solid); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15); }
.account-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.account-row p { margin: 0; }
.account-guest { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.account-guest p { margin: 0; }

.merge-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.merge-col { background: var(--surface-sunk); border-radius: 14px; padding: 12px; }
.merge-col h3 { font-size: 0.9rem; margin-bottom: 6px; }
.merge-list { margin: 0; padding-left: 18px; font-size: 0.9rem; }

.level-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.level-card { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 8px; border-radius: 16px; border: 2px solid var(--line); background: var(--surface); cursor: pointer; text-align: center; }
.level-card .muted { font-size: 0.8rem; }
.level-card.selected { border-color: var(--jade); background: var(--surface-solid); }
/* Shown on the sign-in screen when a 90-day sign-in has ended. */
.auth-notice { margin: 0 0 12px; padding: 10px 12px; border-radius: 12px; background: var(--surface-sunk); border-left: 4px solid var(--jade); font-size: 0.92rem; }

/* Practice difficulty picker (Level 1–20). */
.difficulty { margin-top: 4px; }
.difficulty-readout { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin: 2px 0 6px; }
.difficulty-level { font-size: 1.5rem; line-height: 1.2; }
.difficulty-band { padding: 2px 10px; border-radius: 999px; background: var(--surface-sunk); font-weight: 600; font-size: 0.9rem; }
.difficulty-band[data-band="expert"], .difficulty-band[data-band="master"] { background: var(--jade-deep); color: #fff; }
.difficulty-control { display: flex; align-items: center; gap: 10px; }
.difficulty-step { font-size: 1.4rem; font-weight: 700; width: 44px; height: 44px; }
.difficulty-step:disabled { opacity: 0.4; cursor: default; }
.difficulty-range { flex: 1; min-width: 0; height: 44px; margin: 0; accent-color: var(--jade); cursor: pointer; touch-action: pan-y; }
.difficulty-range::-webkit-slider-thumb { width: 28px; height: 28px; }
.difficulty-range::-moz-range-thumb { width: 26px; height: 26px; }
.difficulty-hint { margin: 4px 0 8px; font-size: 0.9rem; min-height: 2.6em; }
.difficulty-bands { display: flex; flex-wrap: wrap; gap: 6px; }
.difficulty-bands .chip { min-height: 36px; }
.difficulty-bands .chip.selected { background: var(--surface-solid); border-color: var(--jade); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12); }
.difficulty-bands .chip-range { font-weight: 500; opacity: 0.7; font-variant-numeric: tabular-nums; }
.difficulty-engine { margin: 8px 0 0; }
.practice-row { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 12px; }
.practice-row .field-label { margin-bottom: 6px; }
.practice-record { margin: 16px 0 0; padding: 10px 12px; background: var(--surface-sunk); border-radius: 12px; font-size: 0.9rem; }

/* ---------- toasts ---------- */
#toast-layer { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(560px, calc(100vw - 32px)); }
.toast { background: #1f2a26; color: #f6f1e4; padding: 10px 18px; border-radius: 999px; box-shadow: var(--shadow); font-weight: 600; font-size: 0.92rem; animation: rise 0.2s ease-out; text-align: center; }
.toast-warn { background: #6a4a12; }
.toast-error { background: var(--cinnabar); }
.toast.leaving { opacity: 0; transition: opacity 0.3s; }

/* ---------- coins & shop ---------- */
.coin-chip { display: inline-flex; align-items: center; gap: 8px; min-height: 42px; padding: 0 12px; border-radius: 999px; background: var(--surface-solid); border: 1px solid color-mix(in srgb, var(--gold) 55%, var(--line)); color: var(--text); font: inherit; cursor: pointer; }
.coin-chip:hover { background: color-mix(in srgb, var(--gold) 12%, var(--surface-solid)); }
.coin-chip:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.coin-cart { display: inline-flex; align-items: center; gap: 4px; font-size: 0.85rem; font-weight: 650; color: var(--muted); }
.coin-balance { display: inline-flex; align-items: center; gap: 5px; font-weight: 800; font-variant-numeric: tabular-nums; }
.coin-mark { color: var(--gold); display: inline-flex; }
.coin-mark.big .icon { width: 34px; height: 34px; }
.wallet-panel { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: 14px; background: var(--surface-sunk); border: 1px solid var(--line); }
.wallet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.wallet-head .eyebrow { margin: 0; }
.coin-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.coin-action { flex-direction: column; gap: 2px; min-height: 64px; padding: 6px; font-size: 0.82rem; line-height: 1.15; text-align: center; }
.coin-cost { display: inline-flex; align-items: center; gap: 3px; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }
.coin-cost .icon { width: 14px; height: 14px; }
.coin-note { margin: 0; min-height: 1.2em; }
.coin-assisted { align-self: flex-start; color: var(--gold); }
.chip-preview { background: color-mix(in srgb, var(--gold) 22%, var(--surface-solid)); border-color: var(--gold); text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.72rem; }
.shop-packs { list-style: none; margin: 12px 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.shop-pack { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 10px; border-radius: 14px; background: var(--surface-solid); border: 1px dashed var(--line); text-align: center; }
.shop-pack .btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.shop-price { font-size: 0.8rem; }
/* ---------- extended journey ---------- */
.town-region { list-style: none; margin: 10px 4px 2px; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.town-row.current { border-color: var(--jade); box-shadow: inset 0 0 0 2px var(--jade); }
.chip-current { background: var(--jade-deep); color: #fff; border-color: transparent; font-size: 0.72rem; padding: 2px 8px; align-self: flex-start; }
.jump-current { display: inline-flex; align-items: center; gap: 6px; margin-top: 4px; font-weight: 700; color: var(--jade-deep); font-size: 0.85rem; }
.jump-btn { width: 100%; margin-bottom: 8px; }
.town-lesson { display: flex; gap: 8px; align-items: flex-start; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .match-layout, .results-layout { grid-template-columns: 1fr; align-items: start; }
  .board-svg, .board-frame { width: min(100%, 620px); }
  .match-screen, .results-screen { padding-top: 72px; }
}
/* Portrait phones and tablets: the board fills the width and the panel starts below it,
   so Pass and the other moves sit in a bar fixed to the bottom of the screen. */
@media (max-width: 900px) and (orientation: portrait) {
  /* Room under the panel for the fixed bar, so the last controls (Save & Exit) can be scrolled
     clear of it. Specific enough to outlast the narrow-phone padding rule further down. */
  body[data-view="match"] .match-screen { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
  /* A backdrop filter would make the panel the bar's containing block and pin it inside the panel. */
  .match-panel { backdrop-filter: none; -webkit-backdrop-filter: none; }
  .match-actions {
    position: fixed; left: 10px; right: 10px; bottom: max(10px, env(safe-area-inset-bottom)); z-index: 20;
    grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
    padding: 8px; background: var(--surface-solid); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
    max-width: 640px; margin: 0 auto;
  }
  .match-actions .btn-pass { grid-column: auto; }
  .match-actions .btn { padding-left: 6px; padding-right: 6px; }
  /* Toasts appear above the action bar, not over it. */
  body[data-view="match"] #toast-layer { bottom: calc(96px + env(safe-area-inset-bottom)); }
}
@media (max-width: 720px) {
  .topbar { padding: max(10px, env(safe-area-inset-top)) 10px 0; }
  .topbar .label, .brand-sub, .player-chip-text .muted { display: none; }
  .brand { padding: 4px 12px 4px 4px; }
  .brand strong { font-size: 0.95rem; }
  .player-chip { padding: 3px; }
  .player-chip-text { display: none; }
  .btn-ghost { padding: 0 12px; }
  .town-panel { left: 0; right: 0; bottom: 0; top: auto; width: auto; max-height: 74dvh; border-radius: 22px 22px 0 0; animation-name: sheet-in; }
  .town-panel.closing { animation-name: sheet-out; }
  @keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }
  @keyframes sheet-out { to { transform: translateY(40px); opacity: 0; } }
  .hud-bottom { left: 10px; right: 10px; max-width: none; }
  .match-screen, .results-screen { padding: 64px 10px 12px; }
  .match-layout, .results-layout { gap: 12px; }
  .merge-cols { grid-template-columns: 1fr; }
  .level-grid { grid-template-columns: 1fr; }
  .level-card { flex-direction: row; text-align: left; }
  .slider-row { grid-template-columns: 1fr 120px; }
  .results-headline { font-size: 2rem; }
}
@media (max-width: 720px) {
  .coin-cart .label { display: none; }
  .coin-chip { padding: 0 10px; gap: 6px; }
  .shop-packs { grid-template-columns: 1fr; }
  .shop-pack { flex-direction: row; justify-content: space-between; text-align: left; }
}
@media (max-width: 480px) {
  .brand > span:not(.brand-seal) { display: none; }
  .brand { padding: 4px; }
  /* The profile chip opens the same Settings dialog as the gear, so the gear can go. */
  .topbar-actions > .icon-btn { display: none; }
}
@media (max-width: 400px) {
  .topbar-actions { gap: 4px; }
  .coin-cart { display: none; }
  .coin-action-label { font-size: 0.75rem; }
  .btn-ghost { width: 42px; padding: 0; }
}

/* ---------- reduced motion ---------- */
.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  animation-delay: 0ms !important;
  transition-duration: 0.001ms !important;
}
.reduce-motion .cloud-body, .reduce-motion .player-token, .reduce-motion .road-next, .reduce-motion .town-open .halo { animation: none !important; }

/* =====================================================================
   v2 additions: board themes, scoring, scenes, journal, map controls
   ===================================================================== */

/* Board themes — kept quieter than the map so stones stay easy to read. */
:root { --board-wood: #dcb36d; --board-wood-2: #c8964c; --board-line: #3b2a14; --coord: rgba(59, 42, 20, 0.62); }
:root[data-board="bamboo"] { --board-wood: #e3cf98; --board-wood-2: #cdb370; --board-line: #4a3a18; }
:root[data-board="slate"] { --board-wood: #c9ccc6; --board-wood-2: #aeb2ac; --board-line: #2b2f33; --coord: rgba(40, 44, 48, 0.65); --grain-strength: 0.3; --figure-strength: 0.2; }
.grid .coord { fill: var(--coord); }
.board-svg.size-19 .grid line { stroke-width: 3.4; }
.board-svg.size-19 .grid .coord { font-size: 30px; }
.board-svg.size-13 .grid .coord { font-size: 28px; }
.board-swatch { height: 46px; border-radius: 9px; }
.board-swatch.board-kaya { background: linear-gradient(135deg, #e3bd78, #c8964c); }
.board-swatch.board-bamboo { background: repeating-linear-gradient(90deg, #e6d39f 0 14px, #d4bd80 14px 16px); }
.board-swatch.board-slate { background: linear-gradient(135deg, #d4d7d2, #a9ada7); }
.swatch-art.swatch-silk { background: linear-gradient(135deg, #efe4ca 40%, #b8c592 70%, #9dbcb3); }
.swatch-art.swatch-dusk { background: linear-gradient(135deg, #ecd6c8 40%, #c7a7c4 70%, #8ea5bd); }
.swatch-art.swatch-night { background: radial-gradient(circle at 70% 40%, #ffbe5a 0 6%, transparent 18%), linear-gradient(135deg, #1b2232 45%, #2d2c46 70%, #0f1828); }
.swatch-card { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; font-weight: 600; min-width: 92px; }
.swatch-card .swatch-art { display: block; height: 46px; border-radius: 9px; }

/* Scoring marks */
.stone.dead { opacity: 0.55; }
.stone.disputed .stone-face { stroke: var(--cinnabar); stroke-width: 6; }
.dead-mark { fill: none; stroke-width: 7; stroke-linecap: round; }
.dead-mark.on-black { stroke: #f3efe4; }
.dead-mark.on-white { stroke: #1a1a1a; }
.scoring-panel { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: 14px; background: var(--surface-solid); border: 1px solid color-mix(in srgb, var(--gold) 50%, transparent); }
.scoring-panel h3 { font-family: var(--font-display); font-size: 1.1rem; }
.scoring-panel p { margin: 0; }
.score-line { font-weight: 700; font-variant-numeric: tabular-nums; }
.scoring-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.engine-error { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 12px; background: color-mix(in srgb, var(--cinnabar) 12%, var(--surface-solid)); border: 1px solid color-mix(in srgb, var(--cinnabar) 40%, transparent); }
.engine-error p { margin: 0; font-size: 0.9rem; }
.engine-error[hidden], .scoring-panel[hidden], .match-actions[hidden] { display: none; }
.series-line { margin: 2px 0 0; font-size: 0.85rem; }
.save-status[data-state="offline"]::before { color: var(--cinnabar); }
.save-status[data-state="local"]::before { color: var(--jade); }

/* Results review */
.results-board-col { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.review { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px; box-shadow: var(--shadow); }
.review input[type="range"] { width: min(260px, 40vw); accent-color: var(--jade); }
.review .icon-btn { width: 36px; height: 36px; font-size: 0.9rem; }
.review-counter { font-size: 0.85rem; font-variant-numeric: tabular-nums; min-width: 9ch; text-align: center; }
.game-over { margin: 0; font-family: var(--font-display); font-size: 0.85rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.score-table-korean { font-size: 0.86rem; }
.score-table-korean thead th { white-space: normal; line-height: 1.15; }
.score-table caption { caption-side: bottom; font-size: 0.8rem; color: var(--muted); padding-top: 6px; text-align: left; }
.story-tease { display: flex; align-items: center; gap: 8px; margin: 0; padding: 10px 12px; border-radius: 12px; background: var(--surface-sunk); font-weight: 600; }

/* Avatars */
.portrait { border-radius: 50%; overflow: hidden; background: radial-gradient(circle at 50% 35%, #fbf3df, #e4d3ad); box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.5), 0 2px 6px rgba(30, 20, 5, 0.2); }
.portrait svg { display: block; width: 100%; height: 100%; }
.player-token { transform: translate(-50%, calc(-100% - 30px)); gap: 0; }
.player-token .character { filter: drop-shadow(0 3px 3px rgba(30, 20, 5, 0.35)); }
.player-token-name { margin-bottom: 2px; }
.player-token.travelling { animation: none; }
@keyframes bob { 50% { transform: translate(-50%, calc(-100% - 36px)); } }
.avatar-editor { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.avatar-preview { width: 104px; height: 124px; display: grid; place-items: center; border-radius: 18px; background: radial-gradient(circle at 50% 30%, #fbf3df, #e1cfa5); flex: none; }
.avatar-controls { flex: 1; min-width: 200px; display: flex; flex-direction: column; gap: 6px; }
.choice-row { display: flex; flex-wrap: wrap; gap: 8px; }
.choice { border: 2px solid var(--line); background: var(--surface); border-radius: 14px; padding: 6px; cursor: pointer; display: inline-flex; align-items: center; }
.choice.selected { border-color: var(--jade); background: var(--surface-solid); }
.segmented.choice-row { gap: 2px; }
.segmented .choice { border: 0; border-radius: 999px; padding: 7px 14px; background: transparent; font-weight: 600; font-size: 0.9rem; }
.segmented .choice.selected { background: var(--surface-solid); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15); }
.style-choice { display: inline-flex; align-items: center; gap: 6px; padding-right: 6px; font-weight: 600; font-size: 0.88rem; }
.style-choice .character { border-radius: 50%; background: #f1e5c8; }
.swatch-dot { width: 26px; height: 26px; border-radius: 50%; display: block; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.4); }

/* Scenes */
.modal-scene { width: min(620px, 100%); }
.scene-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.scene-counter { font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.scene-body { min-height: 120px; }
.scene-line { display: flex; gap: 14px; align-items: flex-start; animation: rise 0.25s ease-out; }
.scene-line.narration { font-style: italic; color: var(--muted); }
.scene-line.narration .scene-text p { font-size: 1.05rem; }
.scene-text { flex: 1; }
.scene-text p { margin: 4px 0 0; font-size: 1.08rem; line-height: 1.55; }
.speech-line .scene-text { background: var(--surface-sunk); border-radius: 16px; padding: 12px 16px; }
.scene-speaker { font-family: var(--font-display); }
.intro-bio { margin: 6px 0 0; }

/* Journal */
.modal-journal { width: min(760px, 100%); }
.journal-town { border-top: 1px solid var(--line); padding: 14px 0; display: flex; flex-direction: column; gap: 8px; }
.journal-town-head { display: flex; align-items: center; gap: 10px; }
.journal-town h3 { font-family: var(--font-display); }
.journal-entry { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px; cursor: pointer; font-weight: 600; align-self: flex-start; }
.journal-line { display: flex; gap: 10px; align-items: flex-start; }
.journal-line p { margin: 0; display: flex; flex-direction: column; font-size: 0.92rem; }
.clue { background: linear-gradient(120deg, color-mix(in srgb, var(--gold) 18%, var(--surface-solid)), var(--surface-solid)); border: 1px solid color-mix(in srgb, var(--gold) 45%, transparent); border-radius: 14px; padding: 12px; }
.clue p { margin: 4px 0 0; }

/* Map controls, town list, landmarks */
.map-controls { position: absolute; left: 16px; top: 82px; display: flex; gap: 6px; padding: 5px; border-radius: 999px; pointer-events: auto; }
.map-controls .icon-btn { font-size: 1.2rem; font-weight: 700; }
.map-scroll { touch-action: pan-x pan-y; }
.town-list { position: absolute; left: 16px; top: 140px; bottom: 16px; width: min(360px, calc(100vw - 32px)); overflow: auto; padding: 16px; animation: slide-in 0.2s ease-out; z-index: 2; }
.town-rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.town-row { width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-solid); cursor: pointer; text-align: left; }
.town-row.state-locked { opacity: 0.75; }
.town-row-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.town-row-text .muted { font-size: 0.8rem; }
.town-row-wins { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 0.85rem; }
.total-wins { font-size: 0.8rem; margin-top: 4px; }
.size-chip { margin-top: 4px; font-size: 0.78rem; }
.size-tag text { font-size: 12px; font-weight: 700; text-anchor: middle; fill: var(--muted); letter-spacing: 0.04em; }
.town-locked .size-tag { opacity: 0.7; }
.badge-new circle { fill: var(--gold); }
.badge-new text { font-size: 15px; font-weight: 800; text-anchor: middle; fill: #fff; }
.town-available .seal-bg { fill: var(--jade); }
.town-active .seal-bg { fill: var(--jade-deep); }
.town-completed .seal-bg { fill: var(--gold); }
.town-available .halo, .town-active .halo { opacity: 0.28; animation: halo 2.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.lantern-glow { opacity: 0; }
.town:not(.town-locked) .lantern-glow { opacity: 0.18; animation: lantern 3.2s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
:root[data-bg="night"] .town:not(.town-locked) .lantern-glow { opacity: 0.42; }
@keyframes lantern { 50% { opacity: 0.08; transform: scale(0.92); } }
.river-flow { fill: none; stroke: rgba(255, 255, 255, 0.55); stroke-width: 2.2; stroke-dasharray: 6 26; stroke-linecap: round; }
:root[data-bg="night"] .river-flow { stroke: rgba(170, 200, 255, 0.35); }
.lm-ink { fill: var(--mtn-line); opacity: 0.72; }
.lm-line { fill: none; stroke: var(--mtn-line); stroke-width: 2.2; stroke-linecap: round; opacity: 0.75; }
.lm-sail { fill: var(--paper); stroke: var(--mtn-line); stroke-width: 1.5; }
.lm-lantern { fill: #e2643a; stroke: #7a2a14; stroke-width: 1; animation: lantern 2.8s ease-in-out infinite; }
:root[data-bg="night"] .lm-lantern { fill: #ffb24a; }
.lm-smoke { fill: none; stroke: var(--muted); stroke-width: 2; opacity: 0.5; stroke-linecap: round; }
.lm-bell { fill: var(--gold); }
.lm-weir { fill: none; stroke: var(--sea-ink); stroke-width: 5; stroke-linecap: round; }
.lm-moon { fill: #f2e3a8; stroke: var(--mtn-line); stroke-width: 1; }
.lm-ash { fill: #8b8a84; }
.lm-bridge { fill: none; stroke: #9c4a33; stroke-width: 4; }
.lm-silk { fill: none; stroke: #c7568a; stroke-width: 2; stroke-dasharray: 4 3; }
.lm-pillar { fill: none; stroke: #2f8f72; stroke-width: 5; }
.tree-ash .pine { fill: #8a8984; }

/* Ending & epilogue */
.ending-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0 6px; }
.ending-choice { display: flex; flex-direction: column; gap: 6px; text-align: left; padding: 16px; border-radius: 16px; border: 2px solid var(--line); background: var(--surface); cursor: pointer; }
.ending-choice:hover, .ending-choice:focus-visible { border-color: var(--jade); background: var(--surface-solid); }
.ending-choice strong { font-family: var(--font-display); font-size: 1.1rem; }
.epilogue-screen { position: absolute; inset: 0; overflow: auto; padding: 84px 16px 24px; display: grid; place-items: center; }
body[data-view="epilogue"] #screen-root { background: radial-gradient(ellipse at center, var(--veil), color-mix(in srgb, var(--veil) 70%, var(--bg)) 80%); }
body[data-view="epilogue"] .map-scroll { pointer-events: none; }
.epilogue { width: min(620px, 100%); padding: 28px; text-align: center; display: flex; flex-direction: column; gap: 10px; align-items: center; animation: rise 0.6s ease-out; }
.epilogue-line { font-size: 1.08rem; line-height: 1.6; margin: 0; text-align: left; animation: rise 0.8s ease-out both; }
.epilogue-line:nth-of-type(2) { animation-delay: 0.3s; }
.epilogue-line:nth-of-type(3) { animation-delay: 0.6s; }
.epilogue-line:nth-of-type(4) { animation-delay: 0.9s; }
.ending-card strong { font-size: 1rem; }

/* Learn */
.learn-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 10px; }
.modal-learn { width: min(820px, 100%); }
.tutorial-layout { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 18px; align-items: start; margin: 8px 0; }
.tutorial-board .board-svg { width: 100%; max-width: 420px; }
.tutorial-text p { margin: 0 0 10px; line-height: 1.55; }
.tutorial-feedback { font-weight: 700; color: var(--jade-deep); min-height: 1.4em; }
:root[data-bg="night"] .tutorial-feedback { color: var(--jade); }

@media (max-width: 720px) {
  .tutorial-layout { grid-template-columns: 1fr; }
  .learn-grid, .ending-choices { grid-template-columns: 1fr; }
  .map-controls { left: 10px; top: 64px; }
  .town-list { left: 0; right: 0; bottom: 0; top: auto; width: auto; max-height: 74dvh; border-radius: 22px 22px 0 0; }
  .scoring-actions { grid-template-columns: 1fr; }
}
.reduce-motion .river-flow, .reduce-motion .lantern-glow, .reduce-motion .lm-lantern { animation: none !important; }

/* ---------- northern circuits on the map ---------- */
.city-wall { fill: color-mix(in srgb, var(--gold) 8%, transparent); stroke: var(--mtn-line); stroke-width: 3; stroke-dasharray: 2 7; stroke-linecap: round; opacity: 0.7; }
.palace-wall { fill: color-mix(in srgb, var(--jade) 9%, transparent); stroke: var(--gold); stroke-width: 3; stroke-dasharray: 14 6; opacity: 0.7; }
.town.grand .seal-ring { stroke: var(--gold); stroke-width: 4; }

/* ---------- board zoom (touch screens) ---------- */
/* Only the board magnifies. The frame keeps its size and clips; inside it the whole SVG (grid,
   stones, markers) is one layer moved by a CSS transform, so match controls and scores stay as
   they are and a pinch never re-lays-out or redraws the board. No transition: the board must
   follow the fingers exactly. */
.board-wrap { flex-direction: column; gap: 10px; min-width: 0; }
.board-stage { display: flex; justify-content: center; align-items: center; width: 100%; min-width: 0; }
.board-frame {
  position: relative; overflow: hidden; contain: layout paint; isolation: isolate; flex: none;
  aspect-ratio: 1;
  border-radius: 14px; box-shadow: 0 22px 50px rgba(40, 24, 6, 0.35), 0 3px 8px rgba(40, 24, 6, 0.25);
}
.board-frame:has(> .board-svg:focus-visible) { box-shadow: 0 0 0 4px var(--focus), 0 22px 50px rgba(40, 24, 6, 0.35); }
.board-frame > .board-svg { width: 100%; max-width: none; min-width: 0; border-radius: 0; box-shadow: none; transform-origin: 0 0; }
/* Promoted only while fingers are down: moving it is then compositor-only. Dropped afterwards so
   the browser redraws the board sharp at the new scale. */
.board-frame.gesturing > .board-svg { will-change: transform; }
/* At 1× one finger still scrolls the page; two fingers zoom the board, never the page.
   Zoomed in, the board keeps every touch so one finger pans it. */
.board-svg.zoomable { touch-action: pan-x pan-y; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
.board-svg.zoomable.zoomed { touch-action: none; }
.board-zoom-controls { display: flex; align-items: center; gap: 6px; flex: none; }
.zoom-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 44px; height: 44px; padding: 0 10px; border-radius: 12px;
  border: 1px solid var(--line-strong); background: var(--surface-solid); color: var(--text);
  font-weight: 650; font-size: 0.88rem; cursor: pointer; touch-action: manipulation;
}
.zoom-btn:active:not(:disabled) { background: var(--surface-sunk); }
.zoom-btn:disabled { opacity: 0.4; cursor: default; }
.zoom-btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.zoom-level { min-width: 3.2em; font-size: 0.82rem; font-weight: 650; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.touch-board .board-stage { flex-direction: column; gap: 8px; }
.touch-board .board-zoom-controls { align-self: center; }

/* Landscape: controls in a column beside the board, and the board sized to the screen height. */
@media (orientation: landscape) {
  .touch-board .board-stage { flex-direction: row; gap: 10px; }
  .touch-board .board-zoom-controls { flex-direction: column; }
  .touch-board .zoom-fit-label { display: none; }
  .touch-board .board-frame { width: min(100% - 64px, calc(100dvh - 110px), 760px); min-width: 240px; }
}
@media (orientation: landscape) and (max-width: 900px) {
  .touch-board .board-frame { width: min(100% - 64px, calc(100dvh - 84px), 620px); }
}
/* Short landscape screens (phones on their side): the tip goes beside the board instead of
   above it, so the whole board stays on screen. */
@media (orientation: landscape) and (max-height: 560px) {
  .touch-board .board-wrap { flex-direction: row; justify-content: center; align-items: center; gap: 12px; }
  .touch-board .board-stage { width: auto; flex: none; }
  .touch-board .board-frame { width: min(calc(100dvh - 84px), 620px); }
  .touch-board .zoom-tip { flex-direction: column; align-items: stretch; width: auto; max-width: 240px; flex: 0 1 240px; }
  .touch-board .zoom-tip-ok { align-self: flex-end; }
}

.zoom-tip {
  display: flex; align-items: center; gap: 12px;
  width: min(100%, 560px); padding: 10px 10px 10px 14px; border-radius: 14px;
  background: linear-gradient(120deg, #2f8f72 0%, #1d6a56 55%, #12473a 100%);
  color: #f4fbf7; border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 8px 22px rgba(18, 71, 58, 0.28);
  animation: tip-in 0.24s ease-out;
}
@keyframes tip-in { from { opacity: 0; transform: translateY(6px); } }
.zoom-tip-text { flex: 1; min-width: 0; }
.zoom-tip strong { display: block; font-size: 0.95rem; line-height: 1.25; }
.zoom-tip p { margin: 2px 0 0; font-size: 0.84rem; line-height: 1.35; color: rgba(244, 251, 247, 0.92); }
.zoom-tip-ok {
  flex: none; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 0;
  background: #f4fbf7; color: #12473a; font-weight: 700; cursor: pointer; touch-action: manipulation;
}
.zoom-tip-ok:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

/* ---------- Profile & Settings tabs, Metrics dashboard ---------- */
.tabs { display: flex; gap: 4px; padding: 3px; margin: 8px 0 4px; border-radius: 999px; background: var(--surface-sunk); align-self: flex-start; }
.tab { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 16px; border: 0; border-radius: 999px; background: transparent; font-weight: 650; cursor: pointer; color: var(--muted); }
.tab[aria-selected="true"] { background: var(--surface-solid); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15); }
.tab:hover { color: var(--text); }
.tab-panel:focus-visible { outline-offset: 4px; border-radius: 8px; }
.modal-settings.modal-metrics { width: min(860px, 100%); }

.metrics {
  --win: #178a68; --loss: #c4452e; --draw: #5a68c8; --hatch: rgba(255, 255, 255, 0.55);
  display: flex; flex-direction: column; gap: 14px; padding-top: 10px;
}
:root[data-bg="night"] .metrics { --win: #34a882; --loss: #e2694d; --draw: #7f8de6; --hatch: rgba(20, 26, 40, 0.55); }
.metrics-private { margin: 0; font-size: 0.86rem; }
.metrics-filters { display: flex; flex-wrap: wrap; gap: 8px 12px; }
.metrics-seg .choice { min-height: 38px; }
.metrics-body { display: flex; flex-direction: column; gap: 14px; transition: opacity 0.15s; }
.metrics-body.loading { opacity: 0.6; }
.metrics-loading, .metrics-error { padding: 24px 0; text-align: center; }
.metrics-dash { display: flex; flex-direction: column; gap: 16px; }
.metric-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.metric-card { padding: 12px 14px; border-radius: 14px; background: var(--surface-sunk); border: 1px solid var(--line); min-width: 0; }
.metric-label { margin: 0; font-size: 0.78rem; font-weight: 650; color: var(--muted); }
.metric-value { margin: 4px 0 2px; font-family: var(--font-display); font-weight: 700; font-size: 1.5rem; line-height: 1.15; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metric-card.unavailable .metric-value { font-family: var(--font-ui); font-size: 1rem; font-weight: 650; color: var(--muted); padding: 6px 0 3px; }
.metric-sub { margin: 0; font-size: 0.78rem; line-height: 1.35; }
.metrics-notes { margin: -6px 0 0; }
.metrics-charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.metrics-chart { padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); min-width: 0; }
.chart-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; }
.chart-head h4, .metrics-section h4 { margin: 0; font-size: 0.95rem; }
.chart-axis { margin: 2px 0 4px; font-size: 0.75rem; }
.chart-legend { display: flex; gap: 10px; margin: 0; padding: 0; list-style: none; font-size: 0.8rem; }
.chart-legend li { display: inline-flex; align-items: center; gap: 5px; }
.legend-swatch { border-radius: 3px; }
.chart-plot { position: relative; border-radius: 8px; touch-action: pan-y; }
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-axes text { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart-axes .grid { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-axes .baseline { stroke: var(--line-strong); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-svg .fill-win, .legend-swatch .fill-win { fill: var(--win); }
.chart-svg .fill-loss, .legend-swatch .fill-loss { fill: var(--loss); }
.chart-svg .fill-draw, .legend-swatch .fill-draw { fill: var(--draw); }
.chart-svg .hatch, .legend-swatch .hatch { stroke: var(--hatch); stroke-width: 2.2; }
.chart-svg .dot, .legend-swatch .dot { fill: var(--hatch); }
.chart-svg .hit { fill: transparent; cursor: pointer; }
.chart-svg .bar.active .hit, .chart-svg .pt.active .hit { fill: color-mix(in srgb, var(--text) 7%, transparent); }
.pace-line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.pace-dot { fill: var(--accent); stroke: var(--surface-solid); stroke-width: 2; vector-effect: non-scaling-stroke; }
.crosshair { stroke: var(--line-strong); stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.chart-tip {
  position: absolute; z-index: 2; pointer-events: none; display: flex; flex-direction: column; gap: 1px;
  padding: 6px 10px; border-radius: 10px; background: var(--surface-solid); border: 1px solid var(--line-strong);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18); font-size: 0.8rem; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.chart-tip[hidden] { display: none; }
.chart-empty { margin: 0; padding: 40px 8px; text-align: center; font-size: 0.88rem; }
.chart-table { margin-top: 6px; font-size: 0.82rem; }
.chart-table summary { cursor: pointer; color: var(--muted); font-weight: 600; padding: 4px 0; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.metrics table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.metrics th, .metrics td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.metrics thead th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 650; }
.metrics tbody th { font-weight: 600; white-space: nowrap; }
.metrics-section { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.section-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.lifetime-chip { font-size: 0.72rem; padding: 2px 10px; }
.life-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 0; }
.life-grid div { padding: 10px 12px; border-radius: 12px; background: var(--surface-sunk); }
.life-grid dt { font-size: 0.75rem; color: var(--muted); font-weight: 650; }
.life-grid dd { margin: 3px 0 0; font-weight: 700; }
.level-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin: 0; padding: 0; list-style: none; }
.level-cell { display: flex; flex-direction: column; padding: 6px 8px; border-radius: 10px; background: var(--surface-sunk); font-size: 0.8rem; }
.level-cell.empty { opacity: 0.6; }
.level-n { color: var(--muted); font-size: 0.72rem; font-weight: 650; }
.level-rec { font-weight: 650; font-variant-numeric: tabular-nums; }
.result-cell { display: flex; flex-direction: column; gap: 2px; }
.result-pill { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; }
.result-mark { font-size: 0.8em; }
.result-win .result-mark { color: var(--win); }
.result-loss .result-mark { color: var(--loss); }
.result-draw .result-mark { color: var(--draw); }
.result-skip { font-weight: 600; color: var(--muted); }
.result-detail { font-size: 0.78rem; }
.metrics-empty { text-align: center; padding: 28px 12px 18px; }
.metrics-empty-art { font-family: var(--font-display); font-size: 2.4rem; width: 72px; height: 72px; margin: 0 auto 10px; display: grid; place-items: center; border-radius: 50%; background: var(--surface-sunk); color: var(--jade-deep); }
.metrics-empty h4 { margin: 0 0 6px; font-size: 1.05rem; }

@media (max-width: 720px) {
  .metric-cards, .life-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metrics-charts { grid-template-columns: 1fr; }
  .level-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 400px) {
  .level-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metric-value { font-size: 1.25rem; }
  .tab { padding: 0 12px; }
}
@media (forced-colors: active) {
  .chart-svg .fill-win, .chart-svg .fill-loss, .chart-svg .fill-draw { fill: CanvasText; }
  .chart-svg .hatch, .chart-svg .dot { stroke: Canvas; fill: Canvas; }
}
/* Phones: each recent match is a small labelled card instead of a wide table row. */
@media (max-width: 560px) {
  .recent-table thead { display: none; }
  .recent-table tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 14px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .metrics .recent-table th, .metrics .recent-table td { border: 0; padding: 0; }
  .recent-table tbody th { grid-column: 1 / -1; }
  .recent-table td::before { content: attr(data-label); display: block; font-size: 0.68rem; font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
}
