:root {
  --bg: #f4f1ea;
  --panel: #ffffff;
  --ink: #1d1d1f;
  --muted: #5d5d66;
  --line: #e3ded3;
  --soft: #f7f4ee;
  --accent: #d9480f;
  --accent-ink: #ffffff;
  --good: #2b8a3e;
  --good-soft: #ebfbee;
  --focus: #1c7ed6;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.16), 0 2px 6px rgba(0, 0, 0, 0.1);

  /* The device is a physical object: its colors stay the same in light and dark mode. */
  --case-hi: #f4efe4;
  --case-lo: #e4dccb;
  --case-edge: #cfc4ac;
  --dev-ink: #2b2b2e;
  --dev-muted: #6f6a5f;
  --orange: #e8590c;
  --pad: #2e2e32;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121214;
    --panel: #1b1b1f;
    --ink: #ececf1;
    --muted: #a3a3ad;
    --line: #2d2d34;
    --soft: #222228;
    --accent: #ff7a33;
    --accent-ink: #1b1b1f;
    --good: #51cf66;
    --good-soft: #1b2e20;
    --focus: #4dabf7;
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.4);
  }
}
:root[data-theme="dark"] {
  --bg: #121214;
  --panel: #1b1b1f;
  --ink: #ececf1;
  --muted: #a3a3ad;
  --line: #2d2d34;
  --soft: #222228;
  --accent: #ff7a33;
  --accent-ink: #1b1b1f;
  --good: #51cf66;
  --good-soft: #1b2e20;
  --focus: #4dabf7;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }
button:focus-visible, .knob:focus-visible, summary:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

kbd {
  font: 600 0.8em var(--mono);
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--soft);
}

.top { max-width: 1180px; margin: 0 auto; padding: 28px 24px 20px; }
.top h1 { margin: 0; font-size: 28px; letter-spacing: -0.02em; }
.top p { margin: 4px 0 0; color: var(--muted); }

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 410px) minmax(0, 1fr);
  gap: 32px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px 56px;
  align-items: start;
}
@media (min-height: 1040px) { .device-col { position: sticky; top: 16px; } }

/* ---------- the device ---------- */
.device {
  background: linear-gradient(170deg, var(--case-hi), var(--case-lo));
  border: 1px solid var(--case-edge);
  border-radius: 26px;
  padding: 16px 18px 20px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9), inset 0 -3px 0 rgba(0, 0, 0, 0.06), var(--shadow);
  color: var(--dev-ink);
  user-select: none;
  -webkit-user-select: none;
}
.device-top { display: flex; justify-content: space-between; align-items: baseline; margin: 0 4px 10px; }
.brand { font: 800 14px var(--mono); letter-spacing: 0.14em; }
.model { font: 600 11px var(--mono); color: var(--dev-muted); }

.screen-wrap { background: var(--dev-ink); padding: 9px; border-radius: 12px; box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5); }
#lcd { display: block; width: 100%; aspect-ratio: 320 / 200; border-radius: 4px; }

.pages { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin: 14px 0 4px; padding: 4px; border-radius: 14px; }
.page-tab {
  font: 700 11px/1 var(--mono);
  letter-spacing: 0.02em;
  padding: 8px 0;
  white-space: nowrap;
  border-radius: 999px;
  border: 1px solid var(--case-edge);
  background: #faf7f0;
  color: var(--dev-ink);
  cursor: pointer;
}
.page-tab:hover { background: #fff; }
.page-tab.active { background: var(--dev-ink); border-color: var(--dev-ink); color: #fff; }
.page-tab.locked { opacity: 0.35; cursor: not-allowed; }

.knobs { display: grid; grid-template-columns: 1fr 78px 1fr; align-items: start; gap: 4px; margin: 10px 0 12px; }
.knob-wrap { display: flex; flex-direction: column; align-items: center; text-align: center; position: relative; padding: 6px 2px; border-radius: 16px; }
.knob-letter {
  position: absolute; top: 4px; left: 10px;
  font: 800 11px var(--mono);
  width: 20px; height: 20px; line-height: 20px;
  border-radius: 50%; background: var(--dev-ink); color: #fff;
}
.knob-ring {
  --n: 0;
  width: 94px; height: 94px; border-radius: 50%;
  display: grid; place-items: center;
  background: conic-gradient(from 225deg, var(--dev-ink) 0 calc(var(--n) * 270deg), #d2c8b1 0 270deg, transparent 270deg);
}
.knob {
  --deg: -135deg;
  width: 78px; height: 78px; border-radius: 50%;
  position: relative;
  background: radial-gradient(circle at 35% 30%, #ff9b5c, var(--orange) 55%, #b4410a);
  box-shadow: 0 0 0 4px var(--case-hi), 0 6px 10px rgba(0, 0, 0, 0.28), inset 0 -3px 6px rgba(0, 0, 0, 0.2);
  cursor: ns-resize;
  touch-action: none;
  outline-offset: 6px;
}
/* Only the mark rotates, so the knob's shadow stays put. */
.knob-mark { position: absolute; inset: 0; transform: rotate(var(--deg)); }
.knob-mark::after { content: ""; position: absolute; left: 50%; top: 7px; width: 5px; height: 22px; margin-left: -2.5px; border-radius: 3px; background: #fff; }
.knob-wrap.turning .knob { box-shadow: 0 0 0 4px var(--case-hi), 0 3px 6px rgba(0, 0, 0, 0.3), inset 0 -3px 6px rgba(0, 0, 0, 0.2); }
.knob-name { margin-top: 8px; font: 800 12px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; }
.knob-value { font: 600 15px var(--mono); }
.knob-hint { font-size: 12px; line-height: 1.3; color: var(--dev-muted); max-width: 130px; min-height: 2.6em; }
.knob-wrap.locked .knob { filter: grayscale(1) brightness(1.1); opacity: 0.45; cursor: not-allowed; }
.knob-wrap.locked .knob-name, .knob-wrap.locked .knob-value { opacity: 0.45; }

.knob-mid { display: flex; justify-content: center; padding-top: 26px; }
.lfo-switch {
  display: flex; flex-direction: column; gap: 3px;
  padding: 4px; border-radius: 10px;
  border: 1px solid var(--case-edge); background: #faf7f0;
  font: 700 10px var(--mono); cursor: pointer;
}
.lfo-switch[hidden] { display: none; }
.lfo-switch span { padding: 6px 5px; border-radius: 7px; color: var(--dev-muted); }
.lfo-switch span.on { background: var(--dev-ink); color: #fff; }
.lfo-switch:disabled { opacity: 0.4; cursor: not-allowed; }

.fn-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.fn {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 44px; padding: 6px 4px;
  border: none; border-radius: 10px;
  background: #d8cfbb; color: var(--dev-ink);
  font: 800 11px var(--mono); letter-spacing: 0.05em;
  box-shadow: 0 3px 0 #b5a98f;
  cursor: pointer;
}
.fn:active { transform: translateY(2px); box-shadow: 0 1px 0 #b5a98f; }
.fn-sub { font-size: 8px; opacity: 0.65; }
.fn-led { position: absolute; top: 6px; right: 7px; width: 6px; height: 6px; border-radius: 50%; background: #7a2a22; }
.fn.on { background: var(--dev-ink); color: #fff; box-shadow: 0 3px 0 #000; }
.fn.on .fn-led { background: #ff3b30; box-shadow: 0 0 6px #ff3b30; }
.fn-play.on { background: var(--orange); box-shadow: 0 3px 0 #9c3a07; }
.fn.armed { background: #c92a2a; color: #fff; box-shadow: 0 3px 0 #7d1a1a; }
.fn.locked { opacity: 0.35; cursor: not-allowed; }

.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 14px; padding: 4px; border-radius: 16px; touch-action: none; }
.pad {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  border: none; border-radius: 12px;
  background: linear-gradient(#3b3b40, var(--pad));
  color: #f1f1f1;
  font-family: var(--mono);
  box-shadow: 0 4px 0 #161618, 0 6px 10px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.pad-led { position: absolute; top: 8px; right: 8px; width: 7px; height: 7px; border-radius: 50%; background: #4d1a1a; }
.pad-num { position: absolute; top: 5px; left: 9px; font-size: 12px; font-weight: 700; opacity: 0.8; }
.pad-note { position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-35%); text-align: center; font-size: 13px; font-weight: 800; color: #ffb27d; }
.pad-key { position: absolute; bottom: 5px; right: 8px; font-size: 9px; opacity: 0.4; }
.pad.down { transform: translateY(3px); box-shadow: 0 1px 0 #161618; background: linear-gradient(#4a4a50, #3a3a3f); }
.pad.sel { box-shadow: 0 4px 0 #161618, inset 0 0 0 2px var(--orange); }
.pad.down.sel { box-shadow: 0 1px 0 #161618, inset 0 0 0 2px var(--orange); }
.pad.lit .pad-led { background: #ff3b30; box-shadow: 0 0 8px #ff3b30; }
.pad.dim .pad-led { background: #a8322a; }
.pad.idle { opacity: 0.35; }
.pad.step-now { outline: 3px solid #fcc419; outline-offset: 2px; }
.pad.step-now .pad-led { background: #fcc419; box-shadow: 0 0 8px #fcc419; }
.grid.write .pad { background: linear-gradient(#45403a, #2f2b27); }
.grid.write .pad-note { color: #d6d0c4; }
.grid.write .pad.lit .pad-note { color: #ffb27d; }

.keys-hint { text-align: center; font-size: 12.5px; color: var(--muted); margin: 14px 0 0; line-height: 1.9; }

/* Pulsing guide around the controls the current lesson is about. */
.hl { outline: 3px solid transparent; outline-offset: 4px; animation: hl 1.8s ease-in-out infinite; }
@keyframes hl {
  0%, 100% { outline-color: rgba(232, 89, 12, 0); }
  50% { outline-color: rgba(232, 89, 12, 0.75); }
}
.fn.hl, .pages.hl, .grid.hl, .knob-wrap.hl, .lfo-switch.hl { border-radius: 14px; }
@media (prefers-reduced-motion: reduce) {
  .hl { animation: none; outline-color: rgba(232, 89, 12, 0.6); }
}

/* ---------- lesson panel ---------- */
.lesson { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 26px 32px 22px; scroll-margin-top: 12px; }
.progress { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.dot {
  width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--line); background: transparent;
  font: 700 12px var(--mono); color: var(--muted); cursor: pointer;
}
.dot:hover { border-color: var(--muted); }
.dot.complete { border-color: var(--good); color: var(--good); background: var(--good-soft); }
.dot.current { background: var(--ink); border-color: var(--ink); color: var(--panel); }

.eyebrow { margin: 0; font: 700 12px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.lesson h2 { margin: 4px 0 10px; font-size: 28px; line-height: 1.2; letter-spacing: -0.015em; }
.prose { max-width: 68ch; }
.prose p { margin: 0 0 12px; }
.prose ul, .prose ol { margin: 0 0 12px; padding-left: 22px; }
.prose li { margin-bottom: 6px; }
.prose .tip { font-size: 14.5px; color: var(--muted); background: var(--soft); border-radius: 10px; padding: 10px 14px; }

.listen { margin: 16px 0; padding: 10px 14px; border-left: 4px solid var(--accent); background: var(--soft); border-radius: 0 10px 10px 0; max-width: 68ch; }
.listen[hidden] { display: none; }

.tasks { margin: 18px 0 14px; padding: 16px 18px; border: 1px solid var(--line); border-radius: 14px; }
.tasks[hidden] { display: none; }
.tasks h3 { margin: 0 0 8px; font-size: 13px; font-family: var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.tasks ul { list-style: none; margin: 0; padding: 0; }
.tasks li { display: flex; gap: 12px; align-items: flex-start; padding: 7px 0; }
.check {
  flex: none; width: 22px; height: 22px; margin-top: 1px;
  border-radius: 50%; border: 2px solid var(--line);
  display: grid; place-items: center; font-size: 13px; font-weight: 900;
  transition: background 0.2s, border-color 0.2s;
}
.tasks li.done .check { background: var(--good); border-color: var(--good); color: var(--panel); }
.tasks li.done .check::after { content: "✓"; }
.tasks li.done .task-text { color: var(--muted); }
.all-done { margin: 10px 0 0; padding: 10px 14px; border-radius: 10px; background: var(--good-soft); color: var(--good); font-weight: 600; }
.all-done[hidden] { display: none; }

.extras { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.extras[hidden] { display: none; }
.chip { padding: 7px 13px; border-radius: 999px; border: 1px solid var(--accent); background: transparent; color: var(--accent); font-size: 14px; font-weight: 600; cursor: pointer; }
.chip:hover { background: var(--accent); color: var(--accent-ink); }
.chip.quiet { border-color: var(--line); color: var(--muted); }
.chip.quiet:hover { background: var(--soft); color: var(--ink); }

.jargon { margin: 0 0 18px; border: 1px solid var(--line); border-radius: 12px; padding: 0 16px; }
.jargon[hidden] { display: none; }
.jargon summary { cursor: pointer; padding: 11px 0; font-weight: 700; }
.jargon dl { margin: 0 0 14px; display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.jargon dt { font-weight: 700; }
.jargon dd { margin: 0; color: var(--muted); }

.l-nav { display: flex; justify-content: space-between; gap: 12px; }
.btn { padding: 10px 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-weight: 700; cursor: pointer; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn[hidden] { display: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary.ready { animation: ready 1.6s ease-in-out infinite; }
@keyframes ready {
  0%, 100% { box-shadow: 0 0 0 0 rgba(232, 89, 12, 0); }
  50% { box-shadow: 0 0 0 6px rgba(232, 89, 12, 0.3); }
}
.l-foot { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin: 18px 0 0; }
.link { background: none; border: none; padding: 0; color: var(--muted); font-size: 13.5px; text-decoration: underline; cursor: pointer; }
.link[hidden] { display: none; }

.flow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 4px 0 14px; }
.flow span { display: flex; flex-direction: column; padding: 8px 12px; border-radius: 10px; background: var(--soft); border: 1px solid var(--line); font-weight: 700; font-size: 14px; }
.flow small { font-weight: 400; color: var(--muted); font-size: 12px; }
.flow b { color: var(--accent); }

.cheat { border-collapse: collapse; width: 100%; margin: 0 0 14px; font-size: 14.5px; }
.cheat th { text-align: left; font: 700 12px var(--mono); padding: 8px 14px 8px 0; vertical-align: top; white-space: nowrap; }
.cheat td { padding: 8px 0; }
.cheat tr + tr th, .cheat tr + tr td { border-top: 1px solid var(--line); }

@media (max-width: 880px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 0 16px 40px; gap: 24px; }
  .top { padding: 20px 16px 14px; }
  .device-col { position: static !important; width: 100%; max-width: 420px; margin: 0 auto; }
  .lesson { padding: 20px 18px; }
  .lesson h2 { font-size: 24px; }
}
@media (max-width: 380px) {
  .device { padding: 12px 12px 16px; }
  .knobs { grid-template-columns: 1fr 64px 1fr; }
  .knob-ring { width: 80px; height: 80px; }
  .knob { width: 66px; height: 66px; }
  .grid { gap: 7px; }
  .jargon dl { grid-template-columns: 1fr; }
}
