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

:root {
  --bg: #0d0d1a;
  --bg2: #151528;
  --panel: #1a1a2e;
  --border: #2a2a4a;
  --amber: #f5a623;
  --amber-dim: #a06a10;
  --green: #39ff14;
  --red: #ff2d2d;
  --text: #c8c8d8;
  --text-dim: #6a6a8a;
  --wood1: #5c3a1e;
  --wood2: #7a4e2a;
  --wood3: #4a2e14;
  --cyan: #00e5ff;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

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

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
}

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

.power-led {
  width: 12px; height: 12px;
  background: var(--red);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--red);
  animation: pulse-led 1.5s ease-in-out infinite;
}
.power-led.off { background: #440000; box-shadow: none; animation: none; }

@keyframes pulse-led {
  0%, 100% { opacity: 1; box-shadow: 0 0 8px var(--red); }
  50% { opacity: 0.5; box-shadow: 0 0 3px var(--red); }
}

.title {
  font-family: 'Press Start 2P', monospace;
  font-size: 18px;
  background: linear-gradient(90deg, #ff4444, #ff8844, #ffcc44, #44cc44, #4488ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.rainbow-bar {
  display: flex; height: 3px; margin: 4px 0; gap: 1px;
}
.rainbow-bar span { flex: 1; border-radius: 1px; }
.rainbow-bar span:nth-child(1) { background: #ff4444; }
.rainbow-bar span:nth-child(2) { background: #ff8844; }
.rainbow-bar span:nth-child(3) { background: #ffcc44; }
.rainbow-bar span:nth-child(4) { background: #44cc44; }
.rainbow-bar span:nth-child(5) { background: #4488ff; }

.subtitle {
  font-size: 8px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}

.fps-display {
  font-size: 11px;
  color: var(--amber);
  font-family: 'JetBrains Mono', monospace;
}

.btn-icon {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  background: var(--border);
  color: var(--amber);
  border: 1px solid var(--amber-dim);
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
}
.btn-icon:hover { background: var(--amber-dim); color: #fff; }

.tv-frame {
  background: linear-gradient(145deg, var(--wood2), var(--wood1), var(--wood3), var(--wood1));
  border-radius: 20px;
  padding: 20px;
  position: relative;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.05);
  cursor: pointer;
}

.tv-frame::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 20px;
  background: repeating-linear-gradient(90deg, transparent, transparent 3px, rgba(0,0,0,0.08) 3px, rgba(0,0,0,0.08) 6px);
  pointer-events: none;
}

.tv-bezel {
  background: #0a0a0a;
  border-radius: 12px;
  padding: 8px;
  border: 2px solid #222;
}

.tv-screen-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 160 / 192;
  overflow: hidden;
  border-radius: 6px;
}

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

.crt-overlay {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.4) 100%);
  pointer-events: none;
  border-radius: 6px;
}

.scanlines {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, transparent, transparent 1px, rgba(0,0,0,0.15) 1px, rgba(0,0,0,0.15) 2px);
  pointer-events: none;
  border-radius: 6px;
}

.tv-brand {
  position: absolute;
  bottom: 6px;
  right: 24px;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: rgba(255,255,255,0.15);
}

.controls-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.controls-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ctrl-label {
  font-size: 10px;
  color: var(--amber);
  font-family: 'Press Start 2P', monospace;
  white-space: nowrap;
}

.ctrl-select {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
}

.rom-upload-status {
  font-size: 9px;
  color: var(--green);
  padding: 4px 8px;
  background: rgba(57, 255, 20, 0.08);
  border: 1px solid rgba(57, 255, 20, 0.2);
  border-radius: 4px;
  margin-left: 4px;
  white-space: nowrap;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.rom-upload-error {
  font-size: 9px;
  color: var(--red);
  padding: 4px 8px;
  background: rgba(255, 45, 45, 0.08);
  border: 1px solid rgba(255, 45, 45, 0.2);
  border-radius: 4px;
  margin-left: 4px;
  white-space: nowrap;
  animation: fadeIn 0.3s ease;
}

.btn-ctrl {
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  background: var(--bg2);
  color: var(--amber);
  border: 2px solid var(--amber-dim);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  transition: all 0.1s;
  min-width: 36px;
  text-align: center;
}
.btn-ctrl:hover { background: var(--amber-dim); color: #fff; transform: translateY(-1px); }
.btn-ctrl:active { transform: translateY(1px); }
.btn-ctrl.small { font-size: 14px; padding: 4px 8px; border-width: 1px; }

.ctrl-range { width: 80px; accent-color: var(--amber); }
.ctrl-val { font-size: 11px; color: var(--amber); min-width: 24px; }

.switch-label {
  font-size: 9px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  white-space: nowrap;
}
.switch-label input { accent-color: var(--amber); }

.transport { gap: 6px; }

.keyboard-hint {
  font-size: 9px;
  color: var(--text-dim);
  text-align: center;
  margin-top: 8px;
  padding: 6px;
  background: var(--panel);
  border-radius: 4px;
  border: 1px solid var(--border);
}

.debug-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-top: 10px;
  display: none;
  gap: 12px;
  flex-wrap: wrap;
}
.debug-panel.open { display: flex; }

.debug-section {
  flex: 1;
  min-width: 200px;
}
.debug-section.tia-full {
  flex-basis: 100%;
  min-width: 100%;
}

.debug-section h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: var(--amber);
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

.reg-grid {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.reg {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 3px 6px;
  display: flex;
  gap: 4px;
  align-items: center;
}
.reg.wide { min-width: 80px; }
.reg-name { font-size: 9px; color: var(--text-dim); }
.reg-val { font-size: 11px; color: var(--green); font-weight: 700; }

.flags-row {
  display: flex;
  gap: 4px;
  margin-top: 6px;
}
.flag {
  width: 22px; height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  border-radius: 3px;
  background: var(--bg);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.flag.on {
  background: var(--green);
  color: #000;
  border-color: var(--green);
  box-shadow: 0 0 6px rgba(57,255,20,0.4);
}

.disasm-view {
  font-size: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 4px;
  max-height: 160px;
  overflow-y: auto;
  line-height: 1.6;
}
.disasm-line { padding: 1px 4px; }
.disasm-line.current { background: rgba(57,255,20,0.15); color: var(--green); }

/* Full TIA Register Groups */
.tia-groups {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tia-group {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px;
}

.tia-group-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: var(--cyan);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tia-group-regs {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.tia-reg-full {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 2px 5px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 9px;
  min-width: 100px;
  position: relative;
  transition: border-color 0.15s;
}

.tia-reg-full.recently-written {
  border-color: var(--amber);
  box-shadow: 0 0 4px rgba(245,166,35,0.3);
}

.tia-reg-full .tr-addr {
  color: var(--text-dim);
  font-size: 7px;
  min-width: 22px;
}

.tia-reg-full .tr-name {
  color: var(--text);
  font-size: 8px;
  font-weight: 700;
  min-width: 48px;
}

.tia-reg-full .tr-val {
  color: var(--amber);
  font-weight: 700;
  font-size: 10px;
  min-width: 18px;
}

.tia-reg-full .tr-delay {
  font-size: 6px;
  color: var(--green);
  min-width: 14px;
  text-align: right;
}

.tia-reg-full .tr-delay-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  background: var(--green);
  border-radius: 0 0 2px 2px;
  transition: width 0.05s linear;
}

.ram-view {
  font-size: 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 4px;
  max-height: 120px;
  overflow-y: auto;
  white-space: pre;
  line-height: 1.5;
  color: var(--text-dim);
}

footer {
  text-align: center;
  padding: 16px;
  font-size: 9px;
  color: var(--text-dim);
  margin-top: 16px;
}
footer a {
  color: var(--amber);
  text-decoration: none;
  margin-left: 8px;
}
footer a:hover { text-decoration: underline; }

@media (max-width: 600px) {
  .title { font-size: 13px; }
  .subtitle { font-size: 7px; }
  .tv-frame { padding: 12px; border-radius: 14px; }
  .controls-panel { font-size: 10px; }
  .keyboard-hint { display: none; }
  .debug-section { min-width: 100%; }
  .tia-reg-full { min-width: 85px; font-size: 8px; }
}