:root {
  /* Figma board is drawn at 132px cells; the page mockup renders it at ~0.5×.
     --cols is set by JS per level. Board may never exceed viewport width − 40px. */
  --cols: 3;
  --design-width: calc(22 * 2 + var(--cols) * 132 + (var(--cols) - 1) * 10);
  --unit: min(0.5px, calc((100vw - 40px) / var(--design-width)));
  --cell: calc(132 * var(--unit));
  --gap: calc(10 * var(--unit));
  --pad: calc(22 * var(--unit));
  --r-board: calc(32 * var(--unit));
  --r-cell: calc(24 * var(--unit));
  --icon: calc(40 * var(--unit));
  --btn-icon: calc(68 * var(--unit));
  --replay-w: calc(130 * var(--unit));

  --bg: #000;
  --board: #c9c9c9;
  --off: #fff;
  --on: #14d464;
  --red: #ff0000;
  --ink: #000;
  --replay: #a9a9a9;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: #fff;
  touch-action: manipulation;
  overflow: hidden;              /* no page scroll in either axis */
  overscroll-behavior: none;     /* no rubber-banding / pull-to-refresh */
}

body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  position: fixed;               /* iOS: stops the viewport scrolling the body */
  inset: 0;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.logo { padding: 19px 27px; }
.logo button { background: none; border: 0; padding: 0; cursor: pointer; line-height: 0; }
.logo img { display: block; width: 116px; height: auto; }

.foot { padding: 19px 27px; display: flex; justify-content: space-between; align-items: center; }
.credit { display: block; width: 80px; height: auto; opacity: 0.2; }
.shuffle {
  background: none; border: 0; padding: 4px; margin: -4px; cursor: pointer;
  opacity: 0.2; transition: opacity 300ms ease; line-height: 0;
  -webkit-tap-highlight-color: transparent;
}
.shuffle img { width: 24px; height: 24px; display: block; }
.shuffle:hover, .shuffle:focus-visible { opacity: 1; outline: none; }

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 0 20px;
}

.board {
  background: var(--board);
  border-radius: var(--r-board);
  padding: var(--pad);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-auto-rows: var(--cell);
  gap: var(--gap);
}

.grid.end {
  position: relative;
  width: calc(5 * var(--cell) + 4 * var(--gap));
  height: calc(5 * var(--cell) + 4 * var(--gap));
  display: block;
}
.grid.end img {
  position: absolute;
  left: calc(258 * var(--unit));
  top: calc(217 * var(--unit));
  width: calc(340 * var(--unit));
  height: auto;
}

.cell {
  width: var(--cell);
  height: var(--cell);
  border: 0;
  padding: 0;
  border-radius: var(--r-cell);
  background: var(--off);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background-color 120ms ease, transform 180ms cubic-bezier(.2, 1.4, .4, 1);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.cell:active:not(:disabled) { transform: scale(0.92); transition-duration: 120ms, 120ms; transition-timing-function: ease, ease-out; }
.cell.on { background: var(--ink); }
.cell.on .icon { color: #fff; }
.cell.on.bad .icon { color: var(--red); }
/* success + done: ON cells go green, icons in OFF cells go green, icons in ON cells stay white */
.board[data-state="success"] .cell.on,
.board[data-state="done"] .cell.on { background: var(--on); }
.board[data-state="success"] .cell:not(.on) .icon,
.board[data-state="done"] .cell:not(.on) .icon { color: var(--on); }
.cell.missing { background: transparent; cursor: default; pointer-events: none; }
.cell:disabled { cursor: default; }
.cell:focus-visible { outline: 3px solid #333; outline-offset: -3px; }

.icon { width: var(--icon); height: var(--icon); display: block; color: var(--ink); transition: color 500ms ease; }
.icon * { fill: currentColor; }
.cell.bad .icon { color: var(--red); }

.controls { display: flex; gap: 0; }

.btn {
  height: var(--cell);
  border: 0;
  border-radius: var(--r-cell);
  background: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background-color 500ms ease, width 550ms cubic-bezier(.4,0,.2,1), margin 550ms cubic-bezier(.4,0,.2,1), opacity 500ms ease, transform 180ms cubic-bezier(.2, 1.4, .4, 1);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  user-select: none;
}
.btn:active { transform: scale(0.95); transition-duration: 500ms, 550ms, 550ms, 500ms, 120ms; transition-timing-function: ease, cubic-bezier(.4,0,.2,1), cubic-bezier(.4,0,.2,1), ease, ease-out; }
.board[data-state="success"] .btn-main:active { transform: none; }
.btn svg {
  width: var(--btn-icon);
  height: var(--btn-icon);
  stroke: #fff;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 500ms ease, opacity 500ms ease;
}
.btn svg .fill { fill: #fff; stroke: none; }
.btn-main { flex: 1; min-width: 0; }
.btn-side { width: 0; min-width: 0; padding: 0; margin-right: 0; flex: none; background: var(--replay); opacity: 0; pointer-events: none; }
.btn-side.show { width: var(--replay-w); margin-right: var(--gap); opacity: 1; pointer-events: auto; }
.btn.swap svg { animation: iconSwap 500ms ease; }
@keyframes iconSwap {
  0% { opacity: 0; transform: scale(0.6); }
  100% { opacity: 1; transform: scale(1); }
}

.board[data-state="fail"] .btn-main { background: var(--red); }
.board[data-state="success"] .btn-main { background: var(--on); cursor: default; }

.dots { display: flex; gap: 8px; height: 6px; }
.dots[hidden] { visibility: hidden; }
.dots span { width: 6px; height: 6px; border-radius: 50%; background: #fff; opacity: 0.3; }
.dots span[aria-current="true"] { opacity: 1; }

@media (max-width: 600px) {
  .logo { display: flex; justify-content: center; }
}
