@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;
  --jit-amber: #f0a020;
  --jit-green: #30d050;
}

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: 18px;
  color: var(--gb-darkest);
  text-shadow: 2px 2px 0 var(--gb-dark);
}
.subtitle {
  font-size: 6px;
  color: #555;
  margin-top: 6px;
  max-width: 380px;
}

/* JIT Badge */
.jit-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #444;
  font-size: 12px;
  cursor: help;
  transition: background 0.3s, box-shadow 0.3s;
}
.jit-badge.compiling {
  background: var(--jit-amber);
  box-shadow: 0 0 8px var(--jit-amber), 0 0 16px var(--jit-amber);
  animation: jit-pulse 0.6s ease-in-out infinite;
}
.jit-badge.cached {
  background: var(--jit-green);
  box-shadow: 0 0 6px var(--jit-green);
}
@keyframes jit-pulse {
  0%,100% { opacity:1; transform:scale(1); }
  50% { opacity:0.7; transform:scale(1.1); }
}

/* 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);
  animation: cart-insert 0.3s ease-out;
}
@keyframes cart-insert {
  0% { transform: translateY(-10px); }
  60% { transform: translateY(2px); }
  100% { transform: translateY(0); }
}
.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: 480px;
}
.toolbar button, .toolbar select {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 5px 7px;
  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: 50px;
  height: 8px;
}

/* JIT Popover */
.jit-popover {
  position: absolute;
  z-index: 50;
  background: #1a1a2e;
  border: 2px solid var(--jit-amber);
  border-radius: 8px;
  padding: 12px;
  color: #eee;
  width: 260px;
  font-size: 7px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  top: 200px;
}
.jit-popover h4 {
  font-size: 9px;
  color: var(--jit-amber);
  margin-bottom: 8px;
  text-align: center;
}
.jit-setting {
  margin-bottom: 8px;
}
.jit-setting label {
  display: block;
  margin-bottom: 3px;
  color: #aaa;
}
.jit-setting select, .jit-setting input[type=range] {
  width: 100%;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  background: #0a0a1e;
  color: var(--jit-green);
  border: 1px solid #333;
  border-radius: 3px;
  padding: 2px;
}
.jit-flush-btn {
  width: 100%;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 5px;
  background: #8b1a4a;
  color: #fff;
  border: 1px solid #5a0a2a;
  border-radius: 4px;
  cursor: pointer;
  margin-bottom: 8px;
}
.jit-flush-btn:hover { background: #a02060; }
.jit-stats {
  background: #0a0a1e;
  border: 1px solid #333;
  border-radius: 4px;
  padding: 6px;
  line-height: 2;
  color: var(--jit-green);
}

/* 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;
}
.exec-mode-tag {
  position: absolute;
  bottom: 4px; right: 4px;
  font-size: 5px;
  color: rgba(15,56,15,0.5);
  pointer-events: none;
  padding: 1px 3px;
  border-radius: 2px;
  background: rgba(155,188,15,0.3);
}

.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: 340px;
  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;
}

/* JIT Heatmap */
.jit-heatmap-container {
  margin-top: 6px;
}
#jit-heatmap {
  width: 256px;
  height: 64px;
  border: 1px solid #333;
  image-rendering: pixelated;
  background: #000;
}
.jit-hot-blocks {
  margin-top: 6px;
}
.jit-hot-blocks pre {
  color: var(--jit-amber);
}

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

/* Toast */
#toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

/* 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%); }
  .jit-popover { width: 220px; left: 10px; }
  .title-row h1 { font-size: 14px; }
}