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

:root {
  --shell-color: #8B8986;
  --shell-light: #A8A5A0;
  --shell-dark: #6B6865;
  --bg-color: #0D0D1A;
  --bg-gradient: linear-gradient(135deg, #0D0D1A 0%, #16213E 50%, #1A1A2E 100%);
  --berry: #E63946;
  --berry-glow: #ff4d5e;
  --screen-green: #9BBC0F;
  --btn-maroon: #A30000;
  --btn-maroon-press: #7a0000;
  --btn-dark: #3D3D3D;
  --btn-dark-press: #2a2a2a;
  --text-light: #E0DDD8;
  --text-dim: #888;
}

body {
  background: var(--bg-gradient);
  min-height: 100vh;
  font-family: 'Press Start 2P', monospace;
  color: var(--text-light);
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

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

#header {
  text-align: center;
  margin: 20px 0 10px;
}

.title {
  font-size: 28px;
  color: var(--berry);
  text-shadow: 0 0 20px rgba(230, 57, 70, 0.6), 0 0 40px rgba(230, 57, 70, 0.3);
  letter-spacing: 2px;
  animation: glow 2s ease-in-out infinite alternate;
}

@keyframes glow {
  from { text-shadow: 0 0 15px rgba(230, 57, 70, 0.5), 0 0 30px rgba(230, 57, 70, 0.2); }
  to { text-shadow: 0 0 25px rgba(230, 57, 70, 0.8), 0 0 50px rgba(230, 57, 70, 0.4); }
}

.subtitle {
  font-size: 8px;
  color: var(--text-dim);
  margin-top: 8px;
  letter-spacing: 1px;
}

.badge {
  font-size: 6px;
  color: var(--screen-green);
  margin-top: 6px;
  padding: 3px 8px;
  border: 1px solid var(--screen-green);
  border-radius: 3px;
  display: inline-block;
  opacity: 0.8;
}

#gameboy-shell {
  background: linear-gradient(180deg, var(--shell-light) 0%, var(--shell-color) 15%, var(--shell-dark) 100%);
  border-radius: 20px 20px 20px 80px;
  padding: 20px 25px 30px;
  margin: 10px 0;
  width: 100%;
  max-width: 500px;
  box-shadow: 
    0 8px 32px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.2),
    inset 0 -2px 4px rgba(0,0,0,0.2);
  position: relative;
}

.screen-label {
  font-size: 5px;
  text-align: center;
  color: #555;
  letter-spacing: 3px;
  margin-bottom: 4px;
  text-transform: uppercase;
}

#screen-bezel {
  background: #2C2C3A;
  border-radius: 10px;
  padding: 15px 20px 15px 20px;
  position: relative;
  box-shadow: 
    inset 0 3px 8px rgba(0,0,0,0.6),
    inset 0 -1px 2px rgba(255,255,255,0.05);
}

#power-led {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #333;
  position: absolute;
  top: 8px;
  right: 15px;
  box-shadow: none;
  transition: all 0.3s;
}

#power-led.on {
  background: #ff2020;
  box-shadow: 0 0 6px #ff2020, 0 0 12px rgba(255, 32, 32, 0.4);
}

#canvas {
  display: block;
  width: 100%;
  max-width: 480px;
  height: auto;
  aspect-ratio: 160 / 144;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #9BBC0F;
  border-radius: 2px;
  margin: 0 auto;
}

#drop-overlay {
  position: absolute;
  top: 15px;
  left: 20px;
  right: 20px;
  bottom: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 2px;
  z-index: 5;
  transition: background 0.2s;
}

#drop-overlay:hover {
  background: rgba(155, 188, 15, 0.08);
}

#drop-overlay.drag-over {
  background: rgba(230, 57, 70, 0.15);
  border: 2px dashed var(--berry);
}

#drop-overlay.hidden {
  display: none;
}

.drop-text {
  font-size: 8px;
  color: #306230;
  text-align: center;
  line-height: 2;
  animation: bounce-text 2s ease-in-out infinite;
  pointer-events: none;
}

@keyframes bounce-text {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

#rom-info {
  font-size: 6px;
  color: var(--text-dim);
  text-align: center;
  margin-top: 8px;
  min-height: 12px;
}

#virtual-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 20px 10px 5px;
  padding: 0 10px;
}

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

.dpad-btn {
  background: var(--btn-dark);
  border: none;
  color: #777;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Press Start 2P', monospace;
  transition: all 0.05s;
  -webkit-user-select: none;
  user-select: none;
}

.dpad-up { border-radius: 4px 4px 0 0; }
.dpad-down { border-radius: 0 0 4px 4px; }
.dpad-left { border-radius: 4px 0 0 4px; }
.dpad-right { border-radius: 0 4px 4px 0; }
.dpad-center { background: #333; cursor: default; }

.dpad-btn:active, .dpad-btn.pressed {
  background: var(--btn-dark-press);
  transform: scale(0.92);
  color: #aaa;
}

#ab-buttons {
  display: flex;
  gap: 12px;
  transform: rotate(-15deg);
}

.ab-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--btn-maroon);
  border: none;
  color: #ddd;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  cursor: pointer;
  box-shadow: 0 3px 0 #700, 0 4px 8px rgba(0,0,0,0.3);
  transition: all 0.05s;
  -webkit-user-select: none;
  user-select: none;
}

.ab-btn:active, .ab-btn.pressed {
  background: var(--btn-maroon-press);
  box-shadow: 0 1px 0 #500, 0 2px 4px rgba(0,0,0,0.3);
  transform: translateY(2px);
}

#btn-b { margin-top: 15px; }

#ss-buttons {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin: 10px 0;
  transform: rotate(-5deg);
}

.ss-btn {
  padding: 6px 14px;
  border-radius: 10px;
  background: var(--btn-dark);
  border: none;
  color: #777;
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  cursor: pointer;
  box-shadow: 0 2px 0 #222;
  transition: all 0.05s;
  -webkit-user-select: none;
  user-select: none;
}

.ss-btn:active, .ss-btn.pressed {
  background: var(--btn-dark-press);
  box-shadow: 0 0 0 #222;
  transform: translateY(2px);
}

#toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: center;
  margin: 10px 0;
  max-width: 500px;
}

.tool-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 6px 10px;
  border: 1px solid #444;
  background: #222;
  color: var(--text-light);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.tool-btn:hover:not(:disabled) {
  background: #333;
  border-color: var(--berry);
}

.tool-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tool-select {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 5px 6px;
  border: 1px solid #444;
  background: #222;
  color: var(--text-light);
  border-radius: 4px;
  cursor: pointer;
}

.volume-slider {
  width: 60px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: #333;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  vertical-align: middle;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--screen-green);
  cursor: pointer;
  border: 1px solid #222;
}

.volume-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--screen-green);
  cursor: pointer;
  border: 1px solid #222;
}

#fps-counter {
  font-size: 7px;
  color: var(--screen-green);
  min-width: 50px;
  text-align: right;
}

#apu-state {
  margin-bottom: 6px;
  font-family: 'Press Start 2P', monospace;
}

#apu-state .ch-bar {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin: 0 1px;
  vertical-align: middle;
}

#apu-state .ch-on { background: #0f0; box-shadow: 0 0 4px #0f0; }
#apu-state .ch-off { background: #333; }

#keyboard-help, #debug-section {
  max-width: 500px;
  width: 100%;
  text-align: center;
  margin: 4px 0;
}

#key-map {
  font-size: 6px;
  color: var(--text-dim);
  line-height: 2.2;
  margin-top: 6px;
  padding: 8px;
  background: rgba(0,0,0,0.3);
  border-radius: 6px;
}

#debug-panel {
  font-size: 6px;
  color: var(--screen-green);
  margin-top: 6px;
  padding: 10px;
  background: rgba(0,0,0,0.4);
  border-radius: 6px;
  text-align: left;
  line-height: 2;
}

#cpu-regs, #ppu-state {
  margin-bottom: 6px;
  font-family: 'Press Start 2P', monospace;
}

#debug-controls {
  margin: 6px 0;
  display: flex;
  gap: 6px;
}

/* Memory Corruption Section */
#corruption-section {
  margin: 10px 0;
  padding: 10px;
  border: 1px solid #E63946;
  border-radius: 6px;
  background: rgba(230, 57, 70, 0.08);
}

.corruption-header {
  font-size: 7px;
  color: #E63946;
  text-align: center;
  margin-bottom: 8px;
  letter-spacing: 2px;
  text-shadow: 0 0 8px rgba(230, 57, 70, 0.5);
}

.corruption-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.corruption-label {
  font-size: 6px;
  color: #ccc;
  display: flex;
  align-items: center;
  gap: 6px;
}

.corruption-slider {
  width: 120px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(90deg, #333, #E63946);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  vertical-align: middle;
}

.corruption-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #E63946;
  cursor: pointer;
  border: 1px solid #222;
  box-shadow: 0 0 6px rgba(230, 57, 70, 0.6);
}

.corruption-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #E63946;
  cursor: pointer;
  border: 1px solid #222;
  box-shadow: 0 0 6px rgba(230, 57, 70, 0.6);
}

#corruption-value {
  color: #E63946;
  min-width: 28px;
  text-align: right;
  font-size: 7px;
}

.corruption-targets {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.corruption-target-label {
  font-size: 6px;
  color: #aaa;
  display: flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}

.corruption-target-label input[type="checkbox"] {
  accent-color: #E63946;
  width: 10px;
  height: 10px;
  cursor: pointer;
}

.corrupt-btn {
  background: linear-gradient(180deg, #8B0000, #5a0000) !important;
  border-color: #E63946 !important;
  color: #ff6b6b !important;
  font-size: 8px !important;
  padding: 8px 20px !important;
  letter-spacing: 1px;
  text-shadow: 0 0 6px rgba(230, 57, 70, 0.6);
  transition: all 0.15s !important;
}

.corrupt-btn:hover:not(:disabled) {
  background: linear-gradient(180deg, #a00000, #700000) !important;
  box-shadow: 0 0 15px rgba(230, 57, 70, 0.4);
  transform: scale(1.05);
}

.corrupt-btn:active {
  transform: scale(0.95) !important;
}

.corrupt-btn.corrupting {
  animation: corruptPulse 0.3s ease-out;
}

@keyframes corruptPulse {
  0% { box-shadow: 0 0 0px rgba(230, 57, 70, 0); }
  50% { box-shadow: 0 0 25px rgba(230, 57, 70, 0.8); background: linear-gradient(180deg, #c00, #800) !important; }
  100% { box-shadow: 0 0 0px rgba(230, 57, 70, 0); }
}

#corruption-status {
  font-size: 6px;
  color: #E63946;
  text-align: center;
  margin-top: 4px;
  min-height: 10px;
  opacity: 0.8;
}

#tile-viewer {
  image-rendering: pixelated;
  width: 256px;
  height: 384px;
  background: #0F380F;
  margin-top: 6px;
  border: 1px solid #444;
}

.hidden {
  display: none !important;
}

#status-bar {
  font-size: 6px;
  display: flex;
  justify-content: space-between;
  padding: 6px 15px;
  max-width: 500px;
  width: 100%;
  color: var(--text-dim);
}

#footer {
  text-align: center;
  margin: 30px 0 20px;
  font-size: 6px;
  color: var(--text-dim);
  line-height: 2.5;
}

#footer a {
  color: var(--berry);
  text-decoration: none;
}

#footer a:hover {
  text-decoration: underline;
}

.disclaimer {
  opacity: 0.6;
}

@media (max-width: 520px) {
  #gameboy-shell {
    border-radius: 12px 12px 12px 40px;
    padding: 12px 12px 20px;
  }
  
  .title { font-size: 20px; }
  
  .dpad-btn {
    width: 40px;
    height: 40px;
  }
  
  #dpad {
    grid-template-columns: 40px 40px 40px;
    grid-template-rows: 40px 40px 40px;
  }
  
  .ab-btn {
    width: 55px;
    height: 55px;
  }
  
  #toolbar {
    gap: 4px;
  }
  
  .tool-btn, .tool-select {
    font-size: 6px;
    padding: 5px 7px;
  }
}