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

body {
  background: #0d0d1a;
  color: #c0c0d0;
  font-family: 'JetBrains Mono', monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

#app { display: flex; flex-direction: column; min-height: 100vh; }

header {
  background: linear-gradient(135deg, #0a0a1a 0%, #1a1a3a 100%);
  border-bottom: 2px solid #21C842;
  padding: 12px 20px;
  text-align: center;
}

.header-content { display: flex; flex-direction: column; align-items: center; }

.header-title-row {
  display: flex; align-items: center; gap: 12px; justify-content: center;
}

.corruption-badge {
  font-family: 'Press Start 2P', cursive;
  font-size: 7px;
  color: #FF7978;
  background: rgba(252,85,84,0.15);
  border: 1px solid #FC5554;
  border-radius: 4px;
  padding: 3px 8px;
  animation: badge-pulse 2s infinite;
}

@keyframes badge-pulse {
  0%, 100% { box-shadow: 0 0 4px rgba(252,85,84,0.3); }
  50% { box-shadow: 0 0 12px rgba(252,85,84,0.6); }
}

header h1 {
  font-family: 'Press Start 2P', cursive;
  font-size: 18px; color: #42EBF5;
  text-shadow: 0 0 10px rgba(66,235,245,0.5);
  letter-spacing: 2px;
}

.subtitle {
  font-size: 9px; color: #5EDC78;
  margin-top: 4px;
  font-family: 'Press Start 2P', cursive;
}

#main-layout { display: flex; flex: 1; gap: 0; }

#display-area {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; padding: 20px;
  background: radial-gradient(ellipse at center, #1a1a2e 0%, #0d0d1a 70%);
}

#crt-frame {
  background: linear-gradient(145deg, #2a2a3a, #1a1a25);
  border-radius: 20px; padding: 16px;
  box-shadow: 0 0 30px rgba(0,0,0,0.8), inset 0 0 20px rgba(0,0,0,0.5);
  border: 2px solid #333;
}

#crt-screen {
  position: relative; border-radius: 8px;
  overflow: hidden; background: #000;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.8);
}

#screen {
  display: block; width: 684px; height: 524px;
  image-rendering: pixelated; image-rendering: crisp-edges;
}

#scanlines {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  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);
  opacity: 0; transition: opacity 0.3s;
}
#scanlines.active { opacity: 1; }

#corruption-flash {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  background: rgba(252,85,84,0);
  transition: none;
}
#corruption-flash.flash {
  animation: corrupt-flash 0.15s ease-out;
}
@keyframes corrupt-flash {
  0% { background: rgba(252,85,84,0.3); }
  100% { background: rgba(252,85,84,0); }
}

#controls {
  margin-top: 16px; display: flex; flex-direction: column;
  gap: 8px; width: 100%; max-width: 684px;
}
.control-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }

.sram-row {
  background: rgba(33,176,59,0.08);
  border: 1px solid rgba(33,176,59,0.25);
  border-radius: 6px; padding: 6px 10px;
}
.sram-auto-label { font-family: 'Press Start 2P', cursive; font-size: 8px; color: #5EDC78; }
.sram-status { font-size: 9px; color: #5EDC78; font-family: 'Press Start 2P', cursive; }
.sram-dirty-indicator { font-family: 'JetBrains Mono', monospace; font-size: 10px; font-weight: bold; }
.sram-dirty-indicator.dirty { color: #FC5554; animation: pulse-dirty 1s infinite; }
.sram-dirty-indicator.clean { color: #21C842; }
@keyframes pulse-dirty { 0%,100%{opacity:1} 50%{opacity:0.5} }

.file-btn {
  display: inline-flex; align-items: center; gap: 4px;
  background: linear-gradient(180deg, #2a4a3a, #1a3a2a);
  border: 2px solid #21C842; color: #5EDC78;
  padding: 6px 14px; border-radius: 6px; cursor: pointer;
  font-family: 'Press Start 2P', cursive; font-size: 9px;
  transition: all 0.15s;
}
.file-btn:hover { background: #21C842; color: #000; }

.ctrl-btn {
  background: linear-gradient(180deg, #2a2a40, #1a1a30);
  border: 2px solid #5455ED; color: #7D76FC;
  padding: 6px 12px; border-radius: 6px; cursor: pointer;
  font-size: 14px; transition: all 0.15s;
  font-family: 'JetBrains Mono', monospace;
}
.ctrl-btn:hover { background: #5455ED; color: #fff; }
.ctrl-btn:active { transform: translateY(1px); }

.tiny-btn { font-size: 8px !important; padding: 2px 6px !important; }

.ctrl-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 8px; color: #888;
  font-family: 'Press Start 2P', cursive;
}

select, input[type="range"] {
  background: #1a1a30; border: 1px solid #444;
  color: #c0c0d0; padding: 4px; border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
}
input[type="range"] { width: 80px; accent-color: #42EBF5; }

#gamepads-container { margin-top: 16px; display: flex; align-items: flex-start; gap: 20px; justify-content: center; }
.gamepad-wrapper { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.gamepad-label { font-family: 'Press Start 2P', cursive; font-size: 10px; color: #42EBF5; text-shadow: 0 0 6px rgba(66,235,245,0.4); padding: 2px 10px; border: 1px solid #42EBF5; border-radius: 4px; background: rgba(66,235,245,0.08); }
.gamepad-label.p2-label { color: #FF7978; text-shadow: 0 0 6px rgba(255,121,120,0.4); border-color: #FF7978; background: rgba(255,121,120,0.08); }
.gamepad-divider { width: 2px; height: 140px; background: linear-gradient(180deg, transparent, #444, transparent); align-self: center; }
#gamepad, #gamepad-p2 { display: flex; align-items: center; gap: 40px; }
#dpad, #dpad-p2 { display: flex; flex-direction: column; align-items: center; gap: 0; }
.dpad-mid { display: flex; align-items: center; gap: 0; }
.dpad-btn { width: 44px; height: 44px; background: linear-gradient(180deg, #333, #222); border: 2px solid #555; color: #aaa; font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.1s; user-select: none; -webkit-user-select: none; touch-action: none; }
.dpad-btn:active, .dpad-btn.pressed { background: #5455ED; color: #fff; border-color: #7D76FC; }
.dpad-center { width: 44px; height: 44px; background: #2a2a2a; border: 2px solid #444; }
#action-btns, #action-btns-p2 { display: flex; gap: 16px; }
.action-btn { width: 56px; height: 56px; border-radius: 50%; background: linear-gradient(180deg, #D4524D, #a03030); border: 3px solid #FC5554; color: #fff; font-family: 'Press Start 2P', cursive; font-size: 12px; cursor: pointer; transition: all 0.1s; user-select: none; -webkit-user-select: none; touch-action: none; }
.action-btn:active, .action-btn.pressed { background: #FC5554; box-shadow: 0 0 15px rgba(252,85,84,0.6); transform: scale(0.95); }
.p2-dpad:active, .p2-dpad.pressed { background: #D4C154; color: #000; border-color: #E6CE80; }
.p2-action { background: linear-gradient(180deg, #5455ED, #3a3aad) !important; border-color: #7D76FC !important; }
.p2-action:active, .p2-action.pressed { background: #7D76FC !important; box-shadow: 0 0 15px rgba(125,118,252,0.6) !important; transform: scale(0.95); }
#pause-btn-container { display: flex; justify-content: center; margin-left: 8px; }
.pause-reset-btn { padding: 6px 14px; border-radius: 8px; background: linear-gradient(180deg, #4a3a1a, #2a2010); border: 2px solid #D4C154; color: #E6CE80; font-family: 'Press Start 2P', cursive; font-size: 8px; cursor: pointer; transition: all 0.15s; user-select: none; -webkit-user-select: none; touch-action: none; }
.pause-reset-btn:active, .pause-reset-btn.pressed { background: #D4C154; color: #000; }

#key-hints { margin-top: 10px; font-size: 9px; color: #666; font-family: 'Press Start 2P', cursive; }

#debug-panel {
  width: 440px; background: #0f0f1f;
  border-left: 2px solid #333;
  overflow-y: auto; max-height: calc(100vh - 120px); flex-shrink: 0;
}
.debug-header { background: #1a1a30; padding: 10px 14px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; font-family: 'Press Start 2P', cursive; font-size: 10px; color: #42EBF5; border-bottom: 1px solid #333; position: sticky; top: 0; z-index: 2; }
#debug-content { padding: 10px; transition: max-height 0.3s; }
#debug-content.collapsed { display: none; }
.debug-section { margin-bottom: 14px; }
.debug-section h3 { font-family: 'Press Start 2P', cursive; font-size: 8px; color: #D4C154; margin-bottom: 6px; border-bottom: 1px solid #333; padding-bottom: 4px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.module-tag { font-family: 'JetBrains Mono', monospace; font-size: 7px; color: #5455ED; background: rgba(84,85,237,0.15); border: 1px solid rgba(84,85,237,0.3); border-radius: 3px; padding: 1px 5px; font-weight: normal; }
.debug-section pre { font-size: 11px; line-height: 1.5; color: #c0d0c0; white-space: pre-wrap; word-break: break-all; }
#flags-display { display: flex; gap: 6px; flex-wrap: wrap; }
.flag-indicator { padding: 2px 6px; border-radius: 3px; font-size: 10px; font-weight: bold; border: 1px solid #444; background: #1a1a1a; color: #666; }
.flag-indicator.active { background: #21C842; color: #000; border-color: #5EDC78; }
.bp-row { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; }
#bp-input, #mem-addr { background: #1a1a30; border: 1px solid #444; color: #42EBF5; padding: 4px 8px; border-radius: 4px; font-family: 'JetBrains Mono', monospace; font-size: 12px; width: 60px; }
#bp-status { font-size: 10px; color: #888; }
#mem-select { margin-bottom: 4px; font-size: 11px; }
#mem-display { font-size: 10px; max-height: 200px; overflow-y: auto; color: #aaa; }

/* VDP Corruption Section */
.corruption-section {
  background: rgba(252,85,84,0.04);
  border: 1px solid rgba(252,85,84,0.2);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 14px;
}
.corruption-section h3 { color: #FC5554 !important; }
.corruption-controls { display: flex; flex-direction: column; gap: 8px; }
.corruption-mode-row, .corruption-manual-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.corruption-label { font-size: 7px !important; color: #FF7978 !important; white-space: nowrap; }
.corruption-select {
  background: #1a0a0a; border: 1px solid #D4524D;
  color: #FF7978; padding: 3px 6px; border-radius: 4px;
  font-family: 'JetBrains Mono', monospace; font-size: 10px;
}
.corruption-indicator {
  font-size: 16px; line-height: 1;
}
.corruption-indicator.off { color: #444; }
.corruption-indicator.realistic { color: #D4C154; animation: ind-pulse 2s infinite; }
.corruption-indicator.aggressive { color: #FC5554; animation: ind-pulse 1s infinite; }
.corruption-indicator.chaos { color: #FF00FF; animation: ind-chaos 0.3s infinite; }
@keyframes ind-pulse { 0%,100%{opacity:1}50%{opacity:0.4} }
@keyframes ind-chaos { 0%{color:#FF00FF}25%{color:#00FFFF}50%{color:#FF0}75%{color:#0F0}100%{color:#FF00FF} }

.corrupt-vdp-btn {
  background: linear-gradient(180deg, #4a1a2a, #2a0a15) !important;
  border-color: #FC5554 !important;
  color: #FF7978 !important;
  font-size: 10px !important;
  padding: 4px 10px !important;
}
.corrupt-vdp-btn:hover {
  background: linear-gradient(180deg, #6a2a3a, #4a1a25) !important;
  box-shadow: 0 0 10px rgba(252,85,84,0.5);
}

.corruption-stats-row pre {
  font-size: 9px !important; color: #FF7978 !important;
  line-height: 1.4 !important;
}
.corruption-log-header {
  display: flex; justify-content: space-between; align-items: center;
  font-family: 'Press Start 2P', cursive;
  font-size: 7px; color: #888; margin-bottom: 4px;
}
.corruption-log {
  font-size: 8px !important;
  color: #996 !important;
  max-height: 160px;
  overflow-y: auto;
  line-height: 1.3 !important;
  background: rgba(0,0,0,0.3);
  border-radius: 4px;
  padding: 4px;
}

.rom-readonly-row { display: flex; align-items: center; margin-bottom: 6px; }
.rom-readonly-label { display: flex; align-items: center; gap: 8px; font-size: 10px; color: #c0c0d0; font-family: 'JetBrains Mono', monospace; cursor: pointer; user-select: none; }
.rom-readonly-label input[type="checkbox"] { display: none; }
.rom-cb-custom { width: 18px; height: 18px; border: 2px solid #21C842; border-radius: 3px; background: #0a0a18; display: inline-flex; align-items: center; justify-content: center; transition: all 0.2s; flex-shrink: 0; }
.rom-cb-custom::after { content: ''; width: 10px; height: 10px; background: #21C842; border-radius: 1px; opacity: 0; transition: opacity 0.15s; }
.rom-readonly-label input[type="checkbox"]:checked + .rom-cb-custom::after { opacity: 1; }
.rom-readonly-label input[type="checkbox"]:not(:checked) + .rom-cb-custom { border-color: #FC5554; box-shadow: 0 0 6px rgba(252,85,84,0.3); }
.rom-readonly-status { font-size: 9px; color: #21C842; font-family: 'JetBrains Mono', monospace; display: block; }

.corrupt-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.corrupt-label { display: flex; align-items: center; gap: 6px; font-size: 7px; color: #FC5554; font-family: 'Press Start 2P', cursive; }
#corrupt-amount { background: #1a0a0a; border: 1px solid #D4524D; color: #FF7978; padding: 4px 8px; border-radius: 4px; font-family: 'JetBrains Mono', monospace; font-size: 12px; width: 80px; }
.corrupt-btn-style { background: linear-gradient(180deg, #4a1a1a, #2a0a0a) !important; border-color: #D4524D !important; color: #FC5554 !important; font-size: 11px !important; animation: corrupt-idle 3s infinite; }
.corrupt-btn-style:hover { background: linear-gradient(180deg, #6a2a2a, #4a1a1a) !important; border-color: #FC5554 !important; }
@keyframes corrupt-idle { 0%,100%{text-shadow:none} 50%{text-shadow:0 0 6px rgba(252,85,84,0.6)} }
.corrupt-status { font-size: 9px; color: #666; font-family: 'JetBrains Mono', monospace; display: block; }
.corrupt-status.active { color: #FC5554; animation: glitch 0.3s ease; }
@keyframes glitch { 0%{transform:translateX(0)} 20%{transform:translateX(-2px);color:#42EBF5} 40%{transform:translateX(3px);color:#FF7978} 60%{transform:translateX(-1px);color:#21C842} 80%{transform:translateX(2px);color:#D4C154} 100%{transform:translateX(0);color:#FC5554} }

#status-bar {
  background: #0a0a18; border-top: 2px solid #333;
  padding: 6px 16px; display: flex; gap: 16px;
  font-size: 10px; font-family: 'Press Start 2P', cursive;
  color: #666; flex-wrap: wrap; align-items: center;
}
#status-state { color: #FC5554; }
#status-state.running { color: #21C842; animation: pulse 1.5s infinite; }
#status-state.paused { color: #D4C154; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.6} }

.corruption-status-bar {
  font-size: 8px;
  padding: 2px 8px;
  border-radius: 3px;
  border: 1px solid #333;
}
.corruption-status-bar.off { color: #555; }
.corruption-status-bar.realistic { color: #D4C154; border-color: #D4C154; background: rgba(212,193,84,0.1); }
.corruption-status-bar.aggressive { color: #FC5554; border-color: #FC5554; background: rgba(252,85,84,0.1); }
.corruption-status-bar.chaos { color: #FF00FF; border-color: #FF00FF; background: rgba(255,0,255,0.1); animation: ind-chaos 0.5s infinite; }

.dis-addr { color: #21C842; }
.dis-hex { color: #7D76FC; }
.dis-mnemonic { color: #42EBF5; }
.dis-current { background: #2a2a40; display: block; }
.dis-label { color: #555; font-size: 10px; }
.dis-halt { color: #FC5554; font-weight: bold; }

footer {
  background: #0a0a18; padding: 10px 20px;
  text-align: center; font-size: 9px; color: #444;
  display: flex; justify-content: center; gap: 20px;
  font-family: 'Press Start 2P', cursive;
}
footer a { color: #42EBF5; text-decoration: none; }
footer a:hover { text-decoration: underline; }

@media (max-width: 1100px) {
  #main-layout { flex-direction: column; }
  #debug-panel { width: 100%; border-left: none; border-top: 2px solid #333; max-height: 400px; }
  #screen { width: 100%; max-width: 512px; height: auto; }
}
@media (max-width: 600px) {
  header h1 { font-size: 12px; }
  .subtitle { font-size: 7px; }
  #display-area { padding: 10px; }
  #crt-frame { padding: 8px; border-radius: 12px; }
  #screen { max-width: 100%; }
  #gamepads-container { gap: 10px; flex-wrap: wrap; }
  #gamepad, #gamepad-p2 { gap: 20px; }
  .gamepad-divider { height: 2px; width: 100px; }
  .dpad-btn { width: 38px; height: 38px; }
  .dpad-center { width: 38px; height: 38px; }
  .action-btn { width: 48px; height: 48px; }
  #key-hints { display: none; }
  #status-bar { font-size: 7px; gap: 10px; }
}