/* ==========================================================================
   agent-flow — "Calm Console" design language
   Tokens below are reused verbatim from the companion portfolio site this
   project pairs with. Quiet, restrained, instrument-panel aesthetic:
   thin hairlines, muted semantic color, no gradients/glow/bounce.
   ========================================================================== */

:root {
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --bg: #fafafa; --bg-2: #f4f5f7; --surface: #ffffff; --surface-2: #f5f5f5;
  --border: #ebebeb; --border-strong: #e0e0e0; --line: #f0f0f0;
  --text: #111111; --text-2: #404040; --text-3: #737373; --text-4: #a3a3a3;
  --accent: #2563eb; --accent-hover: #1d4ed8; --accent-subtle: #dbeafe; --accent-ghost: rgba(37,99,235,0.08);
  --green: #16a34a; --green-subtle: #f0fdf4;
  --amber: #b45309; --amber-subtle: #fef8ec;
  --red: #dc2626; --red-subtle: #fef2f2;
  --radius: 5px; --radius-sm: 3px; --radius-lg: 9px;
  --shadow-sm: 0 1px 2px rgba(17,17,17,0.04), 0 2px 6px rgba(17,17,17,0.05);

  /* spacing scale — not part of the shared token set, defined locally for
     internal rhythm/consistency across this app's own layout */
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px;

  --t-fast: 150ms ease-out;
  --t-med: 220ms ease-out;
}

html[data-theme="dark"] {
  --bg: #0c0d10; --bg-2: #0e0f13; --surface: #15161b; --surface-2: #1a1c22;
  --border: #262932; --border-strong: #333743; --line: #20232b;
  --text: #f2f3f5; --text-2: #c3c7d0; --text-3: #9297a3; --text-4: #666b77;
  --accent: #6191ff; --accent-hover: #83a8ff; --accent-subtle: rgba(97,145,255,0.16); --accent-ghost: rgba(97,145,255,0.1);
  --green: #4ade80; --green-subtle: rgba(74,222,128,0.12);
  --amber: #fbbf24; --amber-subtle: rgba(251,191,36,0.12);
  --red: #f87171; --red-subtle: rgba(248,113,113,0.12);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
}

/* Respect prefers-color-scheme by default when the user hasn't overridden
   via the toggle (inline boot script sets data-theme before first paint;
   this block only matters if JS is unavailable). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0d10; --bg-2: #0e0f13; --surface: #15161b; --surface-2: #1a1c22;
    --border: #262932; --border-strong: #333743; --line: #20232b;
    --text: #f2f3f5; --text-2: #c3c7d0; --text-3: #9297a3; --text-4: #666b77;
    --accent: #6191ff; --accent-hover: #83a8ff; --accent-subtle: rgba(97,145,255,0.16); --accent-ghost: rgba(97,145,255,0.1);
    --green: #4ade80; --green-subtle: rgba(74,222,128,0.12);
    --amber: #fbbf24; --amber-subtle: rgba(251,191,36,0.12);
    --red: #f87171; --red-subtle: rgba(248,113,113,0.12);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  }
}

/* ==========================================================================
   Reset + base
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background var(--t-med), color var(--t-med);
}
h1, h2, h3, p, ol, ul { margin: 0; }
button, select, input { font-family: inherit; color: inherit; }
button { cursor: pointer; }

/* The `hidden` attribute must always win over component display classes —
   without this, any ".foo[hidden]" element where .foo sets its own
   `display` ties the UA [hidden] rule on specificity and (being
   author-origin) beats it, silently un-hiding the element. */
[hidden] { display: none !important; }
svg { display: block; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ==========================================================================
   Topbar
   ========================================================================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-6);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.topbar__brand { display: flex; align-items: baseline; gap: var(--space-2); }
.topbar__mark { color: var(--accent); flex-shrink: 0; align-self: center; }
.topbar__name {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
  color: var(--text);
}
.topbar__tagline {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-4);
}

.topbar__controls { display: flex; align-items: center; gap: var(--space-3); min-width: 0; flex-shrink: 1; }

.scenario-picker { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.scenario-picker__label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-4);
  flex-shrink: 0;
}
.scenario-picker__select {
  appearance: none; -webkit-appearance: none;
  background-color: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23737373' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 6px 26px 6px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  width: 100%;
  min-width: 0;
  max-width: 280px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition: border-color var(--t-fast);
}
@media (max-width: 640px) {
  .scenario-picker__select { max-width: 150px; }
  .topbar__tagline { display: none; }
}
.scenario-picker__select:hover { border-color: var(--text-4); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--text-4); color: var(--text); }
.icon-btn svg { width: 15px; height: 15px; }

.icon-moon { display: none; }
html[data-theme="dark"] .icon-sun { display: none; }
html[data-theme="dark"] .icon-moon { display: block; }

/* ==========================================================================
   Error banner
   ========================================================================== */

.error-banner {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin: var(--space-4) var(--space-6) 0;
  padding: var(--space-3) var(--space-4);
  background: var(--red-subtle);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  color: var(--red);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
}
.error-banner[hidden] { display: none; }
.error-banner strong { font-weight: 700; }

/* ==========================================================================
   Layout — the workflow player is a single centered column
   ========================================================================== */

.stage-wrap {
  max-width: 1060px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.wf-head { }
.wf-title { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; color: var(--text); }
.wf-subtitle { margin-top: 5px; font-size: 14px; color: var(--text-2); }
.wf-note {
  margin-top: var(--space-2);
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.03em; color: var(--text-4);
}

/* ==========================================================================
   Bracket-frame motif — L-shaped "scan target" corner ticks
   ========================================================================== */

.bracket-frame {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.bf-corner { position: absolute; width: 14px; height: 14px; pointer-events: none; z-index: 2; }
.bf-corner--tl { top: -1px; left: -1px; border-top: 1.5px solid var(--border-strong); border-left: 1.5px solid var(--border-strong); border-top-left-radius: 4px; }
.bf-corner--tr { top: -1px; right: -1px; border-top: 1.5px solid var(--border-strong); border-right: 1.5px solid var(--border-strong); border-top-right-radius: 4px; }
.bf-corner--bl { bottom: -1px; left: -1px; border-bottom: 1.5px solid var(--border-strong); border-left: 1.5px solid var(--border-strong); border-bottom-left-radius: 4px; }
.bf-corner--br { bottom: -1px; right: -1px; border-bottom: 1.5px solid var(--border-strong); border-right: 1.5px solid var(--border-strong); border-bottom-right-radius: 4px; }

/* ==========================================================================
   The pipeline board — columns left→right; a column with >1 stage is parallel
   ========================================================================== */

.board {
  position: relative;
  padding: var(--space-8) var(--space-8) var(--space-6);
  background:
    radial-gradient(120% 90% at 50% 0%, color-mix(in srgb, var(--accent) 5%, transparent), transparent 55%),
    var(--surface);
  overflow: hidden;
}
@media (max-width: 780px) {
  .board { overflow-x: auto; padding: var(--space-6) var(--space-5); }
}

.board__legend {
  position: absolute; top: var(--space-3); right: var(--space-4); z-index: 3;
  display: flex; gap: var(--space-3);
  font-family: var(--font-mono); font-size: 9.5px; letter-spacing: 0.03em; color: var(--text-4);
}
.board__legend-item { display: inline-flex; align-items: center; gap: 5px; }
.board__swatch { width: 16px; height: 0; border-top: 2px solid var(--border-strong); border-radius: 2px; }
.board__swatch--par { border-top-style: dashed; border-top-color: color-mix(in srgb, var(--accent) 55%, transparent); }
@media (max-width: 560px) { .board__legend { display: none; } }

.pipeline {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-width: 700px;
  min-height: 150px;
}

/* the SVG connector overlay (edges + flying packets), behind the cards */
.pipe-svg { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; overflow: visible; pointer-events: none; }
.edge {
  fill: none;
  stroke: var(--border-strong);
  stroke-width: 2;
  opacity: 0.6;
  transition: stroke 320ms ease, opacity 320ms ease;
}
.edge.is-lit {
  stroke: var(--accent);
  opacity: 1;
  filter: drop-shadow(0 0 3px color-mix(in srgb, var(--accent) 45%, transparent));
}
.pipe-packet {
  fill: var(--accent);
  filter: drop-shadow(0 0 6px color-mix(in srgb, var(--accent) 75%, transparent));
}

/* a column: single stage, or several stacked = parallel */
.pipe-col {
  position: relative;
  z-index: 1;
  flex: 1 1 0;
  min-width: 76px;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
}
.pipe-col--parallel {
  gap: var(--space-3);
  padding: 24px var(--space-2) var(--space-3);
  border: 1px dashed color-mix(in srgb, var(--accent) 38%, transparent);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--accent) 3.5%, transparent);
}
.pipe-col__tag {
  position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
  white-space: nowrap;
  font-family: var(--font-mono); font-size: 9px; font-weight: 600;
  letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--accent);
}

/* stage cards */
.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  text-align: center;
  cursor: pointer;
}
.stage__icon {
  position: relative;
  width: 50px; height: 50px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  color: var(--text-4);
  transition: color 260ms ease, border-color 260ms ease, background 260ms ease, transform 260ms ease, box-shadow 260ms ease;
}
.stage__icon svg { width: 23px; height: 23px; }
.stage__label {
  font-family: var(--font-mono);
  font-size: 10.5px; letter-spacing: 0.02em; line-height: 1.3;
  color: var(--text-4);
  max-width: 92px;
  transition: color 260ms ease;
}
.stage__step {
  font-family: var(--font-mono); font-size: 9px; color: var(--text-4); opacity: 0.55;
  font-feature-settings: "tnum";
}
.stage:hover .stage__icon { border-color: var(--text-4); color: var(--text-3); }

.stage.is-active .stage__icon {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-ghost);
  transform: scale(1.09);
  box-shadow: 0 0 0 5px var(--accent-ghost), 0 0 22px -2px color-mix(in srgb, var(--accent) 55%, transparent);
}
.stage.is-active .stage__label { color: var(--text); font-weight: 500; }
.stage.is-active .stage__step { color: var(--accent); opacity: 1; }

.stage.is-done .stage__icon { color: #fff; border-color: var(--accent); background: var(--accent); }
.stage.is-done .stage__label { color: var(--text-2); }
html[data-theme="dark"] .stage.is-done .stage__icon { color: var(--bg); }

/* expanding ring pulse when a stage activates */
.stage--pulse .stage__icon::after {
  content: "";
  position: absolute; inset: -3px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: ringPulse 640ms ease-out forwards;
  pointer-events: none;
}
@keyframes ringPulse {
  from { transform: scale(1); opacity: 0.8; }
  to { transform: scale(1.9); opacity: 0; }
}

/* ==========================================================================
   Meters
   ========================================================================== */

.meters { display: flex; gap: var(--space-3); flex-wrap: wrap; }
.meter {
  flex: 1 1 0; min-width: 116px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  display: flex; flex-direction: column; gap: 5px;
}
.meter__label {
  font-family: var(--font-mono); font-size: 9.5px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-4);
  display: flex; align-items: baseline; gap: 6px;
}
.meter__hint {
  font-style: normal; font-weight: 500; letter-spacing: 0.02em;
  text-transform: none; color: var(--accent); opacity: 0.85;
}
.meter__value {
  font-family: var(--font-mono); font-size: 18px; font-weight: 500;
  color: var(--text); font-feature-settings: "tnum";
  transition: color 200ms ease;
}
.meter__value.is-running { color: var(--accent); }
.meter__value.is-done { color: var(--green); }

/* ==========================================================================
   Panels — "under the hood" learning panel + agent console, side by side
   ========================================================================== */

.panels {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--space-5);
  align-items: stretch;
}
@media (max-width: 880px) { .panels { grid-template-columns: 1fr; } }

.console__head {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.console__dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px var(--green-subtle);
  animation: livePulse 2.4s ease-in-out infinite;
}
.uth__dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ghost);
}
@keyframes livePulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.console__label { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.04em; color: var(--text-3); }
.console__meta { margin-left: auto; font-family: var(--font-mono); font-size: 10.5px; color: var(--text-4); }
.console__meta.is-parallel { color: var(--accent); }

/* ---- under the hood ---- */
.uth { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.uth__body {
  padding: var(--space-4);
  min-height: 156px; max-height: 264px; overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--space-4);
}
.uth__hint { font-family: var(--font-mono); font-size: 12px; color: var(--text-4); line-height: 1.6; }

.uth__stage { display: flex; flex-direction: column; gap: 7px; animation: logIn 260ms ease-out; }
.uth__stage + .uth__stage { padding-top: var(--space-4); border-top: 1px dashed var(--border); }
.uth__stagehead { display: flex; align-items: center; gap: var(--space-2); }
.uth__ico {
  width: 26px; height: 26px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  background: var(--accent-ghost); color: var(--accent);
}
.uth__ico svg { width: 16px; height: 16px; }
.uth__name {
  font-family: var(--font-mono); font-size: 12.5px; font-weight: 600;
  letter-spacing: 0.01em; color: var(--text);
}
.uth__algo { font-size: 12.5px; line-height: 1.55; color: var(--text-2); }
.uth__libs { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-top: 1px; }
.uth__libslabel {
  font-family: var(--font-mono); font-size: 8.5px; font-weight: 600;
  letter-spacing: 0.09em; text-transform: uppercase; color: var(--text-4);
  margin-right: 2px;
}
.uth__lib {
  font-family: var(--font-mono); font-size: 10.5px; color: var(--text-2);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 2px 7px;
}

/* ---- agent console ---- */
.console { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.console__body {
  padding: var(--space-4);
  min-height: 156px; max-height: 264px; overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--space-3);
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.5;
}
.console__hint { color: var(--text-4); }

.logline { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2); animation: logIn 260ms ease-out; }
@keyframes logIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.logline__stage {
  flex-shrink: 0;
  font-size: 9.5px; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--accent); background: var(--accent-ghost);
  padding: 2px 6px; border-radius: var(--radius-sm);
}
.logline__body { color: var(--text-2); }
.logline__gen {
  width: 100%; margin-top: 5px; padding-left: 10px;
  border-left: 2px solid color-mix(in srgb, var(--accent) 40%, transparent);
  color: var(--text);
}
.logline__cursor {
  display: inline-block; width: 7px; height: 1.05em;
  background: var(--accent); margin-left: 1px; vertical-align: -2px;
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.logline--done .logline__stage { color: var(--green); background: var(--green-subtle); }
.logline--done .logline__body { color: var(--green); }

/* the "N agents in parallel" fork marker before a parallel column's logs */
.logline--fork { margin-bottom: -2px; }
.logline__fork {
  font-size: 10px; letter-spacing: 0.03em; color: var(--accent);
  padding-left: 2px; border-left: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  padding-left: 8px;
}

/* ==========================================================================
   Transport (playback controls)
   ========================================================================== */

.transport { display: flex; align-items: center; gap: var(--space-3); }
.transport__btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
}
.transport__btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--text-4); }
.transport__btn:active:not(:disabled) { transform: scale(0.94); }
.transport__btn:disabled { opacity: 0.35; cursor: default; }
.transport__btn svg { width: 14px; height: 14px; }
.transport__btn--primary { width: 40px; height: 40px; background: var(--accent); border-color: var(--accent); color: #fff; }
.transport__btn--primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
html[data-theme="dark"] .transport__btn--primary { color: var(--bg); }

/* play / pause icon toggle — driven by an .is-playing class on the button */
.transport__btn--primary .icon-pause { display: none; }
.transport__btn--primary.is-playing .icon-play { display: none; }
.transport__btn--primary.is-playing .icon-pause { display: block; }

.transport__scrub {
  flex: 1; min-width: 0;
  -webkit-appearance: none; appearance: none;
  height: 3px; background: var(--border-strong); border-radius: 2px; outline-offset: 6px;
}
.transport__scrub::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface); box-shadow: var(--shadow-sm);
  cursor: pointer; transition: transform var(--t-fast);
}
.transport__scrub::-webkit-slider-thumb:hover { transform: scale(1.15); }
.transport__scrub::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface); box-shadow: var(--shadow-sm); cursor: pointer;
}
.transport__scrub::-moz-range-track { height: 3px; background: var(--border-strong); border-radius: 2px; }
.transport__roundlabel {
  flex-shrink: 0; font-family: var(--font-mono); font-size: 11px; color: var(--text-3);
  min-width: 52px; text-align: right; font-feature-settings: "tnum";
}

/* ==========================================================================
   Footer + responsive + reduced motion
   ========================================================================== */

.footer {
  max-width: 1060px; margin: 0 auto;
  padding: 0 var(--space-6) var(--space-8);
  font-family: var(--font-mono); font-size: 10.5px; color: var(--text-4);
}

@media (max-width: 720px) {
  .stage-wrap { padding: var(--space-5) var(--space-4); }
  .meters { gap: var(--space-2); }
  .meter { min-width: calc(50% - var(--space-2)); }
}

@media (prefers-reduced-motion: reduce) {
  .edge, .stage__icon { transition: none !important; }
  .stage--pulse .stage__icon::after, .console__dot { animation: none !important; }
  .logline, .uth__stage { animation: none !important; }
}
