* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --neon-green: #39ff14;
  --neon-blue: #00f0ff;
  --neon-pink: #ff2d95;
  --neon-yellow: #ffe600;
  --neon-purple: #b026ff;
  --bg-dark: #0a0a12;
  --bg-card: #12121f;
  --crt-curve: 3px;
  --scanline-opacity: 0.12;
}

body {
  background: var(--bg-dark);
  font-family: 'Press Start 2P', monospace;
  color: #fff;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  position: relative;
}

#bg-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0;
  pointer-events: none;
}

#crt-overlay {
  position: fixed;
  top: -2px; left: -2px;
  right: -2px; bottom: -2px;
  z-index: 9999;
  pointer-events: none;
  border-radius: var(--crt-curve);
  box-shadow: inset 0 0 80px rgba(0,0,0,0.6), inset 0 0 20px rgba(0,0,0,0.3);
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.4) 100%);
}

#scanlines {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 9998;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,var(--scanline-opacity)) 2px,
    rgba(0,0,0,var(--scanline-opacity)) 4px
  );
}

#app {
  position: relative;
  z-index: 10;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  overflow-x: hidden;
}

#game-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 50;
  display: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Boot Screen */
.boot-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100vh;
  position: relative;
}

.boot-static {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: repeating-linear-gradient(
    0deg,
    rgba(255,255,255,0.03) 0px,
    transparent 1px,
    transparent 2px
  );
  animation: staticFlicker 0.1s infinite;
  opacity: 0;
}

.boot-static.active {
  opacity: 1;
}

@keyframes staticFlicker {
  0% { opacity: 0.8; }
  50% { opacity: 0.4; }
  100% { opacity: 0.9; }
}

.boot-title {
  font-size: clamp(16px, 4vw, 40px);
  text-align: center;
  padding: 0 20px;
  animation: rainbowCycle 3s linear infinite;
  text-shadow: 0 0 20px var(--neon-blue), 0 0 40px var(--neon-purple);
  opacity: 0;
  transition: opacity 0.5s;
}

.boot-title.visible { opacity: 1; }

@keyframes rainbowCycle {
  0% { color: #ff2d95; }
  16% { color: #ff6600; }
  33% { color: #ffe600; }
  50% { color: #39ff14; }
  66% { color: #00f0ff; }
  83% { color: #b026ff; }
  100% { color: #ff2d95; }
}

.press-start {
  margin-top: 40px;
  font-size: clamp(10px, 2vw, 18px);
  color: #fff;
  animation: blink 1s step-end infinite;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.5s;
}

.press-start.visible { opacity: 1; }

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

/* Main Menu */
.main-menu {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  animation: fadeIn 0.3s;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.menu-title {
  font-size: clamp(12px, 3vw, 28px);
  margin: 20px 0 10px;
  animation: rainbowCycle 3s linear infinite;
  text-shadow: 0 0 15px var(--neon-blue);
  text-align: center;
}

.menu-subtitle {
  font-size: clamp(7px, 1.2vw, 11px);
  color: var(--neon-blue);
  margin-bottom: 30px;
  opacity: 0.7;
}

/* Console Carousel */
.console-carousel {
  display: flex;
  gap: 20px;
  padding: 20px;
  overflow-x: auto;
  max-width: 100%;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.console-carousel::-webkit-scrollbar { display: none; }

.console-card {
  flex: 0 0 auto;
  width: clamp(130px, 20vw, 180px);
  height: clamp(160px, 25vw, 220px);
  background: var(--bg-card);
  border: 2px solid #333;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  transition: all 0.2s;
  scroll-snap-align: center;
  position: relative;
  overflow: hidden;
}

.console-card::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(0,240,255,0.05) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.3s;
}

.console-card:hover::before,
.console-card.selected::before {
  opacity: 1;
}

.console-card:hover,
.console-card.selected {
  border-color: var(--neon-blue);
  box-shadow: 0 0 20px rgba(0,240,255,0.3), inset 0 0 20px rgba(0,240,255,0.05);
  transform: translateY(-4px);
}

.console-card img {
  width: 64px;
  height: 64px;
  image-rendering: pixelated;
}

.console-card .console-icon {
  font-size: 48px;
  line-height: 1;
}

.console-card .console-name {
  font-size: clamp(6px, 1.2vw, 9px);
  text-align: center;
  color: var(--neon-green);
  padding: 0 8px;
}

.console-card .console-era {
  font-size: clamp(5px, 1vw, 7px);
  color: #666;
}

/* Game Library Grid */
.game-library {
  width: 100%;
  max-width: 900px;
  padding: 20px;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.library-header {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 20px;
}

.back-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  background: none;
  border: 2px solid var(--neon-pink);
  color: var(--neon-pink);
  padding: 8px 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.back-btn:hover {
  background: var(--neon-pink);
  color: #000;
  box-shadow: 0 0 15px rgba(255,45,149,0.4);
}

.library-title {
  font-size: clamp(10px, 2vw, 16px);
  color: var(--neon-yellow);
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 15px;
}

.game-card {
  background: var(--bg-card);
  border: 2px solid #2a2a3a;
  border-radius: 6px;
  padding: 12px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.game-card:hover {
  border-color: var(--neon-green);
  box-shadow: 0 0 15px rgba(57,255,20,0.2);
  transform: scale(1.03);
}

.game-card img {
  width: 100%;
  max-width: 128px;
  height: 96px;
  object-fit: contain;
  image-rendering: pixelated;
  background: #0a0a0f;
  border-radius: 4px;
}

.game-card .game-title {
  font-size: clamp(6px, 1.1vw, 8px);
  color: #fff;
  text-align: center;
}

.game-card .game-genre {
  font-size: 6px;
  color: var(--neon-blue);
  background: rgba(0,240,255,0.1);
  padding: 3px 8px;
  border-radius: 3px;
}

.game-card .game-stars {
  color: var(--neon-yellow);
  font-size: 8px;
}

.play-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  background: var(--neon-green);
  color: #000;
  border: none;
  padding: 6px 14px;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 4px;
}

.play-btn:hover {
  box-shadow: 0 0 20px rgba(57,255,20,0.5);
  transform: scale(1.1);
}

/* Game HUD */
.game-hud {
  position: fixed;
  top: 0; left: 0;
  width: 100%;
  z-index: 60;
  display: none;
  justify-content: space-between;
  align-items: center;
  padding: 8px 15px;
  background: rgba(0,0,0,0.85);
  border-bottom: 2px solid var(--neon-blue);
  font-size: clamp(6px, 1.2vw, 10px);
}

.game-hud .hud-left { color: var(--neon-green); }
.game-hud .hud-center { color: var(--neon-yellow); }
.game-hud .hud-right { color: var(--neon-pink); }

/* Pause Menu */
.pause-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.8);
  z-index: 70;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.pause-overlay .pause-title {
  font-size: 20px;
  color: var(--neon-yellow);
  animation: blink 1.5s step-end infinite;
}

.pause-overlay button {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  padding: 12px 30px;
  border: 2px solid var(--neon-blue);
  background: transparent;
  color: var(--neon-blue);
  cursor: pointer;
  transition: all 0.2s;
}

.pause-overlay button:hover {
  background: var(--neon-blue);
  color: #000;
}

/* High Scores */
.highscores-screen {
  width: 100%;
  max-width: 600px;
  padding: 20px;
  animation: fadeIn 0.3s;
}

.score-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 15px;
}

.score-table th, .score-table td {
  padding: 8px 12px;
  font-size: clamp(6px, 1.1vw, 9px);
  text-align: left;
  border-bottom: 1px solid #222;
}

.score-table th {
  color: var(--neon-blue);
  border-bottom: 2px solid var(--neon-blue);
}

.score-table td { color: var(--neon-green); }
.score-table tr:nth-child(1) td { color: var(--neon-yellow); }

/* Settings */
.settings-screen {
  width: 100%;
  max-width: 500px;
  padding: 20px;
  animation: fadeIn 0.3s;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #222;
  font-size: clamp(6px, 1.2vw, 9px);
}

.setting-row label { color: var(--neon-blue); }

.setting-row input[type="range"] {
  width: 120px;
  accent-color: var(--neon-green);
}

.setting-row select, .setting-row button {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  background: var(--bg-card);
  color: var(--neon-green);
  border: 1px solid #444;
  padding: 5px 10px;
  cursor: pointer;
}

/* Nav */
.nav-bar {
  display: flex;
  gap: 10px;
  margin: 15px 0 5px;
  flex-wrap: wrap;
  justify-content: center;
}

.nav-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(6px, 1vw, 8px);
  background: none;
  border: 1px solid #444;
  color: #888;
  padding: 6px 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.nav-btn:hover, .nav-btn.active {
  border-color: var(--neon-blue);
  color: var(--neon-blue);
}

/* Footer */
.footer {
  margin-top: auto;
  padding: 20px;
  text-align: center;
  font-size: 7px;
  color: #555;
  width: 100%;
}

.footer a {
  color: var(--neon-pink);
  text-decoration: none;
}

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

.marquee {
  overflow: hidden;
  white-space: nowrap;
  margin-top: 8px;
}

.marquee span {
  display: inline-block;
  animation: marqueeScroll 15s linear infinite;
  color: var(--neon-green);
  font-size: 6px;
}

@keyframes marqueeScroll {
  0% { transform: translateX(100vw); }
  100% { transform: translateX(-100%); }
}

/* Game Over Overlay */
.gameover-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.85);
  z-index: 70;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 15px;
}

.gameover-overlay .go-title {
  font-size: clamp(16px, 4vw, 28px);
  color: var(--neon-pink);
  text-shadow: 0 0 20px var(--neon-pink);
}

.gameover-overlay .go-score {
  font-size: clamp(10px, 2vw, 16px);
  color: var(--neon-yellow);
}

.initials-input {
  display: flex;
  gap: 8px;
  margin: 10px 0;
}

.initials-input input {
  width: 36px;
  height: 40px;
  text-align: center;
  font-family: 'Press Start 2P', monospace;
  font-size: 18px;
  background: var(--bg-card);
  border: 2px solid var(--neon-blue);
  color: var(--neon-green);
  text-transform: uppercase;
}

/* Touch Controls */
#touch-controls {
  position: fixed;
  bottom: 20px;
  left: 0;
  width: 100%;
  z-index: 55;
  display: none;
  justify-content: space-between;
  padding: 0 20px;
  pointer-events: none;
}

#dpad {
  position: relative;
  width: 120px;
  height: 120px;
  pointer-events: auto;
}

.dpad-btn {
  position: absolute;
  width: 40px;
  height: 40px;
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  background: rgba(57,255,20,0.2);
  border: 2px solid var(--neon-green);
  color: var(--neon-green);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 4px;
}

#btn-up { top: 0; left: 40px; }
#btn-down { bottom: 0; left: 40px; }
#btn-left { top: 40px; left: 0; }
#btn-right { top: 40px; right: 0; }

#action-buttons {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  pointer-events: auto;
}

.action-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

#btn-a {
  background: rgba(255,45,149,0.3);
  border: 2px solid var(--neon-pink);
  color: var(--neon-pink);
}

#btn-b {
  background: rgba(0,240,255,0.3);
  border: 2px solid var(--neon-blue);
  color: var(--neon-blue);
  margin-bottom: 20px;
}

/* Channel switch transition */
.channel-switch {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 100;
  background: #fff;
  pointer-events: none;
  animation: channelSwitch 0.3s ease-out forwards;
}

@keyframes channelSwitch {
  0% { opacity: 0.9; }
  10% { opacity: 0; background: #000; }
  30% { opacity: 0.6; background: #333; }
  50% { opacity: 0; }
  100% { opacity: 0; display: none; }
}

/* Responsive */
@media (max-width: 600px) {
  .game-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .console-card {
    width: 110px;
    height: 140px;
  }
}