:root {
  --accent: #00ff41;
  --accent-dim: #00aa2a;
  --accent-glow: rgba(0,255,65,0.3);
  --bg: #0a0a0a;
  --panel: #111111;
  --panel-border: #222;
  --text: #c0c0c0;
  --text-dim: #666;
}

body.amber {
  --accent: #ffb000;
  --accent-dim: #aa7500;
  --accent-glow: rgba(255,176,0,0.3);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Share Tech Mono', monospace;
  overflow-x: hidden;
  min-height: 100vh;
}

body::after {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.08) 2px,
    rgba(0,0,0,0.08) 4px
  );
  pointer-events: none;
  z-index: 9999;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #111; }
::-webkit-scrollbar-thumb { background: var(--accent-dim); border-radius: 3px; }

/* HEADER */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid #222;
  background: #0d0d0d;
}

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

#app-title {
  font-family: 'VT323', monospace;
  font-size: 26px;
  color: var(--accent);
  text-shadow: 0 0 10px var(--accent-glow);
  letter-spacing: 3px;
}

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

.subtitle {
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  color: #666;
}

/* Sync LEDs */
.sync-leds {
  display: flex;
  gap: 8px;
  margin-left: 8px;
}
.sync-led-group {
  display: flex;
  align-items: center;
  gap: 3px;
}
.sync-led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid #333;
}
.sync-led.green {
  background: #00ff41;
  box-shadow: 0 0 6px #00ff41;
}
.sync-led.amber {
  background: #ffb000;
  box-shadow: 0 0 6px #ffb000;
  animation: led-pulse 0.8s ease-in-out infinite;
}
.sync-led.red {
  background: #ff2200;
  box-shadow: 0 0 6px #ff2200;
  animation: led-blink 0.4s step-end infinite;
}
.sync-led-label {
  font-family: 'VT323', monospace;
  font-size: 11px;
  color: #888;
}
@keyframes led-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0.2; }
}
@keyframes led-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* MAIN LAYOUT */
#main-layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

.sidebar {
  width: 270px;
  min-width: 230px;
  padding: 12px;
  background: #0d0d0d;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#left-sidebar { border-right: 1px solid #222; }
#right-sidebar { border-left: 1px solid #222; }

#center-panel {
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* CONTROL PANEL */
.control-panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 12px;
}

.sync-panel {
  border-color: var(--accent-dim);
  box-shadow: 0 0 4px var(--accent-glow);
}

.panel-title {
  font-family: 'VT323', monospace;
  font-size: 14px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 2px;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 6px;
  margin-bottom: 10px;
}
.panel-title.clickable {
  cursor: pointer;
  user-select: none;
}
.collapse-arrow {
  float: right;
  transition: transform 0.2s;
}

/* BUTTONS */
.toggle-btn {
  background: #1a1a1a;
  border: 1px solid #333;
  color: var(--text-dim);
  padding: 4px 10px;
  font-family: 'VT323', monospace;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  border-radius: 2px;
  white-space: nowrap;
}

.toggle-btn.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

.toggle-btn:hover {
  border-color: var(--accent-dim);
}

.preset-btn {
  background: #1a1a1a;
  border: 1px solid #333;
  color: var(--accent);
  padding: 6px 12px;
  font-family: 'VT323', monospace;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  border-radius: 2px;
  white-space: nowrap;
}

.preset-btn:hover {
  background: var(--accent);
  color: #000;
  box-shadow: 0 0 8px var(--accent-glow);
}

.button-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.button-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

/* DROP ZONE */
.drop-zone {
  border: 2px dashed var(--accent-dim);
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  background: rgba(0,255,65,0.02);
}
body.amber .drop-zone { background: rgba(255,176,0,0.02); }
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(0,255,65,0.05);
  box-shadow: 0 0 20px var(--accent-glow);
}
body.amber .drop-zone:hover, body.amber .drop-zone.dragover {
  background: rgba(255,176,0,0.05);
}
.drop-icon {
  color: var(--accent);
  font-size: 24px;
  font-family: 'VT323', monospace;
}
.drop-text {
  color: #666;
  font-size: 12px;
  margin-top: 4px;
}
.drop-hint {
  color: #444;
  font-size: 10px;
}

/* Signal Meter */
.signal-meter {
  position: relative;
  height: 60px;
  margin-bottom: 4px;
}
.meter-arc {
  position: relative;
  width: 100%;
  height: 50px;
  overflow: hidden;
  background: radial-gradient(ellipse at center bottom, #1a1a1a 0%, #0a0a0a 100%);
  border-radius: 4px;
  border: 1px solid #333;
}
.meter-needle {
  position: absolute;
  bottom: 4px;
  left: 50%;
  width: 2px;
  height: 36px;
  background: linear-gradient(to top, #ff4400, #ff8800);
  transform-origin: bottom center;
  transform: rotate(-45deg);
  transition: transform 0.3s ease-out;
  box-shadow: 0 0 4px #ff4400;
  z-index: 2;
}
.meter-labels {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: #555;
  padding: 0 4px;
  font-family: 'VT323', monospace;
}

/* Signal bar graph */
.signal-bar-graph {
  display: flex;
  gap: 2px;
  height: 14px;
  margin-bottom: 6px;
}
.signal-bar-graph .bar-seg {
  flex: 1;
  border-radius: 1px;
  background: #1a1a1a;
  border: 1px solid #222;
  transition: background 0.15s;
}
.signal-bar-graph .bar-seg.on-red { background: #ff2200; box-shadow: 0 0 3px #ff2200; }
.signal-bar-graph .bar-seg.on-yellow { background: #ffb000; box-shadow: 0 0 3px #ffb000; }
.signal-bar-graph .bar-seg.on-green { background: #00ff41; box-shadow: 0 0 3px #00ff41; }

.signal-quality-text {
  text-align: center;
  font-family: 'VT323', monospace;
  font-size: 13px;
  color: var(--accent);
  letter-spacing: 2px;
}

/* SLIDERS */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: #222;
  border-radius: 3px;
  outline: none;
  border: 1px solid #333;
  width: 100%;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 6px var(--accent-glow);
  border: 2px solid var(--accent-dim);
}
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 6px var(--accent-glow);
  border: 2px solid var(--accent-dim);
}

/* Special hold slider styling */
.hhold-slider::-webkit-slider-thumb,
.vhold-slider::-webkit-slider-thumb {
  width: 22px;
  height: 22px;
  border: 3px solid var(--accent-dim);
}

.full-width { width: 100%; }

.slider-group { margin-bottom: 8px; }
.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.static-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.flex-slider { flex: 1; }

.knob-label {
  font-family: 'VT323', monospace;
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.knob-value {
  font-family: 'VT323', monospace;
  font-size: 13px;
  color: var(--accent);
}

/* Waveform controls row */
.waveform-controls-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

/* Sync Separator Canvas */
.sync-sep-container {
  margin: 8px 0;
}
.sync-sep-container canvas {
  display: block;
  width: 100%;
  height: 80px;
  background: #050505;
  border: 1px solid #333;
  border-radius: 3px;
}

/* Oscillator Status */
.osc-status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-top: 8px;
}
.osc-readout {
  background: #0a0a0a;
  border: 1px solid #222;
  padding: 4px 6px;
  border-radius: 2px;
}
.osc-readout.wide {
  grid-column: span 2;
}
.osc-label {
  font-family: 'VT323', monospace;
  font-size: 10px;
  color: #555;
  letter-spacing: 1px;
}
.osc-value {
  font-family: 'VT323', monospace;
  font-size: 14px;
  color: var(--accent);
  text-shadow: 0 0 4px var(--accent-glow);
}

/* RADIO */
.radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #888;
  cursor: pointer;
  padding: 2px 0;
}
.radio-label.active-radio { color: var(--accent); }
.radio-label input[type="radio"] { accent-color: var(--accent); }
.info-text {
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 10px;
  color: #555;
  margin-top: 8px;
}

/* TABS */
#tab-bar { display: flex; flex-wrap: wrap; }
.tab-btn {
  background: #111;
  border: 1px solid #333;
  border-bottom: none;
  color: var(--text-dim);
  padding: 6px 14px;
  font-family: 'VT323', monospace;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.2s;
  margin-right: -1px;
}
.tab-btn.active {
  background: var(--panel);
  color: var(--accent);
  border-color: var(--accent-dim);
  border-bottom: 1px solid var(--panel);
  position: relative;
  z-index: 1;
}

/* DISPLAY AREA */
#display-area {
  flex: 1;
  border: 1px solid #333;
  border-top: none;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0d0d0d;
  min-height: 400px;
}
.view-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* CRT */
.crt-bezel {
  background: linear-gradient(145deg, #2a2a2a 0%, #1a1a1a 50%, #0d0d0d 100%);
  border-radius: 20px;
  padding: 16px;
  box-shadow:
    inset 0 0 30px rgba(0,0,0,0.8),
    0 0 15px rgba(0,0,0,0.5),
    0 4px 20px rgba(0,0,0,0.6);
  position: relative;
  max-width: 720px;
  width: 100%;
}
.crt-bezel::before {
  content: '';
  position: absolute;
  top: 4px; left: 4px; right: 4px; bottom: 4px;
  border-radius: 18px;
  border: 1px solid #333;
  pointer-events: none;
}
.crt-screen {
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  box-shadow: 0 0 40px var(--accent-glow), inset 0 0 20px rgba(0,0,0,0.5);
  transform: perspective(800px) rotateX(0.5deg);
  filter: contrast(1.1) brightness(1.05);
}
.crt-screen canvas {
  display: block;
  width: 100%;
  aspect-ratio: 4/3;
  background: #000;
  image-rendering: auto;
}
.crt-screen::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(0,0,0,0.25) 1px,
    rgba(0,0,0,0.25) 2px
  );
  pointer-events: none;
}

@keyframes crt-warmup {
  0% { transform: perspective(800px) rotateX(0.5deg) scaleY(0.005) scaleX(0.8); filter: brightness(3) blur(2px); }
  30% { transform: perspective(800px) rotateX(0.5deg) scaleY(0.005) scaleX(1); filter: brightness(2) blur(1px); }
  50% { transform: perspective(800px) rotateX(0.5deg) scaleY(0.6) scaleX(1); filter: brightness(1.5) blur(0.5px); }
  100% { transform: perspective(800px) rotateX(0.5deg) scaleY(1) scaleX(1); filter: contrast(1.1) brightness(1.05) blur(0); }
}
.crt-warmup { animation: crt-warmup 1.5s ease-out forwards; }

.led-display {
  font-family: 'VT323', monospace;
  color: var(--accent);
  background: #0a0a0a;
  border: 1px solid #222;
  padding: 6px 12px;
  border-radius: 2px;
  text-shadow: 0 0 6px var(--accent-glow);
  font-size: 14px;
  margin-top: 12px;
  letter-spacing: 2px;
}

.scope-screen {
  background: #050505;
  border: 1px solid #333;
  border-radius: 4px;
  position: relative;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.8);
  width: 100%;
}
.scope-screen canvas {
  display: block;
  width: 100%;
  height: 320px;
}

.legend-row {
  display: flex;
  gap: 16px;
  margin-top: 6px;
  font-size: 12px;
  color: #666;
  flex-wrap: wrap;
}
.accent-text { color: var(--accent); }

/* V-Sync Readout */
.vsync-readout {
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  color: var(--accent);
  background: #0a0a0a;
  border: 1px solid #222;
  padding: 8px 12px;
  border-radius: 2px;
  margin-top: 8px;
  width: 100%;
  text-shadow: 0 0 4px var(--accent-glow);
  line-height: 1.5;
}

.ntsc-joke {
  font-size: 11px;
  color: #ff4444;
  font-style: italic;
  opacity: 0;
  transition: opacity 0.3s;
  height: 0;
  overflow: hidden;
}
.ntsc-joke.visible {
  opacity: 1;
  height: auto;
  margin-top: 2px;
}

.info-tip {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #222;
  border: 1px solid #444;
  color: var(--accent);
  font-size: 10px;
  text-align: center;
  line-height: 13px;
  cursor: help;
  position: relative;
  vertical-align: middle;
  margin-left: 4px;
}
.info-tip:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: 120%;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a1a;
  border: 1px solid var(--accent-dim);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 11px;
  color: var(--text);
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  max-width: 280px;
  white-space: normal;
  width: max-content;
}

/* Educational info */
#info-drawer { margin-top: 10px; }
#info-drawer summary { list-style: none; }
#info-drawer summary::-webkit-details-marker { display: none; }
#info-drawer[open] summary { margin-bottom: 10px; }
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}
.info-card {
  background: #0d0d0d;
  border: 1px solid #222;
  border-radius: 4px;
  padding: 12px;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 13px;
  color: #aaa;
  line-height: 1.6;
}
.info-card ul {
  margin-left: 16px;
  margin-top: 4px;
  list-style: disc;
}
.info-card-title {
  color: var(--accent);
  font-family: 'VT323', monospace;
  font-size: 16px;
  margin-bottom: 8px;
}

#video-info { margin-top: 8px; font-size: 12px; color: #888; }
#video-info .video-name { color: var(--accent); }

/* FOOTER */
#app-footer {
  background: linear-gradient(180deg, #0d0d0d, #080808);
  border-top: 1px solid #222;
  padding: 12px 20px;
  font-family: 'VT323', monospace;
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
#app-footer a { color: var(--accent); text-decoration: none; }
#app-footer a:hover { text-decoration: underline; }
.footer-sep { color: #444; }

/* Responsive */
@media (max-width: 1100px) {
  #main-layout { flex-direction: column; }
  .sidebar {
    width: 100% !important;
    max-width: 100% !important;
    border-left: none !important;
    border-right: none !important;
    border-bottom: 1px solid #222;
  }
  #display-area { min-height: 300px; }
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
#main-layout { flex: 1; }