/* =============================================
   UTU-VM — Virtual Computer
   Matches Time Machine aesthetic
   ============================================= */

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

:root {
  --bg:             #0a0a0c;
  --bg-warm:        #0e0e10;
  --surface:        #151518;
  --surface-hover:  #1a1a1e;
  --surface-raised: #1f1f24;
  --border:         #252528;
  --border-light:   #333338;

  --text:           #e8e4dd;
  --text-secondary: #a09a8f;
  --text-dim:       #5a5854;

  --neon:     #39FF14;
  --neon-dim: rgba(57, 255, 20, 0.08);
  --amber:    #e8a84c;
  --blue:     #6aadf0;
  --green:    #6bc98a;
  --red:      #d96b6b;
  --purple:   #d4a0e8;
  --teal:     #6bcac9;

  --radius:    6px;
  --radius-sm: 4px;

  --font-body:  'Outfit', -apple-system, sans-serif;
  --font-mono:  'JetBrains Mono', 'SF Mono', monospace;
}

/* ---- grain ---- */

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.02;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 200px;
}

/* ---- base ---- */

html { background: var(--bg); }

body {
  background: var(--bg-warm);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 400;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: rgba(57, 255, 20, 0.25);
  color: var(--text);
}

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 10px; }

/* ---- header ---- */

header {
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.logo-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--neon);
  box-shadow: 0 0 8px var(--neon), 0 0 20px rgba(57, 255, 20, 0.3);
  animation: pulse-glow 3s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 8px var(--neon), 0 0 20px rgba(57, 255, 20, 0.3); }
  50% { box-shadow: 0 0 12px var(--neon), 0 0 30px rgba(57, 255, 20, 0.5); }
}

.logo-text {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.5px;
}

.logo-accent {
  color: var(--neon);
  font-weight: 400;
}

.clock-bar {
  display: flex;
  gap: 24px;
  margin-left: auto;
}

.clock-item {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.clock-label {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.clock-value {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
}

.clock-value.neon {
  color: var(--neon);
  text-shadow: 0 0 8px rgba(57, 255, 20, 0.4);
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 16px;
  border-left: 1px solid var(--border);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: all 0.3s;
}

.status-dot.running {
  background: var(--neon);
  box-shadow: 0 0 6px var(--neon);
  animation: pulse-glow 1s ease-in-out infinite;
}

.status-dot.halted {
  background: var(--red);
  box-shadow: 0 0 6px var(--red);
}

.status-dot.ready {
  background: var(--amber);
}

.status-text {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}

/* ---- main layout ---- */

main {
  display: grid;
  grid-template-columns: 280px 1fr 280px;
  gap: 1px;
  height: calc(100vh - 61px);
  background: var(--border);
}

/* ---- panels ---- */

.panel {
  background: var(--bg-warm);
  padding: 16px;
  overflow-y: auto;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel-header h2 {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 2px;
  text-transform: uppercase;
}

.panel-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  background: var(--surface);
  padding: 2px 8px;
  border-radius: 3px;
}

/* ---- memory grid ---- */

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

.mem-cell {
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 4px 2px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  position: relative;
  transition: all 0.15s;
  cursor: default;
}

.mem-cell .mem-addr {
  display: block;
  font-size: 8px;
  color: var(--text-dim);
  margin-bottom: 1px;
}

.mem-cell .mem-val {
  display: block;
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
}

.mem-cell.active {
  border-color: var(--neon);
  background: rgba(57, 255, 20, 0.06);
  box-shadow: 0 0 8px rgba(57, 255, 20, 0.15);
}

.mem-cell.active .mem-val {
  color: var(--neon);
}

.mem-cell.operand {
  border-color: var(--amber);
  background: rgba(232, 168, 76, 0.06);
}

.mem-cell.operand .mem-val {
  color: var(--amber);
}

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

@keyframes cell-flash {
  0% { background: rgba(57, 255, 20, 0.2); }
  100% { background: var(--surface); }
}

.mem-cell.is-opcode .mem-val {
  color: var(--blue);
}

/* ---- CPU panel ---- */

.cpu-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.register-bank {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.register {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  text-align: center;
}

.reg-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 1.5px;
  margin-bottom: 4px;
}

.reg-value {
  display: block;
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--neon);
  text-shadow: 0 0 6px rgba(57, 255, 20, 0.3);
}

/* ---- decoder ---- */

.decoder {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}

.decoder-label {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 1.5px;
  margin-bottom: 6px;
}

.decoder-display {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 600;
  display: flex;
  gap: 12px;
  align-items: baseline;
}

.decoder-opcode {
  color: var(--blue);
}

.decoder-operand {
  color: var(--amber);
  font-size: 18px;
}

.decoder-desc {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ---- controls ---- */

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1px;
  padding: 8px 20px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}

.btn:hover {
  background: var(--surface-hover);
  border-color: var(--text-dim);
}

.btn-step {
  border-color: var(--neon);
  color: var(--neon);
}

.btn-step:hover {
  background: rgba(57, 255, 20, 0.08);
}

.btn-run {
  border-color: var(--green);
  color: var(--green);
}

.btn-run:hover {
  background: rgba(107, 201, 138, 0.08);
}

.btn-run.running {
  border-color: var(--amber);
  color: var(--amber);
}

.btn-run.running:hover {
  background: rgba(232, 168, 76, 0.08);
}

.btn-reset {
  border-color: var(--red);
  color: var(--red);
}

.btn-reset:hover {
  background: rgba(217, 107, 107, 0.08);
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 1px;
}

.speed-control input[type="range"] {
  -webkit-appearance: none;
  width: 100px;
  height: 4px;
  background: var(--border-light);
  border-radius: 2px;
  outline: none;
}

.speed-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--neon);
  cursor: pointer;
  box-shadow: 0 0 4px rgba(57, 255, 20, 0.4);
}

#speed-value {
  min-width: 24px;
  text-align: right;
  color: var(--text-secondary);
}

/* ---- output ---- */

.output-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.output-panel .panel-header {
  margin-bottom: 8px;
}

.btn-clear {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  background: none;
  border: none;
  cursor: pointer;
  letter-spacing: 0.5px;
}

.btn-clear:hover {
  color: var(--text-secondary);
}

.output-log {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-secondary);
  overflow-y: auto;
  min-height: 120px;
}

.output-line {
  display: block;
}

.output-line .out-cycle {
  color: var(--text-dim);
  margin-right: 8px;
}

.output-line .out-val {
  color: var(--neon);
}

.output-line.out-info {
  color: var(--text-dim);
  font-style: italic;
}

.output-line.out-error {
  color: var(--red);
}

.output-line.out-input {
  color: var(--amber);
}

/* ---- program panel ---- */

.program-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.program-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  cursor: pointer;
  transition: all 0.15s;
}

.program-item:hover {
  border-color: var(--neon);
  background: var(--neon-dim);
}

.program-item.selected {
  border-color: var(--neon);
}

.program-item .prog-name {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 2px;
}

.program-item .prog-desc {
  font-size: 11px;
  color: var(--text-dim);
}

.program-editor {
  width: 100%;
  min-height: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
  resize: vertical;
  outline: none;
}

.program-editor:focus {
  border-color: var(--neon);
}

.program-editor::placeholder {
  color: var(--text-dim);
}

.btn-small {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  padding: 3px 10px;
  border: 1px solid var(--neon);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--neon);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-small:hover {
  background: var(--neon-dim);
}

/* ---- call stack ---- */

.stack-display {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  min-height: 40px;
}

.stack-display .empty-hint {
  color: var(--text-dim);
  font-size: 11px;
}

.stack-entry {
  color: var(--purple);
  padding: 2px 0;
}

.stack-entry::before {
  content: '→ ';
  color: var(--text-dim);
}

/* ---- guide button ---- */

.btn-guide {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border-light);
  background: var(--surface);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
  margin-left: 12px;
}

.btn-guide:hover {
  border-color: var(--neon);
  color: var(--neon);
  background: var(--neon-dim);
}

/* ---- guide overlay ---- */

.guide-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(12px);
  z-index: 1000;
  overflow-y: auto;
  padding: 40px 20px;
}

.guide-overlay.open {
  display: block;
}

.guide-modal {
  max-width: 720px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 40px;
  position: relative;
}

.guide-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 28px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.guide-close:hover {
  color: var(--text);
}

.guide-modal h1 {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 600;
  color: var(--neon);
  margin-bottom: 24px;
  letter-spacing: -0.5px;
}

.guide-modal h2 {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-top: 24px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.guide-modal p {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 8px;
}

.guide-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 8px 0;
}

.guide-card {
  background: var(--bg-warm);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.guide-card h3 {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.guide-card p {
  font-size: 12px;
  margin-bottom: 0;
}

.g-green { color: var(--neon); }
.g-amber { color: var(--amber); }
.g-dim { color: var(--text-dim); font-size: 11px; }

.guide-modal table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
}

.guide-modal td {
  padding: 6px 10px;
  font-size: 13px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

.guide-modal td:first-child {
  font-family: var(--font-mono);
  white-space: nowrap;
  width: 200px;
}

.guide-modal ol {
  padding-left: 20px;
  margin: 8px 0;
}

.guide-modal li {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 4px;
}

.guide-modal pre {
  background: var(--bg-warm);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.7;
  overflow-x: auto;
  margin: 8px 0;
}

.guide-modal code {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--neon);
  background: var(--neon-dim);
  padding: 1px 5px;
  border-radius: 3px;
}

.guide-footer {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.guide-footer p {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 2px;
}

/* ---- responsive ---- */

@media (max-width: 900px) {
  main {
    grid-template-columns: 1fr;
    height: auto;
  }

  .memory-grid {
    grid-template-columns: repeat(8, 1fr);
  }

  .register-bank {
    grid-template-columns: repeat(2, 1fr);
  }
}
