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

:root {
  --shell-color: #6B3FA0;
  --shell-light: #8B5FCC;
  --shell-dark: #4A2870;
  --shell-shadow: #3A1860;
  --screen-bg: #0f380f;
}

body {
  font-family: 'Press Start 2P', monospace;
  background: #0a0a14;
  min-height: 100vh;
  overflow-x: hidden;
  color: #ccc;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stars-bg {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 0;
  pointer-events: none;
}

.star {
  position: absolute;
  width: 2px;
  height: 2px;
  background: #fff;
  border-radius: 50%;
  animation: twinkle var(--dur) ease-in-out infinite alternate;
}

@keyframes twinkle {
  0% { opacity: 0.2; }
  100% { opacity: 1; }
}

.top-bar {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 16px;
  width: 100%;
  max-width: 700px;
}

.top-bar h1 {
  font-size: 12px;
  color: #e8b4f8;
  text-shadow: 0 0 10px rgba(200,100,255,0.4);
  white-space: nowrap;
}

.color-picker {
  display: flex;
  gap: 6px;
  align-items: center;
}

.color-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
}

.color-dot:hover { transform: scale(1.2); }
.color-dot.active { border-color: #fff; box-shadow: 0 0 6px rgba(255,255,255,0.5); }

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

.ctrl-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  background: #1a1a2e;
  color: #aaa;
  border: 1px solid #333;
  padding: 5px 8px;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.15s;
}

.ctrl-btn:hover { background: #2a2a3e; color: #fff; }
.ctrl-btn.active { background: #3a2a5e; color: #e8b4f8; border-color: #8B5FCC; }

.load-btn {
  background: #2a1a4e !important;
  color: #e8b4f8 !important;
  border-color: #8B5FCC !important;
}
.load-btn:hover {
  background: #3a2a6e !important;
}

.rom-info {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 7px;
  color: #8B8B8B;
  flex-wrap: wrap;
}

.rom-tag {
  background: #1a1a2e;
  border: 1px solid #333;
  padding: 2px 5px;
  border-radius: 2px;
  font-size: 6px;
  color: #8B5FCC;
}

.fps-counter {
  color: #4a4;
  font-size: 6px;
}

/* GAMEBOY SHELL */
.gb-container {
  position: relative;
  z-index: 10;
  margin: 8px auto;
}

.gb-shell {
  position: relative;
  width: 320px;
  background: var(--shell-color);
  border-radius: 16px 16px 16px 80px;
  padding: 16px 20px 24px;
  box-shadow:
    inset 2px 2px 4px var(--shell-light),
    inset -2px -2px 4px var(--shell-dark),
    0 8px 32px rgba(0,0,0,0.6),
    0 2px 4px rgba(0,0,0,0.3);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: box-shadow 0.3s;
}

.gb-shell.drag-over {
  box-shadow:
    inset 2px 2px 4px var(--shell-light),
    inset -2px -2px 4px var(--shell-dark),
    0 8px 32px rgba(0,0,0,0.6),
    0 0 30px rgba(139,95,204,0.6);
}

.gb-shell.atomic-purple {
  background: linear-gradient(135deg,
    rgba(140,80,200,0.7) 0%,
    rgba(100,50,160,0.6) 30%,
    rgba(160,100,220,0.7) 50%,
    rgba(80,40,140,0.6) 70%,
    rgba(140,80,200,0.7) 100%
  );
  backdrop-filter: blur(2px);
}

.gb-shell.atomic-purple::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  border-radius: inherit;
  background: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 10px,
    rgba(255,255,255,0.03) 10px,
    rgba(255,255,255,0.03) 20px
  );
  pointer-events: none;
}

.gb-top-ridge {
  position: absolute;
  top: -4px;
  left: 40px;
  right: 40px;
  height: 8px;
  background: var(--shell-color);
  border-radius: 4px 4px 0 0;
  box-shadow: inset 1px 1px 2px var(--shell-light);
}

.gb-cart-slot {
  position: absolute;
  top: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: 80px;
  height: 6px;
  background: var(--shell-dark);
  border-radius: 0 0 4px 4px;
  box-shadow: inset 0 2px 3px rgba(0,0,0,0.3);
}

/* Screen area */
.screen-area {
  background: #2a2a3a;
  border-radius: 8px;
  padding: 12px 12px 16px;
  margin-bottom: 12px;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.5);
}

.screen-top-text {
  font-size: 4px;
  color: #666;
  text-align: center;
  margin-bottom: 6px;
  letter-spacing: 1.5px;
}

.screen-wrapper {
  position: relative;
  width: 256px;
  height: 230px;
  margin: 0 auto;
  background: #0f380f;
  border: 3px solid #1a1a28;
  border-radius: 4px;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.3);
  overflow: hidden;
}

.screen-wrapper canvas {
  display: block;
  width: 256px;
  height: 230px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.lcd-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 1px,
      rgba(0,0,0,0.04) 1px,
      rgba(0,0,0,0.04) 2px
    );
  pointer-events: none;
  z-index: 2;
}

.pause-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  pointer-events: none;
}

.pause-text {
  font-size: 16px;
  color: #fff;
  text-shadow: 0 0 10px rgba(255,255,255,0.5);
  animation: blink-pause 1s ease-in-out infinite;
}

@keyframes blink-pause {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.drop-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(139,95,204,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4;
  pointer-events: none;
  border: 3px dashed #8B5FCC;
}

.drop-text {
  font-size: 14px;
  color: #e8b4f8;
  text-shadow: 0 0 10px rgba(200,100,255,0.6);
}

.power-led {
  position: absolute;
  top: 8px;
  left: -20px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #333;
  transition: all 0.3s;
}

.power-led.on {
  background: #4f4;
  box-shadow: 0 0 6px #4f4, 0 0 12px rgba(60,255,60,0.3);
  animation: led-pulse 2s ease-in-out infinite;
}

@keyframes led-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.screen-bottom {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 6px;
}

.gb-logo-text {
  font-size: 6px;
  color: #555;
  letter-spacing: 2px;
}

.color-text {
  font-size: 5px;
  font-weight: bold;
  background: linear-gradient(90deg, #ff0000, #ff8800, #ffff00, #00cc00, #0066ff, #8800cc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* CONTROLS */
.controls-area {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0 8px;
  margin-top: 8px;
}

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

.dpad-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 28px;
  height: 28px;
  background: #2a2a2a;
  border-radius: 50%;
  z-index: 2;
}

.dpad-btn {
  position: absolute;
  background: #2a2a2a;
  cursor: pointer;
  transition: all 0.08s;
  z-index: 1;
}

.dpad-btn:active, .dpad-btn.pressed {
  filter: brightness(0.7);
  transform: scale(0.95);
}

.dpad-up {
  top: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 28px;
  height: 36px;
  border-radius: 6px 6px 0 0;
  box-shadow: inset 0 2px 3px rgba(80,80,80,0.3), 0 -1px 2px rgba(0,0,0,0.3);
}

.dpad-down {
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 28px;
  height: 36px;
  border-radius: 0 0 6px 6px;
  box-shadow: inset 0 -2px 3px rgba(80,80,80,0.3), 0 1px 2px rgba(0,0,0,0.3);
}

.dpad-left {
  left: 2px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 28px;
  border-radius: 6px 0 0 6px;
  box-shadow: inset 2px 0 3px rgba(80,80,80,0.3), -1px 0 2px rgba(0,0,0,0.3);
}

.dpad-right {
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 28px;
  border-radius: 0 6px 6px 0;
  box-shadow: inset -2px 0 3px rgba(80,80,80,0.3), 1px 0 2px rgba(0,0,0,0.3);
}

.dpad-up.pressed { transform: translateX(-50%) scale(0.95); }
.dpad-down.pressed { transform: translateX(-50%) scale(0.95); }
.dpad-left.pressed { transform: translateY(-50%) scale(0.95); }
.dpad-right.pressed { transform: translateY(-50%) scale(0.95); }

/* AB BUTTONS */
.ab-container {
  position: relative;
  width: 110px;
  height: 90px;
  transform: rotate(-25deg);
  margin-top: 10px;
}

.ab-btn {
  position: absolute;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #8B1A4A;
  cursor: pointer;
  box-shadow:
    inset 1px 1px 3px rgba(255,100,150,0.3),
    inset -1px -1px 3px rgba(80,0,30,0.5),
    0 3px 6px rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.08s;
}

.ab-btn:active, .ab-btn.pressed {
  box-shadow:
    inset 2px 2px 4px rgba(80,0,30,0.5),
    0 1px 2px rgba(0,0,0,0.4);
  transform: scale(0.93);
}

.ab-btn span {
  font-size: 8px;
  color: rgba(255,255,255,0.6);
  transform: rotate(25deg);
  pointer-events: none;
}

.btn-a { right: 0; top: 10px; }
.btn-b { left: 0; bottom: 0; }

.ab-label {
  position: absolute;
  font-size: 6px;
  color: var(--shell-dark);
  transform: rotate(25deg);
}

.label-a { right: 10px; bottom: -14px; }
.label-b { left: 10px; bottom: -22px; }

/* START SELECT */
.start-select-area {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin-top: 16px;
  padding: 0 40px;
}

.ss-btn-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.ss-btn {
  width: 36px;
  height: 12px;
  background: #3a3a3a;
  border-radius: 6px;
  cursor: pointer;
  transform: rotate(-25deg);
  box-shadow: inset 0 1px 2px rgba(80,80,80,0.3), 0 1px 3px rgba(0,0,0,0.3);
  transition: all 0.08s;
}

.ss-btn:active, .ss-btn.pressed {
  transform: rotate(-25deg) scale(0.93);
  filter: brightness(0.7);
}

.ss-label {
  font-size: 5px;
  color: var(--shell-dark);
  letter-spacing: 1px;
}

/* SPEAKER */
.speaker-area {
  position: absolute;
  bottom: 30px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transform: rotate(-25deg);
}

.speaker-line {
  width: 32px;
  height: 3px;
  background: var(--shell-dark);
  border-radius: 2px;
  box-shadow: inset 0 1px 1px rgba(0,0,0,0.3);
}

/* FOOTER */
.app-footer {
  position: relative;
  z-index: 10;
  text-align: center;
  padding: 16px;
  margin-top: 8px;
}

.app-footer a {
  color: #8B5FCC;
  text-decoration: none;
  font-size: 7px;
}

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

.app-footer .disclaimer {
  font-size: 5px;
  color: #555;
  margin-top: 6px;
}

.app-footer .controls-help {
  font-size: 5px;
  color: #444;
  margin-top: 4px;
}

/* SPARKLE */
@keyframes sparkle {
  0%, 100% { opacity: 0; transform: scale(0); }
  50% { opacity: 1; transform: scale(1); }
}

.sparkle-dot {
  position: absolute;
  width: 4px;
  height: 4px;
  background: #fff;
  border-radius: 50%;
  pointer-events: none;
  animation: sparkle var(--dur) ease-in-out infinite;
  animation-delay: var(--delay);
  z-index: 20;
}

/* RESPONSIVE */
@media (max-width: 380px) {
  .gb-shell {
    width: 290px;
    padding: 12px 14px 20px;
  }
  .screen-wrapper {
    width: 224px;
    height: 201px;
  }
  .screen-wrapper canvas {
    width: 224px;
    height: 201px;
  }
}

@media (max-height: 700px) and (max-width: 500px) {
  .top-bar { padding: 6px 12px; gap: 6px; }
  .top-bar h1 { font-size: 9px; }
  .gb-shell { padding: 10px 16px 18px; }
  .screen-area { padding: 8px 8px 12px; margin-bottom: 8px; }
}