:root {
  --crt-green: #33ff33;
  --crt-green-dim: #1a9c1a;
  --crt-green-glow: #33ff3380;
  --crt-bg: #0a0a0a;
  --bezel-color: #3d3225;
  --bezel-light: #5a4a38;
  --bezel-dark: #2a2118;
  --panel-bg: #1a1a1a;
  --panel-border: #333;
  --text-dim: #888;
  --red: #ff4444;
  --yellow: #ffcc00;
  --blue: #4488ff;
}

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

body {
  background: #111;
  background-image: 
    radial-gradient(ellipse at 50% 0%, #1a1a1a 0%, #0a0a0a 70%);
  color: #ccc;
  font-family: 'IBM Plex Mono', monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

.app-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

.header {
  text-align: center;
  padding: 20px 0 12px;
}

.header h1 {
  font-family: 'VT323', monospace;
  font-size: 36px;
  color: var(--crt-green);
  text-shadow: 0 0 10px var(--crt-green-glow), 0 0 20px var(--crt-green-glow);
  letter-spacing: 3px;
}

.header .subtitle {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 2px;
  letter-spacing: 1px;
}

/* CRT Monitor */
.monitor-frame {
  background: linear-gradient(145deg, var(--bezel-light), var(--bezel-dark));
  border-radius: 18px;
  padding: 24px;
  margin: 12px auto;
  max-width: 760px;
  box-shadow: 
    0 8px 32px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.08),
    inset 0 -1px 0 rgba(0,0,0,0.3);
  position: relative;
}

.monitor-label {
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: #6b5d4d;
  letter-spacing: 4px;
  font-weight: 700;
  text-transform: uppercase;
}

.screen-bezel {
  background: #050505;
  border-radius: 10px;
  padding: 8px;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.9);
}

.crt-screen {
  position: relative;
  background: var(--crt-bg);
  border-radius: 6px;
  overflow: hidden;
  cursor: text;
}

.crt-screen canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}

.scanlines {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.15) 2px,
    rgba(0,0,0,0.15) 4px
  );
  pointer-events: none;
  z-index: 2;
}

.vignette {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(
    ellipse at center,
    transparent 60%,
    rgba(0,0,0,0.4) 100%
  );
  pointer-events: none;
  z-index: 3;
}

.crt-flicker {
  animation: flicker 0.1s infinite alternate;
}

@keyframes flicker {
  0% { opacity: 1; }
  100% { opacity: 0.985; }
}

/* Controls Panel */
.controls-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}

.panel-section {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 14px;
}

.panel-section h3 {
  font-family: 'VT323', monospace;
  font-size: 18px;
  color: var(--crt-green);
  margin-bottom: 10px;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 6px;
  letter-spacing: 1px;
}

/* Retro buttons */
.btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 14px;
  border: 2px solid;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: all 0.1s;
  background: transparent;
}

.btn:active {
  transform: translateY(1px);
}

.btn-green {
  border-color: var(--crt-green-dim);
  color: var(--crt-green);
}
.btn-green:hover {
  background: rgba(51, 255, 51, 0.1);
  box-shadow: 0 0 8px var(--crt-green-glow);
}

.btn-red {
  border-color: #992222;
  color: var(--red);
}
.btn-red:hover {
  background: rgba(255, 68, 68, 0.1);
}

.btn-yellow {
  border-color: #997700;
  color: var(--yellow);
}
.btn-yellow:hover {
  background: rgba(255, 204, 0, 0.1);
}

.btn-blue {
  border-color: #2255aa;
  color: var(--blue);
}
.btn-blue:hover {
  background: rgba(68, 136, 255, 0.1);
}

.btn-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Register display */
.registers {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.reg-box {
  text-align: center;
  background: #0d0d0d;
  border: 1px solid #2a2a2a;
  border-radius: 3px;
  padding: 4px;
}

.reg-label {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 1px;
}

.reg-value {
  font-family: 'VT323', monospace;
  font-size: 20px;
  color: var(--crt-green);
  text-shadow: 0 0 4px var(--crt-green-glow);
}

/* Flags */
.flags-row {
  display: flex;
  gap: 4px;
  justify-content: center;
}

.flag-indicator {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'VT323', monospace;
  font-size: 16px;
  border-radius: 3px;
  border: 1px solid #2a2a2a;
  background: #0d0d0d;
  color: #444;
  transition: all 0.15s;
}

.flag-indicator.active {
  color: var(--crt-green);
  background: rgba(51, 255, 51, 0.08);
  border-color: var(--crt-green-dim);
  text-shadow: 0 0 4px var(--crt-green-glow);
}

/* File upload */
.file-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.hex-input {
  font-family: 'VT323', monospace;
  font-size: 18px;
  width: 80px;
  background: #0d0d0d;
  border: 1px solid #2a2a2a;
  color: var(--crt-green);
  padding: 4px 8px;
  border-radius: 3px;
  text-align: center;
}

.hex-input:focus {
  outline: none;
  border-color: var(--crt-green-dim);
  box-shadow: 0 0 4px var(--crt-green-glow);
}

.file-input-wrapper {
  position: relative;
}

.file-input-wrapper input[type="file"] {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.file-label {
  display: inline-block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  padding: 6px 14px;
  border: 2px solid var(--panel-border);
  color: #aaa;
  cursor: pointer;
  letter-spacing: 1px;
}
.file-label:hover {
  border-color: #555;
  color: #ddd;
}

.status-msg {
  font-size: 11px;
  color: var(--crt-green-dim);
  margin-top: 4px;
  min-height: 16px;
}

.status-msg.error {
  color: var(--red);
}

/* Speed control */
.speed-control {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.speed-control input[type="range"] {
  flex: 1;
  accent-color: var(--crt-green);
  height: 4px;
}

.speed-label {
  font-family: 'VT323', monospace;
  font-size: 16px;
  color: var(--crt-green);
  min-width: 100px;
  text-align: right;
}

/* Stats */
.stats-row {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-dim);
}

.stats-row span {
  color: var(--crt-green-dim);
}

/* Memory inspector */
.memory-toggle {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.memory-toggle .arrow {
  transition: transform 0.2s;
  display: inline-block;
  font-size: 10px;
}

.memory-toggle .arrow.open {
  transform: rotate(90deg);
}

.memory-viewer {
  background: #0a0a0a;
  border: 1px solid #222;
  border-radius: 3px;
  padding: 8px;
  margin-top: 8px;
  overflow-x: auto;
  font-family: 'VT323', monospace;
  font-size: 14px;
  color: var(--crt-green-dim);
  line-height: 1.6;
  max-height: 260px;
  overflow-y: auto;
}

.mem-addr {
  color: var(--text-dim);
}

.mem-byte {
  color: var(--crt-green-dim);
}

.mem-byte.highlight {
  color: var(--crt-green);
  background: rgba(51, 255, 51, 0.15);
  text-shadow: 0 0 4px var(--crt-green-glow);
}

.mem-page-select {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

/* Footer */
.footer {
  text-align: center;
  padding: 20px 0;
  font-size: 12px;
  color: #555;
}

.footer a {
  color: var(--crt-green-dim);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
  color: var(--crt-green);
}

/* Corrupt memory input */
.corrupt-input {
  color: var(--red) !important;
  border-color: #992222 !important;
}

.corrupt-input:focus {
  box-shadow: 0 0 4px rgba(255, 68, 68, 0.5) !important;
  border-color: var(--red) !important;
}

/* Example button area */
.example-btns {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

/* Responsive */
@media (max-width: 768px) {
  .controls-panel {
    grid-template-columns: 1fr;
  }
  .monitor-frame {
    padding: 12px;
    border-radius: 12px;
  }
  .registers {
    grid-template-columns: repeat(3, 1fr);
  }
  .header h1 {
    font-size: 28px;
  }
}

/* Hidden but accessible keyboard capture */
.keyboard-capture {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

/* Apple-1 Memory Map */
.memory-map-section {
  margin-top: 16px;
  max-width: 1100px;
}

.memmap-container {
  margin-top: 8px;
}

.memmap-description {
  font-size: 12px;
  color: #999;
  line-height: 1.7;
  margin-bottom: 16px;
  padding: 10px 12px;
  background: #0d0d0d;
  border: 1px solid #2a2a2a;
  border-radius: 3px;
  border-left: 3px solid var(--crt-green-dim);
}

/* Visual memory bar */
.memmap-visual {
  margin-bottom: 16px;
}

.memmap-bar {
  display: flex;
  height: 36px;
  border: 1px solid #444;
  border-radius: 3px;
  overflow: hidden;
  background: #0a0a0a;
}

.memmap-region {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  overflow: hidden;
  border-right: 1px solid rgba(0,0,0,0.5);
  transition: filter 0.15s;
  cursor: default;
}

.memmap-region:hover {
  filter: brightness(1.4);
}

.memmap-region:last-child {
  border-right: none;
}

.memmap-region-label {
  font-family: 'VT323', monospace;
  font-size: 11px;
  color: rgba(0,0,0,0.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 2px;
  text-shadow: 0 1px 0 rgba(255,255,255,0.15);
}

.memmap-zp { background: #3388cc; }
.memmap-stack { background: #2277bb; }
.memmap-input { background: #55aadd; }
.memmap-ram { background: #33cc66; }
.memmap-optram { background: #2ba855; }
.memmap-io { background: #ff6644; }
.memmap-basic { background: #cc66ff; }
.memmap-rom { background: #ffcc33; }
.memmap-expansion { background: #ff9944; }
.memmap-empty { background: #222; }

.memmap-empty .memmap-region-label {
  color: #444;
}

.memmap-ticks {
  display: flex;
  justify-content: space-between;
  font-family: 'VT323', monospace;
  font-size: 11px;
  color: #555;
  margin-top: 4px;
  padding: 0 1px;
}

/* Legend */
.memmap-legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 8px 12px;
  background: #0d0d0d;
  border: 1px solid #2a2a2a;
  border-radius: 3px;
}

.memmap-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #999;
}

.memmap-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}

/* Section titles */
.memmap-section-title {
  font-family: 'VT323', monospace;
  font-size: 16px;
  color: var(--crt-green);
  margin: 16px 0 8px;
  letter-spacing: 1px;
}

/* Memory map table */
.memmap-table-wrap {
  overflow-x: auto;
  border: 1px solid #2a2a2a;
  border-radius: 3px;
}

.memmap-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
}

.memmap-table thead th {
  background: #1a1a1a;
  color: #888;
  padding: 8px 12px;
  border: 1px solid #2a2a2a;
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  position: sticky;
  top: 0;
}

.memmap-table tbody td {
  padding: 7px 12px;
  border: 1px solid #222;
  vertical-align: top;
  color: #aaa;
  line-height: 1.5;
}

.memmap-table tbody tr {
  transition: background 0.1s;
}

.memmap-table tbody tr:hover {
  background: rgba(51, 255, 51, 0.03);
}

.memmap-addr {
  font-family: 'VT323', monospace;
  font-size: 15px;
  white-space: nowrap;
  letter-spacing: 0.5px;
}

.memmap-row-zp .memmap-addr,
.memmap-row-stack .memmap-addr { color: #3388cc; }
.memmap-row-input .memmap-addr { color: #55aadd; }
.memmap-row-ram .memmap-addr { color: #33cc66; }
.memmap-row-optram .memmap-addr { color: #2ba855; }
.memmap-row-io .memmap-addr { color: #ff6644; }
.memmap-row-basic .memmap-addr { color: #cc66ff; }
.memmap-row-rom .memmap-addr { color: #ffcc33; }

.memmap-desc {
  font-weight: 700;
  color: #ccc;
  white-space: nowrap;
}

/* Key Technical Notes */
.memmap-notes {
  padding: 10px 12px;
  background: #0d0d0d;
  border: 1px solid #2a2a2a;
  border-radius: 3px;
}

.memmap-note {
  font-size: 12px;
  color: #888;
  line-height: 1.7;
  margin-bottom: 10px;
  padding-left: 12px;
  border-left: 2px solid #333;
}

.memmap-note:last-child {
  margin-bottom: 0;
}

.memmap-note-label {
  color: var(--crt-green);
  font-weight: 700;
  font-family: 'VT323', monospace;
  font-size: 14px;
}

/* 6502 Instruction Set Reference */
.instruction-set-section {
  margin-top: 16px;
  max-width: 1100px;
}

.isa-container {
  margin-top: 8px;
}

.isa-legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 8px;
  background: #0d0d0d;
  border: 1px solid #2a2a2a;
  border-radius: 3px;
}

.isa-legend-item {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 3px;
  border: 1px solid;
}

.isa-legend-item.misc { color: #ccc; border-color: #555; background: rgba(200,200,200,0.05); }
.isa-legend-item.branch { color: #ff9944; border-color: #884400; background: rgba(255,153,68,0.08); }
.isa-legend-item.load { color: #44aaff; border-color: #225588; background: rgba(68,170,255,0.08); }
.isa-legend-item.arith { color: #33ff33; border-color: #1a7a1a; background: rgba(51,255,51,0.08); }
.isa-legend-item.shift { color: #ff66ff; border-color: #772277; background: rgba(255,102,255,0.08); }

.isa-table-wrap {
  overflow-x: auto;
  border: 1px solid #2a2a2a;
  border-radius: 3px;
}

.isa-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'VT323', monospace;
  font-size: 12px;
  min-width: 1000px;
}

.isa-table thead th {
  background: #1a1a1a;
  color: #888;
  padding: 4px 2px;
  border: 1px solid #2a2a2a;
  font-size: 11px;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 1;
}

.isa-table tbody td {
  border: 1px solid #222;
  padding: 2px;
  text-align: center;
  vertical-align: top;
  min-width: 58px;
  height: 52px;
}

.isa-row-header {
  background: #1a1a1a !important;
  color: #888 !important;
  font-size: 11px !important;
  font-weight: bold;
  min-width: 30px !important;
  width: 30px;
}

.isa-cell {
  cursor: default;
  transition: background 0.1s;
}

.isa-cell:hover:not(.isa-empty) {
  filter: brightness(1.3);
}

.isa-empty {
  background: #0a0a0a;
}

.isa-misc { background: rgba(200,200,200,0.03); }
.isa-branch { background: rgba(255,153,68,0.06); }
.isa-load { background: rgba(68,170,255,0.06); }
.isa-arith { background: rgba(51,255,51,0.06); }
.isa-shift { background: rgba(255,102,255,0.06); }

.isa-cell-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  line-height: 1.2;
}

.isa-mnemonic {
  font-weight: bold;
  font-size: 13px;
}

.isa-misc .isa-mnemonic { color: #ccc; }
.isa-branch .isa-mnemonic { color: #ff9944; }
.isa-load .isa-mnemonic { color: #44aaff; }
.isa-arith .isa-mnemonic { color: #33ff33; }
.isa-shift .isa-mnemonic { color: #ff66ff; }

.isa-detail {
  font-size: 10px;
  color: #666;
}

.isa-flags {
  font-size: 9px;
  color: #555;
  letter-spacing: 0.5px;
}

.isa-footnotes {
  margin-top: 10px;
  font-size: 11px;
  color: #555;
  line-height: 1.6;
  padding: 8px;
  background: #0d0d0d;
  border: 1px solid #2a2a2a;
  border-radius: 3px;
}

@media (max-width: 768px) {
  .isa-legend {
    gap: 6px;
  }
  .isa-legend-item {
    font-size: 10px;
    padding: 2px 5px;
  }
}