/* Rush Hour — four worlds around one 6×6 board. Colours, fonts and shadows
   arrive as custom properties from themes.js; the board and vehicles are
   SVG from art.js. */

:root {
  --bg-a: #eef1f0;
  --bg-b: #c8d3d6;
  --blob-1: rgba(255, 255, 255, 0.85);
  --blob-2: rgba(247, 200, 115, 0.45);
  --blob-3: rgba(140, 186, 214, 0.45);
  --ink: #1e252c;
  --ink-soft: #5d6a74;
  --paper: #fbfaf8;
  --paper-2: #eeedea;
  --line: rgba(30, 37, 44, 0.12);
  --accent: #d7263d;
  --accent-2: #a81c2e;
  --accent-ink: #fff;
  --glow: #ffcf4a;
  --star: #f2b134;
  --btn-bg: rgba(255, 255, 255, 0.62);
  --btn-hover: rgba(255, 255, 255, 0.92);
  --btn-border: rgba(30, 37, 44, 0.13);
  --stat-bg: rgba(255, 255, 255, 0.45);
  --stat-border: rgba(255, 255, 255, 0.65);
  --hover: rgba(30, 37, 44, 0.07);
  --backdrop: rgba(24, 30, 36, 0.42);
  --toast-bg: rgba(30, 37, 44, 0.92);
  --toast-ink: #fff;
  --track-off: #c9cfd2;
  --v-shadow: rgba(8, 10, 14, 0.55);
  --v-sx: 0.02;
  --v-sy: 0.07;
  --v-blur: 0.05;
  --cell: 50px;
  --ease: cubic-bezier(0.4, 0.1, 0.2, 1);
  --spring: cubic-bezier(0.3, 1.4, 0.5, 1);
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --display: "Avenir Next", Avenir, "Segoe UI", var(--sans);
  --display-weight: 700;
  --inset: 6.3953%; /* 44 / 688: the frame around the grid */
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  font-family: var(--sans);
  color: var(--ink);
  background: linear-gradient(165deg, var(--bg-a), var(--bg-b));
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
  transition: background 0.6s;
}

button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--glow); outline-offset: 2px; }

/* ---------------------------------------------------------- background */
.bg { position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none; }
.bg .blob { position: absolute; border-radius: 50%; filter: blur(60px); opacity: 0.6; will-change: transform; }
.bg .b1 { width: 60vmax; height: 60vmax; left: -20vmax; top: -25vmax; background: var(--blob-1); animation: drift 48s ease-in-out infinite alternate; }
.bg .b2 { width: 50vmax; height: 50vmax; right: -20vmax; bottom: -20vmax; background: var(--blob-2); animation: drift 60s ease-in-out infinite alternate-reverse; }
.bg .b3 { width: 40vmax; height: 40vmax; left: 30vw; bottom: -25vmax; background: var(--blob-3); animation: drift 72s ease-in-out infinite alternate; }
@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(8vmax, 6vmax) scale(1.12); }
}

/* -------------------------------------------------------------- layout */
.app {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.top { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px 4px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: 40px; height: 40px; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.25)); flex: 0 0 auto; }
.brand span { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand b { font-family: var(--display); font-weight: var(--display-weight); font-size: 22px; letter-spacing: 0.01em; white-space: nowrap; }
.brand small { font-size: 11.5px; color: var(--ink-soft); letter-spacing: 0.08em; text-transform: uppercase; margin-top: 2px; white-space: nowrap; }
.menu { display: flex; gap: 2px; flex: 0 0 auto; }

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg, .btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.stats { display: grid; grid-template-columns: 1.55fr 1fr 1fr 1fr; gap: 8px; padding: 4px 16px 6px; }
.stat {
  background: var(--stat-bg);
  border: 1px solid var(--stat-border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  border-radius: 12px;
  padding: 6px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
  min-width: 0;
}
.stat span { font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); white-space: nowrap; }
.stat b { font-family: var(--display); font-size: 20px; font-weight: var(--display-weight); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.stat b.long { font-size: 15px; line-height: 23px; }
.stat.stars b { display: flex; gap: 1px; align-items: center; height: 23px; }
.stat.stars svg { width: 17px; height: 17px; fill: var(--line); stroke: none; transition: fill 0.35s, transform 0.35s var(--spring); }
.stat.stars svg.lit { fill: var(--star); }

.stage {
  flex: 1;
  min-height: 0;
  container-type: size;
  display: grid;
  place-items: center;
  padding: 8px 16px;
}

.actions { display: flex; gap: 10px; padding: 6px 16px 14px; }
.btn {
  appearance: none;
  flex: 1;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--ink);
  font: 500 15px var(--sans);
  padding: 11px 12px;
  min-height: 46px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  transition: transform 0.15s, background 0.2s, opacity 0.2s, box-shadow 0.2s;
}
.btn svg { width: 19px; height: 19px; }
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn.primary {
  background: linear-gradient(180deg, color-mix(in oklab, var(--accent) 82%, white), var(--accent) 55%, var(--accent-2));
  color: var(--accent-ink);
  border-color: var(--accent-2);
  box-shadow: 0 4px 12px -4px color-mix(in oklab, var(--accent-2) 70%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.28);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}
.btn.primary:hover { filter: brightness(1.06); background: linear-gradient(180deg, color-mix(in oklab, var(--accent) 82%, white), var(--accent) 55%, var(--accent-2)); }
.btn.primary.thinking { animation: breathe 0.8s ease-in-out infinite; }
.btn.subtle { flex: 0 0 auto; background: transparent; box-shadow: none; border-color: transparent; color: var(--ink-soft); font-size: 13.5px; margin: 18px auto 0; display: flex; min-height: 40px; }
@keyframes breathe { 50% { opacity: 0.6; } }

/* --------------------------------------------------------------- board */
.board {
  width: min(100cqw, 100cqh, 640px);
  aspect-ratio: 1;
  position: relative;
  touch-action: none;
  outline: none;
  border-radius: 5%;
}
.board:focus-visible::before { content: ""; position: absolute; inset: -5px; border-radius: 6%; border: 2px solid color-mix(in oklab, var(--glow) 70%, transparent); pointer-events: none; }
.board-art {
  position: absolute;
  inset: 0;
  border-radius: 5%;
  box-shadow: 0 26px 48px -18px rgba(20, 25, 30, 0.55), 0 6px 14px -4px rgba(20, 25, 30, 0.3);
  pointer-events: none;
}
.board-art .board-svg { display: block; width: 100%; height: 100%; }
.grid {
  position: absolute;
  inset: var(--inset);
  touch-action: none;
}
.marks { position: absolute; inset: 0; pointer-events: none; }
.mark {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(100% / 6);
  height: calc(100% / 6);
  animation: fade 0.2s;
}
.mark::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18%;
  height: 18%;
  margin: -9% 0 0 -9%;
  border-radius: 50%;
  background: var(--glow);
  opacity: 0.75;
  box-shadow: 0 0 0.6em color-mix(in oklab, var(--glow) 80%, transparent);
  font-size: var(--cell);
}
.ghost {
  position: absolute;
  left: 0;
  top: 0;
  animation: ghost 1.4s ease-in-out infinite;
}
.ghost::before {
  content: "";
  position: absolute;
  inset: 5%;
  border-radius: calc(var(--cell) * 0.2);
  border: 2.5px dashed var(--glow);
  background: color-mix(in oklab, var(--glow) 22%, transparent);
  box-shadow: 0 0 calc(var(--cell) * 0.3) color-mix(in oklab, var(--glow) 55%, transparent);
}
@keyframes ghost { 50% { opacity: 0.55; } }

.veh {
  position: absolute;
  left: 0;
  top: 0;
  will-change: transform;
  cursor: grab;
  touch-action: none;
  z-index: 2;
}
.veh.lifted { cursor: grabbing; z-index: 4; }
.veh.selected { z-index: 3; }
.veh.exiting { z-index: 6; pointer-events: none; }
.veh.gone { visibility: hidden; pointer-events: none; }
.veh .art {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(calc(var(--cell) * var(--v-sx)) calc(var(--cell) * var(--v-sy)) calc(var(--cell) * var(--v-blur)) var(--v-shadow));
  transition: transform 0.18s var(--ease);
  transform-origin: 50% 50%;
}
.veh.lifted .art { transform: scale(1.045); }
.veh.selected::before {
  content: "";
  position: absolute;
  inset: 2%;
  border-radius: calc(var(--cell) * 0.24);
  box-shadow: 0 0 0 2.5px var(--glow), 0 0 calc(var(--cell) * 0.32) color-mix(in oklab, var(--glow) 70%, transparent);
  pointer-events: none;
  animation: fade 0.18s;
}
.veh.hinted .art { animation: nudge 1.1s ease-in-out infinite; }
.veh.h.hinted .art { --nx: 3%; --ny: 0; }
.veh.v.hinted .art { --nx: 0; --ny: 3%; }
@keyframes nudge { 50% { transform: translate(var(--nx), var(--ny)) scale(1.03); } }
.veh.bump .art { animation: bump 0.24s var(--ease); }
@keyframes bump { 40% { transform: translate(var(--bx), var(--by)); } }

.trail {
  position: absolute;
  right: 72%;
  top: 22%;
  height: 56%;
  width: 180%;
  opacity: 0;
  pointer-events: none;
  transform-origin: 100% 50%;
  border-radius: 999px;
}
.veh.exiting .trail { animation: trail 0.76s ease-in forwards; }
@keyframes trail {
  0% { opacity: 0; transform: scaleX(0.2); }
  35% { opacity: 1; }
  100% { opacity: 0.85; transform: scaleX(1); }
}
.veh.exiting .art { animation: leave 0.76s ease-in forwards; }
@keyframes leave { 0%, 55% { opacity: 1; } 100% { opacity: 0; } }

.board.freed::after {
  content: "";
  position: absolute;
  right: -8%;
  top: 30%;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in oklab, var(--burst, var(--glow)) 80%, transparent), transparent);
  pointer-events: none;
  animation: burst 1.3s ease-out forwards;
  z-index: 7;
}
@keyframes burst {
  0% { opacity: 0; transform: scale(0.4); }
  30% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.6); }
}

.board.enter .veh .art { animation: arrive 0.42s var(--ease) backwards; animation-delay: calc(var(--i) * 22ms); }
@keyframes arrive { from { opacity: 0; transform: scale(0.86); } }

/* World touches: trails and glows */
[data-world="city"] .trail { background: repeating-linear-gradient(180deg, transparent 0 18%, rgba(255, 255, 255, 0.55) 18% 24%, transparent 24% 38%); -webkit-mask: linear-gradient(90deg, transparent, #000 85%); mask: linear-gradient(90deg, transparent, #000 85%); }
[data-world="harbour"] .trail { top: 6%; height: 88%; background: radial-gradient(ellipse 100% 60% at 100% 50%, rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0.25) 45%, transparent 70%); }
[data-world="woodshop"] .trail { background: linear-gradient(90deg, transparent, rgba(255, 236, 200, 0.4)); }
[data-world="neon"] .trail { top: 30%; height: 40%; background: linear-gradient(90deg, transparent, color-mix(in oklab, var(--vc) 75%, transparent)); filter: blur(2px); }
[data-world="neon"] .board-art { box-shadow: 0 0 0 1px rgba(41, 225, 255, 0.15), 0 26px 60px -18px rgba(0, 0, 0, 0.8), 0 0 80px -20px rgba(41, 225, 255, 0.35); }
[data-world="neon"] .board { --burst: #ff3d7f; }
[data-world="neon"] .brand img { filter: drop-shadow(0 0 6px rgba(255, 61, 127, 0.55)); }
[data-world="woodshop"] .board-art { box-shadow: 0 22px 40px -16px rgba(50, 26, 8, 0.6), 0 5px 12px -3px rgba(50, 26, 8, 0.35); }
[data-world="harbour"] .board-art { box-shadow: 0 24px 46px -18px rgba(10, 50, 62, 0.5), 0 6px 14px -4px rgba(10, 50, 62, 0.28); }

/* -------------------------------------------------------- sheets, dialogs */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--backdrop);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade 0.25s;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto;
  z-index: 21;
  max-width: 560px;
  max-height: 86dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.25);
  padding-bottom: env(safe-area-inset-bottom);
  animation: rise 0.32s var(--ease);
}
.sheet.wide { max-width: 640px; height: 86dvh; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet header { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 6px 22px; flex: 0 0 auto; }
.sheet h2, .dialog h2 { font-family: var(--display); font-weight: var(--display-weight); font-size: 24px; margin: 0; letter-spacing: 0.01em; }
.sheet-body {
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 2px 22px 26px;
  font-size: 15px;
  line-height: 1.55;
  flex: 1 1 auto;
  min-height: 0;
  -webkit-user-select: text;
  user-select: text;
}
.sheet-body h3 { font-family: var(--display); font-weight: var(--display-weight); font-size: 17px; margin: 20px 0 8px; color: var(--ink); }
.prose p { margin: 0 0 12px; }
.prose ul { margin: 0; padding-left: 20px; }
.prose li { margin: 6px 0; }
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }
.about { font-size: 13px; margin-top: 22px; text-align: center; }

@media (min-width: 700px) and (min-height: 560px) {
  .sheet {
    bottom: auto;
    top: 50%;
    transform: translateY(-50%);
    border-radius: 24px;
    max-height: 82dvh;
    animation: pop 0.28s var(--ease);
  }
  .sheet.wide { height: 82dvh; }
}
@keyframes pop { from { opacity: 0; transform: translateY(-50%) scale(0.96); } }

.dialog {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 22;
  width: min(92vw, 400px);
  background: var(--paper);
  color: var(--ink);
  border-radius: 24px;
  padding: 26px 24px 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  text-align: center;
  animation: popc 0.3s var(--ease);
  overflow: hidden;
}
@keyframes popc { from { opacity: 0; transform: translate(-50%, -50%) scale(0.94); } }
.dialog p { margin: 8px 0 18px; color: var(--ink-soft); font-size: 15.5px; line-height: 1.5; }
.dialog .row { display: flex; gap: 10px; }
.result { padding-top: 22px; }
.result .glow {
  position: absolute;
  inset: -40% -20% auto;
  height: 70%;
  background: radial-gradient(ellipse at 50% 40%, color-mix(in oklab, var(--glow) 50%, transparent), transparent 65%);
  pointer-events: none;
  opacity: 0.85;
}
.result h2 { position: relative; font-size: 30px; }
.result-stars { position: relative; display: flex; justify-content: center; gap: 6px; margin-bottom: 6px; }
.result-stars svg { width: 46px; height: 46px; fill: var(--line); stroke: none; }
.result-stars svg:nth-child(2) { width: 56px; height: 56px; margin-top: -8px; }
.result-stars svg.lit { fill: var(--star); filter: drop-shadow(0 2px 4px color-mix(in oklab, var(--star) 60%, transparent)); animation: starpop 0.5s var(--spring) backwards; }
.result-stars svg.lit:nth-child(2) { animation-delay: 0.14s; }
.result-stars svg.lit:nth-child(3) { animation-delay: 0.28s; }
@keyframes starpop { from { transform: scale(0.2) rotate(-25deg); opacity: 0; } }
.result[data-stars="3"] h2 { animation: shimmer 2.4s ease-in-out infinite; }
@keyframes shimmer { 50% { text-shadow: 0 0 18px color-mix(in oklab, var(--glow) 80%, white); } }
.result-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; position: relative; }
.result-stats div, .summary div { display: flex; flex-direction: column; align-items: center; background: var(--paper-2); border-radius: 12px; padding: 8px 4px; line-height: 1.2; }
.result-stats span, .summary span { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.result-stats b, .summary b { font-family: var(--display); font-size: 19px; font-weight: var(--display-weight); font-variant-numeric: tabular-nums; }
.result .score { display: flex; flex-direction: column; align-items: center; margin: 4px 0 18px; position: relative; }
.result .score span { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); }
.result .score b { font-family: var(--display); font-size: 44px; font-weight: var(--display-weight); line-height: 1.05; font-variant-numeric: tabular-nums; }
.result .score em { font-style: normal; font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); margin-top: 2px; }

/* ------------------------------------------------------------- levels */
.tabs {
  display: flex;
  gap: 6px;
  padding: 2px 18px 10px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 0 0 auto;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  appearance: none;
  flex: 0 0 auto;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  font: 500 14px var(--sans);
  padding: 8px 14px;
  min-height: 40px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.tab[aria-selected="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.tier-head { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; justify-content: space-between; margin: 4px 0 12px; font-size: 13.5px; color: var(--ink-soft); }
.tier-head .range { font-weight: 600; color: var(--ink); }
.star-total { display: inline-flex; align-items: center; gap: 3px; font-variant-numeric: tabular-nums; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 8px; }
.tile {
  appearance: none;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  border-radius: 14px;
  padding: 7px 7px 6px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, box-shadow 0.2s;
  font: inherit;
}
.tile:active { transform: scale(0.96); }
.tile:hover { border-color: color-mix(in oklab, var(--ink) 30%, transparent); }
.tile.current { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 22%, transparent); }
.tile .mm { width: 100%; height: auto; aspect-ratio: 1; display: block; }
.mm-bg { fill: color-mix(in oklab, var(--ink) 8%, var(--paper)); }
.mm-o { fill: color-mix(in oklab, var(--ink) 34%, var(--paper)); }
.mm-t { fill: var(--accent); }
.mm-exit { stroke: var(--accent); stroke-width: 2.4; stroke-linecap: round; }
.tile.solved .mm-o { fill: color-mix(in oklab, var(--ink) 22%, var(--paper)); }
.tile .meta { display: flex; justify-content: space-between; align-items: baseline; padding: 0 2px; line-height: 1.1; }
.tile .meta b { font-family: var(--display); font-weight: var(--display-weight); font-size: 15px; }
.tile .meta small { font-size: 11px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.stars-row { display: inline-flex; gap: 1px; justify-content: center; }
.stars-row svg { width: 14px; height: 14px; fill: var(--line); }
.stars-row svg.lit { fill: var(--star); }
.stars-row.one svg:not(.lit) { display: none; }
.stars-row.one svg { fill: var(--star); }

.random h3 { margin-top: 6px; }
.random-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.btn.rand { flex-direction: column; gap: 2px; padding: 14px 10px; }
.btn.rand b { font-family: var(--display); font-weight: var(--display-weight); font-size: 16px; }
.btn.rand small { font-size: 12px; color: var(--ink-soft); }
.busy { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 18px; color: var(--ink-soft); flex-wrap: wrap; }
.busy .btn.subtle { margin: 0; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------- results */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.progress { display: grid; gap: 8px; }
.prow { display: grid; grid-template-columns: 7.2em 1fr auto 3.4em; align-items: center; gap: 10px; font-size: 14px; }
.prow .bar { height: 8px; border-radius: 999px; background: var(--paper-2); position: relative; overflow: hidden; }
.prow .bar::after { content: ""; position: absolute; inset: 0 auto 0 0; width: var(--p); border-radius: inherit; background: linear-gradient(90deg, var(--accent-2), var(--accent)); }
.prow small { font-variant-numeric: tabular-nums; color: var(--ink-soft); white-space: nowrap; }
.prow .pstars { display: inline-flex; align-items: center; gap: 2px; justify-content: flex-end; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th { text-align: left; vertical-align: bottom; font-weight: 500; color: var(--ink-soft); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; padding: 4px; border-bottom: 1px solid var(--line); }
td { padding: 7px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
th.moves, th.hints, th.score, td.moves, td.hints, td.score { text-align: right; }
th.stars, td.stars { text-align: center; }
td.level { max-width: 9.5em; overflow: hidden; text-overflow: ellipsis; }
td.score { font-family: var(--display); font-weight: var(--display-weight); font-size: 15px; }
@media (max-width: 420px) { th.hints, td.hints { display: none; } td { padding: 7px 3px; } }

/* ------------------------------------------------------------- settings */
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  appearance: none;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  font: 500 14px var(--sans);
  padding: 8px 14px 8px 10px;
  min-height: 44px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}
.opt:active { transform: scale(0.97); }
.opt[aria-checked="true"] { border-color: var(--accent); background: var(--paper); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 22%, transparent); }
.opt-label { display: flex; flex-direction: column; line-height: 1.2; }
.opt-label b { font-weight: 500; }
.opt-label small { font-size: 11.5px; color: var(--ink-soft); margin-top: 2px; }
.opts.lang .opt { padding-left: 14px; min-width: 96px; justify-content: center; }
.opts.worlds { display: grid; grid-template-columns: 1fr 1fr; }
.opts.worlds .opt { border-radius: 16px; padding: 8px 10px; }
.opts.worlds .opt:first-child { grid-column: 1 / -1; }
.world-swatch { width: 66px; height: 36px; flex: 0 0 auto; display: block; }
.auto-swatch { display: flex; flex: 0 0 auto; }
.auto-swatch .world-swatch { width: 52px; height: 30px; }
.auto-swatch .world-swatch + .world-swatch { margin-left: -14px; }
.toggle { display: flex; align-items: center; gap: 12px; margin-top: 18px; cursor: pointer; font-size: 15px; line-height: 1.35; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle .track { flex: 0 0 auto; width: 46px; height: 28px; border-radius: 999px; background: var(--track-off); position: relative; transition: background 0.25s; }
.toggle .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.25s var(--ease); }
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track::after { transform: translateX(18px); }
.toggle input:focus-visible + .track { outline: 2px solid var(--glow); outline-offset: 2px; }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(10px);
  z-index: 15;
  background: var(--toast-bg);
  color: var(--toast-ink);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  max-width: min(88vw, 420px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ------------------------------------------------------- small screens */
@media (max-height: 640px) {
  .top { padding-top: 6px; }
  .brand small { display: none; }
  .brand b { font-size: 19px; }
  .stat b { font-size: 17px; }
  .stat b.long { font-size: 13.5px; line-height: 20px; }
  .actions { padding-bottom: 10px; }
  .btn { padding: 9px 10px; }
}
@media (max-width: 520px) {
  .actions { gap: 8px; }
  .btn { flex-direction: column; gap: 3px; padding: 8px 6px 7px; font-size: 12.5px; }
  .btn span { white-space: nowrap; }
  .btn svg { width: 21px; height: 21px; }
  .dialog .btn { flex-direction: row; font-size: 14.5px; gap: 6px; }
  .stats { gap: 6px; }
  .stat span { font-size: 9.5px; letter-spacing: 0.06em; }
}
@media (max-width: 380px) {
  .top { padding-left: 12px; padding-right: 10px; }
  .brand { gap: 8px; }
  .brand img { width: 34px; height: 34px; }
  .brand b { font-size: 20px; }
  .brand small { font-size: 9.5px; letter-spacing: 0.04em; }
  .icon-btn { width: 42px; height: 42px; }
  .menu { gap: 0; }
  .stat b.long { font-size: 13px; }
}
@media (min-width: 900px) and (min-height: 700px) {
  .brand b { font-size: 26px; }
  .stage { padding: 14px 16px; }
}

/* Landscape phones: board on the left, everything else in a column. */
@media (orientation: landscape) and (max-height: 520px) {
  .app {
    max-width: none;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(250px, 330px);
    grid-template-rows: auto auto 1fr auto;
    grid-template-areas: "stage top" "stage stats" "stage ." "stage actions";
    column-gap: 8px;
  }
  .top { grid-area: top; padding: 8px 12px 2px 0; }
  .stats { grid-area: stats; grid-template-columns: repeat(3, 1fr); padding: 4px 12px 4px 0; }
  .stat.level { grid-column: 1 / -1; }
  .stage { grid-area: stage; padding: 10px 6px 10px 16px; }
  .actions { grid-area: actions; flex-wrap: wrap; padding: 4px 12px 10px 0; }
  .actions .btn { flex: 1 1 40%; flex-direction: row; font-size: 13.5px; min-height: 42px; }
  .brand small { display: none; }
  .toast { left: auto; right: 12px; transform: translateY(10px); bottom: 70px; max-width: 320px; }
  .toast.show { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .bg .blob { animation: none; }
  .veh .art, .sheet, .dialog, .backdrop, .mark, .ghost, .tile, .result-stars svg.lit, .board.enter .veh .art { animation: none !important; transition-duration: 0.01s !important; }
  .veh.exiting .art { animation: leave 0.2s linear forwards !important; }
  .veh.exiting .trail, .board.freed::after { animation: none; }
}
