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

:root {
  --bg-deep: #0a0a1a;
  --bg-panel: #111128;
  --bg-surface: #1a1a3a;
  --phosphor: #00ff41;
  --amber: #ffb000;
  --cool-blue: #4fc3f7;
  --crt-white: #fffde7;
  --signal-red: #ff5252;
  --text-dim: #667788;
  --text-mid: #99aabb;
  --border-color: #2a2a4a;
}

html, body {
  background: var(--bg-deep);
  color: var(--crt-white);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  overflow-x: hidden;
}

#app-container {
  max-width: 1500px;
  margin: 0 auto;
  padding: 8px;
}

/* Signal Chain Bar */
#signal-chain-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 12px;
  background: linear-gradient(180deg, #1a1a3a, #111128);
  border-bottom: 1px solid var(--border-color);
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  flex-wrap: wrap;
  margin-bottom: 4px;
  border-radius: 4px;
}

.chain-node {
  padding: 2px 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  color: var(--text-mid);
  white-space: nowrap;
}
.chain-node.active { color: var(--phosphor); border-color: var(--phosphor); box-shadow: 0 0 6px rgba(0,255,65,0.3); }
.chain-node.rf { color: var(--amber); border-color: var(--amber); }
.chain-node.crt { color: var(--cool-blue); border-color: var(--cool-blue); }
.chain-arrow { color: var(--text-dim); font-size: 10px; }

/* Header */
#top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: linear-gradient(135deg, #111128 0%, #1a1a3a 100%);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  margin-bottom: 8px;
  flex-wrap: wrap;
  gap: 8px;
}

#top-bar h1 {
  font-family: 'VT323', monospace;
  font-size: 26px;
  color: var(--phosphor);
  text-shadow: 0 0 10px rgba(0,255,65,0.4);
  letter-spacing: 1px;
}

.subtitle {
  font-size: 11px;
  color: var(--amber);
  font-family: 'Share Tech Mono', monospace;
}

.header-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.tv-system-toggle { display: flex; gap: 2px; }
.sys-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-mid);
  padding: 4px 12px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}
.sys-btn:first-child { border-radius: 4px 0 0 4px; }
.sys-btn:last-child { border-radius: 0 4px 4px 0; }
.sys-btn.active {
  background: var(--phosphor);
  color: #000;
  border-color: var(--phosphor);
  font-weight: 700;
}
.sys-btn:hover:not(.active) { background: #2a2a4a; }

.ctrl-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--amber);
  padding: 4px 10px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s;
}
.ctrl-btn:hover { background: #2a2a4a; border-color: var(--amber); }
.ctrl-btn.active { background: var(--amber); color: #000; }

/* Main Layout */
#main-layout {
  display: grid;
  grid-template-columns: 1fr 1.1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 10px;
  overflow: hidden;
}

.panel-title {
  font-family: 'VT323', monospace;
  font-size: 16px;
  color: var(--amber);
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border-color);
}

/* Left Panel */
.source-selector {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.source-selector label {
  font-size: 11px;
  color: var(--text-mid);
  white-space: nowrap;
}
.source-selector select, .source-selector input[type="text"] {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--crt-white);
  padding: 4px 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  border-radius: 3px;
  flex: 1;
  min-width: 100px;
}

.source-preview-wrap {
  text-align: center;
  margin-bottom: 6px;
}
#source-canvas {
  width: 100%;
  max-width: 300px;
  height: auto;
  border: 1px solid var(--border-color);
  border-radius: 3px;
  image-rendering: pixelated;
}

.waveform-stack {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.wf-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-family: 'Share Tech Mono', monospace;
  color: var(--text-mid);
}
.wf-label.comp { color: var(--phosphor); }

.wf-canvas {
  width: 100%;
  height: 40px;
  background: #050510;
  border-radius: 2px;
  border: 1px solid #1a1a2a;
}

/* Center Panel - Scope */
.scope-container {
  position: relative;
  margin-bottom: 6px;
}

#scope-canvas {
  width: 100%;
  height: auto;
  background: #020208;
  border: 2px solid #333;
  border-radius: 8px;
  box-shadow: inset 0 0 30px rgba(0,255,65,0.05), 0 0 15px rgba(0,0,0,0.5);
}

.scope-labels {
  display: flex;
  justify-content: space-around;
  font-size: 9px;
  color: var(--text-dim);
  font-family: 'Share Tech Mono', monospace;
  padding: 2px 20px;
}

.spectrum-container { margin-bottom: 6px; }
#spectrum-canvas {
  width: 100%;
  height: auto;
  background: #020208;
  border: 2px solid #333;
  border-radius: 6px;
  box-shadow: inset 0 0 20px rgba(255,176,0,0.03);
}

.rf-info-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 6px 10px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
}
.rf-info-row {
  display: flex;
  justify-content: space-between;
  padding: 1px 0;
}
.rf-info-row span:first-child { color: var(--text-mid); }
.rf-info-row span:last-child { color: var(--phosphor); }

/* Right Panel - TV */
.tv-set { display: flex; flex-direction: column; align-items: center; }

.tv-antenna {
  display: flex;
  justify-content: center;
  gap: 40px;
  margin-bottom: -4px;
  position: relative;
  z-index: 2;
}
.antenna-left, .antenna-right {
  width: 3px;
  height: 50px;
  background: linear-gradient(to top, #555, #999);
  border-radius: 2px;
}
.antenna-left { transform: rotate(-25deg); transform-origin: bottom center; }
.antenna-right { transform: rotate(25deg); transform-origin: bottom center; }

.tv-body {
  background: linear-gradient(145deg, #3a3528, #2a2520, #1e1a18);
  border-radius: 16px;
  padding: 14px;
  border: 2px solid #4a4038;
  box-shadow: 0 8px 30px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.1);
  width: 100%;
  max-width: 380px;
}

.tv-screen-bezel {
  background: #0a0a0a;
  border-radius: 12px;
  padding: 8px;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.8);
}

#crt-canvas {
  width: 100%;
  height: auto;
  border-radius: 8px;
  display: block;
}

.crt-overlay {
  position: absolute;
  top: 8px; left: 8px; right: 8px; bottom: 8px;
  border-radius: 8px;
  pointer-events: none;
  background:
    repeating-linear-gradient(0deg, transparent, transparent 1px, rgba(0,0,0,0.15) 1px, rgba(0,0,0,0.15) 2px),
    radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.4) 100%);
  mix-blend-mode: multiply;
}

.tv-controls-panel {
  padding: 8px 4px 4px;
  text-align: center;
}

.tv-brand {
  font-family: 'VT323', monospace;
  font-size: 14px;
  color: #8a7a60;
  letter-spacing: 4px;
  margin-bottom: 8px;
}

.knobs-row {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.knob-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.knob-group label {
  font-family: 'Share Tech Mono', monospace;
  font-size: 8px;
  color: #8a7a60;
  text-transform: uppercase;
}

.knob {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #555, #222);
  border: 2px solid #666;
  position: relative;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
  transition: box-shadow 0.2s;
}
.knob:hover { box-shadow: 0 2px 10px rgba(255,176,0,0.3); }
.knob-indicator {
  position: absolute;
  top: 3px;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 10px;
  background: var(--amber);
  border-radius: 1px;
}

.audio-section {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  justify-content: center;
}
.audio-viz {
  display: flex;
  align-items: center;
  gap: 6px;
}
#audio-canvas {
  background: #050510;
  border: 1px solid var(--border-color);
  border-radius: 3px;
  height: 30px;
}
.audio-label {
  font-size: 10px;
  color: var(--text-mid);
  font-family: 'Share Tech Mono', monospace;
}

/* Bottom Panel */
#bottom-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 8px;
}

.sliders-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.slider-group {
  flex: 1;
  min-width: 140px;
}
.slider-group label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-mid);
  font-family: 'Share Tech Mono', monospace;
  margin-bottom: 3px;
}
.slider-group label span { color: var(--phosphor); }

input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--bg-surface);
  border-radius: 3px;
  outline: none;
  border: 1px solid var(--border-color);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--amber);
  cursor: pointer;
  border: 2px solid #000;
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--amber);
  cursor: pointer;
  border: 2px solid #000;
}

.presets-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.preset-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--crt-white);
  padding: 5px 12px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s;
  white-space: nowrap;
}
.preset-btn:hover {
  background: var(--amber);
  color: #000;
  border-color: var(--amber);
}

footer {
  text-align: center;
  padding: 10px;
  font-size: 11px;
  color: var(--text-dim);
  font-family: 'Share Tech Mono', monospace;
}
footer a { color: var(--amber); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* Responsive */
@media (max-width: 1100px) {
  #main-layout {
    grid-template-columns: 1fr 1fr;
  }
  #right-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 700px) {
  #main-layout {
    grid-template-columns: 1fr;
  }
  #signal-chain-bar { font-size: 9px; }
  #top-bar h1 { font-size: 20px; }
  .knobs-row { gap: 4px; }
  .knob { width: 28px; height: 28px; }
}