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

:root {
  --bg-dark: #0d0d1a;
  --bg-mid: #1a1a2e;
  --shell-color: #3d2066;
  --shell-highlight: #5a3491;
  --shell-shadow: #1f0f38;
  --accent-teal: #00ff88;
  --accent-red: #e94560;
  --accent-blue: #0f3460;
  --text-dim: #6a6a8a;
  --text-light: #c4c4e0;
  --screen-off: #2a3a2a;
  --btn-dark: #2a2a44;
  --btn-hover: #3a3a5a;
}

body {
  background: var(--bg-dark);
  background-image: 
    repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(255,255,255,0.008) 2px, rgba(255,255,255,0.008) 4px);
  color: var(--text-light);
  font-family: 'Press Start 2P', monospace;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  -webkit-user-select: none;
  user-select: none;
}

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

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

.title {
  font-size: clamp(14px, 4vw, 28px);
  color: var(--accent-teal);
  text-shadow: 0 0 20px rgba(0,255,136,0.5), 0 0 40px rgba(0,255,136,0.2);
  letter-spacing: 2px;
  margin-bottom: 6px;
}

.berry { filter: drop-shadow(0 0 8px rgba(233,69,96,0.6)); }

.subtitle {
  font-size: clamp(6px, 1.5vw, 9px);
  color: var(--text-dim);
  margin-bottom: 8px;
}

.badge {
  display: inline-block;
  font-size: 6px;
  color: var(--accent-teal);
  border: 1px solid rgba(0,255,136,0.3);
  padding: 3px 8px;
  border-radius: 3px;
  background: rgba(0,255,136,0.05);
}

/* SHELL */
#emulator-wrapper { perspective: 800px; }

#shell {
  background: linear-gradient(145deg, var(--shell-highlight), var(--shell-color), var(--shell-shadow));
  border-radius: 16px 16px 40px 40px;
  padding: 16px 20px 24px;
  position: relative;
  box-shadow: 
    0 8px 32px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.1),
    inset 0 -2px 0 rgba(0,0,0,0.3);
  min-width: 320px;
}

.shell-top-label {
  text-align: center;
  font-size: 8px;
  color: rgba(255,255,255,0.7);
  letter-spacing: 4px;
  margin-bottom: 8px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

#screen-bezel {
  background: #111;
  border-radius: 8px;
  padding: 12px;
  position: relative;
  box-shadow: inset 0 4px 12px rgba(0,0,0,0.8);
  margin-bottom: 16px;
}

#power-led {
  width: 6px; height: 6px;
  background: #333;
  border-radius: 50%;
  position: absolute;
  top: 6px; left: 16px;
  transition: background 0.3s;
}
#power-led.on {
  background: #ff2244;
  box-shadow: 0 0 6px #ff2244;
}

#canvas {
  display: block;
  width: 100%;
  max-width: 640px;
  aspect-ratio: 160/144;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: var(--screen-off);
  border-radius: 4px;
}

#screen-overlay {
  position: absolute;
  top: 12px; left: 12px; right: 12px; bottom: 12px;
  border-radius: 4px;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(0,0,0,0.03) 1px,
    rgba(0,0,0,0.03) 2px
  );
  opacity: 0;
  transition: opacity 0.3s;
}
#screen-overlay.active { opacity: 1; }

#drop-message {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: rgba(100,180,100,0.6);
  font-size: 8px;
  line-height: 2;
  pointer-events: none;
}
#drop-message .drop-icon {
  font-size: 32px;
  animation: pulse 2s ease-in-out infinite;
}
#drop-message.hidden { display: none; }

@keyframes pulse {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.1); }
}

/* CONTROLS */
#controls-area {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
}

#dpad-container { grid-column: 1; grid-row: 1; justify-self: center; }

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

.dpad-btn {
  background: #2a2040;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: rgba(255,255,255,0.5);
  cursor: pointer;
  transition: all 0.05s;
  box-shadow: inset 0 -2px 4px rgba(0,0,0,0.4);
}
.dpad-btn:active, .dpad-btn.pressed {
  background: #1a1030;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.6);
  transform: scale(0.95);
}
.dpad-up { border-radius: 6px 6px 0 0; grid-column: 2; grid-row: 1; }
.dpad-down { border-radius: 0 0 6px 6px; grid-column: 2; grid-row: 3; }
.dpad-left { border-radius: 6px 0 0 6px; grid-column: 1; grid-row: 2; }
.dpad-right { border-radius: 0 6px 6px 0; grid-column: 3; grid-row: 2; }
.dpad-center { background: #231838; grid-column: 2; grid-row: 2; }

#ab-buttons {
  grid-column: 2; grid-row: 1;
  display: flex;
  gap: 12px;
  justify-self: center;
  transform: rotate(-15deg);
}

.action-btn {
  width: 48px; height: 48px;
  border-radius: 50%;
  border: none;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: #fff;
  cursor: pointer;
  transition: all 0.05s;
}
.btn-a {
  background: linear-gradient(145deg, #e94560, #b8344d);
  box-shadow: 0 4px 8px rgba(233,69,96,0.4), inset 0 -3px 0 rgba(0,0,0,0.2);
}
.btn-b {
  background: linear-gradient(145deg, #e94560, #b8344d);
  box-shadow: 0 4px 8px rgba(233,69,96,0.4), inset 0 -3px 0 rgba(0,0,0,0.2);
}
.action-btn:active, .action-btn.pressed {
  transform: scale(0.92);
  box-shadow: 0 1px 2px rgba(233,69,96,0.4), inset 0 2px 0 rgba(0,0,0,0.3);
}

#ss-buttons {
  grid-column: 1 / -1; grid-row: 2;
  display: flex;
  gap: 16px;
  justify-content: center;
  transform: rotate(-10deg);
}

.ss-btn {
  background: #3a3050;
  border: none;
  border-radius: 12px;
  padding: 6px 14px;
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.3);
  transition: all 0.05s;
}
.ss-btn:active, .ss-btn.pressed {
  transform: scale(0.95);
  box-shadow: inset 0 2px 0 rgba(0,0,0,0.4);
}

.speaker-grille {
  position: absolute;
  bottom: 30px;
  right: 24px;
  display: grid;
  grid-template-columns: repeat(6, 6px);
  gap: 4px;
  transform: rotate(-30deg);
}
.grille-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: rgba(0,0,0,0.3);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.5);
}

/* TOOLBAR */
#toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 12px;
  max-width: 700px;
}

.tool-btn {
  background: var(--btn-dark);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  padding: 6px 10px;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.tool-btn:hover:not(:disabled) { background: var(--btn-hover); border-color: var(--accent-teal); }
.tool-btn:disabled { opacity: 0.4; cursor: default; }

.tool-group { display: flex; align-items: center; gap: 4px; }

.vol-slider {
  width: 60px;
  accent-color: var(--accent-teal);
  cursor: pointer;
}

.tool-select {
  background: var(--btn-dark);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  color: var(--text-light);
  cursor: pointer;
}

/* STATUS */
#status-bar {
  display: flex;
  gap: 16px;
  font-size: 6px;
  color: var(--text-dim);
  margin-top: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

#key-legend {
  font-size: 6px;
  color: var(--text-dim);
  margin-top: 6px;
  text-align: center;
  opacity: 0.6;
}

/* DEBUG */
#debug-panel {
  position: fixed;
  right: 0;
  top: 0;
  width: 280px;
  height: 100vh;
  background: rgba(13,13,26,0.97);
  border-left: 2px solid var(--accent-teal);
  padding: 12px;
  overflow-y: auto;
  font-size: 7px;
  z-index: 100;
  transition: transform 0.3s;
}
#debug-panel.hidden { transform: translateX(100%); }
#debug-panel h3 {
  color: var(--accent-teal);
  font-size: 8px;
  margin: 10px 0 4px;
  border-bottom: 1px solid rgba(0,255,136,0.2);
  padding-bottom: 3px;
}
.debug-section {
  font-family: 'Courier New', monospace;
  color: var(--text-light);
  line-height: 1.8;
  font-size: 8px;
}
#debug-tiles {
  image-rendering: pixelated;
  width: 256px;
  height: 384px;
  background: #000;
  border: 1px solid rgba(0,255,136,0.2);
  margin-top: 4px;
}

/* DRAG OVERLAY */
#drag-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13,13,26,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  transition: opacity 0.2s;
}
#drag-overlay.hidden { display: none; }
.drag-content {
  text-align: center;
  font-size: 14px;
  color: var(--accent-teal);
  animation: pulse 1.5s ease-in-out infinite;
}
.drag-content .drag-icon { font-size: 64px; margin-bottom: 16px; }

/* FOOTER */
#footer {
  margin-top: 24px;
  padding: 16px;
  text-align: center;
  font-size: 7px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#footer a {
  color: var(--accent-teal);
  text-decoration: none;
}
#footer a:hover { text-decoration: underline; }

.hidden { display: none !important; }

@media (max-width: 500px) {
  #shell { min-width: unset; width: 100%; padding: 10px 12px 20px; border-radius: 12px 12px 28px 28px; }
  .dpad-btn, .dpad-center { width: 44px; height: 44px; }
  #dpad { grid-template-columns: 44px 44px 44px; grid-template-rows: 44px 44px 44px; }
  .action-btn { width: 56px; height: 56px; font-size: 12px; }
  .speaker-grille { display: none; }
  .tool-btn { font-size: 6px; padding: 5px 7px; }
}