/* ============================================================
   HCPU-16 Mk II — Mil-Spec Terminal Stylesheet
   Industrial / retro-futuristic hardware debugger aesthetic
   ============================================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* Core palette */
  --bg-deep:        #0a0e14;
  --bg-panel:       #0d1117;
  --bg-surface:     #1a1e24;
  --border:         #2a2e34;
  --border-bright:  #3a3e44;

  /* Data colors */
  --phosphor:       #00ff9f;
  --phosphor-dim:   #00cc7f;
  --phosphor-glow:  rgba(0, 255, 159, 0.3);
  --amber:          #ffb347;
  --amber-glow:     rgba(255, 179, 71, 0.5);
  --red:            #ff4444;
  --red-glow:       rgba(255, 68, 68, 0.3);

  /* Text */
  --text-dim:       #4a5568;
  --text-label:     #6b7280;
  --text-muted:     #374151;

  /* Fonts */
  --font-mono:      'JetBrains Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  --font-label:     'JetBrains Mono', system-ui, -apple-system, sans-serif;

  /* Sizing */
  --toolbar-height: 48px;
  --panel-pad:      12px;
  --label-size:     9px;
}

html {
  font-size: 14px;
  height: 100%;
}

body {
  font-family: var(--font-mono);
  background: var(--bg-deep);
  color: var(--phosphor);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- Scanline overlay --- */
body::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  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;
  z-index: 9999;
}

/* --- CRT Frame (curvature illusion) --- */
#crt-frame {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100vh;
  border-radius: 6px;
  box-shadow:
    inset 0 0 80px rgba(0, 0, 0, 0.4),
    inset 0 0 20px rgba(0, 0, 0, 0.2),
    0 0 40px rgba(0, 255, 159, 0.02);
  overflow: hidden;
}

/* --- Title Bar --- */
#title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 36px;
  padding: 0 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.title-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.title-logo {
  color: var(--phosphor);
  font-size: 16px;
  text-shadow: 0 0 8px var(--phosphor-glow);
}

#title-bar h1 {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--phosphor);
  letter-spacing: 2px;
  text-transform: uppercase;
  text-shadow: 0 0 6px var(--phosphor-glow);
}

.title-mk {
  color: var(--amber);
  text-shadow: 0 0 6px var(--amber-glow);
}

.title-sub {
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 3px;
  text-transform: uppercase;
}

.title-right {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 2px;
  text-transform: uppercase;
}

.title-divider {
  color: var(--border);
}

.title-version {
  color: var(--text-label);
}

.title-arch {
  color: var(--text-dim);
}

/* --- Toolbar --- */
#toolbar {
  display: flex;
  align-items: center;
  height: var(--toolbar-height);
  padding: 0 12px;
  gap: 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

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

.toolbar-separator {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}

.toolbar-label {
  font-family: var(--font-label);
  font-size: var(--label-size);
  color: var(--text-dim);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-right: 4px;
}

.toolbar-examples {
  margin-left: auto;
}

/* --- Buttons --- */
.btn {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-label);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 6px 14px;
  cursor: pointer;
  transition: all 0.15s ease;
  outline: none;
  white-space: nowrap;
  user-select: none;
}

.btn:hover {
  border-color: var(--border-bright);
  color: #9ca3af;
}

.btn:active {
  transform: translateY(1px);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
}

.btn-small {
  font-size: 10px;
  padding: 4px 10px;
  letter-spacing: 1px;
}

/* Assemble button — green accent */
.btn-assemble {
  color: var(--phosphor);
  border-color: rgba(0, 255, 159, 0.3);
  background: rgba(0, 255, 159, 0.05);
}

.btn-assemble:hover {
  border-color: rgba(0, 255, 159, 0.5);
  background: rgba(0, 255, 159, 0.1);
  color: var(--phosphor);
  box-shadow: 0 0 8px rgba(0, 255, 159, 0.1);
}

.btn-icon {
  margin-right: 4px;
  font-size: 9px;
}

/* Run button when active */
.btn-run.active {
  color: var(--phosphor);
  border-color: var(--phosphor);
  box-shadow: 0 0 10px var(--phosphor-glow), inset 0 0 10px rgba(0, 255, 159, 0.05);
}

/* Toggle buttons (follow PC/SP) */
.btn-toggle.active {
  color: var(--amber);
  border-color: rgba(255, 179, 71, 0.4);
  background: rgba(255, 179, 71, 0.08);
}

/* Stop button */
.btn-stop:hover {
  border-color: rgba(255, 68, 68, 0.4);
  color: var(--red);
}

/* --- Custom select dropdown --- */
.custom-select {
  position: relative;
  max-width: 260px;
}

.custom-select-trigger {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-label);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 5px 10px;
  outline: none;
  cursor: pointer;
  white-space: nowrap;
  width: 260px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
}

.custom-select-trigger:hover {
  border-color: var(--border-bright);
}

.custom-select.open .custom-select-trigger {
  border-color: rgba(0, 255, 159, 0.3);
}

.custom-select-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 2px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 2px;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  max-height: 200px;
  overflow-y: auto;
}

.custom-select.open .custom-select-dropdown {
  display: block;
}

.custom-select-option {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-label);
  padding: 6px 10px;
  cursor: pointer;
  white-space: nowrap;
}

.custom-select-option:hover {
  background: rgba(0, 255, 159, 0.12);
  color: var(--phosphor);
  text-shadow: 0 0 6px var(--phosphor-glow);
}

.custom-select-option.selected {
  color: var(--phosphor);
}

.custom-select-dropdown::-webkit-scrollbar {
  width: 6px;
}

.custom-select-dropdown::-webkit-scrollbar-track {
  background: var(--bg-panel);
}

.custom-select-dropdown::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* --- Speed slider --- */
.toolbar-speed {
  gap: 8px;
}

#speed-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 80px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

#speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: var(--bg-surface);
  border: 2px solid var(--phosphor-dim);
  border-radius: 2px;
  cursor: pointer;
  transition: border-color 0.15s;
}

#speed-slider::-webkit-slider-thumb:hover {
  border-color: var(--phosphor);
  box-shadow: 0 0 6px var(--phosphor-glow);
}

#speed-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--bg-surface);
  border: 2px solid var(--phosphor-dim);
  border-radius: 2px;
  cursor: pointer;
}

.speed-label {
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 2px;
  text-transform: uppercase;
  min-width: 50px;
}

/* --- Main Workspace --- */
#workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 0;
}

/* --- Panel base styling --- */
.panel {
  position: relative;
  background: var(--bg-panel);
  border: 1px solid var(--border);
}

.panel-label {
  position: absolute;
  top: -1px;
  left: 12px;
  font-family: var(--font-label);
  font-size: var(--label-size);
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 3px;
  text-transform: uppercase;
  background: var(--bg-panel);
  padding: 0 6px;
  transform: translateY(-50%);
  z-index: 1;
  pointer-events: none;
}

/* --- Editor Panel (Left column, ~60%) --- */
#editor-panel {
  flex: 6;
  display: flex;
  flex-direction: column;
  border-left: none;
  border-top: none;
}

.editor-wrapper {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Line numbers gutter */
.line-numbers {
  width: 48px;
  padding: 12px 8px 12px 0;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted);
  text-align: right;
  background: var(--bg-deep);
  border-right: 1px solid var(--border);
  overflow: hidden;
  user-select: none;
  flex-shrink: 0;
  white-space: pre-line;
}

/* Editor textarea */
.editor-textarea {
  flex: 1;
  width: 100%;
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  color: var(--phosphor);
  background: var(--bg-deep);
  border: none;
  outline: none;
  resize: none;
  tab-size: 4;
  -moz-tab-size: 4;
  white-space: pre;
  overflow: auto;
  caret-color: var(--phosphor);
}

.editor-textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

.editor-textarea::selection {
  background: rgba(0, 255, 159, 0.15);
  color: var(--phosphor);
}

.editor-textarea::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.editor-textarea::-webkit-scrollbar-track {
  background: var(--bg-deep);
}

.editor-textarea::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.editor-textarea::-webkit-scrollbar-thumb:hover {
  background: var(--border-bright);
}

/* --- Right Column (~40%) --- */
#right-column {
  flex: 4;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-top: none;
}

/* --- Registers Panel --- */
#registers-panel {
  border-top: none;
  border-right: none;
  padding: 16px var(--panel-pad) var(--panel-pad);
}

.registers-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.reg-row {
  display: flex;
  gap: 0;
}

.reg-cell {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 3px 8px;
  min-width: 0;
}

.reg-name {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  color: var(--text-dim);
  letter-spacing: 1px;
  margin-right: 4px;
  flex-shrink: 0;
}

.reg-value {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  color: var(--phosphor);
  letter-spacing: 1px;
}

.reg-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* Flags row */
.reg-flags-row {
  align-items: center;
  padding: 6px 8px 2px;
}

.flags-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 1px;
  margin-right: 12px;
}

.flag-indicators {
  display: flex;
  gap: 8px;
}

.flag-box {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  width: 28px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text-muted);
  background: var(--bg-deep);
  letter-spacing: 1px;
  transition: all 0.2s ease;
}

.flag-box.active {
  color: var(--phosphor);
  border-color: rgba(0, 255, 159, 0.4);
  background: rgba(0, 255, 159, 0.08);
  text-shadow: 0 0 6px var(--phosphor-glow);
  box-shadow: 0 0 6px rgba(0, 255, 159, 0.1);
}

/* --- Status Panel --- */
#status-panel {
  border-right: none;
  padding: 16px var(--panel-pad) var(--panel-pad);
}

.status-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.status-row {
  display: flex;
  align-items: center;
  padding: 3px 8px;
}

.status-name {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 1px;
  margin-right: 8px;
  min-width: 70px;
}

.status-value {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
}

/* State label colors */
.status-ready   { color: var(--phosphor); }
.status-running {
  color: var(--phosphor);
  text-shadow: 0 0 8px var(--phosphor-glow);
}
.status-halted  { color: var(--amber); text-shadow: 0 0 6px var(--amber-glow); }
.status-error   { color: var(--red); text-shadow: 0 0 6px var(--red-glow); }

/* --- Bottom Row (Memory + Terminal side by side) --- */
#bottom-row {
  display: flex;
  flex-shrink: 0;
}

/* --- Memory Panel --- */
#memory-panel {
  flex: 6;
  border-left: none;
  padding: 16px var(--panel-pad) var(--panel-pad);
}

/* --- Output Panel (Terminal + Display) --- */
#output-panel {
  flex: 4;
  border-left: 1px solid var(--border);
  border-right: none;
  border-top: 2px solid var(--border);
  padding: 16px var(--panel-pad) var(--panel-pad);
  display: flex;
  flex-direction: column;
}

.output-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

/* Hardware channel selector */
.output-tabs {
  display: flex;
}

.output-tab {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-dim);
  background: var(--bg-deep);
  border: 1px solid var(--border);
  padding: 4px 0;
  width: 90px;
  text-align: center;
  cursor: pointer;
  outline: none;
  user-select: none;
  transition: color 0.1s, border-color 0.1s, background 0.1s;
}

.output-tab {
  position: relative;
}

.output-tab:first-child {
  border-radius: 2px 0 0 2px;
}

.output-tab:last-child {
  margin-left: -1px;
  border-radius: 0 2px 2px 0;
}

.output-tab.active {
  z-index: 1;
}

.output-tab:hover:not(.active) {
  color: var(--text-label);
  border-color: var(--border-bright);
}

.output-tab.active {
  color: var(--phosphor);
  background: rgba(0, 255, 159, 0.06);
  border-color: rgba(0, 255, 159, 0.3);
  text-shadow: 0 0 6px var(--phosphor-glow);
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.4);
}


.output-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

/* Pane switching */
.output-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.output-pane {
  display: none;
  flex: 1;
  min-height: 0;
}

.output-pane.active {
  display: flex;
  flex-direction: column;
}

/* Display viewport inside output pane */
.display-viewport {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 2px;
  min-height: 120px;
  overflow: hidden;
}

#lem-canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.terminal-output {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  color: var(--phosphor);
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 8px 10px;
  white-space: pre-wrap;
  word-break: break-all;
  overflow-y: auto;
  min-height: 120px;
  text-shadow: 0 0 5px var(--phosphor-glow);
}

.terminal-output::-webkit-scrollbar {
  width: 6px;
}

.terminal-output::-webkit-scrollbar-track {
  background: var(--bg-deep);
}

.terminal-output::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.terminal-cursor {
  color: var(--phosphor);
  animation: cursor-blink 1s step-end infinite;
}

@keyframes cursor-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.memory-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

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

.mem-addr-input {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--phosphor);
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 4px 8px;
  width: 60px;
  text-align: center;
  text-transform: uppercase;
  outline: none;
  letter-spacing: 1px;
}

.mem-addr-input:focus {
  border-color: rgba(0, 255, 159, 0.3);
}

.mem-control-separator {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.memory-dump-wrapper {
  overflow-x: auto;
}

.memory-dump {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  color: var(--phosphor);
  white-space: pre;
  letter-spacing: 0.5px;
  margin: 0;
}

/* Memory dump header row */
.mem-header {
  color: var(--text-dim);
}

/* Memory address column */
.mem-addr {
  color: var(--text-dim);
}

/* Highlighted memory cells */
.mem-highlight-pc {
  background: rgba(0, 255, 159, 0.12);
  color: var(--phosphor);
  text-shadow: 0 0 6px var(--phosphor-glow);
  border-radius: 1px;
  padding: 0 1px;
}

.mem-highlight-sp {
  background: rgba(255, 179, 71, 0.12);
  color: var(--amber);
  text-shadow: 0 0 6px var(--amber-glow);
  border-radius: 1px;
  padding: 0 1px;
}

/* ASCII column in memory dump */
.mem-ascii {
  color: var(--text-dim);
  letter-spacing: 0;
}

/* --- Console Panel (very bottom) --- */
#console-panel {
  flex-shrink: 0;
  height: 140px;
  border-left: none;
  border-right: none;
  border-bottom: none;
  padding: 16px var(--panel-pad) var(--panel-pad);
}

.console-output {
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.6;
  height: 100px;
  overflow-y: auto;
  padding: 0 4px;
}

.console-output::-webkit-scrollbar {
  width: 6px;
}

.console-output::-webkit-scrollbar-track {
  background: var(--bg-panel);
}

.console-output::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* Console message types */
.console-info {
  color: var(--phosphor-dim);
  opacity: 0.7;
}

.console-error {
  color: var(--red);
  text-shadow: 0 0 4px var(--red-glow);
}

.console-warn {
  color: var(--amber);
}

.console-success {
  color: var(--phosphor);
}

/* --- CRT Glow on data values --- */
.data-value {
  text-shadow: 0 0 5px var(--phosphor-glow);
}

/* --- Register flash animation --- */
@keyframes register-flash {
  0% {
    color: var(--amber);
    text-shadow: 0 0 8px var(--amber-glow);
  }
  100% {
    color: var(--phosphor);
    text-shadow: 0 0 5px var(--phosphor-glow);
  }
}

.register-changed {
  animation: register-flash 0.4s ease-out;
}

/* --- Subtle pulse for running state indicator --- */
@keyframes running-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.status-running {
  animation: running-pulse 1.2s ease-in-out infinite;
}

/* --- Scrollbar styling (global) --- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-deep);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-bright);
}

::-webkit-scrollbar-corner {
  background: var(--bg-deep);
}

/* --- Selection --- */
::selection {
  background: rgba(0, 255, 159, 0.15);
  color: var(--phosphor);
}

/* --- Focus visible outlines (accessibility) --- */
:focus-visible {
  outline: 1px solid rgba(0, 255, 159, 0.3);
  outline-offset: 1px;
}

/* --- Responsive / min-width --- */
@media (max-width: 1100px) {
  .title-sub,
  .title-right {
    display: none;
  }

  .toolbar-examples {
    display: none;
  }
}

@media (max-width: 900px) {
  #workspace {
    flex-direction: column;
  }

  #editor-panel {
    flex: none;
    height: 40vh;
    border-right: none;
  }

  #right-column {
    flex: none;
    flex-direction: row;
    border-left: none;
  }

  #registers-panel,
  #status-panel {
    flex: 1;
    border-right: none;
  }

  #status-panel {
    border-left: 1px solid var(--border);
  }

  .reg-cell {
    padding: 2px 4px;
  }

  .reg-value {
    font-size: 12px;
  }

  #bottom-row {
    flex-direction: column;
  }

  #output-panel {
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .display-viewport {
    min-height: 160px;
    max-height: 260px;
  }
}

@media (max-width: 600px) {
  #toolbar {
    flex-wrap: wrap;
    height: auto;
    padding: 8px 12px;
    gap: 8px;
  }

  .toolbar-speed {
    order: 2;
  }

  .btn {
    padding: 5px 10px;
    font-size: 10px;
  }

  #right-column {
    flex-direction: column;
  }

  #status-panel {
    border-left: none;
    border-top: 1px solid var(--border);
  }
}
