@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Rajdhani:wght@400;500;600;700&display=swap');

:root {
  --bg: #0a0e1a;
  --bg-card: #111827;
  --bg-panel: #0d1321;
  --border: #1e293b;
  --cyan: #06b6d4;
  --blue: #3b82f6;
  --green: #10b981;
  --yellow: #f59e0b;
  --red: #ef4444;
  --text: #e2e8f0;
  --text-dim: #64748b;
  --glow-cyan: 0 0 12px rgba(6,182,212,0.4);
  --glow-blue: 0 0 12px rgba(59,130,246,0.4);
}

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

body {
  font-family: 'Rajdhani', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}

/* === Navbar === */
#navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 56px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 100;
}

.nav-left, .nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  font-family: 'Orbitron', monospace;
  font-size: 22px;
  font-weight: 900;
  color: var(--cyan);
  text-shadow: var(--glow-cyan);
  letter-spacing: 2px;
}

.logo-accent {
  color: var(--yellow);
  text-shadow: 0 0 12px rgba(245,158,11,0.4);
}

select {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  min-width: 180px;
}

select:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: var(--glow-cyan);
}

.rom-selector {
  position: relative;
}

#rom-search {
  width: 200px;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
}

#rom-search:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: var(--glow-cyan);
}

#rom-select {
  position: absolute;
  top: 100%;
  left: 0;
  width: 300px;
  max-height: 400px;
  overflow-y: auto;
  z-index: 200;
  display: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

#rom-select.show {
  display: block;
}

.btn {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-family: 'Rajdhani', sans-serif;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  letter-spacing: 0.5px;
}

.btn-accent {
  background: var(--cyan);
  color: #000;
}

.btn-accent:hover {
  background: #22d3ee;
  box-shadow: var(--glow-cyan);
}

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-outline:hover {
  border-color: var(--cyan);
  color: var(--cyan);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 13px;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}

.btn-close:hover { color: var(--text); }

/* === Main Content === */
#main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* === Emulator === */
#emulator-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: #000;
}

#emulator-container {
  position: relative;
}

#emulator-container canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

#fps-display {
  position: absolute;
  top: 10px;
  left: 10px;
  font-family: 'Orbitron', monospace;
  font-size: 12px;
  color: var(--cyan);
  background: rgba(0,0,0,0.6);
  padding: 4px 8px;
  border-radius: 4px;
  z-index: 10;
}

/* Welcome Screen */
#welcome-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 1000;
}

#welcome-screen.hidden { display: none; }

.welcome-icon {
  font-size: 56px;
  margin-bottom: 12px;
  filter: drop-shadow(0 0 20px rgba(6,182,212,0.5));
}

#welcome-screen h2 {
  font-family: 'Orbitron', 'Microsoft YaHei', monospace;
  font-size: 24px;
  color: var(--cyan);
  margin-bottom: 4px;
  letter-spacing: 3px;
  text-shadow: var(--glow-cyan);
}

#welcome-screen p {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 16px;
}

.welcome-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
  width: 100%;
  max-width: 400px;
}

.welcome-select {
  width: 100%;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  box-sizing: border-box;
}

.welcome-select:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: var(--glow-cyan);
}

.btn-lg {
  padding: 14px 40px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1px;
  border-radius: 8px;
}

.btn-lg:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Scale selector in navbar */
#scale-select {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: 'Orbitron', monospace;
  cursor: pointer;
  min-width: 130px;
}

#scale-select:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: var(--glow-cyan);
}

/* Drop overlay */
#drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(6,182,212,0.1);
  border: 3px dashed var(--cyan);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

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

.drop-text {
  font-family: 'Orbitron', monospace;
  font-size: 20px;
  color: var(--cyan);
  text-shadow: var(--glow-cyan);
}

/* === Control Hints === */
#control-hints {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 8px 16px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.hint {
  font-size: 12px;
  color: var(--text-dim);
}

kbd {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 11px;
  font-family: 'Orbitron', monospace;
  color: var(--cyan);
  margin-right: 3px;
}

/* === Cheat Panel === */
#cheat-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 380px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  z-index: 50;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.3s ease;
}

#cheat-panel.hidden {
  transform: translateX(100%);
  pointer-events: none;
}

.cheat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.cheat-header h3 {
  font-family: 'Orbitron', monospace;
  font-size: 16px;
  color: var(--cyan);
  letter-spacing: 1px;
}

.cheat-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.cheat-section {
  margin-bottom: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}

.cheat-section h4 {
  font-size: 14px;
  color: var(--cyan);
  margin-bottom: 8px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.cheat-desc {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
  line-height: 1.4;
}

.cheat-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.cheat-status {
  font-size: 12px;
  color: var(--yellow);
  margin-bottom: 8px;
  min-height: 16px;
}

.search-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.search-row input, .search-row select {
  flex: 1;
  min-width: 80px;
}

input[type="number"], input[type="text"] {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 13px;
  font-family: 'Rajdhani', sans-serif;
}

input:focus {
  outline: none;
  border-color: var(--cyan);
}

.cheat-results {
  max-height: 200px;
  overflow-y: auto;
}

.cheat-empty {
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  padding: 12px;
}

.cheat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  font-size: 12px;
  transition: background 0.15s;
}

.cheat-item:hover {
  background: rgba(6,182,212,0.05);
}

.cheat-item:last-child { border-bottom: none; }

.cheat-addr {
  font-family: 'Orbitron', monospace;
  color: var(--cyan);
  font-size: 11px;
  min-width: 60px;
}

.cheat-val {
  font-family: 'Orbitron', monospace;
  color: var(--yellow);
  font-size: 11px;
  min-width: 40px;
  text-align: center;
}

.cheat-label {
  flex: 1;
  color: var(--text-dim);
  font-size: 11px;
  margin: 0 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cheat-item .btn-freeze {
  padding: 2px 8px;
  font-size: 11px;
  border-radius: 3px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  transition: all 0.2s;
}

.cheat-item .btn-freeze.active {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

.cheat-item input.freeze-val {
  width: 45px;
  text-align: center;
  padding: 2px 4px;
  font-size: 11px;
  margin-right: 6px;
}

/* Memory Viewer */
.mem-controls {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.mem-controls input {
  flex: 1;
}

.memory-grid {
  font-family: 'Orbitron', monospace;
  font-size: 10px;
  line-height: 1.8;
  background: var(--bg);
  padding: 8px;
  border-radius: 4px;
  max-height: 150px;
  overflow-y: auto;
  white-space: pre;
  color: var(--text-dim);
}

.memory-grid .mem-addr {
  color: var(--cyan);
}

.memory-grid .mem-val {
  color: var(--text);
}

.memory-grid .mem-val-highlight {
  color: var(--yellow);
  text-shadow: 0 0 6px rgba(245,158,11,0.4);
}

/* === Touch Controls === */
#touch-controls {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  z-index: 30;
  pointer-events: none;
}

#touch-controls.hidden { display: none; }

.dpad {
  display: grid;
  grid-template-columns: 56px 56px 56px;
  grid-template-rows: 56px 56px 56px;
  gap: 2px;
  pointer-events: auto;
}

.dpad-btn {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  color: #fff;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.dpad-btn:active {
  background: rgba(6,182,212,0.3);
  border-color: var(--cyan);
}

.dpad-center {
  background: rgba(255,255,255,0.05);
  border: none;
}

.dpad-up { grid-column: 2; grid-row: 1; }
.dpad-left { grid-column: 1; grid-row: 2; }
.dpad-center { grid-column: 2; grid-row: 2; }
.dpad-right { grid-column: 3; grid-row: 2; }
.dpad-down { grid-column: 2; grid-row: 3; }

.action-btns {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  pointer-events: auto;
}

.action-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  font-family: 'Orbitron', monospace;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  border: 2px solid;
  -webkit-tap-highlight-color: transparent;
}

.btn-a {
  background: rgba(239,68,68,0.2);
  border-color: var(--red);
  color: var(--red);
}

.btn-b {
  background: rgba(59,130,246,0.2);
  border-color: var(--blue);
  color: var(--blue);
}

.btn-a:active { background: rgba(239,68,68,0.5); }
.btn-b:active { background: rgba(59,130,246,0.5); }

.meta-btns {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  pointer-events: auto;
}

.meta-btn {
  padding: 6px 20px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 20px;
  color: var(--text-dim);
  font-size: 11px;
  font-family: 'Orbitron', monospace;
  letter-spacing: 1px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.meta-btn:active {
  background: rgba(6,182,212,0.2);
  border-color: var(--cyan);
  color: var(--cyan);
}

/* === State Slots === */
#state-slots {
  position: fixed;
  bottom: 80px;
  right: 20px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  z-index: 40;
}

#state-slots.hidden { display: none; }

.state-header {
  font-family: 'Orbitron', monospace;
  font-size: 12px;
  color: var(--cyan);
  margin-bottom: 8px;
  letter-spacing: 1px;
}

.state-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.state-slot {
  width: 48px;
  height: 36px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Orbitron', monospace;
  font-size: 11px;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s;
}

.state-slot:hover {
  border-color: var(--cyan);
  color: var(--cyan);
}

.state-slot.has-data {
  border-color: var(--green);
  color: var(--green);
}

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(6,182,212,0.2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(6,182,212,0.4); }

/* === Invincibility Indicator === */
#invincible-indicator {
  position: absolute;
  top: 10px;
  right: 10px;
  font-family: 'Orbitron', monospace;
  font-size: 12px;
  color: var(--red);
  background: rgba(239,68,68,0.15);
  border: 1px solid var(--red);
  padding: 4px 10px;
  border-radius: 4px;
  z-index: 10;
  display: none;
  animation: pulse-red 1.5s infinite;
}

#invincible-indicator.active {
  display: block;
}

@keyframes pulse-red {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* === Cheat Buttons === */
.cheat-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cheat-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-family: 'Rajdhani', sans-serif;
  cursor: pointer;
  transition: all 0.2s;
}

.cheat-btn:hover {
  border-color: var(--cyan);
  background: rgba(6,182,212,0.05);
}

.cheat-btn.active {
  background: rgba(16,185,129,0.15);
  border-color: var(--green);
}

.cheat-key {
  font-family: 'Orbitron', monospace;
  font-size: 12px;
  font-weight: 700;
  color: var(--cyan);
  background: rgba(6,182,212,0.15);
  padding: 4px 10px;
  border-radius: 4px;
  min-width: 36px;
  text-align: center;
}

.cheat-btn.active .cheat-key {
  background: rgba(16,185,129,0.25);
  color: var(--green);
}

.cheat-name {
  flex: 1;
  font-weight: 600;
}

.cheat-status {
  font-size: 12px;
  color: var(--text-dim);
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(255,255,255,0.05);
}

.cheat-btn.active .cheat-status {
  color: var(--green);
  background: rgba(16,185,129,0.1);
}

/* === Cheat Log === */
.cheat-log {
  max-height: 200px;
  overflow-y: auto;
  font-size: 12px;
}

.log-entry {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: var(--text-dim);
  font-family: monospace;
}

.log-entry:first-child {
  color: var(--cyan);
}

/* === Responsive === */
@media (max-width: 768px) {
  #navbar { padding: 0 10px; height: 48px; }
  .logo { font-size: 16px; }
  select { min-width: 120px; font-size: 12px; }
  .btn { padding: 6px 10px; font-size: 12px; }
  #control-hints { display: none; }
  #cheat-panel { width: 100%; }
  .meta-btns { bottom: 170px; }
}
