/* Chompfe: deep aubergine "night studio" with acid-lime, coral and sky accents.
   Original identity; deliberately unlike the hardware's look. */
:root {
  --bg: #17121f;
  --panel: #211a2c;
  --panel-2: #2b2239;
  --panel-3: #362b48;
  --ink: #f3ead8;
  --ink-dim: #a99db8;
  --ink-faint: #6f6383;
  --line: #3b2f52;
  --lime: #c6f25e;
  --coral: #ff7a59;
  --sky: #7cc7ff;
  --violet: #b99cff;
  --sun: #ffd166;
  --key-white: #efe6d2;
  --key-white-down: #c6f25e;
  --key-black: #2a2036;
  --key-black-down: #8fbf2c;
  --radius: 16px;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --display: 'Bricolage Grotesque', system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(1200px 500px at 15% -10%, rgba(198, 242, 94, 0.07), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(255, 122, 89, 0.06), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: var(--display);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; }

/* ---------- header */
.top {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px 8px;
  max-width: 1180px;
  margin: 0 auto;
}
.wordmark {
  font-weight: 800;
  font-size: clamp(28px, 5vw, 42px);
  letter-spacing: -0.045em;
  margin: 0;
  line-height: 1;
}
.wordmark .dot { color: var(--lime); }
.meter {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: var(--panel);
  overflow: hidden;
  max-width: 240px;
}
.meter-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--lime), var(--sun), var(--coral));
}
.outvol {
  display: flex;
  align-items: center;
  gap: 6px;
  font: 12px var(--mono);
  color: var(--ink-dim);
}
.outvol input { width: 90px; }
#midi-btn { margin-left: auto; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translate(-50%, 20px);
  background: var(--lime);
  color: var(--bg);
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- rack layout */
.rack {
  max-width: 1180px;
  margin: 0 auto;
  padding: 6px 16px 16px;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-template-areas:
    "wave wave wave wave wave wave wave filter filter filter filter filter"
    "wave wave wave wave wave wave wave shape shape shape shape shape"
    "motion motion motion motion space space space space output output output output"
    "seq seq seq seq seq seq seq seq seq seq seq seq"
    "presets presets presets presets presets presets presets presets presets presets presets presets"
    "keys keys keys keys keys keys keys keys keys keys keys keys";
}
.wave { grid-area: wave; }
.filter { grid-area: filter; }
.shape { grid-area: shape; }
.motion { grid-area: motion; }
.space { grid-area: space; }
.output { grid-area: output; }
.seq { grid-area: seq; }
.presets { grid-area: presets; }
.keys-panel { grid-area: keys; }

@media (max-width: 900px) {
  .rack {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "wave wave" "filter shape" "motion motion" "space output"
      "seq seq" "presets presets" "keys keys";
  }
}
@media (max-width: 560px) {
  .rack {
    grid-template-columns: 1fr;
    grid-template-areas: "wave" "filter" "shape" "motion" "space" "output" "seq" "presets" "keys";
  }
  .top { flex-wrap: wrap; }
  .meter { order: 5; max-width: none; flex-basis: 100%; }
}

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px 14px 14px;
  border: 1px solid rgba(255, 255, 255, 0.03);
  min-width: 0;
}
.panel h2 {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0 0 8px;
  color: var(--ink-dim);
}
.panel h2 small {
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink-faint);
  margin-left: 4px;
}
.panel h2 + .knobs + h2 { margin-top: 10px; }
.wave h2 { color: var(--lime); }
.filter h2 { color: var(--coral); }
.shape h2 { color: var(--sun); }
.motion h2 { color: var(--sky); }
.space h2 { color: var(--violet); }
.seq h2 { color: var(--lime); }

.row { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-top: 8px; }

/* ---------- knobs */
.knobs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 6px 8px;
}
.knobs.compact { display: flex; gap: 8px; }
.knob {
  display: grid;
  justify-items: center;
  gap: 0;
  padding: 4px 2px;
  border-radius: 12px;
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
  outline: none;
}
.knob:focus-visible { box-shadow: 0 0 0 2px var(--sky); }
.knob svg { width: 58px; height: 58px; display: block; }
.knob-track { fill: none; stroke: var(--line); stroke-width: 6; stroke-linecap: round; }
.knob-arc { fill: none; stroke-width: 6; stroke-linecap: round; }
.knob-cap { fill: var(--panel-3); }
.knob.active .knob-cap { fill: #44375a; }
.knob-tick { stroke: var(--ink); stroke-width: 3; stroke-linecap: round; }
.knob-label { font-size: 12px; font-weight: 600; margin-top: 2px; text-align: center; }
.knob-val { font: 11px var(--mono); color: var(--ink-dim); white-space: nowrap; }

/* ---------- wave */
.scope-wrap { position: relative; }
#scope {
  width: 100%;
  height: 150px;
  display: block;
  background:
    linear-gradient(var(--panel-2), var(--panel-2)) padding-box;
  border-radius: 12px;
}
.scope-label {
  position: absolute;
  left: 10px;
  top: 8px;
  font: 12px var(--mono);
  color: var(--ink-dim);
}
.slots { display: flex; gap: 6px; margin: 8px 0 6px; }
.slot {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  border: 2px solid transparent;
  background: var(--panel-2);
  color: var(--ink-dim);
  border-radius: 10px;
  padding: 3px 3px 4px;
  cursor: pointer;
  font: 600 11px var(--mono);
}
.slot canvas { width: 100%; height: 26px; display: block; }
.slot[aria-checked="true"] { border-color: var(--lime); color: var(--ink); }
.slot:focus-visible { outline: 2px solid var(--sky); outline-offset: 2px; }

.toggle { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--ink-dim); cursor: pointer; }
.toggle input { accent-color: var(--lime); width: 16px; height: 16px; }

/* segmented control */
.seg {
  display: inline-flex;
  background: var(--panel-2);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.seg button {
  border: none;
  background: transparent;
  color: var(--ink-dim);
  font: 600 12px var(--mono);
  padding: 4px 8px;
  border-radius: 7px;
  cursor: pointer;
}
.seg button[aria-checked="true"] { background: var(--panel-3); color: var(--lime); }
.seg button:focus-visible { outline: 2px solid var(--sky); }
.seg-label { font-size: 12px; color: var(--ink-faint); margin-right: 4px; align-self: center; }

/* ---------- sequencer */
.seq-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 10px; }
.seq-head h2 { margin: 0; }
.transport { display: flex; gap: 6px; flex-wrap: wrap; }
.tbtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  font: 700 14px var(--display);
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  touch-action: none;
  user-select: none;
}
.tbtn .ico { width: 10px; height: 10px; display: inline-block; }
.tbtn.play .ico { clip-path: polygon(0 0, 100% 50%, 0 100%); background: var(--lime); }
.tbtn.rec .ico { border-radius: 50%; background: var(--coral); }
.tbtn.play[aria-pressed="true"] { background: var(--lime); color: var(--bg); border-color: var(--lime); }
.tbtn.play[aria-pressed="true"] .ico { background: var(--bg); clip-path: none; }
.tbtn.rec[aria-pressed="true"] { background: var(--coral); color: var(--bg); border-color: var(--coral); }
.tbtn.rec[aria-pressed="true"] .ico { background: var(--bg); }
.tbtn.rest.down, .tbtn.rest[aria-pressed="true"] { background: var(--sky); color: var(--bg); border-color: var(--sky); }
.tbtn.flash { animation: flash 0.25s steps(2) 4; }
@keyframes flash { 50% { background: var(--coral); color: var(--bg); } }
.tbtn.rainbow { animation: rainbow 1s linear; }
@keyframes rainbow {
  0% { background: #ff4d4d; } 20% { background: #ffd166; } 40% { background: #c6f25e; }
  60% { background: #7cc7ff; } 80% { background: #b99cff; } 100% { background: var(--panel-2); }
}
.seq-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-left: auto; }
.sel { font-size: 12px; color: var(--ink-dim); }
.sel b { font: 600 13px var(--mono); color: var(--sky); }
.len { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--ink-dim); }
.len output { font: 600 13px var(--mono); color: var(--ink); min-width: 2ch; text-align: center; }

.grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px;
}
.step {
  position: relative;
  aspect-ratio: 2.4;
  min-height: 34px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: var(--panel-2);
  color: var(--ink-dim);
  font: 600 12px var(--mono);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  overflow: hidden;
  padding: 0;
}
.step:nth-child(8n + 1) { box-shadow: inset 3px 0 0 var(--line); }
.step.on { background: #3a4a22; color: var(--lime); border-color: #556b2b; }
.step.rest { background: var(--panel-2); color: var(--ink-faint); border-color: var(--line); }
.step.out { background: rgba(43, 34, 57, 0.45); border: 1px dashed #4a3d63; color: var(--ink-faint); }
.step.out:hover { border-color: var(--lime); }
.step.head { outline: 2px solid var(--ink); outline-offset: -2px; }
.step.on.head { background: var(--lime); color: var(--bg); }
.step-gate {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  background: currentColor;
  opacity: 0;
}
.step.on .step-gate { opacity: 0.7; }
.step:focus-visible { outline: 2px solid var(--sky); outline-offset: 1px; }

/* ---------- presets */
.preset-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.preset-slots { display: grid; grid-template-columns: repeat(14, minmax(0, 1fr)); gap: 4px; flex: 1 1 520px; }
.pslot {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink-faint);
  font: 600 12px var(--mono);
  border-radius: 8px;
  padding: 6px 0;
  cursor: pointer;
  min-width: 0;
}
.pslot.filled { color: var(--ink); background: var(--panel-3); }
.pslot.current { border-color: var(--lime); color: var(--lime); }
.preset-bar.saving .pslot { border-color: var(--sky); }
.preset-bar.erasing .pslot.filled { border-color: var(--coral); }
#p-save[aria-pressed="true"] { background: var(--sky); color: var(--bg); }
#p-erase[aria-pressed="true"] { background: var(--coral); color: var(--bg); }
@media (max-width: 560px) {
  .preset-slots { grid-template-columns: repeat(7, minmax(0, 1fr)); }
}

/* ---------- keyboard */
.keys-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.hint { font-size: 13px; color: var(--ink-dim); margin: 8px 0 0; line-height: 1.45; }
.keys-head .hint { margin: 0; }
kbd {
  font: 11px var(--mono);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 4px;
  color: var(--ink);
}
.keyboard {
  position: relative;
  height: 140px;
  user-select: none;
  touch-action: none;
}
.key {
  position: absolute;
  top: 0;
  border-radius: 0 0 8px 8px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 6px;
  font: 11px var(--mono);
}
.key.white { height: 100%; background: var(--key-white); color: #5d5170; border: 1px solid var(--bg); }
.key.black { height: 60%; background: var(--key-black); color: var(--ink-dim); z-index: 2; border: 1px solid var(--bg); }
.key.white.down { background: var(--key-white-down); }
.key.black.down { background: var(--key-black-down); color: var(--bg); }
.key.playing:not(.down)::after {
  content: '';
  position: absolute;
  bottom: 22px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--coral);
}

/* ---------- buttons, dialog, start */
.btn {
  font: 600 13px var(--display);
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}
.btn.small { font-size: 12px; padding: 4px 10px; }
.btn:hover { border-color: var(--lime); }
.btn.accent { background: var(--lime); color: var(--bg); border-color: var(--lime); }
.btn:focus-visible, .tbtn:focus-visible, .pslot:focus-visible { outline: 2px solid var(--sky); outline-offset: 2px; }
.linkish {
  background: none; border: none; color: var(--ink-dim);
  font: 13px var(--display); text-decoration: underline; cursor: pointer;
}
.foot { max-width: 1180px; margin: 0 auto; padding: 0 16px 24px; }

dialog {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
}
dialog::backdrop { background: rgba(10, 6, 16, 0.7); }
dialog a { color: var(--lime); }
.license {
  font: 11px/1.4 var(--mono);
  white-space: pre-wrap;
  background: var(--panel-2);
  padding: 10px;
  border-radius: 8px;
  color: var(--ink-dim);
}

.start {
  position: fixed;
  inset: 0;
  background: rgba(23, 18, 31, 0.92);
  display: grid;
  place-items: center;
  z-index: 10;
  padding: 16px;
}
.start[hidden] { display: none; }
.start-inner { display: grid; gap: 14px; justify-items: center; }
.start-shared { margin: 0; color: var(--sky); font-weight: 600; }
.start-btn {
  background: var(--lime);
  color: var(--bg);
  border: none;
  border-radius: 999px;
  padding: 22px 34px;
  cursor: pointer;
  display: grid;
  gap: 4px;
  box-shadow: 0 0 0 8px rgba(198, 242, 94, 0.15);
}
.start-btn .big { font-weight: 800; font-size: 24px; letter-spacing: -0.02em; }
.start-btn .small { font-size: 13px; }
.start-err { color: var(--coral); font: 13px var(--mono); max-width: 520px; text-align: center; }

/* ---------- range inputs (out slider) */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  height: 22px;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 6px; background: var(--line); border-radius: 3px; }
input[type="range"]::-moz-range-track { height: 6px; background: var(--line); border-radius: 3px; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px; margin-top: -5px;
  border-radius: 50%; background: var(--ink); border: 3px solid var(--bg);
}
input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%; background: var(--ink); border: 3px solid var(--bg);
}
input[type="range"]:focus-visible { outline: 2px solid var(--sky); outline-offset: 2px; border-radius: 4px; }

@media (prefers-reduced-motion: reduce) {
  .tbtn.flash, .tbtn.rainbow { animation: none; }
  .toast { transition: none; }
}

/* ---------- MIDI dialog + learn */
.devs { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 4px; }
.dim { color: var(--ink-dim); font-size: 13px; }
dialog h3 { font-size: 14px; margin: 14px 0 4px; }
.maps-wrap { max-height: 40vh; overflow: auto; }
.maps { width: 100%; border-collapse: collapse; font-size: 13px; }
.maps td { padding: 6px 4px; border-top: 1px solid var(--line); vertical-align: middle; }
.maps select { background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 3px; font: 12px var(--display); }
.learn-banner {
  position: fixed; left: 50%; top: 10px; transform: translateX(-50%);
  z-index: 30; display: flex; gap: 12px; align-items: center;
  background: var(--sky); color: var(--bg); font-weight: 600;
  padding: 8px 10px 8px 16px; border-radius: 999px;
  max-width: calc(100vw - 32px); box-shadow: 0 6px 30px rgba(0, 0, 0, 0.4);
}
.learn-banner[hidden] { display: none; }
.learning [data-learn] { outline: 2px dashed rgba(124, 199, 255, 0.55); outline-offset: 2px; cursor: crosshair; }
.learning [data-learn].armed { outline: 3px solid var(--lime); animation: armed 0.8s ease-in-out infinite alternate; }
@keyframes armed { to { outline-color: rgba(198, 242, 94, 0.3); } }
[data-learn].mapped { position: relative; }
[data-learn].mapped::before {
  content: ''; position: absolute; top: 3px; right: 3px; width: 7px; height: 7px;
  border-radius: 50%; background: var(--sky); pointer-events: none;
}
@media (prefers-reduced-motion: reduce) { .learning [data-learn].armed { animation: none; } }

/* ---------- custom wavetables */
.table-tools { margin-top: 2px; }
.file-btn { display: inline-flex; align-items: center; }
.drop-hint { font-size: 12px; }
.slot .slot-name {
  display: block; font: 10px var(--display); color: var(--sky);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.slot.custom { border-style: dashed; }
.slot.custom[aria-checked="true"] { border-style: solid; }
.slot.dropping { border-color: var(--sky); background: var(--panel-3); }
body.dragging .slot { outline: 2px dashed rgba(124, 199, 255, 0.5); outline-offset: 2px; }
dialog.import { width: min(680px, calc(100vw - 32px)); }
#imp-overview, #imp-preview { width: 100%; display: block; background: var(--panel-2); border-radius: 10px; }
#imp-overview { height: 60px; margin-bottom: 4px; }
#imp-preview { height: 180px; margin-top: 10px; }
.imp-range { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; font-size: 13px; color: var(--ink-dim); }
.imp-range input { width: 100%; }
#imp-status.err { color: var(--coral); }
#imp-keep:disabled { opacity: 0.4; cursor: not-allowed; }

.midi-mon {
  font: 11px/1.45 var(--mono); color: var(--ink-dim); background: var(--panel-2);
  border-radius: 8px; padding: 8px 10px; margin: 0; height: 9.5em; overflow: hidden; white-space: pre;
}

/* ======================================================================
   Light, cozy theme + the instrument panel (overrides the earlier dark look)
   ====================================================================== */
:root {
  --bg: #f7efe2;
  --panel: #fffaf2;
  --panel-2: #f3e8d8;
  --panel-3: #eadcc8;
  --ink: #2f2440;
  --ink-dim: #6e6080;
  --ink-faint: #a597b3;
  --line: #e2d4c1;
  --lime: #3fae7e;
  --coral: #f2694f;
  --sky: #3d95dd;
  --violet: #7f5fe0;
  --sun: #e9a821;
  --key-white: #fffaf2;
  --key-white-down: #b8f0dc;
  --key-black: #3b2f52;
  --key-black-down: #6a4fb0;
  --body: #3b2f52;
  --body-2: #31264a;
  --round: 'Fredoka', 'Bricolage Grotesque', system-ui, sans-serif;
  color-scheme: light;
}
body {
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 224, 138, 0.35), transparent 34%),
    radial-gradient(circle at 92% 14%, rgba(201, 182, 255, 0.35), transparent 32%),
    radial-gradient(circle at 50% 100%, rgba(184, 240, 220, 0.45), transparent 45%),
    var(--bg);
  color: var(--ink);
}
.wordmark { font-family: var(--round); font-weight: 700; letter-spacing: -0.02em; }
.wordmark .dot { color: var(--coral); }
.btn { background: var(--panel); border-color: var(--line); color: var(--ink); border-radius: 999px; font-family: var(--round); font-weight: 600; }
.btn:hover { border-color: var(--violet); }
.btn.accent { background: #ffe08a; border-color: #e9c45c; color: var(--ink); }
.btn[aria-pressed="true"]#labels-btn { background: #e7dcff; border-color: #c9b6ff; }
.meter { background: var(--panel-3); }
.toast { background: var(--ink); color: var(--panel); }
.panel { background: var(--panel); border: 2px solid var(--line); box-shadow: 0 2px 0 var(--line); }
.knob-cap { fill: var(--panel-3); }
.knob.active .knob-cap { fill: #ddd0bd; }
.step.on { background: #d9f5e8; color: #1f7a54; border-color: #8fd9b8; }
.step.on.head { background: var(--lime); color: #fff; }
.step.head { outline-color: var(--ink); }
.step.out { background: rgba(243, 232, 216, 0.5); border-color: var(--line); }
.tbtn { background: var(--panel); }
.start { background: rgba(247, 239, 226, 0.93); }
.start-btn { background: #ffe08a; color: var(--ink); box-shadow: 0 0 0 8px rgba(255, 224, 138, 0.35), 0 4px 0 #e0b84a; font-family: var(--round); }
.start-shared { color: var(--violet); }
dialog { background: var(--panel); color: var(--ink); border: 2px solid var(--line); }
dialog::backdrop { background: rgba(47, 36, 64, 0.35); }
.license { background: var(--panel-2); }
kbd { background: var(--panel); border-color: var(--line); color: var(--ink); }
.learn-banner { background: var(--violet); color: #fff; }
.seg { background: var(--panel-2); }
.seg button[aria-checked="true"] { background: var(--panel); color: var(--violet); box-shadow: 0 1px 0 var(--line); }
.pslot.filled { background: #efe6ff; }
.pslot.current { border-color: var(--violet); color: var(--violet); }

/* ---------- stage + doodles */
.stage {
  position: relative;
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 16px 40px;
}
.doodles { position: absolute; inset: 0; pointer-events: none; z-index: 0; }
.dd { position: absolute; }
.d1 { width: 34px; left: -6px; top: 10px; transform: rotate(-12deg); }
.d2 { width: 26px; left: 28px; top: 96px; }
.d3 { width: 70px; left: -30px; top: 210px; transform: rotate(-8deg); }
.d4 { width: 30px; right: 4px; top: 6px; transform: rotate(10deg); }
.d5 { width: 64px; right: -40px; top: 120px; }
.d6 { width: 54px; left: -46px; top: 330px; transform: rotate(-10deg); }
.d7 { width: 24px; right: 14px; top: 300px; transform: rotate(18deg); }
.d8 { width: 30px; right: -26px; top: 400px; transform: rotate(-12deg); }
.d9 { width: 70px; right: 40px; top: -14px; }
.d10 { width: 20px; left: 46%; top: -6px; }
.d11 { width: 46px; right: -50px; top: 230px; transform: rotate(12deg); }
.d12 { width: 36px; left: -36px; top: 470px; }
@media (max-width: 1260px) { .d3, .d5, .d6, .d8, .d11, .d12 { display: none; } }
@media (max-width: 700px) { .doodles { display: none; } }

/* ---------- the instrument */
.instrument { position: relative; z-index: 1; }
.inst-face {
  background: linear-gradient(180deg, var(--body), var(--body-2));
  border-radius: 28px;
  padding: 16px 22px 22px;
  box-shadow: 0 0 0 3px var(--ink), 0 10px 0 var(--ink), 0 22px 40px rgba(47, 36, 64, 0.25);
  color: #fdf3e3;
  user-select: none;
  -webkit-user-select: none;
}
.inst-head { display: grid; grid-template-columns: auto 1fr auto; gap: 18px; align-items: center; margin-bottom: 18px; }
.inst-brand { font: 700 30px var(--round); letter-spacing: -0.01em; line-height: 0.9; color: #fdf3e3; }
.inst-brand span { display: block; font-size: 11px; letter-spacing: 0.32em; text-transform: uppercase; color: #c9b6ff; margin-top: 4px; }
.inst-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
/* the engine picker: a two-way slide switch */
.fw-pick { display: inline-flex; border: 2px solid #5a4a78; border-radius: 999px; padding: 2px; background: #241b33; }
.fw-pick button {
  font: 700 11px var(--round); letter-spacing: 0.2em; text-transform: uppercase;
  color: #c9b6ff; background: none; border: 0; border-radius: 999px; padding: 4px 11px; cursor: pointer;
}
.fw-pick button[aria-checked="true"] { background: #fdf3e3; color: var(--ink); }
.fw-pick button:focus-visible { outline: 2px solid #ffe08a; outline-offset: 1px; }
.tape-extras { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.tape-extras[hidden] { display: none; }
.pill {
  font: 600 10px var(--round); letter-spacing: 0.06em; text-transform: uppercase;
  color: #e7dcff; background: none; border: 2px solid #5a4a78; border-radius: 999px; padding: 3px 9px; cursor: pointer;
}
.pill[aria-pressed="true"] { background: #7df0c3; border-color: #7df0c3; color: var(--ink); }
.pill:focus-visible { outline: 2px solid #ffe08a; outline-offset: 1px; }
/* TAPE: a warmer body so you can tell at a glance which engine is up */
.instrument.fw-tape .inst-face { background: linear-gradient(180deg, #4a3346, #3a2737); }
.instrument.fw-tape .inst-brand span { color: #ffb4c8; }
.screen {
  background: #120e18;
  border-radius: 12px;
  padding: 8px 10px;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.7), 0 0 0 3px #1d1628, 0 0 0 5px #5a4a78;
  max-width: 640px;
  justify-self: center;
  width: 100%;
}
.led { display: block; width: 100%; height: auto; aspect-ratio: 120 / 24; }

.inst-controls { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: start; }
.knob-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* tags: the little labels over controls */
.tag {
  display: inline-block;
  font: 600 10px var(--round);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: #fdf3e3;
  color: var(--ink);
  padding: 2px 7px;
  border-radius: 6px;
  white-space: nowrap;
}
body:not(.labels) .instrument .tag,
body:not(.labels) .instrument .enc-func,
body:not(.labels) .instrument .mode-caption,
body:not(.labels) .instrument .star-caption,
body:not(.labels) .instrument .group-cap,
body:not(.labels) .instrument .kkey.black .klabel { visibility: hidden; }

/* encoders */
.enc { display: grid; justify-items: center; gap: 5px; width: 92px; cursor: ns-resize; touch-action: none; outline: none; border-radius: 14px; padding: 2px 0 4px; }
.enc.big { width: 132px; }
.enc:focus-visible { box-shadow: 0 0 0 3px #c9b6ff; }
.enc-led { width: 12px; height: 12px; border-radius: 50%; background: #241b33; box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.6); transition: background 60ms; }
.enc-body { position: relative; width: 66px; height: 66px; }
.enc.big .enc-body { width: 104px; height: 104px; }
.enc-body svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.enc-track { fill: none; stroke: #2a2039; stroke-width: 7; }
.enc-arc { fill: none; stroke: #c9b6ff; stroke-width: 7; stroke-linecap: round; }
.enc-cap {
  position: absolute; inset: 12%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fffaf2, #e8dac6 70%, #cdb99c);
  box-shadow: 0 4px 0 #1d1628, 0 6px 10px rgba(0, 0, 0, 0.35);
}
.enc.big .enc-cap { background: radial-gradient(circle at 35% 30%, #e7dcff, #b9a2f5 70%, #9479df); }
.enc-cap i { position: absolute; left: 50%; top: 8%; width: 5px; height: 30%; margin-left: -2.5px; border-radius: 3px; background: var(--ink); }
.enc.active .enc-cap { box-shadow: 0 2px 0 #1d1628, 0 3px 6px rgba(0, 0, 0, 0.35); transform-origin: center; }
.enc-func { font: 500 11px var(--round); color: #e7dcff; text-align: center; min-height: 14px; line-height: 1.15; }
.instrument.shifted .enc-func { color: #ffe08a; }
.enc-pages { display: flex; gap: 5px; }
.enc-pages i { width: 6px; height: 6px; border-radius: 50%; background: #5a4a78; }
.enc-pages i.on { background: #fdf3e3; }

/* mode switch + star key */
.mode-area { display: grid; justify-items: center; gap: 6px; width: 96px; }
.mode-switch {
  width: 30px; height: 50px; border-radius: 10px; border: 3px solid #1d1628; background: #241b33; position: relative; cursor: pointer; padding: 0;
}
.mode-switch i { position: absolute; left: 3px; right: 3px; height: 20px; border-radius: 6px; background: #fdf3e3; top: 3px; transition: top 120ms; box-shadow: 0 2px 0 #b9a68a; }
.mode-switch[aria-checked="true"] i { top: 21px; }
.mode-switch:focus-visible, .star-key:focus-visible, .tkey:focus-visible, .kkey:focus-visible { outline: 3px solid #ffe08a; outline-offset: 2px; }
.mode-caption, .star-caption { font: 500 11px var(--round); color: #e7dcff; text-align: center; }
.instrument.shifted .star-caption { color: #ffe08a; }
.star-key {
  position: relative; width: 72px; height: 66px; border-radius: 16px; border: 3px solid #1d1628;
  background: linear-gradient(180deg, #e7dcff, #c9b6ff); box-shadow: 0 5px 0 #1d1628; cursor: pointer; padding: 6px 0 0;
}
.star-key:active, .star-key.on { transform: translateY(2px); box-shadow: 0 3px 0 #1d1628, 0 0 18px rgba(201, 182, 255, 0.7); }
.star-key .mascot { width: 44px; height: 44px; }
.key-led { position: absolute; top: 6px; left: 50%; width: 14px; height: 5px; margin-left: -7px; border-radius: 3px; background: rgba(47, 36, 64, 0.25); }

/* play / loop */
.transport-area { display: grid; grid-template-columns: auto auto; gap: 6px 10px; align-items: start; padding-top: 22px; }
.transport-area .tag { grid-row: 1; justify-self: center; }
.tkey {
  grid-row: 2; position: relative; width: 68px; height: 64px; border-radius: 16px; border: 3px solid #1d1628; cursor: pointer;
  box-shadow: 0 5px 0 #1d1628; font: 700 20px var(--round); color: var(--ink); touch-action: none;
}
.tkey b { position: relative; top: 4px; }
.tkey.play { background: linear-gradient(180deg, #c8f7e4, #8fe3c0); }
.tkey.loop { background: linear-gradient(180deg, #ffd0c6, #ff9f8c); font-size: 24px; }
.tkey:active { transform: translateY(2px); box-shadow: 0 3px 0 #1d1628; }

/* keybed */
.keybed { margin-top: 22px; position: relative; }
.black-row { position: relative; height: 70px; }
.white-row { display: grid; grid-template-columns: repeat(15, 1fr); gap: 7px; }
.kkey {
  position: relative; border: 3px solid #1d1628; border-radius: 12px; cursor: pointer; touch-action: none; padding: 0;
  font: 600 12px var(--round); color: var(--ink);
}
.kkey.white { height: 78px; background: linear-gradient(180deg, #fffaf2, #efe2cf); box-shadow: 0 5px 0 #1d1628; }
.kkey.black { position: absolute; bottom: 4px; width: 5.1%; height: 46px; transform: translateX(-50%); background: linear-gradient(180deg, #a993e8, #8a72d6); box-shadow: 0 4px 0 #1d1628; color: #fff; }
.kkey.pressed, .kkey:active { transform: translateY(3px); box-shadow: 0 2px 0 #1d1628; }
.kkey.black.pressed, .kkey.black:active { transform: translate(-50%, 3px); }
.kkey .klabel { position: absolute; left: 0; right: 0; bottom: 7px; text-align: center; font-size: 11px; line-height: 1; pointer-events: none; }
.kkey.black .klabel { font-size: 9px; letter-spacing: 0.02em; }
.instrument.fw-tape .kkey.black .klabel { font-size: 8px; letter-spacing: 0; line-height: 1.05; padding: 0 1px; }
.kkey.white .klabel { color: var(--ink-faint); }
.instrument.shifted .kkey.white .klabel { color: var(--violet); font-weight: 700; }
.instrument.shifted .kkey.black { background: linear-gradient(180deg, #ffe08a, #f2c24f); color: var(--ink); }
.kkey .key-led { top: 7px; }
.group-cap {
  position: absolute; top: 0; height: 16px; text-align: center; font: 600 10px var(--round); letter-spacing: 0.1em; text-transform: uppercase;
  color: #c9b6ff; border-bottom: 2px solid #5a4a78; border-radius: 0 0 4px 4px; pointer-events: none;
  white-space: nowrap; overflow: visible;
}
.instrument.shifted .group-cap { color: #ffe08a; border-color: #ffe08a; }

/* hint line, keys help */
.hint-line {
  position: relative; z-index: 1; margin: 22px auto 0; max-width: 860px; text-align: center;
  font: 500 15px var(--round); color: var(--ink); background: var(--panel); border: 2px solid var(--line);
  border-radius: 14px; padding: 10px 16px; min-height: 2.6em;
}
.keys-help { position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; margin: 10px 0 0; }

/* drawers */
.drawers { position: relative; z-index: 1; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; margin-top: 26px; }
.drawer > summary {
  list-style: none; cursor: pointer; font: 600 17px var(--round); background: var(--panel); border: 2px solid var(--line);
  border-radius: 16px; padding: 12px 16px; display: flex; align-items: baseline; gap: 10px;
}
.drawer > summary::-webkit-details-marker { display: none; }
.drawer > summary::before { content: '+'; display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: #ffe08a; font-size: 15px; }
.drawer[open] > summary::before { content: '−'; }
.drawer > summary small { font: 400 13px var(--display); color: var(--ink-dim); }
.drawer > summary:focus-visible { outline: 3px solid var(--violet); }
.drawer > .panel, .drawer > .param-grid { margin-top: 8px; }
.param-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.cheat-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.cheat-table th, .cheat-table td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.cheat-table thead th { font: 600 12px var(--round); text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-dim); }
.cheat-table tbody th { font: 600 14px var(--round); text-transform: uppercase; color: var(--violet); }
.cheat-list { margin: 12px 0 0; padding-left: 20px; line-height: 1.55; font-size: 14px; }

/* WAVE-only and TAPE-only page parts */
body:not(.tape-mode) .tape-only, body.tape-mode .wave-only { display: none; }
.recipes { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-bottom: 16px; }
.recipe { background: var(--card, rgba(255, 255, 255, 0.5)); border: 2px solid var(--line); border-radius: 14px; padding: 10px 14px; }
.recipe h3 { margin: 0 0 6px; font: 700 15px var(--round); color: var(--violet); }
.recipe p { margin: 0; font-size: 14px; line-height: 1.5; }
.tape-guide .hint .btn { margin-left: 8px; }
@media (max-width: 640px) {
  /* wide tables scroll inside themselves instead of widening the page */
  .cheat-table { display: block; overflow-x: auto; font-size: 13px; }
  .recipes { grid-template-columns: 1fr; }
}
.tape-io { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 10px 0; font-size: 14px; }
.tape-io select { font: inherit; padding: 3px 6px; border-radius: 8px; border: 2px solid var(--line); background: var(--paper, #fff); color: inherit; }
.panel h2 { color: var(--ink-dim); }
.wave h2, .seq h2 { color: var(--lime); }

/* small screens */
@media (max-width: 900px) {
  .inst-head { grid-template-columns: 1fr auto; }
  .inst-head .screen { grid-column: 1 / -1; grid-row: 2; }
  .inst-controls { grid-template-columns: 1fr; }
  .mode-area { grid-template-columns: auto auto auto auto; width: auto; justify-content: start; align-items: center; }
  .knob-row { justify-content: center; }
}
@media (max-width: 600px) {
  .inst-face { padding: 12px 10px 16px; border-radius: 20px; }
  .enc { width: 30%; }
  .enc.big { width: 40%; }
  .enc-body { width: 54px; height: 54px; }
  .enc.big .enc-body { width: 80px; height: 80px; }
  .white-row { gap: 3px; }
  .kkey { border-width: 2px; border-radius: 8px; }
  .kkey.white { height: 64px; }
  .kkey.black { height: 40px; width: 5.4%; }
  .kkey .klabel { font-size: 9px; }
  .kkey.black .klabel { font-size: 7px; }
  .group-cap { font-size: 8px; letter-spacing: 0.02em; }
  .hint-line { font-size: 13px; }
}
