:root {
  --bg: oklch(14% 0.012 255);
  --surface: oklch(17% 0.014 255);
  --surface-raised: oklch(21% 0.016 255);
  --text: oklch(94% 0.01 255);
  --muted: oklch(68% 0.02 255);
  --subtle: oklch(60% 0.02 255); /* AA on --bg and --surface only; use --muted on raised/tinted grounds */
  --line: oklch(28% 0.015 255);
  --accent: oklch(70% 0.14 255);
  --accent-ink: oklch(18% 0.03 255);
  --wordmark-amber: oklch(76% 0.13 71.5); /* the favicon's #e5a34c — wordmark third line, nowhere else */
  --success: oklch(75% 0.14 150);
  --warning: oklch(78% 0.14 80);
  --danger: oklch(69% 0.16 20);
  --info: oklch(74% 0.12 255);
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --selection: oklch(28% 0.038 255);
  --pulse: oklch(75% 0.14 150 / 0.58);
  --radius-control: 6px;
  --radius-panel: 12px;
  color: var(--text);
  background: var(--bg);
  font-family: var(--sans);
  color-scheme: dark;
}

/* Viewer-only light theme (the landing never sets data-theme — dark is its identity).
   Not an inversion: every value below was re-tuned to clear WCAG AA on light ground. */
[data-theme="light"] {
  --bg: oklch(97% 0.005 255);
  --surface: oklch(94.5% 0.008 255);
  --surface-raised: oklch(91% 0.012 255);
  --text: oklch(21% 0.015 255);
  --muted: oklch(44% 0.02 255);
  --subtle: oklch(50% 0.02 255);
  --line: oklch(87% 0.01 255);
  --accent: oklch(48% 0.15 255);
  --accent-ink: oklch(98% 0.005 255);
  --success: oklch(49% 0.14 150);
  --warning: oklch(51% 0.11 80);
  --danger: oklch(53% 0.18 25);
  --info: oklch(51% 0.12 255);
  --selection: oklch(88.5% 0.035 255);
  --pulse: oklch(49% 0.14 150 / 0.45);
  color-scheme: light;
}

/* ANSI re-tuned for light ground — "bright" reads as more intense, so brights go
   darker and more saturated than normals; all hold ≥4.5:1 on the light bg. */
[data-theme="light"] .fg-black { color: oklch(25% 0.02 255); }
[data-theme="light"] .fg-red { color: oklch(55% 0.19 25); }
[data-theme="light"] .fg-green { color: oklch(51% 0.14 150); }
[data-theme="light"] .fg-yellow { color: oklch(52% 0.12 85); }
[data-theme="light"] .fg-blue { color: oklch(52% 0.14 255); }
[data-theme="light"] .fg-magenta { color: oklch(54% 0.16 315); }
[data-theme="light"] .fg-cyan { color: oklch(51% 0.11 210); }
[data-theme="light"] .fg-white { color: oklch(45% 0.015 255); }
[data-theme="light"] .fg-bright-black { color: oklch(40% 0.02 255); }
[data-theme="light"] .fg-bright-red { color: oklch(50% 0.2 25); }
[data-theme="light"] .fg-bright-green { color: oklch(46% 0.15 150); }
[data-theme="light"] .fg-bright-yellow { color: oklch(47% 0.13 85); }
[data-theme="light"] .fg-bright-blue { color: oklch(47% 0.15 255); }
[data-theme="light"] .fg-bright-magenta { color: oklch(49% 0.17 315); }
[data-theme="light"] .fg-bright-cyan { color: oklch(46% 0.12 210); }
[data-theme="light"] .fg-bright-white { color: oklch(12% 0.01 255); }

* { box-sizing: border-box; }

html,
body { min-height: 100%; margin: 0; background: var(--bg); }

button,
input { font: inherit; }

button { cursor: pointer; }

a { color: inherit; text-decoration: none; }

a:focus-visible,
button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.wordmark {
  color: var(--text);
  font: 800 1rem/1 var(--mono);
  letter-spacing: -0.08em;
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
}

.wordmark span { color: var(--accent); }

.marklines {
  display: inline-flex;
  flex-direction: column;
  gap: 3px;
  width: 18px;
}

.marklines i { height: 3px; border-radius: 2px; background: var(--muted); }
.marklines i:nth-child(1) { opacity: 0.45; }
.marklines i:nth-child(2) { opacity: 0.75; width: 80%; }
.marklines i:nth-child(3) { background: var(--wordmark-amber); opacity: 1; }

/* Landing page */

.site-body { display: flex; flex-direction: column; min-height: 100vh; }

.site-header,
.site-footer {
  display: flex;
  align-items: center;
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
}

.site-header {
  justify-content: space-between;
  min-height: 76px;
  border-bottom: 1px solid var(--line);
}

.site-header nav { display: flex; gap: 24px; }

.site-header nav a {
  color: var(--muted);
  font: 600 0.75rem/1 var(--mono);
}

.site-header nav a:hover { color: var(--text); }

.landing-shell {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
}

.landing-hero {
  display: grid;
  grid-template-columns: minmax(300px, 0.88fr) minmax(430px, 1.12fr);
  gap: clamp(36px, 6vw, 88px);
  align-items: center;
  padding: clamp(72px, 10vw, 136px) 0;
}

.hero-copy { max-width: 540px; }

.hero-copy h1 {
  max-width: 10ch;
  margin: 0;
  color: var(--text);
  font: 760 clamp(3.25rem, 6.2vw, 5.8rem)/0.94 var(--sans);
  letter-spacing: -0.04em;
  text-wrap: balance;
}

.hero-lede {
  max-width: 43ch;
  margin: 24px 0 30px;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.65;
  text-wrap: pretty;
}

.command-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  padding: 8px 8px 8px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--surface);
}

.command-block code {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font: 500 0.78rem/1.4 var(--mono);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.command-prompt { color: var(--accent); }

.command-block button {
  flex: none;
  min-height: 38px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-control);
  background: var(--accent);
  color: var(--accent-ink);
  font: 750 0.7rem/1 var(--mono);
  white-space: nowrap;
  transition: filter 160ms ease-out, transform 160ms ease-out;
}

.command-block button:hover { filter: brightness(1.08); }

.command-block button:active { transform: translateY(1px); }

.hero-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  padding: 0;
  margin: 20px 0 0;
  color: var(--muted);
  font: 600 0.68rem/1.4 var(--mono);
  list-style: none;
}

.hero-facts li + li::before { content: "·"; margin-right: 18px; color: var(--accent); }

.landing-preview {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--surface);
}

.preview-toolbar,
.preview-footer {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 46px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font: 600 0.68rem/1 var(--mono);
}

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

.preview-status { display: inline-flex; align-items: center; gap: 6px; color: var(--success); }

.preview-status span,
.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.preview-id { margin-left: auto; color: var(--subtle); }

.preview-lines { min-height: 286px; padding: 16px; font: 500 0.74rem/1.72 var(--mono); }

.preview-lines p { display: grid; grid-template-columns: 34px minmax(0, 1fr); margin: 0; white-space: nowrap; }
.preview-lines p > span { padding-right: 12px; color: var(--subtle); text-align: right; user-select: none; }
.preview-lines code { overflow: hidden; text-overflow: ellipsis; }

.ansi-green { color: var(--success); }
.ansi-yellow { color: var(--warning); }
.ansi-red { color: var(--danger); }
.ansi-blue { color: var(--info); }

.preview-footer { min-height: 38px; border-top: 1px solid var(--line); border-bottom: 0; font-size: 0.62rem; }
.preview-footer span:last-child { margin-left: auto; }

.workflow,
.terminal-note {
  display: grid;
  grid-template-columns: minmax(270px, 0.72fr) minmax(420px, 1.28fr);
  gap: clamp(36px, 6vw, 88px);
  padding: 72px 0;
  border-top: 1px solid var(--line);
}

.workflow h2,
.terminal-note h2 {
  max-width: 13ch;
  margin: 0 0 14px;
  font: 700 clamp(1.8rem, 3vw, 2.8rem)/1.02 var(--sans);
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.workflow p,
.terminal-note p { max-width: 40ch; margin: 0; color: var(--muted); font-size: 0.95rem; line-height: 1.65; }

/* The agent prompt must be readable, not just copyable — let it wrap. */
#agent-skill-prompt { white-space: normal; overflow-wrap: anywhere; }

.agent-skill-link { margin-top: 14px !important; }
.agent-skill-link a { color: var(--accent); font: 700 0.74rem/1.4 var(--mono); }
.agent-skill-link a:hover { color: var(--text); }

.workflow ol { display: grid; gap: 0; padding: 0; margin: 0; list-style: none; }

.workflow li {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr);
  gap: 20px;
  align-items: baseline;
  padding: 20px 0;
  border-top: 1px solid var(--line);
}

.workflow li:last-child { border-bottom: 1px solid var(--line); }
.workflow strong { color: var(--accent); font: 750 0.76rem/1 var(--mono); }
.workflow span { color: var(--text); font-size: 0.94rem; }

.terminal-note { align-items: center; }

.terminal-note code {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--surface);
  color: var(--text);
  font: 500 0.84rem/1.6 var(--mono);
  overflow-wrap: anywhere;
}

.site-footer {
  justify-content: space-between;
  gap: 24px;
  min-height: 86px;
  margin-top: auto;
  border-top: 1px solid var(--line);
  color: var(--muted); /* "never pipe secrets" must be readable — AA at 0.67rem */
  font: 500 0.67rem/1.5 var(--mono);
}

/* Viewer */

/* dvh keeps the footer visible under mobile browser toolbars; vh is the fallback. */
.viewer-body { height: 100vh; height: 100dvh; overflow: hidden; }

.viewer-shell { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100vh; height: 100dvh; }

.viewer-toolbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto auto;
  gap: 16px;
  align-items: center;
  min-height: 68px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.viewer-wordmark { font-size: 0.9rem; }

.stream-heading { min-width: 0; }
.stream-id { overflow: hidden; margin: 0; color: var(--text); font: 650 0.78rem/1.2 var(--mono); text-overflow: ellipsis; white-space: nowrap; }
.stream-detail { margin: 4px 0 0; color: var(--muted); font: 500 0.65rem/1.2 var(--mono); }

.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: var(--muted);
  font: 750 0.68rem/1 var(--mono);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.connection-status[data-state="live"] { color: var(--success); }
.connection-status[data-state="waiting"] { color: var(--accent); }
.connection-status[data-state="ended"] { color: var(--muted); }
.connection-status[data-state="disconnected"] { color: var(--warning); }
.connection-status[data-state="error"] { color: var(--danger); }
.connection-status[data-state="live"] .status-dot { animation: live-pulse 1.8s ease-out infinite; }

@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 var(--pulse); }
  70% { box-shadow: 0 0 0 6px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.toolbar-button {
  min-width: 82px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--text);
  font: 650 0.68rem/1 var(--mono);
  white-space: nowrap;
  transition: border-color 160ms ease-out, background 160ms ease-out;
}

.toolbar-button:hover { border-color: var(--accent); background: var(--surface-raised); }
.toolbar-button:active { background: var(--line); }
.toolbar-button:disabled { opacity: 0.45; cursor: not-allowed; }
.toolbar-button:disabled:hover { border-color: var(--line); background: transparent; }

.viewer-stage { position: relative; min-height: 0; }

.log-output {
  height: 100%;
  overflow: auto;
  padding: 16px 34px 48px 16px;
  font: 500 0.8rem/1.65 var(--mono);
  scrollbar-color: var(--line) var(--bg);
}

.empty-state { max-width: 42ch; padding: 12px 24px; color: var(--muted); }
.empty-title { margin: 0 0 6px; color: var(--text); font: 650 0.84rem/1.35 var(--mono); }
.empty-state p:last-child { margin: 0; font-size: 0.76rem; line-height: 1.6; }

.line {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  min-height: 1.65em;
  border-radius: 2px;
  content-visibility: auto;
  contain-intrinsic-size: auto 1.65em;
  white-space: pre-wrap;
  word-break: break-word;
}

.line:hover { background: var(--surface); }
.line.is-selected { background: var(--selection); }
.line.is-error .line-number::after { content: "!"; color: var(--danger); }
.line.is-warning .line-number::after { content: "~"; color: var(--warning); }

.line-number {
  display: inline-grid;
  grid-template-columns: minmax(3.5ch, auto) 1ch;
  gap: 6px;
  align-items: start;
  min-height: 1.65em;
  padding: 0 10px 0 0;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--subtle);
  font: inherit;
  text-align: right;
}

.line.is-selected .line-number { color: var(--muted); } /* --subtle misses 4.5:1 on the selection tint in both themes */
.line-number:hover,
.line.is-selected .line-number:hover { color: var(--accent); }
.line-content { min-width: 0; padding-left: 12px; }

.bold { font-weight: 700; }
.dim { opacity: 0.62; }
.italic { font-style: italic; }
.underline { text-decoration: underline; }

.fg-black { color: oklch(47% 0.02 255); }
.fg-red { color: oklch(72% 0.16 20); }
.fg-green { color: oklch(78% 0.14 150); }
.fg-yellow { color: oklch(80% 0.14 80); }
.fg-blue { color: oklch(74% 0.12 255); }
.fg-magenta { color: oklch(75% 0.12 315); }
.fg-cyan { color: oklch(78% 0.11 210); }
.fg-white { color: oklch(89% 0.02 255); }
.fg-bright-black { color: oklch(62% 0.02 255); }
.fg-bright-red { color: oklch(78% 0.16 20); }
.fg-bright-green { color: oklch(83% 0.14 150); }
.fg-bright-yellow { color: oklch(86% 0.14 80); }
.fg-bright-blue { color: oklch(81% 0.12 255); }
.fg-bright-magenta { color: oklch(82% 0.12 315); }
.fg-bright-cyan { color: oklch(85% 0.11 210); }
.fg-bright-white { color: #fff; }

.minimap {
  position: absolute;
  top: 12px;
  right: 8px;
  width: 12px;
  height: calc(100% - 24px);
  cursor: pointer;
}

.viewer-footer {
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 38px;
  padding: 0 20px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font: 500 0.63rem/1 var(--mono);
}

.viewer-footer span:last-child { margin-left: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.follow-button {
  position: fixed;
  z-index: 2;
  right: 32px;
  bottom: 62px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font: 750 0.7rem/1 var(--mono);
}

.follow-button:hover { filter: brightness(1.08); }

@media (max-width: 860px) {
  .landing-hero,
  .workflow,
  .terminal-note { grid-template-columns: 1fr; }

  .landing-hero { gap: 44px; padding-block: 72px; }
  .hero-copy { max-width: 660px; }
  .hero-copy h1 { max-width: 12ch; }
  .landing-preview { max-width: 720px; }
}

@media (max-width: 640px) {
  .site-header,
  .site-footer,
  .landing-shell { width: min(100% - 32px, 1180px); }
  .site-header { min-height: 64px; }
  .site-header nav { gap: 14px; }
  .site-header nav a { font-size: 0.64rem; }
  .hero-copy h1 { font-size: clamp(3rem, 16vw, 4.35rem); }
  .command-block { align-items: stretch; flex-direction: column; padding: 12px; }
  .command-block code { white-space: normal; overflow-wrap: anywhere; }
  .command-block button { min-height: 44px; }
  .hero-facts { gap: 6px 10px; }
  .hero-facts li + li::before { margin-right: 10px; }
  .preview-lines { min-height: 232px; padding: 12px; font-size: 0.66rem; }
  .workflow,
  .terminal-note { padding-block: 56px; gap: 28px; }
  .workflow li { grid-template-columns: 82px minmax(0, 1fr); gap: 12px; }
  .site-footer { align-items: flex-start; flex-direction: column; justify-content: center; min-height: 112px; }

  .viewer-toolbar { grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 10px; min-height: 64px; padding: 0 12px; }
  .viewer-wordmark { font-size: 0.76rem; }
  .connection-status { grid-column: 2 / 3; font-size: 0.58rem; }
  .toolbar-button { min-width: 44px; min-height: 44px; padding: 0 8px; font-size: 0.58rem; }
  .stream-detail { display: none; }
  /* 0.75rem × 2.0 line-height = 24px rows — WCAG 2.5.8 target-size floor for the gutter buttons */
  .log-output { padding: 12px 28px 32px 8px; font-size: 0.75rem; line-height: 2; }
  .line { min-height: 2em; contain-intrinsic-size: auto 2em; }
  .line-number { padding-right: 6px; min-height: 2em; }
  .line-content { padding-left: 8px; }
  .viewer-footer { gap: 10px; padding: 0 12px; font-size: 0.56rem; }
  .viewer-footer span:nth-child(2) { display: none; }
  .follow-button { right: 16px; bottom: 54px; min-height: 44px; }
  .minimap { right: 4px; width: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
