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

:root {
  --gb-lightest: #9bbc0f;
  --gb-light: #8bac0f;
  --gb-dark: #306230;
  --gb-darkest: #0f380f;
  --shell-color: #C4C4B4;
  --shell-dark: #a8a898;
  --bezel-color: #4A5A3A;
  --btn-ab: #8B1A4A;
  --btn-meta: #3A3A3A;
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --accent: #8bac0f;
}

body {
  background: var(--bg-primary);
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(48,98,48,0.15) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 50%, rgba(15,56,15,0.1) 0%, transparent 60%);
  color: #e0e0e0;
  font-family: 'JetBrains Mono', monospace;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  overflow-x: hidden;
}

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

header {
  text-align: center;
  margin-bottom: 16px;
}

header h1 {
  font-family: 'Press Start 2P', cursive;
  font-size: 24px;
  color: var(--gb-lightest);
  text-shadow: 2px 2px 0 var(--gb-darkest), 0 0 20px rgba(155,188,15,0.3);
  margin-bottom: 6px;
}

.subtitle {
  font-size: 10px;
  color: var(--gb-dark);
  letter-spacing: 1px;
}

.hidden { display: none !important; }
.visible { display: flex !important; }

/* Drop Zone */
#drop-zone {
  width: 100%;
  max-width: 480px;
  height: 280px;
  border: 3px dashed var(--gb-dark);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15,56,15,0.1);
  transition: all 0.3s;
  cursor: pointer;
  margin-bottom: 16px;
}

#drop-zone.dragover {
  border-color: var(--gb-lightest);
  background: rgba(155,188,15,0.1);
  transform: scale(1.02);
}

.drop-inner { text-align: center; }

.drop-icon {
  font-size: 48px;
  margin-bottom: 12px;
  animation: bounce 2s infinite;
}

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

.drop-text {
  font-family: 'Press Start 2P', cursive;
  font-size: 12px;
  color: var(--gb-light);
  margin-bottom: 8px;
}

.drop-sub {
  font-size: 11px;
  color: var(--gb-dark);
  margin-bottom: 16px;
}

.file-btn {
  display: inline-block;
  padding: 10px 20px;
  background: var(--gb-dark);
  color: var(--gb-lightest);
  border-radius: 8px;
  font-family: 'Press Start 2P', cursive;
  font-size: 10px;
  cursor: pointer;
  transition: background 0.2s;
}

.file-btn:hover { background: var(--gb-darkest); }
.file-btn input { display: none; }

/* ROM Info */
#rom-info {
  width: 100%;
  max-width: 480px;
  background: rgba(15,56,15,0.2);
  border: 1px solid var(--gb-dark);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 12px;
  font-size: 10px;
  color: var(--gb-light);
  font-family: 'JetBrains Mono', monospace;
}

#rom-info span { margin-right: 12px; }

/* Game Boy Shell */
#gameboy-shell {
  background: var(--shell-color);
  background-image: linear-gradient(135deg, rgba(255,255,255,0.08) 0%, transparent 50%, rgba(0,0,0,0.05) 100%);
  border-radius: 20px 20px 20px 80px;
  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.1);
  width: 100%;
  max-width: 400px;
  position: relative;
}

.shell-top {
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
}

.shell-line {
  width: 60px;
  height: 4px;
  background: linear-gradient(to right, var(--shell-dark), var(--shell-color), var(--shell-dark));
  border-radius: 2px;
}

/* Screen Bezel */
.screen-bezel {
  background: var(--bezel-color);
  border-radius: 12px;
  padding: 8px 12px 6px;
  margin: 0 8px 16px;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.4);
}

.screen-label-top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  padding-left: 4px;
}

.power-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #400;
  transition: all 0.3s;
}

.power-led.on {
  background: #f00;
  box-shadow: 0 0 6px #f00, 0 0 12px rgba(255,0,0,0.5);
}

.battery-text {
  font-family: 'Press Start 2P', cursive;
  font-size: 6px;
  color: rgba(255,255,255,0.4);
  letter-spacing: 1px;
}

.screen-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 160/144;
  background: var(--gb-darkest);
  border-radius: 4px;
  overflow: hidden;
}

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

.lcd-overlay {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    transparent 0px,
    rgba(0,0,0,0.03) 1px,
    transparent 2px
  );
  pointer-events: none;
}

.lcd-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.25) 100%);
  pointer-events: none;
}

.screen-label-bottom {
  font-family: 'Press Start 2P', cursive;
  font-size: 5px;
  color: rgba(255,255,255,0.35);
  text-align: center;
  margin-top: 4px;
  letter-spacing: 2px;
}

/* Controls */
.controls-area {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  margin-bottom: 8px;
}

.dpad-container {
  display: grid;
  grid-template-columns: 36px 36px 36px;
  grid-template-rows: 36px 36px 36px;
  gap: 0;
  position: relative;
}

.dpad {
  background: #2a2a2a;
  border: none;
  color: #888;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

.dpad:active { background: #444; }
.dpad-up { grid-column: 2; grid-row: 1; border-radius: 4px 4px 0 0; }
.dpad-left { grid-column: 1; grid-row: 2; border-radius: 4px 0 0 4px; }
.dpad-center { grid-column: 2; grid-row: 2; background: #2a2a2a; }
.dpad-right { grid-column: 3; grid-row: 2; border-radius: 0 4px 4px 0; }
.dpad-down { grid-column: 2; grid-row: 3; border-radius: 0 0 4px 4px; }

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

.ab-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--btn-ab);
  border: none;
  color: rgba(255,255,255,0.7);
  font-family: 'Press Start 2P', cursive;
  font-size: 10px;
  cursor: pointer;
  box-shadow: 0 3px 0 #5a1030, 0 4px 8px rgba(0,0,0,0.3);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

.ab-btn:active {
  box-shadow: 0 1px 0 #5a1030;
  transform: translateY(2px);
}

.meta-buttons {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 12px;
}

.meta-btn {
  width: 52px;
  height: 16px;
  border-radius: 8px;
  background: var(--btn-meta);
  border: none;
  color: rgba(255,255,255,0.5);
  font-family: 'Press Start 2P', cursive;
  font-size: 5px;
  cursor: pointer;
  transform: rotate(-25deg);
  box-shadow: 0 2px 0 #222;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

.meta-btn:active {
  box-shadow: 0 0 0 #222;
  transform: rotate(-25deg) translateY(2px);
}

.speaker-grille {
  display: grid;
  grid-template-columns: repeat(6, 6px);
  gap: 4px;
  position: absolute;
  bottom: 28px;
  right: 28px;
  transform: rotate(-30deg);
}

.grille-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--shell-dark);
  box-shadow: inset 0 1px 1px rgba(0,0,0,0.3);
}

/* Toolbar */
#toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: center;
  margin: 12px 0;
  padding: 8px;
  background: rgba(15,56,15,0.15);
  border: 1px solid rgba(48,98,48,0.3);
  border-radius: 10px;
  width: 100%;
  max-width: 400px;
}

#toolbar button {
  background: var(--gb-darkest);
  border: 1px solid var(--gb-dark);
  color: var(--gb-lightest);
  padding: 6px 10px;
  border-radius: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

#toolbar button:hover {
  background: var(--gb-dark);
}

#volume-slider {
  width: 60px;
  accent-color: var(--gb-light);
}

/* Debug Panel */
#debug-panel {
  width: 100%;
  max-width: 480px;
  background: rgba(0,0,0,0.85);
  border: 1px solid var(--gb-dark);
  border-radius: 8px;
  padding: 12px;
  margin: 8px 0;
  font-size: 10px;
  color: var(--gb-light);
  font-family: 'JetBrains Mono', monospace;
  max-height: 300px;
  overflow-y: auto;
}

#debug-panel h3 {
  font-family: 'Press Start 2P', cursive;
  font-size: 8px;
  color: var(--gb-lightest);
  margin: 8px 0 4px;
  border-bottom: 1px solid rgba(48,98,48,0.3);
  padding-bottom: 2px;
}

#debug-panel h3:first-child { margin-top: 0; }

.dbg-section {
  white-space: pre;
  line-height: 1.6;
}

/* Key Hints */
#key-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 8px 0;
  font-size: 9px;
  color: rgba(139,172,15,0.5);
}

#key-hints span {
  background: rgba(15,56,15,0.2);
  padding: 2px 6px;
  border-radius: 4px;
}

/* Footer */
footer {
  text-align: center;
  margin-top: 16px;
  padding: 12px;
  font-size: 9px;
  color: rgba(255,255,255,0.3);
}

footer a {
  color: var(--gb-light);
  text-decoration: none;
}

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

/* Responsive */
@media (max-width: 420px) {
  #gameboy-shell { border-radius: 12px 12px 12px 40px; padding: 10px 12px 18px; }
  header h1 { font-size: 18px; }
  .ab-btn { width: 40px; height: 40px; font-size: 9px; }
  .dpad-container { grid-template-columns: 32px 32px 32px; grid-template-rows: 32px 32px 32px; }
}