:root {
  --console-dark: #2D2D2D;
  --console-brown: #3B2F2F;
  --lcd-off: #C4CFA1;
  --lcd-on: #2B3A1B;
  --accent-orange: #CC5500;
  --accent-mustard: #D4A017;
  --debug-green: #33FF33;
  --debug-bg: #0A0A0A;
  --bg-warm: #5C4A3A;
}

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

body {
  background: var(--bg-warm);
  background-image:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.03) 0px, rgba(0,0,0,0.03) 2px, transparent 2px, transparent 20px),
    repeating-linear-gradient(0deg, rgba(0,0,0,0.02) 0px, rgba(0,0,0,0.02) 2px, transparent 2px, transparent 20px),
    radial-gradient(ellipse at center, #6B5B4B 0%, #3A2E25 100%);
  min-height: 100vh;
  font-family: 'IBM Plex Mono', monospace;
  color: #e0d8c8;
  overflow-x: hidden;
}

#app-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
}

#main-layout {
  display: flex;
  gap: 24px;
  justify-content: center;
  align-items: flex-start;
  flex-wrap: wrap;
}

#console-column {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* CONSOLE BODY */
#console-body {
  width: 280px;
  background: linear-gradient(180deg, #3B2F2F 0%, #2D2D2D 40%, #252525 100%);
  border-radius: 16px;
  padding: 16px 20px 24px;
  box-shadow:
    0 8px 32px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.08),
    0 2px 0 #1a1a1a;
  position: relative;
  border: 2px solid #1a1715;
}

#cartridge-slot {
  background: #1a1510;
  border-radius: 6px 6px 2px 2px;
  height: 40px;
  margin: 0 10px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #0e0c08;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.8);
  position: relative;
  overflow: hidden;
}

#cartridge-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 1px;
  text-align: center;
  padding: 2px 6px;
  background: rgba(80,70,50,0.3);
  border-radius: 2px;
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#cartridge-label.loaded {
  color: var(--accent-mustard);
  background: rgba(80,70,50,0.6);
}

#console-branding {
  font-family: 'Archivo Black', sans-serif;
  font-size: 22px;
  text-align: center;
  color: #c8b898;
  letter-spacing: 4px;
  text-shadow: 0 1px 0 rgba(0,0,0,0.6), 0 -1px 0 rgba(255,255,255,0.05);
  margin: 4px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

/* LCD SCREEN */
#screen-bezel {
  background: #1a1a14;
  border-radius: 4px;
  padding: 8px;
  margin: 0 16px;
  box-shadow:
    inset 0 3px 10px rgba(0,0,0,0.9),
    inset 0 -1px 0 rgba(255,255,255,0.03),
    0 1px 0 rgba(255,255,255,0.05);
}

#lcd-canvas {
  display: block;
  width: 192px;
  height: 192px;
  margin: 0 auto;
  image-rendering: pixelated;
  border-radius: 2px;
}

/* ACTION BUTTON */
#action-btn-area {
  display: flex;
  justify-content: center;
  margin: 16px 0 8px;
}

#action-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: #ddd;
  background: linear-gradient(180deg, #555 0%, #333 100%);
  border: 2px solid #222;
  border-radius: 4px;
  padding: 10px 28px;
  cursor: pointer;
  box-shadow: 0 3px 0 #111, 0 4px 8px rgba(0,0,0,0.4);
  transition: all 0.05s;
  user-select: none;
  -webkit-user-select: none;
}

#action-btn:active, #action-btn.pressed {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #111, 0 2px 4px rgba(0,0,0,0.3);
  background: linear-gradient(180deg, #444 0%, #2a2a2a 100%);
}

/* PADDLE */
#paddle-area {
  margin: 8px 30px 0;
  text-align: center;
}

#paddle-track {
  height: 24px;
  background: #1a1a14;
  border-radius: 12px;
  position: relative;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.8);
  cursor: pointer;
  touch-action: none;
}

#paddle-knob {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #888 0%, #555 50%, #333 100%);
  border: 2px solid #222;
  position: absolute;
  top: -6px;
  left: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
  cursor: grab;
  touch-action: none;
  transition: left 0.02s linear;
}

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

#paddle-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  color: #777;
  margin-top: 6px;
  letter-spacing: 2px;
}

/* CONTROLS BAR */
#controls-bar {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.ctrl-btn {
  font-size: 16px;
  background: linear-gradient(180deg, #4a3a2a, #332618);
  border: 1px solid #221a10;
  border-radius: 4px;
  color: var(--accent-mustard);
  padding: 6px 10px;
  cursor: pointer;
  box-shadow: 0 2px 0 #1a1208;
  transition: all 0.1s;
  user-select: none;
}

.ctrl-btn:hover { background: linear-gradient(180deg, #5a4a3a, #443828); }
.ctrl-btn:active { transform: translateY(1px); box-shadow: none; }

#speed-control {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: #aaa;
  font-family: 'Press Start 2P', monospace;
}

#speed-slider {
  width: 60px;
  accent-color: var(--accent-orange);
}

#speed-val {
  font-size: 8px;
  color: var(--accent-mustard);
  min-width: 24px;
}

/* SIDE PANEL */
#side-panel {
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-section {
  background: rgba(30,25,20,0.85);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px;
  padding: 14px;
}

.panel-section h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--accent-orange);
  margin-bottom: 10px;
  letter-spacing: 1px;
}

/* DROP ZONE */
#drop-zone {
  border: 2px dashed rgba(204,85,0,0.4);
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 10px;
}

#drop-zone:hover, #drop-zone.dragover {
  border-color: var(--accent-orange);
  background: rgba(204,85,0,0.08);
}

#drop-zone p {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: #aaa;
}

#drop-zone .sub {
  font-size: 7px;
  color: #666;
  margin-top: 4px;
}

.retro-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  padding: 10px 16px;
  background: linear-gradient(180deg, var(--accent-orange), #993d00);
  border: 2px solid #7a3100;
  border-radius: 4px;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 3px 0 #662800, inset 0 1px 0 rgba(255,255,255,0.2);
  transition: all 0.1s;
  display: block;
  width: 100%;
  text-align: center;
}

.retro-btn:hover { background: linear-gradient(180deg, #dd6600, #aa4400); }
.retro-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #662800; }

/* ROM INFO */
#rom-info {
  margin-top: 8px;
  font-size: 10px;
  font-family: 'IBM Plex Mono', monospace;
}

#rom-name {
  color: var(--accent-mustard);
  font-weight: bold;
  margin-bottom: 2px;
  word-break: break-all;
}

#rom-size { color: #999; margin-bottom: 4px; }

#rom-hex {
  background: #0a0a0a;
  color: var(--debug-green);
  padding: 6px;
  border-radius: 4px;
  font-size: 9px;
  line-height: 1.4;
  overflow-x: auto;
  white-space: pre;
  max-height: 80px;
}

/* CPU TOGGLE */
#cpu-toggle {
  display: flex;
  gap: 0;
  border-radius: 4px;
  overflow: hidden;
  border: 2px solid #333;
  margin-bottom: 8px;
}

.cpu-option {
  flex: 1;
  padding: 8px 4px;
  text-align: center;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  cursor: pointer;
  transition: all 0.15s;
  background: #1a1a1a;
  color: #666;
  user-select: none;
}

.cpu-option.selected {
  background: var(--accent-orange);
  color: #fff;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.3);
}

.cpu-option:hover:not(.selected) { background: #2a2a2a; }

#cpu-info {
  font-size: 9px;
  color: #888;
  line-height: 1.4;
}

/* DEMO BUTTONS */
.demo-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 8px 12px;
  background: linear-gradient(180deg, #3a3a2a, #2a2a1a);
  border: 1px solid #444;
  border-radius: 4px;
  color: var(--lcd-off);
  cursor: pointer;
  margin: 3px 3px;
  transition: all 0.1s;
}

.demo-btn:hover { background: linear-gradient(180deg, #4a4a3a, #3a3a2a); color: #fff; }
.demo-btn:active { transform: translateY(1px); }

/* DEBUG PANEL */
#debug-panel {
  background: var(--debug-bg);
  border: 1px solid #1a1a1a;
  border-radius: 8px;
  padding: 14px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--debug-green);
  animation: crtFlicker 3s infinite alternate;
  max-height: 400px;
  overflow-y: auto;
}

@keyframes crtFlicker {
  0% { opacity: 1; }
  50% { opacity: 0.97; }
  100% { opacity: 1; }
}

#debug-panel h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: var(--debug-green);
  margin-bottom: 10px;
  text-shadow: 0 0 8px rgba(51,255,51,0.4);
}

#debug-registers, #debug-disasm, #debug-memory, #debug-cycles, #debug-framebuffer {
  margin-bottom: 8px;
  line-height: 1.5;
  white-space: pre;
  overflow-x: auto;
  font-size: 9px;
}

#debug-registers span.label { color: #00cc00; }
#debug-registers span.val { color: #66ff66; }

#btn-debug { margin-top: 4px; }

/* ABOUT BUTTON */
#about-btn-container {
  text-align: center;
  margin-top: 16px;
}

#btn-about { display: inline-block; width: auto; padding: 8px 24px; }

/* MODALS */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden { display: none; }

.modal-content {
  background: linear-gradient(180deg, #3B2F2F, #2D2D2D);
  border: 2px solid var(--accent-orange);
  border-radius: 12px;
  padding: 24px;
  max-width: 520px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 12px 48px rgba(0,0,0,0.6);
}

.modal-content h2 {
  font-family: 'Archivo Black', sans-serif;
  font-size: 18px;
  color: var(--accent-mustard);
  margin-bottom: 16px;
  letter-spacing: 2px;
}

.modal-content h4 {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--accent-orange);
  margin: 14px 0 6px;
}

.modal-body {
  font-size: 12px;
  line-height: 1.6;
  color: #c8bfaf;
}

.modal-body p { margin-bottom: 8px; }
.modal-body ul { padding-left: 20px; margin-bottom: 8px; }
.modal-body li { margin-bottom: 4px; }
.modal-body .disclaimer { color: #888; font-style: italic; font-size: 10px; margin-top: 12px; }

.modal-body table {
  width: 100%;
  border-collapse: collapse;
}

.modal-body td {
  padding: 4px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 11px;
}

.modal-body td:first-child {
  font-family: 'IBM Plex Mono', monospace;
  color: var(--accent-mustard);
  width: 120px;
}

#modal-close, .overlay-close {
  position: absolute;
  top: 12px;
  right: 16px;
  font-size: 20px;
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
}

#modal-close:hover, .overlay-close:hover { color: #fff; }

.hidden { display: none !important; }

/* FOOTER */
#app-footer {
  text-align: center;
  margin-top: 32px;
  padding: 16px;
}

.footer-divider {
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent-orange), transparent);
  margin-bottom: 12px;
}

#app-footer p {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: #666;
  margin-bottom: 8px;
}

#app-footer a {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: var(--accent-orange);
  text-decoration: none;
}

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

/* SCROLLBAR */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #1a1a1a; }
::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }

/* RESPONSIVE */
@media (max-width: 720px) {
  #main-layout { flex-direction: column; align-items: center; }
  #side-panel { width: 100%; max-width: 320px; }
  #console-body { width: 260px; }
  #lcd-canvas { width: 170px; height: 170px; }
}

@media (max-width: 400px) {
  #console-body { width: 240px; padding: 12px 14px 20px; }
  #lcd-canvas { width: 150px; height: 150px; }
  #screen-bezel { margin: 0 10px; padding: 6px; }
}