:root {
  --ground: #d7f6f2;
  --ink: #0e3c42;
  --board: #146870;
  --board-border: #0c3f44;
  --tile-shadow: #0a3338;
  --good: #e39b12;
  --coral: #ff5d3a;
  --cream: #fff8ef;
  --gap-accent: #b6fff2;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--ground); color: var(--ink); }
body {
  min-height: 100svh;
  font: 16px/1.2 system-ui, sans-serif;
}
main {
  width: min(100%, 520px);
  min-height: 100svh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
}
header, .hud { display: flex; justify-content: space-between; align-items: end; }
header small, .stats span {
  display: block; font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase;
}
header b { font-size: 22px; }
.goal { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; }
.goal i {
  display: block; height: 28px; border-radius: 99px; background: #fff;
  box-shadow: inset 0 0 0 3px var(--ink); overflow: hidden;
}
.goal i b { display: block; height: 100%; width: 0; background: var(--coral); transform-origin: left center; }
.goal span { font-size: 18px; font-weight: 900; font-variant-numeric: tabular-nums; }
.points b { font-size: clamp(42px, 12vw, 56px); line-height: .85; }
.points i { display: block; min-height: 22px; color: var(--coral); font-style: normal; font-weight: 900; font-size: 22px; }
.timer { text-align: right; min-width: 120px; }
.timer > b { font-size: 32px; color: #9a5b00; }
.timer i { display: block; height: 14px; margin-top: 6px; border-radius: 99px; background: #0e3c4224; overflow: hidden; }
.timer i b { display: block; height: 100%; width: 100%; background: #f0a202; transform: scaleX(0); transform-origin: left center; }
.board-wrap {
  flex: 1 1 auto; min-height: 0; margin-top: 18px;
  display: grid; place-items: center; position: relative;
  container-type: size;
}
.board-wrap > .board {
  width: min(100%, 100cqi, 100cqb); height: auto; aspect-ratio: 1; max-height: 100%;
}
.board { --cell: calc(100cqw / var(--n)); background: var(--board); border-radius: 18px; box-shadow: inset 0 0 0 4px var(--board-border); }
.tile .face { background: #fff; color: var(--ink); border-radius: 22%; box-shadow: 0 4px 0 var(--tile-shadow); }
.bgcell::before { content: ''; background: transparent; }
.bgcell.persistent::before { box-shadow: inset 0 0 0 3px var(--gap-accent); border-radius: 18%; }
.shout {
  position: absolute; z-index: 6; margin: 0; left: 0; right: 0; top: 42%;
  text-align: center; font-size: clamp(42px, 12vw, 64px); font-weight: 900; color: #fff;
  text-shadow: 0 4px 0 var(--ink), 0 0 16px var(--coral); pointer-events: none;
}
.shout:empty { display: none; }
button {
  min-height: 60px; border: 0; border-radius: 16px; background: var(--coral); color: var(--cream);
  font: 800 22px/1 system-ui, sans-serif;
}
button:disabled { background: #62556a; color: #fff; }
.level-sheet {
  position: absolute; inset: 8% 4%; z-index: 8; display: flex; flex-direction: column;
  justify-content: center; gap: 12px; text-align: center;
  background: var(--cream); border: 5px solid var(--ink); border-radius: 28px; box-shadow: 0 8px 0 var(--board);
  padding: 22px 14px;
}
.level-sheet[hidden] { display: none; }
.level-sheet h2 { margin: 0; font-size: 28px; }
.level-sheet > b { font-size: clamp(52px, 16vw, 72px); line-height: .9; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats div { background: #fff; border-radius: 14px; padding: 8px 4px; }
.stats b { display: block; font-size: 16px; }
.gem {
  position: fixed; z-index: 30; width: 14px; height: 14px; margin: -7px 0 0 -7px;
  border-radius: 4px; background: #fff; box-shadow: 0 0 0 2px var(--ink); pointer-events: none;
}
.clear-flash { position: absolute; z-index: 2; border-radius: 12px; background: #fff; pointer-events: none; }
