/* The scope gate (js/views/gate.js): four stations on one line, and the proposed actions as dots that ride it.
   A dot is grey while it is only a proposal, white once the gate has let it through, and a ring with a bar
   once it is refused. Green appears in one place: the gate while it holds an action back (its bar and the
   rule that said no), and the stop state. Wide frames run left to right; narrow ones run down the page.
   Without scripting the figure is its plain list; .is-ready swaps the list for the picture. */

.view--gate { overflow: clip; border-radius: var(--radius-frame); background: var(--color-paper-2); box-shadow: inset 0 0 0 1px var(--color-frame-edge); }
.gate { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-lg); margin: 0; padding: var(--space-xl); }
.gate p { margin: 0; }

/* The bar: the count in words, the controls, and the line that says the test is stopped. Stop and Run again
   are the shared dark pill (.tl__run in views.css); the stopped state is the green gate and the green line. */
.gate__bar { position: relative; z-index: 1; display: grid; min-width: 0; }
.gate__tally { color: var(--color-ink); font-variant-numeric: tabular-nums; }
.gate__halt { font-size: var(--text-md); line-height: 1.3; color: var(--color-defense); }
html:not(.rm) .gate__halt { animation: tl-in 320ms var(--ease-out) both; }
.gate__ctl { display: flex; flex-wrap: wrap; gap: var(--space-xs); }
.gate__stop, .gate__again { min-width: 6.5rem; text-align: center; }
.gate__stop:focus-visible, .gate__again:focus-visible, .gate__tok:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; transition: none; }

.gate__body { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-lg); }
.gate__stage { position: relative; display: grid; }
.gate__st { display: contents; }

/* A station: its name and one line, its mark on the rail, and what sits under it. */
.gate__head { display: grid; align-content: start; gap: var(--space-2xs); min-width: 0; }
.gate__name { font-size: var(--text-title); line-height: 1.2; letter-spacing: var(--tracking-title); color: var(--color-ink); }
.gate__line { max-width: 22ch; font-size: var(--text-md); line-height: 1.35; color: var(--color-ink-3); }
.gate__node {
  position: relative; z-index: 1; display: block; width: 20px; height: 20px; margin: var(--space-3xs); border-radius: 50%;
  background: var(--color-paper-2); box-shadow: inset 0 0 0 2px var(--color-ink-3); transition: transform 240ms var(--ease-out);
}
.gate__node::before, .gate__node::after { content: ""; position: absolute; inset: 0; border-radius: inherit; opacity: 0; pointer-events: none; }
/* Act is a square: the module. It fills and swells while it runs an action. */
.gate__node--act { border-radius: var(--radius-nav-btn); }
.gate__node--act::before { background: var(--color-ink-2); transition: opacity 240ms var(--ease-out); }
.gate__node--act.is-on { transform: scale(1.3); }
.gate__node--act.is-on::before { opacity: 1; }
/* A ring leaves Plan when an action is proposed, and Record when one is written down. */
.gate__node::after { box-shadow: inset 0 0 0 1.5px var(--color-ink-2); }
html:not(.rm) .gate__node.is-ping::after { animation: gate-ping 720ms var(--ease-out) 1; }
@keyframes gate-ping { from { opacity: 0.9; transform: scale(1); } to { opacity: 0; transform: scale(2.1); } }

/* The gate: where a dot waits, and the bar across the rail in two halves. Shut is grey. Open slides the
   halves apart. Held, and stopped, are shut and green. */
.gate__port { position: relative; z-index: 1; display: flex; align-items: center; }
.gate__hold { flex: none; width: 24px; height: 24px; }
.gate__barrier { flex: none; display: grid; }
.gate__barrier i { position: relative; display: block; overflow: hidden; background: var(--color-ink-3); transition: transform 160ms var(--ease-out); }
.gate__barrier i::after { content: ""; position: absolute; inset: 0; background: var(--color-defense); opacity: 0; transition: opacity 160ms var(--ease-out); }
.gate__stage[data-gate-state="open"] .gate__barrier i { transition-duration: 220ms; }
.gate__stage[data-gate-state="held"] .gate__barrier i::after, .gate.is-stopped .gate__barrier i::after { opacity: 1; }
html:not(.rm) .gate__stage[data-gate-state="held"] .gate__barrier { animation: gate-hold 460ms var(--ease-out) 1; }
@keyframes gate-hold { 35% { transform: scale(1.4); } }

/* The rules the check asks, each with a mark: a grey dot until it is asked, white once it says yes, the
   green bar if it says no. */
.gate__more--check { display: grid; align-content: start; gap: var(--space-lg); min-width: 0; }
.gate__rules { display: grid; gap: var(--space-xs); margin: 0; padding: 0; list-style: none; }
.gate__rule { display: grid; grid-template-columns: var(--control-hit) minmax(0, 1fr); column-gap: var(--space-xs); font-size: var(--text-md); line-height: 1.4; }
.gate__tick { position: relative; justify-self: center; width: 16px; height: 1.4em; }
.gate__tick::before, .gate__tick::after { content: ""; position: absolute; top: 50%; left: 50%; translate: -50% -50%; transition: opacity 160ms var(--ease-out), transform 220ms var(--ease-out); }
.gate__tick::before { width: 8px; height: 8px; border-radius: 50%; background: var(--color-ink); opacity: 0.2; }
.gate__tick::after { width: 16px; height: 4px; border-radius: var(--radius-nav-btn); background: var(--color-defense); opacity: 0; transform: scaleX(0.4); }
.gate__rule[data-state="ok"] .gate__tick::before { opacity: 1; }
.gate__rule[data-state="no"] .gate__tick::before { opacity: 0; }
.gate__rule[data-state="no"] .gate__tick::after { opacity: 1; transform: none; }
.gate__rule-k { color: var(--color-ink-3); }
.gate__rule-v { color: var(--color-ink-2); font-variant-numeric: tabular-nums; }
.gate__rule[data-state="no"] .gate__rule-v { color: var(--color-ink); }

/* The tray: refused actions land here, one row each, with the reason. */
.gate__tray { display: grid; gap: var(--space-2xs); }
.gate__tray-k { padding-left: calc(var(--control-hit) + var(--space-xs)); font-size: var(--text-md); line-height: 1.4; color: var(--color-ink-3); }
.gate__rows { display: grid; gap: var(--space-2xs); margin: 0; padding: 0; list-style: none; }
.gate__held { display: grid; grid-template-columns: var(--control-hit) minmax(0, 1fr); column-gap: var(--space-xs); align-items: center; min-height: var(--control-hit); }
.gate__held.is-on { cursor: pointer; }
.gate__cell { display: block; width: var(--control-hit); height: var(--control-hit); }
.gate__why { font-size: var(--text-md); line-height: 1.3; color: var(--color-ink-2); transition: opacity 320ms var(--ease-out), color var(--dur-hover) var(--ease-out); }
.gate.is-ready .gate__held:not(.is-on) .gate__why { opacity: 0; }
.gate__held.is-on:hover .gate__why { color: var(--color-ink); }

/* The rack: actions that ran, one cell each. */
.gate__rack { display: grid; grid-template-columns: repeat(auto-fill, var(--control-hit)); align-content: start; justify-content: start; min-width: 0; }

/* The lines under everything: the rail, and the side lane from the gate down to the tray. */
.gate__svg { position: absolute; inset: 0; z-index: 0; display: block; overflow: visible; pointer-events: none; }
.gate__rail, .gate__branch { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.gate__rail { stroke: var(--color-dust-far); transition: opacity 240ms var(--ease-out); }
.gate__branch { stroke: var(--color-paper-4); }
.gate.is-stopped .gate__rail--out { opacity: 0.4; }

/* A dot: one proposed action. The button is the size of a finger; the dot sits in its middle. */
.gate__tok {
  position: absolute; top: 0; left: 0; z-index: 2; display: grid; place-items: center; width: var(--control-hit); height: var(--control-hit);
  translate: -50% -50%; padding: 0; border: 0; border-radius: 50%; background: none; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.gate__tok::before {
  content: ""; position: absolute; top: 50%; left: 50%; width: 28px; height: 28px; translate: -50% -50%; border-radius: 50%;
  box-shadow: inset 0 0 0 1.5px var(--color-ink); opacity: 0; transform: scale(0.7); transition: opacity 200ms var(--ease-out), transform 260ms var(--ease-out);
}
.gate__tok[aria-current="true"]::before { opacity: 1; transform: none; }
.gate__dot { position: relative; display: block; width: 14px; height: 14px; border-radius: 50%; background: var(--color-ink-3); transition: transform 200ms var(--ease-out), background-color 200ms var(--ease-out); }
.gate__dot::after { content: ""; position: absolute; top: 50%; left: 50%; width: 6px; height: 2px; translate: -50% -50%; background: var(--color-ink-2); opacity: 0; transition: opacity 200ms var(--ease-out); }
.gate__tok[data-state="pass"] .gate__dot { background: var(--color-ink); }
.gate__tok[data-state="held"] .gate__dot { background: var(--color-paper-2); box-shadow: inset 0 0 0 2px var(--color-ink-2); }
.gate__tok[data-state="held"] .gate__dot::after { opacity: 1; }
.gate__tok:hover .gate__dot { transform: scale(1.3); }
.gate__tok:active .gate__dot { transform: scale(0.9); }

/* The panel: the action picked, where and when, and what the gate decided. */
.gate__panel {
  position: relative; z-index: 1; display: grid; align-content: start; gap: var(--space-2xs); min-width: 0; padding: var(--space-lg);
  border-radius: var(--radius-view); background: var(--color-paper-3); color: var(--color-ink); box-shadow: inset 0 0 0 1px var(--color-frame-edge);
}
.gate__p-text { font-size: var(--text-title); line-height: 1.2; letter-spacing: var(--tracking-title); color: var(--color-ink); }
.gate__p-meta { font-size: var(--text-md); line-height: 1.4; color: var(--color-ink-3); font-variant-numeric: tabular-nums; }
.gate .gate__p-out { margin-top: var(--space-xs); font-size: var(--text-md); line-height: 1.4; color: var(--color-ink-2); transition: opacity 240ms var(--ease-out); }
.gate__p-word { font-weight: inherit; color: var(--color-ink); }
.gate.is-ready .gate__p-out:not(.is-on) { opacity: 0; transition: none; }
html:not(.rm) .gate__panel.is-swap > :not(.gate__p-out) { animation: tl-in 320ms var(--ease-out) both; }

.gate__caption { font-size: var(--text-md); color: var(--color-ink-3); }

/* ---------- Left to right ---------- */
.gate[data-layout="wide"] .gate__stage {
  grid-template-columns: minmax(9.5rem, 0.8fr) minmax(0, 1.75fr) minmax(0, 0.8fr) minmax(0, 1.1fr);
  grid-template-rows: auto var(--control-hit) auto 1fr; gap: var(--space-sm) var(--space-lg);
}
.gate[data-layout="wide"] [data-gate-st="plan"] > * { grid-column: 1; }
.gate[data-layout="wide"] [data-gate-st="check"] > * { grid-column: 2; }
.gate[data-layout="wide"] [data-gate-st="act"] > * { grid-column: 3; }
.gate[data-layout="wide"] [data-gate-st="record"] > * { grid-column: 4; }
.gate[data-layout="wide"] .gate__head { grid-row: 1; }
.gate[data-layout="wide"] .gate__node, .gate[data-layout="wide"] .gate__port { grid-row: 2; align-self: center; justify-self: start; }
.gate[data-layout="wide"] .gate__barrier { grid-template-rows: 18px 18px; width: 4px; margin-left: var(--space-xs); }
.gate[data-layout="wide"] .gate__barrier i:first-child { border-radius: var(--radius-pill) var(--radius-pill) 0 0; }
.gate[data-layout="wide"] .gate__barrier i:last-child { border-radius: 0 0 var(--radius-pill) var(--radius-pill); }
.gate[data-layout="wide"]:not(.is-stopped) .gate__stage[data-gate-state="open"] .gate__barrier i:first-child { transform: translateY(-11px); }
.gate[data-layout="wide"]:not(.is-stopped) .gate__stage[data-gate-state="open"] .gate__barrier i:last-child { transform: translateY(11px); }
.gate[data-layout="wide"].is-stopped .gate__barrier { transform: scaleX(1.5); }
.gate[data-layout="wide"] .gate__more--check { grid-row: 3 / span 2; padding-left: var(--space-sm); }
/* The rack's first column sits under the Record mark: the mark with its margin is --space-lg wide. */
.gate[data-layout="wide"] .gate__rack { grid-row: 3; margin-left: calc((var(--space-lg) - var(--control-hit)) / 2); }
.gate[data-layout="wide"] .gate__panel { grid-column: 3 / span 2; grid-row: 4; align-self: end; margin-top: var(--space-sm); }
/* Under Plan: the count, one sentence a line, then the stop control. */
.gate[data-layout="wide"] .gate__bar { grid-column: 1; grid-row: 3 / span 2; align-content: start; justify-items: start; gap: var(--space-md); padding-top: var(--space-xs); }
.gate[data-layout="wide"] .gate__tally { font-size: var(--text-title); line-height: 1.3; letter-spacing: var(--tracking-title); }
.gate[data-layout="wide"] .gate__tally > span { display: block; }
.gate[data-layout="wide"] .gate__ctl { flex-direction: column; align-items: flex-start; }

/* ---------- Down the page ---------- */
/* Above Plan: the count on one line, then the stop control with its line beside it. */
.gate[data-layout="tall"] .gate__bar { grid-column: 1 / -1; grid-row: 1; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: var(--space-xs) var(--space-md); padding-bottom: var(--space-sm); }
.gate[data-layout="tall"] .gate__tally { grid-column: 1 / -1; font-size: var(--text-md); line-height: 1.3; }
.gate[data-layout="tall"] .gate__ctl { grid-column: 1; grid-row: 2; flex-wrap: nowrap; align-items: center; min-height: calc(2.6 * var(--text-md)); }
.gate[data-layout="tall"] .gate__halt { grid-column: 2; grid-row: 2; }
.gate[data-layout="tall"] .gate__stage { grid-template-columns: calc(var(--space-xl) + var(--space-xs)) minmax(0, 1fr); row-gap: var(--space-sm); }
.gate[data-layout="tall"] .gate__head { grid-column: 2; }
.gate[data-layout="tall"] .gate__line { max-width: none; }
.gate[data-layout="tall"] .gate__node, .gate[data-layout="tall"] .gate__port { grid-column: 1; align-self: start; justify-self: start; }
.gate[data-layout="tall"] .gate__port { flex-direction: column; }
.gate[data-layout="tall"] .gate__barrier { grid-template-columns: 12px 12px; height: 4px; margin-top: var(--space-xs); }
.gate[data-layout="tall"] .gate__barrier i:first-child { border-radius: var(--radius-pill) 0 0 var(--radius-pill); }
.gate[data-layout="tall"] .gate__barrier i:last-child { border-radius: 0 var(--radius-pill) var(--radius-pill) 0; }
.gate[data-layout="tall"]:not(.is-stopped) .gate__stage[data-gate-state="open"] .gate__barrier i:first-child { transform: translateX(-9px); }
.gate[data-layout="tall"]:not(.is-stopped) .gate__stage[data-gate-state="open"] .gate__barrier i:last-child { transform: translateX(9px); }
.gate[data-layout="tall"].is-stopped .gate__barrier { transform: scaleY(1.5); }
.gate[data-layout="tall"] [data-gate-st="plan"] > * { grid-row: 2; }
.gate[data-layout="tall"] [data-gate-st="check"] > * { grid-row: 3; }
.gate[data-layout="tall"] [data-gate-st="check"] > .gate__more { grid-row: 4; }
.gate[data-layout="tall"] .gate__panel { grid-column: 2; grid-row: 5; }
.gate[data-layout="tall"] [data-gate-st="act"] > * { grid-row: 6; }
.gate[data-layout="tall"] [data-gate-st="record"] > * { grid-row: 7; }
.gate[data-layout="tall"] [data-gate-st="record"] > .gate__more { grid-row: 8; }
.gate[data-layout="tall"] .gate__more--check { grid-column: 1 / -1; gap: var(--space-md); padding-left: calc(var(--space-lg) + var(--space-sm)); }
.gate[data-layout="tall"] .gate__rack { grid-column: 2; }
/* Room between one station and the next. */
.gate[data-layout="tall"] [data-gate-st="plan"] > .gate__head, .gate[data-layout="tall"] [data-gate-st="act"] > .gate__head { padding-bottom: var(--space-md); }
.gate[data-layout="tall"] .gate__panel { margin-bottom: var(--space-md); padding: var(--space-md); }

/* ---------- Without scripting: the list ---------- */
.gate__list { font-size: var(--text-md); line-height: 1.45; color: var(--color-ink-2); }
.gate__list ol { display: grid; gap: var(--space-sm); max-width: 72ch; margin: var(--space-md) 0 0; padding: 0; list-style: none; }
.gate__list strong { font-weight: inherit; color: var(--color-ink); }
.gate__list-note { color: var(--color-ink-3); }
.gate__list-when { color: var(--color-ink-3); font-variant-numeric: tabular-nums; }
.gate.is-ready .gate__list { display: none; }

@media (max-width: 39.99rem) {
  .view--gate { margin-inline: calc(-1 * var(--gutter)); border-radius: 0; box-shadow: inset 0 1px 0 var(--color-frame-edge), inset 0 -1px 0 var(--color-frame-edge); }
  .gate { padding: var(--space-lg) var(--gutter); }
}
