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

:root {
  --gbc-teal: #009688;
  --gbc-purple: #5A328E;
  --gbc-dark: #1a1a2e;
  --gbc-darker: #0f0f1e;
  --lcd-green: #9BBC0F;
  --lcd-dark-green: #0f380f;
  --lcd-bg: #8bac0f;
  --shell-color: #6B3FA0;
  --shell-gradient-top: #7B4FB8;
  --shell-gradient-bot: #4A2570;
  --screen-bezel: #3a3a4a;
  --btn-color: #e6c83e;
  --text-bright: #e0e0e0;
  --text-dim: #8a8a9a;
}

body {
  font-family: 'Press Start 2P', monospace;
  background-color: var(--gbc-darker);
  background-image:
    radial-gradient(circle at 20% 50%, rgba(90, 50, 142, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(0, 150, 136, 0.1) 0%, transparent 50%),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 3px,
      rgba(255,255,255,0.01) 3px,
      rgba(255,255,255,0.01) 4px
    );
  color: var(--text-bright);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* HEADER */
#header {
  background: linear-gradient(135deg, var(--gbc-purple) 0%, #3a1a5e 100%);
  padding: 20px 16px 16px;
  text-align: center;
  border-bottom: 4px solid var(--lcd-green);
  position: relative;
}

#header h1 {
  font-size: 18px;
  color: var(--btn-color);
  text-shadow: 2px 2px 0 rgba(0,0,0,0.5);
  letter-spacing: 1px;
}

#header .header-emoji {
  font-family: sans-serif;
}

.tagline {
  font-size: 8px;
  color: var(--lcd-green);
  margin-top: 8px;
  letter-spacing: 0.5px;
  opacity: 0.9;
}

/* MAIN LAYOUT */
#app {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: flex-start;
  gap: 30px;
  padding: 30px 20px;
  flex: 1;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

/* GAMEBOY SHELL */
#gameboy-column {
  flex-shrink: 0;
}

#gameboy-shell {
  width: 320px;
  background: linear-gradient(180deg, var(--shell-gradient-top) 0%, var(--shell-color) 30%, var(--shell-gradient-bot) 100%);
  border-radius: 20px 20px 20px 80px;
  padding: 12px 20px 20px;
  position: relative;
  box-shadow:
    0 0 0 3px #2a1545,
    0 8px 30px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.15);
}

#gameboy-top-ridge {
  width: 60%;
  height: 6px;
  background: linear-gradient(180deg, rgba(255,255,255,0.15), transparent);
  border-radius: 0 0 4px 4px;
  margin: 0 auto 6px;
}

#screen-label {
  text-align: center;
  font-size: 5px;
  color: rgba(255,255,255,0.4);
  letter-spacing: 2px;
  margin-bottom: 4px;
}

#screen-bezel {
  background: var(--screen-bezel);
  border-radius: 12px;
  padding: 8px 10px 12px;
  margin-bottom: 10px;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.5);
}

#power-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 5px;
  color: rgba(255,255,255,0.3);
  margin-bottom: 4px;
  margin-left: 4px;
}

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

#power-dot.on {
  background: #ff1744;
  box-shadow: 0 0 6px #ff1744;
}

#screen-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 160/144;
  background: var(--lcd-dark-green);
  border-radius: 4px;
  overflow: hidden;
  image-rendering: pixelated;
}

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

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

#drop-zone-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  background: rgba(15, 56, 15, 0.85);
}

#drop-zone-overlay span {
  font-size: 10px;
  color: var(--lcd-green);
  text-align: center;
  line-height: 2;
}

#drop-zone-overlay.dragover {
  opacity: 1;
}

#brand-label {
  text-align: center;
  font-size: 11px;
  color: rgba(255,255,255,0.6);
  margin: 8px 0 12px;
  letter-spacing: 1px;
}

.color-text {
  display: inline-block;
  margin-left: 4px;
  font-size: 9px;
  font-style: italic;
  background: linear-gradient(90deg, #ff4444, #ff8800, #ffdd00, #44cc44, #4488ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* GAMEBOY DECORATIVE CONTROLS */
#gameboy-controls-deco {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 10px;
  margin-bottom: 10px;
}

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

.dpad-h, .dpad-v {
  position: absolute;
  background: #1a1a2e;
  border-radius: 3px;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.5);
}

.dpad-h {
  width: 100%;
  height: 33%;
  top: 33%;
}

.dpad-v {
  height: 100%;
  width: 33%;
  left: 33%;
}

.dpad-center {
  position: absolute;
  width: 33%;
  height: 33%;
  top: 33%;
  left: 33%;
  background: #222;
  border-radius: 2px;
}

#ab-buttons {
  display: flex;
  gap: 10px;
  transform: rotate(-25deg);
}

.ab-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(180deg, #9a1654, #6a0f3a);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  color: rgba(255,255,255,0.4);
  box-shadow: 0 3px 0 #3a0820, inset 0 1px 0 rgba(255,255,255,0.15);
}

#start-select {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 10px;
}

.ss-btn {
  width: 36px;
  height: 8px;
  background: #2a1545;
  border-radius: 10px;
  font-size: 4px;
  color: rgba(255,255,255,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.4);
  padding-top: 1px;
}

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

.grille-line {
  width: 24px;
  height: 2px;
  background: rgba(0,0,0,0.25);
  border-radius: 1px;
}

/* CONTROLS COLUMN */
#controls-column {
  flex: 1;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.control-section {
  background: rgba(255,255,255,0.04);
  border: 2px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 14px;
}

.control-label {
  display: block;
  font-size: 8px;
  color: var(--lcd-green);
  margin-bottom: 10px;
  letter-spacing: 1px;
}

/* CARTRIDGE BUTTON */
.cartridge-btn {
  width: 100%;
  padding: 14px 16px;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: #1a1a2e;
  background: linear-gradient(180deg, #f5d44a, #c9a012);
  border: 3px solid #8a6e0a;
  border-radius: 8px;
  cursor: pointer;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 0 #6b550a, 0 6px 12px rgba(0,0,0,0.3);
  transition: transform 0.1s, box-shadow 0.1s;
  text-align: center;
}

.cartridge-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 0 #6b550a, 0 8px 16px rgba(0,0,0,0.3);
}

.cartridge-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #6b550a, 0 2px 4px rgba(0,0,0,0.3);
}

.save-btn {
  margin-top: 12px;
  background: linear-gradient(180deg, var(--gbc-teal), #006b60);
  border-color: #004d44;
  color: white;
  box-shadow: 0 4px 0 #003d36, 0 6px 12px rgba(0,0,0,0.3);
}

.save-btn:hover {
  box-shadow: 0 5px 0 #003d36, 0 8px 16px rgba(0,0,0,0.3);
}

.save-btn:active {
  box-shadow: 0 1px 0 #003d36, 0 2px 4px rgba(0,0,0,0.3);
}

/* PALETTE LIST */
#palette-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
}

.palette-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s, background 0.15s;
}

.palette-row:hover {
  background: rgba(255,255,255,0.06);
}

.palette-row.active {
  border-color: var(--lcd-green);
  background: rgba(155, 188, 15, 0.1);
}

.palette-name {
  font-size: 7px;
  color: var(--text-dim);
  width: 80px;
  flex-shrink: 0;
}

.palette-row.active .palette-name {
  color: var(--lcd-green);
}

.palette-swatches {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
}

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

/* SLIDERS */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 8px;
  background: #2a2a3e;
  border-radius: 4px;
  outline: none;
  border: 1px solid rgba(255,255,255,0.1);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--lcd-green);
  cursor: pointer;
  box-shadow: 0 0 4px rgba(155,188,15,0.5);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--lcd-green);
  cursor: pointer;
  border: none;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.slider-row input[type="range"] {
  flex: 1;
}

.slider-label {
  font-size: 6px;
  color: var(--text-dim);
  white-space: nowrap;
}

.slider-value {
  font-size: 7px;
  color: var(--text-dim);
  text-align: center;
  margin-top: 4px;
}

/* TOGGLE BUTTONS */
.toggle-group {
  display: flex;
  gap: 4px;
}

.toggle-btn {
  flex: 1;
  padding: 8px 4px;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: var(--text-dim);
  background: #1a1a2e;
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.toggle-btn:hover {
  background: #252540;
}

.toggle-btn.active {
  color: var(--gbc-dark);
  background: var(--lcd-green);
  border-color: var(--lcd-green);
}

/* FOOTER */
#footer {
  text-align: center;
  padding: 20px 16px;
  border-top: 2px solid rgba(255,255,255,0.06);
  margin-top: auto;
}

#footer p {
  font-size: 7px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.remix-link {
  display: inline-block;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: var(--lcd-green);
  text-decoration: none;
  border: 2px solid var(--lcd-green);
  padding: 8px 16px;
  border-radius: 6px;
  transition: all 0.15s;
}

.remix-link:hover {
  background: var(--lcd-green);
  color: var(--gbc-dark);
}

/* SCROLLBAR */
#palette-list::-webkit-scrollbar {
  width: 6px;
}

#palette-list::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.02);
  border-radius: 3px;
}

#palette-list::-webkit-scrollbar-thumb {
  background: rgba(155,188,15,0.3);
  border-radius: 3px;
}

/* BOOT ANIMATION */
@keyframes bootFlicker {
  0% { opacity: 0; }
  10% { opacity: 1; background: #e0e8d0; }
  20% { opacity: 0.5; }
  30% { opacity: 1; background: #c8d8a0; }
  50% { opacity: 0.8; }
  100% { opacity: 1; background: transparent; }
}

.boot-animation {
  animation: bootFlicker 0.6s ease-out;
}

/* RESPONSIVE */
@media (max-width: 750px) {
  #app {
    flex-direction: column;
    align-items: center;
    padding: 16px 12px;
    gap: 20px;
  }

  #gameboy-shell {
    width: 280px;
  }

  #controls-column {
    max-width: 100%;
    width: 100%;
  }

  #header h1 {
    font-size: 14px;
  }

  .tagline {
    font-size: 7px;
  }
}

@media (max-width: 360px) {
  #gameboy-shell {
    width: 260px;
  }
}