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

:root {
  --green: #33FF33;
  --green-dim: #22CC22;
  --green-dark: #0a5f0a;
  --amber: #FFAA00;
  --amber-dim: #cc8800;
  --bg-deep: #0a0a0a;
  --bg-panel: #111111;
  --bg-control: #1a1a1a;
  --border: #2a2a2a;
  --red: #cc2222;
  --red-bright: #ff3333;
}

body {
  background: var(--bg-deep);
  color: var(--green);
  font-family: 'IBM Plex Mono', monospace;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

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

.header {
  background: linear-gradient(180deg, #1a1a1a 0%, #111 100%);
  border-bottom: 1px solid var(--green-dark);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  box-shadow: 0 2px 12px rgba(51, 255, 51, 0.05);
}

.header-title {
  font-family: 'Press Start 2P', cursive;
  font-size: 14px;
  color: var(--green);
  text-shadow: 0 0 10px rgba(51,255,51,0.5);
  letter-spacing: 2px;
}

.header-sub {
  font-size: 9px;
  color: var(--green-dim);
  opacity: 0.7;
  margin-top: 2px;
}

.header-apple {
  font-size: 24px;
  margin-right: 10px;
  filter: hue-rotate(0deg);
}

.main-area {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.terminal-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  position: relative;
  background: radial-gradient(ellipse at center, #0f0f0f 0%, #050505 100%);
}

.crt-container {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  box-shadow:
    0 0 40px rgba(51, 255, 51, 0.08),
    inset 0 0 80px rgba(0,0,0,0.5);
  border: 2px solid #1a1a1a;
  background: #000;
}

.crt-container::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(0,0,0,0.15) 0px,
    rgba(0,0,0,0.15) 1px,
    transparent 1px,
    transparent 3px
  );
  pointer-events: none;
  z-index: 2;
}

.crt-container::after {
  content: '';
  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;
}

#terminal-canvas {
  display: block;
  image-rendering: pixelated;
  position: relative;
  z-index: 1;
}

.sidebar {
  width: 320px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.panel {
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
}

.panel-title {
  font-family: 'Press Start 2P', cursive;
  font-size: 8px;
  color: var(--amber);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 4px;
  text-transform: uppercase;
  transition: all 0.1s;
  letter-spacing: 1px;
}

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

.btn-reset {
  background: var(--red);
  color: #fff;
  box-shadow: 0 3px 0 #881111, 0 0 8px rgba(204,34,34,0.3);
}
.btn-reset:hover { background: var(--red-bright); }
.btn-reset:active { box-shadow: 0 1px 0 #881111; }

.btn-green {
  background: var(--green-dark);
  color: var(--green);
  box-shadow: 0 3px 0 #043d04, 0 0 8px rgba(51,255,51,0.1);
}
.btn-green:hover { background: #0b7a0b; }
.btn-green:active { box-shadow: 0 1px 0 #043d04; }

.btn-amber {
  background: #3d2e00;
  color: var(--amber);
  box-shadow: 0 3px 0 #2a1f00, 0 0 8px rgba(255,170,0,0.1);
}
.btn-amber:hover { background: #4d3a00; }
.btn-amber:active { box-shadow: 0 1px 0 #2a1f00; }

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

.speed-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: #222;
  border-radius: 3px;
  outline: none;
  margin: 8px 0 4px 0;
}
.speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--green);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 6px rgba(51,255,51,0.4);
}

.speed-label {
  font-size: 9px;
  color: var(--green-dim);
  display: flex;
  justify-content: space-between;
}

.drop-zone {
  border: 2px dashed var(--green-dark);
  border-radius: 8px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 8px;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--green);
  background: rgba(51,255,51,0.03);
}
.drop-zone-text {
  font-size: 10px;
  color: var(--green-dim);
}

.hex-input {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  background: #0a0a0a;
  border: 1px solid var(--border);
  color: var(--green);
  padding: 4px 8px;
  border-radius: 4px;
  outline: none;
  width: 80px;
}
.hex-input:focus {
  border-color: var(--green-dark);
  box-shadow: 0 0 4px rgba(51,255,51,0.2);
}

.file-info {
  font-size: 9px;
  color: var(--green-dim);
  margin-top: 6px;
  padding: 4px 6px;
  background: rgba(51,255,51,0.03);
  border-radius: 4px;
}

.registers {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.reg-box {
  background: #0a0a0a;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 6px;
  text-align: center;
}
.reg-label {
  font-size: 8px;
  color: var(--amber);
  font-weight: 700;
}
.reg-value {
  font-size: 12px;
  color: var(--green);
  font-weight: 700;
  font-family: 'IBM Plex Mono', monospace;
}

.flags-row {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  justify-content: center;
}

.flag-led {
  width: 28px;
  text-align: center;
  font-size: 8px;
  font-weight: 700;
  padding: 3px 0;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: #0a0a0a;
}
.flag-led.on {
  color: #000;
  background: var(--green);
  border-color: var(--green);
  box-shadow: 0 0 6px rgba(51,255,51,0.5);
}
.flag-led.off {
  color: #333;
}

.opcode-display {
  font-size: 10px;
  color: var(--amber);
  margin-top: 6px;
  padding: 4px 6px;
  background: #0a0a0a;
  border-radius: 4px;
  text-align: center;
  border: 1px solid var(--border);
}

.mem-inspector {
  margin-top: 6px;
}
.mem-dump {
  font-size: 9px;
  color: var(--green-dim);
  background: #0a0a0a;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px;
  white-space: pre;
  overflow-x: auto;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.4;
}

.footer {
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  padding: 6px 16px;
  font-size: 9px;
  color: #444;
  text-align: center;
  flex-shrink: 0;
}
.footer a {
  color: var(--green-dark);
  text-decoration: none;
}
.footer a:hover {
  color: var(--green);
}

.help-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.85);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.help-card {
  background: var(--bg-panel);
  border: 1px solid var(--green-dark);
  border-radius: 12px;
  padding: 24px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 0 40px rgba(51,255,51,0.1);
}

.help-card h2 {
  font-family: 'Press Start 2P', cursive;
  font-size: 12px;
  color: var(--amber);
  margin-bottom: 16px;
}

.help-card h3 {
  font-size: 10px;
  color: var(--green);
  margin: 12px 0 6px;
  font-family: 'Press Start 2P', cursive;
}

.help-card p, .help-card li {
  font-size: 11px;
  color: var(--green-dim);
  line-height: 1.6;
}

.help-card code {
  background: #0a0a0a;
  padding: 1px 4px;
  border-radius: 2px;
  color: var(--green);
}

.presets-select {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  background: #0a0a0a;
  border: 1px solid var(--border);
  color: var(--green);
  padding: 4px 6px;
  border-radius: 4px;
  width: 100%;
  outline: none;
}
.presets-select:focus {
  border-color: var(--green-dark);
}

.status-msg {
  font-size: 9px;
  padding: 4px 8px;
  border-radius: 4px;
  margin-top: 4px;
}
.status-msg.success {
  color: var(--green);
  background: rgba(51,255,51,0.05);
}
.status-msg.error {
  color: var(--red-bright);
  background: rgba(255,51,51,0.05);
}

@media (max-width: 768px) {
  .main-area {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    max-height: 40vh;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .terminal-wrap {
    padding: 8px;
  }
  .header-title { font-size: 10px; }
  .header-sub { font-size: 7px; }
}