/* WordTwist styles. Each language has its own theme, set by body[data-theme]:
   en  - the old library: navy reading room, cream paper cubes, brass and walnut.
   yue - Hong Kong neon nights: rain-dark streets, glowing pink, red and teal signs.
   tl  - fiesta in the barrio: banderitas flags, jeepney colours and chrome, woven banig mats.
   nl  - Delft blue: glazed white tiles with cobalt drawing, canal houses and tulips.
   home - all four together. */

:root {
  --radius: 14px;
  --ease: cubic-bezier(.2, .9, .25, 1.15);
  --font-ui: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;

  --bg: #16131f; --bg-2: #241d33; --ink: #f5f1ea; --muted: #b9b0c8; --panel: rgba(255,255,255,.06); --panel-line: rgba(255,255,255,.12);
  --accent: #f2c14e; --accent-ink: #1b1520; --accent-2: #ff3b7f;
  --frame: linear-gradient(160deg, #2c2540, #15111d); --frame-line: rgba(255,255,255,.14);
  --tile-bg: #f4efe2; --tile-ink: #1b1520; --tile-edge: #c9bfa8; --tile-glow: transparent;
  --font-display: "Fraunces", Georgia, serif; --font-tile: "Inter", system-ui, sans-serif; --tile-weight: 800;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh;
  background: var(--bg); color: var(--ink);
  font: 16px/1.5 var(--font-ui);
  overflow-x: hidden;
}
a { color: inherit; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- Scenery behind everything ---------- */
.scene, .scene-a, .scene-b { position: fixed; inset: 0; pointer-events: none; }
.scene { z-index: 0; background: radial-gradient(1200px 700px at 50% -10%, var(--bg-2), transparent 70%), var(--bg); }
.topbar, main, .toast { position: relative; z-index: 1; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  max-width: 1100px; margin: 0 auto; padding: 14px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-cubes { display: grid; grid-template-columns: repeat(2, 13px); gap: 3px; transform: rotate(-8deg); }
.brand-cubes i { width: 13px; height: 13px; border-radius: 3px; background: #f2c14e; box-shadow: inset 0 -2px 0 rgba(0,0,0,.25); }
.brand-cubes i:nth-child(2) { background: #ff3b7f; } .brand-cubes i:nth-child(3) { background: #1c5bd6; } .brand-cubes i:nth-child(4) { background: #f4efe2; }
.brand-name { font: 700 1.35rem/1 var(--font-display); letter-spacing: -.01em; }
.brand-name b { color: var(--accent); font-weight: 900; }
.nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.nav a, .sound {
  text-decoration: none; padding: 8px 12px; border-radius: 999px; font-weight: 600; font-size: .92rem;
  border: 1px solid transparent; background: none; cursor: pointer;
}
.nav a:hover, .sound:hover { background: var(--panel); }
.nav a[aria-current="page"] { background: var(--panel); border-color: var(--panel-line); }
.sound { border-color: var(--panel-line); }
.sound[aria-pressed="false"] { opacity: .6; }

main { max-width: 1100px; margin: 0 auto; padding: 8px 16px 64px; outline: none; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.1; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border-radius: 12px; border: 0; cursor: pointer; text-decoration: none;
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
  box-shadow: 0 3px 0 rgba(0,0,0,.25); transition: transform .12s ease, box-shadow .12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.25); }
.btn.ghost { background: var(--panel); color: var(--ink); border: 1px solid var(--panel-line); box-shadow: none; }
.btn[disabled] { opacity: .55; cursor: default; transform: none; }

/* ---------- Home ---------- */
.hero { text-align: center; padding: 28px 0 8px; }
.hero h1 { font-size: clamp(2.6rem, 9vw, 5rem); margin: 0; font-weight: 900; }
.hero h1 .tw { display: inline-block; color: var(--accent); transform: rotate(-3deg); }
.hero p { max-width: 560px; margin: 12px auto 0; color: var(--muted); font-size: 1.08rem; }
.how { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 28px auto 8px; max-width: 860px; }
.how div { background: var(--panel); border: 1px solid var(--panel-line); border-radius: var(--radius); padding: 14px 16px; }
.how b { display: block; font-family: var(--font-display); font-size: 1.1rem; margin-bottom: 2px; }
.how span { color: var(--muted); font-size: .94rem; }
.langs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 28px; }
.lang-card {
  position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 10px; min-height: 230px;
  padding: 20px; border-radius: 20px; text-decoration: none; isolation: isolate;
  box-shadow: 0 10px 30px rgba(0,0,0,.35); transition: transform .2s var(--ease), box-shadow .2s ease;
}
.lang-card:hover { transform: translateY(-4px) rotate(-.4deg); box-shadow: 0 16px 40px rgba(0,0,0,.45); }
.lang-card .native { font-size: 2.1rem; font-weight: 900; line-height: 1; }
.lang-card .name { font-size: .95rem; font-weight: 600; opacity: .85; }
.lang-card .tagline { font-size: .95rem; opacity: .85; }
.lang-card .mini { display: flex; gap: 6px; margin-top: auto; }
.lang-card .mini span { padding: 6px 9px; border-radius: 8px; font-weight: 800; font-size: .95rem; }
.lang-card .stats { display: flex; gap: 14px; font-size: .88rem; font-weight: 600; }
.lang-card .bar { height: 6px; border-radius: 99px; background: rgba(0,0,0,.25); overflow: hidden; }
.lang-card .bar i { display: block; height: 100%; width: var(--p, 0%); background: currentColor; border-radius: 99px; }
.lang-card .go { position: absolute; right: 18px; top: 18px; font-weight: 800; font-size: .85rem; padding: 6px 10px; border-radius: 99px; background: rgba(255,255,255,.18); }

.lang-card.en { color: #f4ead2; background: linear-gradient(160deg, #1f2a44, #121a2e); font-family: "Playfair Display", serif; }
.lang-card.en::before { content: ""; position: absolute; inset: auto 0 0 0; height: 70px; z-index: -1; opacity: .5;
  background: repeating-linear-gradient(90deg, #6b3f25 0 14px, #8a5532 14px 22px, #3b5a7a 22px 34px, #7a2f2f 34px 44px, #c9a45b 44px 50px, #2f4a3a 50px 62px); }
.lang-card.en .mini span { background: #f4ead2; color: #1f2a44; box-shadow: inset 0 0 0 2px #c9a45b; }
.lang-card.yue { color: #ffe9f3; background: linear-gradient(170deg, #1a0b26, #07040c); font-family: "Noto Sans HK", sans-serif; box-shadow: 0 0 0 2px #ff3b7f inset, 0 10px 30px rgba(0,0,0,.4); }
.lang-card.yue .native { color: #ff5c95; text-shadow: 0 0 8px #ff3b7f, 0 0 22px #ff3b7f; }
.lang-card.yue::before { content: "香港"; position: absolute; right: 16px; bottom: 50px; writing-mode: vertical-rl; font-size: 2.6rem; font-weight: 900; color: #3ff0e0; opacity: .85; text-shadow: 0 0 8px #18d4c4, 0 0 24px #18d4c4; z-index: -1; }
.lang-card.yue .mini span { background: #12081c; color: #ffd1e4; box-shadow: 0 0 0 1.5px #ff3b7f, 0 0 12px rgba(255,59,127,.5); }
.lang-card.tl { color: #2a1600; font-family: "Baloo 2", sans-serif;
  background: repeating-linear-gradient(45deg, rgba(255,255,255,.18) 0 10px, transparent 10px 20px), repeating-linear-gradient(-45deg, rgba(206,17,38,.18) 0 10px, transparent 10px 20px), linear-gradient(160deg, #ffd23f, #ff9f1c); }
.lang-card.tl::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 22px; z-index: -1;
  background: conic-gradient(from 135deg at 50% 0, #ce1126 0 90deg, transparent 0) 0 0/24px 22px, conic-gradient(from 135deg at 50% 0, #0038a8 0 90deg, transparent 0) 12px 0/24px 22px; }
.lang-card.tl .native { margin-top: 12px; color: #0038a8; }
.lang-card.tl .mini span { background: #ce1126; color: #fff; box-shadow: inset 0 0 0 2px #e8e8e8, 0 2px 0 #7a0a17; }
.lang-card.tl .mini span:nth-child(2) { background: #0038a8; box-shadow: inset 0 0 0 2px #e8e8e8, 0 2px 0 #001f5e; }
.lang-card.nl { color: #163a8c; font-family: "Fraunces", serif;
  background: radial-gradient(circle at 0 0, #1c4fb8 0 9px, transparent 10px) 0 0/44px 44px, radial-gradient(circle at 100% 100%, #1c4fb8 0 9px, transparent 10px) 0 0/44px 44px, linear-gradient(#f7f9fd, #e9eef8); }
.lang-card.nl .mini span { background: #fff; color: #163a8c; box-shadow: inset 0 0 0 2px #1c4fb8; }
.lang-card.nl .go, .lang-card.tl .go { background: rgba(0,0,0,.08); }

/* ---------- Game ---------- */
.game { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 300px); gap: 24px; align-items: start; margin-top: 4px; }
.game-main { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.lang-title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; justify-content: center; margin: 0 0 10px; }
.lang-title h1 { margin: 0; font-size: clamp(1.6rem, 5vw, 2.3rem); }
.lang-title span { color: var(--muted); font-weight: 600; }
.hud { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; width: min(100%, 560px); margin-bottom: 12px; }
.hud div { background: var(--panel); border: 1px solid var(--panel-line); border-radius: 12px; padding: 8px 10px; text-align: center; }
.hud small { display: block; color: var(--muted); font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.hud b { font: 800 1.45rem/1.15 var(--font-display); font-variant-numeric: tabular-nums; }
.hud .low b { color: var(--accent-2); }

/* The cube stage: the 3D cube fills a square with the language's frame around it. */
.frame {
  position: relative; width: min(100%, 560px); aspect-ratio: 1 / 1; border-radius: 28px; background: var(--frame);
  box-shadow: 0 0 0 1px var(--frame-line) inset, 0 18px 50px rgba(0,0,0,.45);
  touch-action: none; user-select: none; -webkit-user-select: none; overflow: hidden;
}
.cube-host { position: absolute; inset: 0; outline: none; }
.cube-host:focus-visible { box-shadow: inset 0 0 0 3px var(--accent); border-radius: 28px; }
.cube-canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.cube-canvas:active { cursor: grabbing; }
.face-tag { position: absolute; left: 12px; top: 10px; z-index: 2; font-size: .78rem; font-weight: 700; color: rgba(255,255,255,.72); text-shadow: 0 1px 2px rgba(0,0,0,.6); pointer-events: none; }

.controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; width: min(100%, 560px); }
.controls .group { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--panel); border: 1px solid var(--panel-line); }
.controls button {
  border: 0; border-radius: 10px; min-width: 44px; min-height: 44px; padding: 0 12px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: rgba(255,255,255,.08); color: var(--ink); font: 700 .92rem var(--font-ui);
}
.controls button:hover { background: rgba(255,255,255,.18); }
.controls button[disabled] { opacity: .4; cursor: default; }
.controls button svg { width: 16px; height: 16px; fill: currentColor; }
.controls .label { align-self: center; font-size: .75rem; font-weight: 700; color: var(--muted); padding: 0 4px 0 6px; text-transform: uppercase; letter-spacing: .05em; }

.clues { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.clue { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 4px 10px; align-items: center; padding: 8px 10px 8px 6px; border-radius: 12px; background: rgba(255,255,255,.05); border: 1px solid var(--panel-line); }
.clue .hear { grid-row: span 2; width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); }
.clue .hear svg { width: 18px; height: 18px; fill: currentColor; }
.clue .m { font-size: .92rem; line-height: 1.25; }
.clue .boxes { display: flex; gap: 4px; flex-wrap: wrap; }
.clue .boxes span { min-width: 30px; padding: 3px 7px; border-radius: 7px; text-align: center; font-weight: 800; font-size: .9rem; background: rgba(0,0,0,.22); color: var(--muted); }
.clue .boxes span small { display: block; font-size: .62rem; font-weight: 600; opacity: .85; }
.clue.hinted .boxes span { color: #ff2bd6; background: rgba(255,43,214,.12); }
.clue.found { border-color: var(--accent); }
.clue.found .boxes span { background: var(--accent); color: var(--accent-ink); }
.clue.found .m::after { content: "  \2713"; color: var(--accent); font-weight: 900; }
body[data-theme="yue"] .clue .boxes span { font-family: "Noto Sans HK", sans-serif; }
.stars { color: var(--accent); letter-spacing: .1em; }
.dialog .stars { font-size: 2rem; text-align: center; margin: 4px 0; }
.keys { margin: 10px 0 0; color: var(--muted); font-size: .82rem; line-height: 1.45; }
.keys kbd { font: 700 .78rem var(--font-ui); padding: 1px 5px; border-radius: 5px; border: 1px solid var(--panel-line); background: rgba(255,255,255,.06); }
@keyframes arrive { from { opacity: 0; scale: .2; rotate: -30deg; } }

.float {
  position: absolute; left: 50%; top: 45%; z-index: 5; translate: -50% -50%; pointer-events: none; text-align: center;
  font: 900 clamp(1.6rem, 6vw, 2.4rem)/1 var(--font-display); color: var(--accent); text-shadow: 0 3px 0 rgba(0,0,0,.4), 0 0 20px rgba(0,0,0,.4);
  animation: float 1.2s ease forwards;
}
.float small { display: block; font-size: .5em; margin-top: 4px; color: var(--ink); }
@keyframes float { from { opacity: 0; translate: -50% -20%; } 15% { opacity: 1; translate: -50% -50%; } 75% { opacity: 1; } to { opacity: 0; translate: -50% -110%; } }

.say { min-height: 3.2em; margin: 14px 0 6px; text-align: center; max-width: 420px; }
.say .word { font: 700 1.25rem/1.2 var(--font-display); }
.say .meaning { color: var(--muted); }
.game-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 16px; }
@media (hover: none) { .keys { display: none; } }

.side { background: var(--panel); border: 1px solid var(--panel-line); border-radius: 18px; padding: 16px; }
.side h2 { margin: 0 0 4px; font-size: 1.2rem; }
.side ol { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: .92rem; }
.side ol li { margin: 4px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  border: 1px solid var(--panel-line); background: rgba(255,255,255,.06); border-radius: 999px; padding: 5px 10px 5px 8px; cursor: pointer;
  font-weight: 700; font-size: .9rem; display: inline-flex; align-items: center; gap: 6px; animation: arrive .4s var(--ease) both;
}
.chip svg { width: 13px; height: 13px; fill: currentColor; opacity: .7; }
.empty { color: var(--muted); font-size: .92rem; margin: 8px 0 0; }

/* ---------- Round over ---------- */
.dialog-back { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(5,3,10,.6); backdrop-filter: blur(4px); animation: fade .25s ease; }
.dialog { width: min(440px, 100%); max-height: calc(100dvh - 32px); overflow: auto; background: var(--bg); color: var(--ink); border: 1px solid var(--panel-line); border-radius: 22px; padding: 22px; box-shadow: 0 30px 80px rgba(0,0,0,.6); animation: arrive .4s var(--ease) both; }
.dialog h2 { margin: 0; font-size: 1.8rem; }
.dialog .big { font: 900 3.2rem/1 var(--font-display); color: var(--accent); margin: 8px 0 2px; }
.dialog form { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.dialog input { flex: 1 1 160px; min-width: 0; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--panel-line); background: rgba(255,255,255,.06); color: var(--ink); font: inherit; }
.dialog .row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.dialog .note { min-height: 1.4em; margin: 8px 0 0; font-size: .92rem; color: var(--muted); }
@keyframes fade { from { opacity: 0; } }

/* ---------- Tabs (library and leaderboard) ---------- */
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 12px 0 16px; }
.page-head h1 { margin: 0; font-size: clamp(2rem, 6vw, 3rem); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs a { text-decoration: none; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--panel-line); background: var(--panel); font-weight: 700; font-size: .92rem; }
.tabs a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* ---------- Library ---------- */
.progress { display: flex; align-items: center; gap: 16px; background: var(--panel); border: 1px solid var(--panel-line); border-radius: 18px; padding: 14px 18px; margin-bottom: 14px; flex-wrap: wrap; }
.ring { --p: 0; width: 74px; height: 74px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: radial-gradient(closest-side, var(--bg) 78%, transparent 80% 100%), conic-gradient(var(--accent) calc(var(--p) * 1%), rgba(255,255,255,.12) 0); }
.ring b { font: 800 1.05rem/1 var(--font-display); }
.progress .txt { flex: 1 1 200px; min-width: 0; }
.progress .txt b { font-family: var(--font-display); font-size: 1.2rem; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filters button { border: 1px solid var(--panel-line); background: none; border-radius: 999px; padding: 6px 12px; cursor: pointer; font-weight: 600; font-size: .88rem; }
.filters button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 12px; }
.card {
  position: relative; display: flex; flex-direction: column; gap: 6px; min-height: 150px; padding: 14px; border-radius: 16px;
  background: var(--tile-bg); color: var(--tile-ink); box-shadow: inset 0 0 0 2px var(--tile-edge), 0 4px 0 rgba(0,0,0,.25), 0 0 14px var(--tile-glow);
  text-align: left; border: 0; cursor: pointer; transition: transform .15s var(--ease);
}
.card:hover { transform: translateY(-3px) rotate(-.5deg); }
.card .num { position: absolute; right: 12px; top: 10px; font-size: .75rem; font-weight: 700; opacity: .55; }
.card .script { font: 900 2rem/1 "Noto Sans HK", sans-serif; }
.card .w { font: var(--tile-weight) 1.35rem/1.1 var(--font-tile); overflow-wrap: anywhere; }
.card .parts { display: flex; gap: 4px; flex-wrap: wrap; }
.card .parts span { font-size: .72rem; font-weight: 800; padding: 3px 6px; border-radius: 6px; background: rgba(0,0,0,.08); box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); text-transform: uppercase; }
.card .m { font-size: .86rem; opacity: .8; }
.card .meta { margin-top: auto; display: flex; justify-content: space-between; align-items: center; font-size: .78rem; font-weight: 700; opacity: .75; }
.card .meta svg { width: 16px; height: 16px; fill: currentColor; }
.card.locked { background: rgba(255,255,255,.04); color: var(--muted); box-shadow: inset 0 0 0 1.5px var(--panel-line); cursor: default; }
.card.locked:hover { transform: none; }
.card.locked .q { display: flex; gap: 6px; margin-top: 6px; }
.card.locked .q span { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; font-weight: 800; background: rgba(255,255,255,.06); box-shadow: inset 0 0 0 1px var(--panel-line); }

/* ---------- Leaderboard ---------- */
.podium { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; align-items: end; margin: 8px 0 18px; }
.podium .p { text-align: center; padding: 14px 8px; border-radius: 16px 16px 8px 8px; background: var(--panel); border: 1px solid var(--panel-line); min-width: 0; }
.podium .p .medal { width: 46px; height: 46px; margin: 0 auto 6px; border-radius: 12px; display: grid; place-items: center; font: 900 1.3rem/1 var(--font-display); color: #1b1520; box-shadow: inset 0 -4px 0 rgba(0,0,0,.2), 0 3px 0 rgba(0,0,0,.25); transform: rotate(-6deg); }
.podium .p1 { padding-top: 30px; } .podium .p1 .medal { background: #f2c14e; width: 56px; height: 56px; }
.podium .p2 .medal { background: #d6dbe4; } .podium .p3 .medal { background: #d08a4d; }
.podium .nm { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.podium .sc { font: 800 1.4rem/1.1 var(--font-display); color: var(--accent); }
.ranks { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ranks li { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding: 10px 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--panel-line); }
.ranks li.me { border-color: var(--accent); }
.ranks .r { font-weight: 800; color: var(--muted); }
.ranks .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranks .lg { font-size: .78rem; font-weight: 700; padding: 3px 8px; border-radius: 99px; background: rgba(255,255,255,.1); }
.ranks .sc { font: 800 1.1rem/1 var(--font-display); font-variant-numeric: tabular-nums; }
.yours { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 22px; }
.yours div { background: var(--panel); border: 1px solid var(--panel-line); border-radius: 14px; padding: 12px; }
.yours small { color: var(--muted); font-weight: 600; } .yours b { display: block; font: 800 1.3rem/1.2 var(--font-display); }

.toast { position: fixed; left: 50%; bottom: 20px; translate: -50% 0; z-index: 30; max-width: min(92vw, 520px); padding: 10px 16px; border-radius: 12px; background: #0b0910; color: #f5f1ea; font-weight: 600; font-size: .92rem; box-shadow: 0 10px 30px rgba(0,0,0,.4); opacity: 0; pointer-events: none; transition: opacity .25s ease, translate .25s ease; }
.toast.show { opacity: 1; translate: -50% -6px; }
.noscript { text-align: center; padding: 40px; }

/* ---------- Themes ---------- */

/* English: the old library */
body[data-theme="en"] {
  --bg: #121a2e; --bg-2: #24345a; --ink: #f4ead2; --muted: #b8b09b; --panel: rgba(244,234,210,.07); --panel-line: rgba(201,164,91,.3);
  --accent: #d9b25f; --accent-ink: #1a1408; --accent-2: #e57a5a;
  --frame: linear-gradient(160deg, #5a3520, #3a2114 60%, #2a170d); --frame-line: rgba(217,178,95,.55);
  --tile-bg: linear-gradient(180deg, #faf3e0, #efe3c4); --tile-ink: #1f2a44; --tile-edge: #c9a45b;
  --font-display: "Playfair Display", Georgia, serif; --font-tile: "Playfair Display", Georgia, serif; --tile-weight: 800;
}
body[data-theme="en"] .scene-a { top: auto; height: 110px; opacity: .16;
  -webkit-mask-image: linear-gradient(transparent, #000 70%); mask-image: linear-gradient(transparent, #000 70%);
  background: repeating-linear-gradient(90deg, #6b3f25 0 18px, #8a5532 18px 28px, #3b5a7a 28px 44px, #7a2f2f 44px 58px, #c9a45b 58px 64px, #2f4a3a 64px 80px, #4a2a5a 80px 92px); }
body[data-theme="en"] .scene-b { background: radial-gradient(500px 300px at 85% 10%, rgba(255,214,140,.14), transparent 70%); }
body[data-theme="en"] .card.v1 { --tile-bg: linear-gradient(180deg, #f6ecd2, #e8d8b2); }
body[data-theme="en"] .card.v2 { --tile-bg: linear-gradient(180deg, #fbf6e8, #f1e6cc); --tile-ink: #5a1f1f; }
body[data-theme="en"] .card.v3 { --tile-bg: linear-gradient(180deg, #f3e7c9, #e2cfa4); --tile-ink: #2f4a3a; }

/* Cantonese: Hong Kong neon nights */
body[data-theme="yue"] {
  --bg: #07040c; --bg-2: #2a0d33; --ink: #ffeef6; --muted: #c4a8c8; --panel: rgba(255,59,127,.06); --panel-line: rgba(255,92,149,.3);
  --accent: #3ff0e0; --accent-ink: #04140f; --accent-2: #ff3b7f;
  --frame: linear-gradient(160deg, #1a0f22, #0a0610); --frame-line: rgba(255,59,127,.7);
  --tile-bg: linear-gradient(180deg, #1d0f28, #120819); --tile-ink: #ffd1e4; --tile-edge: #ff3b7f; --tile-glow: rgba(255,59,127,.55);
  --font-display: "Noto Sans HK", sans-serif; --font-tile: "Inter", sans-serif; --tile-weight: 800;
}
body[data-theme="yue"] .card.v1 { --tile-edge: #3ff0e0; --tile-ink: #c9fff9; --tile-glow: rgba(63,240,224,.45); }
body[data-theme="yue"] .card.v2 { --tile-edge: #ffb627; --tile-ink: #ffe7b8; --tile-glow: rgba(255,182,39,.45); }
body[data-theme="yue"] .card.v3 { --tile-edge: #b56cff; --tile-ink: #ecd9ff; --tile-glow: rgba(181,108,255,.45); }
body[data-theme="yue"] .scene-a { opacity: .5; background: repeating-linear-gradient(100deg, transparent 0 22px, rgba(160,200,255,.05) 22px 23px, transparent 23px 60px); animation: rain 1.4s linear infinite; }
body[data-theme="yue"] .scene-b::before, body[data-theme="yue"] .scene-b::after {
  position: absolute; writing-mode: vertical-rl; font: 900 clamp(2.4rem, 7vw, 4.6rem)/1 "Noto Sans HK", sans-serif; padding: 14px 6px; border-radius: 10px; opacity: .55; }
body[data-theme="yue"] .scene-b::before { content: "茶餐廳"; left: 2vw; top: 110px; color: #ff5c95; border: 3px solid #ff3b7f; text-shadow: 0 0 10px #ff3b7f, 0 0 30px #ff3b7f; box-shadow: 0 0 18px rgba(255,59,127,.6), inset 0 0 18px rgba(255,59,127,.4); animation: flicker 5s infinite; }
body[data-theme="yue"] .scene-b::after { content: "香港"; right: 2vw; top: 260px; color: #3ff0e0; border: 3px solid #18d4c4; text-shadow: 0 0 10px #18d4c4, 0 0 30px #18d4c4; box-shadow: 0 0 18px rgba(24,212,196,.6), inset 0 0 18px rgba(24,212,196,.4); }
body[data-theme="yue"] .frame { box-shadow: 0 0 0 2px #ff3b7f inset, 0 0 30px rgba(255,59,127,.35), 0 18px 50px rgba(0,0,0,.6); }
body[data-theme="yue"] .card .w { text-transform: none; }
@keyframes rain { to { background-position: 60px 400px; } }
@keyframes flicker { 0%, 92%, 96%, 100% { opacity: .55; } 94% { opacity: .2; } }

/* Tagalog: fiesta in the barrio */
body[data-theme="tl"] {
  --bg: #fff3d6; --bg-2: #ffd98a; --ink: #2a1600; --muted: #7a5a2c; --panel: rgba(255,255,255,.6); --panel-line: rgba(122,90,44,.25);
  --accent: #ce1126; --accent-ink: #fff; --accent-2: #ce1126;
  --frame: linear-gradient(180deg, #f2f2f2, #b9bec6 45%, #e8eaee 55%, #9aa1ab); --frame-line: rgba(0,0,0,.25);
  --tile-bg: linear-gradient(180deg, #e3172f, #b80e22); --tile-ink: #fff; --tile-edge: #f4f4f4;
  --font-display: "Baloo 2", sans-serif; --font-tile: "Baloo 2", sans-serif; --tile-weight: 800;
}
body[data-theme="tl"] .scene {
  background:
    repeating-linear-gradient(45deg, rgba(206,17,38,.06) 0 14px, transparent 14px 28px),
    repeating-linear-gradient(-45deg, rgba(0,56,168,.06) 0 14px, transparent 14px 28px),
    radial-gradient(900px 500px at 50% -10%, #ffe7a3, transparent 70%), var(--bg); }
body[data-theme="tl"] .scene-a { bottom: auto; height: 34px;
  background:
    conic-gradient(from 135deg at 50% 0, #ce1126 0 90deg, transparent 0) 0 6px/36px 28px repeat-x,
    conic-gradient(from 135deg at 50% 0, #0038a8 0 90deg, transparent 0) 12px 6px/36px 28px repeat-x,
    conic-gradient(from 135deg at 50% 0, #fcd116 0 90deg, transparent 0) 24px 6px/36px 28px repeat-x,
    linear-gradient(#5b3a1a, #5b3a1a) 0 5px/100% 2px no-repeat; }
body[data-theme="tl"] .topbar { padding-top: 40px; }
body[data-theme="tl"] .scene-b { background: radial-gradient(260px 260px at 92% 18%, rgba(252,209,22,.45), transparent 70%); }
body[data-theme="tl"] .frame { box-shadow: inset 0 0 0 2px rgba(255,255,255,.7), 0 0 0 4px #ce1126, 0 0 0 8px #fcd116, 0 0 0 12px #0038a8, 0 22px 50px rgba(90,50,0,.35); }
body[data-theme="tl"] .card.v1 { --tile-bg: linear-gradient(180deg, #1650c9, #0038a8); }
body[data-theme="tl"] .card.v2 { --tile-bg: linear-gradient(180deg, #ffe066, #fcd116); --tile-ink: #3a2400; }
body[data-theme="tl"] .card.v3 { --tile-bg: linear-gradient(180deg, #23a35a, #158043); }
body[data-theme="tl"] .hud div, body[data-theme="tl"] .side { box-shadow: 0 3px 0 rgba(122,90,44,.15); }
body[data-theme="tl"] .toast { background: #2a1600; }

/* Dutch: Delft blue */
body[data-theme="nl"] {
  --bg: #f4f7fc; --bg-2: #dfe8f7; --ink: #10275f; --muted: #4f6596; --panel: rgba(255,255,255,.75); --panel-line: rgba(28,79,184,.22);
  --accent: #1c4fb8; --accent-ink: #fff; --accent-2: #d1495b;
  --frame: linear-gradient(160deg, #1c4fb8, #10306f); --frame-line: rgba(255,255,255,.35);
  --tile-bg: linear-gradient(180deg, #ffffff, #eef2fa);
  --tile-ink: #163a8c; --tile-edge: #b9c8e8;
  --font-display: "Fraunces", Georgia, serif; --font-tile: "Fraunces", Georgia, serif; --tile-weight: 800;
}
body[data-theme="nl"] .scene {
  background:
    radial-gradient(circle at 0 0, rgba(28,79,184,.16) 0 10px, transparent 11px) 0 0/64px 64px,
    linear-gradient(90deg, rgba(28,79,184,.08) 1px, transparent 1px) 0 0/64px 64px,
    linear-gradient(rgba(28,79,184,.08) 1px, transparent 1px) 0 0/64px 64px,
    radial-gradient(900px 500px at 50% -10%, #ffffff, transparent 70%), var(--bg); }
body[data-theme="nl"] .scene-a { top: auto; height: 120px; opacity: .16; background: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22360%22%20height%3D%22120%22%20viewBox%3D%220%200%20360%20120%22%3E%3Cg%20fill%3D%22%231c4fb8%22%3E%3Cpath%20d%3D%22M0%20120V40h8v-8h8v-8h8v8h8v8h8v80z%22%2F%3E%3Cpath%20d%3D%22M44%20120V30q0-14%2018-18%2018%204%2018%2018v90z%22%2F%3E%3Cpath%20d%3D%22M84%20120V48l20-22%2020%2022v72z%22%2F%3E%3Cpath%20d%3D%22M128%20120V36h6v-8h6v-8h12v8h6v8h6v84z%22%2F%3E%3Cpath%20d%3D%22M168%20120V44q0-16%2022-20%2022%204%2022%2020v76z%22%2F%3E%3Cpath%20d%3D%22M216%20120V30h8v-8h8v-8h8v8h8v8h8v90z%22%2F%3E%3Cpath%20d%3D%22M260%20120V50l24-24%2024%2024v70z%22%2F%3E%3Cpath%20d%3D%22M312%20120V38q0-12%2024-16%2024%204%2024%2016v82z%22%2F%3E%3C%2Fg%3E%3Cg%20fill%3D%22%23fff%22%20opacity%3D%22.55%22%3E%3Crect%20x%3D%2212%22%20y%3D%2252%22%20width%3D%226%22%20height%3D%229%22%2F%3E%3Crect%20x%3D%2224%22%20y%3D%2252%22%20width%3D%226%22%20height%3D%229%22%2F%3E%3Crect%20x%3D%2256%22%20y%3D%2240%22%20width%3D%226%22%20height%3D%229%22%2F%3E%3Crect%20x%3D%2266%22%20y%3D%2240%22%20width%3D%226%22%20height%3D%229%22%2F%3E%3Crect%20x%3D%2298%22%20y%3D%2258%22%20width%3D%2212%22%20height%3D%229%22%2F%3E%3Crect%20x%3D%22138%22%20y%3D%2246%22%20width%3D%226%22%20height%3D%229%22%2F%3E%3Crect%20x%3D%22150%22%20y%3D%2246%22%20width%3D%226%22%20height%3D%229%22%2F%3E%3Crect%20x%3D%22182%22%20y%3D%2252%22%20width%3D%2216%22%20height%3D%229%22%2F%3E%3Crect%20x%3D%22226%22%20y%3D%2244%22%20width%3D%226%22%20height%3D%229%22%2F%3E%3Crect%20x%3D%22240%22%20y%3D%2244%22%20width%3D%226%22%20height%3D%229%22%2F%3E%3Crect%20x%3D%22276%22%20y%3D%2260%22%20width%3D%2216%22%20height%3D%229%22%2F%3E%3Crect%20x%3D%22326%22%20y%3D%2248%22%20width%3D%226%22%20height%3D%229%22%2F%3E%3Crect%20x%3D%22340%22%20y%3D%2248%22%20width%3D%226%22%20height%3D%229%22%2F%3E%3C%2Fg%3E%3Cg%3E%3Cpath%20d%3D%22M30%20120v-14%22%20stroke%3D%22%232f7d4f%22%20stroke-width%3D%222%22%2F%3E%3Cpath%20d%3D%22M25%20100q5-8%2010%200v6h-10z%22%20fill%3D%22%23d1495b%22%2F%3E%3Cpath%20d%3D%22M150%20120v-16%22%20stroke%3D%22%232f7d4f%22%20stroke-width%3D%222%22%2F%3E%3Cpath%20d%3D%22M145%2098q5-8%2010%200v6h-10z%22%20fill%3D%22%23f2a541%22%2F%3E%3Cpath%20d%3D%22M290%20120v-14%22%20stroke%3D%22%232f7d4f%22%20stroke-width%3D%222%22%2F%3E%3Cpath%20d%3D%22M285%20100q5-8%2010%200v6h-10z%22%20fill%3D%22%23d1495b%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E") 0 100%/360px 120px repeat-x; }
  box-shadow: inset 0 0 0 4px #fff, inset 0 0 0 5.5px #1c4fb8, inset 0 -5px 0 rgba(0,0,0,.08), 0 4px 0 rgba(16,48,111,.35); }
  background: radial-gradient(circle at 0 0, #1c4fb8 0 9px, transparent 10px), radial-gradient(circle at 100% 0, #1c4fb8 0 9px, transparent 10px),
    radial-gradient(circle at 0 100%, #1c4fb8 0 9px, transparent 10px), radial-gradient(circle at 100% 100%, #1c4fb8 0 9px, transparent 10px); opacity: .9; }
    radial-gradient(circle at 0 50%, #1c4fb8 0 6px, transparent 7px), radial-gradient(circle at 100% 50%, #1c4fb8 0 6px, transparent 7px); }
body[data-theme="nl"] .card.v1 { --tile-ink: #10306f; }
body[data-theme="nl"] .card.v2 { --tile-ink: #d1495b; }
body[data-theme="nl"] .card .w, body[data-theme="nl"] .card .parts span { text-transform: lowercase; }
body[data-theme="nl"] .toast { background: #10275f; }

/* Light themes need dark dialog backgrounds to read */
body[data-theme="tl"] .dialog, body[data-theme="nl"] .dialog { background: #fffdf7; }
body[data-theme="tl"] .dialog input, body[data-theme="nl"] .dialog input { background: #fff; }
body[data-theme="tl"] .ring, body[data-theme="nl"] .ring { background: radial-gradient(closest-side, #fff 78%, transparent 80% 100%), conic-gradient(var(--accent) calc(var(--p) * 1%), rgba(0,0,0,.1) 0); }
body[data-theme="tl"] .card.locked, body[data-theme="nl"] .card.locked { background: rgba(255,255,255,.45); }
body[data-theme="tl"] .chip, body[data-theme="nl"] .chip { background: #fff; }

/* ---------- Narrow screens ---------- */
@media (max-width: 860px) {
  .game { grid-template-columns: minmax(0, 1fr); }
  body[data-theme="yue"] .scene-b::before, body[data-theme="yue"] .scene-b::after { opacity: .14; animation: none; }
  .side { max-width: 520px; width: 100%; justify-self: center; }
}
@media (max-width: 640px) {
  .how { grid-template-columns: minmax(0, 1fr); }
  .langs { grid-template-columns: minmax(0, 1fr); }
  .lang-card { min-height: 190px; }
  .yours { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .podium .p { padding: 10px 4px; }
  .ranks li { grid-template-columns: 28px minmax(0, 1fr) auto; }
  .ranks .lg { display: none; }
  .brand-name { font-size: 1.15rem; }
  .nav a, .sound { padding: 6px 9px; font-size: .85rem; }
  .hud b { font-size: 1.2rem; }
  .hud small { font-size: .66rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
