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

html, body {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  background: #0a0a1a;
  font-family: 'Press Start 2P', monospace;
}

#app-container {
  width: 100%;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 10px;
  background: radial-gradient(ellipse at center, #1a1a2e 0%, #0a0a1a 70%);
}

#tv-frame {
  position: relative;
  flex-shrink: 0;
}

#tv-bezel {
  background: linear-gradient(145deg, #3a3a4a, #252535, #1e1e2e);
  border-radius: 16px;
  padding: 16px 20px 36px 20px;
  box-shadow:
    0 0 0 3px #111,
    0 8px 32px rgba(0,0,0,0.8),
    inset 0 1px 0 rgba(255,255,255,0.05);
  position: relative;
}

#screen-container {
  position: relative;
  overflow: hidden;
  border-radius: 6px;
  background: #000;
  box-shadow: inset 0 0 30px rgba(0,0,0,0.9);
}

#canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  width: 512px;
  height: 480px;
}

#scanline-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(0, 0, 0, 0.12) 1px,
    rgba(0, 0, 0, 0.12) 2px
  );
  z-index: 2;
}

#crt-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.4) 100%);
  z-index: 3;
}

#bezel-label {
  color: #555;
  font-size: 6px;
  text-align: center;
  margin-top: 8px;
  letter-spacing: 3px;
}

#bezel-led {
  position: absolute;
  bottom: 12px;
  right: 28px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #333;
  box-shadow: none;
  transition: none;
}

#bezel-led.on {
  background: #ff2222;
  box-shadow: 0 0 6px #ff2222, 0 0 12px #ff000066;
  animation: led-pulse 2s ease-in-out infinite;
}

@keyframes led-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

#controls-bar {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.nes-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  background: #c41a1a;
  color: #fff;
  border: 2px solid #8b0e0e;
  padding: 8px 14px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  box-shadow: 0 3px 0 #600808;
  transition: none;
}
.nes-btn:hover { background: #d42a2a; }
.nes-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #600808; }
.nes-btn.small { font-size: 7px; padding: 6px 10px; }
.nes-btn.tiny { font-size: 6px; padding: 4px 8px; background: #2a2a4a; border-color: #3a3a5a; box-shadow: 0 2px 0 #1a1a2a; }
.nes-btn.tiny:hover { background: #3a3a5a; }

#status-bar {
  display: flex;
  gap: 16px;
  margin-top: 6px;
  font-size: 7px;
  color: #888;
  letter-spacing: 1px;
}
#status-bar span { display: inline-block; }
#emu-status { color: #0f0; }
#fps-display { color: #ff0; }
#rom-name { color: #aaa; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#error-display {
  margin-top: 8px;
  font-size: 7px;
  color: #f44;
  background: #1a0000;
  border: 1px solid #f44;
  padding: 8px 12px;
  max-width: 520px;
  text-align: center;
}

#settings-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #111128;
  border: 2px solid #444;
  padding: 16px;
  z-index: 100;
  min-width: 260px;
}
.settings-title {
  font-size: 10px;
  color: #ff0;
  margin-bottom: 12px;
  text-align: center;
}
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 7px;
  color: #ccc;
}

#debug-panel {
  position: fixed;
  top: 10px;
  right: 10px;
  background: rgba(0,0,0,0.92);
  border: 1px solid #333;
  padding: 8px;
  z-index: 90;
  font-size: 7px;
  color: #0f0;
  max-width: 300px;
  max-height: 400px;
  overflow: auto;
}
.debug-title { color: #ff0; margin-bottom: 4px; font-size: 8px; }
#debug-panel pre { margin: 0; white-space: pre-wrap; word-break: break-all; line-height: 1.6; }

#mobile-controls {
  width: 100%;
  max-width: 520px;
  padding: 10px 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

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

.dpad-btn {
  background: #2a2a3a;
  border: 1px solid #3a3a4a;
  color: #888;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.dpad-btn:active { background: #4a4a5a; color: #fff; }
#dpad-up { grid-column: 2; grid-row: 1; border-radius: 6px 6px 0 0; }
#dpad-left { grid-column: 1; grid-row: 2; border-radius: 6px 0 0 6px; }
.dpad-center { grid-column: 2; grid-row: 2; background: #333344; cursor: default; }
#dpad-right { grid-column: 3; grid-row: 2; border-radius: 0 6px 6px 0; }
#dpad-down { grid-column: 2; grid-row: 3; border-radius: 0 0 6px 6px; }

#action-buttons { display: flex; flex-direction: column; align-items: center; gap: 10px; }
#meta-buttons { display: flex; gap: 12px; }
.meta-btn {
  background: #444;
  border: none;
  color: #aaa;
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  padding: 6px 10px;
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.meta-btn:active { background: #666; color: #fff; }
#ab-buttons { display: flex; gap: 16px; }
.action-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #8b1a1a;
  border: 2px solid #6b0e0e;
  color: #ddd;
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  box-shadow: 0 3px 0 #500a0a;
}
.action-btn:active { background: #aa2a2a; transform: translateY(2px); box-shadow: 0 1px 0 #500a0a; }

#footer {
  color: #444;
  font-size: 7px;
  padding: 8px;
  text-align: center;
  letter-spacing: 1px;
  flex-shrink: 0;
  margin-top: auto;
}
#footer a { color: #666; text-decoration: none; margin-left: 12px; }
#footer a:hover { color: #999; }

/* Drag-drop highlight */
#screen-container.drag-over {
  outline: 3px dashed #0f0;
  outline-offset: -3px;
}

@media (max-width: 600px) {
  #canvas { width: 100vw; height: calc(100vw * 240 / 256); }
  #tv-bezel { border-radius: 0; padding: 4px 4px 20px 4px; }
  #bezel-label { font-size: 5px; margin-top: 4px; }
  #bezel-led { bottom: 6px; right: 10px; width: 6px; height: 6px; }
  #mobile-controls { display: flex !important; }
}