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

:root {
  --shell-color: #C4CFA1;
  --shell-dark: #A8B48A;
  --shell-light: #D4DFBB;
  --screen-border: #65665B;
  --screen-bg: #9BBC0F;
  --lcd-0: #9BBC0F;
  --lcd-1: #8BAC0F;
  --lcd-2: #306230;
  --lcd-3: #0F380F;
  --btn-dark: #2C2C3A;
  --btn-ab: #9E2344;
  --btn-ab-dark: #7A1A34;
  --btn-ss: #6B6B7B;
  --accent: #FF6B9D;
  --font-pixel: 'Press Start 2P', monospace;
  --font-silk: 'Silkscreen', monospace;
  --crt-green: #33FF33;
  --crt-bg: #0A1A0A;
}

body {
  background: linear-gradient(145deg, #0D0D12 0%, #1A1A2E 40%, #0D0D12 100%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  font-family: var(--font-silk);
  color: #ccc;
  overflow-x: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px;
  max-width: 520px;
  width: 100%;
}

/* Toolbar */
#toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: center;
  padding: 10px;
  margin-bottom: 10px;
  width: 100%;
}

.toolbar-group {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.toolbar-btn {
  font-family: var(--font-pixel);
  font-size: 9px;
  background: linear-gradient(180deg, #3A3A5C, #2A2A44);
  color: #FFD700;
  border: 2px solid #4A4A6C;
  padding: 8px 14px;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.15s;
  text-transform: uppercase;
  white-space: nowrap;
}

.toolbar-btn:hover {
  background: linear-gradient(180deg, #4A4A6C, #3A3A5C);
  border-color: #FFD700;
}

.toolbar-btn:active {
  transform: scale(0.96);
}

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

/* APU Badge */
.apu-badge {
  position: relative;
  font-family: var(--font-pixel);
  font-size: 7px;
  background: linear-gradient(180deg, #1A3A1A, #0A2A0A);
  color: #33FF33;
  border: 2px solid #33FF33;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: default;
  box-shadow: 0 0 8px rgba(51, 255, 51, 0.3);
  animation: apu-glow 2s ease-in-out infinite;
}

@keyframes apu-glow {
  0%, 100% { box-shadow: 0 0 8px rgba(51, 255, 51, 0.3); }
  50% { box-shadow: 0 0 16px rgba(51, 255, 51, 0.6); }
}

.apu-badge-icon {
  font-size: 10px;
}

.apu-badge-tooltip {
  display: none;
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: #0A1A0A;
  border: 1px solid #33FF33;
  padding: 10px;
  border-radius: 6px;
  width: 260px;
  z-index: 50;
  font-size: 6px;
  line-height: 1.8;
  color: #88FF88;
  margin-top: 4px;
}

.apu-badge-tooltip strong {
  color: #33FF33;
  font-size: 7px;
}

.apu-badge-tooltip ul {
  list-style: none;
  padding: 0;
  margin-top: 4px;
}

.apu-badge-tooltip li::before {
  content: '✓ ';
  color: #33FF33;
}

.apu-badge:hover .apu-badge-tooltip {
  display: block;
}

/* Power Switch */
.power-switch {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  background: #1A1A2E;
  padding: 4px 10px;
  border-radius: 12px;
  border: 2px solid #333;
}

.power-knob {
  width: 22px;
  height: 12px;
  background: #555;
  border-radius: 6px;
  position: relative;
  transition: background 0.3s;
}

.power-knob::after {
  content: '';
  position: absolute;
  width: 10px;
  height: 10px;
  background: #888;
  border-radius: 50%;
  top: 1px;
  left: 1px;
  transition: all 0.3s;
}

.power-switch.on .power-knob {
  background: #2E7D32;
}

.power-switch.on .power-knob::after {
  left: 11px;
  background: #4CAF50;
}

.power-label {
  font-family: var(--font-pixel);
  font-size: 7px;
  color: #888;
}

.power-switch.on .power-label {
  color: #4CAF50;
}

/* Speed Buttons */
.speed-btns {
  display: flex;
  gap: 2px;
}

.speed-btn {
  font-family: var(--font-pixel);
  font-size: 7px;
  background: #2A2A44;
  color: #888;
  border: 1px solid #444;
  padding: 4px 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.speed-btn:first-child { border-radius: 4px 0 0 4px; }
.speed-btn:last-child { border-radius: 0 4px 4px 0; }

.speed-btn.active {
  background: #4A4A6C;
  color: #FFD700;
  border-color: #FFD700;
}

/* Volume */
.volume-control {
  display: flex;
  align-items: center;
  gap: 4px;
}

#volume-icon { font-size: 14px; cursor: pointer; }

#volume-slider {
  width: 60px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: #333;
  border-radius: 2px;
  outline: none;
}

#volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  background: #FFD700;
  border-radius: 50%;
  cursor: pointer;
}

/* Filter Select */
#filter-select {
  font-family: var(--font-pixel);
  font-size: 7px;
  background: #2A2A44;
  color: #ccc;
  border: 1px solid #444;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
}

/* Game Boy Shell */
#gameboy-shell {
  background: linear-gradient(180deg, var(--shell-light) 0%, var(--shell-color) 30%, var(--shell-dark) 100%);
  border-radius: 16px 16px 60px 16px;
  padding: 16px 20px 30px;
  width: 100%;
  max-width: 460px;
  box-shadow:
    0 8px 32px rgba(0,0,0,0.6),
    inset 0 2px 0 rgba(255,255,255,0.3),
    inset 0 -2px 4px rgba(0,0,0,0.15);
  position: relative;
}

.shell-top-ridge {
  height: 4px;
  background: linear-gradient(180deg, rgba(255,255,255,0.2), transparent);
  border-radius: 2px;
  margin: -4px -4px 8px;
}

.screen-label {
  font-family: var(--font-pixel);
  font-size: 5px;
  color: #65665B;
  text-align: center;
  margin-bottom: 4px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

#screen-bezel {
  background: linear-gradient(135deg, #4A4550, #3A3540, #2E2A30);
  border-radius: 10px;
  padding: 18px 22px 14px;
  margin: 0 10px;
  position: relative;
  box-shadow:
    inset 0 3px 8px rgba(0,0,0,0.5),
    0 2px 0 rgba(255,255,255,0.1);
}

.power-led {
  position: absolute;
  top: 8px;
  left: 16px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #333;
  box-shadow: none;
  transition: all 0.5s;
}

.power-led.on {
  background: #FF1744;
  box-shadow: 0 0 6px #FF1744, 0 0 12px rgba(255,23,68,0.5);
  animation: led-pulse 2s infinite;
}

@keyframes led-pulse {
  0%, 100% { box-shadow: 0 0 6px #FF1744, 0 0 12px rgba(255,23,68,0.5); }
  50% { box-shadow: 0 0 8px #FF1744, 0 0 20px rgba(255,23,68,0.7); }
}

#screen-container {
  position: relative;
  background: var(--lcd-3);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.8);
  aspect-ratio: 160/144;
  width: 100%;
}

#lcd {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#screen-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 2;
}

#screen-overlay.scanlines::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.08) 2px,
    rgba(0,0,0,0.08) 4px
  );
}

#screen-overlay.vignette::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.3) 100%);
}

/* Splash Screen */
#splash-screen {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  cursor: pointer;
}

#splash-screen.hidden { display: none; }

.splash-content { text-align: center; }

.splash-berry {
  font-size: 36px;
  animation: splash-bounce 1.5s ease-in-out infinite;
}

.splash-title {
  font-family: var(--font-pixel);
  font-size: 14px;
  color: var(--lcd-0);
  margin: 8px 0;
  text-shadow: 2px 2px 0 var(--lcd-3);
}

.splash-sub {
  font-family: var(--font-silk);
  font-size: 9px;
  color: var(--lcd-1);
  line-height: 1.6;
}

.splash-arrow {
  font-size: 18px;
  color: var(--lcd-0);
  margin-top: 10px;
  animation: arrow-bounce 1s ease-in-out infinite;
}

@keyframes splash-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes arrow-bounce {
  0%, 100% { transform: translateY(0); opacity: 1; }
  50% { transform: translateY(6px); opacity: 0.5; }
}

/* Brand Label */
.brand-label {
  text-align: center;
  margin: 10px 0 14px;
  user-select: none;
}

.nintendo-text {
  font-family: serif;
  font-style: italic;
  font-weight: bold;
  font-size: 13px;
  color: #2C2C5A;
  letter-spacing: 1px;
}

.gameboy-text {
  font-family: var(--font-pixel);
  font-size: 14px;
  color: #2C2C5A;
  font-weight: bold;
  letter-spacing: 3px;
}

.tm {
  font-size: 6px;
  vertical-align: super;
  color: #2C2C5A;
}

/* Controls Area */
#controls-area {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 10px 0;
}

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

#dpad {
  position: relative;
  width: 100%;
  height: 100%;
}

.dpad-btn {
  position: absolute;
  background: var(--btn-dark);
  border: none;
  color: #555;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s;
  z-index: 1;
}

.dpad-btn:active, .dpad-btn.pressed {
  background: #1A1A28;
  color: #777;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
}

.dpad-up { left: 38px; top: 0; width: 44px; height: 44px; border-radius: 6px 6px 0 0; }
.dpad-down { left: 38px; bottom: 0; width: 44px; height: 44px; border-radius: 0 0 6px 6px; }
.dpad-left { left: 0; top: 38px; width: 44px; height: 44px; border-radius: 6px 0 0 6px; }
.dpad-right { right: 0; top: 38px; width: 44px; height: 44px; border-radius: 0 6px 6px 0; }
.dpad-center { position: absolute; left: 38px; top: 38px; width: 44px; height: 44px; background: var(--btn-dark); z-index: 0; }

/* A/B Buttons */
#ab-container { padding-right: 10px; }

.ab-buttons {
  display: flex;
  gap: 16px;
  transform: rotate(-25deg);
}

.ab-btn-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.ab-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--btn-ab), var(--btn-ab-dark));
  border: 2px solid #6A1230;
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0,0,0,0.3), inset 0 1px 2px rgba(255,255,255,0.15);
  transition: all 0.1s;
}

.ab-btn:active, .ab-btn.pressed {
  box-shadow: 0 1px 2px rgba(0,0,0,0.3), inset 0 2px 4px rgba(0,0,0,0.4);
  transform: scale(0.95);
}

.ab-label {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: #65665B;
  transform: rotate(25deg);
}

/* Start/Select */
#start-select-area {
  display: flex;
  justify-content: center;
  gap: 24px;
  padding: 16px 0 4px;
  transform: rotate(-25deg);
  margin-left: 20px;
}

.ss-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.ss-btn {
  width: 44px;
  height: 14px;
  border-radius: 7px;
  background: linear-gradient(180deg, var(--btn-ss), #555);
  border: 1px solid #555;
  cursor: pointer;
  box-shadow: 0 2px 3px rgba(0,0,0,0.2);
  transition: all 0.1s;
}

.ss-btn:active, .ss-btn.pressed {
  box-shadow: inset 0 2px 3px rgba(0,0,0,0.4);
  transform: scale(0.95);
}

.ss-label {
  font-family: var(--font-pixel);
  font-size: 5px;
  color: #65665B;
  letter-spacing: 1px;
  transform: rotate(25deg);
}

/* Speaker Grille */
.shell-speaker {
  position: absolute;
  bottom: 30px;
  right: 22px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transform: rotate(-25deg);
}

.speaker-line {
  width: 24px;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--shell-dark), transparent);
  border-radius: 2px;
}

.speaker-line:nth-child(odd) { width: 20px; margin-left: 4px; }

/* Debug buttons row */
.debug-buttons {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* Controls Help Panel */
#controls-panel.hidden { display: none; }

.controls-card {
  background: linear-gradient(180deg, #2A2A44, #1E1E34);
  border: 2px solid #4A4A6C;
  border-radius: 8px;
  padding: 14px;
  max-width: 300px;
  margin-top: 8px;
}

.controls-card h3 {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: #FFD700;
  margin-bottom: 10px;
  text-align: center;
}

.key-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 10px;
  border-bottom: 1px solid #333;
}

.key-row:last-child { border-bottom: none; }

kbd {
  background: #1A1A2E;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 2px 6px;
  font-family: var(--font-pixel);
  font-size: 7px;
  color: #ddd;
  box-shadow: 0 2px 0 #333;
}

/* APU Debug Panel */
#apu-debug-panel.hidden { display: none; }

.apu-debug-card {
  background: var(--crt-bg);
  border: 2px solid #1A4A1A;
  border-radius: 8px;
  padding: 14px;
  max-width: 480px;
  width: 100%;
  margin-top: 8px;
  box-shadow: 0 0 20px rgba(51, 255, 51, 0.1);
}

.apu-debug-card h3 {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--crt-green);
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.apu-debug-close {
  cursor: pointer;
  font-size: 12px;
  color: #FF4444;
}

.apu-debug-close:hover { color: #FF8888; }

.apu-debug-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.apu-ch-box {
  background: #0D1F0D;
  border: 1px solid #1A3A1A;
  border-radius: 4px;
  padding: 6px;
}

.apu-ch-header {
  font-family: var(--font-pixel);
  font-size: 6px;
  color: #88FF88;
  margin-bottom: 4px;
}

.apu-ch-box canvas {
  width: 100%;
  height: 32px;
  image-rendering: pixelated;
  border: 1px solid #1A3A1A;
  border-radius: 2px;
}

.apu-ch-info {
  font-family: var(--font-pixel);
  font-size: 5px;
  color: #55AA55;
  margin-top: 4px;
  word-break: break-all;
}

.apu-debug-row {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-pixel);
  font-size: 6px;
  color: #55AA55;
  padding: 4px 0;
  border-top: 1px solid #1A3A1A;
}

.apu-debug-row strong {
  color: var(--crt-green);
}

.apu-indicator {
  padding: 2px 6px;
  border-radius: 3px;
  background: #0D2A0D;
  border: 1px solid #1A3A1A;
}

.apu-indicator.corrupt {
  background: #3A1A0A;
  border-color: #FF4444;
  color: #FF8888;
  animation: corrupt-flash 0.5s ease-in-out infinite;
}

@keyframes corrupt-flash {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.apu-zombie-log {
  margin-top: 8px;
  border-top: 1px solid #1A3A1A;
  padding-top: 6px;
}

.apu-zombie-header {
  font-family: var(--font-pixel);
  font-size: 6px;
  color: #FFAA33;
  margin-bottom: 4px;
}

.apu-zombie-entries {
  font-family: var(--font-pixel);
  font-size: 5px;
  color: #AA8833;
  max-height: 60px;
  overflow-y: auto;
}

.zombie-entry {
  padding: 1px 0;
  border-bottom: 1px solid #1A2A1A;
}

/* Status Bar */
#status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  padding: 10px;
  font-family: var(--font-pixel);
  font-size: 6px;
  color: #666;
  margin-top: 8px;
}

#status-bar span {
  padding: 2px 6px;
  background: rgba(255,255,255,0.03);
  border-radius: 3px;
}

#emu-status { color: #888; }

/* Toast */
#toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #2A2A44;
  color: #FFD700;
  font-family: var(--font-pixel);
  font-size: 8px;
  padding: 10px 20px;
  border-radius: 6px;
  border: 2px solid #FFD700;
  z-index: 100;
  transition: opacity 0.3s;
}

#toast.hidden { opacity: 0; pointer-events: none; }

/* Footer */
#footer {
  margin-top: 16px;
  padding: 12px;
  text-align: center;
  font-size: 9px;
  color: #555;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#footer a {
  color: var(--accent);
  text-decoration: none;
}

#footer a:hover { text-decoration: underline; }
#footer small { font-size: 7px; color: #444; }

/* Responsive */
@media (max-width: 480px) {
  #gameboy-shell {
    border-radius: 12px 12px 40px 12px;
    padding: 12px 14px 24px;
  }

  #screen-bezel {
    margin: 0 4px;
    padding: 14px 16px 10px;
  }

  .toolbar-btn { font-size: 7px; padding: 6px 10px; }
  .toolbar-btn.small { font-size: 6px; padding: 4px 8px; }
  .ab-btn { width: 42px; height: 42px; }
  #controls-area { padding: 8px 4px 0; }

  .apu-debug-grid {
    grid-template-columns: 1fr;
  }

  .apu-badge-tooltip {
    width: 200px;
    left: 0;
    transform: none;
  }
}