:root {
  --bg: #14110d;
  --fg: #faf9f5;
  --accent: #d97757;
  --muted: #8a8070;
  --panel: #1e1a14;
  --panel-border: #2d261d;
  --dim: #5a5247;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Helvetica Neue", Arial, sans-serif;
  font-size: 18px;
  line-height: 1.5;
  min-height: 100vh;
}

.page {
  max-width: 920px;
  margin: 0 auto;
  padding: 64px 32px 96px;
}

.brand {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-weight: 700;
  color: var(--accent);
  font-size: 64px;
  letter-spacing: 0.04em;
  line-height: 1;
}

h1 {
  font-size: 36px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 24px 0 8px;
}

.subtitle {
  color: var(--muted);
  font-size: 16px;
  letter-spacing: 0.04em;
  margin-bottom: 32px;
}

.controls {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

button.run {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 16px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 10px 18px;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}
button.run:hover:not(:disabled) {
  background: var(--accent);
  color: var(--bg);
}
button.run:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.status {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 8px;
  min-height: 1.5em;
}

/* The terminal-wrapper anchors the absolutely-positioned #cursor span to
   the same coordinate space as pre.output's content area. */
.terminal-wrapper {
  position: relative;
  margin: 0 0 32px;
}

pre.output {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  color: var(--fg);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 15px;
  /* Tighter line-height (1.2) matches typical terminal-emulator spacing
     (macOS Terminal ≈ 1.2, iTerm default 1.0–1.2). Was 1.55 (web-page
     prose default), which felt double-spaced for shell output. The
     cursor span and demo.js's render() use the same value so the
     overlay sits exactly on the rendered glyph rows. */
  line-height: 1.2;
  padding: 20px 24px;
  /* 24 rows × 15px × 1.2 line-height ≈ 432px content; +40px padding ≈ 472px.
     min-height (not height) so the ANSI 24-row buffer is always fully visible
     without forcing a scrollbar; overflow stays auto in case any future
     program emits more than 24 rows. */
  min-height: 480px;
  overflow: auto;
  margin: 0;
  /* The ANSI interpreter renders a fixed 80×24 grid as a single text string
     with hard \n at row boundaries — let the browser render it as-is, no
     re-wrapping. Horizontal scroll appears at narrow viewports. */
  white-space: pre;
}

/* Blinking block cursor positioned over the terminal at (row, col).
   demo.js sets inline `top` / `left` on every render based on the ANSI
   state. 1ch = width of '0' in the current monospace font; 1.2em
   matches pre.output's line-height. The (20px, 24px) padding offsets
   in JS match pre.output's padding above. */
#cursor {
  position: absolute;
  width: 1ch;
  height: 1.2em;
  background: var(--accent);
  opacity: 0.7;
  pointer-events: none;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 15px;
  line-height: 1.2;
  animation: cursor-blink 1s steps(2, jump-none) infinite;
}
#cursor.hidden {
  display: none;
}
@keyframes cursor-blink {
  0%, 50%      { opacity: 0.7; }
  50.01%, 100% { opacity: 0; }
}
pre.output .stderr { color: var(--muted); }
pre.output .meta   { color: var(--dim); }

.explain {
  color: var(--muted);
  font-size: 15px;
  margin-bottom: 32px;
}
.explain code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--fg);
  background: var(--panel);
  padding: 1px 6px;
  border-radius: 4px;
}

.footer-links {
  display: flex;
  gap: 24px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 14px;
}
.footer-links a {
  color: var(--accent);
  text-decoration: none;
}
.footer-links a:hover { color: var(--fg); }

/* ----- trace block (auto-shown after halt for trace-enabled programs) ----- */

.trace-details {
  margin: 0 0 32px;
}
.trace-details summary {
  cursor: pointer;
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 14px;
  padding: 6px 0;
  list-style: none;
}
.trace-details summary::-webkit-details-marker { display: none; }
.trace-details summary::before {
  content: "▸ ";
  color: var(--accent);
}
.trace-details[open] summary::before { content: "▾ "; }
.trace-details summary:hover { color: var(--fg); }
.trace-details .trace-meta {
  color: var(--dim);
  margin-left: 6px;
}

pre.trace {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.4;
  padding: 16px 20px;
  height: 480px;
  overflow: auto;
  margin: 8px 0 0;
  white-space: pre;
}

/* ----- terminal prompt + typed command (inside pre.output) ----- */

pre.output .prompt { color: var(--accent); font-weight: 600; }
pre.output .cmd    { color: var(--fg); }

/* ----- program selector + focusable terminal ----- */

.program-selector {
  margin-bottom: 0.5rem;
  font-family: var(--mono, monospace);
  color: var(--ink, #cccccc);
}
.program-selector select {
  background: transparent;
  color: inherit;
  border: 1px solid currentColor;
  padding: 0.1rem 0.3rem;
  font-family: inherit;
  font-size: inherit;
}
.program-hint {
  margin-left: 0.5rem;
  opacity: 0.6;
}
#output {
  outline: none;
  cursor: text;
}
#output:focus {
  outline: 2px solid var(--accent, #66ff99);
  outline-offset: 2px;
}
.program-hint.hidden {
  display: none;
}

.program-instructions {
  margin: 0 0 16px;
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.6;
}
.program-instructions.hidden {
  display: none;
}
.program-instructions strong {
  color: var(--accent);
  font-weight: 600;
  margin-right: 6px;
}
.program-instructions code {
  color: var(--fg);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--panel-border);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 13px;
}
.program-instructions a {
  color: var(--accent);
  text-decoration: none;
}
.program-instructions a:hover {
  color: var(--fg);
  text-decoration: underline;
}
.program-instructions .link-icon {
  width: 13px;
  height: 13px;
  vertical-align: -2px;
  margin-right: 2px;
}
.device-warning {
  margin-top: 8px;
  color: var(--accent);
}
