:root {
  --bg: #0f1020;
  --bg2: #171833;
  --card: #1e2044;
  --card2: #262a55;
  --line: #33376b;
  --text: #ececff;
  --muted: #9aa0d0;
  --accent: #6366f1;
  --accent2: #8b5cf6;
  --good: #34d399;
  --bad: #f87171;
  --warn: #fbbf24;
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overscroll-behavior-y: contain;
}
#app { max-width: 640px; margin: 0 auto; padding: 16px; }

h1, h2, h3 { margin: 0 0 8px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }

/* header */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; min-height: 40px; }
.topbar .back { font-size: 20px; }
.topbar .title { font-weight: 700; font-size: 18px; }
.pill { font-size: 12px; color: var(--muted); background: var(--bg2); border: 1px solid var(--line); padding: 4px 10px; border-radius: 999px; }

/* buttons */
button, .btn {
  font: inherit; color: var(--text); background: var(--card2); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 16px; cursor: pointer; touch-action: manipulation;
  transition: transform .05s ease, background .15s ease;
}
button:active, .btn:active { transform: scale(0.98); }
button:disabled { opacity: .5; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); border: none; font-weight: 700; }
.btn-block { display: block; width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn-ghost { background: transparent; }

/* cards / tiles */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.tiles { display: grid; gap: 14px; }
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; display: flex; gap: 16px; align-items: center; cursor: pointer;
}
.tile:active { transform: scale(0.99); }
.tile .emoji { font-size: 40px; line-height: 1; }
.tile h2 { margin: 0; font-size: 20px; }
.tile p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

/* passcode gate */
.gate { min-height: 70dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; text-align: center; }
.gate input { font-size: 22px; letter-spacing: 6px; text-align: center; padding: 14px; width: 220px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); }

/* trivia */
.q-meta { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.q-progress { height: 6px; background: var(--bg2); border-radius: 999px; overflow: hidden; margin-bottom: 16px; }
.q-progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .3s; }
.q-text { font-size: 20px; font-weight: 600; margin: 8px 0 18px; }
.options { display: grid; gap: 10px; }
.option { text-align: left; padding: 14px 16px; font-size: 16px; }
.option.correct { background: rgba(52,211,153,.18); border-color: var(--good); }
.option.wrong { background: rgba(248,113,113,.18); border-color: var(--bad); }
.explain { margin-top: 14px; padding: 12px 14px; background: var(--bg2); border-left: 3px solid var(--accent); border-radius: 8px; font-size: 14px; color: var(--muted); }
.timer-bar { height: 6px; background: var(--bg2); border-radius: 999px; overflow: hidden; margin-bottom: 12px; }
.timer-bar > i { display: block; height: 100%; background: var(--warn); }

/* stats */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.stat b { font-size: 22px; display: block; }
.stat span { font-size: 12px; color: var(--muted); }

/* puzzles */
.puz-grid { display: grid; gap: 6px; justify-content: center; margin: 16px auto; touch-action: manipulation; }
.cell { width: 100%; aspect-ratio: 1; border-radius: 8px; background: var(--card2); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 18px; cursor: pointer; user-select: none; }
.cell.on { background: linear-gradient(135deg, var(--accent), var(--accent2)); border: none; }
.cell.blank { background: transparent; border: 1px dashed var(--line); cursor: default; }
.cell.fill { background: var(--text); }
.cell.mark { color: var(--bad); }
.nono-wrap { display: grid; gap: 6px; margin: 12px auto; justify-content: center; }
.clue { color: var(--muted); font-size: 12px; display: flex; gap: 4px; align-items: center; justify-content: flex-end; }
.clue.col { flex-direction: column; justify-content: flex-end; align-items: center; }

/* pokemon */
.mon { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.mon .name { font-weight: 700; display: flex; gap: 6px; align-items: center; }
.hpbar { height: 8px; background: #0c0c1a; border-radius: 999px; overflow: hidden; margin-top: 6px; }
.hpbar > i { display: block; height: 100%; background: var(--good); transition: width .35s; }
.hpbar.mid > i { background: var(--warn); }
.hpbar.low > i { background: var(--bad); }
.badge { font-size: 11px; font-weight: 700; color: #fff; padding: 2px 7px; border-radius: 999px; text-transform: uppercase; }
.team-row { display: flex; gap: 6px; margin-top: 8px; }
.team-slot { width: 34px; height: 34px; border-radius: 8px; background: var(--card2); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; font-size: 16px; }
.team-slot.fainted { opacity: .3; }
.team-slot.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.battle-log { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; height: 120px; overflow-y: auto; font-size: 13px; color: var(--muted); margin: 12px 0; }
.battle-log div { padding: 1px 0; }
.moves { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.move-btn { text-align: left; padding: 10px 12px; }
.move-btn small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.switch-list { display: flex; gap: 8px; flex-wrap: wrap; }

/* type colors */
.t-Normal{background:#9099a1}.t-Fire{background:#ff9d55}.t-Water{background:#4d90d5}.t-Electric{background:#f4d23c}
.t-Grass{background:#63bc5a}.t-Ice{background:#73cec0}.t-Fighting{background:#ce4069}.t-Poison{background:#ab6ac8}
.t-Ground{background:#d97845}.t-Flying{background:#8fa9de}.t-Psychic{background:#f97176}.t-Bug{background:#90c12c}
.t-Rock{background:#c7b78b}.t-Ghost{background:#5269ac}.t-Dragon{background:#0b6dc3}.t-Dark{background:#5a5366}
.t-Steel{background:#5a8ea1}.t-Fairy{background:#ec8fe6}

/* toast */
#toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--card2); border: 1px solid var(--line); padding: 12px 18px; border-radius: 12px; opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; }

.footer-hint { margin-top: 20px; font-size: 12px; color: var(--muted); text-align: center; }

/* leaderboard */
.lb { display: flex; flex-direction: column; gap: 4px; }
.lb-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; background: var(--bg2); font-variant-numeric: tabular-nums; }
.lb-row.hl { background: linear-gradient(135deg, rgba(99,102,241,.35), rgba(139,92,246,.35)); border: 1px solid var(--accent); }
.lb-rank { width: 22px; color: var(--muted); font-weight: 700; text-align: right; }
.lb-init { font-weight: 800; letter-spacing: 2px; font-family: ui-monospace, monospace; }
.lb-score { text-align: right; font-weight: 700; }
.lb-mode { font-size: 11px; text-transform: capitalize; }
.init-input { font-size: 40px; letter-spacing: 14px; text-align: center; text-transform: uppercase; width: 180px; padding: 12px 12px 12px 26px; margin-top: 12px; border-radius: 12px; border: 2px solid var(--accent); background: var(--bg2); color: var(--text); font-family: ui-monospace, monospace; }

/* word scramble */
.scramble-tiles { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.stile { width: 40px; height: 48px; display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 800; background: var(--card2); border: 1px solid var(--line); border-radius: 10px; font-family: ui-monospace, monospace; }
.scramble-input { font-size: 22px; text-align: center; letter-spacing: 2px; width: 100%; max-width: 280px; padding: 12px; border-radius: 12px; border: 2px solid var(--accent); background: var(--bg2); color: var(--text); }

/* quick math */
.math-problem { font-size: 40px; font-weight: 800; margin: 8px 0 18px; font-variant-numeric: tabular-nums; }
.math-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.math-opt { font-size: 24px; font-weight: 700; padding: 16px; font-variant-numeric: tabular-nums; }

/* memory */
.cell.mem { cursor: pointer; }
.cell.mem.flipped { background: linear-gradient(135deg, var(--accent), var(--accent2)); border: none; }
.list-btns { display: grid; gap: 10px; }
.result-big { font-size: 40px; text-align: center; margin: 10px 0; }
