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

:root {
  --sega-blue: #0033aa;
  --sega-blue-light: #0055dd;
  --sega-dark: #0a0a14;
  --sega-darker: #050510;
  --bezel-color: #1a1a2e;
  --text-primary: #e0e0e0;
  --text-dim: #808090;
  --red-accent: #cc2222;
  --green-accent: #00cc44;
  --crt-glow: rgba(0, 100, 255, 0.05);
}

html, body {
  background: var(--sega-darker);
  color: var(--text-primary);
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  line-height: 1.6;
  overflow-x: hidden;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* HEADER */
#header {
  background: linear-gradient(135deg, #000066 0%, var(--sega-blue) 50%, var(--sega-blue-light) 100%);
  padding: 12px 16px;
  border-bottom: 3px solid #0066ff;
  box-shadow: 0 4px 20px rgba(0, 50, 200, 0.3);
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 900px;
  margin: 0 auto;
}

#header h1 {
  font-size: 14px;
  letter-spacing: 3px;
  text-shadow: 0 0 10px rgba(100, 150, 255, 0.5), 2px 2px 0 #000033;
  color: white;
}

.badge {
  font-size: 8px;
  background: rgba(255,255,255,0.15);
  padding: 4px 8px;
  border-radius: 4px;
  color: #ffcc00;
}

/* MAIN */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 10px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

/* UPLOAD */
.upload-zone {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 30px;
  width: 100%;
  max-width: 500px;
}

.cartridge-slot {
  background: linear-gradient(180deg, #222 0%, #111 100%);
  border: 3px solid #333;
  border-radius: 12px;
  padding: 40px 30px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  width: 100%;
  position: relative;
  box-shadow: inset 0 2px 20px rgba(0,0,0,0.5), 0 0 30px rgba(0,50,150,0.1);
}

.cartridge-slot:hover {
  border-color: var(--sega-blue-light);
  box-shadow: inset 0 2px 20px rgba(0,0,0,0.5), 0 0 40px rgba(0,80,200,0.2);
}

.cartridge-slot.drag-over {
  border-color: var(--green-accent);
  box-shadow: 0 0 40px rgba(0,200,100,0.3);
}

.slot-opening {
  width: 80%;
  height: 6px;
  background: #000;
  border: 1px solid #222;
  margin: 0 auto 20px;
  border-radius: 2px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.8);
}

.slot-label {
  font-size: 14px;
  color: #fff;
  margin-bottom: 8px;
  text-shadow: 0 0 8px rgba(0,100,255,0.4);
}

.slot-sub {
  font-size: 7px;
  color: var(--text-dim);
  margin-bottom: 20px;
}

/* BUTTONS */
.retro-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  background: linear-gradient(180deg, #444 0%, #222 100%);
  color: #ddd;
  border: 2px solid #555;
  border-radius: 4px;
  padding: 8px 16px;
  cursor: pointer;
  transition: all 0.15s;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.retro-btn:hover {
  background: linear-gradient(180deg, #555 0%, #333 100%);
  border-color: var(--sega-blue-light);
  color: white;
}

.retro-btn:active {
  transform: scale(0.95);
  background: linear-gradient(180deg, #333 0%, #111 100%);
}

/* DISPLAY */
.display-wrapper {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
}

.crt-bezel {
  background: linear-gradient(145deg, #2a2a3a 0%, #1a1a28 50%, #222235 100%);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.05);
  border: 2px solid #333;
}

.crt-screen {
  position: relative;
  width: 100%;
  padding-bottom: 75%; /* 4:3 */
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: inset 0 0 60px rgba(0,0,0,0.8), 0 0 2px var(--crt-glow);
}

.crt-screen canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.scanlines {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(0, 0, 0, 0.15) 1px,
    rgba(0, 0, 0, 0.15) 2px
  );
  pointer-events: none;
  z-index: 2;
}

.scanlines.off { display: none; }

.vignette {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.4) 100%);
  pointer-events: none;
  z-index: 3;
}

/* CONTROLS */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 14px;
  padding: 0 10px;
}

.ctrl-btn {
  font-size: 7px;
  padding: 6px 10px;
}

/* GAMEPAD */
.gamepad {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 400px;
  margin-top: 16px;
  padding: 16px;
  background: linear-gradient(180deg, #1a1a1a 0%, #0d0d0d 100%);
  border: 2px solid #333;
  border-radius: 30px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

.gp-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.gp-lr {
  display: flex;
  gap: 24px;
}

.gp-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  width: 40px; height: 40px;
  border: none;
  border-radius: 4px;
  background: #333;
  color: #ccc;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

.gp-btn:active { background: #555; }

.gp-1, .gp-2 {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--red-accent);
  color: white;
  font-size: 12px;
  border: 3px solid #881111;
}

.gp-1:active, .gp-2:active {
  background: #ff3333;
}

.gp-right {
  display: flex;
  gap: 12px;
  align-items: center;
}

.gp-start {
  font-size: 7px;
  width: auto;
  padding: 8px 14px;
  border-radius: 12px;
}

/* KEYBOARD HELP */
.keyboard-help {
  margin-top: 12px;
  max-width: 500px;
  width: 100%;
}

.help-title {
  font-size: 8px;
  color: var(--text-dim);
  cursor: pointer;
  text-align: center;
  padding: 6px;
}

.help-title:hover { color: var(--sega-blue-light); }

.key-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  justify-content: center;
  padding: 8px;
  font-size: 7px;
  color: var(--text-dim);
  background: rgba(255,255,255,0.03);
  border-radius: 6px;
}

/* DEBUG */
.debug-panel {
  position: fixed;
  top: 0; right: 0;
  width: 320px;
  height: 100vh;
  background: rgba(5, 10, 5, 0.95);
  border-left: 2px solid #004400;
  color: #00ff44;
  font-family: 'Courier New', monospace;
  font-size: 10px;
  padding: 12px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: -4px 0 20px rgba(0,0,0,0.5);
}

.debug-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: #00ff44;
  margin-bottom: 10px;
  text-shadow: 0 0 6px rgba(0,255,50,0.4);
}

#debug-content {
  white-space: pre;
  line-height: 1.5;
  font-size: 9px;
}

/* STATUS */
.status-bar {
  display: flex;
  justify-content: space-between;
  padding: 6px 16px;
  font-size: 7px;
  color: var(--text-dim);
  background: #0a0a14;
  border-top: 1px solid #222;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

/* FOOTER */
#footer {
  display: flex;
  justify-content: center;
  gap: 20px;
  padding: 12px;
  font-size: 7px;
  color: var(--text-dim);
  border-top: 1px solid #1a1a2e;
}

#footer a {
  color: var(--sega-blue-light);
  text-decoration: none;
}

#footer a:hover {
  text-decoration: underline;
}

.hidden { display: none !important; }

/* Responsive */
@media (max-width: 600px) {
  #header h1 { font-size: 10px; letter-spacing: 1px; }
  .crt-bezel { padding: 10px; border-radius: 10px; }
  .slot-label { font-size: 11px; }
  .status-bar { font-size: 6px; flex-wrap: wrap; gap: 4px; }
  .debug-panel { width: 100%; height: 50vh; top: auto; bottom: 0; border-left: none; border-top: 2px solid #004400; }
  .controls { gap: 4px; }
  .ctrl-btn { font-size: 6px; padding: 5px 7px; }
}