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

:root {
  --green: #00FF41;
  --green-dim: #00aa2a;
  --green-dark: #005511;
  --bg: #0a0a0a;
  --panel-bg: #111111;
  --bezel: #1a1a1a;
  --bezel-edge: #2a2a2a;
  --text: #cccccc;
  --glow: 0 0 10px #00FF41, 0 0 20px #00FF4166, 0 0 40px #00FF4133;
  --glow-sm: 0 0 5px #00FF41, 0 0 10px #00FF4166;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'VT323', 'Share Tech Mono', monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

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

#title {
  font-family: 'VT323', monospace;
  font-size: 56px;
  color: var(--green);
  text-shadow: var(--glow);
  letter-spacing: 8px;
  line-height: 1;
}

#title .dot {
  color: #ff4444;
  text-shadow: 0 0 10px #ff4444, 0 0 20px #ff444466;
}

#subtitle {
  color: var(--green-dim);
  font-size: 18px;
  letter-spacing: 4px;
  text-shadow: var(--glow-sm);
  margin-top: 4px;
}

/* Cartridge Slot */
.cartridge-slot {
  max-width: 600px;
  margin: 16px auto;
  background: linear-gradient(180deg, #222 0%, #181818 100%);
  border: 2px solid #333;
  border-radius: 8px;
  padding: 4px;
  position: relative;
}

.cartridge-slot::before {
  content: '';
  position: absolute;
  top: -4px; left: 20%; right: 20%;
  height: 4px;
  background: var(--green-dark);
  border-radius: 2px 2px 0 0;
  box-shadow: var(--glow-sm);
}

.upload-zone {
  padding: 20px;
  text-align: center;
  cursor: pointer;
  border: 1px dashed #444;
  border-radius: 6px;
  transition: all 0.3s;
}

.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--green);
  background: #001a0a;
  box-shadow: inset 0 0 30px #00FF4111;
}

.slot-label {
  font-size: 14px;
  color: #555;
  letter-spacing: 6px;
  margin-bottom: 8px;
}

.upload-text {
  color: var(--green-dim);
  font-size: 18px;
}

.rom-info {
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--green);
  font-size: 16px;
}

.rom-info #rom-name { flex: 1; text-shadow: var(--glow-sm); }
.rom-info #rom-size { color: var(--green-dim); }

.hidden { display: none !important; }

/* Main Layout */
#main-area {
  display: flex;
  gap: 20px;
  justify-content: center;
  align-items: flex-start;
  margin: 16px 0;
  flex-wrap: wrap;
}

/* Vectrex Housing */
#vectrex-housing {
  background: linear-gradient(145deg, #222 0%, #111 50%, #1a1a1a 100%);
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 0 40px #00000088, inset 0 1px 0 #333, 0 4px 20px #000;
  border: 1px solid #2a2a2a;
  position: relative;
}

#vectrex-housing::before {
  content: '';
  position: absolute;
  top: 8px; left: 8px; right: 8px; bottom: 8px;
  border-radius: 16px;
  border: 1px solid #1f1f1f;
  pointer-events: none;
}

#screen-bezel {
  background: #000;
  border-radius: 12px;
  padding: 8px;
  position: relative;
  box-shadow: inset 0 0 20px #000, 0 0 2px #333;
  overflow: hidden;
}

#canvas {
  display: block;
  background: #000;
  border-radius: 6px;
  width: 360px;
  height: 480px;
}

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

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

#screen-overlay-label {
  position: absolute;
  top: 16px; left: 0; right: 0;
  text-align: center;
  color: #00FF4133;
  font-size: 14px;
  letter-spacing: 4px;
  z-index: 4;
  pointer-events: none;
}

/* Side Panel */
#side-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 260px;
  max-width: 300px;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid #2a2a2a;
  border-radius: 10px;
  padding: 14px;
}

.panel h3 {
  color: var(--green);
  font-size: 18px;
  letter-spacing: 3px;
  margin-bottom: 10px;
  text-shadow: var(--glow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Buttons */
.btn {
  font-family: 'VT323', monospace;
  font-size: 16px;
  background: #1a1a1a;
  color: var(--green);
  border: 1px solid #333;
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
  transition: all 0.2s;
  text-shadow: var(--glow-sm);
}

.btn:hover {
  background: #002a11;
  border-color: var(--green);
  box-shadow: 0 0 10px #00FF4133;
}

.btn:active { transform: scale(0.97); }

.btn-sm { font-size: 13px; padding: 4px 10px; }
.btn-close { background: transparent; border: none; color: #666; font-size: 18px; }
.btn-close:hover { color: #ff4444; }

.btn-eject {
  background: #2a1111;
  border-color: #662222;
  color: #ff6666;
}
.btn-eject:hover { background: #441111; border-color: #ff4444; }

.btn-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 15px;
}

.control-row label { color: #888; }

.control-row select {
  font-family: 'VT323', monospace;
  font-size: 15px;
  background: #1a1a1a;
  color: var(--green);
  border: 1px solid #333;
  border-radius: 4px;
  padding: 2px 8px;
}

.control-row input[type="checkbox"] {
  appearance: none;
  width: 40px; height: 20px;
  background: #222;
  border: 1px solid #444;
  border-radius: 10px;
  position: relative;
  cursor: pointer;
  transition: all 0.2s;
}

.control-row input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #555;
  transition: all 0.2s;
}

.control-row input[type="checkbox"]:checked {
  background: #002a11;
  border-color: var(--green-dim);
}

.control-row input[type="checkbox"]:checked::after {
  left: 22px;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

/* D-Pad */
#dpad-area {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.dpad {
  display: grid;
  grid-template-columns: 40px 40px 40px;
  grid-template-rows: 40px 40px 40px;
  gap: 2px;
}

.dpad-btn {
  font-family: 'VT323', monospace;
  font-size: 18px;
  background: #222;
  color: #888;
  border: 1px solid #333;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s;
  user-select: none;
  -webkit-user-select: none;
}

.dpad-btn:active, .dpad-btn.active {
  background: #003a15;
  color: var(--green);
  border-color: var(--green-dim);
}

.dpad-center {
  background: #1a1a1a;
  border-radius: 50%;
  cursor: default;
}

.dpad-up { grid-column: 2; grid-row: 1; }
.dpad-left { grid-column: 1; grid-row: 2; }
.dpad-center { grid-column: 2; grid-row: 2; }
.dpad-right { grid-column: 3; grid-row: 2; }
.dpad-down { grid-column: 2; grid-row: 3; }

/* Game Buttons */
#buttons-area {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.game-btn {
  font-family: 'VT323', monospace;
  font-size: 20px;
  width: 50px; height: 50px;
  background: radial-gradient(circle at 30% 30%, #333, #1a1a1a);
  color: #aaa;
  border: 2px solid #444;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all 0.1s;
  user-select: none;
  -webkit-user-select: none;
}

.game-btn span {
  font-size: 10px;
  color: #555;
}

.game-btn:active, .game-btn.active {
  background: radial-gradient(circle at 30% 30%, #004a1a, #002a0a);
  color: var(--green);
  border-color: var(--green-dim);
  box-shadow: 0 0 10px #00FF4133;
}

/* Debug Panel */
.debug-panel {
  max-width: 800px;
  margin: 16px auto;
  max-height: 300px;
  overflow-y: auto;
}

#debug-content {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  font-size: 14px;
  color: var(--green-dim);
}

#debug-content > div {
  background: #0a0a0a;
  border: 1px solid #222;
  border-radius: 6px;
  padding: 8px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 13px;
  white-space: pre;
  line-height: 1.5;
}

/* Help Overlay */
.overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.overlay-content {
  background: var(--panel-bg);
  border: 1px solid var(--green-dark);
  border-radius: 12px;
  padding: 24px;
  max-width: 400px;
  width: 90%;
  text-align: center;
}

.overlay-content h3 {
  color: var(--green);
  font-size: 22px;
  letter-spacing: 3px;
  margin-bottom: 16px;
  text-shadow: var(--glow-sm);
}

.key-grid {
  text-align: left;
  margin-bottom: 16px;
}

.key-grid div {
  padding: 4px 0;
  font-size: 16px;
  color: #aaa;
}

kbd {
  background: #222;
  border: 1px solid #444;
  border-radius: 4px;
  padding: 2px 8px;
  color: var(--green);
  font-family: 'VT323', monospace;
  font-size: 15px;
}

/* Footer */
#footer {
  text-align: center;
  padding: 20px 0;
  border-top: 1px solid #1a1a1a;
  margin-top: 20px;
}

#footer a {
  color: var(--green-dim);
  text-decoration: none;
  font-size: 16px;
  letter-spacing: 2px;
  text-shadow: var(--glow-sm);
  transition: all 0.3s;
}

#footer a:hover {
  color: var(--green);
  text-shadow: var(--glow);
}

/* Responsive */
@media (max-width: 800px) {
  #main-area { flex-direction: column; align-items: center; }
  #side-panel { max-width: 400px; width: 100%; }
  #canvas { width: 300px; height: 400px; }
  #title { font-size: 36px; letter-spacing: 4px; }
  #debug-content { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  #canvas { width: 260px; height: 347px; }
  #title { font-size: 28px; }
  .game-btn { width: 44px; height: 44px; font-size: 18px; }
}