:root {
  --bg: #0d0d1a;
  --shell-body: #7b6ba5;
  --shell-dark: #5a4d80;
  --shell-highlight: #9b8cc5;
  --screen-off: #8bac0f;
  --screen-border: #2d2d3d;
  --teal: #00CED1;
  --berry: #c040a0;
  --red: #E60012;
  --cream: #f0e8d8;
  --toolbar-bg: #16162a;
  --btn-bg: #252540;
  --btn-hover: #353560;
}

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

html, body {
  width: 100%; height: 100%;
  background: var(--bg);
  font-family: 'IBM Plex Mono', monospace;
  color: var(--cream);
  overflow-x: hidden;
}

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

/* TOOLBAR */
#toolbar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 10px;
  background: var(--toolbar-bg);
  border-radius: 12px;
  margin-bottom: 12px;
  max-width: 600px;
  width: 100%;
}

#toolbar button, #toolbar select {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  background: var(--btn-bg);
  color: var(--cream);
  border: 1px solid #444;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

#toolbar button:hover:not(:disabled), #toolbar select:hover {
  background: var(--btn-hover);
  border-color: var(--teal);
}

#toolbar button:disabled {
  opacity: 0.4;
  cursor: default;
}

#toolbar select {
  appearance: auto;
}

/* GAME BOY SHELL */
#gameboy-shell {
  width: 340px;
  background: linear-gradient(165deg, var(--shell-highlight) 0%, var(--shell-body) 35%, var(--shell-dark) 100%);
  border-radius: 20px 20px 20px 80px;
  padding: 16px 20px 24px;
  box-shadow:
    0 0 0 3px #4a3d70,
    0 8px 32px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.15);
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

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

#power-led {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #333;
  box-shadow: none;
  transition: all 0.5s;
}

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

#screen-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 5px;
  color: #3a2d60;
  letter-spacing: 0.5px;
}

/* SCREEN BEZEL */
#screen-bezel {
  background: #1a1a2e;
  border-radius: 8px;
  padding: 16px 20px;
  margin: 0 auto;
  width: 100%;
  position: relative;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.6), inset 0 0 2px rgba(0,0,0,0.8);
}

#lcd {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  background: var(--screen-off);
  border-radius: 2px;
  box-shadow: inset 0 0 4px rgba(0,0,0,0.3);
}

#welcome-msg {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: #306230;
  text-align: center;
  line-height: 1.8;
  pointer-events: none;
  padding: 0 30px;
}

/* COLOR LABEL */
#color-label {
  text-align: center;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 4px;
  margin: 8px 0 4px;
}

.c-c { color: #ff4060; }
.c-o { color: #ff8020; }
.c-l { color: #ffd020; }
.c-o2 { color: #40c040; }
.c-r { color: #4080ff; }

/* CONTROLS */
#controls-area {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 8px 6px;
}

/* D-PAD */
#dpad-container {
  width: 100px;
  height: 100px;
  position: relative;
}

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

.dpad-btn {
  position: absolute;
  background: #2a2040;
  z-index: 2;
  cursor: pointer;
  transition: background 0.05s;
}

.dpad-btn:active, .dpad-btn.pressed {
  background: #1a1030;
}

.dpad-up {
  width: 32px; height: 34px;
  left: 34px; top: 0;
  border-radius: 4px 4px 0 0;
}

.dpad-down {
  width: 32px; height: 34px;
  left: 34px; bottom: 0;
  border-radius: 0 0 4px 4px;
}

.dpad-left {
  width: 34px; height: 32px;
  left: 0; top: 34px;
  border-radius: 4px 0 0 4px;
}

.dpad-right {
  width: 34px; height: 32px;
  right: 0; top: 34px;
  border-radius: 0 4px 4px 0;
}

.dpad-center {
  position: absolute;
  width: 32px; height: 32px;
  left: 34px; top: 34px;
  background: #2a2040;
  z-index: 3;
}

/* A/B BUTTONS */
#ab-container {
  display: flex;
  gap: 12px;
  transform: rotate(-25deg);
}

.ab-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid #3a2d60;
  background: #8B008B;
  color: var(--cream);
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  cursor: pointer;
  box-shadow: 0 3px 0 #5a0060, 0 4px 8px rgba(0,0,0,0.3);
  transition: all 0.05s;
  -webkit-tap-highlight-color: transparent;
}

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

#btn-a { background: #a020a0; }
#btn-b { background: #8B008B; }

/* START/SELECT */
#startselect-area {
  display: flex;
  justify-content: center;
  gap: 20px;
  padding: 8px 0;
  transform: rotate(-25deg);
}

.ss-btn {
  width: 52px;
  height: 16px;
  border-radius: 8px;
  border: 1px solid #3a2d60;
  background: #3a2d60;
  color: #8b7bb5;
  font-family: 'Press Start 2P', monospace;
  font-size: 5px;
  cursor: pointer;
  box-shadow: 0 2px 0 #2a1d50;
  transition: all 0.05s;
  -webkit-tap-highlight-color: transparent;
}

.ss-btn:active, .ss-btn.pressed {
  box-shadow: 0 0px 0 #2a1d50;
  transform: translateY(2px);
}

/* SPEAKER GRILLE */
#speaker-grille {
  position: absolute;
  bottom: 20px;
  right: 18px;
  width: 50px;
  height: 50px;
  transform: rotate(30deg);
}

.grille-dots {
  width: 100%;
  height: 100%;
  background-image: radial-gradient(circle, #5a4d70 2px, transparent 2px);
  background-size: 8px 8px;
  opacity: 0.6;
}

/* STATUS BAR */
#status-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  padding: 8px 16px;
  margin-top: 10px;
  background: var(--toolbar-bg);
  border-radius: 8px;
  font-size: 9px;
  font-family: 'Press Start 2P', monospace;
  max-width: 600px;
  width: 100%;
}

.badge {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 8px;
}

.badge-off { background: #333; color: #666; }
.badge-gb { background: #306230; color: #8bac0f; }
.badge-gbc { background: #1a4a8a; color: #60c0ff; }

/* SETTINGS DRAWER */
#settings-drawer {
  position: fixed;
  top: 0; right: 0;
  width: 280px;
  height: 100vh;
  background: #1a1a30;
  border-left: 2px solid var(--teal);
  z-index: 1000;
  overflow-y: auto;
  transition: transform 0.3s ease;
}

#settings-drawer.hidden {
  transform: translateX(100%);
}

#settings-content {
  padding: 20px;
}

#settings-content h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  color: var(--teal);
  margin-bottom: 20px;
}

.setting-group {
  margin-bottom: 16px;
}

.setting-group > label {
  display: block;
  font-size: 10px;
  font-family: 'Press Start 2P', monospace;
  color: var(--cream);
  margin-bottom: 6px;
}

.setting-group select {
  width: 100%;
  padding: 6px;
  background: var(--btn-bg);
  color: var(--cream);
  border: 1px solid #444;
  border-radius: 4px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
}

.channel-toggles label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0;
}

.ch-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: var(--teal);
  background: rgba(0,206,209,0.1);
  padding: 1px 4px;
  border-radius: 3px;
}

.kbd-info {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: #aaa;
  line-height: 1.6;
}

#settings-close {
  margin-top: 16px;
  width: 100%;
  padding: 8px;
  background: var(--berry);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
}

/* TOAST */
#toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: #2a1a40;
  color: var(--cream);
  padding: 10px 20px;
  border-radius: 8px;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  border: 1px solid var(--berry);
  z-index: 999;
  transition: opacity 0.3s;
  text-align: center;
  max-width: 90vw;
}

#toast.hidden { opacity: 0; pointer-events: none; }

/* FOOTER */
footer {
  margin-top: 16px;
  padding: 12px;
  text-align: center;
  font-size: 9px;
  color: #555;
}

footer a {
  color: var(--teal);
  text-decoration: none;
  margin-left: 8px;
}

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

.berry-icon { font-size: 12px; }

/* DRAG OVER HIGHLIGHT */
#screen-bezel.drag-over {
  box-shadow: inset 0 0 20px rgba(0,206,209,0.4), inset 0 2px 8px rgba(0,0,0,0.6);
}

/* FULLSCREEN */
#gameboy-shell:fullscreen,
#gameboy-shell:-webkit-full-screen {
  background: #000;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border-radius: 0;
}

/* RESPONSIVE */
@media (max-width: 400px) {
  #gameboy-shell {
    width: 100%;
    border-radius: 12px;
    padding: 10px 12px 20px;
  }

  #toolbar button, #toolbar select {
    font-size: 7px;
    padding: 5px 7px;
  }

  .ab-btn {
    width: 38px;
    height: 38px;
    font-size: 9px;
  }

  #dpad-container, #dpad {
    width: 84px;
    height: 84px;
  }

  .dpad-up { width: 28px; height: 28px; left: 28px; }
  .dpad-down { width: 28px; height: 28px; left: 28px; }
  .dpad-left { width: 28px; height: 28px; top: 28px; }
  .dpad-right { width: 28px; height: 28px; top: 28px; }
  .dpad-center { width: 28px; height: 28px; left: 28px; top: 28px; }
}

@keyframes powerOn {
  0% { opacity: 0.5; filter: brightness(0.5); }
  100% { opacity: 1; filter: brightness(1); }
}

.power-on-anim {
  animation: powerOn 0.6s ease-out;
}