:root {
  --bg: #0f1115;
  --tile-off: #191d24;
  --tile-off-edge: #2b313c;
  --tile-on: #f4f4f5;
  --accent: #64d2ff;

  /* Sized by game.js on load and resize. */
  --tile: 56px;
  --gap: 9px;
  --gutter: 39px;
  --grid-w: 251px;
  --stage-w: 329px;

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--tile-on);
  font: 500 16px/1 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---- progress hairline ---- */

.progress {
  position: fixed;
  inset: 0 0 auto;
  height: 2px;
  background: #1b2029;
  z-index: 3;
}

.progress > i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .26s cubic-bezier(.22, .61, .36, 1);
}

/* ---- build stamp ---- */

/* Also the manual refresh: the page has no scroll, so there is no
   pull-to-refresh to fall back on. Padding buys a real tap target
   around a deliberately small label. */
.build {
  position: fixed;
  top: env(safe-area-inset-top);
  right: env(safe-area-inset-right);
  z-index: 5;
  padding: 13px 15px;
  border: 0;
  background: none;
  font: 400 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .08em;
  color: #5c636f;
  cursor: pointer;
  transition: color .12s ease;
}

.build:active { color: var(--accent); }

/* the hash could not be read — treat what you're looking at as unknown */
.build.unknown { color: #ff7a7a; }

/* ---- stage ---- */

.stage {
  width: var(--stage-w);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* ---- board ---- */

.board {
  position: relative;
  flex: 1;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 22%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 22%);
}

.stack {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0;
  transition: transform .26s cubic-bezier(.22, .61, .36, 1);
}

.row {
  position: absolute;
  left: 0;
  right: 0;
  height: var(--tile);
  display: flex;
  gap: var(--gap);
  padding: 0 var(--gutter);
  opacity: 0;
  transition: opacity .26s ease;
}

.tile {
  flex: 1;
  border-radius: calc(var(--tile) * .18);
  background: var(--tile-off);
  box-shadow: inset 0 0 0 1px var(--tile-off-edge);
}

.tile.on {
  background: var(--tile-on);
  box-shadow: none;
}

/* the two operand rows read a touch brighter than the queue above them */
.row.op .tile.on { box-shadow: 0 0 calc(var(--tile) * .3) rgba(244, 244, 245, .28); }

.plus {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--gutter);
  height: var(--tile);
  display: grid;
  place-items: center;
  font-size: calc(var(--tile) * .46);
  font-weight: 400;
  color: var(--tile-on);
  opacity: 0;
  transition: opacity .26s ease;
}

.row.lower .plus { opacity: .45; }

/* ---- rule ---- */

.rule {
  width: var(--grid-w);
  height: 2px;
  margin: calc(var(--tile) * .34) auto calc(var(--tile) * .3);
  border-radius: 2px;
  background: var(--tile-on);
  opacity: .8;
}

/* ---- input ---- */

.input {
  display: flex;
  gap: var(--gap);
  padding: 0 var(--gutter) calc(var(--tile) * .42 + env(safe-area-inset-bottom));
}

.itile {
  flex: 1;
  height: var(--tile);
  padding: 0;
  border: 0;
  border-radius: calc(var(--tile) * .18);
  background: var(--tile-off);
  box-shadow: inset 0 0 0 2px var(--tile-off-edge);
  cursor: pointer;
  transition: transform .09s ease, background .09s ease, box-shadow .09s ease;
}

.itile.on {
  background: var(--tile-on);
  box-shadow: inset 0 0 0 2px var(--tile-on);
}

.itile:active { transform: scale(.93); }

/* ---- summary ---- */

.summary {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 10, 14, .84);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  animation: fade .28s ease both;
}

.summary[hidden] { display: none; }

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

.card {
  text-align: center;
  animation: rise .34s cubic-bezier(.22, .61, .36, 1) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px) scale(.97) }
  to   { opacity: 1; transform: none }
}

.score {
  display: block;
  font-size: clamp(3.5rem, 20vw, 6rem);
  font-weight: 700;
  letter-spacing: -.04em;
  line-height: .95;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.score-label,
.stats span,
.best {
  font-size: 11px;
  letter-spacing: .22em;
  color: #6d7482;
}

.score-label { display: block; margin-top: 10px; }

.stats {
  display: flex;
  justify-content: center;
  gap: clamp(20px, 8vw, 40px);
  margin: 34px 0 26px;
}

.stats div { display: grid; gap: 7px; }

.stats b {
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--tile-on);
}

.best { min-height: 13px; }
.best.new { color: var(--accent); }

/* ---- particle overlay ---- */

/* above the summary, so the finishing burst plays over it */
#fx {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 7;
}

@media (prefers-reduced-motion: reduce) {
  .stack, .row, .progress > i, .plus { transition-duration: .01ms; }
}
