:root {
  --accent: #00ff41;
  --accent-dim: #00aa2a;
  --accent-glow: rgba(0,255,65,0.3);
  --bg: #0a0a0a;
  --panel: #111111;
  --panel-border: #1e1e1e;
  --text: #b0b0b0;
  --text-dim: #555;
}

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

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

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

#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
  border-bottom: 1px solid #1a1a1a;
  background: #0d0d0d;
}

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

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

.header-center { display: flex; align-items: center; }
.subtitle { font-size: 11px; color: #555; }
.header-right { display: flex; align-items: center; }

#main-layout { display: flex; flex: 1; min-height: 0; }

.sidebar {
  width: 240px;
  min-width: 200px;
  padding: 8px;
  background: #0d0d0d;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

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

#display-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #080808;
  border: 1px solid #1a1a1a;
  border-radius: 4px;
  min-height: 400px;
}

.view-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.control-panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  padding: 8px;
}

.panel-title {
  font-family: 'VT323', monospace;
  font-size: 13px;
  color: var(--accent);
  letter-spacing: 2px;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 4px;
  margin-bottom: 6px;
}

.toggle-btn {
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  color: var(--text-dim);
  padding: 3px 7px;
  font-family: 'VT323', monospace;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  border-radius: 2px;
  white-space: nowrap;
}

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

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

.preset-btn {
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  color: var(--accent);
  padding: 4px 8px;
  font-family: 'VT323', monospace;
  font-size: 12px;
  cursor: pointer;
  border-radius: 2px;
}

.preset-btn:hover { background: var(--accent); color: #000; }

.button-row { display: flex; gap: 5px; flex-wrap: wrap; }
.button-grid { display: flex; flex-wrap: wrap; gap: 3px; }

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
}

.hw-preset-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 5px 3px;
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 2px;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-dim);
}

.hw-preset-btn:hover { border-color: var(--accent-dim); background: #1f1f1f; }

.hw-preset-btn.active {
  border-color: var(--accent);
  background: #0f1f0f;
  box-shadow: 0 0 6px var(--accent-glow);
}

body.amber .hw-preset-btn.active { background: #1f1800; }

.hw-icon { font-size: 16px; }
.hw-name { font-family: 'VT323', monospace; font-size: 11px; color: var(--accent); letter-spacing: 1px; }

.drop-zone {
  border: 1px dashed var(--accent-dim);
  border-radius: 6px;
  padding: 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: rgba(0,255,65,0.01);
}

.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(0,255,65,0.04);
  box-shadow: 0 0 12px var(--accent-glow);
}

.drop-icon { color: var(--accent); font-size: 18px; }
.drop-text { color: #555; font-size: 10px; margin-top: 2px; }
.drop-hint { color: #333; font-size: 9px; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 5px;
  background: #1a1a1a;
  border-radius: 3px;
  outline: none;
  border: 1px solid #2a2a2a;
  width: 100%;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 4px var(--accent-glow);
  border: 1px solid var(--accent-dim);
}

input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 1px solid var(--accent-dim);
}

.full-width { width: 100%; }

.slider-group { margin-bottom: 5px; }

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2px;
}

.knob-label {
  font-family: 'VT323', monospace;
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 1px;
}

.knob-value {
  font-family: 'VT323', monospace;
  font-size: 12px;
  color: var(--accent);
}

.retro-select {
  width: 100%;
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  color: var(--accent);
  padding: 3px 6px;
  font-family: 'VT323', monospace;
  font-size: 12px;
  border-radius: 2px;
  cursor: pointer;
}

.retro-select option { background: #1a1a1a; color: var(--accent); }

.radio-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: #666;
  cursor: pointer;
  padding: 2px 0;
}

.radio-label.active-radio { color: var(--accent); }
.radio-label input[type="radio"] { accent-color: var(--accent); }

.crt-bezel {
  background: linear-gradient(145deg, #252525 0%, #151515 50%, #0a0a0a 100%);
  border-radius: 16px;
  padding: 12px;
  box-shadow:
    inset 0 0 25px rgba(0,0,0,0.8),
    0 0 10px rgba(0,0,0,0.4),
    0 3px 15px rgba(0,0,0,0.5);
  position: relative;
  max-width: 700px;
  width: 100%;
}

.crt-bezel::before {
  content: '';
  position: absolute;
  top: 3px; left: 3px; right: 3px; bottom: 3px;
  border-radius: 14px;
  border: 1px solid #2a2a2a;
  pointer-events: none;
}

.crt-screen {
  border-radius: 10px;
  overflow: hidden;
  position: relative;
  box-shadow: 0 0 30px var(--accent-glow), inset 0 0 15px rgba(0,0,0,0.5);
  transform: perspective(800px) rotateX(0.3deg);
  filter: contrast(1.08) brightness(1.03);
}

.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.15) 1px,
    rgba(0,0,0,0.15) 2px
  );
  pointer-events: none;
}

@keyframes crt-warmup {
  0% { transform: perspective(800px) rotateX(0.3deg) scaleY(0.005) scaleX(0.8); filter: brightness(3) blur(2px); }
  30% { transform: perspective(800px) rotateX(0.3deg) scaleY(0.005) scaleX(1); }
  50% { transform: perspective(800px) rotateX(0.3deg) scaleY(0.6) scaleX(1); filter: brightness(1.5); }
  100% { transform: perspective(800px) rotateX(0.3deg) scaleY(1) scaleX(1); filter: contrast(1.08) brightness(1.03); }
}

.crt-warmup { animation: crt-warmup 1.2s ease-out forwards; }

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

.ntsc-joke {
  font-size: 10px;
  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; }

.sync-hint {
  font-size: 9px;
  color: #444;
  font-style: italic;
  margin-top: 1px;
  line-height: 1.2;
  transition: color 0.3s;
}

.sync-hint.active-drift {
  color: #ff6644;
}

#video-info { margin-top: 5px; font-size: 10px; color: #666; }
#video-info .video-name { color: var(--accent); }

#app-footer {
  background: #080808;
  border-top: 1px solid #1a1a1a;
  padding: 8px 20px;
  font-family: 'VT323', monospace;
  font-size: 11px;
  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: #333; }

@media (max-width: 1024px) {
  #main-layout { flex-direction: column; }
  .sidebar {
    width: 100% !important;
    max-width: 100% !important;
    border: none !important;
    border-bottom: 1px solid #1a1a1a;
    flex-direction: row;
    flex-wrap: wrap;
    overflow-y: visible;
  }
  .sidebar .control-panel { flex: 1; min-width: 200px; }
  .preset-grid { grid-template-columns: repeat(4, 1fr); }
  #display-area { min-height: 300px; }
}