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

body {
  background: #0d0d0d;
  font-family: 'Press Start 2P', monospace;
  color: #c0c0c0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

#app {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 10px;
}

#console-wrapper {
  background: #1a1a1a;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.8), inset 0 1px 0 rgba(255,255,255,0.05);
  border: 2px solid #2a2a2a;
}

#console-top {
  margin-bottom: 10px;
}

#cartridge-slot {
  background: #111;
  border: 3px solid #333;
  border-radius: 8px 8px 0 0;
  padding: 15px;
  text-align: center;
  position: relative;
  transition: all 0.3s;
}

#cartridge-slot.drag-over {
  border-color: #ff6600;
  background: #1a1000;
  box-shadow: 0 0 20px rgba(255,102,0,0.3);
}

#cart-drop-zone {
  cursor: pointer;
  padding: 10px;
  position: relative;
}

#cart-label {
  font-size: 10px;
  color: #ff6600;
  letter-spacing: 2px;
  padding: 8px 20px;
  background: linear-gradient(180deg, #cc3300, #ff6600, #ffcc00, #33cc33, #3366ff, #9933cc);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: rainbow-shift 3s linear infinite;
}

@keyframes rainbow-shift {
  0%, 100% { filter: hue-rotate(0deg); }
  50% { filter: hue-rotate(30deg); }
}

#cart-name {
  font-size: 7px;
  color: #aaa;
  margin-top: 5px;
  word-break: break-all;
}

#rom-input {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  opacity: 0;
  cursor: pointer;
}

#screen-bezel {
  background: #111;
  border: 4px solid #222;
  border-radius: 12px;
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 10px;
}

#crt-container {
  position: relative;
  width: 640px;
  height: 480px;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 0 30px rgba(100,255,100,0.05), 0 0 60px rgba(0,0,0,0.5);
}

#screen {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  display: block;
}

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

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

#screen-message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 8px;
  color: #ff6600;
  text-align: center;
  z-index: 4;
  pointer-events: none;
  text-shadow: 0 0 10px rgba(255,102,0,0.5);
  line-height: 1.8;
  display: none;
}

#woodgrain-strip {
  background: linear-gradient(180deg, 
    #8B6914 0%, #a07828 15%, #7a5a10 30%, 
    #9b7020 45%, #6d4e0c 55%, #8B6914 70%,
    #a07828 85%, #7a5a10 100%
  );
  background-size: 100% 8px;
  padding: 12px 20px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  position: relative;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.3);
}

#woodgrain-strip::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    90deg,
    transparent 0px, transparent 3px,
    rgba(0,0,0,0.05) 3px, rgba(0,0,0,0.05) 4px
  );
  border-radius: 4px;
}

#atari-logo {
  font-size: 14px;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
  letter-spacing: 6px;
  flex-shrink: 0;
  margin-right: 20px;
  z-index: 1;
}

#switch-panel {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  z-index: 1;
}

.switch-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.switch-group label {
  font-size: 5px;
  color: #fff;
  letter-spacing: 1px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.toggle-switch {
  width: 32px;
  height: 18px;
  background: #444;
  border-radius: 3px;
  cursor: pointer;
  position: relative;
  border: 1px solid #555;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.5);
}

.toggle-switch.active {
  background: #666;
}

.toggle-knob {
  width: 12px;
  height: 14px;
  background: linear-gradient(180deg, #ddd, #999);
  border-radius: 2px;
  position: absolute;
  top: 1px;
  left: 2px;
  transition: left 0.15s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.toggle-switch.active .toggle-knob {
  left: 16px;
}

.console-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 5px;
  padding: 4px 8px;
  background: linear-gradient(180deg, #888, #555);
  color: #fff;
  border: 1px solid #666;
  border-radius: 2px;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.console-btn:active {
  transform: translateY(1px);
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

#controls-area {
  display: none;
  justify-content: space-between;
  align-items: center;
  padding: 15px 30px;
  margin-bottom: 10px;
}

#dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.dpad-row {
  display: flex;
  gap: 2px;
  align-items: center;
}

.dpad-btn {
  width: 48px;
  height: 48px;
  background: #333;
  border: 2px solid #444;
  border-radius: 6px;
  color: #aaa;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.dpad-btn:active, .dpad-btn.pressed {
  background: #555;
  border-color: #ff6600;
  color: #ff6600;
}

.dpad-center {
  width: 48px;
  height: 48px;
  background: #222;
  border-radius: 50%;
}

#fire-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: radial-gradient(circle, #cc3300, #991100);
  border: 3px solid #ff4400;
  color: #fff;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(204,51,0,0.4);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#fire-btn:active, #fire-btn.pressed {
  transform: scale(0.95);
  box-shadow: 0 2px 8px rgba(204,51,0,0.6);
}

#toolbar {
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 10px;
  flex-wrap: wrap;
}

#toolbar button {
  background: #222;
  border: 1px solid #444;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s;
  color: #ccc;
}

#toolbar button:hover {
  background: #333;
  border-color: #ff6600;
}

#toolbar button.active {
  background: #442200;
  border-color: #ff6600;
}

#debug-panel {
  background: #0a0a0a;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 12px;
  margin-top: 8px;
  font-size: 7px;
  line-height: 1.8;
}

#debug-panel.hidden {
  display: none;
}

.debug-section {
  margin-bottom: 8px;
}

.debug-section h3 {
  color: #ff6600;
  font-size: 7px;
  margin-bottom: 3px;
}

.debug-section div {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  color: #8f8;
  font-size: 7px;
  word-break: break-all;
}

.debug-controls {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.debug-controls button {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  padding: 4px 10px;
  background: #222;
  border: 1px solid #444;
  color: #8f8;
  border-radius: 4px;
  cursor: pointer;
}

.debug-controls button:hover {
  border-color: #8f8;
}

#help-panel {
  background: #0a0a0a;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 12px;
  margin-top: 8px;
}

#help-panel.hidden {
  display: none;
}

#help-panel h3 {
  color: #ff6600;
  font-size: 8px;
  margin-bottom: 8px;
}

.help-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 20px;
  font-size: 7px;
}

.help-grid span:nth-child(odd) {
  color: #aaa;
}

.help-grid span:nth-child(even) {
  color: #8f8;
}

footer {
  text-align: center;
  padding: 15px;
  margin-top: 10px;
}

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

footer a:hover {
  color: #ff6600;
}

@media (max-width: 700px) {
  #app {
    padding: 5px;
  }
  #console-wrapper {
    padding: 8px;
    border-radius: 10px;
  }
  #screen-bezel {
    padding: 8px;
  }
  #crt-container {
    width: 320px;
    height: 240px;
    border-radius: 10px;
  }
  #controls-area {
    display: flex;
  }
  #switch-panel {
    gap: 6px;
  }
  .switch-group label {
    font-size: 4px;
  }
  #atari-logo {
    font-size: 10px;
    letter-spacing: 3px;
    margin-right: 8px;
  }
  #woodgrain-strip {
    padding: 8px 10px;
  }
}

@media (min-width: 701px) {
  #controls-area {
    display: none;
  }
}