/* Card A demo: the safety gate. An illustration in the site's style: one beam across the middle, commands landing on
   it one at a time and settling below with the gate's verdict. The rows use Kelvin's own dark-theme tokens and its
   approval card (src/labharness/web/static/app.css: .approval, .btn, .verdict). Sizes are in em on a stage whose font
   follows the container, so the picture scales; below 380px each row puts its verdict under the command. */

.kd-gate {
  --g-bg: #0a0d12;
  --g-card: #141c25; --g-card-line: #26323f; --g-raised: #19232e;
  --g-text: #e6edf4; --g-text-2: #c2ccd6; --g-muted: #8d9aa8;
  --g-line-strong: #3b4a5a; --g-muted-soft: #1c2631;
  --g-accent: #5aa2e6; --g-accent-ink: #08111a;
  --g-ok: #3fb950; --g-ok-soft: #14301f;
  --g-warn: #e3b341; --g-warn-bg: #2b2412; --g-warn-line: #8f6f1c; --g-warn-soft: #3a2f12;
  --g-danger: #ef5350; --g-danger-text: #f47e7b; --g-danger-bg: #241517; --g-danger-line: #5e2a2c;
  --g-ease: var(--ease, cubic-bezier(0.2, 0.7, 0.2, 1));
  --g-move: cubic-bezier(0.4, 0, 0.2, 1);   /* rows gliding; the approval card grows and folds on the same curve */
  --g-sans: var(--font, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
  --g-mono: var(--mono, ui-monospace, "SFMono-Regular", Consolas, monospace);

  position: relative;
  container-type: inline-size;
  color: var(--g-text);
  text-align: left;
}
.kd-gate [hidden] { display: none !important; }

/* ---------- the stage ---------- */

.kd-gate-stage {
  --gate-y: 41%;
  --lane: min(31em, 100% - 2.4em);
  position: relative;
  isolation: isolate;
  overflow: hidden;
  aspect-ratio: 5 / 4;
  font: 400 clamp(12px, 2.6cqw, 14.5px) / 1.35 var(--g-sans);
  background:
    radial-gradient(62% 30% at 50% var(--gate-y), rgba(90, 162, 230, 0.075), transparent 72%),
    var(--g-bg);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  -webkit-font-smoothing: antialiased;
}
.kd-gate-stage::before { /* a faint graticule, like the hero's sky */
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px);
  background-size: 2.4em 2.4em;
  background-position: 50% 0;
  -webkit-mask-image: radial-gradient(70% 62% at 50% var(--gate-y), #000, transparent 80%);
  mask-image: radial-gradient(70% 62% at 50% var(--gate-y), #000, transparent 80%);
}

/* the gate: a thin bright line with a soft glow */
.kd-gate-beam, .kd-gate-light { position: absolute; left: 0; right: 0; top: var(--gate-y); height: 0; pointer-events: none; }
.kd-gate-beam::before {
  content: ""; position: absolute; left: 0; right: 0; top: -0.5px; height: 1px;
  background: linear-gradient(90deg, rgba(200, 226, 250, 0) 0%, rgba(200, 226, 250, 0.7) 14%, #e6f2fd 50%, rgba(200, 226, 250, 0.7) 86%, rgba(200, 226, 250, 0) 100%);
}
.kd-gate-beam::after {
  content: ""; position: absolute; left: 7%; right: 7%; top: -3px; height: 6px; border-radius: 999px;
  background: linear-gradient(90deg, transparent, rgba(90, 162, 230, 0.5) 24%, rgba(90, 162, 230, 0.5) 76%, transparent);
  filter: blur(4px);
}

/* the verdict lights the beam in its colour, with a soft pool where the command rests */
.kd-gate-light { opacity: 0; transition: opacity 0.45s ease; }
.kd-gate-light::before {
  content: ""; position: absolute; left: 10%; right: 10%; top: -1px; height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--c) 30%, var(--c) 70%, transparent);
}
.kd-gate-light::after {
  content: ""; position: absolute; left: 0; right: 0; margin: 0 auto; top: -3.2em; height: 6.4em;
  width: calc(var(--lane) + 6em);
  background: radial-gradient(closest-side, rgb(var(--rgb) / 0.2), transparent);
}
.kd-gate-light.info { --c: #d4e9fc; --rgb: 140 196 242; }
.kd-gate-light.ok { --c: #3fb950; --rgb: 63 185 80; }
.kd-gate-light.warn { --c: #e3b341; --rgb: 227 179 65; }
.kd-gate-light.danger { --c: #ef5350; --rgb: 239 83 80; }
.kd-gate-stage[data-lit="info"] .kd-gate-light.info,
.kd-gate-stage[data-lit="ok"] .kd-gate-light.ok,
.kd-gate-stage[data-lit="warn"] .kd-gate-light.warn,
.kd-gate-stage[data-lit="danger"] .kd-gate-light.danger { opacity: 1; }
.kd-gate-stage[data-lit="warn"] .kd-gate-light.warn::after { animation: kd-gate-breathe 2.6s ease-in-out infinite; }
@keyframes kd-gate-breathe { 50% { opacity: 0.45; } }

/* the gate reads each command as it lands: a short bright sweep along the beam */
.kd-gate-scan {
  position: absolute; left: 0; right: 0; margin: 0 auto; width: var(--lane);
  top: calc(var(--gate-y) - 3px); height: 6px; overflow: hidden; pointer-events: none;
}
.kd-gate-scan::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: -50%; right: -50%;
  background: radial-gradient(closest-side, #fff, rgba(140, 196, 242, 0.55) 45%, transparent) 50% 50% / 4em 100% no-repeat;
  opacity: 0; transform: translateX(-25%);
}
.kd-gate-scan.on::before { animation: kd-gate-scan 0.5s cubic-bezier(0.45, 0, 0.3, 1) both; }
@keyframes kd-gate-scan {
  0% { opacity: 0; transform: translateX(-25%); }
  18%, 80% { opacity: 1; }
  100% { opacity: 0; transform: translateX(25%); }
}

/* ---------- the commands ---------- */

.kd-gate-lane {
  position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: 0 auto; width: var(--lane); z-index: 2;
  -webkit-mask-image: linear-gradient(180deg, #000 calc(100% - 5.5em), transparent calc(100% - 0.3em));
  mask-image: linear-gradient(180deg, #000 calc(100% - 5.5em), transparent calc(100% - 0.3em));
}
.kd-gate-lane.is-clearing { opacity: 0; transition: opacity 0.45s ease; }

.kd-gate-row {
  position: absolute; left: 0; right: 0; top: 0;
  display: grid;
  grid-template-columns: 1.1em minmax(0, 1fr) auto;
  grid-template-areas: "ico code chip" ". from detail" ". act act";
  align-items: center; column-gap: 0.55em; row-gap: 0.1em;
  padding: 0.6em 0.85em 0.62em 0.75em;
  background: var(--g-card);
  border: 1px solid var(--g-card-line);
  border-radius: 0.75em;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 0.7em 1.4em -0.9em rgba(0, 0, 0, 0.85);
  transform: translate3d(0, 0, 0);
  transition: transform var(--t, 0ms) var(--g-move), opacity 0.45s ease, background-color 0.35s ease, border-color 0.35s ease;
  will-change: transform, opacity;
}

.kd-gate-ico { grid-area: ico; width: 1.1em; height: 1.1em; display: grid; place-items: center; color: var(--g-muted); }
.kd-gate-ico svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; animation: kd-gate-pop 0.3s var(--g-ease) both; }
.kd-gate-ico[data-icon="wait"] svg { stroke-width: 1.8; opacity: 0.8; animation: none; }
@keyframes kd-gate-pop { from { opacity: 0; transform: scale(0.6); } }

.kd-gate-code {
  grid-area: code; min-width: 0;
  font: 500 1em/1.35 var(--g-mono); color: var(--g-text); letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kd-gate-from {
  grid-area: from; min-width: 0;
  font-size: max(11px, 0.86em); color: var(--g-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* the verdict */
.kd-gate-chip {
  grid-area: chip; justify-self: end; margin-left: 0.5em;
  font-size: max(11px, 0.8em); font-weight: 600; line-height: 1.5; white-space: nowrap;
  padding: 0 0.68em; border-radius: 999px;
  background: var(--g-muted-soft); color: var(--g-text-2); border: 1px solid var(--g-line-strong);
  opacity: 0; transform: translateX(0.35em);
  transition: opacity 0.35s ease, transform 0.4s var(--g-ease);
}
.kd-gate-detail {
  grid-area: detail; justify-self: end; margin-left: 0.5em;
  font-size: max(11px, 0.86em); color: var(--g-text-2); white-space: nowrap;
  opacity: 0; transition: opacity 0.35s ease 0.08s;
}
.kd-gate-row.is-checked .kd-gate-chip { opacity: 1; transform: none; }
.kd-gate-row.is-checked .kd-gate-detail { opacity: 1; }

.kd-gate-row[data-kind="measure"] .kd-gate-ico { color: var(--g-text-2); }
.kd-gate-row[data-kind="safe"] .kd-gate-ico { color: var(--g-ok); }
.kd-gate-row[data-kind="safe"] .kd-gate-chip { background: var(--g-ok-soft); color: var(--g-ok); border-color: rgba(63, 185, 80, 0.3); }
.kd-gate-row[data-kind="away"] .kd-gate-ico { color: var(--g-warn); }
.kd-gate-row[data-kind="away"] .kd-gate-chip { background: var(--g-warn-soft); color: var(--g-warn); border-color: rgba(227, 179, 65, 0.32); }
.kd-gate-row[data-kind="refused"] { background: var(--g-danger-bg); border-color: var(--g-danger-line); }
.kd-gate-row[data-kind="refused"] .kd-gate-ico { color: var(--g-danger); }
.kd-gate-row[data-kind="refused"] .kd-gate-chip { background: rgba(239, 83, 80, 0.13); color: var(--g-danger-text); border-color: rgba(239, 83, 80, 0.36); }
.kd-gate-row[data-kind="refused"] .kd-gate-detail { color: var(--g-danger-text); }

/* away from safe: Kelvin's approval card, amber, until a person answers */
.kd-gate-row.is-waiting { background: var(--g-warn-bg); border-color: var(--g-warn-line); }
.kd-gate-act { grid-area: act; display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.42s var(--g-move); }
.kd-gate-actin { min-height: 0; overflow: hidden; }
.kd-gate-actrow { display: flex; align-items: center; gap: 0.5em; padding-top: 0.5em; opacity: 0; transition: opacity 0.25s ease; }
.kd-gate-row.is-waiting .kd-gate-act { grid-template-rows: 1fr; }
.kd-gate-row.is-waiting .kd-gate-actrow { opacity: 1; transition: opacity 0.3s ease 0.15s; }
.kd-gate-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  font: 550 max(11px, 0.84em) / 1.3 var(--g-sans);
  padding: 0.3em 0.85em; border-radius: 0.6em;
  border: 1px solid var(--g-line-strong); background: var(--g-raised); color: var(--g-text);
  transition: transform 0.12s ease, filter 0.12s ease;
}
.kd-gate-btn.primary { background: var(--g-accent); border-color: var(--g-accent); color: var(--g-accent-ink); font-weight: 600; }
.kd-gate-btn.pressed { transform: scale(0.93); filter: brightness(1.18); }
.kd-gate-count { margin-left: 0.2em; font-size: max(11px, 0.82em); color: var(--g-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

/* a person said yes: the card folds back, as Kelvin's does */
.kd-gate-row.is-approved { background: var(--g-card); border-color: var(--g-card-line); }
.kd-gate-row.is-approved .kd-gate-ico { color: var(--g-ok); }
.kd-gate-row.is-approved .kd-gate-detail { color: var(--g-ok); font-weight: 600; }

/* the pointer of the person who approves */
.kd-gate-cursor {
  position: absolute; left: 0; top: 0; z-index: 5; width: 20px; height: 20px; pointer-events: none;
  opacity: 0; transform: translate(var(--cx, 0px), var(--cy, 0px));
  transition: transform 0.85s cubic-bezier(0.45, 0.05, 0.25, 1), opacity 0.3s ease;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}
.kd-gate-cursor.on { opacity: 1; }
.kd-gate-cursor.still { transition: none; }
.kd-gate-cursor svg { display: block; width: 100%; height: 100%; transition: transform 0.12s ease; }
.kd-gate-cursor.down svg { transform: scale(0.82); }

/* ---------- widths ---------- */

@container (min-width: 640px) {
  .kd-gate-stage { aspect-ratio: 3 / 2; --gate-y: 42%; }
}
@container (max-width: 379.98px) {
  /* the font is at its 12px floor here, so the rows have a fixed height: so does the stage */
  .kd-gate-stage { aspect-ratio: auto; height: 26.5em; --gate-y: 39%; --lane: calc(100% - 1.4em); }
  .kd-gate-row {
    grid-template-areas: "ico code code" ". from chip" ". detail detail" ". act act";
    padding: 0.55em 0.7em 0.6em 0.65em;
  }
  .kd-gate-detail { justify-self: start; margin-left: 0; }
  .kd-gate-count { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .kd-gate *, .kd-gate *::before, .kd-gate *::after { animation: none !important; transition: none !important; }
}
