@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

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

:root {
  --bg-deep: #0d0d1a;
  --bg-dark: #1a1a2e;
  --tv-bezel: #8B7355;
  --tv-bezel-dark: #5c4d3a;
  --tv-bezel-light: #a89070;
  --console-body: #d4c5a9;
  --console-dark: #b0a48a;
  --accent-red: #ff3333;
  --accent-green: #33ff66;
  --phosphor: #33ff6622;
  --text-glow: #88ffaa;
  --crt-tint: rgba(40, 255, 80, 0.03);
}

body {
  background: var(--bg-deep);
  color: #ccc;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  overflow-x: hidden;
  min-height: 100vh;
}

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

/* HEADER */
header {
  text-align: center;
  padding: 16px 10px 10px;
  position: relative;
}

header h1 {
  font-size: 16px;
  color: #f0e6d0;
  text-shadow: 0 0 20px rgba(255,200,100,0.4), 2px 2px 0 #000;
  letter-spacing: 3px;
  margin-bottom: 6px;
}

header .subtitle {
  font-size: 7px;
  color: #aa9977;
  letter-spacing: 1px;
}

.power-led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-red);
  box-shadow: 0 0 8px var(--accent-red), 0 0 2px var(--accent-red);
  position: absolute;
  top: 14px;
  left: 20px;
  animation: blink-led 2s ease-in-out infinite;
}

.power-led.on {
  background: var(--accent-green);
  box-shadow: 0 0 12px var(--accent-green), 0 0 4px var(--accent-green);
  animation: none;
}

@keyframes blink-led {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* MAIN AREA */
#main-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

#tv-and-debug {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  width: 100%;
  justify-content: center;
}

/* TV FRAME */
#tv-frame {
  background: linear-gradient(145deg, var(--tv-bezel-light), var(--tv-bezel), var(--tv-bezel-dark));
  border-radius: 20px;
  padding: 20px 20px 12px;
  box-shadow:
    0 8px 32px rgba(0,0,0,0.7),
    inset 0 2px 4px rgba(255,255,255,0.15),
    inset 0 -2px 4px rgba(0,0,0,0.3);
  position: relative;
  flex-shrink: 0;
}

#tv-screen-wrapper {
  position: relative;
  width: 512px;
  height: 384px;
  background: #000;
  border-radius: 16px;
  overflow: hidden;
  box-shadow:
    inset 0 0 60px rgba(0,0,0,0.8),
    inset 0 0 20px rgba(40,255,80,0.05),
    0 0 2px #000;
}

#canvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  position: relative;
  z-index: 1;
  filter: brightness(var(--canvas-brightness, 1));
}

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

#tv-screen-wrapper::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 3;
  pointer-events: none;
  border-radius: 16px;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.5) 100%);
}

/* TV CONTROLS */
#tv-controls {
  display: flex;
  justify-content: center;
  gap: 30px;
  padding: 10px 0 0;
  align-items: center;
}

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

.knob-group label {
  font-size: 6px;
  color: #d4c5a9;
  letter-spacing: 1px;
}

.knob-slider {
  -webkit-appearance: none;
  width: 80px;
  height: 6px;
  background: #5c4d3a;
  border-radius: 3px;
  outline: none;
}

.knob-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: radial-gradient(circle, #ddd, #999);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid #555;
}

#oscilloscope {
  border: 1px solid #5c4d3a;
  border-radius: 3px;
  background: #111;
}

#muteBtn {
  background: none;
  border: 1px solid #5c4d3a;
  color: #d4c5a9;
  font-size: 12px;
  cursor: pointer;
  border-radius: 4px;
  padding: 2px 6px;
}

#muteBtn:hover { background: #5c4d3a; }

/* DEBUG PANEL */
#debug-panel {
  background: #111118;
  border: 1px solid #333;
  border-radius: 8px;
  width: 240px;
  flex-shrink: 0;
  overflow: hidden;
  transition: width 0.3s;
}

#debug-panel.collapsed {
  width: 40px;
}

#debug-panel.collapsed #debug-content {
  display: none;
}

#debugToggle {
  background: #1a1a2e;
  border: none;
  color: var(--accent-green);
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 8px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  border-bottom: 1px solid #333;
}

#debug-content {
  padding: 8px;
  max-height: 370px;
  overflow-y: auto;
}

#debug-content::-webkit-scrollbar {
  width: 4px;
}

#debug-content::-webkit-scrollbar-thumb {
  background: #444;
  border-radius: 2px;
}

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

.debug-section h3 {
  font-size: 6px;
  color: var(--accent-green);
  margin-bottom: 4px;
  border-bottom: 1px solid #222;
  padding-bottom: 2px;
}

#regDisplay {
  font-size: 7px;
  line-height: 1.8;
  color: #aaffaa;
}

#regDisplay .reg-changed {
  color: #ffff00;
  text-shadow: 0 0 4px #ffff00;
}

#disasmDisplay {
  font-size: 6px;
  color: #88aaff;
  line-height: 1.6;
  max-height: 60px;
  overflow-y: auto;
}

#debugControls {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

#debugControls button {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  padding: 4px 8px;
  background: #222;
  border: 1px solid #555;
  color: #ccc;
  cursor: pointer;
  border-radius: 3px;
}

#debugControls button:hover {
  background: #333;
  border-color: var(--accent-green);
  color: var(--accent-green);
}

.speed-control {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.speed-control label {
  font-size: 6px;
  color: #888;
}

.speed-control input[type="range"] {
  width: 80px;
  height: 4px;
}

#speedLabel {
  font-size: 6px;
  color: var(--accent-green);
}

#memViewer {
  font-size: 5px;
  color: #668866;
  line-height: 1.4;
  max-height: 80px;
  overflow-y: auto;
  word-break: break-all;
}

/* CONSOLE UNIT */
#console-unit {
  width: 100%;
  max-width: 700px;
}

#console-body {
  background: linear-gradient(180deg, var(--console-body), var(--console-dark));
  border-radius: 12px 12px 6px 6px;
  padding: 14px 20px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5), inset 0 1px 2px rgba(255,255,255,0.3);
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

/* CASSETTE SLOT */
#cassette-slot {
  cursor: pointer;
  border: 2px dashed #8B7355;
  border-radius: 8px;
  padding: 6px;
  background: #222;
  transition: border-color 0.3s, box-shadow 0.3s;
  min-width: 160px;
}

#cassette-slot:hover {
  border-color: var(--accent-green);
  box-shadow: 0 0 10px rgba(51,255,102,0.2);
}

#cassette-slot.drag-over {
  border-color: var(--accent-green);
  background: #1a2e1a;
}

.cassette-body {
  background: linear-gradient(180deg, #f5e6c8, #d4b896);
  border-radius: 6px;
  padding: 6px 10px;
  text-align: center;
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.5), 0 2px 4px rgba(0,0,0,0.3);
  transition: transform 0.4s ease;
}

.cassette-body.inserted {
  animation: cassette-insert 0.5s ease-out;
}

@keyframes cassette-insert {
  0% { transform: translateY(-30px); opacity: 0.5; }
  60% { transform: translateY(3px); }
  100% { transform: translateY(0); opacity: 1; }
}

.cassette-window {
  display: flex;
  justify-content: center;
  gap: 20px;
  padding: 4px;
  background: #3a3020;
  border-radius: 4px;
  margin-bottom: 4px;
}

.reel {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #f5e6c8;
  background: #2a2010;
}

.cassette-label {
  font-size: 5px;
  color: #555;
  padding: 2px;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ROM INFO */
#rom-info {
  font-size: 6px;
  color: #888;
  padding: 4px;
  max-width: 160px;
}

#romHex {
  font-size: 5px;
  color: #668866;
  max-height: 40px;
  overflow-y: auto;
  word-break: break-all;
  margin-top: 2px;
}

/* CONTROLLERS */
#controllers {
  display: flex;
  gap: 20px;
}

.controller {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.controller-label {
  font-size: 6px;
  color: #666;
}

.paddle-knob {
  cursor: grab;
  border-radius: 50%;
  border: 2px solid #8B7355;
}

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

.action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.action-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #333;
  cursor: pointer;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  box-shadow: 0 3px 6px rgba(0,0,0,0.4), inset 0 1px 2px rgba(255,255,255,0.2);
  transition: transform 0.1s, box-shadow 0.1s;
}

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

.btn-red { background: linear-gradient(180deg, #ee4444, #aa2222); }
.btn-blue { background: linear-gradient(180deg, #4444ee, #2222aa); }
.btn-yellow { background: linear-gradient(180deg, #eecc22, #aa9911); }
.btn-green { background: linear-gradient(180deg, #44cc44, #22aa22); }

/* KEY BINDINGS */
#key-bindings-toggle {
  text-align: center;
  margin-top: 6px;
}

#showKeysBtn, #showInfoBtn {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  background: #222;
  border: 1px solid #444;
  color: #aaa;
  padding: 6px 12px;
  cursor: pointer;
  border-radius: 4px;
}

#showKeysBtn:hover, #showInfoBtn:hover {
  border-color: var(--accent-green);
  color: var(--accent-green);
}

#keyBindings {
  margin-top: 6px;
  font-size: 6px;
  color: #888;
  line-height: 2;
  text-align: left;
  background: #111;
  padding: 8px;
  border-radius: 4px;
}

/* INFO PANEL */
#info-toggle {
  text-align: center;
  margin-top: 10px;
}

#info-panel {
  background: #111118;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 14px;
  margin-top: 8px;
  font-size: 7px;
  line-height: 2;
  color: #aaa;
  max-width: 700px;
  margin-left: auto;
  margin-right: auto;
}

#info-panel h3 {
  color: #f0e6d0;
  font-size: 10px;
  margin-bottom: 8px;
}

#info-panel h4 {
  color: var(--accent-green);
  margin-top: 8px;
}

#info-panel .disclaimer {
  font-size: 5px;
  color: #666;
  margin-top: 10px;
  border-top: 1px solid #222;
  padding-top: 6px;
}

/* FOOTER */
footer {
  text-align: center;
  padding: 16px;
  margin-top: 16px;
  border-top: 1px solid #222;
}

footer a {
  color: var(--accent-green);
  text-decoration: none;
  font-size: 8px;
}

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

.footer-disclaimer {
  display: block;
  font-size: 5px;
  color: #555;
  margin-top: 6px;
}

/* TOAST */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 7px;
  z-index: 1000;
  transition: opacity 0.3s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  border: 1px solid var(--accent-red);
}

.toast.hidden {
  opacity: 0;
  pointer-events: none;
}

/* RESPONSIVE */
@media (max-width: 900px) {
  #tv-and-debug {
    flex-direction: column;
    align-items: center;
  }

  #tv-screen-wrapper {
    width: 340px;
    height: 255px;
  }

  #tv-frame {
    padding: 14px 14px 10px;
  }

  #debug-panel {
    width: 100%;
    max-width: 380px;
  }

  #debug-panel.collapsed {
    width: 100%;
  }

  header h1 {
    font-size: 10px;
  }
}

@media (max-width: 500px) {
  #tv-screen-wrapper {
    width: 280px;
    height: 210px;
  }

  #console-body {
    flex-direction: column;
    padding: 10px;
  }

  #controllers {
    flex-direction: row;
    gap: 10px;
  }
}