:root {
  --vic-black: #000000;
  --vic-white: #ffffff;
  --vic-red-brown: #a8734a;
  --vic-lt-red-brown: #e9b287;
  --vic-dark-red: #772d26;
  --vic-light-red: #b66862;
  --vic-cyan: #85d4dc;
  --vic-lt-cyan: #c5ffff;
  --vic-purple: #a85fb4;
  --vic-lt-purple: #e99df5;
  --vic-green: #559e4a;
  --vic-lt-green: #92df87;
  --vic-blue: #42348b;
  --vic-lt-blue: #7e70ca;
  --vic-yellow-green: #bdcc71;
  --vic-lt-yellow: #ffffb0;

  --bg-primary: #0d0d1a;
  --bg-secondary: #1a1a2e;
  --bg-panel: #16213e;
  --bg-panel-header: #1e2d50;
  --text-primary: #e0e0e0;
  --text-accent: var(--vic-lt-yellow);
  --border-color: #2a2a4a;
  --btn-bg: var(--vic-blue);
  --btn-text: var(--vic-lt-yellow);
}

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

body {
  background: var(--bg-primary);
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(66,52,139,0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(85,158,74,0.08) 0%, transparent 40%);
  color: var(--text-primary);
  font-family: 'IBM Plex Mono', monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 10px;
}

#header {
  text-align: center;
  padding: 16px 10px 10px;
  background: linear-gradient(135deg, var(--vic-blue), #2a1f5e);
  border-radius: 8px 8px 0 0;
  border-bottom: 3px solid var(--vic-lt-blue);
  margin-bottom: 12px;
}
#header h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(12px, 2.5vw, 22px);
  color: var(--vic-lt-yellow);
  text-shadow: 2px 2px 0 rgba(0,0,0,0.5), 0 0 20px rgba(255,255,176,0.3);
  letter-spacing: 1px;
}
.tagline {
  font-size: clamp(9px, 1.5vw, 12px);
  color: var(--vic-lt-cyan);
  margin-top: 6px;
  opacity: 0.8;
}

#main-layout {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
#screen-column { flex: 1; min-width: 0; }
#panel-column { width: 340px; flex-shrink: 0; }

/* Monitor */
#monitor-bezel {
  background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
  border-radius: 18px;
  padding: 18px 18px 10px;
  box-shadow:
    0 0 0 2px #3a3a3a,
    0 8px 32px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.05);
  margin-bottom: 10px;
  position: relative;
}
#monitor-inner {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
  border: 2px solid #111;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.8);
  line-height: 0;
}
#canvas {
  width: 100%;
  height: auto;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
#scanline-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent 0px,
    transparent 2px,
    rgba(0,0,0,0.12) 2px,
    rgba(0,0,0,0.12) 4px
  );
  pointer-events: none;
  z-index: 2;
}
#vignette-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.5) 100%);
  pointer-events: none;
  z-index: 3;
}
#monitor-label {
  text-align: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: #555;
  margin-top: 8px;
  letter-spacing: 3px;
}

/* Control bar */
#control-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  background: var(--bg-secondary);
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: 10px;
  border: 1px solid var(--border-color);
}
.ctrl-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  padding: 5px 10px;
  background: var(--btn-bg);
  color: var(--btn-text);
  border: 1px solid var(--vic-lt-blue);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.ctrl-btn:hover:not(:disabled) {
  background: var(--vic-lt-blue);
  color: #000;
}
.ctrl-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.ctrl-btn.small { padding: 5px 8px; font-size: 13px; }
.ctrl-info {
  font-size: 11px;
  color: var(--vic-lt-green);
  padding: 0 6px;
}
.ctrl-group {
  display: flex;
  align-items: center;
  gap: 4px;
}
#volume-slider {
  width: 60px;
  accent-color: var(--vic-green);
}

/* Panels */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  margin-bottom: 8px;
  overflow: hidden;
}
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg-panel-header);
  cursor: pointer;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: var(--vic-lt-cyan);
  user-select: none;
  transition: background 0.2s;
}
.panel-header:hover { background: #263556; }
.chevron { transition: transform 0.3s; font-size: 10px; }
.panel-body {
  padding: 12px;
  max-height: 800px;
  overflow: hidden;
  transition: max-height 0.4s ease, padding 0.3s ease, opacity 0.3s;
  opacity: 1;
}
.panel-body.collapsed {
  max-height: 0;
  padding: 0 12px;
  opacity: 0;
}

/* Upload zones */
.upload-zone {
  border: 2px dashed var(--border-color);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 8px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}
.upload-zone:hover {
  border-color: var(--vic-lt-blue);
  background: rgba(66,52,139,0.1);
}
.upload-zone.loaded {
  border-color: var(--vic-green);
  background: rgba(85,158,74,0.1);
}
.upload-zone.loaded .upload-status { color: var(--vic-lt-green); }
.upload-zone.error {
  border-color: var(--vic-dark-red);
  background: rgba(119,45,38,0.1);
}
.upload-zone.small { padding: 10px; }
.upload-icon { font-size: 24px; margin-bottom: 4px; }
.upload-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--vic-lt-yellow);
  margin-bottom: 4px;
}
.upload-detail {
  font-size: 10px;
  color: #888;
  margin-bottom: 4px;
}
.upload-status {
  font-size: 10px;
  color: #666;
}
.file-input {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* Power button */
.power-btn {
  display: block;
  width: 100%;
  padding: 14px;
  margin-top: 8px;
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  background: linear-gradient(180deg, #4a0000, #2a0000);
  color: #ff4444;
  border: 3px solid #600;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  text-shadow: 0 0 10px rgba(255,0,0,0.5);
}
.power-btn:not(:disabled):hover {
  background: linear-gradient(180deg, #660000, #440000);
  box-shadow: 0 0 20px rgba(255,0,0,0.3);
}
.power-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.power-btn.on {
  background: linear-gradient(180deg, #004a00, #002a00);
  color: #44ff44;
  border-color: #060;
  text-shadow: 0 0 10px rgba(0,255,0,0.5);
}
.power-icon { font-size: 18px; }

/* VIC register table */
#vic-reg-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
}
#vic-reg-table th {
  background: var(--bg-panel-header);
  padding: 4px 6px;
  text-align: left;
  color: var(--vic-lt-cyan);
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
}
#vic-reg-table td {
  padding: 3px 6px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-family: 'IBM Plex Mono', monospace;
}
#vic-reg-table tr.changed td { color: var(--vic-lt-yellow); }

/* CPU debug */
#cpu-registers, #cpu-flags {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  margin-bottom: 6px;
  padding: 6px;
  background: rgba(0,0,0,0.3);
  border-radius: 4px;
}
#cpu-registers span, #cpu-flags span {
  display: inline-block;
  margin-right: 10px;
}
.flag-set { color: var(--vic-lt-green); font-weight: 700; }
.flag-clear { color: #555; }
#cpu-controls {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
  align-items: center;
}
#breakpoint-input {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  padding: 4px 8px;
  background: #0a0a1a;
  color: var(--vic-lt-yellow);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  width: 110px;
}
#disassembly {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  background: rgba(0,0,0,0.3);
  border-radius: 4px;
  padding: 6px;
  max-height: 180px;
  overflow-y: auto;
  line-height: 1.5;
}
.disasm-current { color: var(--vic-lt-yellow); font-weight: 700; }
.disasm-line { color: #888; }

/* Virtual keyboard */
#virtual-keyboard {
  background: linear-gradient(145deg, #3a3028, #2a2018);
  border-radius: 10px;
  padding: 10px 8px;
  border: 2px solid #4a4038;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}
.kb-row {
  display: flex;
  gap: 3px;
  margin-bottom: 3px;
  justify-content: center;
}
.kb-key {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  font-weight: 700;
  min-width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #d4c8a8, #b8a888);
  color: #2a2018;
  border: 1px solid #8a7a5a;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
  transition: all 0.1s;
  padding: 0 4px;
  box-shadow: 0 2px 0 #6a5a3a, inset 0 1px 0 rgba(255,255,255,0.3);
}
.kb-key:active, .kb-key.pressed {
  background: linear-gradient(180deg, #a89868, #988858);
  box-shadow: 0 0 0 #6a5a3a;
  transform: translateY(2px);
}
.kb-key.dark {
  background: linear-gradient(180deg, #5a4a3a, #4a3a2a);
  color: #d4c8a8;
  border-color: #3a2a1a;
  box-shadow: 0 2px 0 #2a1a0a, inset 0 1px 0 rgba(255,255,255,0.1);
}
.kb-key.dark:active, .kb-key.dark.pressed {
  background: linear-gradient(180deg, #3a2a1a, #2a1a0a);
  box-shadow: 0 0 0 #2a1a0a;
  transform: translateY(2px);
}
.kb-key.wide { min-width: 50px; }
.kb-key.wider { min-width: 70px; }
.kb-key.space { min-width: 180px; }

/* Help */
.help-content h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--vic-lt-yellow);
  margin: 8px 0 4px;
}
.help-cmds {
  font-size: 10px;
  color: #aaa;
  line-height: 1.6;
}

/* Status bar */
#status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  background: var(--bg-secondary);
  border-radius: 0 0 8px 8px;
  border-top: 1px solid var(--border-color);
  margin-top: 10px;
  font-size: 10px;
  flex-wrap: wrap;
  gap: 8px;
}
#emu-status { color: var(--vic-lt-yellow); }
#frame-info { color: #666; }
#status-bar a {
  color: var(--vic-lt-cyan);
  text-decoration: none;
}
#status-bar a:hover { text-decoration: underline; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }

/* Responsive */
@media (max-width: 900px) {
  #main-layout {
    flex-direction: column;
  }
  #panel-column {
    width: 100%;
  }
  .kb-key {
    min-width: 22px;
    height: 24px;
    font-size: 7px;
  }
  .kb-key.space { min-width: 120px; }
  .kb-key.wide { min-width: 38px; }
  .kb-key.wider { min-width: 52px; }
}