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

:root {
  --phosphor: #33FF33;
  --phosphor-dim: #115511;
  --bg-dark: #0A0A0A;
  --bg-panel: #141414;
  --bg-bezel: #1A1A1A;
  --bg-console: #111111;
  --bg-slot: #0D0D0D;
  --text-dim: #556655;
  --glow-sm: 0 0 4px var(--phosphor);
  --glow-md: 0 0 10px var(--phosphor);
  --glow-lg: 0 0 20px var(--phosphor), 0 0 40px var(--phosphor);
}

body {
  background: var(--bg-dark);
  color: var(--phosphor);
  font-family: 'VT323', 'Share Tech Mono', monospace;
  overflow-x: hidden;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 10px;
}

#app-container {
  width: 100%;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

#console-body {
  width: 100%;
  background: linear-gradient(145deg, #181818 0%, #0E0E0E 50%, #151515 100%);
  border-radius: 18px;
  padding: 16px;
  border: 2px solid #222;
  box-shadow: 0 0 40px rgba(0,0,0,0.8), inset 0 1px 0 rgba(255,255,255,0.03);
  position: relative;
  overflow: hidden;
}

#console-body::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='4' height='4' xmlns='http://www.w3.org/2000/svg'%3E%3Crect width='1' height='1' fill='%23ffffff08'/%3E%3C/svg%3E") repeat;
  pointer-events: none;
  border-radius: 18px;
}

#console-top {
  text-align: center;
  margin-bottom: 10px;
}

#vectrex-logo {
  font-family: 'VT323', monospace;
  font-size: 42px;
  letter-spacing: 14px;
  color: var(--phosphor);
  text-shadow: var(--glow-lg);
  margin-bottom: 8px;
  text-transform: uppercase;
  user-select: none;
}

#cart-slot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px;
  background: var(--bg-slot);
  border-radius: 8px;
  border: 1px solid #222;
}

#cart-slot-inner {
  background: #0A0A0A;
  border: 1px solid #333;
  border-radius: 4px;
  padding: 4px 12px;
  min-width: 160px;
  text-align: center;
}

#cart-label {
  font-size: 14px;
  color: var(--text-dim);
  transition: color 0.3s;
}

#cart-label.loaded {
  color: var(--phosphor);
  text-shadow: var(--glow-sm);
}

#cart-drop-zone {
  cursor: pointer;
  padding: 6px 14px;
  background: #1A1A1A;
  border: 1px dashed #444;
  border-radius: 6px;
  font-size: 15px;
  transition: all 0.3s;
}

#cart-drop-zone:hover, #cart-drop-zone.dragover {
  border-color: var(--phosphor);
  background: #1A2A1A;
  box-shadow: var(--glow-sm);
}

#cart-drop-text {
  color: #888;
  font-size: 14px;
}

#demo-selector {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

#demo-selector label {
  color: #666;
  font-size: 12px;
}

#demo-select {
  background: #1A1A1A;
  color: var(--phosphor);
  border: 1px solid #333;
  border-radius: 4px;
  padding: 3px 6px;
  font-family: 'VT323', monospace;
  font-size: 14px;
  cursor: pointer;
}

#demo-select:focus {
  outline: none;
  border-color: var(--phosphor);
  box-shadow: var(--glow-sm);
}

/* Screen */
#screen-bezel {
  background: linear-gradient(135deg, #0D0D0D, #1A1A1A, #0D0D0D);
  border-radius: 14px;
  padding: 12px;
  margin: 8px auto;
  border: 3px solid #222;
  box-shadow: inset 0 0 30px rgba(0,0,0,0.9), 0 0 20px rgba(0,0,0,0.5);
  max-width: 540px;
}

#screen-curvature {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 1;
  background: #000;
}

#canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: auto;
}

#scanline-overlay {
  position: absolute;
  inset: 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;
}

#screen-reflection {
  position: absolute;
  top: -20%;
  left: -20%;
  width: 60%;
  height: 60%;
  background: radial-gradient(ellipse, rgba(255,255,255,0.02) 0%, transparent 70%);
  pointer-events: none;
  transform: rotate(-30deg);
}

/* Controls Bar */
#controls-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  margin-top: 6px;
  background: #0D0D0D;
  border-radius: 8px;
  border: 1px solid #1A1A1A;
  align-items: center;
  justify-content: center;
}

.control-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.control-group label {
  font-size: 11px;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.switch {
  width: 48px;
  height: 24px;
  background: #222;
  border-radius: 12px;
  cursor: pointer;
  position: relative;
  border: 1px solid #333;
  transition: all 0.3s;
}

.switch .switch-handle {
  width: 20px;
  height: 20px;
  background: #555;
  border-radius: 50%;
  position: absolute;
  top: 1px;
  left: 1px;
  transition: all 0.3s;
}

.switch.on {
  background: #1A2A1A;
  border-color: var(--phosphor);
  box-shadow: var(--glow-sm);
}

.switch.on .switch-handle {
  left: 25px;
  background: var(--phosphor);
  box-shadow: var(--glow-md);
}

input[type="range"] {
  width: 80px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: #333;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--phosphor);
  border-radius: 50%;
  box-shadow: var(--glow-sm);
  cursor: pointer;
}

#speed-label {
  font-size: 12px;
  color: #888;
}

#color-options {
  display: flex;
  gap: 4px;
}

.color-opt {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
}

.color-opt:hover {
  transform: scale(1.2);
}

.color-opt.selected {
  border-color: #fff;
  box-shadow: 0 0 8px currentColor;
}

.ctrl-btn {
  background: #1A1A1A;
  color: var(--phosphor);
  border: 1px solid #333;
  border-radius: 4px;
  padding: 4px 10px;
  font-family: 'VT323', monospace;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.ctrl-btn:hover {
  background: #222;
  border-color: var(--phosphor);
  box-shadow: var(--glow-sm);
}

.ctrl-btn:active {
  transform: scale(0.95);
}

.ctrl-btn.small {
  font-size: 12px;
  padding: 2px 8px;
}

/* Virtual Controller */
#virtual-controller {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 40px;
  padding: 14px;
  margin-top: 6px;
}

#joystick-base {
  width: 120px;
  height: 120px;
  background: radial-gradient(circle, #222 0%, #111 100%);
  border-radius: 50%;
  border: 2px solid #333;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.8);
}

#joystick-knob {
  width: 40px;
  height: 40px;
  background: radial-gradient(circle at 35% 35%, #444, #222);
  border-radius: 50%;
  border: 1px solid #555;
  position: absolute;
  transition: transform 0.1s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.6);
  z-index: 2;
}

.joy-dir {
  position: absolute;
  font-size: 14px;
  color: #444;
  user-select: none;
}

.joy-dir.joy-up { top: 8px; }
.joy-dir.joy-down { bottom: 8px; }
.joy-dir.joy-left { left: 10px; }
.joy-dir.joy-right { right: 10px; }

.joy-dir.active {
  color: var(--phosphor);
  text-shadow: var(--glow-sm);
}

#button-area {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.game-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #2A2A2A, #151515);
  border: 2px solid #333;
  color: #666;
  font-family: 'VT323', monospace;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.1s;
  box-shadow: 0 3px 6px rgba(0,0,0,0.6);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.game-btn:active, .game-btn.pressed {
  transform: translateY(2px);
  box-shadow: 0 1px 2px rgba(0,0,0,0.4);
  background: radial-gradient(circle at 35% 35%, #333, #1A1A1A);
  border-color: var(--phosphor);
  color: var(--phosphor);
  text-shadow: var(--glow-sm);
}

/* Keymap */
#keymap-toggle {
  text-align: center;
  margin-top: 4px;
}

#keymap-legend {
  margin-top: 4px;
  font-size: 12px;
  color: #555;
  line-height: 1.6;
}

#keymap-legend.hidden {
  display: none;
}

/* Sound Note */
#sound-note {
  text-align: center;
  font-size: 12px;
  color: #444;
  margin-top: 6px;
}

/* Debug Panel */
#debug-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 340px;
  height: 100vh;
  background: #0D0D0D;
  border-left: 2px solid #222;
  overflow-y: auto;
  z-index: 1000;
  font-size: 13px;
  transition: transform 0.3s;
}

#debug-panel.hidden {
  transform: translateX(100%);
}

#debug-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #141414;
  border-bottom: 1px solid #222;
  position: sticky;
  top: 0;
  z-index: 1;
}

#debug-header span {
  color: var(--phosphor);
  text-shadow: var(--glow-sm);
  font-size: 15px;
}

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

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

#debug-content {
  padding: 8px;
}

#debug-content h3 {
  color: var(--phosphor);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin: 10px 0 4px;
  border-bottom: 1px solid #1A1A1A;
  padding-bottom: 2px;
}

#reg-display, #flag-display, #disasm-display, #vector-display, #memory-display {
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  color: #8A8;
  line-height: 1.5;
  white-space: pre;
  overflow-x: auto;
  padding: 4px;
  background: #0A0A0A;
  border-radius: 4px;
  margin-bottom: 6px;
  max-height: 200px;
  overflow-y: auto;
}

/* Status Bar */
#status-bar {
  width: 100%;
  max-width: 800px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 6px 12px;
  background: #0D0D0D;
  border: 1px solid #1A1A1A;
  border-radius: 0 0 8px 8px;
  font-size: 12px;
  color: #555;
  justify-content: center;
}

#status-bar span {
  white-space: nowrap;
}

/* Footer */
#app-footer {
  margin-top: 14px;
  text-align: center;
}

#app-footer a {
  color: var(--phosphor);
  text-decoration: none;
  font-size: 13px;
  opacity: 0.6;
  text-shadow: var(--glow-sm);
  transition: opacity 0.3s;
}

#app-footer a:hover {
  opacity: 1;
}

/* Responsive */
@media (max-width: 600px) {
  body { padding: 4px; }
  #console-body { padding: 8px; border-radius: 12px; }
  #vectrex-logo { font-size: 28px; letter-spacing: 8px; }
  #screen-bezel { padding: 6px; }
  #controls-bar { gap: 4px; padding: 6px; }
  input[type="range"] { width: 60px; }
  .ctrl-btn { padding: 3px 6px; font-size: 12px; }
  #virtual-controller { gap: 20px; }
  #joystick-base { width: 90px; height: 90px; }
  #joystick-knob { width: 30px; height: 30px; }
  .game-btn { width: 44px; height: 44px; font-size: 16px; }
  #debug-panel { width: 100%; }
  #cart-slot { gap: 4px; }
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #0A0A0A; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }