/* ============================================================
   Audio Toolkit — Professional Audio Measurement Web App
   Dark technical aesthetic: cool slate, cyan accent, monospace data
   ============================================================ */

:root {
  --font-body: 'General Sans', 'Helvetica Neue', sans-serif;
  --font-mono: 'JetBrains Mono', 'Menlo', monospace;

  --text-xs: clamp(0.7rem, 0.65rem + 0.25vw, 0.8rem);
  --text-sm: clamp(0.8rem, 0.75rem + 0.25vw, 0.875rem);
  --text-base: clamp(0.875rem, 0.85rem + 0.15vw, 1rem);
  --text-lg: clamp(1rem, 0.95rem + 0.3vw, 1.25rem);
  --text-xl: clamp(1.25rem, 1.1rem + 0.5vw, 1.5rem);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --transition: 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---- Dark Theme (default) ---- */
[data-theme="dark"] {
  --bg: #0c0e12;
  --surface: #13161c;
  --surface-2: #1a1d25;
  --surface-3: #22262f;
  --border: #2a2f3a;
  --border-hover: #3a4050;
  --text: #e0e2e8;
  --text-muted: #8a8f9c;
  --text-faint: #555a66;
  --accent: #00d4aa;
  --accent-dim: rgba(0, 212, 170, 0.12);
  --accent-hover: #00f0c0;
  --red: #ff4060;
  --yellow: #ffc040;
  --green: #40d060;
  --meter-bg: #0a0c10;
  --flash: #ffffff;
}

/* ---- Light Theme ---- */
[data-theme="light"] {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --surface-3: #eef0f4;
  --border: #d0d4dc;
  --border-hover: #b0b6c4;
  --text: #1a1c22;
  --text-muted: #5a5e6a;
  --text-faint: #9a9ea8;
  --accent: #008866;
  --accent-dim: rgba(0, 136, 102, 0.1);
  --accent-hover: #006a50;
  --red: #cc2040;
  --yellow: #cc9000;
  --green: #20a040;
  --meter-bg: #e4e6ec;
  --flash: #1a1c22;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
body {
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
button { cursor: pointer; font: inherit; border: none; background: none; color: inherit; }
input { font: inherit; color: inherit; }

/* ---- Header ---- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  overflow-x: auto;
}
@media (max-width: 600px) {
  .header-inner {
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
  }
  .logo-text { display: none; }
  .tab {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-xs);
  }
}
.logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--accent);
  flex-shrink: 0;
}
.logo-text {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

/* ---- Tabs ---- */
.tab-nav {
  display: flex;
  gap: var(--space-1);
}
.tab {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-muted);
  border-radius: var(--radius-md);
  transition: all var(--transition);
  white-space: nowrap;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active {
  color: var(--accent);
  background: var(--accent-dim);
}
.tab svg { flex-shrink: 0; }

/* ---- Panels ---- */
.app-main {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-6);
}
.panel { display: none; }
.panel.active { display: block; }
.panel-header { margin-bottom: var(--space-6); }
.panel-header h1 {
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.panel-desc {
  color: var(--text-muted);
  font-size: var(--text-sm);
  margin-top: var(--space-1);
  max-width: 65ch;
}

/* ---- Generator Grid ---- */
.gen-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-3);
}
@media (max-width: 1200px) {
  .gen-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .gen-grid { grid-template-columns: 1fr; }
  .gen-viz-card { grid-column: span 1; }
}
.gen-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
}
.gen-card-head {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}
.gen-desc {
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.4;
  margin-bottom: var(--space-2);
}
.gen-fields {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  flex: 1;
}
.gen-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.gen-row label {
  font-size: 11px;
  color: var(--text-faint);
  width: 54px;
  flex-shrink: 0;
}
.gen-slider { flex: 1; height: 4px; }
.gen-val {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  min-width: 32px;
  text-align: right;
}
.gen-select {
  flex: 1;
  padding: 5px 8px;
  font-size: 11px;
  font-family: var(--font-mono);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}
.gen-select:focus { border-color: var(--accent); }
.gen-play {
  margin-top: var(--space-2);
  padding: var(--space-2);
  font-size: var(--text-xs);
}
.gen-info {
  margin-top: var(--space-2);
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  text-align: center;
}
.gen-info strong { color: var(--accent); }
.gen-progress {
  height: 3px;
  margin-top: var(--space-2);
  background: var(--surface-3);
  border-radius: 2px;
  overflow: hidden;
}
.gen-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0;
  transition: width 100ms linear;
}
/* Polarity Check */
.polarity-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4);
  background: var(--surface-2);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-2);
}
.polarity-icon {
  font-size: 36px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-faint);
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 2px solid var(--border);
}
.polarity-icon.pass { color: var(--green); border-color: var(--green); background: rgba(64,208,96,0.1); }
.polarity-icon.fail { color: var(--red); border-color: var(--red); background: rgba(255,64,96,0.1); }
.polarity-icon.testing { color: var(--accent); border-color: var(--accent); }
.polarity-text {
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--text-muted);
  text-align: center;
}

.gen-viz-card canvas {
  width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
}

/* ---- Controls ---- */
.control-group { margin-bottom: var(--space-5); }
.control-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}
.control-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.input-unit {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  flex-shrink: 0;
}
.num-input {
  width: 60px;
  background: transparent;
  border: none;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  text-align: right;
  outline: none;
  -moz-appearance: textfield;
}
.num-input::-webkit-inner-spin-button,
.num-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.unit {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-faint);
}

/* ---- Slider ---- */
.slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  outline: none;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 2px var(--accent);
  transition: transform var(--transition);
}
.slider::-webkit-slider-thumb:hover { transform: scale(1.15); }
.slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 2px var(--accent);
}

/* ---- Presets ---- */
.freq-presets, .fps-btns {
  display: flex;
  gap: var(--space-1);
  margin-top: var(--space-2);
  flex-wrap: wrap;
}
.preset {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.preset:hover {
  border-color: var(--border-hover);
  background: var(--surface-2);
}
.preset.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

/* ---- Waveform buttons ---- */
.waveform-btns {
  display: flex;
  gap: var(--space-2);
}
.wave-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  transition: all var(--transition);
}
.wave-btn:hover { border-color: var(--border-hover); background: var(--surface-2); }
.wave-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}
.wave-btn svg { color: inherit; }

/* ---- Play Button ---- */
.btn-play {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-base);
  font-weight: 600;
  background: var(--accent);
  color: var(--bg);
  border-radius: var(--radius-md);
  transition: all var(--transition);
  margin-top: var(--space-4);
}
.btn-play:hover { background: var(--accent-hover); }
.btn-play.playing {
  background: var(--red);
}
.btn-play.playing:hover {
  background: #ff5070;
}

/* ---- Visualization Cards ---- */
.tone-viz {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.viz-card, .meter-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.viz-header {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: var(--space-3);
}
.viz-card canvas, .meter-card canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-sm);
}
.meter-container { position: relative; }
.meter-labels {
  display: flex;
  justify-content: space-between;
  padding: var(--space-1) 0 0;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-faint);
}
.meter-readout {
  text-align: center;
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--accent);
  margin-top: var(--space-2);
}

/* ============================================================
   A/V SYNC TEST
   ============================================================ */
.sync-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: var(--space-6);
  align-items: start;
}
@media (max-width: 1000px) {
  .sync-layout { grid-template-columns: 1fr; }
}

.sync-main-area {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.sync-display-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  display: flex;
  justify-content: center;
}
.sync-display-card canvas {
  width: 100%;
  max-width: 800px;
  height: auto;
  display: block;
  border-radius: var(--radius-sm);
}
.sync-controls-row {
  display: flex;
  gap: var(--space-4);
  align-items: flex-end;
  flex-wrap: wrap;
}
@media (max-width: 600px) {
  .sync-controls-row {
    flex-direction: column;
    align-items: stretch;
  }
  .sync-play { width: 100%; }
}
.control-group.compact { margin-bottom: 0; }
.sync-play { width: auto; padding: var(--space-3) var(--space-8); margin-top: 0; }

/* ---- Info Panel ---- */
.sync-info-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.info-card h3 {
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: var(--space-3);
  color: var(--text);
}
.instructions {
  list-style: none;
  counter-reset: step;
}
.instructions li {
  counter-increment: step;
  padding-left: var(--space-6);
  position: relative;
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-2);
  line-height: 1.5;
}
.instructions li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  width: 20px;
  height: 20px;
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 50%;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  top: 1px;
}
.info-text {
  font-size: var(--text-sm);
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: var(--space-3);
}

/* ---- Offset Table ---- */
.offset-table {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}
.offset-header {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.offset-rows {
  max-height: 200px;
  overflow-y: auto;
}
.offset-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-top: 1px solid var(--border);
}
.offset-row.zero {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}
.offset-row .early { color: var(--yellow); }
.offset-row .late { color: var(--red); }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ---- Focus styles ---- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ============================================================
   R128 LOUDNESS METER — Compact Dashboard
   ============================================================ */

/* Top bar */
.r128-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
  gap: var(--space-3);
}
.r128-title {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
}
.r128-title h1 {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.r128-subtitle {
  font-size: var(--text-xs);
  color: var(--text-faint);
  font-family: var(--font-mono);
}
.r128-controls {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.r128-play {
  padding: var(--space-2) var(--space-5);
  font-size: var(--text-sm);
  margin-top: 0;
}
.btn-reset {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all var(--transition);
}
.btn-reset:hover {
  border-color: var(--border-hover);
  color: var(--text);
  background: var(--surface-2);
}
.r128-stat {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-muted);
}

/* Grid: 5 cells in 2 rows */
.r128-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 2fr 2fr 1.5fr;
  gap: var(--space-3);
  height: calc(100vh - 160px);
  min-height: 400px;
  max-height: 700px;
}
@media (max-width: 1300px) {
  .r128-grid {
    grid-template-columns: 2fr 1fr 2fr;
    height: auto;
    max-height: none;
  }
}
@media (max-width: 800px) {
  .r128-grid {
    grid-template-columns: 1fr 1fr;
    height: auto;
    max-height: none;
  }
}
@media (max-width: 500px) {
  .r128-grid {
    grid-template-columns: 1fr;
    height: auto;
    max-height: none;
  }
}

/* Cell */
.r128-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}
.r128-cell-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--space-2);
  flex-shrink: 0;
}
.r128-cell-head span:first-child {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.r128-unit {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-faint);
}
.r128-cell canvas {
  width: 100%;
  flex: 1;
  min-height: 0;
  border-radius: var(--radius-sm);
}

/* Readouts */
.r128-readouts {
  display: flex;
  gap: var(--space-3);
  justify-content: center;
  margin-top: var(--space-2);
  flex-shrink: 0;
}
.r128-rd {
  display: flex;
  align-items: baseline;
  gap: var(--space-1);
}
.r128-rd-l {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
}
.r128-rd-v {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 600;
  color: #5599dd;
}
.r128-rd-main .r128-rd-v {
  font-size: var(--text-base);
  color: #66aaff;
}
.r128-tp-val { color: #ddaa20; }

/* FFT + Correlation span full second row */
.r128-fft { grid-column: span 3; }
.r128-corr { grid-column: span 2; justify-content: flex-start; }
.r128-corr canvas { flex: 0; height: auto; }
@media (max-width: 1300px) {
  .r128-fft { grid-column: span 2; }
  .r128-corr { grid-column: span 1; }
}
@media (max-width: 800px) {
  .r128-fft { grid-column: span 1; }
  .r128-corr { grid-column: span 1; }
}

/* Stats */
.r128-stats {
  margin-top: var(--space-2);
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.r128-stat-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-family: var(--font-mono);
}
.r128-stat-row:last-child { border-bottom: none; }
.r128-stat-row span:first-child { color: var(--text-faint); }
.r128-stat-row span:last-child { color: var(--text-muted); font-weight: 500; }
.r128-target span:last-child { color: var(--accent); }

/* ============================================================
   RECHNER
   ============================================================ */
.calc-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
  align-items: start;
}
@media (max-width: 1200px) {
  .calc-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
  .calc-grid { grid-template-columns: 1fr; }
}
.calc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.calc-card-head {
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: var(--space-1);
}
.calc-desc {
  font-size: var(--text-xs);
  color: var(--text-faint);
  margin-bottom: var(--space-4);
  line-height: 1.4;
}
.calc-settings {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}
.calc-setting {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  flex: 1;
  min-width: 120px;
}
.calc-setting label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
}
.calc-setting select, .calc-select-full {
  padding: 5px 8px;
  font-size: 11px;
  font-family: var(--font-mono);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  width: 100%;
}
.calc-setting select:focus, .calc-select-full:focus { border-color: var(--accent); }

.calc-fields {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.calc-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.calc-field label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
}
.calc-ref {
  font-weight: 400;
  color: var(--text-faint);
  font-size: 10px;
}
.calc-input-wrap {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  overflow: hidden;
  transition: border-color var(--transition);
}
.calc-input-wrap:focus-within { border-color: var(--accent); }
.calc-input-wrap input {
  flex: 1;
  padding: 6px 8px;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text);
  min-width: 0;
}
.calc-unit {
  padding: 0 8px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-faint);
  flex-shrink: 0;
}

/* Results */
.calc-results {
  margin-top: var(--space-4);
  border-top: 1px solid var(--border);
  padding-top: var(--space-3);
}
.calc-result-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-family: var(--font-mono);
}
.calc-result-row:last-child { border-bottom: none; }
.calc-result-row span:first-child { color: var(--text-faint); }
.calc-result-row span:last-child { color: var(--accent); font-weight: 500; }

/* ============================================================
   MIDI MONITOR
   ============================================================ */
.midi-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
  gap: var(--space-3);
}
.midi-controls {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.midi-status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--text-muted);
}
.midi-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
}
.midi-status-dot.online { background: var(--green); }
.midi-status-dot.offline { background: var(--text-faint); }

.midi-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: var(--space-4);
  height: calc(100vh - 160px);
  min-height: 400px;
}
@media (max-width: 800px) {
  .midi-layout { grid-template-columns: 1fr; height: auto; }
}

/* Sidebar */
.midi-sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  overflow-y: auto;
}
.midi-devices {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.midi-no-device {
  font-size: var(--text-xs);
  color: var(--text-faint);
  line-height: 1.5;
  padding: var(--space-2) 0;
}
.midi-device-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}
.midi-device-item:hover { border-color: var(--border-hover); background: var(--surface-2); }
.midi-device-item.active { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.midi-device-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}

/* Filters */
.midi-filters {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.midi-filter-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-muted);
  cursor: pointer;
}
.midi-filter-item input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
}

/* Activity */
.midi-activity {
  display: flex;
  flex-direction: column;
}
.midi-act-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-family: var(--font-mono);
}
.midi-act-row:last-child { border-bottom: none; }
.midi-act-row span:first-child { color: var(--text-faint); }
.midi-act-row span:last-child { color: var(--text); font-weight: 500; }

/* Log */
.midi-log-area {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.midi-log-header {
  display: grid;
  grid-template-columns: 80px 100px 40px 110px 1fr 120px;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--surface-2);
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.midi-log {
  flex: 1;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 11px;
}
.midi-log-empty {
  padding: var(--space-8);
  text-align: center;
  color: var(--text-faint);
  font-size: var(--text-sm);
}
.midi-row {
  display: grid;
  grid-template-columns: 80px 100px 40px 110px 1fr 120px;
  gap: var(--space-2);
  padding: 3px var(--space-3);
  border-bottom: 1px solid var(--border);
  align-items: center;
  transition: background 80ms;
}
.midi-row:hover { background: var(--surface-2); }
.midi-row .time { color: var(--text-faint); }
.midi-row .port { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.midi-row .ch { color: var(--accent); font-weight: 600; }
.midi-row .type { font-weight: 500; }
.midi-row .type.note-on { color: var(--green); }
.midi-row .type.note-off { color: var(--text-faint); }
.midi-row .type.cc { color: #66aaff; }
.midi-row .type.pb { color: var(--yellow); }
.midi-row .type.pgm { color: var(--purple, #a86fdf); }
.midi-row .type.at { color: var(--orange, #fdab43); }
.midi-row .type.sys { color: var(--text-faint); }
.midi-row .data { color: var(--text); }
.midi-row .hex { color: var(--text-faint); font-size: 10px; }

/* Note Generator */
.midigen-controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.midigen-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.midigen-label {
  font-size: 11px;
  color: var(--text-faint);
  width: 62px;
  flex-shrink: 0;
}
.midigen-select {
  flex: 1;
  padding: 4px 6px;
  font-size: 11px;
  font-family: var(--font-mono);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}
.midigen-select:focus { border-color: var(--accent); }
.midigen-select-sm { flex: 0; width: 56px; }
.midigen-note-pick {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex: 1;
}
.midigen-notenum {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  min-width: 24px;
  text-align: right;
}
.midigen-slider { flex: 1; height: 4px; }
.midigen-val {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  min-width: 30px;
  text-align: right;
}
.midigen-send {
  width: 100%;
  padding: var(--space-2);
  font-size: var(--text-xs);
  margin-top: var(--space-1);
}

/* Mini Keyboard */
.midigen-keyboard {
  display: flex;
  position: relative;
  height: 48px;
  margin-top: var(--space-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.mk-white {
  flex: 1;
  background: #ccc;
  border: 1px solid var(--border);
  border-radius: 0 0 3px 3px;
  cursor: pointer;
  transition: background 80ms;
  min-width: 0;
}
.mk-white:hover { background: #ddd; }
.mk-white.active { background: var(--accent); }
.mk-black {
  position: absolute;
  width: 10px;
  height: 30px;
  background: #222;
  border-radius: 0 0 2px 2px;
  cursor: pointer;
  z-index: 2;
  transition: background 80ms;
}
.mk-black:hover { background: #444; }
.mk-black.active { background: var(--accent); }
[data-theme="light"] .mk-white { background: #fff; }
[data-theme="light"] .mk-white:hover { background: #eee; }
[data-theme="light"] .mk-black { background: #333; }

/* ============================================================
   SPATIAL AUDIO
   ============================================================ */
.sp-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  align-items: start;
}
@media (max-width: 1000px) { .sp-layout { grid-template-columns: 1fr; } }
.sp-map-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
}
.sp-map-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-2);
}
.sp-map-title {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.sp-map-area canvas { width: 100%; height: auto; border-radius: var(--radius-sm); }
.sp-map-legend {
  display: flex;
  gap: var(--space-4);
  margin-top: var(--space-2);
  font-size: 10px;
  color: var(--text-faint);
  align-items: center;
}
.sp-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}
.sp-dot-ear { background: var(--accent); }
.sp-dot-spk { background: #66aaff; }
.sp-dot-top { background: #aa77ee; }

.sp-controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}
.sp-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
}
.sp-card-head {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

/* Delay channel list */
.sp-dist-head, .sp-dist-row {
  display: grid;
  grid-template-columns: 60px 1fr 80px 80px;
  gap: var(--space-2);
  align-items: center;
  padding: 3px 0;
  font-size: 11px;
  font-family: var(--font-mono);
}
.sp-dist-head {
  color: var(--text-faint);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10px;
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--space-1);
  margin-bottom: var(--space-1);
}
.sp-dist-row { border-bottom: 1px solid var(--border); }
.sp-dist-row:last-child { border-bottom: none; }
.sp-dist-row .sp-dist-ch { color: var(--text-muted); font-weight: 600; }
.sp-dist-row input {
  width: 100%;
  padding: 3px 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  -moz-appearance: textfield;
}
.sp-dist-row input::-webkit-inner-spin-button { -webkit-appearance: none; }
.sp-dist-row input:focus { border-color: var(--accent); }
.sp-dist-row .sp-dist-delay { color: var(--accent); }
.sp-dist-row .sp-dist-smp { color: var(--text-faint); }
.sp-setting {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
  font-size: 11px;
  color: var(--text-faint);
}
.sp-setting .gen-select { flex: 1; }

/* Channel test buttons */
.sp-test-controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.sp-test-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.sp-test-row label {
  font-size: 11px;
  color: var(--text-faint);
  width: 50px;
  flex-shrink: 0;
}
.sp-channel-btns {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}
.sp-ch-btn {
  padding: 6px 10px;
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  background: transparent;
  color: var(--text-muted);
}
.sp-ch-btn:hover { border-color: var(--border-hover); background: var(--surface-2); }
.sp-ch-btn.playing { border-color: var(--accent); color: var(--bg); background: var(--accent); }
.sp-ch-btn.lfe { color: var(--yellow); }
.sp-ch-btn.top { color: #aa77ee; }

/* Reference table */
.sp-ref-table { font-size: 11px; font-family: var(--font-mono); }
.sp-ref-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.sp-ref-row:last-child { border-bottom: none; }
.sp-ref-row span:first-child { color: var(--text-faint); }
.sp-ref-row span:last-child { color: var(--text-muted); font-weight: 500; }
.sp-ref-note span:last-child { color: var(--yellow); }

/* Wizard */
.sp-wizard { display: flex; flex-direction: column; gap: var(--space-2); }
.sp-wiz-step-select {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: 11px; color: var(--text-faint); margin-bottom: var(--space-1);
}
.sp-wiz-step-select label { width: 40px; flex-shrink: 0; }
.sp-wiz-step-select .gen-select { flex: 1; }
.sp-wiz-status {
  font-family: var(--font-mono); font-size: 11px; color: var(--text-muted);
  padding: var(--space-2); background: var(--surface-2); border-radius: var(--radius-sm); text-align: center;
}
.sp-wiz-steps { display: flex; gap: 2px; flex-wrap: wrap; }
.sp-wiz-step-dot {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-family: var(--font-mono); font-weight: 600;
  border: 1px solid var(--border); color: var(--text-faint); background: transparent;
  cursor: pointer; transition: all var(--transition);
}
.sp-wiz-step-dot.active { border-color: var(--accent); color: var(--bg); background: var(--accent); }
.sp-wiz-step-dot.done { border-color: var(--green); color: var(--green); background: rgba(64,208,96,0.1); }
.sp-wiz-buttons {
  display: flex; gap: var(--space-2); margin-top: var(--space-1);
}
.sp-wiz-buttons .gen-play { margin-top: 0; }
.sp-wiz-detail {
  background: var(--surface-2); border-radius: var(--radius-md);
  padding: var(--space-3); display: none; flex-direction: column; gap: var(--space-2);
}
.sp-wiz-detail.visible { display: flex; }
.sp-wiz-ch {
  font-family: var(--font-mono); font-size: var(--text-lg); font-weight: 700; color: var(--accent);
}
.sp-wiz-instruction {
  font-size: var(--text-xs); color: var(--text-muted); line-height: 1.5;
}
.sp-wiz-target {
  font-family: var(--font-mono); font-size: var(--text-sm); font-weight: 600;
  color: var(--yellow); background: rgba(255,192,64,0.08);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); text-align: center;
}
.sp-wiz-note-field {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: 11px; color: var(--text-faint);
}
.sp-wiz-note-field label { flex-shrink: 0; }
.sp-wiz-note-input {
  flex: 1; padding: 5px 8px; font-family: var(--font-mono); font-size: 11px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); outline: none;
}
.sp-wiz-note-input:focus { border-color: var(--accent); }

/* Protocol */
.sp-wiz-protocol { display: none; }
.sp-wiz-protocol.visible { display: block; }
.sp-proto-row {
  display: grid; grid-template-columns: 50px 1fr 80px;
  gap: var(--space-2); padding: 3px 0; border-bottom: 1px solid var(--border);
  font-size: 11px; font-family: var(--font-mono);
}
.sp-proto-row:last-child { border-bottom: none; }
.sp-proto-row span:first-child { color: var(--text-muted); font-weight: 600; }
.sp-proto-row span:nth-child(2) { color: var(--text-faint); }
.sp-proto-row span:last-child { color: var(--accent); text-align: right; }
.sp-proto-row.fail span:last-child { color: var(--red); }

/* ============================================================
   TIMECODE
   ============================================================ */
.tc-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}
@media (max-width: 800px) {
  .tc-layout { grid-template-columns: 1fr; }
}
.tc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.tc-card-head {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: var(--space-4);
  align-self: flex-start;
}
.tc-display {
  font-family: var(--font-mono);
  font-size: clamp(2.5rem, 6vw, 4.5rem);
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--accent);
  background: var(--meter-bg);
  padding: var(--space-4) var(--space-6);
  border-radius: var(--radius-md);
  text-align: center;
  width: 100%;
  margin-bottom: var(--space-2);
}
.tc-display-reader { color: var(--text-faint); }
.tc-display-reader.active { color: var(--accent); }
.tc-sub {
  font-size: var(--text-xs);
  color: var(--text-faint);
  margin-bottom: var(--space-4);
  font-family: var(--font-mono);
}
.tc-fields {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.tc-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.tc-row label {
  font-size: 11px;
  color: var(--text-faint);
  width: 80px;
  flex-shrink: 0;
}
.tc-row .gen-select { flex: 1; }
.tc-start-inputs {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
}
.tc-num {
  width: 42px;
  padding: 5px 4px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  -moz-appearance: textfield;
}
.tc-num::-webkit-inner-spin-button,
.tc-num::-webkit-outer-spin-button { -webkit-appearance: none; }
.tc-num:focus { border-color: var(--accent); }
.tc-sep {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-faint);
}
.tc-source-info, .tc-detected, .tc-ltc-info {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}
.tc-ltc-info { font-size: 10px; color: var(--text-faint); margin-left: var(--space-2); }
.tc-buttons {
  display: flex;
  gap: var(--space-3);
  width: 100%;
  margin-bottom: var(--space-4);
}
.tc-buttons .gen-play { flex: 1; }
.tc-buttons .btn-reset { flex: 0; white-space: nowrap; }
.tc-stats {
  width: 100%;
  border-top: 1px solid var(--border);
  padding-top: var(--space-3);
}
.tc-stat-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-family: var(--font-mono);
}
.tc-stat-row:last-child { border-bottom: none; }
.tc-stat-row span:first-child { color: var(--text-faint); }
.tc-stat-row span:last-child { color: var(--text-muted); font-weight: 500; }

/* ---- Footer ---- */
.app-footer {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-6) var(--space-6);
  text-align: center;
  font-size: var(--text-xs);
  color: var(--text-faint);
  border-top: 1px solid var(--border);
  margin-top: var(--space-8);
}
.app-footer a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition);
}
.app-footer a:hover {
  color: var(--accent);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
