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

:root {
  --cream: #F5E6C8;
  --brown: #6B3410;
  --brown-dark: #3A1A05;
  --brown-mid: #8B4513;
  --orange: #D2691E;
  --tan: #C4A36E;
  --dark: #1A0E06;
  --panel-bg: #2A1508;
  --bezel-outer: #C4A882;
  --bezel-inner: #3C2415;
  --green-glow: rgba(80, 200, 80, 0.15);
}

body {
  background: var(--dark);
  background-image:
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 3px,
      rgba(90, 50, 20, 0.08) 3px,
      rgba(90, 50, 20, 0.08) 6px
    ),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 60px,
      rgba(60, 30, 10, 0.12) 60px,
      rgba(60, 30, 10, 0.12) 62px
    ),
    linear-gradient(170deg, #2A1508 0%, #1A0E06 50%, #0F0804 100%);
  color: var(--cream);
  font-family: 'VT323', monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

#app-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px;
}

/* Header */
#header {
  text-align: center;
  padding: 20px 0 12px;
  border-bottom: 3px solid var(--brown);
  margin-bottom: 16px;
}

#title-text {
  font-family: 'Press Start 2P', monospace;
  font-size: 28px;
  color: var(--orange);
  text-shadow: 0 0 20px rgba(210, 105, 30, 0.5), 3px 3px 0 var(--brown-dark);
  letter-spacing: 2px;
  cursor: pointer;
  user-select: none;
}

#subtitle {
  font-family: 'VT323', monospace;
  font-size: 18px;
  color: var(--tan);
  margin-top: 8px;
  letter-spacing: 1px;
}

/* Main Layout */
#main-layout {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

/* Panels */
#left-panel, #right-panel {
  flex: 0 0 260px;
}

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

/* Cartridge Panel */
#cartridge-panel {
  background: var(--panel-bg);
  border: 2px solid var(--brown);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}

#cartridge-label {
  background: linear-gradient(135deg, #C94040, #D46030);
  color: white;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  padding: 8px;
  border-radius: 4px;
  text-align: center;
  margin-bottom: 8px;
  border: 2px solid #FFF3;
  word-break: break-all;
  line-height: 1.6;
}

#drop-zone {
  border: 2px dashed var(--brown-mid);
  border-radius: 6px;
  padding: 16px;
  text-align: center;
  transition: all 0.3s;
  cursor: pointer;
}

#drop-zone.drag-over {
  border-color: var(--orange);
  background: rgba(210, 105, 30, 0.15);
  box-shadow: 0 0 20px rgba(210, 105, 30, 0.3);
}

#insert-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  background: linear-gradient(180deg, #3A2415, #1A0E06);
  color: var(--cream);
  border: 3px solid var(--brown);
  border-radius: 4px;
  padding: 12px 20px;
  cursor: pointer;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.4), 0 2px 8px rgba(0,0,0,0.5);
  transition: all 0.15s;
  width: 100%;
}

#insert-btn:hover {
  background: linear-gradient(180deg, #4A3425, #2A1E16);
  border-color: var(--orange);
}

#insert-btn:active {
  box-shadow: inset 0 3px 0 rgba(0,0,0,0.4);
  transform: translateY(1px);
}

.drop-hint {
  font-size: 13px;
  color: var(--tan);
  margin-top: 8px;
  opacity: 0.7;
}

#eject-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  background: #5A1010;
  color: #FFA0A0;
  border: 2px solid #8A3030;
  border-radius: 4px;
  padding: 6px 12px;
  cursor: pointer;
  width: 100%;
  margin-top: 8px;
}

#eject-btn:hover { background: #7A2020; }

/* Console Buttons */
#console-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
}

.console-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  background: linear-gradient(180deg, #555, #333);
  color: var(--cream);
  border: 2px solid #666;
  border-radius: 3px;
  padding: 10px 6px;
  cursor: pointer;
  box-shadow: 0 3px 0 #111, 0 4px 8px rgba(0,0,0,0.4);
  transition: all 0.1s;
}

.console-btn:active, .console-btn.pressed {
  box-shadow: 0 1px 0 #111;
  transform: translateY(2px);
  background: linear-gradient(180deg, #444, #222);
}

/* Controller Panel */
#controller-panel {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.controller {
  flex: 1;
  background: var(--panel-bg);
  border: 2px solid var(--brown);
  border-radius: 8px;
  padding: 8px;
  text-align: center;
}

.controller h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: var(--orange);
  margin-bottom: 6px;
}

.ctrl-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  margin-bottom: 6px;
}

.key {
  background: #333;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 3px 2px;
  font-size: 10px;
  color: var(--cream);
  font-family: 'IBM Plex Mono', monospace;
}

.key-center {
  background: #444;
  border: 1px solid #666;
  border-radius: 50%;
  padding: 3px;
  font-size: 10px;
  color: var(--orange);
}

.ctrl-extra {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
}

.ctrl-extra .key {
  font-size: 8px;
  padding: 2px;
}

/* Audio Controls */
#audio-controls {
  background: var(--panel-bg);
  border: 2px solid var(--brown);
  border-radius: 8px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
}

#audio-controls label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--tan);
}

#audio-controls input[type="range"] {
  flex: 1;
  accent-color: var(--orange);
}

/* TV Bezel */
#tv-bezel {
  background: linear-gradient(160deg, var(--bezel-outer) 0%, #A08860 40%, #8A7050 100%);
  border-radius: 24px;
  padding: 24px 28px;
  box-shadow:
    inset 0 2px 4px rgba(255,255,255,0.2),
    inset 0 -2px 4px rgba(0,0,0,0.3),
    0 8px 32px rgba(0,0,0,0.6),
    0 0 60px var(--green-glow);
  position: relative;
}

#screen-container {
  position: relative;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  border: 4px solid var(--bezel-inner);
  box-shadow: inset 0 0 30px rgba(0,0,0,0.8);
  line-height: 0;
}

#canvas {
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
  max-width: 768px;
}

#scanline-overlay {
  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;
}

#scanline-overlay.hidden { display: none; }

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

/* Speed Controls */
#speed-controls {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.speed-btn {
  font-family: 'VT323', monospace;
  font-size: 16px;
  background: var(--panel-bg);
  color: var(--cream);
  border: 2px solid var(--brown);
  border-radius: 4px;
  padding: 4px 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.speed-btn:hover { border-color: var(--orange); }
.speed-btn.active { background: var(--brown); border-color: var(--orange); color: var(--orange); }

#fps-counter {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  color: var(--tan);
  opacity: 0.7;
}

/* Right / Debug Panel */
#debug-toggle {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  background: linear-gradient(180deg, #333, #1A1A1A);
  color: #0F0;
  border: 2px solid #444;
  border-radius: 4px;
  padding: 8px 16px;
  cursor: pointer;
  width: 100%;
  margin-bottom: 8px;
  box-shadow: inset 0 -2px 0 rgba(0,255,0,0.1);
}

#debug-toggle:hover { border-color: #0F0; }

#debug-panel {
  background: #0A0A0A;
  border: 2px solid #333;
  border-radius: 6px;
  padding: 10px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: #0C0;
  max-height: 600px;
  overflow-y: auto;
}

#debug-panel h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: #0A0;
  margin: 8px 0 4px;
  border-bottom: 1px solid #222;
  padding-bottom: 2px;
}

#debug-panel h3:first-child { margin-top: 0; }

#debug-panel pre {
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.4;
  margin-bottom: 4px;
}

#breakpoint-ctrl {
  display: flex;
  gap: 4px;
  align-items: center;
  margin: 6px 0;
}

#bp-input {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  background: #111;
  color: #0F0;
  border: 1px solid #333;
  border-radius: 3px;
  padding: 2px 4px;
  width: 50px;
}

#bp-set, #bp-clear {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  background: #1A1A1A;
  color: #0C0;
  border: 1px solid #333;
  border-radius: 3px;
  padding: 2px 6px;
  cursor: pointer;
}

#vram-thumb {
  width: 100%;
  image-rendering: pixelated;
  border: 1px solid #333;
  margin-top: 4px;
}

/* Footer */
#footer {
  text-align: center;
  padding: 16px 0;
  margin-top: 20px;
  border-top: 2px solid var(--brown);
  color: var(--tan);
  font-size: 14px;
}

#footer a {
  color: var(--orange);
  text-decoration: none;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  display: inline-block;
  margin-top: 6px;
}

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

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-overlay.hidden { display: none; }

.modal-content {
  background: linear-gradient(160deg, #2A1508, #1A0E06);
  border: 3px solid var(--orange);
  border-radius: 12px;
  padding: 28px;
  max-width: 520px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 0 60px rgba(210, 105, 30, 0.3);
}

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

.modal-content h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: var(--cream);
  margin: 14px 0 8px;
}

.modal-content p, .modal-content li {
  font-family: 'VT323', monospace;
  font-size: 18px;
  color: var(--tan);
  line-height: 1.5;
  margin-bottom: 8px;
}

.modal-content ul {
  list-style: none;
  padding-left: 10px;
}

.modal-content li::before {
  content: "▸ ";
  color: var(--orange);
}

#close-modal {
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  background: var(--orange);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 12px 24px;
  cursor: pointer;
  margin-top: 16px;
  width: 100%;
  transition: background 0.2s;
}

#close-modal:hover { background: #E8802E; }

/* Responsive */
@media (max-width: 1024px) {
  #main-layout {
    flex-direction: column;
  }
  #left-panel, #right-panel {
    flex: none;
    width: 100%;
  }
  #controller-panel { flex-wrap: wrap; }
  #console-buttons { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 600px) {
  #title-text { font-size: 16px; }
  #tv-bezel { padding: 12px 14px; border-radius: 16px; }
  .console-btn { font-size: 6px; padding: 8px 4px; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #111; }
::-webkit-scrollbar-thumb { background: var(--brown); border-radius: 3px; }