* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  background: #1a1a1e;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 100vh;
  font-family: 'Press Start 2P', monospace;
  overflow-x: hidden;
  padding-top: 10px;
}

#gameboy-shell {
  background: linear-gradient(145deg, #c8c4bf, #b0aaa4);
  border-radius: 18px 18px 18px 60px;
  padding: 14px 18px 20px 18px;
  width: 360px;
  box-shadow: 
    0 8px 32px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.3),
    inset 0 -2px 4px rgba(0,0,0,0.1);
  position: relative;
}

#top-label {
  background: linear-gradient(180deg, #2a2a35, #1a1a25);
  border-radius: 4px;
  padding: 6px 10px;
  margin-bottom: 8px;
  text-align: center;
  border: 1px solid #444;
}

#label-title {
  color: #c0c0c8;
  font-size: 14px;
  letter-spacing: 3px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8), 0 0 6px rgba(180,180,200,0.2);
}

#label-subtitle {
  color: #888890;
  font-size: 7px;
  margin-top: 3px;
  font-style: italic;
  letter-spacing: 1px;
}

#screen-bezel {
  background: #2d2d3a;
  border-radius: 8px;
  padding: 12px 14px 8px 14px;
  margin: 0 auto;
  position: relative;
  border: 2px solid #222;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.6);
}

#power-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}

#power-indicator .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ff2244;
  box-shadow: 0 0 6px #ff2244;
  animation: pulse-power 2s ease-in-out infinite;
}

@keyframes pulse-power {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.power-text {
  font-size: 5px;
  color: #666;
  letter-spacing: 2px;
}

#canvas {
  display: block;
  width: 320px;
  height: 288px;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  background: #0f380f;
  border-radius: 3px;
}

#controls-deco {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-top: 16px;
  padding: 0 10px;
}

#dpad {
  display: grid;
  grid-template-columns: 28px 28px 28px;
  grid-template-rows: 28px 28px 28px;
  gap: 0;
  position: relative;
}

.dpad-up, .dpad-down, .dpad-left, .dpad-right, .dpad-center {
  background: #2a2a32;
  border-radius: 2px;
}

.dpad-up { grid-column: 2; grid-row: 1; border-radius: 4px 4px 0 0; }
.dpad-left { grid-column: 1; grid-row: 2; border-radius: 4px 0 0 4px; }
.dpad-center { grid-column: 2; grid-row: 2; }
.dpad-right { grid-column: 3; grid-row: 2; border-radius: 0 4px 4px 0; }
.dpad-down { grid-column: 2; grid-row: 3; border-radius: 0 0 4px 4px; }

#ab-buttons {
  display: flex;
  gap: 10px;
  transform: rotate(-25deg);
  margin-top: 10px;
}

.btn-a, .btn-b {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(145deg, #8b1a4a, #6b1238);
  color: #c0c0c0;
  font-size: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.4);
  font-family: 'Press Start 2P', monospace;
}

#start-select {
  display: flex;
  gap: 14px;
  position: absolute;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
}

.btn-start, .btn-select {
  width: 40px;
  height: 10px;
  background: #555;
  border-radius: 8px;
  position: relative;
}

.btn-start::after, .btn-select::after {
  content: attr(class);
  position: absolute;
  bottom: -14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 5px;
  color: #555;
  text-transform: uppercase;
  white-space: nowrap;
}

.btn-start::after { content: 'START'; }
.btn-select::after { content: 'SELECT'; }

#speaker-grille {
  display: flex;
  flex-direction: column;
  gap: 3px;
  position: absolute;
  bottom: 18px;
  right: 22px;
  transform: rotate(-25deg);
}

.grille-line {
  width: 28px;
  height: 2px;
  background: #999;
  border-radius: 1px;
}

/* Touch controls */
#touch-controls {
  display: none;
  width: 100%;
  max-width: 400px;
  padding: 12px 16px;
  justify-content: space-between;
  align-items: flex-start;
}

#touch-left {
  flex: 0 0 auto;
}

.touch-dpad {
  display: grid;
  grid-template-columns: 52px 52px 52px;
  grid-template-rows: 52px 52px 52px;
  gap: 2px;
}

.touch-dpad button {
  background: rgba(60, 60, 70, 0.9);
  border: 1px solid rgba(100,100,110,0.5);
  color: #aaa;
  font-size: 18px;
  border-radius: 6px;
  font-family: sans-serif;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.touch-dpad button:active {
  background: rgba(100,100,120,0.9);
}

.t-up { grid-column: 2; grid-row: 1; }
.t-left { grid-column: 1; grid-row: 2; }
.t-down { grid-column: 2; grid-row: 3; }
.t-right { grid-column: 3; grid-row: 2; }

#touch-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.t-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid rgba(100,100,110,0.5);
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  color: #ccc;
  cursor: pointer;
}

.t-a { background: rgba(139, 26, 74, 0.8); }
.t-b { background: rgba(80, 40, 100, 0.8); }
.t-btn:active { opacity: 0.7; }

.touch-meta {
  display: flex;
  gap: 8px;
}

.t-small {
  padding: 8px 14px;
  background: rgba(60, 60, 70, 0.9);
  border: 1px solid rgba(100,100,110,0.5);
  color: #aaa;
  font-size: 7px;
  font-family: 'Press Start 2P', monospace;
  border-radius: 12px;
  cursor: pointer;
}

.t-small:active { background: rgba(100,100,120,0.9); }

footer {
  margin-top: 16px;
  padding: 10px;
}

footer a {
  color: #555;
  font-size: 10px;
  text-decoration: none;
  font-family: 'Press Start 2P', monospace;
}

footer a:hover {
  color: #888;
}

@media (max-width: 420px) {
  #gameboy-shell {
    width: 100vw;
    border-radius: 0;
    padding: 8px 10px 14px 10px;
  }
  #canvas {
    width: calc(100vw - 60px);
    height: auto;
    aspect-ratio: 160/144;
  }
  #controls-deco {
    display: none;
  }
  #speaker-grille {
    display: none;
  }
  #touch-controls {
    display: flex;
  }
  #start-select {
    display: none;
  }
}

@media (min-width: 421px) and (max-width: 768px) {
  #touch-controls {
    display: flex;
  }
}