:root {
  --bg: #0d0f14;
  --panel: #161a22;
  --line: #2a303c;
  --text: #e9ecf2;
  --muted: #9aa3b2;
  --r: #ff0000;
  --g: #00ff00;
  --b: #0000ff;
  --from: #000;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

header { padding: 1.25rem 1.25rem 0; max-width: 72rem; margin: 0 auto; }
h1 { margin: 0; font-size: 1.75rem; letter-spacing: -0.01em; }
header p { margin: 0.25rem 0 0; color: var(--muted); }

.modes {
  display: inline-flex; margin-top: 0.75rem;
  border: 1px solid var(--line); border-radius: 999px; padding: 0.2rem;
  background: var(--panel);
}
.modes button { border: 0; background: transparent; padding: 0.4rem 1.1rem; }
.modes button[aria-pressed="true"] { background: var(--text); color: var(--bg); font-weight: 600; }

main {
  display: grid;
  gap: 1.25rem;
  padding: 1.25rem;
  max-width: 72rem;
  margin: 0 auto;
}
@media (min-width: 900px) {
  main { grid-template-columns: 1.4fr 1fr; align-items: start; }
  .stage { position: sticky; top: 1.25rem; }
}

.stage {
  position: relative;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  max-height: 70vh;
}
canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
canvas.dragging { cursor: grabbing; }

button {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.ghost {
  position: absolute; right: 0.75rem; bottom: 0.75rem;
  background: rgba(0, 0, 0, 0.6); font-size: 0.875rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.25rem;
  display: grid;
  gap: 1.25rem;
}

.result { display: flex; gap: 1rem; align-items: center; }
.swatch {
  flex: none;
  width: 5.5rem; height: 5.5rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #000;
}
.result p { margin: 0; }
.equation { font-size: 1.25rem; font-weight: 650; }
.hint { color: var(--muted); }
code { font: 0.875rem ui-monospace, "SF Mono", Menlo, monospace; color: var(--muted); }

.sliders { display: grid; gap: 0.9rem; }
.channel {
  display: grid;
  grid-template-columns: 6.25rem 1fr 4.5rem;
  align-items: center;
  gap: 0.75rem;
}
.channel label { font-weight: 600; white-space: nowrap; }
.channel[data-channel="r"] { --c: var(--r); }
.channel[data-channel="g"] { --c: var(--g); }
.channel[data-channel="b"] { --c: var(--b); }
/* Paint mode: each slot holds the paint that absorbs that channel, from none (white) to full. */
[data-mode="paint"] { --from: #fff; }
[data-mode="paint"] .channel[data-channel="r"] { --c: #00ffff; }
[data-mode="paint"] .channel[data-channel="g"] { --c: #ff00ff; }
[data-mode="paint"] .channel[data-channel="b"] { --c: #ffff00; }
[data-mode="paint"] .stage { background: #fff; }
.channel label::before {
  content: ""; display: inline-block;
  width: 0.6rem; height: 0.6rem; margin-right: 0.4rem;
  border-radius: 50%; background: var(--c);
}

/* The track itself shows the lesson: 0 is dark, 255 is the full-power light. */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 1.75rem; margin: 0;
  background: transparent;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 0.75rem; border-radius: 999px;
  background: linear-gradient(to right, var(--from), var(--c));
  border: 1px solid var(--line);
}
input[type="range"]::-moz-range-track {
  height: 0.75rem; border-radius: 999px;
  background: linear-gradient(to right, var(--from), var(--c));
  border: 1px solid var(--line);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 1.5rem; height: 1.5rem; margin-top: -0.43rem;
  border-radius: 50%; background: #fff; border: 3px solid var(--bg);
  box-shadow: 0 0 0 1px var(--muted);
}
input[type="range"]::-moz-range-thumb {
  width: 1.2rem; height: 1.2rem;
  border-radius: 50%; background: #fff; border: 3px solid var(--bg);
  box-shadow: 0 0 0 1px var(--muted);
}

/* 16px keeps iOS Safari from zooming the page on focus. */
input[type="number"] {
  width: 100%;
  font: 16px ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
  text-align: right;
}

.presets { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.presets button { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; }
.presets button span {
  width: 0.8rem; height: 0.8rem; border-radius: 50%;
  border: 1px solid var(--line);
}

.probe {
  margin: 0;
  display: flex; align-items: center; gap: 0.6rem;
  min-height: 2rem;
  color: var(--muted); font-size: 0.95rem;
}
.probe span.dot {
  flex: none; width: 1.4rem; height: 1.4rem; border-radius: 6px;
  border: 1px solid var(--line);
}

details { color: var(--muted); }
summary { cursor: pointer; color: var(--text); font-weight: 600; }
details ul { padding-left: 1.2rem; }
