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

:root {
  --bg-dark: #0f0f1a;
  --bg-mid: #1a1a2e;
  --shell-top: #8B3FC0;
  --shell-bot: #6B2FA0;
  --btn-ab: #8B1A4A;
  --btn-dpad: #2d2d2d;
  --led-green: #39FF14;
  --debug-bg: #111827;
  --debug-border: #1e293b;
  --accent-cyan: #22d3ee;
  --accent-yellow: #fbbf24;
  --accent-green: #4ade80;
  --text-dim: #94a3b8;
  --text-light: #e2e8f0;
}

body {
  background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-mid) 50%, var(--bg-dark) 100%);
  background-attachment: fixed;
  min-height: 100vh;
  color: var(--text-light);
  font-family: 'Fira Code', monospace;
  overflow-x: hidden;
}

/* Noise overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
}

/* Header */
#header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: rgba(15,15,26,0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(139,63,192,0.3);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-family: 'Press Start 2P', cursive;
  font-size: 14px;
  color: var(--shell-top);
  text-shadow: 0 0 10px rgba(139,63,192,0.5);
}

.header-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.header-controls button, .rom-btn {
  background: rgba(139,63,192,0.2);
  border: 1px solid rgba(139,63,192,0.4);
  color: var(--text-light);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-family: 'Fira Code', monospace;
  transition: all 0.15s;
  user-select: none;
}

.header-controls button:hover, .rom-btn:hover {
  background: rgba(139,63,192,0.4);
  border-color: var(--shell-top);
}

.header-controls button:active {
  transform: scale(0.95);
}

/* Main Content */
#main-content {
  display: flex;
  gap: 20px;
  padding: 20px;
  justify-content: center;
  align-items: flex-start;
  flex: 1;
}

/* GBC Shell */
#gbc-shell {
  background: linear-gradient(180deg, var(--shell-top) 0%, var(--shell-bot) 100%);
  border-radius: 20px 20px 60px 20px;
  padding: 20px 24px 30px;
  width: 360px;
  box-shadow:
    0 0 0 3px rgba(80,20,120,0.6),
    0 8px 32px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.15);
  position: relative;
  flex-shrink: 0;
}

.shell-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding-left: 4px;
}

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

.power-led.on {
  background: var(--led-green);
  box-shadow: 0 0 8px var(--led-green), 0 0 20px rgba(57,255,20,0.3);
}

.shell-label {
  font-family: 'Press Start 2P', cursive;
  font-size: 11px;
  color: rgba(255,255,255,0.7);
  letter-spacing: 2px;
}

.shell-label-color {
  font-family: 'Press Start 2P', cursive;
  font-size: 11px;
  background: linear-gradient(90deg, #ff6b6b, #ffd93d, #6bcb77, #4d96ff, #9b59b6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 1px;
}

/* Screen */
.screen-bezel {
  background: #1a1a2a;
  border-radius: 10px;
  padding: 8px 10px 12px;
  margin: 6px 0 16px;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.8);
}

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

.screen-area {
  position: relative;
  width: 320px;
  height: 288px;
  margin: 0 auto;
  background: #0f380f;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.5);
}

#gbScreen {
  width: 320px;
  height: 288px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

.drop-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15,56,15,0.85);
  z-index: 5;
  transition: opacity 0.3s;
}

.drop-overlay.hidden { opacity: 0; pointer-events: none; }
.drop-overlay.drag-active { background: rgba(57,255,20,0.2); border: 2px dashed var(--led-green); }

.drop-text {
  font-family: 'Press Start 2P', cursive;
  font-size: 9px;
  color: #9bbc0f;
  text-align: center;
  line-height: 2;
}

.scanline-overlay {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(0,0,0,0.08) 1px,
    rgba(0,0,0,0.08) 2px
  );
  pointer-events: none;
  z-index: 3;
  display: none;
}

.scanline-overlay.active { display: block; }

/* D-Pad & Buttons */
.controls-area {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
}

.dpad-container { padding-left: 10px; }

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

.dpad-btn {
  background: var(--btn-dpad);
  border: none;
  color: rgba(255,255,255,0.4);
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  transition: all 0.08s;
}

.dpad-btn:active, .dpad-btn.pressed {
  background: #1a1a1a;
  transform: scale(0.93);
}

.dpad-up { grid-column: 2; grid-row: 1; border-radius: 6px 6px 0 0; }
.dpad-down { grid-column: 2; grid-row: 3; border-radius: 0 0 6px 6px; }
.dpad-left { grid-column: 1; grid-row: 2; border-radius: 6px 0 0 6px; }
.dpad-right { grid-column: 3; grid-row: 2; border-radius: 0 6px 6px 0; }
.dpad-center { grid-column: 2; grid-row: 2; background: var(--btn-dpad); }

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

.ab-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--btn-ab);
  border: 2px solid rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.7);
  font-family: 'Press Start 2P', cursive;
  font-size: 10px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 3px 6px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.1);
  transition: all 0.08s;
}

.ab-btn:active, .ab-btn.pressed {
  transform: scale(0.92);
  box-shadow: 0 1px 2px rgba(0,0,0,0.4);
  background: #6b1040;
}

.meta-buttons {
  display: flex;
  justify-content: center;
  gap: 20px;
  padding: 8px 0;
}

.meta-btn {
  background: #555;
  border: none;
  color: rgba(255,255,255,0.5);
  font-family: 'Press Start 2P', cursive;
  font-size: 6px;
  padding: 6px 16px;
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
  letter-spacing: 1px;
  transition: all 0.08s;
}

.meta-btn:active, .meta-btn.pressed {
  transform: scale(0.93);
  background: #444;
}

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

.grille-hole {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(0,0,0,0.3);
}

/* Debug Panel */
.debug-panel {
  width: 360px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  background: var(--debug-bg);
  border: 1px solid var(--debug-border);
  border-radius: 12px;
  transition: all 0.3s;
}

.debug-panel.hidden {
  display: none;
}

.debug-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--debug-border);
  font-family: 'Press Start 2P', cursive;
  font-size: 10px;
  color: var(--accent-cyan);
}

.debug-header button {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
}

.debug-content {
  padding: 10px 14px;
}

.debug-section {
  margin-bottom: 14px;
}

.debug-section h3 {
  font-family: 'Press Start 2P', cursive;
  font-size: 8px;
  color: var(--accent-yellow);
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(251,191,36,0.2);
}

.debug-mono {
  font-family: 'Fira Code', monospace;
  font-size: 10px;
  line-height: 1.6;
  color: var(--accent-green);
  word-break: break-all;
}

.debug-section button {
  background: rgba(34,211,238,0.15);
  border: 1px solid rgba(34,211,238,0.3);
  color: var(--accent-cyan);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-family: 'Fira Code', monospace;
  font-size: 10px;
  margin-right: 6px;
  margin-top: 4px;
}

.debug-section button:hover {
  background: rgba(34,211,238,0.3);
}

.fifo-viz label {
  font-size: 9px;
  color: var(--text-dim);
  display: block;
  margin: 4px 0 2px;
}

.fifo-strip {
  display: flex;
  gap: 1px;
  min-height: 16px;
  background: rgba(0,0,0,0.3);
  border-radius: 3px;
  padding: 2px;
  overflow: hidden;
}

.fifo-pixel {
  width: 14px;
  height: 14px;
  border-radius: 2px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.1);
}

.fetcher-state {
  margin-top: 6px;
  font-size: 9px;
  color: var(--text-dim);
}

.fetcher-indicator {
  color: var(--led-green);
  font-weight: 700;
}

#tileViewer, #bgMapViewer {
  image-rendering: pixelated;
  background: #000;
  border-radius: 4px;
  width: 100%;
  max-width: 256px;
}

#tileViewer { height: auto; max-height: 192px; }
#bgMapViewer { height: auto; max-height: 256px; }

.palette-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.pal-swatch {
  width: 20px;
  height: 20px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.1);
}

/* Status Bar */
#statusBar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding: 8px 20px;
  font-size: 10px;
  color: var(--text-dim);
  background: rgba(15,15,26,0.8);
  border-top: 1px solid rgba(139,63,192,0.2);
}

/* Footer */
footer {
  padding: 16px;
  text-align: center;
  font-size: 10px;
  color: var(--text-dim);
  display: flex;
  gap: 16px;
  justify-content: center;
}

footer a {
  color: var(--shell-top);
  text-decoration: none;
}

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

/* Mobile responsive */
@media (max-width: 800px) {
  #main-content {
    flex-direction: column;
    align-items: center;
  }
  #gbc-shell {
    width: 340px;
    padding: 16px 18px 24px;
  }
  .screen-area, #gbScreen {
    width: 288px;
    height: 259px;
  }
  .debug-panel {
    width: 100%;
    max-width: 340px;
  }
  #header {
    flex-direction: column;
    gap: 8px;
  }
}

@media (max-width: 400px) {
  #gbc-shell {
    width: 300px;
    padding: 12px 14px 20px;
  }
  .screen-area, #gbScreen {
    width: 256px;
    height: 230px;
  }
}

/* Scrollbar styling */
.debug-panel::-webkit-scrollbar { width: 6px; }
.debug-panel::-webkit-scrollbar-track { background: transparent; }
.debug-panel::-webkit-scrollbar-thumb { background: rgba(139,63,192,0.4); border-radius: 3px; }