@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

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

:root {
  --gb-darkest: #0f380f;
  --gb-dark: #306230;
  --gb-light: #8bac0f;
  --gb-lightest: #9bbc0f;
  --shell-color: #c4cfa1;
  --shell-dark: #a8b48a;
  --accent: #8b1a4a;
  --screen-bg: #9bbc0f;
}

body {
  font-family: 'Press Start 2P', monospace;
  background: #b0b8a0;
  background-image: 
    radial-gradient(circle, #a0a890 1px, transparent 1px);
  background-size: 8px 8px;
  min-height: 100vh;
  color: #2a2a2a;
  overflow-x: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  max-width: 900px;
  margin: 0 auto;
  position: relative;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 12px;
}
.title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.title-row h1 {
  font-size: 20px;
  color: var(--gb-darkest);
  text-shadow: 2px 2px 0 var(--gb-dark);
}
.subtitle {
  font-size: 7px;
  color: #555;
  margin-top: 6px;
}

/* LED */
.led-indicator {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #555;
  box-shadow: 0 0 2px #333;
  display: inline-block;
}
.led-indicator.on {
  background: #0f0;
  box-shadow: 0 0 8px #0f0, 0 0 16px #0f0;
  animation: led-blink 1.5s ease-in-out infinite;
}
@keyframes led-blink {
  0%,100% { opacity:1; }
  50% { opacity:0.6; }
}

/* Cartridge Drop */
.cartridge {
  width: 260px;
  background: #8a8a8a;
  border-radius: 10px 10px 4px 4px;
  padding: 8px;
  margin-bottom: 10px;
  cursor: pointer;
  border: 2px solid #666;
  position: relative;
  transition: transform 0.2s, box-shadow 0.2s;
}
.cartridge:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.cartridge.loaded {
  background: #7a7a9a;
  border-color: var(--accent);
}
.cartridge-notch {
  width: 40px; height: 8px;
  background: #666;
  border-radius: 0 0 4px 4px;
  margin: 0 auto 6px;
}
.cartridge-label {
  background: #f5f0e0;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 10px 8px;
  text-align: center;
}
.cart-text { font-size: 7px; color: #333; margin-bottom:4px; }
.cart-text-small { font-size: 6px; color: #666; margin-bottom: 2px; }
.cart-ext { font-size: 5px; color: #999; }

/* Cart Info */
.cart-info {
  font-size: 6px;
  color: var(--gb-darkest);
  background: rgba(255,255,255,0.6);
  border: 1px solid var(--gb-dark);
  border-radius: 4px;
  padding: 6px 10px;
  margin-bottom: 8px;
  max-width: 400px;
  text-align: center;
  line-height: 1.8;
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  margin-bottom: 10px;
  max-width: 440px;
}
.toolbar button, .toolbar select {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  padding: 5px 8px;
  border: 2px solid #555;
  border-radius: 4px;
  background: #d0d0d0;
  cursor: pointer;
  color: #222;
}
.toolbar button:hover, .toolbar select:hover {
  background: #bbb;
}
.toolbar button:active {
  transform: scale(0.95);
}
.toolbar button.active {
  background: var(--accent);
  color: #fff;
  border-color: #5a0a2a;
}
.vol-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
}
.vol-label input[type=range] {
  width: 60px;
  height: 8px;
}

/* Game Boy Shell */
.gameboy-shell {
  background: var(--shell-color);
  border: 3px solid var(--shell-dark);
  border-radius: 20px 20px 20px 60px;
  padding: 16px 20px 24px;
  box-shadow: 
    4px 4px 0 var(--shell-dark),
    inset 0 2px 4px rgba(255,255,255,0.4),
    0 8px 24px rgba(0,0,0,0.3);
  max-width: 420px;
  width: 100%;
}

/* Screen Bezel */
.screen-bezel {
  background: #3a3a5a;
  border-radius: 12px;
  padding: 10px 14px 14px;
  margin-bottom: 10px;
  box-shadow: inset 0 3px 8px rgba(0,0,0,0.5);
}
.dot-matrix-label {
  font-size: 5px;
  color: #8888aa;
  text-align: center;
  margin-bottom: 4px;
  letter-spacing: 1px;
}
.power-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}
.power-led {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #500;
}
.power-led.on {
  background: #f00;
  box-shadow: 0 0 4px #f00;
}
.power-text {
  font-size: 5px;
  color: #8888aa;
}

/* Screen */
.screen-container {
  position: relative;
  background: var(--screen-bg);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}
#canvas {
  width: 320px;
  height: 288px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
  background: var(--gb-lightest);
}
.scanline-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(0,0,0,0.08) 1px,
    rgba(0,0,0,0.08) 2px
  );
  pointer-events: none;
}
.fps-counter {
  position: absolute;
  top: 4px; right: 4px;
  font-size: 6px;
  color: rgba(15,56,15,0.6);
  pointer-events: none;
}
.speed-indicator {
  position: absolute;
  top: 4px; left: 4px;
  font-size: 6px;
  color: rgba(15,56,15,0.6);
  pointer-events: none;
}

.berry-boy-label {
  text-align: center;
  font-size: 14px;
  color: var(--shell-dark);
  letter-spacing: 4px;
  margin: 8px 0 4px;
  text-shadow: 1px 1px 0 rgba(255,255,255,0.5);
}

/* Controls */
.controls-area {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 10px 0;
}

/* D-Pad */
.dpad-container {
  display: grid;
  grid-template-columns: 36px 36px 36px;
  grid-template-rows: 36px 36px 36px;
  gap: 0;
}
.dpad {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ccc;
  -webkit-tap-highlight-color: transparent;
}
.dpad-up { grid-column:2; grid-row:1; background:#444; border-radius:4px 4px 0 0; }
.dpad-down { grid-column:2; grid-row:3; background:#444; border-radius:0 0 4px 4px; }
.dpad-left { grid-column:1; grid-row:2; background:#444; border-radius:4px 0 0 4px; }
.dpad-right { grid-column:3; grid-row:2; background:#444; border-radius:0 4px 4px 0; }
.dpad-center { grid-column:2; grid-row:2; background:#444; }
.dpad:active, .dpad.pressed { background:#333; transform:scale(0.93); }

/* AB Buttons */
.ab-container {
  display: flex;
  gap: 12px;
  transform: rotate(-20deg);
}
.ab-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #5a0a2a;
  color: #fff;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  cursor: pointer;
  box-shadow: 2px 3px 0 #5a0a2a;
  -webkit-tap-highlight-color: transparent;
}
.ab-btn:active, .ab-btn.pressed {
  box-shadow: 0 1px 0 #5a0a2a;
  transform: translateY(2px);
}

/* Start/Select */
.startsel-area {
  display: flex;
  justify-content: center;
  gap: 20px;
  padding: 8px 0 0;
  transform: rotate(-8deg);
}
.startsel-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  padding: 4px 12px;
  border-radius: 10px;
  background: #666;
  border: 2px solid #444;
  color: #ccc;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.startsel-btn:active, .startsel-btn.pressed {
  background: #444;
  transform: scale(0.95);
}

/* Debug Panel */
.debug-panel {
  position: fixed;
  right: 0;
  top: 0;
  width: 320px;
  height: 100vh;
  background: #0a0a1e;
  color: #0f0;
  overflow-y: auto;
  padding: 12px;
  font-size: 7px;
  border-left: 2px solid var(--gb-dark);
  z-index: 100;
  transition: transform 0.3s;
}
.debug-panel.hidden {
  transform: translateX(100%);
}
.debug-panel h3 {
  font-size: 10px;
  color: var(--gb-light);
  margin-bottom: 8px;
}
.debug-section {
  margin-bottom: 10px;
  border-bottom: 1px solid #1a3a1a;
  padding-bottom: 6px;
}
.debug-section h4 {
  font-size: 7px;
  color: var(--gb-lightest);
  margin-bottom: 4px;
}
.debug-section pre {
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.6;
}

.hidden { display: none !important; }
.debug-panel.hidden { display: block !important; }

/* Footer */
footer {
  text-align: center;
  margin-top: 20px;
  padding: 16px;
  font-size: 6px;
  color: #666;
}
footer a {
  color: var(--accent);
  text-decoration: none;
}
footer a:hover { text-decoration: underline; }
.disclaimer {
  margin-top: 6px;
  font-style: italic;
}

/* Responsive */
@media (max-width: 480px) {
  .gameboy-shell { padding: 10px 12px 16px; border-radius: 14px 14px 14px 40px; }
  #canvas { width: 260px; height: 234px; }
  .toolbar { font-size: 6px; }
  .toolbar button, .toolbar select { font-size: 6px; padding: 4px 5px; }
  .dpad-container { grid-template-columns: 30px 30px 30px; grid-template-rows: 30px 30px 30px; }
  .ab-btn { width: 36px; height: 36px; font-size: 8px; }
  .debug-panel { width: 100%; height: 50vh; top: auto; bottom: 0; border-left: none; border-top: 2px solid var(--gb-dark); }
  .debug-panel.hidden { transform: translateY(100%); }
}