:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-classic: #2a78d6;
  --series-angry: #e34948;
  --board-bg: #bbada0;
  --cell-bg: #cdc1b4;
  --accent: #8f7a66;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-classic: #3987e5;
    --series-angry: #e66767;
    --board-bg: #3e3a34;
    --cell-bg: #4c463e;
    --accent: #8f7a66;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 460px; margin: 0 auto; padding: 20px 16px 48px; }
.hidden { display: none !important; }

.header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 16px; }
h1 { font-size: 28px; margin: 0; letter-spacing: -0.5px; }
h1 .sub { font-size: 15px; color: var(--muted); font-weight: 600; }
h2 { font-size: 17px; margin: 0; }

.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.tab {
  border: 0; background: transparent; color: var(--ink-2); font: inherit; font-size: 13px;
  font-weight: 600; padding: 6px 12px; border-radius: 7px; cursor: pointer;
}
.tab.active { background: var(--accent); color: #fff; }

.controls { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.mode-switch { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.mode {
  border: 0; background: transparent; color: var(--ink-2); font: inherit; font-size: 13px;
  font-weight: 600; padding: 6px 12px; border-radius: 7px; cursor: pointer;
}
.mode.active[data-mode="classic"] { background: var(--series-classic); color: #fff; }
.mode.active[data-mode="angry"] { background: var(--series-angry); color: #fff; }
.mode:disabled { opacity: 0.5; cursor: default; }

.btn-primary {
  border: 0; background: var(--accent); color: #fff; font: inherit; font-size: 14px;
  font-weight: 700; padding: 9px 16px; border-radius: 10px; cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-quiet {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-2); font: inherit;
  font-size: 12px; font-weight: 600; padding: 6px 10px; border-radius: 8px; cursor: pointer;
}

.hud { display: flex; gap: 10px; margin-bottom: 12px; }
.hud-box { flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; }
.hud-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
.hud-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }

.board-wrap { position: relative; }
.board {
  position: relative;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  gap: 10px;
  background: var(--board-bg); border-radius: 14px; padding: 10px;
  aspect-ratio: 1; touch-action: none; user-select: none;
}
.cell { border-radius: 8px; background: var(--cell-bg); }
.tile-layer { position: absolute; inset: 0; }
.tile {
  position: absolute; left: 0; top: 0;
  transition: transform 120ms ease-in-out;
  will-change: transform;
}
/* the tile itself only translates; the visible face is an inner element,
   so the spawn pop can scale it without touching the tile's position */
.face {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  font-weight: 800; font-size: clamp(28px, 11vw, 52px);
}
.tile.pop .face { animation: pop 150ms ease-out; }
@keyframes pop { from { transform: scale(0.4); } to { transform: scale(1); } }

.t2    { background: #eee4da; color: #776e65; }
.t4    { background: #ede0c8; color: #776e65; }
.t8    { background: #f2b179; color: #f9f6f2; }
.t16   { background: #f59563; color: #f9f6f2; }
.t32   { background: #f67c5f; color: #f9f6f2; }
.t64   { background: #f65e3b; color: #f9f6f2; }
.t128  { background: #edcf72; color: #f9f6f2; font-size: clamp(24px, 9vw, 44px); }
.t256  { background: #edcc61; color: #f9f6f2; font-size: clamp(24px, 9vw, 44px); }
.t512  { background: #edc850; color: #f9f6f2; font-size: clamp(24px, 9vw, 44px); }
.t1024 { background: #edc53f; color: #f9f6f2; font-size: clamp(20px, 7.5vw, 36px); }

.overlay {
  position: absolute; inset: 0; border-radius: 14px;
  background: color-mix(in srgb, var(--page) 78%, transparent);
  backdrop-filter: blur(2px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
}
.overlay-text { font-size: 22px; font-weight: 800; text-align: center; line-height: 1.4; }
.overlay-text small { display: block; font-size: 14px; font-weight: 600; color: var(--ink-2); }

/* ---- stats ---- */
.stats-head { display: flex; justify-content: space-between; align-items: center; margin: 4px 0 14px; }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 14px 8px; margin-bottom: 12px;
}
.panel-title { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 700; margin-bottom: 2px; }
.chip { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.panel-sub { color: var(--muted); font-size: 12px; margin: 0 0 6px 18px; }
.panel svg { display: block; width: 100%; height: auto; }
.panel .bar { cursor: default; }

.empty-note { color: var(--muted); font-size: 13px; padding: 18px 4px 22px; text-align: center; }

.tooltip {
  position: fixed; z-index: 10; pointer-events: none;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 9px; font-size: 12px; font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  white-space: nowrap;
}
.tooltip .tt-sub { color: var(--ink-2); font-weight: 500; }
