: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; }

/* Header lock LED */
.lock-led {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: 'VT323', monospace; font-size: 14px; letter-spacing: 1px;
  padding: 3px 10px; border-radius: 3px; border: 1px solid #333; background: #0a0a0a;
}
.lock-led .lock-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.lock-led.lock-locked { color: #00ffaa; border-color: #045; }
.lock-led.lock-locked .lock-dot { background: #00ffaa; box-shadow: 0 0 8px #00ffaa; }
.lock-led.lock-search { color: #ffaa22; border-color: #442800; }
.lock-led.lock-search .lock-dot { background: #ffaa22; box-shadow: 0 0 8px #ffaa22; animation: blink 0.6s steps(1) infinite; }
.lock-led.lock-loss { color: #ff4444; border-color: #400; }
.lock-led.lock-loss .lock-dot { background: #ff4444; box-shadow: 0 0 8px #ff4444; animation: blink 0.3s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0.15; } }

/* MAIN LAYOUT */
#main-layout { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: 268px; min-width: 228px; 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 { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 4px; padding: 12px; }
.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;
}

/* Sync separator panel accent */
.sync-panel { border-color: #443300; box-shadow: inset 0 0 20px rgba(255,136,0,0.04); }
.sync-panel .panel-title { color: #ff8800; }

.mini-select {
  background: #1a1a1a; border: 1px solid #444; color: #ff8800;
  font-family: 'VT323', monospace; font-size: 13px; padding: 3px 6px; border-radius: 2px; cursor: pointer;
}

.slice-note {
  font-size: 11px; font-family: 'VT323', monospace; margin-top: 4px; letter-spacing: 0.5px;
}
.slice-note.ok { color: #00ffaa; }
.slice-note.warn { color: #ffaa22; }
.slice-note.err { color: #ff4444; }

.slice-presets { margin-top: 8px; }
.preset-btn.tiny { padding: 3px 6px; font-size: 12px; }

.sync-metrics {
  margin-top: 10px; border-top: 1px dashed #333; padding-top: 8px;
  display: flex; flex-direction: column; gap: 3px;
}
.metric-row {
  display: flex; justify-content: space-between; font-family: 'VT323', monospace;
  font-size: 13px; color: #777;
}
.metric-row .m-val { color: var(--accent); }
.metric-row .m-val.ok { color: #00ffaa; }
.metric-row .m-val.warn { color: #ffaa22; }
.metric-row .m-val.err { color: #ff4444; }

/* 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; }
.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; }

/* 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);
}
/* Sync threshold sliders get amber thumbs */
#ctrl-slice::-webkit-slider-thumb, #hsync-slice-mirror::-webkit-slider-thumb { background: #ff8800; border-color: #aa5500; box-shadow: 0 0 6px rgba(255,136,0,0.5); }
#ctrl-slice::-moz-range-thumb, #hsync-slice-mirror::-moz-range-thumb { background: #ff8800; border-color: #aa5500; }

.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); }

/* 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 16px; 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 */
.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: 340px; }
.legend-row { display: flex; gap: 16px; margin-top: 6px; font-size: 12px; color: #666; flex-wrap: wrap; }
.accent-text { color: var(--accent); }

.hsync-teach {
  margin-top: 8px; padding: 10px 12px; background: rgba(255,136,0,0.05);
  border: 1px solid #332200; border-radius: 4px; font-family: 'IBM Plex Sans', sans-serif;
  font-size: 12px; line-height: 1.6; color: #b09070; width: 100%;
}
.hsync-teach strong { color: #ffaa44; }

/* NTSC joke */
.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 */
.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;
}
.sync-info-card { border-color: #443300; box-shadow: inset 0 0 20px rgba(255,136,0,0.04); }
.sync-info-card .info-card-title { color: #ff8800; }
.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: 1024px) {
  #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; }