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

:root {
  --bg: #0f0f23;
  --bezel: #5a5a5a;
  --bezel-light: #8a8a8a;
  --text-amber: #ffb000;
  --text-green: #00ff41;
  --led-green: #00ff41;
  --amstrad-red: #dd0000;
  --cpc-blue: #00006B;
  --cpc-yellow: #FFFF00;
  --cpc-cyan: #00FFFF;
  --panel-bg: #111128;
  --ctrl-bg: #2a2a3e;
  --ctrl-border: #444466;
}

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

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

/* TOP BAR */
#top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: linear-gradient(180deg, #1e1e3a, #14142a);
  border-bottom: 1px solid #333355;
  flex-wrap: wrap;
  gap: 8px;
}

#top-left, #top-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

#title {
  font-family: 'Press Start 2P', cursive;
  font-size: 14px;
  color: var(--cpc-yellow);
  text-shadow: 0 0 10px rgba(255,255,0,0.3);
}

select, .ctrl-btn, #upload-btn {
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  background: var(--ctrl-bg);
  color: #ddd;
  border: 1px solid var(--ctrl-border);
  padding: 5px 10px;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.15s;
}

select:hover, .ctrl-btn:hover, #upload-btn:hover {
  background: #3a3a5e;
  border-color: #6666aa;
}

#upload-btn {
  background: linear-gradient(180deg, #3a3a6e, #2a2a4e);
  color: var(--cpc-yellow);
  font-weight: bold;
  border-color: #5555aa;
  padding: 6px 14px;
}

.ctrl-btn.reset {
  background: linear-gradient(180deg, #6a2222, #4a1111);
  color: #ff6666;
  border-color: #882222;
}

.ctrl-btn.hard-reset {
  background: linear-gradient(180deg, #552200, #331100);
  color: #ff8833;
  border-color: #774400;
}

.ctrl-btn.small { padding: 4px 8px; font-size: 11px; }

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

#monitor-wrapper {
  flex-shrink: 0;
}

#monitor-bezel {
  position: relative;
  background: linear-gradient(145deg, var(--bezel-light), var(--bezel), #484848);
  border-radius: 20px;
  padding: 20px 24px 30px;
  box-shadow: 
    0 0 40px rgba(0,0,0,0.8),
    inset 0 1px 0 rgba(255,255,255,0.15),
    inset 0 -1px 0 rgba(0,0,0,0.4);
}

#power-led {
  position: absolute;
  top: 10px;
  right: 24px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #330000;
  transition: all 0.3s;
}

#power-led.on {
  background: var(--led-green);
  box-shadow: 0 0 6px var(--led-green), 0 0 12px rgba(0,255,65,0.4);
}

#screen-container {
  position: relative;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  border: 3px solid #222;
  box-shadow: inset 0 0 30px rgba(0,0,107,0.3);
}

#cpc-canvas {
  display: block;
  width: 768px;
  height: 544px;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

#scanline-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(0,0,0,0.25) 1px,
    rgba(0,0,0,0.25) 2px
  );
  mix-blend-mode: multiply;
}

#scanline-overlay.active {
  opacity: 1;
}

.crt-active #screen-container {
  border-radius: 16px;
}

.crt-active #cpc-canvas {
  filter: contrast(1.1) brightness(1.05);
}

#drop-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,107,0.85);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 10;
}

#drop-overlay.visible {
  display: flex;
}

#drop-text {
  font-family: 'Press Start 2P', cursive;
  font-size: 20px;
  color: var(--cpc-yellow);
  text-shadow: 0 0 20px rgba(255,255,0,0.5);
  border: 3px dashed var(--cpc-yellow);
  padding: 30px 40px;
  animation: pulse-border 1s ease-in-out infinite;
}

@keyframes pulse-border {
  0%,100% { border-color: var(--cpc-yellow); }
  50% { border-color: transparent; }
}

#bezel-label {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Press Start 2P', cursive;
  font-size: 10px;
  color: #999;
  letter-spacing: 4px;
}

/* SCREEN GLOW */
.screen-glow #screen-container {
  box-shadow: inset 0 0 30px rgba(0,0,107,0.3), 0 0 40px rgba(0,0,107,0.2);
}

/* DEBUG PANEL */
#debug-panel {
  width: 360px;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  background: var(--panel-bg);
  border: 1px solid #333355;
  border-radius: 8px;
  flex-shrink: 0;
}

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

#debug-tabs {
  display: flex;
  flex-wrap: wrap;
  border-bottom: 1px solid #333355;
  background: #191938;
}

.debug-tab {
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  padding: 6px 8px;
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.debug-tab.active {
  color: var(--text-green);
  border-bottom-color: var(--text-green);
}

.debug-tab:hover { color: #bbb; }

#debug-content { padding: 10px; }

.tab-content { display: none; font-size: 11px; line-height: 1.6; }
.tab-content.active { display: block; }

.reg-row { display: flex; justify-content: space-between; }
.reg-name { color: var(--text-amber); }
.reg-val { color: var(--text-green); font-weight: bold; }
.flag-row { display: flex; gap: 6px; margin: 6px 0; }
.flag-led { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #333; border: 1px solid #555; }
.flag-led.on { background: var(--led-green); box-shadow: 0 0 4px var(--led-green); }
.debug-section { margin-bottom: 12px; }
.debug-section h4 { color: var(--cpc-yellow); font-size: 11px; margin-bottom: 4px; border-bottom: 1px solid #333; padding-bottom: 2px; }

.disasm-line { color: #8888cc; }
.disasm-line.current { color: var(--text-green); font-weight: bold; }

/* Memory viewer */
.mem-row { white-space: pre; color: #888; }
.mem-addr { color: var(--text-amber); }
.mem-hex { color: var(--text-green); }
.mem-ascii { color: #888; }

/* Palette */
.palette-grid { display: flex; flex-wrap: wrap; gap: 4px; }
.pal-swatch { width: 28px; height: 28px; border: 1px solid #555; border-radius: 2px; position: relative; }
.pal-swatch .pal-num { position: absolute; bottom: 0; right: 1px; font-size: 7px; color: #fff; text-shadow: 0 0 2px #000; }

/* BOTTOM BAR */
#bottom-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 16px;
  background: linear-gradient(180deg, #14142a, #1e1e3a);
  border-top: 1px solid #333355;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 11px;
}

#bottom-left, #bottom-center, #bottom-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.led {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #331111;
  transition: all 0.15s;
}

.led.active {
  background: #ff3333;
  box-shadow: 0 0 6px #ff3333;
}

.led-label { color: #888; font-size: 10px; }

#file-name { color: #666; font-size: 10px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#fps-display { color: var(--text-green); font-size: 10px; }

#volume-slider {
  width: 60px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: #333;
  border-radius: 2px;
  outline: none;
}

#volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-green);
  cursor: pointer;
}

/* VIRTUAL KEYBOARD */
#virtual-keyboard {
  background: #222240;
  border-top: 1px solid #444466;
  padding: 10px;
  overflow-x: auto;
}

#virtual-keyboard.hidden { display: none; }

.kb-row { display: flex; gap: 3px; margin-bottom: 3px; justify-content: center; }

.kb-key {
  font-family: 'Share Tech Mono', monospace;
  font-size: 9px;
  min-width: 32px;
  height: 28px;
  background: linear-gradient(180deg, #444466, #333355);
  color: #ddd;
  border: 1px solid #555577;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  transition: all 0.1s;
  padding: 0 4px;
}

.kb-key:active, .kb-key.pressed {
  background: linear-gradient(180deg, #666688, #555577);
  transform: translateY(1px);
}

.kb-key.fn-key { background: linear-gradient(180deg, #664444, #553333); color: #ff8888; }
.kb-key.wide { min-width: 50px; }
.kb-key.wider { min-width: 70px; }
.kb-key.space { min-width: 200px; }
.kb-key.enter { min-width: 46px; background: linear-gradient(180deg, #446644, #335533); color: #88ff88; }

/* MODAL */
.modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.7); display: flex; justify-content: center; align-items: center; z-index: 100; }
.modal.hidden { display: none; }
.modal-content { background: var(--panel-bg); border: 1px solid #444466; border-radius: 8px; padding: 20px; text-align: center; min-width: 300px; }
.modal-content h3 { font-family: 'Press Start 2P', cursive; font-size: 12px; color: var(--cpc-yellow); margin-bottom: 12px; }
.modal-content p { margin-bottom: 16px; color: #aaa; font-size: 13px; }
.modal-btn { font-family: 'Share Tech Mono', monospace; font-size: 12px; padding: 8px 16px; margin: 4px; background: var(--ctrl-bg); color: #ddd; border: 1px solid var(--ctrl-border); border-radius: 4px; cursor: pointer; }
.modal-btn:hover { background: #3a3a5e; }
.modal-btn.cancel { color: #ff6666; }
.modal-addr-row { display: flex; align-items: center; justify-content: center; gap: 4px; margin: 4px 0; }
#load-address { font-family: 'Share Tech Mono', monospace; width: 60px; padding: 6px; background: #1a1a2e; color: var(--text-green); border: 1px solid var(--ctrl-border); border-radius: 3px; text-align: center; }

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

#footer a {
  font-family: 'Press Start 2P', cursive;
  font-size: 10px;
  color: var(--amstrad-red);
  text-decoration: none;
  transition: color 0.3s;
}

#footer a:hover { color: #ff4444; text-shadow: 0 0 10px rgba(255,0,0,0.3); }

/* RESPONSIVE */
@media (max-width: 900px) {
  #cpc-canvas { width: 100%; height: auto; }
  #monitor-bezel { padding: 12px 14px 24px; border-radius: 12px; }
  #main-area { flex-direction: column; align-items: center; }
  #debug-panel { width: 100%; max-height: 300px; }
  #title { font-size: 10px; }
}

@media (max-width: 500px) {
  #top-bar { padding: 6px 8px; }
  #top-right { gap: 4px; }
  .ctrl-btn, select, #upload-btn { font-size: 10px; padding: 4px 6px; }
  #title { font-size: 8px; }
  #bottom-bar { font-size: 9px; }
  .kb-key { min-width: 24px; height: 24px; font-size: 7px; }
  .kb-key.space { min-width: 120px; }
}