/* run.css: what run.js brings to life (DESIGN-R6 §3.1, §3.2, §5, §7). base.css owns every static
   look (header row, console box, trace grid, chips, live line); this file adds the proof ticks, the
   console's run states and answers, the step states, the pill and its panel. Motion sits in the
   no-preference block at the end: reduced motion gets the same end states, still. */

/* Fallbacks only (zero specificity): base.css's :root wins whenever it is there. */
:where(:root) {
  --deep: #0b1035; --deep-2: #141b52; --deep-3: #232c78; --line: rgba(246, 242, 232, .16);
  --foam: #f6f2e8; --foam-2: #c7cbea; --foam-3: #9ca3d6;
  --coral: #ff5a3d; --sea: #2fe0c2; --lamp: #ffc531; --violet: #8d7bff;
}

/* ---------- the proof: a ring that draws into a tick when the trace verifies it ---------- */
[data-proof] > li { position: relative; }
[data-proof] > li::before,
[data-proof] > li::after { content: ''; box-sizing: border-box; pointer-events: none; }
/* In the li's flex row (base.css), before the link. */
[data-proof] > li::before {
  flex: none;
  width: 1.1em;
  height: 1.1em;
  border: .12em solid var(--sea);
  border-radius: 50%;
  background: var(--sea);
}
[data-proof] > li::after {
  position: absolute;
  left: .4em;
  top: 50%;
  width: .32em;
  height: .58em;
  margin-top: -.36em;
  border: solid var(--deep);
  border-width: 0 .13em .13em 0;
  transform: rotate(45deg);
}
/* run.js arms the list only when it will tick it: without it the ticks stand. */
[data-proof].is-armed > li:not(.is-verified)::before { border-color: var(--foam-3); background: transparent; }
[data-proof].is-armed > li:not(.is-verified)::after { opacity: 0; }

/* ---------- the crew console ---------- */
/* One column; the answer region stays rendered while empty or spoken-only (a live region must exist
   before it speaks), with its gap taken back. */
.console { display: flex; flex-direction: column; }
.console-result:empty { display: block; }
.console:not(.has-result) > .console-result { margin-top: calc(-1 * var(--sp-4, 16px)); }
.trace,
.console-result { scrollbar-width: thin; scrollbar-color: rgba(156, 163, 214, .6) transparent; }
.trace { align-content: start; }
/* "filter" and "check" are the longest machine words; with subgrid every line shares the widest
   word present, so the first run's four-letter words leave its text more room. */
.tr { grid-template-columns: 6ch minmax(0, 1fr) auto; }
@supports (grid-template-columns: subgrid) {
  .trace { grid-template-columns: max-content minmax(0, 1fr) auto; }
  .tr { grid-column: 1 / -1; grid-template-columns: subgrid; }
  .tr-t:last-child { grid-column: 2 / -1; }
}
.tr.is-cmd .tr-t { color: var(--foam); overflow-wrap: anywhere; }
.tr-v { text-align: end; white-space: nowrap; }
.tr[data-kind='tool'] .tr-v { color: var(--sea); }
.tr.is-waiting .tr-v { opacity: 0; }
.tr.is-pending { visibility: hidden; }

/* The answer, built from the page's own elements. */
.console-result { min-width: 0; color: var(--foam); font-size: .9375rem; line-height: 1.5; }
.console-result p { margin: 0; }
.console-result a { color: var(--coral); }
.console-result > div > * + * { margin-top: 10px; }
.result-prs,
.result-links { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; line-height: 1.4; }
.result-prs { gap: 6px; }
/* A merged PR: its title (one line, ellipsis), then repo and date; on one row from 1024px. */
.result-prs li { display: grid; min-width: 0; }
.result-prs a { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.result-meta { display: flex; gap: 1.5ch; color: var(--foam-3); font: .75rem/1.5 var(--font-mono, monospace); white-space: nowrap; }
.result-row { display: flex; flex-wrap: wrap; gap: 4px 20px; }
.result-rules { display: grid; gap: 8px; }
.result-rules .result-links + .result-links { padding-top: 8px; border-top: 1px solid var(--line); }
.result-title { color: var(--foam); font: 800 1.75rem/1 var(--font-display, sans-serif); }
.result-go {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  background: var(--coral);
  color: var(--deep);
  font: 700 .9375rem/1.2 var(--font-body, sans-serif);
  cursor: pointer;
}
.result-go:hover { background: #ff7a62; }
.run-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
/* The running task's chip stays lit; another chip still cancels it and starts its own. */
.chip[aria-disabled='true'] { border-color: var(--coral); background: var(--coral); color: var(--deep); cursor: progress; }

/* Phones: the last four lines that have landed (run.js marks the older .is-old), instead of
   base.css's last four children, so the first run streams in from its first line. */
@media (max-width: 720px) {
  .console { padding: var(--sp-4, 16px); }
  /* About four wrapped lines held open, so the chips below barely move while a run streams in. */
  .trace.is-live { min-height: calc(6 * 1.55em + 18px); }
  .has-result .trace.is-live { min-height: 0; }
  .trace.is-live > .tr:nth-last-child(n + 5) { display: grid; }
  .trace.is-live > .tr:is(.is-pending, .is-old) { display: none; }
  .tr { column-gap: 1.5ch; }
}

/* Two columns. The console keeps one height: run.js (is-fixed) holds the trace at the first run's own
   height (--screen), never less than an answer's 165px plus one folded line (--room). Every run streams
   inside it; an answer folds the trace to its done line (--fold tall) and takes the rest, sized so
   nothing shows by half (three PRs, the rules in two columns, the project's line clamped, its button
   always in view); what still overflows scrolls with a short fade. The chips sit in two rows, two wide
   then three, a long label wrapping inside its chip. Without run.js every part keeps its natural
   height. The trace sets at 13px here (not 14) so the first run fits six lines at 1440. */
@media (min-width: 1024px) {
  .console { gap: var(--sp-3, 12px); padding-block: 20px; }
  .console:not(.has-result) > .console-result { margin-top: calc(-1 * var(--sp-3, 12px)); }
  .console > .chips { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 6px; }
  .console .chip {
    grid-column: span 4;
    min-height: 32px;
    padding: 5px 10px;
    font-size: .8125rem;
    line-height: 1.2;
    text-align: center;
  }
  .console .chip:nth-child(-n + 2) { grid-column: span 6; }
  .trace { font-size: .8125rem; }
  .is-fixed { --room: max(var(--screen, 0px), calc(165px + var(--sp-3, 12px) + 1.55 * .8125rem)); }
  .is-fixed .trace { height: var(--room); overflow-y: auto; }
  .has-result .trace > .tr:not(:last-child) { display: none; }
  .is-fixed.has-result .trace { height: auto; }
  .is-fixed.has-result > .console-result {
    height: calc(var(--room) - var(--fold, 0px) - var(--sp-3, 12px));
    min-height: 3em;
    overflow-y: auto;
  }
  .trace.is-up {
    -webkit-mask-image: linear-gradient(transparent, #000 28px);
    mask-image: linear-gradient(transparent, #000 28px);
  }
  .console-result.is-more {
    -webkit-mask-image: linear-gradient(#000 calc(100% - 28px), transparent);
    mask-image: linear-gradient(#000 calc(100% - 28px), transparent);
  }
  .result-prs li { grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; column-gap: 12px; }
  .result-prs li:nth-child(n + 4) { display: none; }
  .result-rules { grid-template-columns: 1fr 1fr; align-items: start; gap: 0; font-size: .875rem; }
  .result-rules .result-links { gap: 5px; line-height: 1.3; }
  .result-rules .result-links:first-child { padding-right: 14px; }
  .result-rules .result-links + .result-links { padding: 0 0 0 14px; border-top: 0; border-left: 1px solid var(--line); }
  .result-title { font-size: 1.25rem; }
  .result-project .result-text {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
  }
  .result-go { min-height: 34px; padding-inline: 14px; }
}

/* A narrow console gives the longest label ("How do you keep agents in line?") the widest chip. */
@media (min-width: 1024px) and (max-width: 1279px) {
  .console .chip:nth-child(3) { grid-column: span 5; }
  .console .chip:nth-child(5) { grid-column: span 3; }
}

/* ---------- the run rail: todo is base.css's hollow ring; now a lamp dot, done a sea tick ---------- */
.run-state { position: relative; }
.run-state::after { content: ''; position: absolute; box-sizing: border-box; opacity: 0; }
[data-run-steps] > [data-state='now'] .run-state { border-color: var(--lamp); background: var(--lamp); }
[data-run-steps] > [data-state='now'] .run-state::after { inset: -2px; border: 2px solid var(--lamp); border-radius: 50%; }
[data-run-steps] > [data-state='done'] .run-state { border-color: transparent; }
[data-run-steps] > [data-state='done'] .run-state::after {
  left: 0;
  top: -3px;
  width: 5px;
  height: 9px;
  border: solid var(--sea);
  border-width: 0 2px 2px 0;
  opacity: 1;
  transform: rotate(45deg);
}
[data-run-steps] > [data-state='todo'] > a { color: var(--foam-3); }
[data-run-steps] > li > a[aria-current='step'] { color: var(--foam); background: var(--deep-2); }

.run-pill {
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 40px;
  padding: 0 14px 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--deep-2);
  color: var(--foam);
  font: 600 .9375rem/1.2 var(--font-body, sans-serif);
  cursor: pointer;
}
.run-count { color: var(--lamp); font-variant-numeric: tabular-nums; }
.run-name { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
/* A chevron drawn with two borders (no arrow characters). */
.run-pill::after {
  content: '';
  flex: none;
  width: 7px;
  height: 7px;
  margin-inline-start: 2px;
  border: solid currentColor;
  border-width: 0 1.5px 1.5px 0;
  transform: translateY(-2px) rotate(45deg);
}
.run-pill[aria-expanded='true']::after { transform: translateY(2px) rotate(-135deg); }

/* Below 1100px, once run.js runs (has-run): the list folds into the pill and opens as a panel. */
@media (max-width: 1099px) {
  .has-run .run { position: relative; flex-wrap: nowrap; }
  .has-run .run-pill { display: inline-flex; margin-left: auto; }
  .has-run .lang-toggle { margin-left: 0; }
  .has-run .run-steps { display: none; }
  .has-run.is-open .run-steps {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 2;
    display: grid;
    gap: 2px;
    width: min(340px, 100%);
    max-height: calc(100svh - var(--header-h, 56px) - 24px);
    margin: 0;
    padding: 8px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--deep-2);
  }
  .has-run.is-open .run-steps a { display: flex; min-height: 44px; padding-inline: 12px; border-radius: 10px; font-size: 1rem; }
  .has-run.is-open .run-steps a:is(:hover, [aria-current='step']) { background: var(--deep-3); }
}

/* The live line clips its overflow, so its link's focus ring is drawn inside the link. */
[data-swarm-log] a:focus-visible { outline-offset: -3px; }

/* "Take me there": the tile clears the header and is outlined for 2 s. */
[data-project] { scroll-margin-top: 24px; }
.is-picked { outline: 3px solid var(--focus, var(--deep)); outline-offset: 6px; }

/* ---------- motion ---------- */
@media (prefers-reduced-motion: no-preference) {
  [data-proof].is-armed > li::before { transition: background-color .2s, border-color .2s; }
  [data-proof].is-armed > li.is-verified::before { animation: ring-fill .36s cubic-bezier(.2, .7, .2, 1); }
  [data-proof].is-armed > li.is-verified::after { animation: tick-draw .34s ease-out .08s both; }
  .tr.is-new { animation: tr-in .22s ease-out both; }
  .tr-v { transition: opacity .16s; }
  .console-state[data-state='running']::before { animation: blink .8s ease-in-out infinite alternate; }
  .run-state,
  .run-state::after { transition: opacity .15s, background-color .15s, border-color .15s; }
  [data-run-steps] > [data-state='now'] .run-state::after { animation: now-pulse 2.4s ease-out infinite; }
  .run-bar { transition: transform .12s linear; }
  .run-pill::after { transition: transform .15s; }
}

@keyframes ring-fill { from { border-color: var(--foam-3); background: transparent; transform: scale(.85); } 60% { transform: scale(1.14); } }
@keyframes tick-draw {
  from { clip-path: inset(calc(100% - .13em) 100% 0 0); }
  45% { clip-path: inset(calc(100% - .13em) 0 0 0); }
  to { clip-path: inset(0); }
}
@keyframes tr-in { from { opacity: 0; transform: translateY(4px); } }
@keyframes blink { from { opacity: .35; } }
@keyframes now-pulse { from { opacity: .8; transform: scale(1); } 55%, to { opacity: 0; transform: scale(2.2); } }
