:root {
  --sega-blue: #0058A8;
  --sega-red: #D32F2F;
  --bg-dark: #0d0d1a;
  --bg-panel: #1a1a2e;
  --bg-bezel: #1c1c1c;
  --text-dim: #8888aa;
  --crt-glow: rgba(0, 88, 168, 0.15);
}

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

html, body {
  background: var(--bg-dark);
  color: #e0e0e0;
  font-family: 'IBM Plex Mono', monospace;
  overflow-x: hidden;
  min-height: 100vh;
}

body {
  background: radial-gradient(ellipse at center top, #16162e 0%, #0d0d1a 60%, #050510 100%);
}

/* CRT Screen Effects */
.crt-container {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  background: #000;
  box-shadow:
    0 0 60px rgba(0, 88, 168, 0.12),
    0 0 120px rgba(0, 88, 168, 0.06),
    inset 0 0 80px rgba(0,0,0,0.8);
}

.crt-screen {
  position: relative;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.crt-screen canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
  width: 100%;
  height: 100%;
}

/* Scanline overlay */
.scanlines {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(0, 0, 0, 0.2) 1px,
    rgba(0, 0, 0, 0.2) 2px
  );
  z-index: 3;
}

/* CRT curvature */
.crt-curvature {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 4;
  background: radial-gradient(
    ellipse at center,
    transparent 60%,
    rgba(0, 0, 0, 0.4) 100%
  );
  border-radius: 18px;
}

/* Phosphor glow */
.phosphor-glow {
  position: absolute;
  top: -2px; left: -2px; right: -2px; bottom: -2px;
  pointer-events: none;
  z-index: 1;
  border-radius: 20px;
  box-shadow:
    inset 0 0 40px rgba(100, 200, 255, 0.04),
    inset 0 0 80px rgba(100, 200, 255, 0.02);
}

/* Screen reflection */
.screen-reflection {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 5;
  background: linear-gradient(
    135deg,
    rgba(255,255,255,0.04) 0%,
    transparent 40%,
    transparent 60%,
    rgba(255,255,255,0.01) 100%
  );
  border-radius: 18px;
}

/* Bezel */
.bezel {
  background: linear-gradient(180deg, #2a2a2a 0%, #1c1c1c 30%, #151515 100%);
  border-radius: 24px;
  padding: 18px;
  box-shadow:
    0 8px 32px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.06),
    inset 0 -1px 0 rgba(0,0,0,0.4);
  position: relative;
}

.bezel::before {
  content: '';
  position: absolute;
  top: 2px; left: 10%; right: 10%; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent);
}

/* Console body */
.console-body {
  background: linear-gradient(180deg, #1a1a1a 0%, #111 50%, #0a0a0a 100%);
  border-radius: 12px;
  position: relative;
  overflow: hidden;
  box-shadow:
    0 4px 16px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.04);
}

.console-stripe {
  height: 6px;
  background: linear-gradient(90deg, var(--sega-red), #e53935, var(--sega-red));
  box-shadow: 0 0 12px rgba(211, 47, 47, 0.3);
}

/* Physical buttons */
.phys-btn {
  background: linear-gradient(180deg, #3a3a3a 0%, #222 100%);
  border: 2px solid #111;
  color: #ccc;
  border-radius: 6px;
  box-shadow:
    0 3px 6px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.1);
  cursor: pointer;
  transition: all 0.1s;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 1px;
}

.phys-btn:active {
  transform: translateY(2px);
  box-shadow:
    0 1px 2px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.05);
}

.phys-btn.power-btn {
  background: linear-gradient(180deg, #c62828 0%, #8e0000 100%);
  border-color: #6d0000;
  color: #fff;
}

.phys-btn.power-btn.on {
  background: linear-gradient(180deg, #2e7d32 0%, #1b5e20 100%);
  border-color: #0d3d10;
  box-shadow:
    0 3px 6px rgba(0,0,0,0.5),
    0 0 12px rgba(46, 125, 50, 0.3),
    inset 0 1px 0 rgba(255,255,255,0.1);
}

/* D-pad */
.dpad-container {
  position: relative;
  width: 120px;
  height: 120px;
}

.dpad-center {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 36px; height: 36px;
  background: #222;
  border-radius: 4px;
  z-index: 1;
}

.dpad-btn {
  position: absolute;
  background: linear-gradient(180deg, #2a2a2a, #1a1a1a);
  border: 1px solid #111;
  cursor: pointer;
  z-index: 2;
  transition: background 0.05s;
}

.dpad-btn:active, .dpad-btn.pressed {
  background: linear-gradient(180deg, #1a1a1a, #0a0a0a);
}

.dpad-up { top: 0; left: 50%; transform: translateX(-50%); width: 36px; height: 42px; border-radius: 6px 6px 0 0; }
.dpad-down { bottom: 0; left: 50%; transform: translateX(-50%); width: 36px; height: 42px; border-radius: 0 0 6px 6px; }
.dpad-left { left: 0; top: 50%; transform: translateY(-50%); width: 42px; height: 36px; border-radius: 6px 0 0 6px; }
.dpad-right { right: 0; top: 50%; transform: translateY(-50%); width: 42px; height: 36px; border-radius: 0 6px 6px 0; }

/* Action buttons */
.action-btn {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: linear-gradient(180deg, #c62828 0%, #8e0000 100%);
  border: 2px solid #6d0000;
  color: #fff;
  font-family: 'Oswald', sans-serif;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  box-shadow:
    0 3px 8px rgba(0,0,0,0.6),
    inset 0 2px 0 rgba(255,255,255,0.15);
  transition: all 0.05s;
}

.action-btn:active, .action-btn.pressed {
  transform: translateY(2px);
  box-shadow:
    0 1px 2px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.05);
}

/* LED */
.led {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  transition: all 0.3s;
}

.led-off {
  background: #4a0000;
  box-shadow: 0 0 2px rgba(74, 0, 0, 0.5);
}

.led-red {
  background: #ff1744;
  box-shadow: 0 0 8px rgba(255, 23, 68, 0.6);
}

.led-green {
  background: #00e676;
  box-shadow: 0 0 8px rgba(0, 230, 118, 0.6);
}

/* Upload screen styles */
.bios-screen {
  background: #0044cc;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: 'IBM Plex Mono', monospace;
}

.bios-grid {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.04) 1px, transparent 1px);
  background-size: 16px 16px;
  pointer-events: none;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

.blink-cursor::after {
  content: '█';
  animation: blink 1s infinite;
  margin-left: 2px;
}

/* Loading animation */
@keyframes loading-dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

.loading-text::after {
  content: '';
  animation: loading-dots 1.2s infinite;
}

/* Debug panel */
.debug-panel {
  background: rgba(10, 10, 26, 0.95);
  border: 1px solid rgba(0, 88, 168, 0.2);
  border-radius: 8px;
  font-size: 11px;
  line-height: 1.4;
}

.debug-section {
  border-bottom: 1px solid rgba(255,255,255,0.05);
  padding: 8px 12px;
}

.debug-label {
  color: var(--sega-blue);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.register-val {
  color: #4fc3f7;
  font-weight: 600;
}

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

.modal-content {
  background: var(--bg-panel);
  border: 1px solid rgba(0, 88, 168, 0.3);
  border-radius: 12px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0, 88, 168, 0.3); border-radius: 3px; }

/* Touch device gamepad visibility */
@media (hover: hover) and (pointer: fine) {
  .touch-gamepad { display: none !important; }
}

@media (hover: none), (pointer: coarse) {
  .touch-gamepad { display: flex !important; }
}

/* Waveform canvas */
.waveform-canvas {
  image-rendering: auto;
}

/* Key reference */
.key-ref {
  display: inline-block;
  background: #333;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 600;
  color: #ccc;
  box-shadow: 0 2px 0 #222;
}