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

:root {
  --bg: #0e0e0e;
  --panel: #1a1a1a;
  --panel-border: #2a2a2a;
  --text: #d0d0d0;
  --text-dim: #777;
  --accent: #cc0000;
  --green: #2ecc40;
  --yellow: #ffdc00;
  --blue: #4a9eff;
  --red: #ff4136;
  --mono: 'JetBrains Mono', 'Consolas', monospace;
  --display: 'Share Tech Mono', monospace;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  min-height: 100vh;
  background-image: radial-gradient(circle at 1px 1px, #1a1a1a 1px, transparent 0);
  background-size: 20px 20px;
}

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

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

header h1 {
  font-family: var(--display);
  font-size: 28px;
  font-weight: 400;
  letter-spacing: 2px;
  color: #fff;
}

header h1 .accent { color: var(--accent); }

.subtitle {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 11px;
}

.status {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status.stopped .status-dot { background: var(--red); box-shadow: 0 0 6px var(--red); }
.status.running .status-dot { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status.paused .status-dot { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }

#fps-display, #cycles-display { color: var(--text-dim); }

#main-layout {
  display: flex;
  gap: 12px;
}

#display-column {
  flex: 1;
  min-width: 0;
}

#debug-column {
  width: 340px;
  flex-shrink: 0;
}

#tv-bezel {
  background: #222;
  border-radius: 20px;
  padding: 24px;
  border: 3px solid #333;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.5), 0 0 30px rgba(0,0,0,0.8);
  position: relative;
  overflow: hidden;
}

#screen-container {
  position: relative;
  background: #e8e8e8;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 4/3;
  box-shadow: 0 0 20px rgba(255,255,255,0.05), inset 0 0 60px rgba(0,0,0,0.1);
}

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

#scanlines {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.03) 2px,
    rgba(0,0,0,0.03) 4px
  );
  pointer-events: none;
}

#controls-panel {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.control-group {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 12px;
  flex: 1;
  min-width: 180px;
}

.control-group h3 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-dim);
  margin-bottom: 8px;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 4px;
}

.btn {
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 12px;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  color: #fff;
  display: inline-block;
  margin: 2px;
}

.btn:hover { filter: brightness(1.2); transform: translateY(-1px); }
.btn:active { transform: translateY(0px); filter: brightness(0.9); }

.btn-blue { background: #2563eb; border-color: #3b82f6; }
.btn-green { background: #16a34a; border-color: #22c55e; }
.btn-red { background: #dc2626; border-color: #ef4444; }
.btn-yellow { background: #ca8a04; border-color: #eab308; }
.btn-gray { background: #444; border-color: #555; }
.btn-small { font-size: 10px; padding: 4px 8px; margin-bottom: 8px; }

.btn-row { display: flex; flex-wrap: wrap; gap: 4px; }

.file-info {
  font-size: 10px;
  color: var(--blue);
  margin-top: 6px;
  min-height: 14px;
}

.speed-control {
  margin-top: 8px;
}

.speed-control label {
  font-size: 11px;
  color: var(--text-dim);
}

.speed-control input[type="range"] {
  width: 100%;
  margin-top: 4px;
  accent-color: var(--accent);
}

#keyboard-panel {
  margin-top: 12px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 12px;
}

#keyboard-panel h3 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

#keyboard {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kb-row {
  display: flex;
  gap: 4px;
  justify-content: center;
}

.kb-key {
  background: #e8e0d4;
  color: #111;
  border: 1px solid #bbb;
  border-radius: 4px;
  min-width: 48px;
  height: 42px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  transition: all 0.1s;
  position: relative;
  box-shadow: 0 2px 0 #999;
}

.kb-key .kb-label {
  font-size: 7px;
  font-weight: 400;
  color: #888;
  position: absolute;
  bottom: 2px;
}

.kb-key:hover { background: #d8d0c4; }
.kb-key.pressed { background: #bbb; box-shadow: 0 0 0 #999; transform: translateY(2px); }
.kb-key.wide { min-width: 72px; }

#debug-panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 12px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}

.debug-section {
  margin-bottom: 12px;
}

.debug-section h3 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-dim);
  margin-bottom: 6px;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 4px;
}

.debug-section pre {
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  color: #aaa;
  white-space: pre;
  overflow-x: auto;
}

#flags-display {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.flag {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  background: #222;
  color: #555;
  border: 1px solid #333;
}

.flag.set {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 6px rgba(204,0,0,0.3);
}

.mem-input {
  font-family: var(--mono);
  font-size: 11px;
  width: 50px;
  background: #222;
  border: 1px solid #444;
  color: var(--text);
  padding: 2px 4px;
  border-radius: 3px;
  margin-left: 8px;
}

.disasm-current {
  background: rgba(204,0,0,0.2);
  color: #fff !important;
}

.modal {
  position: fixed;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 20px;
  min-width: 280px;
}

.modal-content h3 {
  margin-bottom: 12px;
  color: #fff;
}

.modal-content label {
  font-size: 12px;
  display: block;
}

.modal-content input[type="text"] {
  font-family: var(--mono);
  font-size: 13px;
  width: 80px;
  background: #222;
  border: 1px solid #444;
  color: var(--text);
  padding: 4px 6px;
  border-radius: 3px;
  margin-left: 8px;
}

footer {
  margin-top: 20px;
  text-align: center;
  padding: 12px;
  font-size: 10px;
  color: var(--text-dim);
  border-top: 1px solid var(--panel-border);
}

footer a {
  color: var(--accent);
  text-decoration: none;
  margin-left: 16px;
}

footer a:hover { text-decoration: underline; }

@media (max-width: 900px) {
  #main-layout { flex-direction: column; }
  #debug-column { width: 100%; }
  #debug-panel { max-height: 400px; }
}

@media (max-width: 600px) {
  header { flex-direction: column; gap: 8px; text-align: center; }
  header h1 { font-size: 22px; }
  .header-right { justify-content: center; flex-wrap: wrap; }
  #controls-panel { flex-direction: column; }
  .kb-key { min-width: 30px; height: 34px; font-size: 10px; }
  .kb-key.wide { min-width: 50px; }
  #tv-bezel { padding: 12px; border-radius: 12px; }
}