html {
  font-size: 1px;
}

:root {
  --bg: #14161c;
  --panel: #1d2129;
  --board: #1d222c;
  --floor-rgb: 0, 88, 143;
  --floor-alpha: 0.08;
  --piece-fill: 0.92; /* exit FX chip opacity (pieces are opaque plastic) */
  --piece-glow: 0; /* unused with plastic pieces; kept for settings export */
  --piece-radius: 0.18; /* corner radius as fraction of cell (Lego plate) */
  --grid-line-rgb: 92, 92, 92;
  --grid-line-alpha: 0.35;
  --grid-glow-rgb: 255, 255, 255;
  --grid-glow: 0;
  --rim-glow-rgb: 0, 0, 0;
  --rim-glow: 0.30; /* shared intensity: border wash + door wash */
  /* Falloff layers from curve editor (distance px + gain 0..1) */
  --rim-d0: 30.34; --rim-a0: 0.458;
  --rim-d1: 35.33; --rim-a1: 0.885;
  --rim-d2: 41.66; --rim-a2: 0.885;
  --rim-d3: 61.15; --rim-a3: 0.698;
  --grid-d0: 0.50; --grid-a0: 1.000;
  --grid-d1: 1.44; --grid-a1: 0.990;
  --grid-d2: 3.41; --grid-a2: 0.990;
  --grid-d3: 5.36; --grid-a3: 0.958;
  --piece-d0: 1.65; --piece-a0: 0.760;
  --piece-d1: 3.86; --piece-a1: 0.844;
  --piece-d2: 7.95; --piece-a2: 0.333;
  --piece-d3: 14.65; --piece-a3: 0.094;
  /* Slate frame rim */
  --frame: #273444;
  --frame-edge: #1a2430;
  --text: #e8eaf0;
  --text-dim: #8a90a0;
  --accent: #3e8ef7;
  /* Board geometry in px — JS overrides --cell; keep seam/cell out of rem scale */
  --cell: 32px;
  --stage-margin: 50rem;
  --seam: 2px;
  /*
   * Frame sits outside the cells with the same gap pieces use between each
   * other (each side insets --seam, so gap = 2×seam). Centerline is
   * seam + half stroke past the board edge → no overhang onto pieces.
   */
  --frame-stroke: 0.18;
  --frame-thick: calc(var(--cell) * var(--frame-stroke));
  --frame-outset: calc(var(--seam) + var(--frame-thick) / 2);
  --door-scale: 1.2;
  --door-thick: calc(var(--frame-thick) * var(--door-scale));
  /* Outer face of a door centered on the rim centerline */
  --door-outer: calc(var(--frame-outset) + var(--door-thick) / 2);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

body {
  display: flex;
  flex-direction: column;
}

html.is-splash .game-app { display: none !important; }
html.is-playing .splash { display: none !important; }
html.is-playing .game-app { display: flex; }

/* ---------- Splash ---------- */

.splash {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(8rem, env(safe-area-inset-top)) 16rem max(10rem, env(safe-area-inset-bottom));
  font-family: "Outfit", "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(ellipse 90% 55% at 50% 18%, rgba(247, 107, 21, 0.16), transparent 58%),
    radial-gradient(ellipse 70% 45% at 18% 72%, rgba(62, 142, 247, 0.12), transparent 55%),
    radial-gradient(ellipse 60% 40% at 88% 78%, rgba(229, 72, 77, 0.1), transparent 50%),
    linear-gradient(180deg, #10131a 0%, #0b0d12 55%, #090b10 100%);
  overflow: hidden;
}

.splash-stage {
  width: min(100%, 400rem);
  height: 100%;
  max-height: 720rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(6rem, 1.4vh, 14rem);
  text-align: center;
}

.splash-brand {
  margin: 0;
  width: min(72%, 280rem);
  flex: 0 0 auto;
  line-height: 0;
  animation: splash-rise 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.splash-logo {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 6rem 20rem rgba(0, 0, 0, 0.45));
  /* Drop baked black plate from the transparent export */
  mix-blend-mode: lighten;
}

.splash-hero {
  width: min(78%, 280rem);
  flex: 1 1 auto;
  min-height: 0;
  max-height: min(34vh, 260rem);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: splash-rise 0.8s cubic-bezier(0.22, 1, 0.36, 1) 0.08s both;
}

.splash-board {
  display: block;
  width: 100%;
  height: auto;
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 12rem 24rem rgba(0, 0, 0, 0.55));
  mix-blend-mode: lighten;
  animation: splash-float 5.5s ease-in-out 0.9s infinite;
}

.splash-cta {
  width: min(82%, 300rem);
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8rem;
  animation: splash-rise 0.75s cubic-bezier(0.22, 1, 0.36, 1) 0.16s both;
}

.splash-play {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  width: 100%;
  line-height: 0;
  cursor: pointer;
  border-radius: 999rem;
  transition: transform 0.14s ease, filter 0.14s ease;
  filter: drop-shadow(0 8rem 18rem rgba(247, 107, 21, 0.35));
}
.splash-play:hover {
  transform: translateY(-2rem) scale(1.02);
  filter: drop-shadow(0 12rem 24rem rgba(247, 107, 21, 0.48));
}
.splash-play:active { transform: translateY(1rem) scale(0.985); }
.splash-play:focus-visible {
  outline: 2rem solid rgba(247, 107, 21, 0.85);
  outline-offset: 4rem;
}

.splash-play-art {
  display: block;
  width: 100%;
  height: auto;
  /* Drop baked black plate from the art */
  mix-blend-mode: lighten;
  pointer-events: none;
  user-select: none;
}

/* Levels + TEN Second Games — Play shape, dark nav coloring */
.splash-secondary {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 46rem;
  padding: 12rem 18rem;
  margin: 0;
  border: 0;
  border-radius: 999rem;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02)),
    #1a1f2a;
  box-shadow:
    inset 0 1rem 0 rgba(255, 255, 255, 0.08),
    inset 0 -2rem 4rem rgba(0, 0, 0, 0.35),
    0 6rem 14rem rgba(0, 0, 0, 0.35);
  color: rgba(232, 234, 240, 0.88);
  font-family: inherit;
  font-size: 13rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.12s ease;
}
.splash-secondary:hover {
  color: #fff;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.04)),
    #222836;
}
.splash-secondary:active { transform: scale(0.985); }
.splash-secondary:focus-visible {
  outline: 2rem solid rgba(62, 142, 247, 0.7);
  outline-offset: 3rem;
}

.splash-tagline {
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10rem;
  width: min(82%, 300rem);
  flex: 0 0 auto;
  font-size: 10rem;
  font-weight: 700;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: rgba(232, 234, 240, 0.5);
  animation: splash-rise 0.75s cubic-bezier(0.22, 1, 0.36, 1) 0.24s both;
}
.splash-tagline::before,
.splash-tagline::after {
  content: "";
  flex: 1;
  height: 1rem;
  background: linear-gradient(90deg, transparent, rgba(232, 234, 240, 0.22), transparent);
}
.splash-tagline span { white-space: nowrap; }

@keyframes splash-rise {
  from {
    opacity: 0;
    transform: translateY(10rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes splash-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4rem); }
}

@media (max-height: 640px) {
  .splash-stage { gap: 4rem; }
  .splash-brand { width: min(58%, 220rem); }
  .splash-hero { max-height: min(28vh, 180rem); }
  .splash-cta { width: min(70%, 240rem); gap: 6rem; }
  .splash-secondary { min-height: 40rem; padding: 10rem 16rem; font-size: 12rem; }
}

.game-app {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* ---------- HUD ---------- */

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10rem 16rem;
  background: var(--panel);
  box-shadow: 0 2rem 8rem rgba(0, 0, 0, 0.35);
  z-index: 5;
  flex-shrink: 0;
}

.hud-left, .hud-right {
  display: flex;
  align-items: center;
  gap: 8rem;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6rem;
  min-width: 0;
  height: 36rem;
  padding: 0 12rem 0 10rem;
  font-size: 14rem;
  font-weight: 600;
}
.back-chevron {
  font-size: 16rem;
  line-height: 1;
  transform: translateY(-1rem);
}
.back-label {
  letter-spacing: 0.04em;
}

.level-box {
  display: flex;
  align-items: center;
  gap: 8rem;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 8rem;
  padding: 4rem 12rem;
}

.level-label {
  font-size: 11rem;
  letter-spacing: 1.5rem;
  color: var(--text-dim);
}

.level-value {
  font-size: 20rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  min-width: 1.4em;
  text-align: center;
}

.btn {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: var(--text);
  font-size: 18rem;
  border-radius: 8rem;
  min-width: 36rem;
  height: 36rem;
  cursor: pointer;
  transition: background 0.15s;
}
.btn:hover { background: rgba(255, 255, 255, 0.16); }
.btn-wide { padding: 0 16rem; font-size: 14rem; font-weight: 600; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #5ba0f9; }

.stat {
  font-size: 13rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.best-stat #bestTime {
  color: var(--text);
  font-weight: 600;
}

.btn-icon {
  font-size: 20rem;
  line-height: 1;
  padding: 0 2rem;
}

.btn-depot {
  min-width: 0;
  height: auto;
  padding: 6rem 10rem;
  font-size: 11rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-decoration: none;
  color: var(--text-dim);
  white-space: nowrap;
}
.btn-depot:hover { color: var(--text); }

@media (max-width: 420px) {
  .back-label { display: none; }
  .back-btn { padding: 0 10rem; }
  .hud { padding: 10rem 10rem; gap: 6rem; }
  .hud-left, .hud-right { gap: 6rem; }
}

/* ---------- Settings PIN pad ---------- */

.pin-screen {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16rem;
  background: rgba(8, 10, 14, 0.88);
}
.pin-screen.hidden { display: none; }

.pin-panel {
  width: min(280rem, calc(100vw - 32rem));
  padding: 16rem;
  background: var(--panel);
  border: 1rem solid rgba(255, 255, 255, 0.12);
  border-radius: 10rem;
  box-shadow: 0 10rem 28rem rgba(0, 0, 0, 0.55);
}

.pin-panel h2 {
  margin: 0 0 10rem;
  text-align: center;
  font-size: 14rem;
  letter-spacing: 0.2em;
  color: var(--text);
}

.pin-display {
  font: bold 22rem monospace;
  letter-spacing: 0.35em;
  text-align: center;
  color: var(--text);
  margin: 8rem 0 14rem;
  padding: 10rem 8rem;
  background: rgba(0, 0, 0, 0.35);
  border: 1rem solid rgba(255, 255, 255, 0.12);
  border-radius: 6rem;
}

.pin-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6rem;
  margin-bottom: 10rem;
}

.pin-grid button {
  font-size: 16rem;
  font-weight: 700;
  padding: 12rem 0;
  cursor: pointer;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: 8rem;
}
.pin-grid button:hover { background: rgba(255, 255, 255, 0.16); }

.pin-msg {
  min-height: 14rem;
  margin: 0 0 8rem;
  font-size: 11rem;
  letter-spacing: 0.08em;
  text-align: center;
  color: #f87171;
}

/* ---------- Draggable look panel ---------- */

.settings-panel {
  position: fixed;
  top: 56rem;
  right: 12rem;
  z-index: 20;
  width: 256rem;
  background: var(--panel);
  border: 1rem solid rgba(255, 255, 255, 0.12);
  border-radius: 10rem;
  box-shadow: 0 10rem 28rem rgba(0, 0, 0, 0.55);
  color: var(--text);
  overflow: hidden;
}
.settings-panel.hidden { display: none; }

.settings-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8rem;
  padding: 6rem 8rem 6rem 10rem;
  background: rgba(255, 255, 255, 0.06);
  cursor: grab;
  touch-action: none;
}
.settings-titlebar:active { cursor: grabbing; }
.settings-title {
  font-size: 11rem;
  font-weight: 700;
  letter-spacing: 1rem;
  text-transform: uppercase;
  color: var(--text-dim);
}
.settings-title-actions {
  display: flex;
  align-items: center;
  gap: 4rem;
}
.settings-tool {
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-dim);
  font-size: 10rem;
  font-weight: 600;
  padding: 3rem 8rem;
  border-radius: 5rem;
  cursor: pointer;
}
.settings-tool:hover { background: rgba(255, 255, 255, 0.14); color: var(--text); }
.settings-close {
  width: 22rem;
  height: 22rem;
  border: none;
  border-radius: 6rem;
  background: transparent;
  color: var(--text);
  font-size: 16rem;
  line-height: 1;
  cursor: pointer;
}
.settings-close:hover { background: rgba(255, 255, 255, 0.12); }
.btn-curve {
  flex: 0 0 22rem;
  width: 22rem;
  height: 22rem;
  border: none;
  border-radius: 5rem;
  background: rgba(255, 255, 255, 0.08);
  color: #8eb8f0;
  font-size: 13rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.btn-curve:hover,
.btn-curve.active {
  background: rgba(62, 142, 247, 0.28);
  color: #fff;
}

.settings-body {
  display: flex;
  flex-direction: column;
  gap: 5rem;
  padding: 8rem 10rem 10rem;
}
.set-row {
  display: flex;
  align-items: center;
  gap: 6rem;
  min-height: 24rem;
  cursor: pointer;
}
.set-row > span:first-child {
  flex: 0 0 58rem;
  font-size: 10rem;
  letter-spacing: 0.4rem;
  color: var(--text-dim);
  text-transform: uppercase;
  white-space: nowrap;
}
.set-row input[type="color"] {
  flex: 0 0 24rem;
  width: 24rem;
  height: 20rem;
  padding: 0;
  border: 1rem solid rgba(255, 255, 255, 0.2);
  border-radius: 4rem;
  background: transparent;
  cursor: pointer;
}
.set-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 1rem; }
.set-row input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 2rem;
}
.set-row input[type="range"] {
  flex: 1 1 auto;
  min-width: 0;
  accent-color: #c8d0dc;
  cursor: pointer;
}
.set-row input[type="checkbox"] {
  flex: 0 0 auto;
  width: 16rem;
  height: 16rem;
  accent-color: #3e8ef7;
  cursor: pointer;
}
.set-row em {
  flex: 0 0 2.8em;
  font-style: normal;
  font-size: 10rem;
  color: var(--text-dim);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.set-row-tight { margin-top: 2rem; padding: 0 2rem; }
.set-row-tight em { flex-basis: 2.8em; }

/* Floating falloff curve popup (shared by rim / grid / piece) */
.falloff-popup {
  position: fixed;
  top: 120rem;
  right: 280rem;
  z-index: 30;
  width: 260rem;
  padding: 0 10rem 10rem;
  background: var(--panel);
  border: 1rem solid rgba(255, 255, 255, 0.14);
  border-radius: 10rem;
  box-shadow: 0 12rem 32rem rgba(0, 0, 0, 0.55);
}
.falloff-popup.hidden { display: none; }
.falloff-popup-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8rem;
  margin: 0 -10rem 6rem;
  padding: 6rem 8rem 6rem 10rem;
  background: rgba(255, 255, 255, 0.06);
  cursor: grab;
  touch-action: none;
  border-radius: 10rem 10rem 0 0;
}
.falloff-popup-bar:active { cursor: grabbing; }
.falloff-popup-bar > span {
  font-size: 11rem;
  font-weight: 700;
  letter-spacing: 0.6rem;
  text-transform: uppercase;
  color: var(--text-dim);
}
#falloffCurve {
  display: block;
  width: 100%;
  height: 120rem;
  border-radius: 6rem;
  background: #12151a;
  border: 1rem solid rgba(255, 255, 255, 0.1);
  cursor: crosshair;
  touch-action: none;
}
.set-curve-axis {
  display: flex;
  justify-content: space-between;
  margin: 2rem 0 4rem;
  font-size: 9rem;
  color: var(--text-dim);
  opacity: 0.85;
}

/* ---------- Stage / board ---------- */

#stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.stage-timer-wrap {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4rem 12rem 0;
}

.level-timer {
  font-family: "Outfit", "Segoe UI", system-ui, sans-serif;
  font-size: clamp(36rem, 11vw, 56rem);
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1;
  color: #7ec8ff;
  text-shadow:
    0 0 18rem rgba(126, 200, 255, 0.45),
    0 2rem 10rem rgba(0, 0, 0, 0.45);
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.stage-board {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  /* Fixed screen margin — door overhang is reserved in fitBoard, not here */
  padding: var(--stage-margin, 30rem);
}

#boardWrap { position: relative; }

/* Tron de-rez particles — sits above pieces, ignores hits */
.derez-canvas {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 6;
  pointer-events: none;
}

#board {
  position: relative;
  /* width/height set per level from game.js (= bbox); voids are transparent */
  box-sizing: content-box;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  overflow: visible;
}

/* Playable floor — single baked canvas (see drawFloorLayer in game.js) */
.floor-canvas {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 0;
  pointer-events: none;
}

/* Legacy play-cell styles kept unused; floor is canvas-backed now */
.play-cell {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  background: rgba(var(--floor-rgb), var(--floor-alpha));
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.play-cell::after {
  content: none;
}

/* SVG stroke outside the cells — seam gap matches unconnected piece padding */
.board-frame {
  position: absolute;
  z-index: 4;
  pointer-events: none;
  overflow: visible;
}
/* Indirect light wash — layer distances/gains from Rim falloff curve */
.board-frame .frame-shade {
  fill: none;
  stroke: rgb(var(--rim-glow-rgb));
  stroke-width: calc(0.15 + var(--rim-glow) * var(--rim-a0) * 0.4);
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: calc(0.15 + var(--rim-glow) * var(--rim-a0) * 0.7);
}
.board-frame .frame-path {
  fill: none;
  stroke: var(--frame);
  stroke-width: var(--frame-stroke);
  stroke-linecap: round;
  stroke-linejoin: round;
  filter:
    drop-shadow(0 0 calc(var(--rim-glow) * var(--rim-d0) * 1rem) rgba(var(--rim-glow-rgb), calc(var(--rim-glow) * var(--rim-a0))))
    drop-shadow(0 0 calc(var(--rim-glow) * var(--rim-d1) * 1rem) rgba(var(--rim-glow-rgb), calc(var(--rim-glow) * var(--rim-a1))))
    drop-shadow(0 0 calc(var(--rim-glow) * var(--rim-d2) * 1rem) rgba(var(--rim-glow-rgb), calc(var(--rim-glow) * var(--rim-a2))))
    drop-shadow(0 0 calc(var(--rim-glow) * var(--rim-d3) * 1rem) rgba(var(--rim-glow-rgb), calc(var(--rim-glow) * var(--rim-a3))));
}

/* Sealed gate wall — opens when its unlock section is cleared */
.gate-cell {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  z-index: 1;
  pointer-events: none;
  background: var(--frame);
  border-radius: 4rem;
  box-shadow:
    inset 0 1rem 0 rgba(255, 255, 255, 0.45),
    inset 0 -2rem 3rem rgba(0, 0, 0, 0.18),
    inset 0 0 0 1rem var(--frame-edge),
    0 1rem 3rem rgba(0, 0, 0, 0.35);
  transition: opacity 0.28s ease, transform 0.28s ease;
}
.gate-cell .gate-stripe {
  position: absolute;
  inset: 18%;
  border-radius: 3rem;
  background: repeating-linear-gradient(
    -45deg,
    rgba(60, 50, 40, 0.22) 0 3rem,
    transparent 3rem 7rem
  );
}
.gate-cell.gate-open {
  opacity: 0;
  transform: scale(0.85);
}

/* Static interior pillars — muted glass blockers */
.pillar {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  z-index: 1;
  pointer-events: none;
  --block-color: #6b7280;
  --block-rgb: 107, 114, 128;
}
.pillar-surface {
  position: absolute;
  inset: var(--seam);
  border-radius: calc(var(--cell) * var(--piece-radius));
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.12), transparent 45%),
    rgba(107, 114, 128, 0.45);
  box-shadow:
    inset 0 0 0 1.5rem rgba(180, 190, 205, 0.35),
    inset 0 0 10rem rgba(107, 114, 128, 0.25),
    0 0 8rem rgba(107, 114, 128, 0.2);
  backdrop-filter: blur(1rem);
}

/* ---------- Doors (1.2× rim, centered on border) ---------- */

.door {
  --door-color: #fff;
  --door-wash-inset:
    inset 0 1rem 0 rgba(255, 255, 255, 0.35),
    inset 0 -2rem 3rem rgba(0, 0, 0, 0.28);
  position: absolute;
  border-radius: 3rem;
  /* Solid plate only — no outer color bloom / rim wash */
  box-shadow: var(--door-wash-inset);
  z-index: 6;
  pointer-events: none;
}
.door::after {
  content: "";
  position: absolute;
  inset: 2rem;
  border-radius: 2rem;
  background: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.22) 0 4rem,
    transparent 4rem 8rem
  );
}
.door.tone-light {
  --door-wash-inset:
    inset 0 1rem 0 rgba(255, 255, 255, 0.65),
    inset 0 -2rem 3rem rgba(0, 0, 0, 0.18),
    inset 0 0 0 1rem rgba(0, 0, 0, 0.12);
}
.door.tone-dark {
  --door-wash-inset:
    inset 0 1rem 0 rgba(255, 255, 255, 0.22),
    inset 0 -2rem 3rem rgba(0, 0, 0, 0.55);
}
/* Outward chevron */
.door .chevron {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  transform: translate(-50%, -50%);
  z-index: 1;
  border-style: solid;
  border-color: transparent;
  filter: drop-shadow(0 1rem 1rem rgba(0, 0, 0, 0.35));
}
.door.side-0 .chevron { /* up */
  border-width: 0 5rem 7rem 5rem;
  border-bottom-color: rgba(255, 255, 255, 0.92);
}
.door.side-1 .chevron { /* right */
  border-width: 5rem 0 5rem 7rem;
  border-left-color: rgba(255, 255, 255, 0.92);
}
.door.side-2 .chevron { /* down */
  border-width: 7rem 5rem 0 5rem;
  border-top-color: rgba(255, 255, 255, 0.92);
}
.door.side-3 .chevron { /* left */
  border-width: 5rem 7rem 5rem 0;
  border-right-color: rgba(255, 255, 255, 0.92);
}

/* ---------- Blocks (opaque plastic Lego plates + studs) ---------- */

.block {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  cursor: grab;
  transition: transform 0.09s ease-out;
  filter: drop-shadow(0 2rem 3rem rgba(0, 0, 0, 0.45));
  will-change: transform;
}
.block.dragging {
  cursor: grabbing;
  z-index: 3;
  /* 1:1 finger follow — no laggy transition while dragging */
  transition: none;
  filter: drop-shadow(0 5rem 8rem rgba(0, 0, 0, 0.5));
}
.block.settling {
  transition: transform 0.12s ease-out;
}
.block.exiting {
  transition: none;
  pointer-events: none;
  z-index: 5;
}
.block.exiting .bcell.is-out {
  visibility: hidden;
}
.block.denied { animation: shake 0.22s; }

/* Independent `translate` composes with inline `transform` (grid position). */
@keyframes shake {
  0%, 100% { translate: 0 0; }
  25% { translate: -3rem 0; }
  75% { translate: 3rem 0; }
}

/* One grid cell of a piece — fused neighbors share flush edges → one silhouette */
.bcell {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
}

/* Opaque plate; inset only on silhouette edges so same-piece cells fuse. */
.surface {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0) 45%),
    var(--block-color);
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, 0.28);
}

/* 2×2 studs per grid cell (a 1×1 brick has 4). */
.studs {
  position: absolute;
  inset: 6%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  place-items: center;
  pointer-events: none;
}
.stud {
  width: 78%;
  height: 78%;
  transform: translateY(-6%);
  border-radius: 50%;
  background:
    radial-gradient(circle at 38% 32%,
      rgba(255, 255, 255, 0.35),
      rgba(255, 255, 255, 0.06) 48%,
      rgba(0, 0, 0, 0.18) 100%),
    var(--block-color);
  box-shadow:
    0 2px 2px rgba(0, 0, 0, 0.35),
    inset 0 1px 1px rgba(255, 255, 255, 0.4),
    inset 0 -2px 2px rgba(0, 0, 0, 0.25);
}
.stud::after {
  content: "";
  position: absolute;
  inset: 14%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.07);
}

.tone-light .surface {
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0) 50%),
    var(--block-color);
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, 0.18);
}
.tone-light .stud {
  background:
    radial-gradient(circle at 38% 32%,
      rgba(255, 255, 255, 0.55),
      rgba(255, 255, 255, 0.12) 48%,
      rgba(0, 0, 0, 0.12) 100%),
    var(--block-color);
}

.tone-dark .surface {
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0) 45%),
    var(--block-color);
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, 0.45);
}
.tone-dark .stud {
  background:
    radial-gradient(circle at 38% 32%,
      rgba(255, 255, 255, 0.22),
      rgba(255, 255, 255, 0.04) 48%,
      rgba(0, 0, 0, 0.35) 100%),
    var(--block-color);
}

/* One-way arrows baked into each tile cell (sit on the stud) */
.axis-arrow {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
  pointer-events: none;
  filter: drop-shadow(0 1rem 1rem rgba(0, 0, 0, 0.45));
  opacity: 0.9;
}
.axis-arrow.axis-h {
  width: 58%;
  height: 22%;
  min-width: 14rem;
  min-height: 7rem;
  background: rgba(255, 255, 255, 0.92);
  clip-path: polygon(
    0% 50%, 20% 0%, 20% 32%, 80% 32%, 80% 0%,
    100% 50%, 80% 100%, 80% 68%, 20% 68%, 20% 100%
  );
}
.axis-arrow.axis-v {
  width: 22%;
  height: 58%;
  min-width: 7rem;
  min-height: 14rem;
  background: rgba(255, 255, 255, 0.92);
  clip-path: polygon(
    50% 0%, 100% 20%, 68% 20%, 68% 80%, 100% 80%,
    50% 100%, 0% 80%, 32% 80%, 32% 20%, 0% 20%
  );
}
.tone-light .axis-arrow.axis-h,
.tone-light .axis-arrow.axis-v {
  background: rgba(30, 36, 48, 0.72);
  filter: drop-shadow(0 1rem 1rem rgba(0, 0, 0, 0.25));
}

/* Glued dual-color pair — same plastic shadow as a normal piece */
.block.joined {
  filter: drop-shadow(0 2rem 3rem rgba(0, 0, 0, 0.5));
}
.block.joined.dragging {
  filter: drop-shadow(0 5rem 8rem rgba(0, 0, 0, 0.55));
}
.join-badge {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 5;
  width: 18rem;
  height: 18rem;
  margin-top: -1rem;
  border-radius: 50%;
  background: rgba(12, 14, 18, 0.55);
  color: #fff;
  font-size: 11rem;
  line-height: 18rem;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.45);
}

/* ---------- Win / levels overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  backdrop-filter: blur(3rem);
  padding: 20rem;
}
.overlay.hidden { display: none; }

.overlay-card {
  background: var(--panel);
  border-radius: 16rem;
  padding: 32rem 40rem;
  text-align: center;
  box-shadow: 0 16rem 60rem rgba(0, 0, 0, 0.6);
  width: min(100%, 360rem);
}

.win-card { padding: 28rem 32rem 26rem; }
.win-kicker {
  margin: 0 0 6rem;
  font-size: 12rem;
  font-weight: 700;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.win-level-headline {
  margin: 0 0 14rem;
  font-size: clamp(34rem, 9vw, 44rem);
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1;
  color: var(--text);
  text-shadow: 0 0 28rem rgba(62, 142, 247, 0.35);
}

.star-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8rem;
  margin: 0 0 22rem;
}
.star {
  font-size: 28rem;
  line-height: 1;
  color: rgba(232, 234, 240, 0.18);
  text-shadow: none;
  transition: color 0.15s ease, transform 0.15s ease, text-shadow 0.15s ease;
}
.star.on {
  color: #f0b400;
  text-shadow: 0 0 14rem rgba(240, 180, 0, 0.55);
}
.win-stars .star { font-size: 34rem; }
.win-stars .star.on {
  animation: star-pop 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.win-stars .star.on:nth-child(2) { animation-delay: 0.08s; }
.win-stars .star.on:nth-child(3) { animation-delay: 0.16s; }

@keyframes star-pop {
  from { opacity: 0; transform: scale(0.55) translateY(6rem); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.win-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12rem 18rem;
  margin: 0 0 22rem;
  text-align: center;
}
.win-stat { min-width: 0; }
.win-moves-label {
  margin: 0 0 6rem;
  font-size: 11rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.win-moves {
  margin: 0;
  font-size: 32rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
#winTime {
  color: #7ec8ff;
  text-shadow: 0 0 22rem rgba(126, 200, 255, 0.35);
}
.win-par {
  margin: 6rem 0 0;
  font-size: 12rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.overlay-actions {
  display: flex;
  gap: 12rem;
  justify-content: center;
  flex-wrap: wrap;
}
.overlay-actions-col {
  flex-direction: column;
  align-items: stretch;
}
.overlay-actions-col .btn {
  width: 100%;
  height: 42rem;
}

.levels-card {
  padding: 24rem 22rem 22rem;
  max-height: min(100%, 560rem);
  display: flex;
  flex-direction: column;
  gap: 12rem;
}
.levels-title {
  margin: 0;
  font-size: 22rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.levels-sub {
  margin: 0;
  font-size: 13rem;
  color: var(--text-dim);
}
.level-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8rem;
  width: 100%;
  max-height: 320rem;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 10rem;
  -webkit-overflow-scrolling: touch;
  border: 1rem solid rgba(255, 255, 255, 0.1);
  border-radius: 12rem;
  background: rgba(0, 0, 0, 0.28);
  scrollbar-width: thin;
}
.level-btn {
  font: inherit;
  font-size: 15rem;
  font-weight: 700;
  cursor: pointer;
  padding: 10rem 0 8rem;
  color: var(--text);
  background: rgba(62, 142, 247, 0.28);
  border: 1rem solid rgba(62, 142, 247, 0.55);
  border-radius: 8rem;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4rem;
}
.level-btn-num { line-height: 1.1; }
.level-btn .star-row {
  margin: 0;
  gap: 2rem;
}
.level-btn .star {
  font-size: 10rem;
  color: rgba(232, 234, 240, 0.2);
}
.level-btn .star.on {
  color: #f0b400;
  text-shadow: none;
}
.level-btn:hover:not(:disabled) {
  background: rgba(62, 142, 247, 0.45);
}
.level-btn:disabled {
  cursor: default;
  color: rgba(232, 234, 240, 0.28);
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
}
.level-btn:disabled .star { color: rgba(232, 234, 240, 0.1); }
.levels-card > .btn {
  width: 100%;
  height: 42rem;
  margin-top: 4rem;
}

/* ---------- Footer ---------- */

.foot {
  text-align: center;
  padding: 6rem;
  font-size: 11rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
