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

body {
  background: #0d0d1a;
  background-image: 
    radial-gradient(ellipse at 50% 0%, #1a1a3a 0%, transparent 60%),
    repeating-linear-gradient(0deg, transparent, transparent 49px, #ffffff05 49px, #ffffff05 50px),
    repeating-linear-gradient(90deg, transparent, transparent 49px, #ffffff05 49px, #ffffff05 50px);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 10px;
  overflow-x: hidden;
  font-family: 'JetBrains Mono', monospace;
  color: #ccc;
}

#app-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 1200px;
}

/* Toolbar */
#toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: #1a1a2e;
  border: 1px solid #2a2a4a;
  border-radius: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

#toolbar button {
  background: #2a2a4a;
  border: 1px solid #3a3a5a;
  color: #9BBC0F;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-family: 'JetBrains Mono', monospace;
  transition: all 0.15s;
}
#toolbar button:hover { background: #3a3a5a; }
#toolbar button:active { background: #4a4a6a; transform: scale(0.95); }
#toolbar button.active { background: #306230; border-color: #8BAC0F; }

#volume-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

#volume-slider {
  width: 60px;
  accent-color: #8BAC0F;
}

#toolbar select {
  background: #2a2a4a;
  border: 1px solid #3a3a5a;
  color: #9BBC0F;
  padding: 5px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
}

#toolbar select:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Mode Badge */
.mode-badge-dmg {
  font-family: 'Press Start 2P', cursive;
  font-size: 8px;
  padding: 3px 8px;
  border-radius: 4px;
  background: #4a6a4a;
  color: #9BBC0F;
  border: 1px solid #6a8a6a;
}

.mode-badge-gbc {
  font-family: 'Press Start 2P', cursive;
  font-size: 8px;
  padding: 3px 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, #ff4444, #ff8844, #ffcc44, #44cc44, #4488ff, #8844ff);
  color: #fff;
  border: 1px solid #666;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* Game Boy Shell - DMG */
.shell-dmg {
  background: linear-gradient(145deg, #c8c8b8 0%, #b8b8a8 50%, #a8a898 100%);
  border-radius: 16px 16px 16px 60px;
  padding: 16px 20px 24px;
  box-shadow: 
    0 8px 32px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.3),
    inset 0 -2px 0 rgba(0,0,0,0.15);
  max-width: 380px;
  width: 100%;
  position: relative;
  transition: background 0.5s ease, box-shadow 0.5s ease;
}

/* Game Boy Shell - GBC (Atomic Purple) */
.shell-gbc {
  background: linear-gradient(145deg, 
    rgba(140, 100, 180, 0.85) 0%, 
    rgba(100, 70, 160, 0.8) 25%,
    rgba(130, 90, 170, 0.85) 50%, 
    rgba(90, 60, 140, 0.8) 75%,
    rgba(120, 80, 165, 0.85) 100%);
  border-radius: 16px 16px 16px 60px;
  padding: 16px 20px 24px;
  box-shadow: 
    0 8px 32px rgba(100, 50, 150, 0.4),
    inset 0 1px 0 rgba(255,255,255,0.25),
    inset 0 -2px 0 rgba(0,0,0,0.15),
    inset 0 0 60px rgba(200, 150, 255, 0.08);
  max-width: 380px;
  width: 100%;
  position: relative;
  transition: background 0.5s ease, box-shadow 0.5s ease;
}

.shell-gbc::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 16px 16px 16px 60px;
  background: 
    linear-gradient(135deg, transparent 30%, rgba(255,255,255,0.06) 50%, transparent 70%);
  pointer-events: none;
}

#shell-top {
  margin-bottom: 10px;
  padding-left: 4px;
}

#accent-line {
  width: 60px;
  height: 4px;
  background: linear-gradient(90deg, #8B1A8B, #5B2C8B);
  border-radius: 2px;
  margin-bottom: 4px;
  transition: all 0.5s ease;
}

.accent-gbc {
  width: 100px !important;
  height: 4px;
  background: linear-gradient(90deg, #FF4444, #FF8844, #FFCC44, #44CC44, #4488FF, #8844FF) !important;
  border-radius: 2px;
  margin-bottom: 4px;
}

#brand-text {
  display: flex;
  flex-direction: column;
}

.brand-main {
  font-family: 'Press Start 2P', cursive;
  font-size: 16px;
  color: #2a2a5a;
  letter-spacing: 2px;
}

.rainbow-text {
  font-family: 'Press Start 2P', cursive;
  font-size: 13px;
  background: linear-gradient(90deg, #FF2222, #FF7722, #FFCC22, #22CC22, #2266FF, #6622FF, #FF22FF);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 1px;
  filter: brightness(1.1) saturate(1.3);
}

.brand-sub {
  font-family: 'JetBrains Mono', monospace;
  font-size: 7px;
  color: #5a5a7a;
  font-style: italic;
  margin-top: 2px;
  transition: all 0.5s ease;
}

.shell-gbc .brand-sub {
  font-size: 9px;
  font-weight: 700;
  font-style: normal;
  color: #3a2a5a;
  letter-spacing: 3px;
}

/* Screen */
#screen-bezel {
  background: #3a3a2a;
  border-radius: 10px;
  padding: 12px 14px 14px;
  box-shadow: 
    inset 0 3px 8px rgba(0,0,0,0.6),
    inset 0 -1px 0 rgba(255,255,255,0.08);
  position: relative;
  margin: 0 auto;
  text-align: center;
  transition: background 0.5s ease, box-shadow 0.5s ease;
}

.bezel-gbc {
  background: #1a1a1a !important;
  box-shadow: 
    inset 0 3px 8px rgba(0,0,0,0.8),
    inset 0 -1px 0 rgba(255,255,255,0.05) !important;
}

#screen-bezel.dragover {
  box-shadow: 
    inset 0 3px 8px rgba(0,0,0,0.6),
    0 0 20px rgba(139,172,15,0.6);
}

.shell-gbc #screen-bezel.dragover {
  box-shadow: 
    inset 0 3px 8px rgba(0,0,0,0.6),
    0 0 15px rgba(255,68,68,0.4),
    0 0 25px rgba(68,204,68,0.3),
    0 0 35px rgba(68,136,255,0.3);
}

#power-indicator {
  position: absolute;
  top: 4px;
  left: 14px;
  display: flex;
  align-items: center;
  gap: 3px;
}
#power-led {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #cc3333;
  box-shadow: 0 0 4px rgba(204,51,51,0.6);
  transition: all 0.3s;
}
#power-led.running { background: #33cc33; box-shadow: 0 0 6px rgba(51,204,51,0.8); }
#power-led.running.gbc { background: #00ff44; box-shadow: 0 0 8px rgba(0,255,68,0.9); }
#power-led.paused { background: #cccc33; box-shadow: 0 0 4px rgba(204,204,51,0.6); }

#power-indicator span {
  font-family: 'Press Start 2P', cursive;
  font-size: 5px;
  color: #6a6a5a;
}

#screen {
  display: block;
  width: 320px;
  height: 288px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #0d0d1a;
  border-radius: 2px;
  margin: 0 auto;
}

#drop-overlay {
  position: absolute;
  top: 12px;
  left: 14px;
  right: 14px;
  bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Press Start 2P', cursive;
  font-size: 10px;
  color: rgba(139,172,15,0.6);
  pointer-events: none;
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.2s;
}
#drop-overlay.visible { opacity: 1; background: rgba(15,56,15,0.3); }

#rom-info {
  text-align: center;
  margin-top: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
#rom-title {
  font-family: 'Press Start 2P', cursive;
  font-size: 7px;
  color: #5a5a7a;
}

.rom-badge {
  font-family: 'Press Start 2P', cursive;
  font-size: 6px;
  padding: 2px 6px;
  border-radius: 3px;
}
.rom-badge.hidden { display: none; }
.dmg-badge {
  background: #3a5a3a;
  color: #9BBC0F;
  border: 1px solid #5a7a5a;
}
.gbc-badge {
  background: linear-gradient(90deg, #663399, #4422aa);
  color: #e0d0ff;
  border: 1px solid #8855cc;
}

/* Controls */
#controls-area {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  padding: 0 8px;
}

#dpad-container {
  width: 100px;
  height: 100px;
  position: relative;
}

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

.dpad-btn {
  position: absolute;
  width: 32px;
  height: 32px;
  background: #3a3a3a;
  border: none;
  color: #1a1a1a;
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.1);
  transition: all 0.08s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.dpad-btn:active, .dpad-btn.pressed {
  background: #2a2a2a;
  box-shadow: 0 0 2px rgba(0,0,0,0.4), inset 0 2px 4px rgba(0,0,0,0.4);
  transform: scale(0.95);
}

.shell-gbc .dpad-btn {
  background: #2a2a3a;
}
.shell-gbc .dpad-btn:active, .shell-gbc .dpad-btn.pressed {
  background: #1a1a2a;
}

.dpad-up { top: 0; left: 34px; border-radius: 4px 4px 0 0; }
.dpad-down { bottom: 0; left: 34px; border-radius: 0 0 4px 4px; }
.dpad-left { top: 34px; left: 0; border-radius: 4px 0 0 4px; }
.dpad-right { top: 34px; right: 0; border-radius: 0 4px 4px 0; }
.dpad-center {
  position: absolute;
  top: 32px;
  left: 32px;
  width: 36px;
  height: 36px;
  background: #3a3a3a;
}
.shell-gbc .dpad-center {
  background: #2a2a3a;
}

#ab-container {
  display: flex;
  gap: 12px;
  transform: rotate(-25deg);
}

.action-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(145deg, #8B1A4A, #6B1A3A);
  border: none;
  color: #2a0a1a;
  font-family: 'Press Start 2P', cursive;
  font-size: 10px;
  cursor: pointer;
  box-shadow: 0 3px 6px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.15);
  transition: all 0.08s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.shell-gbc .action-btn {
  background: linear-gradient(145deg, #5B1A5A, #3B1A4A);
}

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

#start-select-container {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 14px;
  transform: rotate(-25deg);
}

.sys-btn {
  width: 48px;
  height: 16px;
  border-radius: 8px;
  background: #5a5a5a;
  border: none;
  color: #2a2a2a;
  font-family: 'Press Start 2P', cursive;
  font-size: 5px;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.1);
  transition: all 0.08s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.sys-btn:active, .sys-btn.pressed {
  box-shadow: 0 0 2px rgba(0,0,0,0.3), inset 0 2px 3px rgba(0,0,0,0.4);
  transform: scale(0.93);
}

.shell-gbc .sys-btn {
  background: #4a4a5a;
}

#load-rom-container {
  text-align: center;
  margin-top: 16px;
}

#btn-load-rom {
  font-family: 'Press Start 2P', cursive;
  font-size: 8px;
  padding: 8px 16px;
  background: #2a2a5a;
  border: 2px solid #4a4a7a;
  color: #9BBC0F;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
#btn-load-rom:hover { background: #3a3a6a; }

.shell-gbc #btn-load-rom {
  border-color: #6644aa;
  background: #3a2260;
}

/* Cart Info */
#cart-info {
  background: #1a1a2e;
  border: 1px solid #2a2a4a;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 11px;
  max-width: 380px;
  width: 100%;
}
#cart-details {
  font-family: 'JetBrains Mono', monospace;
  color: #8BAC0F;
  line-height: 1.6;
}

/* Debug Panel */
#debug-panel {
  position: fixed;
  right: 0;
  top: 0;
  width: 340px;
  height: 100vh;
  background: #0a0a14;
  border-left: 2px solid #1a3a1a;
  overflow-y: auto;
  padding: 14px;
  z-index: 100;
  transition: transform 0.3s ease;
  font-size: 11px;
}
#debug-panel.hidden {
  transform: translateX(100%);
}

#debug-panel h3 {
  font-family: 'Press Start 2P', cursive;
  font-size: 8px;
  color: #8BAC0F;
  margin: 12px 0 6px;
  border-bottom: 1px solid #1a3a1a;
  padding-bottom: 4px;
}

#debug-regs, #debug-flags, #debug-opcode, #debug-interrupts, #debug-timer, #debug-ppu, #debug-fps, #debug-speed, #debug-gbc-extra {
  font-family: 'JetBrains Mono', monospace;
  color: #33cc66;
  line-height: 1.5;
  font-size: 10px;
}

#debug-flags .flag-set { color: #8BAC0F; font-weight: bold; }
#debug-flags .flag-unset { color: #3a3a3a; }

.speed-double { color: #ff8844; font-weight: bold; }
.speed-normal { color: #44cc88; }

.palette-grid {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 4px 0;
}
.palette-row {
  display: flex;
  align-items: center;
  gap: 3px;
}
.pal-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 8px;
  color: #5a8a5a;
  width: 20px;
}
.color-swatch {
  display: inline-block;
  width: 16px;
  height: 12px;
  border: 1px solid #333;
  border-radius: 2px;
}

#vram-canvas {
  image-rendering: pixelated;
  width: 256px;
  height: 384px;
  background: #0F380F;
  border: 1px solid #1a3a1a;
}

#debug-log {
  height: 100px;
  overflow-y: auto;
  background: #050510;
  border: 1px solid #1a3a1a;
  padding: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  color: #33aa55;
  line-height: 1.4;
}

/* Key Hint */
#key-hint {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  color: #4a4a6a;
  text-align: center;
  margin-top: 4px;
}

footer {
  margin-top: 12px;
  text-align: center;
}
footer a {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: #4a4a6a;
  text-decoration: none;
}
footer a:hover { color: #8BAC0F; }

/* Mobile */
@media (max-width: 500px) {
  .shell-dmg, .shell-gbc { max-width: 100%; padding: 12px 14px 20px; }
  #screen { width: 100%; height: auto; aspect-ratio: 160/144; }
  .brand-main { font-size: 12px; }
  .rainbow-text { font-size: 10px; }
  #dpad-container { width: 90px; height: 90px; }
  #dpad { width: 90px; height: 90px; }
  .dpad-btn { width: 28px; height: 28px; font-size: 8px; }
  .dpad-up { left: 31px; }
  .dpad-down { left: 31px; }
  .dpad-left { top: 31px; }
  .dpad-right { top: 31px; }
  .dpad-center { top: 28px; left: 28px; width: 34px; height: 34px; }
  .action-btn { width: 40px; height: 40px; }
  #debug-panel { width: 280px; }
  #key-hint { display: none; }
}