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

:root {
  --gb-darkest: #0f380f;
  --gb-dark: #306230;
  --gb-light: #8bac0f;
  --gb-lightest: #9bbc0f;
  --shell-color: #c0b8a8;
  --shell-dark: #8a8478;
  --shell-highlight: #d8d0c0;
  --bg: #0a0a14;
  --panel-bg: #12121e;
  --text: #c8c8d0;
  --accent: #9bbc0f;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  overflow-x: hidden;
  min-height: 100vh;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 16px;
}

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

#header h1 {
  font-size: 24px;
  color: var(--gb-lightest);
  text-shadow: 0 0 20px rgba(155,188,15,0.4), 2px 2px 0 var(--gb-darkest);
  margin-bottom: 8px;
}

.subtitle {
  font-size: 8px;
  color: var(--gb-light);
  opacity: 0.7;
}

#main-container {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 1100px;
}

/* GAME BOY SHELL */
#gameboy-shell {
  background: linear-gradient(145deg, var(--shell-highlight), var(--shell-color), var(--shell-dark));
  border-radius: 12px 12px 12px 60px;
  padding: 16px 20px 24px 20px;
  width: 340px;
  box-shadow: 4px 4px 0 #000, 8px 8px 20px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.3);
  position: relative;
}

#shell-top {
  display: flex;
  align-items: center;
  margin-bottom: 6px;
  padding-left: 4px;
}

#power-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
}

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

#power-led.on {
  background: #ff2040;
  box-shadow: 0 0 8px #ff2040, 0 0 16px rgba(255,32,64,0.5);
}

.power-label {
  font-size: 6px;
  color: #555;
  letter-spacing: 1px;
}

#screen-bezel {
  background: #3a3456;
  border-radius: 8px 8px 8px 40px;
  padding: 10px 14px 14px;
  margin-bottom: 8px;
  position: relative;
}

#dot-matrix-label {
  font-size: 5px;
  color: #8a82a0;
  text-align: center;
  margin-bottom: 6px;
  letter-spacing: 2px;
}

#screen-wrapper {
  position: relative;
  width: 288px;
  height: 260px;
  margin: 0 auto;
  background: var(--gb-lightest);
  border: 3px solid #2a2446;
  border-radius: 2px;
  overflow: hidden;
}

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

#screen-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    transparent 0px,
    transparent 1px,
    rgba(0,0,0,0.03) 1px,
    rgba(0,0,0,0.03) 2px
  );
  mix-blend-mode: multiply;
}

#drop-zone-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15,56,15,0.85);
  color: var(--gb-lightest);
  font-size: 12px;
  z-index: 10;
}

#drop-zone-overlay.active { display: flex; }

#brand-label {
  text-align: center;
  font-size: 14px;
  color: #3a3870;
  margin: 6px 0 12px;
  font-style: italic;
}

.tm { font-size: 6px; vertical-align: super; }

/* CONTROLS */
#controls-area {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px;
  min-height: 100px;
}

#dpad-container {
  display: grid;
  grid-template-columns: 28px 28px 28px;
  grid-template-rows: 28px 28px 28px;
  gap: 0;
}

.dpad-btn {
  background: #2a2a2a;
  border: 2px solid #1a1a1a;
  color: #888;
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.dpad-btn:active, .dpad-btn.pressed { background: #1a1a1a; }
.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: #222; }
.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: 10px;
  transform: rotate(-25deg);
}

.ab-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: #8b2252;
  border: 3px solid #6a1a40;
  color: #d0a0b0;
  font-size: 10px;
  font-family: 'Press Start 2P', monospace;
  cursor: pointer;
  box-shadow: 2px 2px 0 #1a1a1a;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.ab-btn:active, .ab-btn.pressed {
  box-shadow: 0 0 0 #1a1a1a;
  transform: translate(2px,2px);
}

#startselect-container {
  position: absolute;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
}

.ss-btn {
  background: #666;
  border: none;
  border-radius: 10px;
  width: 48px;
  height: 12px;
  font-size: 5px;
  color: #aaa;
  font-family: 'Press Start 2P', monospace;
  cursor: pointer;
  transform: rotate(-5deg);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.ss-btn:active, .ss-btn.pressed { background: #444; }

#speaker-grille {
  position: absolute;
  bottom: 24px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transform: rotate(-30deg);
}

.grille-line {
  width: 28px;
  height: 3px;
  background: var(--shell-dark);
  border-radius: 2px;
}

/* SIDE PANEL */
#side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 340px;
}

.panel-section {
  background: var(--panel-bg);
  border: 2px solid #222;
  padding: 12px;
  border-radius: 4px;
}

.panel-section h2 {
  font-size: 10px;
  color: var(--accent);
  margin-bottom: 10px;
}

#drop-zone {
  border: 2px dashed var(--gb-dark);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s;
}

#drop-zone:hover, #drop-zone.dragover {
  border-color: var(--gb-lightest);
  background: rgba(155,188,15,0.05);
}

#drop-zone p { font-size: 8px; margin-bottom: 6px; }
.small { font-size: 6px; opacity: 0.5; }

.file-label {
  display: inline-block;
  background: var(--gb-dark);
  color: var(--gb-lightest);
  padding: 8px 16px;
  font-size: 8px;
  font-family: 'Press Start 2P', monospace;
  cursor: pointer;
  border: 2px solid var(--gb-darkest);
  margin-top: 4px;
}

.file-label:hover { background: var(--gb-darkest); }

#toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tool-btn {
  background: #1a1a2e;
  border: 2px solid #333;
  color: var(--text);
  padding: 6px 10px;
  font-size: 7px;
  font-family: 'Press Start 2P', monospace;
  cursor: pointer;
  transition: all 0.15s;
}

.tool-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.tool-btn:disabled { opacity: 0.3; cursor: not-allowed; }

#status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 6px;
  flex-wrap: wrap;
  gap: 4px;
}

#rom-info { color: var(--gb-light); flex: 1; }
#emu-status { padding: 2px 6px; border-radius: 2px; }
.status-idle { background: #333; color: #888; }
.status-running { background: var(--gb-dark); color: var(--gb-lightest); }
.status-paused { background: #665500; color: #ffcc00; }
#fps-display { color: #888; }

details summary {
  cursor: pointer;
  font-size: 9px;
  color: var(--accent);
  padding: 4px 0;
  -webkit-user-select: none;
  user-select: none;
}

.keybind-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  font-size: 7px;
  padding: 8px 0;
}

.keybind-grid span:nth-child(odd) { color: var(--gb-light); }

.debug-section h3 { font-size: 7px; color: var(--gb-light); margin: 4px 0; }
.debug-section pre {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 7px;
  color: #a0a0b0;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.6;
}

footer {
  margin-top: 24px;
  padding: 16px;
  text-align: center;
}

footer a {
  color: var(--gb-dark);
  font-size: 8px;
  text-decoration: none;
  font-family: 'Press Start 2P', monospace;
}

footer a:hover { color: var(--gb-lightest); }

@media (max-width: 720px) {
  #main-container { flex-direction: column; align-items: center; }
  #side-panel { width: 340px; }
}

@media (max-width: 380px) {
  #gameboy-shell { width: 300px; padding: 12px 14px 20px; }
  #screen-wrapper { width: 240px; height: 216px; }
  #screen { width: 240px; height: 216px; }
  #side-panel { width: 300px; }
}