:root {
  --bg: #0e0e13;
  --panel: #1b1b24;
  --panel2: #2a2a38;
  --text: #f4f4f8;
  --muted: #9a9ab0;
  --accent: #ffd23f;
  --radius: 16px;
  --tap: 52px;
  color-scheme: dark;
}

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

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 12px 8px;
}
header h1 { font-size: 1.25rem; margin: 0; flex: 1; }
header button { min-width: 44px; min-height: 44px; font-size: 1.3rem; }

main { flex: 1; min-height: 0; position: relative; }

.screen {
  display: none;
  height: 100%;
  flex-direction: column;
  gap: 12px;
  padding: 0 16px 12px;
  overflow-y: auto;
}
.screen.active { display: flex; }

.stage {
  flex: 1;
  min-height: 40dvh;
  position: relative;
  container-type: size;
}
.stage canvas {
  position: absolute;
  inset: 0;
  margin: auto;
  border-radius: 4px;
  background: #000;
  box-shadow: 0 0 0 2px #33334a;
  touch-action: none;
  image-rendering: pixelated;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-shrink: 0;
}

/* ---------- buttons ---------- */
button, .btn {
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0 10px;
  font: inherit;
  font-size: 1.5rem;
  color: var(--text);
  background: var(--panel2);
  border: 0;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .08s;
}
button:active, .btn:active { transform: scale(.92); }
button.active, button[aria-pressed="true"] {
  background: #44445c;
  box-shadow: 0 0 0 3px var(--accent);
}
button:focus-visible, .btn:focus-within { outline: 3px solid #7aa7ff; outline-offset: 2px; }
button.wide { padding: 0 18px; font-size: 1.2rem; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.size-row { display: flex; align-items: center; justify-content: center; gap: 16px; }
.size-label { font-size: 1.3rem; font-weight: 700; min-width: 5ch; text-align: center; font-variant-numeric: tabular-nums; }

/* ---------- parent mode: numbers ---------- */
.num { display: none; color: var(--muted); font-variant-numeric: tabular-nums; }
body.parent .num { display: inline; }

/* ---------- RGB lamp sliders ---------- */
.rgb-sliders { display: flex; flex-direction: column; gap: 6px; }
.slider-row { display: flex; align-items: center; gap: 12px; }
.slider-row .num { min-width: 3ch; text-align: right; }

.lamp {
  flex: 0 0 auto;
  width: 52px; height: 52px;
  min-width: 0; padding: 0;
  border-radius: 50%;
  background: var(--cur);
  border: 3px solid var(--c);
  box-shadow: 0 0 calc(var(--glow) * 26px) calc(var(--glow) * 6px) var(--c);
}
.lamp:active { transform: scale(.88); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  min-width: 0;
  height: 48px;
  margin: 0;
  background: transparent;
  touch-action: pan-y;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 22px;
  border-radius: 11px;
  background: var(--track);
  box-shadow: inset 0 0 0 2px #3a3a50;
}
input[type="range"]::-moz-range-track {
  height: 22px;
  border-radius: 11px;
  background: var(--track);
  box-shadow: inset 0 0 0 2px #3a3a50;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 42px; height: 42px;
  margin-top: -10px;
  border-radius: 50%;
  background: var(--thumb);
  border: 4px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.6);
}
input[type="range"]::-moz-range-thumb {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--thumb);
  border: 4px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.6);
}
.lamp-range { --track: linear-gradient(90deg, #000, var(--c)); --thumb: var(--cur); }
.plain-range { --track: var(--panel2); --thumb: var(--accent); }

.zoom-row { display: flex; align-items: center; gap: 10px; font-size: 1.5rem; }

/* ---------- 💡 lights ---------- */
.lights-stage { display: grid; place-items: center; min-height: 34dvh; }
.venn {
  position: relative;
  width: min(100cqw, 100cqh);
  aspect-ratio: 1;
  isolation: isolate;
  background: #000;
  border-radius: 24px;
  overflow: hidden;
}
.spot {
  position: absolute;
  width: 56%;
  aspect-ratio: 1;
  border-radius: 50%;
  mix-blend-mode: screen;
  background: #000;
}
.spot:nth-child(1) { left: 22%; top: 5%; }
.spot:nth-child(2) { left: 5%;  top: 38%; }
.spot:nth-child(3) { left: 39%; top: 38%; }

.pixel-demo { display: flex; align-items: center; justify-content: center; gap: 14px; }
.subpixels, .solid {
  width: 120px; height: 120px;
  border-radius: 12px;
  box-shadow: 0 0 0 2px #33334a;
}
.subpixels { background: #000; }
.eq { font-size: 2rem; color: var(--muted); }
.solid-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.color-name { font-size: 1.1rem; font-weight: 700; }

/* ---------- 🎨 paint ---------- */
.palette { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.swatch {
  width: 46px; height: 46px;
  min-width: 0; min-height: 0; padding: 0;
  border-radius: 50%;
  border: 3px solid #44445c;
}
.swatch.active { box-shadow: 0 0 0 3px var(--accent); border-color: #000; }
.swatch.mix {
  font-size: 1.3rem;
  background: var(--cur, #000);
  border-color: #fff;
}
.mixer { display: flex; gap: 12px; align-items: center; }
.mixer .sliders { flex: 1; }
.mix-preview { width: 64px; height: 64px; border-radius: 12px; box-shadow: 0 0 0 2px #33334a; flex-shrink: 0; }

/* ---------- 📷 photo ---------- */
#screen-photo .size-label { align-self: center; }

/* ---------- 🎯 game ---------- */
.game-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 34dvh;
  overflow: hidden; /* confetti must not make the screen scroll */
}
.game-boxes { display: flex; align-items: center; gap: 10px; }
.game-boxes figure { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.game-boxes figcaption { font-size: 1.4rem; }
.game-boxes figcaption .num { font-size: .9rem; }
.box {
  width: min(36cqw, 52cqh);
  aspect-ratio: 1;
  border-radius: 20px;
  box-shadow: 0 0 0 3px #33334a;
}
.face { font-size: clamp(2rem, 10cqw, 3.5rem); }
.stars { font-size: 2.4rem; color: var(--accent); letter-spacing: 4px; }
.score { font-size: 1.1rem; color: var(--muted); }

.pulse { animation: pulse 0.9s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.1); box-shadow: 0 0 0 4px var(--accent); } }

.confetti {
  position: absolute;
  top: 45%;
  font-size: 2rem;
  pointer-events: none;
  animation: burst 1.4s ease-out forwards;
}
@keyframes burst {
  from { transform: translate(0, 0) scale(.4); opacity: 1; }
  to   { transform: translate(var(--dx), var(--dy)) scale(1.2) rotate(var(--rot)); opacity: 0; }
}

/* ---------- tabs ---------- */
.tabs {
  display: flex;
  background: var(--panel);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1;
  flex-direction: column;
  gap: 0;
  min-height: 62px;
  border-radius: 0;
  background: transparent;
  font-size: 1.7rem;
}
.tabs button span { font-size: .75rem; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--panel2); box-shadow: inset 0 3px 0 var(--accent); }
.tabs button[aria-selected="true"] span { color: var(--text); }

/* ---------- dialogs ---------- */
dialog {
  background: var(--panel);
  color: var(--text);
  border: 0;
  border-radius: 20px;
  width: min(560px, calc(100vw - 32px));
  max-height: 85dvh;
  padding: 20px;
  overflow: auto;
  user-select: text;
  -webkit-user-select: text;
  line-height: 1.45;
}
dialog::backdrop { background: rgba(0, 0, 0, .65); }
dialog h2 { margin-top: 0; }
dialog li { margin-bottom: 6px; }
dialog form { display: flex; justify-content: flex-end; }
dialog form button { font-size: 1.1rem; padding: 0 20px; }
.check { display: flex; gap: 10px; align-items: center; font-weight: 600; padding: 8px 0; }
.check input { width: 26px; height: 26px; }
.small { font-size: .9rem; color: var(--muted); }
.t-r { color: #ff4d4d; } .t-g { color: #3dff6e; } .t-b { color: #5c8bff; }

/* ---------- wide / landscape: controls beside the picture ---------- */
@media (orientation: landscape) and (min-width: 600px) {
  .screen { flex-direction: row; padding: 4px 16px 12px; }
  .stage, .lights-stage, .game-stage { min-height: 0; }
  .controls { width: min(400px, 45%); justify-content: center; overflow-y: auto; }
}
