:root {
  --bg: #0b0d10;
  --device-1: #2b2f35;
  --device-2: #14161a;
  --board-bg: #0c0e11;
  --cell-bg: #1a1d22;
  --ink: #f2f4f7;
  --muted: #8b93a1;
  --red-1: #f2635a;
  --red-2: #b81f1a;
  --blue-1: #46a3ee;
  --blue-2: #1c66b3;
  --yellow-1: #ffd44a;
  --yellow-2: #d99b00;
  --accent: #ff5b52;
  --radius: 12px;
}

* { box-sizing: border-box; }

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

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 800px at 50% -10%, #1b2130 0%, transparent 60%),
    radial-gradient(900px 700px at 90% 110%, #16232b 0%, transparent 55%),
    var(--bg);
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(10px, 3dvh, 24px) 16px;
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 1.8dvh, 18px);
  width: 100%;
  max-width: min(380px, calc((100dvh - 228px) * 0.8 + 32px));
}

.controls-hint {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--muted);
  text-align: center;
  opacity: 0.8;
}

.device-footer .hw-btn {
  flex: 0 0 40px;
  height: 34px;
  --radius: 9px;
}
.sound-toggle::after,
.shutdown-toggle::after {
  content: "";
  position: absolute;
  top: 5px;
  right: 5px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #f6c945;
  box-shadow: 0 0 5px #f6c945aa;
  pointer-events: none;
  transition: transform 80ms ease;
}
.sound-toggle[aria-pressed="false"]::after,
.shutdown-toggle[aria-pressed="false"]::after { background: #68707a; box-shadow: none; }
.sound-toggle:active::after,
.sound-toggle.key-pressed::after,
.shutdown-toggle:active::after { transform: translateY(3px); }
.sound-toggle svg { width: 17px; height: 17px; fill: currentColor; }
.sound-toggle svg path:not(:first-child) {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}
.sound-toggle[aria-pressed="false"] .sound-wave,
.sound-toggle[aria-pressed="true"] .sound-muted { display: none; }
.shutdown-toggle[aria-pressed="true"]::after {
  background: #7ce69a;
  box-shadow: 0 0 5px #7ce69aaa;
}
.shutdown-toggle svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.device-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  margin: 12px 4px 0;
}
.device-footer .sound-toggle { margin-inline-start: auto; }
.speaker-grille {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: 104px;
  height: 38px;
  border: 2px solid #090b0e;
  border-radius: 7px;
  background:
    radial-gradient(circle, #69717a 0 1px, transparent 1.45px) 0 0 / 7px 7px,
    linear-gradient(160deg, #090b0e, #1d2025);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.68), 0 1px 0 rgba(255, 255, 255, 0.1);
}
.device.powered-off .device-top,
.device.powered-off .board { visibility: hidden; }

/* ---------- Device body ---------- */
.device {
  width: 100%;
  background: linear-gradient(165deg, var(--device-1), var(--device-2) 70%);
  border-radius: var(--radius);
  padding: 16px 16px 18px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.14) inset,
    0 -10px 30px rgba(0, 0, 0, 0.55) inset,
    0 30px 60px -20px rgba(0, 0, 0, 0.8),
    0 2px 6px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-bottom-color: rgba(255, 255, 255, 0.025);
}

.device-top {
  display: grid;
  grid-template-columns: minmax(0, 86fr) minmax(0, 96fr) repeat(3, minmax(0, 44fr));
  gap: 8px;
  margin-bottom: 14px;
}

.displays,
.device-buttons { display: contents; }

.device-top > .displays > *,
.device-top > .device-buttons > * {
  height: 60px;
  min-width: 0;
}

/* ---------- LED mini display ---------- */
.led {
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(160deg, #05070a, #0c0f13);
  border-radius: var(--radius);
  padding: 8px 10px;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.05) inset,
    0 4px 10px rgba(0, 0, 0, 0.6) inset,
    0 1px 0 rgba(255, 255, 255, 0.06);
}

.led-grid {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 2px;
  width: 34px;
  height: 43px;
}

.led-px {
  border-radius: 1.5px;
  background: #14181d;
  box-shadow: 0 0 1px rgba(0, 0, 0, 0.6) inset;
  transition: background 0.12s ease, box-shadow 0.12s ease;
}
.led-px.on-red { background: #ff3b30; box-shadow: 0 0 5px #ff3b30aa; }
.led-px.on-yellow { background: #ffd60a; box-shadow: 0 0 4px #ffd60aaa; }
.led-px.on-green { background: #30d158; box-shadow: 0 0 4px #30d158aa; }
.led-px.on-blue { background: #0a84ff; box-shadow: 0 0 4px #0a84ffaa; }

.led.celebrate .led-label { color: #48e08a; }
.led.celebrate .led-px {
  background: #16482a;
  box-shadow: none;
  animation: led-sweep 550ms ease-out both;
}
.led.celebrate .led-px:nth-child(n + 5) { animation-delay: 80ms; }
.led.celebrate .led-px:nth-child(n + 9) { animation-delay: 160ms; }
.led.celebrate .led-px:nth-child(n + 13) { animation-delay: 240ms; }
.led.celebrate .led-px:nth-child(n + 17) { animation-delay: 320ms; }
.led.celebrate .led-px:is(:nth-child(8), :nth-child(9), :nth-child(11), :nth-child(14)) {
  background: #48e08a;
  box-shadow: 0 0 5px #48e08aaa;
}
@keyframes led-sweep {
  0% { opacity: 0.4; }
  45% { background: #a4ffbc; box-shadow: 0 0 6px #48e08a; }
  100% { opacity: 1; }
}

.led-info {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  line-height: 1;
  white-space: nowrap;
}
.led-label {
  font-size: 8px;
  letter-spacing: 1px;
  color: #3c7d55;
  font-weight: 700;
}
.led-level {
  font-family: "Consolas", "SFMono-Regular", monospace;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #48e08a;
  text-shadow: 0 0 8px rgba(72, 224, 138, 0.55);
}
.led-level.three-digits { font-size: 13px; }

/* ---------- Secondary meter display ---------- */
.meter {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  background: linear-gradient(160deg, #05070a, #0c0f13);
  border-radius: var(--radius);
  padding: 5px 10px;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.05) inset,
    0 4px 10px rgba(0, 0, 0, 0.6) inset,
    0 1px 0 rgba(255, 255, 255, 0.06);
}
.meter-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.meter-label {
  font-size: 8px;
  letter-spacing: 0.75px;
  font-weight: 700;
  color: #3c7d55;
}
.meter-value {
  font-family: "Consolas", "SFMono-Regular", monospace;
  font-size: 13px;
  line-height: 1;
  font-weight: 700;
  color: #48e08a;
  text-shadow: 0 0 7px rgba(72, 224, 138, 0.5);
  font-variant-numeric: tabular-nums;
}

.meter.on-par {
  box-shadow: inset 0 0 0 1px #48e08a80, inset 0 0 12px #48e08a26;
}
.meter.on-par .meter-label { color: #48e08a; }
.meter-par-art { display: none; }
.meter.on-par .meter-par-art {
  position: absolute;
  inset: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: calc(var(--radius) - 2px);
  background: #0a1510;
  color: #48e08a;
  pointer-events: none;
  animation: par-readout 1100ms ease-out both;
}
.meter-par-art svg {
  width: 76%;
  max-width: 66px;
  filter: drop-shadow(0 0 4px #48e08a80);
}
.meter-par-art path { animation: par-pixel-on 260ms ease-out both; }
.meter-par-art path:nth-child(2) { animation-delay: 100ms; }
.meter-par-art path:nth-child(3) { animation-delay: 200ms; }

@keyframes par-pixel-on {
  from { opacity: 0; }
  50% { color: #c5ffdc; }
  to { opacity: 1; }
}
@keyframes par-readout {
  0%, 74% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------- Hardware buttons ---------- */
.hw-btn {
  --key-top: #454b54;
  --key-bottom: #2a2e35;
  --key-base: #171a20;
  position: relative;
  width: 100%;
  padding: 0 0 4px;
  border: 1px solid #101216;
  border-radius: var(--radius);
  cursor: pointer;
  color: #e5e9ef;
  background: var(--key-base);
  box-shadow: 0 1px 0 #ffffff12;
  display: grid;
  place-items: center;
}
.hw-btn::before {
  content: "";
  position: absolute;
  inset: 1px 1px 5px;
  border-radius: calc(var(--radius) - 2px);
  background: linear-gradient(165deg, var(--key-top), var(--key-bottom) 82%);
  box-shadow: inset 0 1px 0 #ffffff30, inset 0 -1px 0 #0005, 0 1px 2px #0006;
  pointer-events: none;
  transition: transform 80ms ease, filter 120ms ease;
}
.hw-btn > * {
  position: relative;
  filter: drop-shadow(0 1px 0 #0008);
  transition: transform 80ms ease;
}
.hw-btn:hover:not(:disabled)::before { filter: brightness(1.14); }
.hw-btn:active:not(:disabled)::before,
.hw-btn.key-pressed::before,
.hw-btn.key-pressed > *,
.hw-btn:active:not(:disabled) > * { transform: translateY(3px); }
.hw-btn:disabled {
  cursor: default;
  color: #9da5b0;
}
.hw-btn:disabled::before { filter: brightness(0.82); }
.hw-btn:focus-visible {
  outline: 2px solid rgba(120, 180, 255, 0.85);
  outline-offset: 2px;
}
.hw-btn svg { display: block; }

#btnReset {
  --key-top: #e3685e;
  --key-bottom: #a82924;
  --key-base: #651a19;
  color: #fff1ed;
  font: 800 17px/1 ui-monospace, monospace;
}

/* ---------- Board ---------- */
.board {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 5;
  background: linear-gradient(160deg, #101318, #07080b);
  border-radius: var(--radius);
  padding: 8px;
  box-shadow:
    0 0 0 2px rgba(0, 0, 0, 0.6),
    0 0 0 3px rgba(255, 255, 255, 0.05),
    0 10px 24px rgba(0, 0, 0, 0.55) inset;
  touch-action: none;
  overflow: hidden;
}

.cells {
  position: absolute;
  inset: 8px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(5, 1fr);
}
.cell {
  background: var(--cell-bg);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.55) inset,
    0 1px 0 rgba(255, 255, 255, 0.03) inset;
}

.goal {
  position: absolute;
  left: calc(8px + (100% - 16px) * 0.25);
  top: calc(8px + (100% - 16px) * 0.60);
  width: calc((100% - 16px) * 0.5);
  height: calc((100% - 16px) * 0.4);
  border: 2px dashed rgba(255, 90, 80, 0.35);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  background: rgba(255, 90, 80, 0.04);
}
.goal svg {
  width: 34%;
  fill: none;
  stroke: rgba(255, 90, 80, 0.28);
  stroke-width: 2;
  stroke-linejoin: round;
}
.board.solved .goal { opacity: 0; }

.tiles {
  position: absolute;
  inset: 8px;
}

/* ---------- Tiles ---------- */
.tile {
  position: absolute;
  padding: 2.5px;
  cursor: grab;
  transition: left 0.13s cubic-bezier(0.3, 0.7, 0.4, 1),
              top 0.13s cubic-bezier(0.3, 0.7, 0.4, 1);
  touch-action: none;
}
.tile.dragging { cursor: grabbing; z-index: 5; }
.tile .face {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow:
    0 2px 1px rgba(255, 255, 255, 0.28) inset,
    0 -6px 10px rgba(0, 0, 0, 0.38) inset,
    0 5px 9px rgba(0, 0, 0, 0.45),
    0 1px 0 rgba(255, 255, 255, 0.06);
}
.tile .face::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(150deg, rgba(255, 255, 255, 0.28), transparent 42%);
  pointer-events: none;
}

/* Big red 2x2 */
.tile.big .face {
  border-radius: var(--radius);
  background: linear-gradient(155deg, var(--red-1), var(--red-2) 85%);
}
.tile .tile-pattern {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: var(--groove-color);
  stroke-width: 3px;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 1px 0 var(--groove-light));
  pointer-events: none;
}
.tile-pattern .groove {
  vector-effect: non-scaling-stroke;
}
.tile-pattern .groove-inset {
  fill: var(--groove-inset);
}
.tile-pattern .facet {
  fill: #ffffff19;
  stroke: none;
}
.tile-pattern .groove-core {
  fill: var(--groove-color);
  stroke: none;
  opacity: 0.55;
}
.tile.big {
  --groove-color: #800a0a9c;
  --groove-inset: #800a0a4d;
  --groove-light: #ffa08a73;
}

/* Blue rectangles */
.tile.rect .face {
  background: linear-gradient(155deg, var(--blue-1), var(--blue-2) 88%);
}
.tile.rect {
  --groove-color: #06346a9e;
  --groove-inset: #06346a4d;
  --groove-light: #9cddff73;
}
.tile.rect.target .face {
  background: linear-gradient(155deg, var(--red-1), var(--red-2) 85%);
}
.tile.rect.target {
  --groove-color: #800a0a9c;
  --groove-inset: #800a0a4d;
  --groove-light: #ffa08a73;
}

/* Yellow small squares */
.tile.small .face {
  border-radius: var(--radius);
  background: linear-gradient(155deg, var(--yellow-1), var(--yellow-2) 92%);
}
.tile.small {
  --groove-color: #936000a8;
  --groove-light: #fff3a573;
}

/* selection */
.tile.selected .face {
  outline: 3px solid rgba(255, 255, 255, 0.85);
  outline-offset: -3px;
  filter: brightness(1.08);
}

/* win flash */
.board.solved .tile.big .face,
.board.solved .tile.target .face {
  animation: winpulse 0.7s ease-in-out 2 alternate;
}
@keyframes winpulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.35) drop-shadow(0 0 10px rgba(255, 90, 80, 0.8)); }
}

@media (prefers-reduced-motion: reduce) {
  .meter.on-par .meter-par-art { display: none; }
  .led.celebrate .led-px,
  .board.solved .tile.big .face,
  .board.solved .tile.target .face { animation: none; }
}

/* ---------- Control panel ---------- */
.panel {
  width: 100%;
  padding: 0 6px;
}
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.level-name {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.3px;
}
.badge {
  display: inline-block;
  margin-top: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(70, 163, 238, 0.16);
  color: #7dc0ff;
  border: 1px solid rgba(70, 163, 238, 0.3);
}
.badge[data-diff="Beginner"] { background: rgba(48,209,88,.16); color:#5be07d; border-color: rgba(48,209,88,.3); }
.badge[data-diff="Makkelijk"] { background: rgba(72,224,138,.16); color:#48e08a; border-color: rgba(72,224,138,.3); }
.badge[data-diff="Gelijkmatig"] { background: rgba(255,214,10,.14); color:#ffd60a; border-color: rgba(255,214,10,.3); }
.badge[data-diff="Moeilijk"] { background: rgba(255,159,10,.16); color:#ffb340; border-color: rgba(255,159,10,.3); }
.badge[data-diff="Expert"] { background: rgba(255,69,58,.16); color:#ff6b60; border-color: rgba(255,69,58,.3); }

.ghost-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.ghost-btn:hover { background: rgba(255, 255, 255, 0.1); }

.goal-text {
  margin: 12px 0 14px;
  font-size: 13.5px;
  color: var(--muted);
}
.goal-text strong { color: #ff7a70; }

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.stat {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: var(--radius);
  padding: 8px 6px;
  text-align: center;
}
.stat-label { display: block; font-size: 10px; letter-spacing: 0.6px; text-transform: uppercase; color: var(--muted); }
.stat-value { display: block; font-size: 18px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }

.controls {
  display: grid;
  grid-template-columns: 48px 1fr 1fr 48px;
  gap: 8px;
}
.ctrl-btn {
  height: 46px;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.06s ease;
}
.ctrl-btn:hover { background: rgba(255, 255, 255, 0.11); }
.ctrl-btn:active { transform: translateY(1px); }
.ctrl-btn.primary {
  background: linear-gradient(160deg, #ff6b60, #d8322a);
  border-color: transparent;
  box-shadow: 0 6px 16px -6px rgba(255, 91, 82, 0.8);
}
.ctrl-btn.primary:hover { background: linear-gradient(160deg, #ff7d73, #e33c33); }
.ctrl-btn .chev { font-size: 22px; line-height: 0; }

.hint {
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 9, 0.72);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal[hidden] { display: none; }
.modal-card {
  width: 100%;
  max-width: 460px;
  max-height: 80dvh;
  overflow: auto;
  background: linear-gradient(170deg, #242830, #14171b);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.9);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.modal-head h2 { margin: 0; font-size: 18px; }
.icon-btn {
  width: 34px; height: 34px;
  border-radius: var(--radius);
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.15); }

.level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.level-chip {
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius);
  padding: 10px 4px 8px;
  cursor: pointer;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.level-chip:hover:not(:disabled) { background: rgba(255, 255, 255, 0.1); }
.level-chip:disabled { cursor: default; opacity: 0.55; }
.level-chip:disabled .dot { visibility: hidden; }
.level-chip .num { font-size: 16px; font-weight: 700; }
.level-chip .par { font-size: 10px; color: var(--muted); }
.level-chip.done { border-color: rgba(48, 209, 88, 0.5); }
.level-chip.done::after {
  content: "✓";
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 11px;
  color: #48e08a;
  font-weight: 700;
}
.level-chip.current {
  background: linear-gradient(160deg, rgba(255, 107, 96, 0.3), rgba(216, 50, 42, 0.2));
  border-color: rgba(255, 107, 96, 0.7);
}
.level-chip .dot {
  width: 7px; height: 7px; border-radius: 50%; margin-top: 3px;
  background: var(--muted);
}
.level-chip[data-diff="Beginner"] .dot { background: #30d158; }
.level-chip[data-diff="Makkelijk"] .dot { background: #48e08a; }
.level-chip[data-diff="Gelijkmatig"] .dot { background: #ffd60a; }
.level-chip[data-diff="Moeilijk"] .dot { background: #ff9f0a; }
.level-chip[data-diff="Expert"] .dot { background: #ff453a; }

/* ---------- Win overlay ---------- */
.win {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 6, 9, 0.7);
  backdrop-filter: blur(7px);
  z-index: 60;
  padding: 20px;
  animation: fadein 0.2s ease;
}
.win[hidden] { display: none; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.win-card {
  position: relative;
  width: 100%;
  max-width: 340px;
  background: linear-gradient(170deg, #262a32, #14171b);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: var(--radius);
  padding: 24px 22px 20px;
  text-align: center;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.9);
  overflow: hidden;
  animation: pop 0.32s cubic-bezier(0.2, 0.9, 0.35, 1.1);
}
@keyframes pop { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.win-glow {
  position: absolute;
  top: -60%;
  left: 50%;
  transform: translateX(-50%);
  width: 260px;
  height: 260px;
  background: radial-gradient(circle, rgba(255, 91, 82, 0.5), transparent 65%);
  pointer-events: none;
}
.win-kicker {
  position: relative;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 3px;
  font-size: 12px;
  font-weight: 700;
  color: #ff7a70;
}
.win-title { position: relative; margin: 4px 0 18px; font-size: 22px; }
.win-stats {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}
.win-stats > div {
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius);
  padding: 10px 6px;
}
.win-stats span { display: block; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.win-stats small { color: var(--muted); font-size: 11px; }
.win-actions { position: relative; display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }

/* ---------- Responsive ---------- */
@media (max-width: 390px) {
  .device { padding: 12px 12px 14px; }
  .device-top { gap: 6px; }
  .led, .meter { padding-inline: 6px; }
  .led, .meter-row { gap: 4px; }
  .led-grid { width: 27px; height: 35px; }
  .led-level { font-size: 15px; }
}

@media (max-width: 360px) {
  .tile { padding: 2px; }
  .stats { gap: 6px; }
  .stat-value { font-size: 16px; }
  .controls { grid-template-columns: 42px 1fr 1fr 42px; }
  .ctrl-btn { font-size: 12.5px; }
}

/* Keep the whole game on screen in short windows and landscape phones. */
@media (max-height: 560px) {
  body { padding-block: 8px; }
  .stage {
    gap: 8px;
    max-width: min(380px, calc((100dvh - 146px) * 0.8 + 20px));
  }
  .device { padding: 10px 10px 12px; }
  .device-top { gap: 6px; margin-bottom: 8px; }
  .device-top > .displays > *,
  .device-top > .device-buttons > * { height: 52px; }
  .led { padding: 5px 8px; }
  .led-grid { width: 28px; height: 38px; }
  .meter { padding: 4px 8px; gap: 1px; }
  .meter-label { font-size: 7px; }
  .meter-value { font-size: 12px; }
  .device-footer { min-height: 30px; margin: 6px 2px 0; }
  .controls-hint { display: none; }
}

/* Short landscape phones: drop decorative readouts so the controls stay readable. */
@media (max-height: 430px) {
  .led-grid, .led-label, .meter-label { display: none; }
  .led, .meter-row { justify-content: center; }
  .device-top { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .led-level { font-size: 16px; }
}

@media (max-height: 350px) {
  .meter { display: none; }
  .device-top { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
