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

body {
  background: linear-gradient(145deg, #1a1a1a 0%, #2d2d2d 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: 'Press Start 2P', monospace;
  overflow-x: hidden;
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

#gameboy-shell {
  position: relative;
  z-index: 1;
  background: linear-gradient(180deg, #4a4a50 0%, #3a3a40 50%, #2e2e34 100%);
  border-radius: 20px 20px 80px 20px;
  padding: 20px 24px 30px 24px;
  box-shadow:
    0 8px 32px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.1),
    inset 0 -2px 0 rgba(0,0,0,0.3);
  margin-top: 20px;
}

.shell-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding-left: 4px;
}

.power-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff2222;
  box-shadow: 0 0 6px #ff2222, 0 0 12px #ff222288;
  animation: ledPulse 3s ease-in-out infinite;
}

@keyframes ledPulse {
  0%, 100% { opacity: 0.8; box-shadow: 0 0 6px #ff2222, 0 0 12px #ff222244; }
  50% { opacity: 1; box-shadow: 0 0 8px #ff2222, 0 0 16px #ff222288; }
}

.shell-label-top {
  font-size: 6px;
  color: #888;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.screen-bezel {
  position: relative;
  background: #1a1a2e;
  border-radius: 8px;
  padding: 12px;
  box-shadow:
    inset 0 4px 8px rgba(0,0,0,0.5),
    inset 0 -1px 0 rgba(255,255,255,0.05);
}

#canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: 640px;
  height: 576px;
  border-radius: 4px;
}

.scanline-overlay {
  position: absolute;
  top: 12px; left: 12px; right: 12px; bottom: 12px;
  border-radius: 4px;
  background: repeating-linear-gradient(
    0deg,
    transparent 0px,
    transparent 3px,
    rgba(0,0,0,0.05) 3px,
    rgba(0,0,0,0.05) 4px
  );
  pointer-events: none;
}

.shell-bottom {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 12px;
  padding: 0 8px;
}

.shell-brand {
  font-size: 8px;
  color: #666;
  letter-spacing: 1px;
  opacity: 0.6;
}

.speaker-grille {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  transform: rotate(-25deg);
}

.speaker-grille .dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #2a2a30;
  box-shadow: inset 0 1px 1px rgba(0,0,0,0.5);
}

/* Controls - mobile virtual buttons */
#controls {
  display: none;
  position: relative;
  z-index: 1;
  margin-top: 16px;
  padding: 12px 20px;
  width: 100%;
  max-width: 680px;
}

.controls-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.dpad-container {
  display: grid;
  grid-template-areas:
    ". up ."
    "left center right"
    ". down .";
  grid-template-columns: 48px 48px 48px;
  grid-template-rows: 48px 48px 48px;
  gap: 0;
}

.dpad {
  background: #2a2a30;
  border: none;
  color: #888;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.dpad:active { background: #3a3a44; }
.dpad-up { grid-area: up; border-radius: 8px 8px 0 0; }
.dpad-down { grid-area: down; border-radius: 0 0 8px 8px; }
.dpad-left { grid-area: left; border-radius: 8px 0 0 8px; }
.dpad-right { grid-area: right; border-radius: 0 8px 8px 0; }
.dpad-center { grid-area: center; background: #2a2a30; }

.ab-container {
  display: flex;
  gap: 16px;
  transform: rotate(-20deg);
}

.btn-ab {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #8b2252;
  border: none;
  color: #ddd;
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  cursor: pointer;
  box-shadow: 0 4px 0 #5a1538, 0 6px 8px rgba(0,0,0,0.3);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.btn-ab:active {
  box-shadow: 0 2px 0 #5a1538;
  transform: translateY(2px);
}

.btn-a { background: #8b2252; }
.btn-b { background: #8b2252; }

.controls-row-bottom {
  display: flex;
  justify-content: center;
  gap: 24px;
}

.btn-small {
  padding: 8px 20px;
  border-radius: 20px;
  background: #3a3a40;
  border: none;
  color: #888;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  cursor: pointer;
  box-shadow: 0 2px 0 #222;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.btn-small:active {
  box-shadow: none;
  transform: translateY(2px);
}

.btn-debug {
  background: #2a3a20 !important;
  color: #44ff44 !important;
  font-size: 6px !important;
  padding: 6px 12px !important;
}

#game-footer {
  position: relative;
  z-index: 1;
  margin-top: 20px;
  margin-bottom: 20px;
  text-align: center;
  font-size: 7px;
  color: #555;
  line-height: 2;
}

#game-footer a {
  color: #777;
  text-decoration: none;
  border-bottom: 1px solid #555;
  transition: color 0.2s;
}

#game-footer a:hover {
  color: #c8a84e;
  border-color: #c8a84e;
}

/* Responsive */
@media (max-width: 700px) {
  #canvas {
    width: 480px;
    height: 432px;
  }
  #controls { display: block; }
}

@media (max-width: 520px) {
  #canvas {
    width: 320px;
    height: 288px;
  }
  #gameboy-shell {
    border-radius: 12px 12px 40px 12px;
    padding: 12px 16px 20px 16px;
  }
  .screen-bezel { padding: 8px; }
}

@media (max-width: 360px) {
  #canvas {
    width: 288px;
    height: 259px;
  }
}

/* Touch devices */
@media (hover: none) and (pointer: coarse) {
  #controls { display: block; }
}