/*
 * base.css — the design system: tokens, reset, and the layout primitives that every
 * milestone shares. This file is copied forward unchanged; a milestone that needs a
 * new colour or a new control shape adds a token here rather than a one-off rule in
 * app.css, so ten apps keep looking like one machine.
 *
 * The aesthetic target is studio hardware, not a web form: dark anodised panels,
 * silk-screened labels, backlit rubber pads and an LCD for anything numeric.
 */

:root {
  /* surfaces */
  --bg: #0e0f13;
  --panel: #171922;
  --panel-2: #1f2230;
  --edge: #2b2f40;

  /* type */
  --text: #e7e9f0;
  --muted: #8a90a6;

  /* signals */
  --accent: #ff5a3c;      /* transport, active step, anything "hot" */
  --accent-2: #33d1a0;    /* alternate highlight, the tutorial */
  --warn: #ffcc44;        /* the deliberately naive clock lives on this colour */

  /* one hue per track, used for pads, labels and meters alike */
  --track-1: #ff6b4a;
  --track-2: #ffc247;
  --track-3: #47d3ff;
  --track-4: #b98cff;
  --track-5: #4ade80;
  --track-6: #ff8fd0;
  --track-7: #7dd3fc;
  --track-8: #fbbf24;

  /* geometry */
  --radius: 10px;
  --gap: 10px;

  /* stacking: the tour must out-stack the manual, which must out-stack the app */
  --z-panel: 10;
  --z-modal: 900;
  --z-tour: 1000;

  /* Monospace for anything numeric (digits must not jiggle), system sans for prose.
     No webfonts anywhere: a @font-face URL would be a network request. */
  --font: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}

/* ------------------------------------------------------------------ reset */

*, *::before, *::after { box-sizing: border-box; }

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

body {
  background:
    radial-gradient(1200px 620px at 50% -160px, #1a1d29 0%, var(--bg) 62%),
    var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }
button, input, output, select { font: inherit; color: inherit; }

code {
  font-family: var(--font);
  font-size: .92em;
  color: var(--warn);
}

/* Keyboard users must always be able to see where they are. Every interactive
   control in DRUMLAB opts into this one ring; nothing suppresses it. */
:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: var(--z-modal);
  padding: 8px 12px;
  background: var(--panel-2);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  color: var(--text);
}
.skip-link:focus { left: 8px; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap;
}

/* --------------------------------------------------------------- primitives */

/*
 * A panel is a piece of the machine's front plate: a slightly lifted, slightly
 * lit slab with a hairline edge. The inset highlight along the top is what reads
 * as "metal" rather than "div".
 */
.panel {
  position: relative;
  z-index: var(--z-panel);
  background: linear-gradient(180deg, var(--panel-2) 0%, var(--panel) 100%);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .045),
    0 10px 24px rgba(0, 0, 0, .35);
}

/* Silk-screened label above a group of controls. */
.unit__label,
.readout__label,
.field__label {
  display: block;
  font: 10px/1 var(--font);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  min-height: 36px;
  background: linear-gradient(180deg, #2a2f42 0%, #1d2130 100%);
  color: var(--text);
  border: 1px solid var(--edge);
  border-radius: 8px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 2px 0 rgba(0, 0, 0, .5);
  font: 600 13px/1 var(--font-ui);
  cursor: pointer;
  transition: transform .06s ease, filter .12s ease, background-color .12s ease;
}
.btn:hover { filter: brightness(1.14); }
.btn:active { transform: translateY(1px); box-shadow: inset 0 2px 4px rgba(0, 0, 0, .55); }
.btn[disabled] { opacity: .45; cursor: default; }

.btn__glyph { font-size: 11px; line-height: 1; }

.btn--ghost {
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}
.btn--ghost:hover { color: var(--text); }

.btn--primary {
  background: linear-gradient(180deg, #3ee0ac 0%, #23a37c 100%);
  border-color: #1d7f61;
  color: #06110d;
}

.btn--round {
  width: 36px;
  padding: 0;
  justify-content: center;
  border-radius: 50%;
  font: 700 16px/1 var(--font-ui);
}

/* A chip is a status legend, not a control. */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, .03);
  font: 11px/1 var(--font);
  letter-spacing: .06em;
  color: var(--muted);
}
.chip--warn {
  border-color: rgba(255, 204, 68, .5);
  background: rgba(255, 204, 68, .1);
  color: var(--warn);
}
/* The healthy counterpart, added in M02 when the clock finally has a good state
   to report. The same chip switches between the two colours in the Timing Lab. */
.chip--ok {
  border-color: rgba(51, 209, 160, .5);
  background: rgba(51, 209, 160, .1);
  color: var(--accent-2);
}

/*
 * A two-position rocker switch, built out of two real radio inputs sharing a name.
 * The inputs are made transparent rather than hidden: `display:none` would take them
 * out of the tab order and out of the accessibility tree, and then arrow-key
 * selection, the focus ring and the screen-reader announcement all have to be
 * rebuilt by hand. Here the platform still owns every one of those.
 */
.switch {
  display: inline-flex;
  background: #0a0c11;
  border: 1px solid var(--edge);
  border-radius: 8px;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, .8);
  overflow: hidden;
}

.switch__opt { position: relative; display: inline-flex; }

.switch__opt input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch__face {
  padding: 8px 14px;
  font: 600 11px/1 var(--font);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  transition: color .12s ease, background-color .12s ease;
}

.switch__opt input:checked + .switch__face {
  background: linear-gradient(180deg, #2a2f42 0%, #1d2130 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08);
  color: var(--text);
}
/* The engaged position is colour-coded to match the status chip beside it: the
   correct clock reads green, the deliberately naive one reads amber. */
.switch__opt input[value="lookahead"]:checked + .switch__face { color: var(--accent-2); }
.switch__opt input[value="naive"]:checked + .switch__face { color: var(--warn); }

/* The ring goes inside, because the switch clips its children to its own radius. */
.switch__opt input:focus-visible + .switch__face {
  outline: 2px solid var(--accent-2);
  outline-offset: -2px;
}

/*
 * The LCD. Numbers live here: monospace, tabular figures, faint scan glow. It is a
 * readout, never an input — that separation is what makes hardware legible.
 */
.lcd {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  padding: 6px 10px;
  min-width: 92px;
  justify-content: center;
  background: #0a0c11;
  border: 1px solid #000;
  border-radius: 6px;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, .8);
  font: 600 16px/1.2 var(--font);
  font-variant-numeric: tabular-nums;
  color: var(--accent-2);
  text-shadow: 0 0 12px rgba(51, 209, 160, .35);
}
.lcd--wide { min-width: 190px; font-size: 13px; }
.lcd__unit { font-size: 10px; letter-spacing: .1em; color: var(--muted); text-shadow: none; }
/* An LCD wraps its own contents at its peril: "100 %" breaking after "100" turns a
   readout into two half-numbers stacked on top of each other. */
.lcd__value, .lcd__unit { white-space: nowrap; }

/*
 * The slider is a real <input type="range">. Rotating or restyling one is fine;
 * replacing it with divs is not — arrow keys, Shift+arrow, focus and screen-reader
 * support all come free from the platform and cost 200 lines of ARIA to rebuild.
 */
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 26px;
  background: transparent;
  cursor: pointer;
}
.slider::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(180deg, #05070b, #14172180);
  border: 1px solid #000;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, .9);
}
.slider::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: #05070b;
  border: 1px solid #000;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  margin-top: -8px;
  width: 16px;
  height: 22px;
  border-radius: 4px;
  background: linear-gradient(180deg, #f4f6ff 0%, #aab1c8 48%, #6f778f 52%, #333a4d 100%);
  border: 1px solid #0a0c11;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .6);
}
.slider::-moz-range-thumb {
  width: 16px;
  height: 22px;
  border-radius: 4px;
  background: linear-gradient(180deg, #f4f6ff 0%, #6f778f 52%, #333a4d 100%);
  border: 1px solid #0a0c11;
}

.field { display: inline-flex; flex-direction: column; gap: 5px; }
.field__input {
  width: 110px;
  padding: 7px 9px;
  background: #0a0c11;
  border: 1px solid var(--edge);
  border-radius: 6px;
  color: var(--text);
  font: 14px/1 var(--font);
  font-variant-numeric: tabular-nums;
}

/*
 * Inline coach mark (SPEC §5c). One sentence, one tap, no modal. Built by
 * DM.UI.coach() so that every milestone's explanations look and behave the same.
 */
.coach {
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, .04);
  color: var(--muted);
  font: 700 11px/1 var(--font-ui);
  cursor: pointer;
}
.coach:hover { color: var(--accent-2); border-color: var(--accent-2); }

/* Transient one-line feedback: "Demo beat loaded". Never used for errors. */
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: var(--z-modal);
  padding: 9px 16px;
  background: var(--panel-2);
  border: 1px solid var(--edge);
  border-radius: 999px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .55);
  font: 13px/1 var(--font-ui);
  color: var(--text);
}

/* ============================================== added in M03: mixer primitives */

/*
 * THE KNOB. Written once here, and it is the deliverable that serves the remaining
 * seven milestones: after this, exposing a new parameter is one call to DM.UI.knob().
 * Every filter cutoff in M06, every parameter lock in M07 and every automation lane
 * in M10 is this control.
 *
 * The moving part you can see is a <span>; the control you can USE is a real
 * <input type="range"> laid over it at opacity 0. That split is the whole trick.
 * Arrow keys, Home/End, the focus ring, the value announcement and the "slider,
 * 62 percent" a screen reader reads out all come from the platform for free, and
 * rebuilding them by hand is 200 lines of ARIA that will be subtly wrong. The div
 * only has to look like anodised aluminium.
 *
 * --turn is 0..1 and is written by ui.js on every input event: the conic ring draws
 * the value and the pointer rotates through the conventional 270 degrees of travel,
 * from 7:30 round to 4:30.
 */
.knob {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 46px;
}

.knob__label {
  font: 9px/1 var(--font);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.knob__body { position: relative; width: 38px; height: 38px; }

/* The input sits FIRST in the DOM so the dial can be styled as its sibling on
   focus — and above it in z-order so it still receives the pointer. */
.knob__input {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: ns-resize;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}
.knob__input:disabled { cursor: not-allowed; }

.knob__dial {
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 28%, #434a61 0%, #1c202c 60%, #0d0f16 100%);
  border: 1px solid var(--edge);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .1), 0 3px 6px rgba(0, 0, 0, .6);
}

/* The value ring, drawn as a conic gradient and masked into an arc. `from 225deg`
   puts 0 at 7:30, and the sweep stops at 270deg, so the last quarter is the gap at
   the bottom that tells you which way is "off". */
.knob__dial::before {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  background: conic-gradient(from 225deg,
    var(--accent-2) 0 calc(var(--turn, 0) * 270deg),
    rgba(255, 255, 255, .09) calc(var(--turn, 0) * 270deg) 270deg,
    transparent 270deg);
  -webkit-mask: radial-gradient(circle, transparent 0 61%, #000 62%);
  mask: radial-gradient(circle, transparent 0 61%, #000 62%);
}

.knob__pointer {
  position: absolute;
  inset: 0;
  transform: rotate(calc(-135deg + var(--turn, 0) * 270deg));
}
.knob__pointer::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 4px;
  width: 2px;
  height: 11px;
  margin-left: -1px;
  border-radius: 1px;
  background: var(--text);
  box-shadow: 0 0 6px rgba(231, 233, 240, .55);
}

.knob__value {
  font: 10px/1 var(--font);
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* The ring belongs on the thing you can see, not on the invisible input. */
.knob__input:focus-visible ~ .knob__dial {
  outline: 2px solid var(--accent-2);
  outline-offset: 3px;
}

.knob.is-disabled { opacity: .35; }
.knob.is-disabled .knob__pointer::after { background: var(--muted); box-shadow: none; }

/*
 * THE METER. An AnalyserNode is a tap: it passes audio through untouched and reading
 * it changes nothing, which is why one can sit in the middle of every channel.
 *
 * The bar is a fixed full-width gradient that is CLIPPED rather than scaled, so
 * "amber" always means the same level instead of sliding around as the bar moves.
 * The scale is decibels, floor -48 dB — a linear meter spends nine tenths of its
 * travel on the top 20 dB and reads as broken.
 *
 * The thin bright line is PEAK; the filled bar is RMS. They are different questions:
 * RMS is roughly how loud it sounds, peak is whether it will clip. A kick can read
 * halfway on RMS and still be pinning the peak.
 */
.meter {
  position: relative;
  overflow: hidden;
  width: 100%;
  min-width: 56px;
  height: 10px;
  background: #0a0c11;
  border: 1px solid #000;
  border-radius: 3px;
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, .85);
}

.meter__rms {
  position: absolute;
  inset: 0;
  clip-path: inset(0 100% 0 0);
  background: linear-gradient(90deg,
    #1f9c76 0%, var(--accent-2) 55%, var(--warn) 82%, var(--accent) 100%);
}

.meter__peak {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 2px;
  background: var(--text);
  transform: translateX(-4px);
  box-shadow: 0 0 6px rgba(231, 233, 240, .6);
}

.meter--master { height: 14px; min-width: 170px; }

/*
 * An LED is a lamp that latches, not a button that does something — but it is built
 * as a <button> because clicking it resets the latch, and a clickable thing has to be
 * focusable and operable from the keyboard.
 */
.led {
  padding: 5px 9px;
  border: 1px solid var(--edge);
  border-radius: 4px;
  background: rgba(255, 255, 255, .03);
  color: var(--muted);
  font: 700 9px/1 var(--font);
  letter-spacing: .14em;
  cursor: pointer;
}
.led--clip.is-lit {
  background: linear-gradient(180deg, #ff7a5f 0%, #d33c22 100%);
  border-color: #8f2a17;
  color: #140603;
  box-shadow: 0 0 16px rgba(255, 90, 60, .65);
}
.led--gr.is-lit {
  border-color: rgba(255, 204, 68, .6);
  background: rgba(255, 204, 68, .12);
  color: var(--warn);
}

/* A channel button: momentary-looking, latching in behaviour. M is amber because a
   mute is a warning state; S is green because a solo is a listening state. */
.chanbtn {
  width: 28px;
  height: 26px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--edge);
  border-radius: 5px;
  background: linear-gradient(180deg, #2a2f42 0%, #1d2130 100%);
  color: var(--muted);
  font: 700 11px/1 var(--font);
  cursor: pointer;
}
.chanbtn:hover { filter: brightness(1.2); }
.chanbtn--mute.is-on {
  background: linear-gradient(180deg, #ffd76a 0%, #d99b12 100%);
  border-color: #9b6f08;
  color: #180f00;
  box-shadow: 0 0 12px rgba(255, 204, 68, .5);
}
.chanbtn--solo.is-on {
  background: linear-gradient(180deg, #4ee7b4 0%, #1d9c74 100%);
  border-color: #157055;
  color: #04150f;
  box-shadow: 0 0 12px rgba(51, 209, 160, .5);
}

/* A short LCD, for the numbers that live inside a channel strip. Wide enough for
   "120 %" beside "+1.6 dB", because those two numbers are the same fader read on the
   two scales that matter and splitting them across a wrap would defeat the point. */
.lcd--tiny { min-width: 108px; padding: 4px 7px; font-size: 11px; }

/* The bank selector: the same rocker as the clock switch, with room for five. */
.switch--wide { flex-wrap: wrap; }
.switch--wide .switch__face { padding: 7px 10px; letter-spacing: .08em; }
.switch--wide .switch__opt input:checked + .switch__face { color: var(--accent-2); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
  .btn { transition: none; }
  .switch__face { transition: none; }
  .chanbtn { transition: none; }
}
