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

:root {
  --shell-bg: #7B6BA5;
  --shell-dark: #5C4D80;
  --shell-light: #9B8BC5;
  --bezel-bg: #3A3550;
  --screen-off: #8B9B5A;
  --btn-ab: #8B2252;
  --btn-ab-shadow: #5C1639;
  --dpad-color: #2D2B3A;
  --dpad-shadow: #1A1825;
  --meta-color: #5C5478;
  --led-off: #555;
  --led-on: #2ECC40;
}

html, body {
  height: 100%;
  background: linear-gradient(145deg, #1a1520 0%, #0d0a12 50%, #151020 100%);
  font-family: 'IBM Plex Sans', sans-serif;
  color: #e0d8f0;
  overflow-x: hidden;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 10px;
}

#app-header {
  text-align: center;
  padding: 12px 0 8px;
}

#app-header h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: 18px;
  color: #d4c8f0;
  text-shadow: 0 0 20px rgba(150, 100, 255, 0.4);
}

.tagline {
  font-size: 12px;
  color: #8878a8;
  margin-top: 4px;
  font-style: italic;
}

#gameboy-shell {
  position: relative;
  width: 380px;
  background: linear-gradient(170deg, var(--shell-light) 0%, var(--shell-bg) 30%, var(--shell-dark) 100%);
  border-radius: 20px 20px 80px 20px;
  padding: 16px 20px 30px;
  box-shadow:
    0 8px 30px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.2),
    inset 0 -2px 0 rgba(0,0,0,0.2),
    0 0 60px rgba(100, 70, 160, 0.15);
  margin: 0 auto;
  user-select: none;
}

#top-strip {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 6px;
}

#power-area {
  display: flex;
  align-items: center;
  gap: 6px;
}

.power-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  color: rgba(255,255,255,0.4);
  letter-spacing: 1px;
}

.power-switch {
  position: relative;
  width: 40px;
  height: 18px;
  cursor: pointer;
}

.power-switch input { display: none; }

.power-switch .slider {
  position: absolute;
  inset: 0;
  background: #3a3550;
  border-radius: 9px;
  transition: 0.3s;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.4);
}

.power-switch .slider::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  left: 2px;
  bottom: 2px;
  background: #888;
  border-radius: 50%;
  transition: 0.3s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.power-switch input:checked + .slider {
  background: #4a6b40;
}

.power-switch input:checked + .slider::before {
  transform: translateX(22px);
  background: #8f8;
}

#brand-label {
  text-align: center;
  margin: 4px 0 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

#power-led {
  font-size: 12px;
  filter: grayscale(1) brightness(0.5);
  transition: 0.3s;
}

#power-led.on {
  filter: grayscale(0) brightness(1);
  animation: led-glow 2s ease-in-out infinite;
}

@keyframes led-glow {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.3); }
}

.brand-text {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  color: #2D2B3A;
  text-shadow: 0 1px 0 rgba(255,255,255,0.15);
  letter-spacing: 2px;
}

.color-text {
  color: #c44;
  font-style: italic;
}

#screen-bezel {
  background: var(--bezel-bg);
  border-radius: 12px;
  padding: 12px 14px 14px;
  box-shadow:
    inset 0 3px 8px rgba(0,0,0,0.5),
    inset 0 -1px 0 rgba(255,255,255,0.05);
  margin-bottom: 16px;
}

.dot-matrix-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 5px;
  color: rgba(255,255,255,0.25);
  text-align: center;
  margin-bottom: 6px;
  letter-spacing: 2px;
}

#screen-container {
  position: relative;
  width: 320px;
  height: 288px;
  margin: 0 auto;
  background: var(--screen-off);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.4);
}

#canvas {
  width: 320px;
  height: 288px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

#screen-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(120, 140, 80, 0.95);
  cursor: pointer;
  z-index: 2;
}

#screen-overlay.active {
  display: flex;
}

.drop-prompt {
  text-align: center;
}

.prompt-icon {
  font-size: 40px;
  animation: pulse-icon 2s ease-in-out infinite;
}

@keyframes pulse-icon {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.1); opacity: 1; }
}

.prompt-text {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: #2D2B3A;
  line-height: 1.8;
  margin-top: 10px;
}

#scanline-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  display: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(0,0,0,0.08) 1px,
    rgba(0,0,0,0.08) 2px
  );
}

#scanline-overlay.active {
  display: block;
}

#controls-area {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  margin-bottom: 4px;
}

#dpad-container {
  width: 110px;
  height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.dpad-btn {
  background: var(--dpad-color);
  border: none;
  color: rgba(255,255,255,0.3);
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: 0.1s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.dpad-btn:active, .dpad-btn.pressed {
  transform: scale(0.92);
  box-shadow: 0 0px 2px rgba(0,0,0,0.3);
  background: var(--dpad-shadow);
}

.dpad-up { grid-column: 2; grid-row: 1; border-radius: 6px 6px 0 0; }
.dpad-down { grid-column: 2; grid-row: 3; border-radius: 0 0 6px 6px; }
.dpad-left { grid-column: 1; grid-row: 2; border-radius: 6px 0 0 6px; }
.dpad-right { grid-column: 3; grid-row: 2; border-radius: 0 6px 6px 0; }
.dpad-center { grid-column: 2; grid-row: 2; background: var(--dpad-color); }

#ab-container {
  display: flex;
  gap: 12px;
  transform: rotate(-25deg);
  margin-right: 10px;
}

.ab-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--btn-ab), var(--btn-ab-shadow));
  border: none;
  color: rgba(255,255,255,0.6);
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  cursor: pointer;
  box-shadow: 0 3px 6px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.15);
  transition: 0.1s;
}

.ab-btn:active, .ab-btn.pressed {
  transform: scale(0.9);
  box-shadow: 0 1px 3px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.1);
}

#meta-buttons {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 12px;
  transform: rotate(-25deg);
  margin-left: 20px;
}

.meta-btn {
  width: 50px;
  height: 16px;
  border-radius: 8px;
  background: var(--meta-color);
  border: none;
  color: rgba(255,255,255,0.4);
  font-family: 'Press Start 2P', monospace;
  font-size: 5px;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
  transition: 0.1s;
}

.meta-btn:active, .meta-btn.pressed {
  transform: scale(0.92);
  box-shadow: 0 0 2px rgba(0,0,0,0.3);
}

#bottom-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px;
  gap: 8px;
}

#upload-btn, #settings-btn {
  background: rgba(0,0,0,0.2);
  border: 1px solid rgba(255,255,255,0.1);
  color: #c4b8e0;
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-family: 'IBM Plex Sans', sans-serif;
  transition: 0.2s;
}

#upload-btn:hover, #settings-btn:hover {
  background: rgba(0,0,0,0.3);
  border-color: rgba(255,255,255,0.2);
}

#volume-control {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
}

#volume-slider {
  width: 60px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(0,0,0,0.3);
  border-radius: 2px;
  outline: none;
}

#volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #c4b8e0;
  cursor: pointer;
}

#info-strip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: 'Press Start 2P', monospace;
  font-size: 5px;
  color: rgba(255,255,255,0.3);
  padding: 4px 4px 0;
  gap: 4px;
}

#rom-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#fps-counter {
  white-space: nowrap;
}

/* Settings Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
}

.modal.hidden { display: none; }

.modal-content {
  background: #2a2540;
  border: 1px solid rgba(150,120,200,0.2);
  border-radius: 16px;
  width: 360px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.modal-header h2 {
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  color: #d4c8f0;
}

#close-settings {
  background: none;
  border: none;
  color: #888;
  font-size: 18px;
  cursor: pointer;
}

.modal-body {
  padding: 16px 20px;
}

.setting-group {
  margin-bottom: 16px;
}

.setting-group h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: #a898c8;
  margin-bottom: 8px;
}

.key-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 11px;
}

.rebind-btn {
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.1);
  color: #c4b8e0;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 10px;
  cursor: pointer;
  font-family: 'IBM Plex Sans', sans-serif;
  min-width: 70px;
  text-align: center;
}

.rebind-btn.listening {
  border-color: #8f8;
  color: #8f8;
  animation: blink 0.5s infinite;
}

@keyframes blink {
  50% { opacity: 0.5; }
}

.palette-btn, .speed-btn {
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.1);
  color: #c4b8e0;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 10px;
  cursor: pointer;
  margin: 2px;
  font-family: 'IBM Plex Sans', sans-serif;
}

.palette-btn.active, .speed-btn.active {
  background: rgba(100, 70, 160, 0.4);
  border-color: rgba(150, 120, 200, 0.5);
  color: #fff;
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}

.save-state-btns {
  display: flex;
  gap: 8px;
}

.save-state-btns button, #screenshot-btn {
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.1);
  color: #c4b8e0;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  font-family: 'IBM Plex Sans', sans-serif;
}

#app-footer {
  text-align: center;
  padding: 16px;
  font-size: 11px;
  color: #5a4e78;
}

#app-footer a {
  color: #8878a8;
  text-decoration: none;
  margin-left: 12px;
}

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

/* Drag over effect */
#screen-container.drag-over {
  outline: 3px dashed rgba(100,255,100,0.5);
}

/* Responsive */
@media (max-width: 420px) {
  #gameboy-shell {
    width: 100%;
    max-width: 380px;
    border-radius: 16px 16px 60px 16px;
    padding: 12px 14px 24px;
  }
  
  #screen-container {
    width: 280px;
    height: 252px;
  }
  
  #canvas {
    width: 280px;
    height: 252px;
  }
  
  #dpad-container {
    width: 95px;
    height: 95px;
  }
  
  #dpad {
    grid-template-columns: 30px 30px 30px;
    grid-template-rows: 30px 30px 30px;
  }
  
  .ab-btn {
    width: 40px;
    height: 40px;
    font-size: 9px;
  }
  
  .modal-content {
    width: 95vw;
  }
}