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

body.blue-pal {
  --accent: #4488ff;
  --accent-dim: #2255bb;
  --accent-glow: rgba(68,136,255,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.06) 2px,rgba(0,0,0,0.06) 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 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 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: 22px;
  color: var(--accent);
  text-shadow: 0 0 10px var(--accent-glow);
  letter-spacing: 2px;
}

.header-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.subtitle { font-size: 10px; color: #666; }
.subtitle-hw { font-family: 'VT323', monospace; font-size: 12px; color: var(--accent-dim); letter-spacing: 1px; }

#encoding-selector {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.enc-btn {
  background: #1a1a1a;
  border: 2px solid #333;
  color: var(--text-dim);
  padding: 4px 16px;
  font-family: 'VT323', monospace;
  font-size: 16px;
  letter-spacing: 2px;
  cursor: pointer;
  transition: all 0.2s;
  border-radius: 3px;
}

.enc-btn.active {
  background: #1a2a1a;
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow), inset 0 0 8px var(--accent-glow);
  text-shadow: 0 0 8px var(--accent-glow);
}

body.amber .enc-btn.active { background: #2a2200; }
body.blue-pal .enc-btn.active { background: #0a1a3a; }

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

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

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

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

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

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

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

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

.toggle-btn {
  background: #1a1a1a;
  border: 1px solid #333;
  color: var(--text-dim);
  padding: 3px 7px;
  font-family: 'VT323', monospace;
  font-size: 12px;
  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: 4px 10px;
  font-family: 'VT323', monospace;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  border-radius: 2px;
}

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

.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: 0px;
  padding: 5px 3px;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.25s;
  color: var(--text-dim);
}

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

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

body.amber .hw-preset-btn.active { background: #2a2200; }
body.blue-pal .hw-preset-btn.active { background: #0a1a3a; }

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

.drop-zone {
  border: 2px dashed var(--accent-dim);
  border-radius: 8px;
  padding: 14px;
  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); }
body.blue-pal .drop-zone { background: rgba(68,136,255,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);
}

.drop-icon { color: var(--accent); font-size: 20px; font-family: 'VT323', monospace; }
.drop-text { color: #666; font-size: 11px; margin-top: 2px; }
.drop-hint { color: #444; font-size: 10px; }

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; width: 12px; height: 12px; 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: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); cursor: pointer;
  box-shadow: 0 0 6px var(--accent-glow); border: 2px solid var(--accent-dim);
}

.artifact-slider::-webkit-slider-thumb {
  background: #ff6644; border-color: #cc4422; box-shadow: 0 0 8px rgba(255,100,60,0.4);
}

.artifact-slider::-moz-range-thumb {
  background: #ff6644; border-color: #cc4422; box-shadow: 0 0 8px rgba(255,100,60,0.4);
}

.full-width { width: 100%; }
.slider-group { margin-bottom: 5px; }

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

.slider-row { display: flex; align-items: center; gap: 8px; }
.static-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.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: 12px; color: var(--accent); }

.retro-select {
  width: 100%; background: #1a1a1a; border: 1px solid #333;
  color: var(--accent); padding: 4px 8px;
  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: 6px;
  font-size: 11px; 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: 4px; }

#tab-bar { display: flex; flex-wrap: wrap; }

.tab-btn {
  background: #111; border: 1px solid #333; border-bottom: none;
  color: var(--text-dim); padding: 5px 12px;
  font-family: 'VT323', monospace; font-size: 14px; 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 {
  flex: 1; border: 1px solid #333; border-top: none;
  padding: 10px; 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-bezel {
  background: linear-gradient(145deg, #2a2a2a 0%, #1a1a1a 50%, #0d0d0d 100%);
  border-radius: 20px; padding: 12px;
  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: 700px; 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.2) 1px,rgba(0,0,0,0.2) 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: 4px 10px; border-radius: 2px;
  text-shadow: 0 0 6px var(--accent-glow);
  font-size: 12px; margin-top: 8px; letter-spacing: 1px;
}

.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: 14px; margin-top: 5px; font-size: 11px; color: #666; flex-wrap: wrap;
}

.accent-text { color: var(--accent); }

.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: 13px; height: 13px; border-radius: 50%;
  background: #222; border: 1px solid #444; color: var(--accent);
  font-size: 9px; text-align: center; line-height: 12px;
  cursor: help; position: relative; vertical-align: middle; margin-left: 3px;
}

.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: 5px 8px; border-radius: 4px;
  font-size: 10px; color: var(--text); z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5); max-width: 260px;
  white-space: normal; width: max-content;
}

#info-drawer { margin-top: 8px; }
#info-drawer summary { list-style: none; }
#info-drawer summary::-webkit-details-marker { display: none; }
#info-drawer[open] summary { margin-bottom: 8px; }

.info-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px;
}

.info-card {
  background: #0d0d0d; border: 1px solid #222; border-radius: 4px;
  padding: 8px; font-family: 'IBM Plex Sans', sans-serif;
  font-size: 11px; color: #aaa; line-height: 1.5;
}

.info-card ul { margin-left: 14px; margin-top: 3px; list-style: disc; }

.info-card-title {
  color: var(--accent); font-family: 'VT323', monospace;
  font-size: 14px; margin-bottom: 4px;
}

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

/* ====== Encyclopedia Styles ====== */
.encyclopedia-scroll {
  width: 100%; max-height: 70vh; overflow-y: auto;
  padding: 10px; text-align: left;
}

.enc-section {
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid #1a1a1a;
}

.enc-title {
  font-family: 'VT323', monospace;
  font-size: 28px;
  color: var(--accent);
  text-shadow: 0 0 10px var(--accent-glow);
  letter-spacing: 3px;
  text-align: center;
}

.enc-subtitle {
  text-align: center;
  color: #666;
  font-size: 12px;
  margin-top: 4px;
}

.enc-heading {
  font-family: 'VT323', monospace;
  font-size: 18px;
  color: var(--accent);
  margin-bottom: 8px;
  letter-spacing: 2px;
  border-left: 3px solid var(--accent);
  padding-left: 10px;
}

.enc-section p {
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 12px;
  color: #bbb;
  line-height: 1.7;
  margin-bottom: 8px;
}

.enc-section strong { color: var(--accent); }

.enc-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  margin: 10px 0;
}

.enc-table th, .enc-table td {
  border: 1px solid #333;
  padding: 5px 8px;
  text-align: left;
}

.enc-table th {
  background: #1a1a1a;
  color: #888;
  font-weight: normal;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.enc-table td { color: #bbb; }

.enc-table th.enc-active {
  color: var(--accent);
  background: #0a1a0a;
  border-color: var(--accent-dim);
}

body.amber .enc-table th.enc-active { background: #1a1500; }
body.blue-pal .enc-table th.enc-active { background: #0a0a2a; }

.enc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.enc-card {
  background: #0d0d0d;
  border: 1px solid #222;
  border-radius: 4px;
  padding: 10px;
}

.enc-card h4 {
  font-family: 'VT323', monospace;
  font-size: 14px;
  color: var(--accent);
  margin-bottom: 4px;
}

.enc-card p {
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 11px;
  color: #aaa;
  line-height: 1.6;
  margin-bottom: 0;
}

/* Anatomy tooltip */
.anatomy-tooltip {
  position: absolute;
  background: #1a1a1a;
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 8px 12px;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 11px;
  color: #ccc;
  max-width: 250px;
  z-index: 10;
  box-shadow: 0 4px 16px rgba(0,0,0,0.6);
  pointer-events: none;
}

/* ====== Footer ====== */
#app-footer {
  background: linear-gradient(180deg, #0d0d0d, #080808);
  border-top: 1px solid #222;
  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: #444; }

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

@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;
  }
  .preset-grid { grid-template-columns: repeat(4, 1fr); }
  #display-area { min-height: 300px; }
  #app-title { font-size: 16px; }
  .enc-btn { padding: 3px 10px; font-size: 13px; }
  .tab-btn { padding: 4px 8px; font-size: 12px; }
}