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

:root {
  --bg: #0a0a0a;
  --bg2: #111111;
  --bg3: #1a1a1a;
  --phosphor: #00ff41;
  --phosphor-dim: #00aa2a;
  --accent: #00d4ff;
  --accent-dim: #007a99;
  --amber: #ffaa00;
  --bezel: #2a2a2a;
  --bezel-light: #3a3a3a;
  --bezel-dark: #151515;
  --text: #aaaaaa;
  --text-bright: #dddddd;
  --font-mono: 'Share Tech Mono', monospace;
  --font-display: 'Orbitron', sans-serif;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  overflow-x: hidden;
  min-height: 100vh;
}

body {
  background:
    radial-gradient(ellipse at 50% 0%, #0f1a0f 0%, transparent 60%),
    repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,255,65,0.015) 2px, rgba(0,255,65,0.015) 4px),
    var(--bg);
}

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

/* Header */
#header {
  text-align: center;
  padding: 15px 0 10px;
}

.title {
  font-family: var(--font-display);
  font-size: clamp(28px, 5vw, 48px);
  font-weight: 900;
  letter-spacing: 12px;
  color: var(--phosphor);
  text-shadow:
    0 0 10px var(--phosphor),
    0 0 30px var(--phosphor),
    0 0 60px rgba(0,255,65,0.3);
  animation: titleGlow 3s ease-in-out infinite alternate;
}

@keyframes titleGlow {
  0% { text-shadow: 0 0 10px var(--phosphor), 0 0 30px var(--phosphor), 0 0 60px rgba(0,255,65,0.3); }
  100% { text-shadow: 0 0 15px var(--phosphor), 0 0 40px var(--phosphor), 0 0 80px rgba(0,255,65,0.5); }
}

.subtitle {
  font-family: var(--font-display);
  font-size: clamp(10px, 1.5vw, 14px);
  color: var(--accent-dim);
  letter-spacing: 8px;
  display: block;
  margin-top: 2px;
}

/* Main Layout */
#main-layout {
  display: flex;
  gap: 15px;
  justify-content: center;
  align-items: flex-start;
  flex-wrap: wrap;
}

/* Left Panel */
#left-panel {
  width: 280px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

/* ROM Panel */
#rom-panel {
  background: var(--bg2);
  border: 1px solid var(--bezel-light);
  border-radius: 8px;
  padding: 12px;
}

.cartridge-slot {
  text-align: center;
}

.slot-label {
  font-family: var(--font-display);
  font-size: 10px;
  color: var(--amber);
  letter-spacing: 2px;
  margin-bottom: 8px;
}

.drop-zone {
  border: 2px dashed var(--bezel-light);
  border-radius: 6px;
  padding: 20px 10px;
  cursor: pointer;
  transition: all 0.3s;
  background: rgba(0,255,65,0.02);
}

.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--phosphor);
  background: rgba(0,255,65,0.06);
  box-shadow: 0 0 15px rgba(0,255,65,0.1) inset;
}

.drop-text {
  font-size: 13px;
  color: var(--text);
  line-height: 1.6;
}

.drop-sub {
  font-size: 10px;
  color: #666;
}

.retro-btn {
  font-family: var(--font-display);
  font-size: 11px;
  background: linear-gradient(180deg, var(--bezel-light) 0%, var(--bezel-dark) 100%);
  color: var(--phosphor);
  border: 1px solid var(--bezel-light);
  border-radius: 4px;
  padding: 8px 18px;
  cursor: pointer;
  letter-spacing: 2px;
  margin-top: 10px;
  transition: all 0.2s;
}

.retro-btn:hover {
  background: linear-gradient(180deg, #444 0%, #222 100%);
  box-shadow: 0 0 10px rgba(0,255,65,0.2);
}

.retro-btn.small {
  padding: 4px 10px;
  font-size: 10px;
  margin-top: 0;
}

.rom-info {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--bezel);
}

.rom-filename {
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rom-details {
  font-size: 10px;
  color: #555;
  margin-top: 4px;
}

/* Controls Legend */
.controls-legend {
  background: var(--bg2);
  border: 1px solid var(--bezel-light);
  border-radius: 8px;
  padding: 12px;
}

.legend-title {
  font-family: var(--font-display);
  font-size: 10px;
  color: var(--amber);
  letter-spacing: 2px;
  margin-bottom: 8px;
}

.legend-row {
  font-size: 11px;
  color: #888;
  padding: 2px 0;
  display: flex;
  gap: 8px;
}

.key {
  background: var(--bezel);
  color: var(--phosphor);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  min-width: 30px;
  text-align: center;
  border: 1px solid #444;
}

/* Toolbar */
.toolbar {
  background: var(--bg2);
  border: 1px solid var(--bezel-light);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.tool-btn {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--bezel-dark);
  color: var(--text);
  border: 1px solid var(--bezel-light);
  border-radius: 4px;
  padding: 5px 10px;
  cursor: pointer;
  transition: all 0.2s;
}

.tool-btn:hover {
  background: var(--bezel);
  color: var(--phosphor);
}

.tool-btn.active {
  color: var(--phosphor);
  border-color: var(--phosphor-dim);
  box-shadow: 0 0 5px rgba(0,255,65,0.2);
}

.tool-sep {
  width: 1px;
  height: 20px;
  background: var(--bezel-light);
}

.tool-label {
  font-family: var(--font-display);
  font-size: 9px;
  color: #666;
  letter-spacing: 1px;
}

.tool-select {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bezel-dark);
  color: var(--phosphor);
  border: 1px solid var(--bezel-light);
  border-radius: 3px;
  padding: 3px 5px;
  cursor: pointer;
}

.vol-slider {
  width: 60px;
  accent-color: var(--phosphor);
}

/* Center Panel - Vectrex */
#center-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
}

/* Vectrex Bezel */
.vectrex-bezel {
  background: linear-gradient(160deg, #333 0%, #1a1a1a 30%, #111 70%, #222 100%);
  border-radius: 20px;
  padding: 20px 18px 14px;
  box-shadow:
    0 0 0 2px #444,
    0 0 0 4px #111,
    0 8px 30px rgba(0,0,0,0.8),
    inset 0 1px 0 rgba(255,255,255,0.05);
  position: relative;
}

.bezel-inner {
  background: #0a0a0a;
  border-radius: 12px;
  padding: 6px;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.8), inset 0 0 3px #000;
}

.screen-frame {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  line-height: 0;
}

#vectrex-screen {
  display: block;
  width: 330px;
  height: 410px;
  background: #020302;
  border-radius: 6px;
  image-rendering: auto;
}

.crt-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  border-radius: 6px;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.4) 100%);
}

.scanlines {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  border-radius: 6px;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(0,0,0,0.12) 1px,
    rgba(0,0,0,0.12) 2px
  );
}

.vignette {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  border-radius: 6px;
  box-shadow: inset 0 0 80px rgba(0,0,0,0.5);
}

.bezel-logo {
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 6px;
  color: #555;
  text-align: center;
  margin-top: 8px;
}

/* Virtual Controller */
.controller {
  display: flex;
  align-items: center;
  gap: 30px;
  padding: 15px 20px;
  background: linear-gradient(180deg, #222 0%, #181818 100%);
  border-radius: 12px;
  border: 1px solid #333;
}

.joystick-area {
  display: flex;
  align-items: center;
  justify-content: center;
}

.joystick-base {
  width: 80px;
  height: 80px;
  background: radial-gradient(circle, #2a2a2a 0%, #151515 100%);
  border-radius: 50%;
  border: 2px solid #444;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.5);
  touch-action: none;
}

.joystick-knob {
  width: 32px;
  height: 32px;
  background: radial-gradient(circle at 35% 35%, #555, #222);
  border-radius: 50%;
  border: 1px solid #666;
  position: absolute;
  cursor: grab;
  transition: transform 0.05s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

.buttons-area {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.ctrl-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #3a3a3a, #1a1a1a);
  border: 2px solid #555;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.1s;
  box-shadow: 0 3px 6px rgba(0,0,0,0.5);
}

.ctrl-btn:active, .ctrl-btn.pressed {
  background: radial-gradient(circle at 35% 35%, #555, #333);
  border-color: var(--phosphor);
  color: var(--phosphor);
  box-shadow: 0 0 10px rgba(0,255,65,0.3), 0 1px 3px rgba(0,0,0,0.5);
  transform: translateY(1px);
}

/* Debug Panel */
.debug-panel {
  width: 300px;
  background: var(--bg2);
  border: 1px solid var(--bezel-light);
  border-radius: 8px;
  padding: 0;
  overflow-y: auto;
  max-height: 80vh;
  flex-shrink: 0;
}

.debug-panel.hidden {
  display: none;
}

.debug-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--bezel-dark);
  border-bottom: 1px solid var(--bezel-light);
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 2px;
  border-radius: 8px 8px 0 0;
}

.debug-close {
  background: none;
  border: none;
  color: #666;
  cursor: pointer;
  font-size: 16px;
}

.debug-close:hover { color: var(--phosphor); }

.debug-section {
  padding: 8px 12px;
  border-bottom: 1px solid #1a1a1a;
}

.debug-title {
  font-family: var(--font-display);
  font-size: 9px;
  color: var(--amber);
  letter-spacing: 2px;
  margin-bottom: 6px;
}

.reg-display, .flags-display, .via-display, .vector-display {
  font-size: 11px;
  line-height: 1.8;
  color: var(--phosphor);
}

.flags-display {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.flag-indicator {
  display: inline-block;
  width: 22px;
  height: 18px;
  text-align: center;
  line-height: 18px;
  font-size: 10px;
  border-radius: 3px;
  font-family: var(--font-display);
}

.flag-indicator.on {
  background: var(--phosphor);
  color: #000;
  box-shadow: 0 0 6px var(--phosphor);
}

.flag-indicator.off {
  background: #1a1a1a;
  color: #444;
  border: 1px solid #333;
}

.disasm-display {
  font-size: 10px;
  line-height: 1.6;
  color: #888;
  max-height: 120px;
  overflow-y: auto;
}

.disasm-display .current {
  color: var(--phosphor);
  background: rgba(0,255,65,0.08);
}

.mem-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  font-size: 10px;
  color: #888;
}

.mem-addr-input {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bezel-dark);
  color: var(--phosphor);
  border: 1px solid var(--bezel-light);
  border-radius: 3px;
  padding: 3px 6px;
  width: 60px;
  text-transform: uppercase;
}

.mem-display {
  font-size: 9px;
  line-height: 1.5;
  color: var(--phosphor-dim);
  max-height: 150px;
  overflow-y: auto;
  white-space: pre;
  opacity: 0.8;
}

/* Footer */
.footer {
  text-align: center;
  padding: 20px 0 10px;
  font-size: 11px;
  color: #444;
}

.footer a {
  color: var(--accent-dim);
  text-decoration: none;
}

.footer a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.footer .sep {
  margin: 0 8px;
}

/* Responsive */
@media (max-width: 1000px) {
  #main-layout {
    flex-direction: column;
    align-items: center;
  }
  #left-panel {
    width: 100%;
    max-width: 380px;
  }
  .debug-panel {
    width: 100%;
    max-width: 380px;
  }
}

@media (max-width: 400px) {
  #vectrex-screen {
    width: 280px;
    height: 348px;
  }
  .vectrex-bezel {
    padding: 14px 12px 10px;
  }
  .controller {
    gap: 15px;
    padding: 10px;
  }
  .joystick-base {
    width: 65px;
    height: 65px;
  }
  .joystick-knob {
    width: 26px;
    height: 26px;
  }
  .ctrl-btn {
    width: 38px;
    height: 38px;
    font-size: 11px;
  }
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bezel-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--bezel); }