:root {
  --bg: #f7f3ea;
  --bg-2: #efe9dc;
  --card: #ffffff;
  --ink: #1d1b2f;
  --ink-2: #5d5a72;
  --line: #e2dccd;
  --key: #ffffff;
  --key-ink: #1d1b2f;
  --good: #16a34a;
  --bad: #dc2626;
  --gold: #e0a100;
  --accent: #5b4bdb;
  --accent-ink: #ffffff;
  --shadow: 0 1px 2px rgb(30 20 60 / 8%), 0 6px 18px rgb(30 20 60 / 8%);
  --radius: 18px;
  --m-classic: #5b4bdb;
  --m-uganda: #e3a600;
  --m-evil: #9333ea;
  --m-bomb: #ea580c;
  --m-coins: #ca8a04;
  --m-duel: #0d9488;
  --m-daily: #2563eb;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14122b;
    --bg-2: #1c1a3a;
    --card: #221f45;
    --ink: #f3f1ff;
    --ink-2: #a9a5c8;
    --line: #34305e;
    --key: #2e2a5a;
    --key-ink: #f3f1ff;
    --good: #22c55e;
    --bad: #f43f5e;
    --gold: #fbbf24;
    --accent: #8b7cff;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
h1, h2, h3, .display { font-family: ui-rounded, "SF Pro Rounded", system-ui, sans-serif; letter-spacing: -0.01em; }

.app { min-height: 100dvh; max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; }
.view { flex: 1; padding: 12px 16px calc(92px + env(safe-area-inset-bottom)); outline: none; }
.app.in-game .view { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
.app.in-game .tabbar { display: none; }

/* Tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 560px;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); z-index: 10;
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px; text-decoration: none;
  font-size: 12px; font-weight: 600; color: var(--ink-2); border-radius: 12px; }
.tabbar a span { font-size: 22px; filter: grayscale(0.6); }
.tabbar a.active { color: var(--accent); }
.tabbar a.active span { filter: none; transform: scale(1.1); }

/* Header */
.top { display: flex; align-items: center; gap: 10px; padding: 4px 0 12px; }
.brand { font-size: 26px; font-weight: 800; margin: 0; flex: 1; display: flex; align-items: center; gap: 8px; }
.brand small { font-size: 11px; font-weight: 700; color: var(--ink-2); letter-spacing: 0.08em; text-transform: uppercase; display: block; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 6px 10px; border-radius: 999px; background: var(--card);
  box-shadow: var(--shadow); font-weight: 700; font-size: 14px; white-space: nowrap; }
.lv { background: var(--accent); color: var(--accent-ink); }

/* Cards */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.hello { display: flex; align-items: center; gap: 12px; }
.hello .avatar { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-size: 24px;
  background: var(--bg-2); flex: none; }
.hello h2 { margin: 0; font-size: 18px; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.bar { height: 8px; border-radius: 99px; background: var(--bg-2); overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #c084fc); border-radius: inherit;
  transition: width 0.8s cubic-bezier(.2,.9,.3,1.2); }

.daily { display: flex; align-items: center; gap: 14px; text-decoration: none; color: #fff;
  background: linear-gradient(135deg, #2563eb, #7c3aed); }
.daily .big { font-size: 34px; }
.daily h3 { margin: 0; font-size: 18px; }
.daily p { margin: 2px 0 0; opacity: 0.9; font-size: 14px; }
.daily .go { margin-left: auto; background: rgb(255 255 255 / 20%); padding: 8px 14px; border-radius: 999px; font-weight: 700; white-space: nowrap; }

.section-title { font-size: 13px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); margin: 20px 4px 10px; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode {
  position: relative; text-align: left; border: 0; border-radius: var(--radius); padding: 14px; min-height: 132px;
  background: var(--card); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; overflow: hidden;
  transition: transform 0.15s;
}
.mode:active { transform: scale(0.97); }
.mode::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 5px; background: var(--mc); }
.mode .ic { font-size: 30px; line-height: 1; }
.mode b { font-size: 16px; }
.mode span { font-size: 13px; color: var(--ink-2); line-height: 1.3; }
.mode .tag { position: absolute; top: 12px; right: 10px; font-size: 10px; font-weight: 800; letter-spacing: 0.05em;
  padding: 3px 7px; border-radius: 99px; background: color-mix(in srgb, var(--mc) 18%, transparent); color: var(--mc); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 14px;
  padding: 14px 18px; font-weight: 700; background: var(--accent); color: var(--accent-ink); min-height: 50px;
  text-decoration: none; transition: transform 0.1s, opacity 0.2s; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; }
.btn.secondary { background: var(--bg-2); color: var(--ink); }
.btn.ghost { background: transparent; color: var(--ink-2); }
.btn.block { width: 100%; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.stack > * + * { margin-top: 10px; }

/* Forms */
label.field { display: block; font-size: 13px; font-weight: 700; color: var(--ink-2); margin-bottom: 12px; }
.field input { display: block; width: 100%; margin-top: 6px; padding: 14px; border-radius: 12px; border: 2px solid var(--line);
  background: var(--bg); font-size: 17px; }
.field input:focus { outline: none; border-color: var(--accent); }
.error { color: var(--bad); font-size: 14px; min-height: 20px; margin: 4px 0 8px; }

/* Game */
.gbar { display: flex; align-items: center; gap: 8px; padding: 2px 0 6px; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--card); box-shadow: var(--shadow);
  display: grid; place-items: center; font-size: 20px; flex: none; }
.gbar h1 { flex: 1; margin: 0; font-size: 18px; text-align: center; }
.game { display: flex; flex-direction: column; min-height: calc(100dvh - 72px - env(safe-area-inset-bottom)); }
.stage { position: relative; display: grid; place-items: center; min-height: 160px; flex: 1; max-height: 260px; }
.stage svg { width: min(62vw, 230px); height: auto; max-height: 100%; }
.stage.shake { animation: shake 0.35s; }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
.lives { display: flex; justify-content: center; gap: 4px; font-size: 16px; min-height: 22px; }
.lives .lost { opacity: 0.2; filter: grayscale(1); }
.chips { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin: 6px 0; min-height: 30px; }
.chip { padding: 5px 12px; border-radius: 999px; background: var(--bg-2); font-size: 13px; font-weight: 700; }
.chip.accent { background: color-mix(in srgb, var(--mc, var(--accent)) 18%, transparent); color: var(--mc, var(--accent)); }

.word { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 4px; margin: 10px 0 12px; }
.word .w { display: flex; gap: 4px; }
.word .slot { width: var(--sw, 34px); height: calc(var(--sw, 34px) * 1.25); border-bottom: 3px solid var(--ink);
  display: grid; place-items: center; font: 800 calc(var(--sw, 34px) * 0.75) ui-rounded, system-ui, sans-serif; text-transform: uppercase; }
.word .slot.pop { animation: pop 0.35s cubic-bezier(.2,.9,.3,1.6); color: var(--good); }
.word .slot.missed { color: var(--bad); }
.word .gap { width: calc(var(--sw, 34px) * 0.5); }
@keyframes pop { 0% { transform: scale(0.3); } 100% { transform: scale(1); } }

.msg { text-align: center; min-height: 22px; font-weight: 600; color: var(--ink-2); font-size: 14px; }

.shop { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.shop button { border: 0; border-radius: 12px; padding: 8px 4px; background: var(--card); box-shadow: var(--shadow);
  font-size: 13px; font-weight: 700; line-height: 1.2; }
.shop button small { display: block; color: var(--gold); font-weight: 800; }
.shop button:disabled { opacity: 0.4; }

.kb { display: flex; flex-direction: column; gap: 7px; margin-top: auto; padding-top: 6px; user-select: none; }
.kb .r { display: flex; justify-content: center; gap: 5px; }
.kb button { flex: 1; max-width: 46px; height: 54px; border: 0; border-radius: 10px; background: var(--key); color: var(--key-ink);
  font: 800 19px ui-rounded, system-ui, sans-serif; box-shadow: 0 2px 0 var(--line); text-transform: uppercase;
  transition: background 0.2s, transform 0.08s; touch-action: manipulation; }
.kb button:active { transform: translateY(2px); box-shadow: none; }
.kb button.hit { background: var(--good); color: #fff; box-shadow: none; }
.kb button.miss { background: var(--bad); color: #fff; opacity: 0.55; box-shadow: none; }
.kb button:disabled { cursor: default; }

/* Bomb fuse */
.fuse { width: 100%; max-width: 280px; margin: 0 auto 4px; }
.fuse .bar { height: 10px; }
.fuse .bar i { background: linear-gradient(90deg, #f59e0b, #ef4444); transition: none; }
.fuse.urgent .bar i { animation: blink 0.5s infinite; }
@keyframes blink { 50% { opacity: 0.4; } }
.spark { animation: spark 0.25s infinite alternate; transform-origin: center; transform-box: fill-box; }
@keyframes spark { from { transform: scale(0.8) rotate(0deg); } to { transform: scale(1.25) rotate(45deg); } }

/* Coin bank */
.bank { text-align: center; }
.bank .amt { font: 900 56px ui-rounded, system-ui, sans-serif; color: var(--gold); line-height: 1; }
.bank .delta { font-weight: 800; color: var(--bad); height: 22px; }
.bank .delta.up { color: var(--good); }
.coin-ic { font-size: 54px; display: block; animation: bob 2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px); } }

/* Hangman drawing */
.hm .part { stroke: var(--ink); stroke-width: 6; stroke-linecap: round; fill: none; opacity: 0; transition: opacity 0.3s; }
.hm .part.on { opacity: 1; animation: draw 0.4s ease-out; }
.hm .gallows { stroke: var(--ink-2); stroke-width: 7; stroke-linecap: round; fill: none; }
.hm .rope { stroke: var(--gold); stroke-width: 4; }
.hm.dead .part { stroke: var(--bad); }
.hm.saved .part { stroke: var(--good); }
@keyframes draw { from { opacity: 0; transform: scale(0.9); } }

/* Sheets */
.scrim { position: fixed; inset: 0; background: rgb(10 8 30 / 55%); z-index: 50; display: flex; align-items: flex-end;
  justify-content: center; animation: fade 0.2s; }
.sheet { width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto; background: var(--card); border-radius: 24px 24px 0 0;
  padding: 10px 18px calc(18px + env(safe-area-inset-bottom)); animation: up 0.3s cubic-bezier(.2,.9,.3,1.1); }
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { margin: 0 0 6px; font-size: 22px; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
.cats { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 16px; }
.cats button { border: 2px solid var(--line); background: var(--bg); border-radius: 999px; padding: 10px 16px; font-weight: 700; }
.cats button:active, .cats button.sel { border-color: var(--mc, var(--accent)); color: var(--mc, var(--accent)); }

/* Result */
.result { text-align: center; }
.result .emoji { font-size: 64px; line-height: 1; margin-top: 6px; animation: pop 0.5s cubic-bezier(.2,.9,.3,1.6); }
.result h2 { font-size: 28px; margin: 6px 0 2px; }
.reveal { font: 900 30px ui-rounded, system-ui, sans-serif; letter-spacing: 0.12em; text-transform: uppercase; margin: 8px 0; word-break: break-word; }
.fact { text-align: left; background: color-mix(in srgb, var(--m-uganda) 14%, var(--card)); border-left: 4px solid var(--m-uganda);
  border-radius: 12px; padding: 12px 14px; margin: 12px 0; font-size: 15px; }
.fact b { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--m-uganda); margin-bottom: 2px; }
.points { margin: 12px 0; text-align: left; }
.points div { display: flex; justify-content: space-between; padding: 6px 2px; border-bottom: 1px dashed var(--line);
  animation: fade 0.4s both; }
.points .total { border: 0; font-weight: 900; font-size: 20px; color: var(--accent); }
.badge-new { display: flex; align-items: center; gap: 12px; text-align: left; padding: 12px; border-radius: 14px; margin: 8px 0;
  background: linear-gradient(135deg, color-mix(in srgb, var(--gold) 25%, var(--card)), var(--card)); animation: pop 0.5s both; }
.badge-new .e { font-size: 34px; }
.levelup { background: linear-gradient(135deg, #7c3aed, #db2777); color: #fff; border-radius: 14px; padding: 12px; margin: 8px 0;
  font-weight: 800; animation: pop 0.5s both; }

/* Leaderboard */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.tabs button { border: 0; padding: 9px 14px; border-radius: 999px; background: var(--card); box-shadow: var(--shadow);
  font-weight: 700; font-size: 14px; white-space: nowrap; }
.tabs button.on { background: var(--accent); color: var(--accent-ink); }
.lb { list-style: none; margin: 0; padding: 0; }
.lb li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; background: var(--card);
  margin-bottom: 8px; box-shadow: var(--shadow); }
.lb li.me { outline: 2px solid var(--accent); }
.lb .rk { width: 32px; text-align: center; font-weight: 900; font-size: 18px; color: var(--ink-2); }
.lb .nm { flex: 1; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.lb .nm small { display: block; font-weight: 500; color: var(--ink-2); }
.lb .vl { font-weight: 900; font-variant-numeric: tabular-nums; }
.empty { text-align: center; padding: 30px 10px; color: var(--ink-2); }
.empty .e { font-size: 44px; }

/* Profile */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats div { background: var(--bg-2); border-radius: 12px; padding: 10px 6px; text-align: center; }
.stats b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 11px; color: var(--ink-2); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.badges div { background: var(--bg-2); border-radius: 14px; padding: 10px 6px; text-align: center; font-size: 12px; }
.badges .e { font-size: 30px; display: block; }
.badges b { display: block; font-size: 12px; margin-top: 2px; }
.badges .locked { opacity: 0.4; }
.badges .locked .e { filter: grayscale(1); }
.switch { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; font-weight: 600; }
.switch input { width: 48px; height: 28px; accent-color: var(--accent); }

/* Duel */
.code { font: 900 44px ui-rounded, system-ui, sans-serif; letter-spacing: 0.18em; text-align: center; margin: 6px 0; color: var(--m-duel); }
.vs { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.vs .who { flex: 1; background: var(--card); box-shadow: var(--shadow); border-radius: 14px; padding: 8px 10px; font-size: 13px; }
.vs .who b { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ink-2); margin-right: 4px; }
.dot.on { background: var(--good); }
.waiting { text-align: center; font-size: 46px; animation: bob 1.4s ease-in-out infinite; }

/* Toast + confetti */
.toast { position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top)); transform: translate(-50%, -150%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 700; font-size: 14px;
  z-index: 100; transition: transform 0.3s cubic-bezier(.2,.9,.3,1.2); max-width: 90vw; text-align: center; }
.toast.show { transform: translate(-50%, 0); }
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }

@media (min-width: 420px) { .modes { gap: 14px; } }
@media (max-height: 640px) { .stage { min-height: 120px; max-height: 170px; } .kb button { height: 48px; } }
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } }

/* Mode colours (classes, because the CSP forbids inline style attributes) */
.m-classic { --mc: var(--m-classic); }
.m-uganda { --mc: var(--m-uganda); }
.m-evil { --mc: var(--m-evil); }
.m-bomb { --mc: var(--m-bomb); }
.m-coins { --mc: var(--m-coins); }
.m-duel { --mc: var(--m-duel); }
.m-daily { --mc: var(--m-daily); }
.gbar h1 { color: var(--mc, var(--ink)); }
.grow { flex: 1; min-width: 0; }
.join input { flex: 2; min-width: 0; padding: 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--bg);
  font: 800 20px ui-rounded, system-ui, sans-serif; letter-spacing: 0.15em; text-transform: uppercase; }
.join input:focus { outline: none; border-color: var(--m-duel); }
a.pill, a.card, a.btn { text-decoration: none; }
.cal { flex: none; width: 52px; border-radius: 12px; background: #fff; color: #1d1b2f; text-align: center; overflow: hidden;
  font: 900 24px/1.25 ui-rounded, system-ui, sans-serif; box-shadow: 0 2px 6px rgb(0 0 0 / 20%); }
.cal b { display: block; background: #ef4444; color: #fff; font-size: 11px; letter-spacing: 0.08em; line-height: 1.7; }
@media (prefers-color-scheme: dark) {
  :root { --m-classic: #a99cff; --m-uganda: #fcd34d; --m-evil: #d8b4fe; --m-bomb: #fb923c; --m-coins: #fcd34d;
    --m-duel: #2dd4bf; --m-daily: #93c5fd; }
}
.hintrow { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 40px; margin-bottom: 6px; }
.hintrow .msg { flex: 1; text-align: left; }
.hintrow .msg:empty { display: none; }
.hint-btn { border: 0; border-radius: 999px; padding: 9px 14px; font-weight: 800; font-size: 14px; white-space: nowrap;
  background: color-mix(in srgb, var(--gold) 22%, var(--card)); color: var(--ink); box-shadow: var(--shadow); }
.hint-btn small { font-weight: 700; color: var(--ink-2); margin-left: 4px; }
.hint-btn:disabled { opacity: 0.45; }
.clue { background: color-mix(in srgb, var(--gold) 14%, var(--card)); border-left: 4px solid var(--gold); border-radius: 12px;
  padding: 10px 12px; font-size: 15px; margin: 4px 0 2px; }
.clue b { display: block; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--gold); }
.clue.pop-in { animation: pop 0.4s cubic-bezier(.2,.9,.3,1.4); }
.shop { grid-template-columns: repeat(4, 1fr); }
.points b.neg { color: var(--bad); }
/* Game screens fit the phone: the drawing shrinks to make room for clues, so the keyboard never scrolls away. */
.game { min-height: 0; height: calc(100dvh - 24px - env(safe-area-inset-bottom)); }
.stage { flex: 1 1 0; min-height: 70px; max-height: 260px; overflow: hidden; }
.stage svg { height: 100%; width: auto; max-width: min(62vw, 230px); }
.stage .bank .coin-ic { font-size: clamp(24px, 8vh, 54px); }
.stage .bank .amt { font-size: clamp(30px, 7vh, 56px); }
.clue { font-size: 14px; line-height: 1.35; }
.word { margin: 6px 0 8px; }
@media (max-height: 640px) {
  .stage { min-height: 50px; }
  .kb { gap: 5px; } .kb button { height: 44px; font-size: 17px; }
  .gbar { padding: 0 0 2px; } .icon-btn { width: 38px; height: 38px; }
  .shop button { padding: 5px 2px; font-size: 12px; } .shop { margin-bottom: 6px; }
  .chips { margin: 2px 0; min-height: 26px; } .chip { padding: 3px 10px; font-size: 12px; }
  .clue { padding: 7px 10px; font-size: 13px; } .hintrow { min-height: 34px; margin-bottom: 2px; }
  .hint-btn { padding: 7px 12px; font-size: 13px; } .lives { font-size: 13px; min-height: 18px; }
}
