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

:root {
  --phosphor: #A0D0FF;
  --phosphor-bright: #D0EAFF;
  --amber: #FFB347;
  --amber-dim: #CC8830;
  --bg-dark: #0A0A0C;
  --bg-mid: #111114;
  --bezel: #1A1A1E;
  --bezel-edge: #252528;
  --text-dim: #556;
  --text-mid: #889;
  --green-term: #33FF66;
  --font-mono: 'IBM Plex Mono', 'Share Tech Mono', 'Courier New', monospace;
  --font-display: 'Share Tech Mono', 'IBM Plex Mono', monospace;
}

html, body {
  height: 100%;
  background: var(--bg-dark);
  color: #aab;
  font-family: var(--font-mono);
  overflow-x: hidden;
  -webkit-user-select: none;
  user-select: none;
}

body {
  background-image:
    radial-gradient(ellipse at 50% 0%, rgba(160,208,255,0.03) 0%, transparent 60%),
    repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(255,255,255,0.008) 2px, rgba(255,255,255,0.008) 4px);
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
}

/* HEADER */
#header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid #222;
}

.header-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--phosphor);
  letter-spacing: 4px;
  text-shadow: 0 0 10px rgba(160,208,255,0.5), 0 0 30px rgba(160,208,255,0.2);
}

.header-subtitle {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 3px;
  margin-left: 8px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.fps {
  font-size: 11px;
  color: var(--amber-dim);
  letter-spacing: 1px;
}

.icon-btn {
  background: #1a1a1e;
  border: 1px solid #333;
  color: var(--text-mid);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-family: var(--font-mono);
  transition: all 0.15s;
}
.icon-btn:hover {
  background: #252528;
  color: var(--phosphor);
  border-color: var(--phosphor);
  box-shadow: 0 0 8px rgba(160,208,255,0.2);
}

/* MAIN */
#main-area {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 16px;
  padding: 12px 16px;
  flex: 1;
}

/* CONSOLE FRAME */
#console-frame {
  background: linear-gradient(160deg, #1E1E22, #141416);
  border: 2px solid #2a2a2e;
  border-radius: 16px;
  padding: 8px;
  box-shadow:
    0 0 40px rgba(0,0,0,0.8),
    inset 0 1px 0 rgba(255,255,255,0.04),
    0 0 80px rgba(160,208,255,0.03);
  flex-shrink: 0;
}

.bezel-top {
  text-align: center;
  padding: 6px 0 4px;
}

.bezel-brand {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 8px;
  color: #444;
  text-shadow: 0 1px 0 rgba(255,255,255,0.05), 0 -1px 0 rgba(0,0,0,0.5);
}

.bezel-bottom {
  height: 8px;
}

#screen-container {
  position: relative;
  width: 360px;
  height: 480px;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: inset 0 0 30px rgba(0,0,0,1), inset 0 0 60px rgba(0,0,0,0.5);
}

.screen-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.screen-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  mix-blend-mode: multiply;
  opacity: 0.15;
  border-radius: 12px;
}

.scanline-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(0,0,0,0.15) 1px,
    rgba(0,0,0,0.15) 2px
  );
  border-radius: 12px;
  z-index: 5;
}

.crt-effect {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 10;
  border-radius: 12px;
}

.crt-effect.hidden { display: none; }

/* DEBUG PANEL */
#debug-panel {
  background: #0a0e0a;
  border: 1px solid #1a3a1a;
  border-radius: 8px;
  padding: 12px;
  width: 280px;
  font-size: 11px;
  color: var(--green-term);
  font-family: var(--font-mono);
  max-height: 520px;
  overflow-y: auto;
  box-shadow: 0 0 20px rgba(0,0,0,0.5), inset 0 0 20px rgba(51,255,102,0.02);
}

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

.debug-header {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2px;
  border-bottom: 1px solid #1a3a1a;
  padding-bottom: 6px;
  margin-bottom: 8px;
  color: #44ff77;
}

.debug-section {
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid #0d1a0d;
}

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

.debug-label {
  color: #226633;
  font-size: 9px;
  letter-spacing: 2px;
  margin-bottom: 2px;
}

.debug-value {
  color: var(--green-term);
}

.debug-highlight {
  background: rgba(51,255,102,0.1);
  padding: 1px 3px;
}

/* CONTROLS */
#controls-panel {
  padding: 12px 16px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

.controls-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.program-select label {
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--text-dim);
  display: block;
  margin-bottom: 3px;
}

.program-select select {
  background: #1a1a1e;
  color: var(--amber);
  border: 1px solid #333;
  border-radius: 4px;
  padding: 6px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  outline: none;
}

.program-select select:focus {
  border-color: var(--amber);
  box-shadow: 0 0 8px rgba(255,179,71,0.2);
}

.control-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.ctrl-btn {
  background: linear-gradient(180deg, #2a2a2e, #1a1a1e);
  border: 1px solid #333;
  color: var(--text-mid);
  padding: 6px 12px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all 0.1s;
}

.ctrl-btn:hover {
  background: linear-gradient(180deg, #333, #222);
  color: var(--phosphor);
  border-color: #555;
}

.ctrl-btn:active {
  transform: translateY(1px);
  background: #181818;
}

.game-controls {
  gap: 30px;
}

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

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

.dpad-btn {
  background: linear-gradient(180deg, #2a2a2e, #1a1a1e);
  border: 1px solid #333;
  color: #667;
  width: 38px;
  height: 38px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.08s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dpad-btn:active, .dpad-btn.pressed {
  background: #111;
  color: var(--phosphor);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
}

.dpad-center {
  width: 38px;
  height: 38px;
  background: #1a1a1e;
  border-radius: 50%;
  border: 1px solid #252528;
}

.action-buttons {
  display: flex;
  gap: 8px;
}

.action-btn {
  background: linear-gradient(180deg, #2a2a2e, #1a1a1e);
  border: 1px solid #333;
  color: #667;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  transition: all 0.08s;
}

.action-btn:active, .action-btn.pressed {
  background: #111;
  color: var(--amber);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.5), 0 0 8px rgba(255,179,71,0.15);
}

/* MODAL */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.85);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal.hidden { display: none; }

.modal-content {
  background: #141416;
  border: 1px solid #2a2a2e;
  border-radius: 12px;
  max-width: 420px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 0 60px rgba(0,0,0,0.8);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid #222;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--phosphor);
}

.modal-close {
  background: none;
  border: none;
  color: #555;
  font-size: 18px;
  cursor: pointer;
}
.modal-close:hover { color: #aaa; }

.modal-body {
  padding: 16px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 12px;
}

.setting-row label {
  font-size: 11px;
  color: var(--text-mid);
  min-width: 140px;
}

.setting-row input[type="range"] {
  flex: 1;
  accent-color: var(--phosphor);
  height: 4px;
}

.setting-row span {
  font-size: 10px;
  color: var(--amber);
  min-width: 35px;
  text-align: right;
}

.setting-row input[type="checkbox"] {
  accent-color: var(--phosphor);
  width: 16px;
  height: 16px;
}

.info-body p {
  font-size: 12px;
  line-height: 1.7;
  margin-bottom: 10px;
  color: #99a;
}

.info-body strong {
  color: var(--phosphor);
}

.info-credit {
  font-size: 10px;
  color: var(--text-dim);
  font-style: italic;
}

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

.footer-text {
  font-size: 11px;
  color: #445;
  text-shadow: 0 0 15px rgba(160,208,255,0.1);
}

.footer-sep {
  color: #333;
  margin: 0 8px;
}

.footer-link {
  font-size: 11px;
  color: var(--amber-dim);
  text-decoration: none;
  transition: color 0.2s;
}

.footer-link:hover {
  color: var(--amber);
  text-shadow: 0 0 8px rgba(255,179,71,0.3);
}

/* RESPONSIVE */
@media (max-width: 800px) {
  #main-area {
    flex-direction: column;
    align-items: center;
  }

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

  #screen-container {
    width: 300px;
    height: 400px;
  }
}

@media (max-width: 450px) {
  #screen-container {
    width: 260px;
    height: 347px;
  }

  .header-title {
    font-size: 16px;
    letter-spacing: 2px;
  }

  .header-subtitle {
    display: none;
  }

  .ctrl-btn {
    padding: 5px 8px;
    font-size: 9px;
  }

  .dpad-btn {
    width: 34px;
    height: 34px;
  }

  .action-btn {
    width: 40px;
    height: 40px;
  }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #111; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #444; }