:root {
  --bg: #060607;
  --bg-panel: #0e0b0c;
  --line: #2a1418;
  --fg: #f2e4e6;
  --dim: #7a6468;
  --accent: #ff2f4e;
  --accent2: #ff8a3d;
  --cell: #150a0c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, "Courier New", monospace;
}

body {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 32px 16px 64px;
}

main { width: 100%; max-width: 860px; }

.robot {
  display: table;          /* shrink-wrap so the art keeps its own alignment */
  text-align: left;
  color: var(--accent);
  font-size: 15px;
  line-height: 1.3;
  margin: 0 auto 6px;
  text-shadow: 0 0 12px rgba(255, 47, 78, 0.4);
  transition: text-shadow 0.08s ease, color 0.08s ease, transform 0.35s ease-out;
  will-change: transform;
}
.robot.hit {
  color: var(--accent2);
  text-shadow: 0 0 18px rgba(255, 138, 61, 0.65);
}

.title {
  text-align: center;
  font-size: 28px;
  letter-spacing: 2px;
  margin: 0;
  transition: transform 0.35s ease-out;
  will-change: transform;
}
.blink { animation: blink 1.1s steps(1) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

.tagline { text-align: center; color: var(--dim); margin: 6px 0 28px; font-size: 13px; }

.start { text-align: center; margin: 48px 0; }
.start-btn {
  background: var(--accent);
  color: #1a0004;
  border: none;
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  padding: 14px 22px;
  border-radius: 6px;
  cursor: pointer;
  letter-spacing: 0.5px;
}
.start-btn:hover { filter: brightness(1.08); }
.start-btn:active { transform: translateY(1px); }
.hint { color: var(--dim); font-size: 12px; margin: 12px 0 0; }

.panel {
  border: 1px solid var(--line);
  background: var(--bg-panel);
  border-radius: 10px;
  padding: 20px;
}
.row { margin-bottom: 24px; }
.row:last-child { margin-bottom: 0; }

.section-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--dim);
  margin: 0 0 10px;
  font-weight: 600;
}
.section-label .dim { text-transform: none; letter-spacing: 0; color: #4a3236; }
.dim { color: var(--dim); }
.small-note { font-size: 11.5px; margin: 6px 0 12px; line-height: 1.5; }

/* buttons + inputs */
.btn {
  background: #150a0c;
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 10px 14px;
  cursor: pointer;
  letter-spacing: 0.3px;
  touch-action: manipulation;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a0004; }
.btn.primary:hover { filter: brightness(1.08); color: #1a0004; }
.btn.on { background: var(--accent); border-color: var(--accent); color: #1a0004; }
#recBtn.on { background: #ff0033; animation: pulse 0.9s ease-in-out infinite; }
@keyframes pulse { 50% { filter: brightness(1.5); } }
.btn:disabled { opacity: 0.4; cursor: default; }

input[type="text"], input[type="number"], select {
  background: #150a0c;
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 5px;
  font-family: inherit;
  font-size: 13px;
  padding: 7px 8px;
  min-width: 0;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus { outline: none; border-color: var(--accent); }
input[type="number"] { width: 64px; }
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }

label.inline { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--dim); text-transform: uppercase; letter-spacing: 1px; }
label.inline.check { text-transform: none; letter-spacing: 0; color: var(--fg); }
label.grow { flex: 1 1 140px; }
label.grow input { flex: 1; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  background: var(--line);
  border-radius: 2px;
  outline: none;
  margin: 8px 0;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); cursor: pointer;
  box-shadow: 0 0 8px rgba(255, 47, 78, 0.55);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%; border: none;
  background: var(--accent); cursor: pointer;
  box-shadow: 0 0 8px rgba(255, 47, 78, 0.55);
}

.knob-group { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.knob-group label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--dim); }

/* transport */
.transport {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  padding-bottom: 18px; border-bottom: 1px solid var(--line);
}

/* patterns */
.pat-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.pat-btns { display: flex; gap: 6px; }
.pat-btn {
  width: 34px; height: 34px; border-radius: 6px;
  border: 1px solid var(--line); background: #150a0c; color: var(--fg);
  font-family: inherit; font-weight: 700; cursor: pointer; position: relative;
}
.pat-btn:hover { border-color: var(--accent); }
.pat-btn.sel { background: var(--accent); border-color: var(--accent); color: #1a0004; }
.pat-btn.has::after {
  content: ""; position: absolute; right: 3px; top: 3px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent2);
}
.pat-tools { display: flex; gap: 6px; }
.song-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 10px; }
#chainInput { width: 190px; text-transform: uppercase; letter-spacing: 2px; }

/* sequencer */
.seq { display: flex; flex-direction: column; gap: 4px; }
.seq-row { display: grid; grid-template-columns: 74px 1fr; gap: 6px; align-items: stretch; }
.seq-name {
  background: #150a0c; color: var(--fg); border: 1px solid var(--line); border-radius: 5px;
  font-family: inherit; font-size: 10.5px; font-weight: 700; text-align: left;
  padding: 0 6px; height: 30px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer;
}
.seq-name.sel { border-color: var(--accent); color: var(--accent); }
.seq-name.muted { opacity: 0.4; text-decoration: line-through; }
.cells { display: grid; grid-template-columns: repeat(16, 1fr); gap: 2px; }
.cell {
  height: 30px; border-radius: 3px; background: var(--cell); border: 1px solid var(--line);
  cursor: pointer; touch-action: manipulation; position: relative;
}
.cell:nth-child(4n) { margin-right: 4px; }
.cell:nth-child(4n+1) { background-image: linear-gradient(rgba(255,255,255,0.03), rgba(255,255,255,0.03)); }
.cell[data-l="1"] { background: rgba(255, 47, 78, 0.35); border-color: rgba(255, 47, 78, 0.55); }
.cell[data-l="2"] { background: rgba(255, 47, 78, 0.7); border-color: rgba(255, 47, 78, 0.85); }
.cell[data-l="3"] { background: var(--accent); border-color: var(--accent); }
.cell.now { outline: 1px solid var(--accent2); outline-offset: 0; box-shadow: 0 0 8px rgba(255, 138, 61, 0.7); }
.seq-head { display: grid; grid-template-columns: 74px 1fr; gap: 6px; }
.seq-head .cells .num { font-size: 9px; color: var(--dim); text-align: center; height: auto; background: none; border: none; cursor: default; }
.seq-head .cells .num.beat { color: var(--fg); }

/* pads */
.pads { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pad {
  border: 1px solid var(--line); background: #150a0c; color: var(--fg);
  border-radius: 8px; padding: 18px 8px; cursor: pointer; text-align: center;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
  transition: transform 0.04s ease, background 0.06s ease, border-color 0.06s ease;
  position: relative;
}
.pad .num { display: block; font-size: 10px; color: var(--dim); margin-bottom: 4px; }
.pad .lbl { display: block; font-size: 12px; font-weight: 700; letter-spacing: 0.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pad .src { display: block; font-size: 9.5px; color: var(--dim); margin-top: 4px; }
.pad.sel { border-color: var(--accent); }
.pad.custom .src { color: var(--accent2); }
.pad.muted { opacity: 0.45; }
.pad:hover { border-color: var(--accent); }
.pad:active, .pad.active { background: var(--accent2); color: #200a02; border-color: var(--accent2); transform: translateY(2px) scale(0.98); }
.pad:active .num, .pad.active .num, .pad:active .src, .pad.active .src { color: #200a02; }
.pad.drop { outline: 2px dashed var(--accent2); }

/* keys */
.keys-tools { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-bottom: 10px; }
.oct-group { display: inline-flex; align-items: center; gap: 10px; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
.oct-btn {
  width: 26px; height: 26px; border-radius: 5px; border: 1px solid var(--line);
  background: #150a0c; color: var(--fg); cursor: pointer; font-size: 15px; line-height: 1;
}
.oct-btn:hover { border-color: var(--accent); color: var(--accent); }
#octLabel { min-width: 14px; text-align: center; color: var(--accent); font-weight: 700; }
.keyboard { display: flex; gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.key {
  flex: 1 0 34px; min-width: 34px; height: 92px; border-radius: 5px; border: 1px solid var(--line);
  background: #f2e4e6; color: #180a0c; display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: 8px; font-size: 11px; font-weight: 700; cursor: pointer;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
  transition: transform 0.04s ease, background 0.06s ease;
}
.key.black { background: #1a0e10; color: var(--dim); height: 60px; align-self: flex-start; border-color: #000; }
.key:active, .key.active { background: var(--accent); color: #1a0004; transform: translateY(2px); }
.key.black.active, .key.black:active { background: var(--accent2); color: #200a02; }

/* editor */
.ed-top { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
#unitName { flex: 1 1 140px; }
#libSelect { max-width: 100%; flex: 1 1 200px; }
.file-btn { display: inline-block; }
.file-btn input { display: none; }
#wave { width: 100%; height: 70px; border: 1px solid var(--line); border-radius: 6px; background: #0a0607; display: block; }
.ed-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px 18px; }
.ed-flags { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 14px; }

/* master */
.controls {
  display: flex; flex-wrap: wrap; gap: 22px; align-items: flex-end;
  padding: 20px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.controls .knob-group { flex: 1 1 120px; min-width: 110px; }
.check-group { flex: 0 0 auto !important; }

/* export */
.ex-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px 14px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--dim); }
.field input[type="number"] { width: 100%; }
.field input, .field select { text-transform: none; letter-spacing: 0; }
.ex-flags { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 12px; }
.ex-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.status { min-height: 1.4em; font-size: 12px; color: var(--accent2); margin: 12px 0 0; line-height: 1.5; white-space: pre-line; }
.status.err { color: var(--accent); }
.midi-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 14px; font-size: 12px; }

.instructions { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 13px; color: #d9c3c6; }
.instructions summary { cursor: pointer; color: var(--dim); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 10px; }
.instructions ul { margin: 10px 0 0; padding-left: 18px; }
.instructions li { margin-bottom: 8px; line-height: 1.5; }

footer { text-align: center; color: var(--dim); font-size: 11.5px; margin-top: 28px; line-height: 1.6; }
footer a { color: var(--dim); }
footer a:hover { color: var(--accent); }

@media (max-width: 560px) {
  body { padding: 20px 10px 48px; }
  .panel { padding: 14px 10px; }
  .robot { font-size: 12px; }
  .title { font-size: 22px; }
  .seq-row, .seq-head { grid-template-columns: 52px 1fr; gap: 4px; }
  .seq-name { font-size: 9.5px; padding: 0 4px; }
  .cell { height: 34px; }
  .cell:nth-child(4n) { margin-right: 2px; }
  .cells { gap: 1px; }
  .pads { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .pad { padding: 16px 2px; }
  .pad .lbl { font-size: 10.5px; }
  #chainInput { width: 100%; }
  .key { height: 72px; }
  .key.black { height: 46px; }
}

/* ================= CircuitStomp additions ================= */
.labs-link { position: fixed; top: calc(14px + env(safe-area-inset-top, 0px)); right: 16px; color: var(--accent); text-decoration: none; font-size: 13px; z-index: 50; background: rgba(6,6,7,.8); padding: 4px 8px; border-radius: 4px; }
.labs-link:hover { text-decoration: underline; }
.head { position: relative; }
.scope { display: block; width: 100%; max-width: 420px; height: 36px; margin: 14px auto 0; opacity: .9; }

:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }

/* paint mode chips */
.paint { display: inline-flex; gap: 4px; margin-left: 6px; vertical-align: middle; }
.chip { font-family: inherit; font-size: 10.5px; text-transform: none; letter-spacing: 0; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line); background: #150a0c; color: var(--dim); cursor: pointer; }
.chip.on { border-color: var(--accent2); color: var(--accent2); }
.paint-val { display: inline-flex; align-items: center; gap: 6px; margin-left: 8px; text-transform: none; letter-spacing: 0; font-weight: 400; }
.paint-val input[type="range"] { width: 110px; margin: 0; }
.paint-val output { color: var(--accent2); min-width: 30px; display: inline-block; }

/* step extras: pitch lock + chance */
.cell .pl { position: absolute; left: 2px; top: 1px; font-size: 8.5px; line-height: 1; color: #fff; font-weight: 700; pointer-events: none; text-shadow: 0 0 2px #000; }
.cell .ch { position: absolute; left: 1px; right: 1px; bottom: 1px; height: 3px; background: repeating-linear-gradient(90deg, #000 0 2px, transparent 2px 4px); opacity: .75; pointer-events: none; }
.cell.fired { box-shadow: inset 0 0 0 2px var(--accent2); }

.brain-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; font-size: 12px; }

/* sample-only controls hidden for synth units */
.editor.synth .sample-only { display: none; }

/* slim drawers */
.drawers { margin-top: 18px; display: flex; flex-direction: column; gap: 6px; }
.drawer { border: 1px solid var(--line); border-radius: 8px; background: var(--bg-panel); }
.drawer > summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 12px; padding: 11px 14px; user-select: none; }
.drawer > summary::-webkit-details-marker { display: none; }
.drawer > summary::before { content: "+"; color: var(--accent); width: 10px; font-weight: 700; }
.drawer[open] > summary::before { content: "\2212"; }
.drawer > summary:hover .d-name { color: var(--accent); }
.d-name { font-size: 13px; font-weight: 700; letter-spacing: .5px; min-width: 96px; }
.d-sub { font-size: 11.5px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d-body { padding: 4px 16px 16px 36px; font-size: 13px; line-height: 1.6; color: #d9c3c6; }
.d-body p { margin: 8px 0; }
.btn.danger:hover { border-color: #ff0033; color: #ff0033; }

/* lessons */
.learn > p { max-width: 68ch; }
.lesson { border-top: 1px solid var(--line); padding: 2px 0; }
.lesson > summary { cursor: pointer; padding: 8px 0; color: var(--fg); font-weight: 700; font-size: 12.5px; }
.lesson > summary:hover { color: var(--accent); }
.lesson p { max-width: 68ch; }
.lesson .try { margin: 4px 0 12px; }

/* midi */
.midi-grid { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; margin: 8px 0; }
.midi-grid .field { min-width: 140px; }

/* promo */
.promo-wrap { position: relative; width: 100%; aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: #000; margin-top: 6px; }
#promoCanvas { width: 100%; height: 100%; display: block; }
.promo-play { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--accent); color: #1a0004; border: none; border-radius: 6px; font-family: inherit; font-weight: 700; font-size: 14px; padding: 12px 18px; cursor: pointer; }
.promo-play[hidden] { display: none; }
.promo-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 10px; }

.keys-table { border-collapse: collapse; font-size: 12px; }
.keys-table td { padding: 5px 14px 5px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.keys-table td:first-child { color: var(--accent2); white-space: nowrap; }

/* mini transport: appears once the main transport scrolls away */
.mini { position: fixed; left: 50%; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); display: flex; align-items: center; gap: 10px; background: rgba(14,11,12,.94); border: 1px solid var(--line); border-radius: 999px; padding: 5px 14px 5px 6px; z-index: 60; font-size: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.6); }
.mini[hidden] { display: none; }
.mini .btn { border-radius: 999px; width: 34px; padding: 6px 0; }
.mini-steps { display: inline-flex; gap: 2px; }
.mini-steps i { width: 5px; height: 10px; background: var(--line); border-radius: 1px; display: inline-block; }
.mini-steps i.now { background: var(--accent2); }

.promo-on .mini { display: none !important; }
footer .mark { color: #1d1113; font-size: 9px; letter-spacing: 3px; margin-top: 6px; user-select: none; }

@media (max-width: 560px) {
  .d-body { padding: 4px 12px 14px 14px; }
  .d-sub { display: none; }
  .paint { display: flex; margin: 6px 0 0; }
  .paint-val { margin: 6px 0 0; }
  .labs-link { font-size: 11px; position: absolute; }
}
@media (prefers-reduced-motion: reduce) {
  .blink, #recBtn.on { animation: none; }
  .robot, .title { transition: none; }
}
