:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  --ink: #f8f2ff;
  --muted: #d4c4e2;
  --surface: #241931;
  --edge: #79658c;
  --accent: #e8c7ff;
  --on-accent: #291439;
  --focus: #ffe29a;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
body { margin: 0; }
button { font: inherit; touch-action: manipulation; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.tools { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.tools a, .tools button, .actions button, .stack {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: .45rem .75rem;
  border: 1px solid var(--edge);
  border-radius: .55rem;
  background: var(--surface);
  color: var(--ink);
  font: 650 .875rem/1.25 system-ui, sans-serif;
  text-decoration: none;
}
.tools button, .actions button, .stack { cursor: pointer; }
.tools a { margin-inline-end: auto; }
.tools a:hover { text-decoration: underline; }
@media (max-width: 23rem) {
  .tools a, .tools button { padding-inline: .55rem; }
}
.tools button[aria-pressed="true"], .actions button:not(.ghost), .stack {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
button:disabled { opacity: .65; cursor: default; }
.arcade-page { background: #15101e; color: var(--ink); }
.game-shell {
  display: grid;
  gap: .8rem;
  width: min(100%, 47rem);
  margin-inline: auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(.75rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
    max(.85rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}
.game-header { display: flex; justify-content: space-between; align-items: end; flex-wrap: wrap; gap: .6rem 1rem; }
.game-header h1 {
  margin: 0;
  color: var(--accent);
  font-size: clamp(1.85rem, 6.4vw, 3.3rem);
  line-height: 1;
  letter-spacing: -.055em;
}
.game-stats { display: flex; flex-wrap: wrap; gap: .4rem 1rem; margin: 0; }
.game-stats dt, .daily-meta, .hint, .over p { color: var(--muted); font-size: .875rem; }
.game-stats dd { margin: .15rem 0 0; font-size: 1.6rem; line-height: 1; font-weight: 750; font-variant-numeric: tabular-nums; }
.hint, .over p { margin: 0; line-height: 1.45; }

.tower-page[data-mode="daily"] {
  --accent: #ffe29a;
  --edge: #967350;
  --surface: #342438;
  --on-accent: #352116;
}
.tower-shell { grid-template-rows: auto auto minmax(15rem, 1fr) auto; }
.tower-page .game-header h1 { font-weight: 850; }
.daily-meta { display: flex; flex-wrap: wrap; gap: .15rem .8rem; margin-top: .4rem; }
.daily-meta time { font-variant-numeric: tabular-nums; }
.tower-field, #arena {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--edge);
  background: var(--surface);
}
.tower-field { border-radius: .55rem; }
#c { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: manipulation; }
.combo {
  position: absolute;
  inset: .8rem .8rem auto;
  color: var(--focus);
  font-weight: 750;
  text-align: center;
  pointer-events: none;
  opacity: 0;
}
.combo.on { opacity: 1; }
.game-footer { display: grid; justify-items: center; gap: .45rem; text-align: center; }
.stack { min-width: min(100%, 13rem); font-size: 1rem; }
.over {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  gap: .55rem;
  overflow: auto;
  padding: 1rem;
  background: var(--surface);
  text-align: center;
}
.over.show { display: flex; }
.over h2 { margin: 0; color: var(--accent); font-size: clamp(1.25rem, 5vw, 1.9rem); line-height: 1.15; }
.over .final { font-size: clamp(2.5rem, 12vw, 5rem); font-weight: 800; line-height: .95; font-variant-numeric: tabular-nums; }
.over .newbest { color: var(--accent); }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .55rem; margin-top: .35rem; }
.over input { width: min(100%, 25rem); min-height: 44px; padding: .5rem; font: inherit; }
#share-status:empty { display: none; }
.tower-page .over { background: color-mix(in srgb, var(--surface) 94%, transparent); }

.hue-page {
  background: #102522;
  --ink: #f4fff9;
  --muted: #b9ddd1;
  --surface: #18342e;
  --edge: #5b8a7c;
  --accent: #b9f8db;
  --on-accent: #122e25;
}
.hue-shell {
  width: min(100%, 37rem);
  grid-template-rows: auto auto auto minmax(18.25rem, 1fr) auto;
}
.hue-page h1 { font-weight: 680; }
.bar { height: .5rem; border-radius: 99px; background: #36534b; overflow: hidden; }
.bar i { display: block; height: 100%; width: 100%; background: #a5efcb; }
.bar i.warn { background: #ffe29a; }
.bar i.crit { background: #ff9d8e; }
#arena { display: grid; border-radius: 1rem; }
#board { display: grid; align-content: stretch; gap: clamp(3px, 1vw, 8px); padding: 3px; min-width: 0; }
.tile {
  position: relative;
  min-width: 0;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: clamp(.35rem, 1.8vw, .8rem);
  cursor: pointer;
}
.tile:focus-visible { z-index: 1; outline-offset: -4px; box-shadow: inset 0 0 0 6px #102522; }
.tile.wrong-tile { box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 6px #652b2f; }
#flashbad { position: absolute; inset: 0; background: #a82d36; opacity: 0; pointer-events: none; }
#board.wrong + #flashbad { opacity: .14; }
@media (prefers-reduced-motion: reduce) { #board.wrong + #flashbad { opacity: 0; } }
.shade-sample { display: grid; grid-template-columns: repeat(2, 1fr); gap: .3rem; width: 5.2rem; margin-bottom: .4rem; transform: rotate(-8deg); }
.shade-sample i { aspect-ratio: 1; background: #79c5a9; border-radius: .42rem; }
.shade-sample i:nth-child(3) { background: #b9f8db; }
.hue-shell .hint { text-align: center; }

@media (orientation: landscape) and (max-height: 31rem) {
  .hue-shell {
    grid-template:
      "tools  arena" auto
      "header arena" auto
      "timer  arena" auto
      "hint   arena" 1fr / clamp(8.5rem, 33vw, 13rem) minmax(0, 1fr);
    gap: .375rem .75rem;
    padding: max(.5rem, env(safe-area-inset-top)) max(.5rem, env(safe-area-inset-right))
      max(.5rem, env(safe-area-inset-bottom)) max(.5rem, env(safe-area-inset-left));
  }
  .hue-shell .tools {
    grid-area: tools;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .25rem;
  }
  .hue-shell .tools a, .hue-shell .tools button { margin: 0; padding-inline: .25rem; }
  .hue-shell .game-header { grid-area: header; gap: .35rem; }
  .hue-shell .game-header h1, .hue-shell .game-stats dd { font-size: 1.4rem; }
  .hue-shell .game-stats { width: 100%; gap: .75rem; }
  .hue-shell .bar { grid-area: timer; }
  .hue-shell .hint { grid-area: hint; text-align: start; font-size: .75rem; line-height: 1.3; }
  .hue-shell #arena { grid-area: arena; }
  .hue-shell #board { gap: 3px; }
  .hue-shell .tile { min-height: 0; }
  .hue-shell .over { padding: .75rem; }
  .hue-shell .over .final { font-size: 2.75rem; }
}
@media (orientation: landscape) and (max-width: 30rem) and (max-height: 17rem) {
  .hue-shell { column-gap: .25rem; }
  .hue-shell .tools :is(button, a) { min-height: 36px; padding: .15rem; font-size: .75rem; }
  .hue-shell .game-header h1, .hue-shell .game-stats dd { font-size: 1.15rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
