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

:root {
  --shell-color: #6a0dad;
  --shell-light: #8b2fc9;
  --shell-dark: #4a0080;
  --bezel-color: #1a1a2e;
  --screen-bg: #0f380f;
  --btn-dark: #2d2d2d;
  --btn-ab: #8B0000;
  --btn-ab-light: #a52a2a;
  --bg-color: #0d0d1a;
  --text-color: #c0c0c0;
  --accent: #2a9d8f;
}

body {
  background: var(--bg-color);
  color: var(--text-color);
  font-family: 'JetBrains Mono', monospace;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-user-select: none;
  user-select: none;
}

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

/* Toolbar */
#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

#toolbar button {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text-color);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  transition: all 0.15s;
  white-space: nowrap;
}
#toolbar button:hover { background: rgba(255,255,255,0.15); }
#toolbar button:active { transform: scale(0.95); }

#btn-load { background: var(--accent); color: #fff; border-color: var(--accent); }
#btn-load:hover { background: #35b8a8; }

#rom-name {
  font-size: 9px;
  color: #888;
  font-family: 'Press Start 2P', monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 120px;
}

.toolbar-right {
  display: flex;
  gap: 4px;
  margin-left: auto;
  flex-wrap: wrap;
}

.btn-icon { font-style: normal; }

/* Game Boy Shell */
#gameboy-shell {
  background: linear-gradient(160deg, var(--shell-light) 0%, var(--shell-color) 40%, var(--shell-dark) 100%);
  border-radius: 20px 20px 60px 20px;
  padding: 15px 20px 30px;
  box-shadow: 
    0 8px 32px rgba(106,13,173,0.4),
    inset 0 1px 0 rgba(255,255,255,0.15),
    inset 0 -2px 0 rgba(0,0,0,0.2);
  position: relative;
  width: 100%;
  max-width: 480px;
}

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

.power-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #333;
  box-shadow: none;
  transition: all 0.3s;
}
.power-led.on {
  background: #39ff14;
  box-shadow: 0 0 8px #39ff14, 0 0 20px rgba(57,255,20,0.4);
  animation: led-pulse 2s ease-in-out infinite;
}
@keyframes led-pulse {
  0%, 100% { box-shadow: 0 0 8px #39ff14, 0 0 20px rgba(57,255,20,0.4); }
  50% { box-shadow: 0 0 12px #39ff14, 0 0 30px rgba(57,255,20,0.6); }
}

.gbc-logo {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  letter-spacing: 2px;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.5);
}
.gbc-sub {
  font-size: 7px;
  color: #ddd;
  margin-left: 4px;
  vertical-align: super;
}

/* Screen */
#screen-bezel {
  background: #111;
  border-radius: 6px;
  padding: 12px;
  margin: 0 auto 15px;
  box-shadow: inset 0 3px 10px rgba(0,0,0,0.8), inset 0 0 0 2px #222;
  position: relative;
  overflow: hidden;
  width: fit-content;
}

#canvas {
  display: block;
  width: 320px;
  height: 288px;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  background: var(--screen-bg);
  border-radius: 2px;
}

#scanline-overlay {
  position: absolute;
  top: 12px; left: 12px; right: 12px; bottom: 12px;
  pointer-events: none;
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.3s;
}
#scanline-overlay.scanlines {
  opacity: 0.12;
  background: repeating-linear-gradient(
    0deg,
    transparent, transparent 1px,
    rgba(0,0,0,0.6) 1px, rgba(0,0,0,0.6) 2px
  );
}
#scanline-overlay.lcd {
  opacity: 0.08;
  background: 
    repeating-linear-gradient(0deg, transparent, transparent 1px, rgba(0,0,0,0.5) 1px, rgba(0,0,0,0.5) 2px),
    repeating-linear-gradient(90deg, transparent, transparent 1px, rgba(0,0,0,0.5) 1px, rgba(0,0,0,0.5) 2px);
}

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

/* D-Pad */
#dpad {
  display: grid;
  grid-template-columns: 36px 36px 36px;
  grid-template-rows: 36px 36px 36px;
  gap: 0;
  position: relative;
}
.dpad-btn {
  background: var(--btn-dark);
  border: 1px solid #444;
  color: #888;
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.dpad-btn:active, .dpad-btn.pressed {
  background: #444;
  transform: scale(0.92);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
}
.dpad-up { border-radius: 6px 6px 0 0; grid-column: 2; grid-row: 1; }
.dpad-left { border-radius: 6px 0 0 6px; grid-column: 1; grid-row: 2; }
.dpad-center { background: #3a3a3a; border: 1px solid #444; grid-column: 2; grid-row: 2; cursor: default; border-radius: 0; }
.dpad-right { border-radius: 0 6px 6px 0; grid-column: 3; grid-row: 2; }
.dpad-down { border-radius: 0 0 6px 6px; grid-column: 2; grid-row: 3; }

/* A/B Buttons */
#ab-buttons {
  display: flex;
  gap: 12px;
  transform: rotate(-15deg);
}
.ab-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--btn-ab);
  border: 2px solid #600;
  color: #fdd;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  cursor: pointer;
  box-shadow: 0 3px 6px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.15);
  transition: all 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.ab-btn:active, .ab-btn.pressed {
  transform: scale(0.9);
  box-shadow: 0 1px 2px rgba(0,0,0,0.4), inset 0 2px 4px rgba(0,0,0,0.5);
  background: #600;
}
#btn-b { margin-top: 14px; }

/* Start/Select */
#start-select {
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
}
.ss-btn {
  background: #555;
  border: 1px solid #666;
  color: #bbb;
  padding: 5px 14px;
  border-radius: 12px;
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  cursor: pointer;
  transform: rotate(-8deg);
  transition: all 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.ss-btn:active, .ss-btn.pressed {
  background: #777;
  transform: rotate(-8deg) scale(0.92);
}

/* Speaker Grille */
.speaker-grille {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transform: rotate(-30deg);
}
.speaker-grille div {
  width: 30px;
  height: 2px;
  background: rgba(0,0,0,0.3);
  border-radius: 1px;
}

/* ROM Info */
#rom-info {
  width: 100%;
  max-width: 480px;
  margin-top: 10px;
  background: rgba(255,255,255,0.03);
  border-radius: 8px;
  overflow: hidden;
}
#btn-toggle-info {
  width: 100%;
  background: transparent;
  border: none;
  color: #777;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 8px;
  cursor: pointer;
}
#info-content {
  padding: 8px 12px;
  font-size: 9px;
  display: none;
  color: #999;
}
#rom-info:not(.collapsed) #info-content { display: block; }
#cart-info { margin-bottom: 4px; }
#fps-counter { color: var(--accent); }
#btn-debug {
  background: rgba(0,255,0,0.1);
  border: 1px solid rgba(0,255,0,0.2);
  color: #0f0;
  padding: 3px 8px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 8px;
  margin-top: 6px;
  cursor: pointer;
}
#debug-view {
  background: #000;
  color: #0f0;
  padding: 8px;
  border-radius: 4px;
  font-size: 8px;
  margin-top: 6px;
  line-height: 1.6;
  overflow-x: auto;
}
.hidden { display: none !important; }

/* Settings */
#settings-panel {
  position: fixed;
  top: 0; right: 0;
  width: 280px;
  height: 100vh;
  background: #1a1a2e;
  border-left: 2px solid rgba(106,13,173,0.5);
  z-index: 1000;
  padding: 15px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}
#settings-panel:not(.hidden) { transform: translateX(0); }
.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}
.settings-header h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: #fff;
}
.settings-header button {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}
.settings-body label {
  display: block;
  margin-bottom: 12px;
  font-size: 10px;
  color: #aaa;
}
.settings-body select, .settings-body input[type="checkbox"] {
  margin-top: 4px;
}
.settings-body select {
  display: block;
  width: 100%;
  background: #222;
  color: #ddd;
  border: 1px solid #444;
  padding: 5px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
}
.channel-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.channel-toggles label {
  font-size: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 0;
}

/* Drop Overlay */
#drop-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(106,13,173,0.85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
#drop-overlay.active { display: flex; }
.drop-content {
  text-align: center;
  color: #fff;
  font-family: 'Press Start 2P', monospace;
}
.cartridge-icon {
  font-size: 80px;
  animation: cart-bounce 0.6s ease-in-out infinite alternate;
}
@keyframes cart-bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-20px); }
}
.drop-content p { font-size: 14px; margin-top: 15px; }

/* Footer */
footer {
  margin-top: 15px;
  text-align: center;
  font-size: 9px;
  color: #555;
}
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }
footer .tiny { font-size: 7px; margin-top: 4px; color: #444; }

/* Splash screen on canvas */
@keyframes splash-scan {
  0% { transform: translateY(-100%); }
  100% { transform: translateY(100%); }
}

/* Mobile adjustments */
@media (max-width: 520px) {
  #gameboy-shell { max-width: 100%; border-radius: 14px 14px 40px 14px; padding: 10px 12px 25px; }
  #canvas { width: 256px; height: 230px; }
  #screen-bezel { padding: 8px; }
  .dpad-btn { width: 32px; height: 32px; }
  #dpad { grid-template-columns: 32px 32px 32px; grid-template-rows: 32px 32px 32px; }
  .ab-btn { width: 40px; height: 40px; font-size: 9px; }
  #toolbar { font-size: 7px; }
  #toolbar button { padding: 5px 6px; font-size: 7px; }
}