/* ─────────────────────────────────────────────────────────────
   Design tokens
   ───────────────────────────────────────────────────────────── */
:root {
  /* Background scale (dark → darkest) */
  --bg-0: #0a0b0f;
  --bg-1: #14161c;
  --bg-2: #1d2029;
  --bg-3: #262932;
  --bg-4: #353844;

  /* Foreground scale */
  --fg-0: #f0f1f5;
  --fg-1: #9ba0ad;
  --fg-2: #5f6573;

  /* Accent palette */
  --accent: #ff7a1a;
  --accent-soft: rgba(255, 122, 26, 0.32);
  --sync: #1a8cff;
  --hot-cue: #8b5cf6;
  --hot-cue-soft: rgba(139, 92, 246, 0.45);
  --loop-color: #ffcc00;
  --loop-soft: rgba(255, 204, 0, 0.22);
  --kill: #ef4444;
  --rec: #dc2626;
  --success: #22c55e;
  --warn: #facc15;
  --danger: #ef4444;

  /* Borders & shadows */
  --border-1: #22252e;
  --border-2: #2d313c;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 6px 24px rgba(0, 0, 0, 0.45);
  --glow-accent: 0 0 12px rgba(255, 122, 26, 0.4);
  --glow-rec: 0 0 12px rgba(220, 38, 38, 0.55);

  /* Spacing scale */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;

  /* Radii */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;

  /* Typography */
  --font-display: "Inter", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse at top, #1b1e28 0%, var(--bg-0) 55%) fixed;
  color: var(--fg-0);
  font-family: var(--font-display);
  -webkit-font-smoothing: antialiased;
}

/* ─────────────────────────────────────────────────────────────
   App shell
   ───────────────────────────────────────────────────────────── */
.app {
  min-height: 100vh;
  padding: var(--s-5) var(--s-4);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-4);
  overflow-x: auto;
}
.app__title {
  font-size: 1.75rem;
  letter-spacing: 0.4em;
  font-weight: 600;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(255, 122, 26, 0.35);
  margin-bottom: var(--s-2);
}
.app__board {
  display: flex;
  align-items: flex-start;
  gap: var(--s-4);
}
.app__hint {
  color: var(--fg-2);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-align: center;
  max-width: 880px;
  line-height: 1.8;
  margin-top: var(--s-2);
}
.app__hint kbd {
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--fg-0);
}

/* ─────────────────────────────────────────────────────────────
   Panels
   ───────────────────────────────────────────────────────────── */
.panel {
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  box-shadow: var(--shadow-2);
}
.deck-panel {
  width: 280px;
  gap: var(--s-2);
}
.mixer-panel {
  background: var(--bg-0);
  border-color: var(--border-2);
  padding: var(--s-4);
  gap: var(--s-3);
}
.strip {
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--r-md);
  padding: var(--s-3);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  width: 190px;
  box-sizing: border-box;
}
.strip--master { width: 110px; }

/* ─────────────────────────────────────────────────────────────
   Typography helpers
   ───────────────────────────────────────────────────────────── */
.label {
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  color: var(--fg-1);
  text-transform: uppercase;
  font-weight: 600;
}
.deck-label {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--accent);
}
.master-label { color: var(--loop-color); }
.numeric {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--fg-1);
  font-size: 0.76rem;
}
.muted { color: var(--fg-2); font-size: 0.72rem; }
.error-msg {
  color: var(--danger);
  font-size: 0.76rem;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: var(--r-sm);
  padding: 4px 8px;
}

/* ─────────────────────────────────────────────────────────────
   Buttons
   ───────────────────────────────────────────────────────────── */
.btn {
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 6px 12px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: var(--bg-4);
  color: var(--fg-0);
  cursor: pointer;
  transition: background 0.14s ease, transform 0.05s ease,
              border-color 0.14s ease, box-shadow 0.14s ease;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #434756; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn--sm { padding: 4px 10px; font-size: 0.72rem; }
.btn--xs { padding: 2px 8px; font-size: 0.7rem; }

.btn--accent { background: var(--accent); }
.btn--accent:hover:not(:disabled) { background: #ff8d3a; box-shadow: var(--glow-accent); }

.btn--sync { background: var(--sync); }
.btn--sync:hover:not(:disabled) { background: #3aa0ff; }

.btn--danger { background: #5a1a1a; }
.btn--danger:hover:not(:disabled) { background: #791e1e; }

.btn--rec { background: var(--rec); box-shadow: var(--glow-rec); }
.btn--rec:hover:not(:disabled) { background: #ef3838; }

.btn--ghost {
  background: transparent;
  border-color: var(--border-2);
  color: var(--fg-1);
}
.btn--ghost:hover:not(:disabled) {
  background: var(--bg-3);
  color: var(--fg-0);
}

/* Hot-cue cell */
.btn--hot {
  padding: 6px 0;
  font-size: 0.72rem;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
}
.btn--hot.is-set {
  background: var(--hot-cue);
  border-color: var(--hot-cue);
  box-shadow: 0 0 8px var(--hot-cue-soft);
}

/* Kill toggle */
.btn--kill {
  font-size: 0.66rem;
  padding: 3px 8px;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
}
.btn--kill.is-on {
  background: var(--kill);
  border-color: var(--kill);
  color: #fff;
}

/* Pitch-mode toggle */
.btn--pitch.is-indep {
  background: var(--sync);
  border-color: var(--sync);
}

/* ─────────────────────────────────────────────────────────────
   Sliders (horizontal & vertical)
   ───────────────────────────────────────────────────────────── */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
}
input[type="range"]:focus { outline: none; }

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--bg-3);
  border-radius: 2px;
}
input[type="range"]::-moz-range-track {
  height: 4px;
  background: var(--bg-3);
  border-radius: 2px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(255, 122, 26, 0.55);
  transition: transform 0.08s ease;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.18); }
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(255, 122, 26, 0.55);
}
input[type="range"]:disabled::-webkit-slider-thumb { background: var(--fg-2); box-shadow: none; }
input[type="range"]:disabled::-moz-range-thumb { background: var(--fg-2); box-shadow: none; }

/* Vertical fader (uses writing-mode: vertical-lr; direction: rtl) */
.fader { writing-mode: vertical-lr; direction: rtl; width: 28px; }
.fader--lg { height: 200px; }
.fader--md { height: 140px; }

/* Slider rows */
.row {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  width: 100%;
  min-width: 0;
}
.row__label { width: 32px; flex-shrink: 0; }
.row__label--wide { width: 48px; }
.row__slider { flex: 1; min-width: 0; }

/* ─────────────────────────────────────────────────────────────
   Vertical fader + meter pair
   ───────────────────────────────────────────────────────────── */
.fader-stack {
  display: flex;
  align-items: flex-end;
  gap: var(--s-2);
}
.meter {
  position: relative;
  width: 8px;
  background: var(--bg-3);
  border-radius: 2px;
  overflow: hidden;
}
.meter--lg { height: 200px; }
.meter--md { height: 140px; }
.meter__fill {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: var(--success);
  transition: height 0.06s linear;
}
.meter__fill.is-warn { background: var(--warn); }
.meter__fill.is-clip { background: var(--danger); }

/* ─────────────────────────────────────────────────────────────
   Waveform
   ───────────────────────────────────────────────────────────── */
.waveform {
  position: relative;
  border-radius: var(--r-sm);
  background: var(--bg-0);
  cursor: grab;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px var(--border-1);
  transition: box-shadow 0.12s ease;
  user-select: none;
}
.waveform:active { cursor: grabbing; }
.waveform.is-bending {
  box-shadow:
    inset 0 0 0 1px var(--accent),
    0 0 18px rgba(255, 122, 26, 0.35);
}
.waveform__played {
  position: absolute; inset: 0 auto 0 0;
  background: var(--accent-soft);
  pointer-events: none;
}
.waveform__head {
  position: absolute; top: 0; bottom: 0; width: 2px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-soft);
  pointer-events: none;
}
.waveform__cue {
  position: absolute; top: 0; bottom: 0; width: 2px;
  background: var(--fg-0);
  pointer-events: none;
}
.waveform__hot {
  position: absolute; top: 0; bottom: 0; width: 2px;
  background: var(--hot-cue);
  pointer-events: none;
}
.waveform__loop {
  position: absolute; top: 0; bottom: 0;
  background: var(--loop-soft);
  border-left: 2px solid var(--loop-color);
  border-right: 2px solid var(--loop-color);
  pointer-events: none;
}

/* ─────────────────────────────────────────────────────────────
   Misc layout helpers
   ───────────────────────────────────────────────────────────── */
.deck-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: var(--s-2);
}
.bpm-display {
  flex: 1;
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--fg-1);
  font-size: 0.74rem;
}
.file-name {
  color: var(--fg-1);
  font-size: 0.74rem;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.divider {
  height: 1px;
  background: var(--border-1);
  width: 100%;
}
.transport-row {
  display: flex;
  gap: var(--s-2);
  flex-wrap: wrap;
  justify-content: center;
}
.hot-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
  width: 100%;
}
.loop-row,
.pitch-row {
  display: flex;
  align-items: center;
  gap: var(--s-1);
}

/* File input (subtle modernization) */
.file-input {
  width: 100%;
  font-size: 0.72rem;
  color: var(--fg-1);
}
.file-input::file-selector-button {
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  color: var(--fg-0);
  padding: 4px 10px;
  border-radius: var(--r-sm);
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  margin-right: var(--s-2);
  transition: background 0.14s ease;
}
.file-input::file-selector-button:hover { background: var(--bg-4); }

/* Download link */
.download-link {
  font-size: 0.7rem;
  color: var(--success);
  text-decoration: none;
}
.download-link:hover { text-decoration: underline; }

/* Crossfader sized */
.xfader { width: 240px; }

/* ─────────────────────────────────────────────────────────────
   Library
   ───────────────────────────────────────────────────────────── */
.library {
  width: min(920px, 96vw);
  background: var(--bg-1);
  border: 1px dashed var(--border-2);
  border-radius: var(--r-lg);
  padding: var(--s-3) var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.library.is-drop-active {
  border-color: var(--accent);
  background: rgba(255, 122, 26, 0.05);
  border-style: solid;
}
.library__header {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-wrap: wrap;
}
.library__add {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}
.library__hint {
  margin-left: auto;
}
.library__empty {
  color: var(--fg-2);
  font-size: 0.78rem;
  padding: var(--s-3) 0;
  text-align: center;
  letter-spacing: 0.04em;
}
.library__list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--s-2);
}
.library-entry {
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--r-md);
  padding: var(--s-2) var(--s-3);
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: grab;
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.05s ease;
}
.library-entry:hover {
  background: var(--bg-3);
  border-color: var(--border-2);
}
.library-entry:active { cursor: grabbing; transform: translateY(1px); }
.library-entry__name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--fg-0);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.library-entry__meta {
  font-size: 0.7rem;
  color: var(--fg-1);
}
.library-entry__actions {
  display: flex;
  gap: 4px;
  margin-top: 2px;
}

/* Deck panel drop-target affordance */
.deck-panel.is-drop-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 28px rgba(255, 122, 26, 0.35);
}

/* Master limiter gain-reduction meter (horizontal, fills left→right as
   reduction grows; ~0–12 dB range). */
.reduction-meter {
  position: relative;
  width: 100%;
  height: 6px;
  background: var(--bg-3);
  border-radius: 3px;
  overflow: hidden;
}
.reduction-meter__fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: linear-gradient(to right, var(--warn), var(--danger));
  transition: width 0.06s linear;
}
