:root {
  --bg: #0b0a14;
  --bg-2: #12101f;
  --panel: rgba(255, 255, 255, 0.04);
  --panel-line: rgba(255, 255, 255, 0.09);
  --ink: #ece9ff;
  --ink-dim: #9b95b8;
  --accent: #a78bfa;
  --accent-2: #38bdf8;
  --good: #4ade80;
  --bad: #fb7185;

  --t0: #ff4d6d;
  --t1: #ffb703;
  --t2: #4ade80;
  --t3: #38bdf8;
  --t4: #a78bfa;
  --t5: #f0abfc;

  --glow-a: rgba(167, 139, 250, 0.18);
  --glow-b: rgba(56, 189, 248, 0.10);

  --radius: 16px;
  --tile-radius: 13px;
  --gap: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(90% 60% at 50% -10%, var(--glow-a), transparent 60%),
    radial-gradient(60% 50% at 100% 100%, var(--glow-b), transparent 55%),
    linear-gradient(180deg, var(--bg-2), var(--bg) 45%);
  color: var(--ink);
  font: 15px/1.5 "Manrope", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1120px;
  margin: 0 auto;
  padding: 22px 22px 34px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 100vh;
}

/* ── HUD ─────────────────────────────────────────────────────────── */

.hud {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: "Newsreader", Georgia, serif;
  font-size: 26px;
  letter-spacing: 0.01em;
}

.brand-mark {
  color: var(--accent);
  filter: drop-shadow(0 0 10px rgba(167, 139, 250, 0.7));
}

.brand-name {
  background: linear-gradient(92deg, #fff 10%, var(--accent) 60%, var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-weight: 700;
}

.stats {
  display: flex;
  gap: 10px;
  margin-left: auto;
}

.stat {
  min-width: 92px;
  padding: 8px 14px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-key {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.stat-val {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-moves .stat-val { color: var(--accent-2); }

.hud-actions { display: flex; gap: 8px; }

.btn {
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--panel-line);
  border-radius: 11px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 140ms, transform 140ms, border-color 140ms;
}

.btn:hover { background: rgba(255, 255, 255, 0.12); }
.btn:active { transform: translateY(1px); }

.btn-ghost { padding: 10px 12px; }

.btn-primary {
  background: linear-gradient(120deg, var(--accent), #7c3aed);
  border-color: transparent;
  color: #150e2b;
}

/* ── Stage ───────────────────────────────────────────────────────── */

.stage {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 22px;
  align-items: start;
}

.board-wrap {
  position: relative;
  display: grid;
  place-items: center;
}

.board {
  width: 100%;
  max-width: 620px;
  aspect-ratio: 1;
  display: grid;
  gap: var(--gap);
  padding: var(--gap);
  border-radius: 22px;
  background:
    radial-gradient(120% 120% at 30% 0%, rgba(255, 255, 255, 0.06), transparent 60%),
    rgba(9, 8, 18, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  grid-template-columns: repeat(var(--cols, 8), 1fr);
  grid-template-rows: repeat(var(--rows, 8), 1fr);
  touch-action: manipulation;
}

.tile {
  position: relative;
  padding: 0;
  border: var(--tile-border, 0);
  border-radius: var(--tile-radius, 13px);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-family: var(--tile-font, inherit);
  font-size: clamp(18px, 3.1vw, 30px);
  color: var(--tile-glyph, rgba(0, 0, 0, 0.42));
  background: #221f36;
  box-shadow: var(--tile-shadow,
      inset 0 2px 0 rgba(255, 255, 255, 0.35),
      inset 0 -3px 10px rgba(0, 0, 0, 0.35),
      0 4px 10px rgba(0, 0, 0, 0.35));
  transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease;
  will-change: transform;
  overflow: hidden;
}

/* Per-theme texture: scanlines, grain, holo wash. Junk keeps its own hatch. */
.tile:not([data-type="6"])::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background-image: var(--tile-overlay, none);
  background-size: var(--tile-overlay-size, auto);
  opacity: var(--tile-overlay-opacity, 0);
  pointer-events: none;
}

.tile[data-type="0"] {
  background: linear-gradient(160deg,
    color-mix(in srgb, var(--t0) 62%, white),
    var(--t0) 55%,
    color-mix(in srgb, var(--t0) 58%, black));
}
.tile[data-type="1"] {
  background: linear-gradient(160deg,
    color-mix(in srgb, var(--t1) 62%, white),
    var(--t1) 55%,
    color-mix(in srgb, var(--t1) 58%, black));
}
.tile[data-type="2"] {
  background: linear-gradient(160deg,
    color-mix(in srgb, var(--t2) 62%, white),
    var(--t2) 55%,
    color-mix(in srgb, var(--t2) 58%, black));
}
.tile[data-type="3"] {
  background: linear-gradient(160deg,
    color-mix(in srgb, var(--t3) 62%, white),
    var(--t3) 55%,
    color-mix(in srgb, var(--t3) 58%, black));
}
.tile[data-type="4"] {
  background: linear-gradient(160deg,
    color-mix(in srgb, var(--t4) 62%, white),
    var(--t4) 55%,
    color-mix(in srgb, var(--t4) 58%, black));
}
.tile[data-type="5"] {
  background: linear-gradient(160deg,
    color-mix(in srgb, var(--t5) 62%, white),
    var(--t5) 55%,
    color-mix(in srgb, var(--t5) 58%, black));
}

.tile:hover { transform: translateY(-2px); filter: brightness(1.06); }

.tile[data-selected="true"] {
  transform: translateY(-3px) scale(1.04);
  box-shadow:
    0 0 0 3px #fff,
    0 0 22px 4px rgba(255, 255, 255, 0.55),
    inset 0 2px 0 rgba(255, 255, 255, 0.45);
  z-index: 2;
}

.tile[data-hint="true"] {
  animation: hintPulse 1.1s ease-in-out infinite;
}

.tile[data-clearing="true"] {
  animation: pop 170ms ease forwards;
}

.tile[data-spawn="true"] {
  animation: drop 170ms ease;
}

@keyframes pop {
  0% { transform: scale(1); filter: brightness(1); }
  45% { transform: scale(1.16); filter: brightness(1.9); }
  100% { transform: scale(0.2); opacity: 0; filter: brightness(2.4); }
}

@keyframes drop {
  0% { transform: translateY(-26%); opacity: 0.2; }
  100% { transform: translateY(0); opacity: 1; }
}

@keyframes hintPulse {
  0%, 100% { box-shadow: inset 0 2px 0 rgba(255,255,255,0.35), 0 0 0 0 rgba(255,255,255,0.7); }
  50% { box-shadow: inset 0 2px 0 rgba(255,255,255,0.35), 0 0 0 4px rgba(255,255,255,0.35); }
}

.board[data-shake="true"] { animation: shake 240ms ease; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ── Side panels ─────────────────────────────────────────────────── */

.side { display: flex; flex-direction: column; gap: 12px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.panel-title {
  margin: 0 0 8px;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
  font-weight: 600;
}

.rules {
  margin: 0;
  padding-left: 18px;
  color: #cfc9e6;
  font-size: 13.5px;
}

.rules li { margin: 4px 0; }
.rules em { color: var(--accent); font-style: normal; font-weight: 600; }

.toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  padding: 5px 0;
  cursor: pointer;
}

.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }

.hint-text, .log-line {
  margin: 6px 0 0;
  font-size: 12.5px;
  color: var(--ink-dim);
}

/* ── Banner / toast ──────────────────────────────────────────────── */

.banner {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 10px;
  text-align: center;
  border-radius: 22px;
  background: rgba(7, 6, 14, 0.82);
  backdrop-filter: blur(6px);
  animation: fade 220ms ease;
}

.banner[hidden] { display: none; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.banner-title {
  margin: 0;
  font-family: "Newsreader", Georgia, serif;
  font-size: 34px;
}

.banner-body { margin: 0 0 6px; color: #cfc9e6; }

/* Notifications stack upward instead of landing on top of each other: each
   arrival lifts the ones already on screen, and the oldest fades out first. */
.toasts {
  position: fixed;
  left: 50%;
  bottom: 26px;
  width: min(92vw, 460px);
  height: 0;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 40;
}

.toast-item {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translate(-50%, 0);
  background: rgba(18, 16, 30, 0.96);
  border: 1px solid var(--panel-line);
  color: var(--ink);
  padding: 9px 17px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  transition: transform 230ms cubic-bezier(.2, .8, .3, 1), opacity 180ms ease;
  will-change: transform, opacity;
}

.toast-item[data-tone="bad"] { border-color: rgba(251, 113, 133, 0.55); color: #ffe4e6; }
.toast-item[data-tone="good"] { border-color: rgba(74, 222, 128, 0.55); color: #dcfce7; }

@media (max-width: 520px) {
  .toast-item { font-size: 12.5px; padding: 8px 14px; }
}

/* Without motion the stack must still be readable: the lift is the transform
   itself, so dropping the transition simply places each toast at its slot. */
@media (prefers-reduced-motion: reduce) {
  .toast-item { transition: none; }
}

/* ── Footer ──────────────────────────────────────────────────────── */

.foot {
  margin-top: auto;
  color: var(--ink-dim);
  font-size: 12.5px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.foot .dot { opacity: 0.5; }

/* ── Narrow screens ──────────────────────────────────────────────── */

@media (max-width: 900px) {
  .stage { grid-template-columns: minmax(0, 1fr); }
  .side { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .panel-log { grid-column: 1 / -1; }
  .stats { order: 3; width: 100%; margin-left: 0; }
  .stat { flex: 1; }
}

@media (max-width: 520px) {
  .app { padding: 14px 12px 24px; }
  .brand { font-size: 21px; }
  .side { grid-template-columns: 1fr; }
  .stat-val { font-size: 17px; }
}


/* ── Mode bar ────────────────────────────────────────────────────── */

.modebar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.modes {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 14px;
}

.mode-btn {
  font: inherit;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--ink-dim);
  background: transparent;
  border: 0;
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 140ms, color 140ms;
}

.mode-btn:hover { color: var(--ink); }

.mode-btn.is-active {
  color: #150e2b;
  background: linear-gradient(120deg, var(--accent), #7c3aed);
}

.name-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--ink-dim);
  margin-left: auto;
}

.name-field input,
.pvp-row input {
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  padding: 8px 10px;
  width: 130px;
}

.name-field input:focus,
.pvp-row input:focus {
  outline: 2px solid rgba(167, 139, 250, 0.6);
  outline-offset: 1px;
}

/* ── Leaderboard ─────────────────────────────────────────────────── */

.panel-sub {
  color: var(--accent);
  letter-spacing: 0.06em;
}

.lb {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.lb li {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: baseline;
  font-size: 13px;
  padding: 4px 0;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.06);
}

.lb li:last-child { border-bottom: 0; }

.lb-rank { color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-value { font-variant-numeric: tabular-nums; font-weight: 700; color: #fff; }
.lb-empty { display: block !important; color: var(--ink-dim); font-size: 12.5px; border: 0 !important; }
.lb-you .lb-name { color: var(--good); }

/* ── PvP ─────────────────────────────────────────────────────────── */

.pvp-row { display: flex; gap: 8px; }
.pvp-row input { width: 100%; text-transform: uppercase; letter-spacing: 0.14em; }

.muted { color: var(--ink-dim); font-size: 12.5px; margin: 8px 0 10px; }

.vs { display: flex; flex-direction: column; gap: 4px; }

.vs-row {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
}

.vs-name { color: var(--ink-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vs-score { font-variant-numeric: tabular-nums; font-weight: 700; }

.bar {
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  margin-bottom: 8px;
}

.bar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 260ms ease;
}

.bar-foe i { background: linear-gradient(90deg, #fb7185, #f59e0b); }

/* ── Effects layer ───────────────────────────────────────────────── */

.fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  overflow: visible;
}

.particle {
  position: absolute;
  border-radius: 3px;
  transform: translate(-50%, -50%);
  animation: particleFly 620ms cubic-bezier(.2,.7,.3,1) forwards;
}

@keyframes particleFly {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0); }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.2) rotate(var(--spin));
  }
}

.float-text {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 800;
  letter-spacing: 0.01em;
  pointer-events: none;
  animation: floatUp 950ms cubic-bezier(.2,.8,.3,1) forwards;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
}

.float-score { font-size: 20px; color: #fff; }
.float-combo { font-size: 26px; color: var(--t1); }

@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.7); }
  25% { opacity: 1; transform: translate(-50%, -70%) scale(1.08); }
  100% { opacity: 0; transform: translate(-50%, -180%) scale(1); }
}

.big-banner {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 2px;
  text-align: center;
  pointer-events: none;
  animation: bannerIn 1100ms ease forwards;
  z-index: 6;
}

.big-word {
  font-family: "Newsreader", Georgia, serif;
  font-size: clamp(38px, 9vw, 76px);
  font-weight: 800;
  letter-spacing: 0.02em;
  background: linear-gradient(100deg, #fff 5%, var(--t1) 45%, var(--t0) 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 24px rgba(255, 183, 3, 0.35));
}

.big-sub {
  font-size: 12px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.75);
}

@keyframes bannerIn {
  0% { opacity: 0; transform: scale(0.72); }
  18% { opacity: 1; transform: scale(1.06); }
  32% { transform: scale(1); }
  78% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.04); }
}

.fx-flash {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  animation: flashOut 260ms ease forwards;
  border-radius: 22px;
}

@keyframes flashOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

.shake { animation: shake 300ms ease; }

/* ── Junk tiles ──────────────────────────────────────────────────── */

.tile[data-type="6"] {
  background: linear-gradient(160deg, #5b5b6d, #3a3a48 55%, #23232c);
  color: rgba(255, 255, 255, 0.5);
  cursor: not-allowed;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.16),
    inset 0 -3px 10px rgba(0, 0, 0, 0.5),
    0 2px 6px rgba(0, 0, 0, 0.4);
}

.tile[data-type="6"]::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 8px;
  background-image: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.08) 0 3px,
    transparent 3px 7px
  );
}

.tile[data-type="6"]:hover { transform: none; filter: none; }

@media (max-width: 900px) {
  .modebar { gap: 10px; }
  .name-field { margin-left: 0; }
  .mode-btn { padding: 7px 11px; font-size: 12.5px; }
}


/* ── Themes ───────────────────────────────────────────────────────
   A theme is a palette swap: background, glow, accents and the six tile
   colours. Levels can suggest one, and the player can override it. */
:root[data-theme="ocean"] {
  --bg: #04101c;
  --bg-2: #071a2b;
  --accent: #38bdf8;
  --accent-2: #22d3ee;
  --glow-a: rgba(56, 189, 248, 0.20);
  --glow-b: rgba(34, 211, 238, 0.12);

  --t0: #fb7185;
  --t1: #fbbf24;
  --t2: #34d399;
  --t3: #38bdf8;
  --t4: #818cf8;
  --t5: #bae6fd;
}

:root[data-theme="meadow"] {
  --bg: #06120a;
  --bg-2: #0a1d10;
  --accent: #86efac;
  --accent-2: #fbbf24;
  --glow-a: rgba(134, 239, 172, 0.16);
  --glow-b: rgba(251, 191, 36, 0.10);

  --t0: #f97316;
  --t1: #facc15;
  --t2: #4ade80;
  --t3: #2dd4bf;
  --t4: #a3e635;
  --t5: #fda4af;
}

/* ── Level chip ──────────────────────────────────────────────────── */

.level-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 6px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  font-size: 12.5px;
  min-width: 0;
}

.level-num {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  color: #150e2b;
  font-weight: 800;
  font-size: 12px;
}

.level-name {
  color: var(--ink-dim);
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.level-stars {
  color: #fbbf24;
  letter-spacing: 1px;
  font-size: 12px;
}

.select-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  padding: 7px 0 3px;
}

.select-row select {
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--panel-line);
  border-radius: 9px;
  padding: 6px 8px;
}

@media (max-width: 520px) {
  .level-name { max-width: 84px; }
}


/* ── Matrix ───────────────────────────────────────────────────────
   Monochrome green, katakana tiles, scanlines. Deliberately not a hue
   swap of the default: the tile shape, font and texture all change. */
:root[data-theme="matrix"] {
  --bg: #000700;
  --bg-2: #01130a;
  --panel: rgba(0, 255, 65, 0.05);
  --panel-line: rgba(0, 255, 65, 0.18);
  --ink: #b7ffce;
  --ink-dim: #4f9c6a;
  --accent: #00ff41;
  --accent-2: #0aff9d;
  --glow-a: rgba(0, 255, 65, 0.16);
  --glow-b: rgba(0, 255, 65, 0.06);

  --t0: #00ff41;
  --t1: #7dffb0;
  --t2: #0aff9d;
  --t3: #00d97e;
  --t4: #b6ffcc;
  --t5: #2bff88;

  --tile-radius: 4px;
  --tile-border: 1px solid rgba(0, 255, 65, 0.5);
  --tile-glyph: rgba(0, 20, 8, 0.82);
  --tile-font: "Consolas", "SFMono-Regular", ui-monospace, monospace;
  --tile-shadow: 0 0 10px rgba(0, 255, 65, 0.35), inset 0 0 8px rgba(0, 0, 0, 0.5);
  --tile-overlay: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.35) 0 1px, transparent 1px 3px);
  --tile-overlay-opacity: 1;
}

/* ── Cyberpunk ────────────────────────────────────────────────────
   Hard corners, neon outlines, hot pink and cyan. */
:root[data-theme="cyberpunk"] {
  --bg: #0a0016;
  --bg-2: #150030;
  --panel: rgba(255, 46, 136, 0.07);
  --panel-line: rgba(0, 229, 255, 0.22);
  --ink: #eaf7ff;
  --ink-dim: #948fd6;
  --accent: #ff2e88;
  --accent-2: #00e5ff;
  --glow-a: rgba(255, 46, 136, 0.20);
  --glow-b: rgba(0, 229, 255, 0.14);

  --t0: #ff2e88;
  --t1: #faff00;
  --t2: #00e5ff;
  --t3: #9d00ff;
  --t4: #00ffa3;
  --t5: #ff7ad9;

  --tile-radius: 2px;
  --tile-border: 2px solid rgba(0, 229, 255, 0.55);
  --tile-glyph: rgba(4, 0, 16, 0.85);
  --tile-font: "Rajdhani", "Segoe UI", system-ui, sans-serif;
  --tile-shadow: 0 0 12px rgba(255, 46, 136, 0.45), 0 2px 6px rgba(0, 0, 0, 0.6);
  --tile-overlay: linear-gradient(115deg, rgba(255, 255, 255, 0.35) 0%, transparent 40%, transparent 60%, rgba(0, 0, 0, 0.3) 100%);
  --tile-overlay-opacity: 0.45;
}

/* ── Woodcut ──────────────────────────────────────────────────────
   Warm oak, serif card pips, a printed grain. */
:root[data-theme="wood"] {
  --bg: #1b120a;
  --bg-2: #2a1c0f;
  --panel: rgba(217, 160, 102, 0.08);
  --panel-line: rgba(217, 160, 102, 0.26);
  --ink: #f3e3c8;
  --ink-dim: #b89a72;
  --accent: #d9a066;
  --accent-2: #e0b57b;
  --glow-a: rgba(217, 160, 102, 0.16);
  --glow-b: rgba(107, 62, 26, 0.18);

  --t0: #b23a2e;
  --t1: #d9a066;
  --t2: #6b8e23;
  --t3: #2e5a7a;
  --t4: #8b5a2b;
  --t5: #d7c4a3;

  --tile-radius: 11px;
  --tile-border: 1px solid rgba(63, 42, 20, 0.65);
  --tile-glyph: rgba(38, 22, 8, 0.72);
  --tile-font: "Newsreader", Georgia, "Times New Roman", serif;
  --tile-shadow: inset 0 2px 0 rgba(255, 240, 210, 0.35), inset 0 -4px 10px rgba(30, 15, 0, 0.55), 0 3px 8px rgba(0, 0, 0, 0.45);
  --tile-overlay: repeating-linear-gradient(92deg, rgba(60, 35, 10, 0.18) 0 2px, transparent 2px 6px);
  --tile-overlay-opacity: 1;
}

/* Headline type follows the era too. */
:root[data-theme="matrix"] .brand-name,
:root[data-theme="matrix"] .big-word { font-family: "Consolas", ui-monospace, monospace; letter-spacing: 0.04em; }
:root[data-theme="cyberpunk"] .brand-name,
:root[data-theme="cyberpunk"] .big-word { font-family: "Rajdhani", "Segoe UI", system-ui, sans-serif; letter-spacing: 0.12em; text-transform: uppercase; }
:root[data-theme="wood"] .brand-name,
:root[data-theme="wood"] .big-word { font-family: "Newsreader", Georgia, serif; }

/* ── Theme switcher ──────────────────────────────────────────────
   A popover rather than a bare select: swatches you can see at a glance,
   with hover, focus and active states, and its own light/dark awareness. */
.theme-panel {
  position: fixed;
  top: 72px;
  right: max(18px, calc((100vw - 1120px) / 2 + 22px));
  width: 268px;
  padding: 12px;
  z-index: 60;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 40%),
    rgba(14, 12, 24, 0.94);
  border: 1px solid var(--panel-line);
  border-radius: 16px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.6), 0 2px 0 rgba(255, 255, 255, 0.05) inset;
  backdrop-filter: blur(14px);
  animation: panelIn 160ms cubic-bezier(.2, .9, .3, 1.1);
}

.theme-panel[hidden] { display: none; }

/* little pointer back at the toolbar button */
.theme-panel::before {
  content: "";
  position: absolute;
  top: -6px;
  right: 22px;
  width: 11px;
  height: 11px;
  background: rgba(14, 12, 24, 0.94);
  border-left: 1px solid var(--panel-line);
  border-top: 1px solid var(--panel-line);
  transform: rotate(45deg);
}

@keyframes panelIn {
  from { opacity: 0; transform: translateY(-6px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.theme-panel-title {
  margin: 2px 2px 10px;
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-dim);
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-panel-title kbd {
  font: inherit;
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--panel-line);
  border-radius: 5px;
  padding: 1px 5px;
}

.theme-grid {
  display: grid;
  gap: 3px;
}

.theme-swatch {
  font: inherit;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition: background 130ms ease, border-color 130ms ease, transform 90ms ease;
}

.theme-swatch:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: var(--panel-line);
}

.theme-swatch:active { transform: scale(0.985); }

.theme-swatch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.theme-swatch.is-active {
  background: rgba(255, 255, 255, 0.10);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.theme-swatch.is-active .swatch-label { font-weight: 700; }

.theme-swatch.is-active::after {
  content: "✓";
  margin-left: auto;
  color: var(--accent);
  font-size: 12px;
}

.swatch-dots {
  display: inline-flex;
  gap: 3px;
  flex: 0 0 auto;
}

.swatch-dots i {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.swatch-label { font-size: 13.5px; }

@media (max-width: 900px) {
  .theme-panel {
    left: 12px;
    right: 12px;
    width: auto;
    top: 64px;
  }
  .theme-panel::before { right: 26px; }
  .theme-grid { grid-template-columns: 1fr 1fr; }
  .theme-swatch { padding: 9px 8px; }
  .swatch-label { font-size: 12.5px; }
}


/* ── Feedback on the counters ────────────────────────────────────── */

.stat-val.pulse {
  display: inline-block;
  animation: scorePulse 420ms cubic-bezier(.2, .9, .3, 1.2);
}

@keyframes scorePulse {
  0% { transform: scale(1); }
  35% { transform: scale(1.16); color: var(--accent-2); }
  100% { transform: scale(1); }
}

.stat.is-low {
  border-color: rgba(251, 113, 133, 0.55);
  background: rgba(251, 113, 133, 0.08);
}

.stat.is-low .stat-val {
  color: #fb7185;
  animation: lowPulse 1.1s ease-in-out infinite;
}

@keyframes lowPulse {
  50% { opacity: 0.5; }
}

@media (prefers-reduced-motion: reduce) {
  .stat-val.pulse,
  .stat.is-low .stat-val { animation: none; }
}


/* ── Goal bar ──────────────────────────────────────────────────────
   The score counter tells you the number; the bar tells you how far that is.
   The scale runs to twice the target so the star thresholds fit on it. */
.goal-bar {
  position: relative;
  height: 8px;
  margin: 2px 0 2px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.5);
}

.goal-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 12px var(--accent);
  transition: width 340ms cubic-bezier(.2, .8, .3, 1);
}

.goal-tick {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(255, 255, 255, 0.4);
  pointer-events: none;
}

.goal-bar.is-complete .goal-fill {
  background: linear-gradient(90deg, var(--accent-2), #fbbf24);
  box-shadow: 0 0 16px #fbbf24;
}


/* ── Level map ─────────────────────────────────────────────────────
   Reuses the theme popover shell; only the contents differ. */
.level-panel {
  width: 320px;
  /* Five adventures is ~590px of content; the old 520px cap left the last
     block permanently half-hidden behind a scrollbar. */
  max-height: min(80vh, 680px);
  overflow-y: auto;
  /* Opaque, unlike the theme popover: this one is tall enough to sit over the
     leaderboard, and 94% alpha let the scores read through the level numbers. */
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent 40%),
    #0e0c18;
  z-index: 70;
}

.level-panel::-webkit-scrollbar { width: 8px; }
.level-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 8px;
}

/* Nudge the little pointer so it still lines up under the map button. */
.level-panel::before { right: 60px; }

.adventure-list { display: flex; flex-direction: column; gap: 14px; }

.adventure-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}

.adventure-name {
  font-weight: 700;
  font-size: 13.5px;
}

.adventure-count {
  font-size: 11px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}

.adventure-blurb {
  margin: 0 0 8px;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--ink-dim);
}

.adventure.is-complete .adventure-name { color: var(--good); }
.adventure.is-complete .adventure-count { color: var(--good); }

.level-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 5px;
}

.level-cell {
  position: relative;
  font: inherit;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--panel-line);
  border-radius: 9px;
  padding: 7px 0 5px;
  cursor: pointer;
  transition: background 130ms, border-color 130ms, transform 90ms;
}

.level-cell:hover:not(.is-locked) { background: rgba(255, 255, 255, 0.14); }
.level-cell:active:not(.is-locked) { transform: scale(0.96); }

.level-cell.is-current {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}

.level-cell.is-locked {
  opacity: 0.38;
  cursor: not-allowed;
}

.level-cell .level-cell-stars {
  display: block;
  font-size: 8.5px;
  letter-spacing: 0.5px;
  color: #fbbf24;
  margin-top: 1px;
}

.level-cell.is-locked .level-cell-stars { color: transparent; }

@media (max-width: 900px) {
  .level-panel {
    width: auto;
    left: 12px;
    right: 12px;
  }
  .level-cell { padding: 9px 0 7px; }
}


/* ── Objectives ────────────────────────────────────────────────────
   A collect objective is a second win condition, so it sits on its own row
   under the score bar rather than being folded into it. */
.objective {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: -8px 0 0;
  font-size: 12px;
  color: var(--ink-dim);
  animation: panelIn 160ms ease;
}

.objective[hidden] { display: none; }

.objective-label {
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.objective-parts { display: inline-flex; gap: 8px; flex-wrap: wrap; }

.objective-part {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px 4px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-line);
  font-variant-numeric: tabular-nums;
  transition: border-color 160ms, background 160ms;
}

.objective-glyph {
  font-style: normal;
  font-size: 11px;
  line-height: 1;
  color: var(--t, var(--ink));
  text-shadow: 0 0 8px color-mix(in srgb, var(--t, transparent) 60%, transparent);
}

.objective-part b { color: var(--ink); font-weight: 700; }
.objective-need { color: var(--ink-dim); }

.objective-part.is-done {
  border-color: color-mix(in srgb, var(--good) 55%, transparent);
  background: color-mix(in srgb, var(--good) 12%, transparent);
}
.objective-part.is-done .objective-need { color: color-mix(in srgb, var(--good) 70%, white); }
.objective-check { color: var(--good); font-size: 11px; }

/* Objective badge on a level-map cell */
.level-cell .level-cell-goal {
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 7px;
  line-height: 1;
  color: #fbbf24;
  opacity: 0.85;
}

@media (max-width: 620px) {
  .objective { gap: 6px; }
  .objective-part { padding: 3px 8px 3px 6px; }
}
