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

:root {
  --bg: #0d0d1a;
  --bg-secondary: #151528;
  --amber: #ffb347;
  --amber-dim: #cc8a2e;
  --lcd-bg: #8B9A6B;
  --lcd-dark: #0F380F;
  --lcd-light: #9dad7a;
  --device-brown: #8B7355;
  --device-dark: #5C4A32;
  --device-highlight: #a08a6a;
  --text: #c8c8d0;
  --text-dim: #6a6a80;
  --danger: #e05555;
  --green: #4ec94e;
  --bezel: #2a2a2a;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

#scanlines {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.08) 2px,
    rgba(0,0,0,0.08) 4px
  );
}

header {
  text-align: center;
  padding: 24px 16px 8px;
}

header h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(14px, 3vw, 24px);
  color: var(--amber);
  text-shadow: 0 0 20px rgba(255,179,71,0.4), 0 2px 0 #805a20;
  letter-spacing: 2px;
}

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

#main-container {
  display: flex;
  gap: 24px;
  max-width: 1200px;
  margin: 16px auto;
  padding: 0 16px;
  align-items: flex-start;
}

#device-column {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

#debug-column {
  flex: 1;
  min-width: 280px;
  max-width: 420px;
}

/* ROM Upload Area */
#rom-upload-area {
  width: 380px;
  max-width: 95vw;
}

#drop-zone {
  border: 2px dashed var(--amber-dim);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  background: rgba(255,179,71,0.04);
  transition: all 0.3s;
  cursor: pointer;
}

#drop-zone:hover, #drop-zone.drag-over {
  border-color: var(--amber);
  background: rgba(255,179,71,0.1);
  box-shadow: 0 0 30px rgba(255,179,71,0.15);
}

.cartridge-icon {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: var(--amber-dim);
  line-height: 1.4;
  margin-bottom: 8px;
  opacity: 0.7;
}

.drop-text {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.drop-subtext {
  font-size: 9px;
  color: var(--amber-dim);
  margin-bottom: 12px;
  font-style: italic;
  opacity: 0.7;
}

.retro-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  padding: 10px 20px;
  background: var(--bg-secondary);
  color: var(--amber);
  border: 2px solid var(--amber-dim);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
}

.retro-btn:hover {
  background: rgba(255,179,71,0.15);
  border-color: var(--amber);
  box-shadow: 0 0 15px rgba(255,179,71,0.2);
}

.retro-btn.small {
  font-size: 8px;
  padding: 6px 12px;
}

.retro-btn.danger {
  color: var(--danger);
  border-color: var(--danger);
}

.retro-btn.danger:hover {
  background: rgba(224,85,85,0.15);
}

#rom-info {
  background: var(--bg-secondary);
  border: 1px solid #2a2a3e;
  border-radius: 8px;
  padding: 12px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--amber);
}

#hex-preview {
  font-size: 9px;
  color: var(--text-dim);
  margin-top: 8px;
  word-break: break-all;
  line-height: 1.6;
  max-height: 40px;
  overflow: hidden;
}

.rom-buttons {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

/* Device Body */
#device-body {
  width: 380px;
  max-width: 95vw;
  background: linear-gradient(145deg, var(--device-highlight), var(--device-brown), var(--device-dark));
  border-radius: 24px;
  padding: 20px;
  box-shadow:
    0 8px 32px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.1),
    inset 0 -2px 0 rgba(0,0,0,0.3);
  position: relative;
}

#device-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: rgba(255,255,255,0.3);
  text-align: center;
  letter-spacing: 4px;
  margin-bottom: 6px;
}

#hw-info-strip {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.hw-tag {
  font-family: 'Press Start 2P', monospace;
  font-size: 5px;
  color: #ff6b35;
  background: rgba(255, 107, 53, 0.12);
  border: 1px solid rgba(255, 107, 53, 0.3);
  border-radius: 3px;
  padding: 3px 6px;
  letter-spacing: 1px;
  text-transform: uppercase;
  animation: tagPulse 3s ease-in-out infinite;
}

.hw-tag:nth-child(2) { animation-delay: 1s; }
.hw-tag:nth-child(3) { animation-delay: 2s; }

@keyframes tagPulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; border-color: rgba(255, 107, 53, 0.6); }
}

#lcd-bezel {
  background: var(--bezel);
  border-radius: 12px;
  padding: 12px;
  box-shadow:
    inset 0 3px 8px rgba(0,0,0,0.8),
    0 1px 0 rgba(255,255,255,0.05);
  position: relative;
  margin: 0 auto;
  width: fit-content;
}

#lcd-canvas {
  display: block;
  border-radius: 4px;
  image-rendering: pixelated;
}

#lcd-overlay {
  position: absolute;
  top: 12px; left: 12px;
  right: 12px; bottom: 12px;
  border-radius: 4px;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.15) 100%);
}

/* Controls Area */
#controls-area {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 20px;
  padding: 0 8px;
}

#paddle-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

#paddle-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  color: rgba(255,255,255,0.3);
  letter-spacing: 2px;
}

#paddle-track {
  width: 180px;
  height: 24px;
  background: #3a3020;
  border-radius: 12px;
  position: relative;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
  cursor: pointer;
}

#paddle-knob {
  width: 32px;
  height: 32px;
  background: radial-gradient(circle at 40% 35%, #e0d0b0, #8a7a5a);
  border-radius: 50%;
  position: absolute;
  top: -4px;
  left: calc(50% - 16px);
  box-shadow: 0 2px 6px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.3);
  cursor: grab;
  transition: left 0.05s;
}

#paddle-knob:active {
  cursor: grabbing;
}

#paddle-value {
  font-size: 10px;
  color: rgba(255,255,255,0.4);
  font-family: 'JetBrains Mono', monospace;
}

#action-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #d04040, #801818);
  border: 3px solid #601010;
  box-shadow: 0 4px 0 #400808, 0 6px 12px rgba(0,0,0,0.4);
  cursor: pointer;
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  color: rgba(255,255,255,0.6);
  transition: all 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}

#action-btn:active, #action-btn.pressed {
  box-shadow: 0 1px 0 #400808, 0 2px 4px rgba(0,0,0,0.4);
  transform: translateY(3px);
}

#controls-hint {
  font-size: 8px;
  color: rgba(255,255,255,0.2);
  text-align: center;
  margin-top: 12px;
  font-family: 'JetBrains Mono', monospace;
}

#arch-note {
  font-size: 7px;
  color: rgba(255, 179, 71, 0.35);
  text-align: center;
  margin-top: 8px;
  font-family: 'JetBrains Mono', monospace;
  line-height: 1.4;
  padding: 0 12px;
}

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

.overlay-toggle-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  color: rgba(255,255,255,0.35);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.overlay-toggle-label input {
  accent-color: var(--amber);
}

#overlay-select {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  background: rgba(0,0,0,0.4);
  color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 4px;
  padding: 3px 6px;
  cursor: pointer;
}

#overlay-select:focus {
  border-color: var(--amber-dim);
  outline: none;
}

#plastic-overlay {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  bottom: 12px;
  border-radius: 4px;
  pointer-events: none;
  z-index: 2;
  transition: opacity 0.3s;
}

#plastic-overlay.overlay-hidden {
  opacity: 0;
}

#plastic-overlay canvas {
  width: 100%;
  height: 100%;
  border-radius: 4px;
}

/* Debug Panel */
#debug-toggle {
  width: 100%;
  text-align: left;
  margin-bottom: 8px;
}

#debug-panel {
  background: var(--bg-secondary);
  border: 1px solid #2a2a3e;
  border-radius: 12px;
  padding: 16px;
  max-height: 80vh;
  overflow-y: auto;
}

.debug-section {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #1a1a30;
}

.debug-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.debug-section h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: var(--amber);
  margin-bottom: 8px;
  letter-spacing: 1px;
}

.mono-grid {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  line-height: 1.8;
  color: var(--text);
}

.mono-grid .label {
  color: var(--text-dim);
}

.mono-grid .value {
  color: var(--green);
}

.mono-scroll {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  line-height: 1.6;
  color: var(--text-dim);
  max-height: 160px;
  overflow-y: auto;
  background: rgba(0,0,0,0.3);
  border-radius: 6px;
  padding: 8px;
}

.mono-scroll::-webkit-scrollbar {
  width: 6px;
}

.mono-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.mono-scroll::-webkit-scrollbar-thumb {
  background: var(--text-dim);
  border-radius: 3px;
}

#emu-controls {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

#speed-control {
  font-size: 10px;
  color: var(--text-dim);
}

#speed-control label {
  display: flex;
  align-items: center;
  gap: 8px;
}

#speed-slider {
  flex: 1;
  accent-color: var(--amber);
}

.checkbox-label {
  font-size: 11px;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

#bitbang-canvas {
  display: block;
  margin-top: 8px;
  background: rgba(0,0,0,0.3);
  border-radius: 6px;
}

.disasm-current {
  color: var(--amber) !important;
  font-weight: bold;
}

.port-bit-on {
  color: var(--green);
}

.port-bit-off {
  color: #333;
}

/* Status Bar */
#status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 8px auto;
  padding: 8px 20px;
  background: var(--bg-secondary);
  border-top: 1px solid #2a2a3e;
  font-size: 10px;
  color: var(--text-dim);
  font-family: 'JetBrains Mono', monospace;
  flex-wrap: wrap;
  gap: 8px;
}

#emu-status {
  color: var(--amber);
}

/* Footer */
footer {
  text-align: center;
  padding: 20px;
  font-size: 10px;
  color: var(--text-dim);
}

footer a {
  color: var(--amber);
  text-decoration: none;
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
}

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

.disclaimer {
  display: block;
  margin-top: 8px;
  font-size: 8px;
  color: #444;
}

/* About Modal */
#about-modal {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.8);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: var(--bg-secondary);
  border: 2px solid var(--amber-dim);
  border-radius: 16px;
  padding: 32px;
  max-width: 500px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.8;
}

.modal-content h2 {
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  color: var(--amber);
  margin-bottom: 16px;
}

.modal-subhead {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: #ff6b35;
  margin: 14px 0 6px 0;
  letter-spacing: 0.5px;
}

.modal-content p {
  margin-bottom: 12px;
}

.modal-tech {
  font-size: 11px;
  color: var(--text-dim);
  border-top: 1px solid #2a2a3e;
  padding-top: 12px;
  margin-top: 16px;
}

.modal-content button {
  margin-top: 12px;
}

/* Responsive */
@media (max-width: 800px) {
  #main-container {
    flex-direction: column;
    align-items: center;
  }
  
  #debug-column {
    width: 100%;
    max-width: 380px;
  }
  
  #device-body, #rom-upload-area {
    width: 340px;
  }
}

@media (max-width: 400px) {
  #device-body, #rom-upload-area {
    width: 300px;
  }
  
  #lcd-canvas {
    width: 260px !important;
    height: 260px !important;
  }
}