/* Keystone · walkthrough and staged motion. Loaded after Keystone and theme/fincrime.css.
   One story in numbered steps. Each step has two panes: the source on the left, what the system
   concludes on the right. Everything inside a step arrives in reading order, and the verdict lands last.
   Only transform, opacity, filter and background-size move. */

.kw-page { min-height: 100vh; box-sizing: border-box; background: var(--ground); color: var(--ink); font-family: var(--font-sans); }
.kw { display: flex; flex-direction: column; max-width: 1240px; margin: 0 auto; box-sizing: border-box; }
.kw__head { display: flex; flex-direction: column; gap: 10px; }
.kw__top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* stepper: each tab carries its own progress line */
.kw-phases { display: grid; grid-template-columns: 3fr 2fr; }
.kw-phase { font-family: var(--font-mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.kw-phase b { font-weight: 500; color: var(--ink); }
.kw-tabs { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); }
.kw-tab { position: relative; display: grid; gap: 3px; min-height: 64px; box-sizing: border-box; padding: 10px 12px 16px; border: 0; border-radius: var(--radius-sm); background: var(--surface); box-shadow: inset 0 0 0 1px var(--hairline); color: var(--ink-3); font: inherit; text-align: left; cursor: pointer; transition: background-color var(--dur-flip) var(--ease-out), color var(--dur-flip) var(--ease-out), transform var(--dur-tap) var(--ease-out); }
.kw-tab:active { transform: scale(.98); }
.kw-tab:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.kw-tab small { font-family: var(--font-mono); font-size: 11px; }
.kw-tab b { font-weight: 500; font-size: 14.5px; }
.kw-tab.is-done { color: var(--ink-2); }
.kw-tab[aria-selected="true"] { background: var(--surface-2); color: var(--ink); }
.kw-tab__bar { position: absolute; left: 12px; right: 12px; bottom: 8px; height: 2px; border-radius: 1px; background: var(--line); overflow: hidden; }
.kw-tab__bar i { position: absolute; inset: 0; transform: scaleX(0); transform-origin: left; background: var(--ink-3); }
.kw-tab.is-done .kw-tab__bar i { transform: none; }
.kw-tab[aria-selected="true"] .kw-tab__bar i { background: linear-gradient(90deg, var(--spectrum-1), var(--spectrum-2), var(--spectrum-3), var(--spectrum-4), var(--spectrum-5)); animation: kw-fill var(--dur, 7s) linear forwards; }
.kw.is-paused .kw-tab[aria-selected="true"] .kw-tab__bar i { animation-play-state: paused; }
@keyframes kw-fill { to { transform: none; } }

.kw-ctl { display: flex; align-items: center; gap: 8px; }
.kw-count { margin-right: auto; font-family: var(--font-mono); font-size: 12px; color: var(--ink-3); }

/* the stage */
.kw-stage { border-radius: var(--radius-xl); background: var(--ground-2); box-shadow: inset 0 0 0 1px var(--hairline); box-sizing: border-box; }
.kw-panel[hidden] { display: none; }
.kw-say { margin: 0 auto; max-width: 34ch; text-align: center; font-weight: 500; letter-spacing: -.02em; text-wrap: balance; animation: kw-in .5s var(--ease-out) both; }
.kw-panes { display: grid; align-items: start; }
.kw-src, .kw-con { display: grid; gap: 4px; align-content: start; min-width: 0; box-sizing: border-box; border-radius: var(--radius-lg); background: var(--surface); box-shadow: inset 0 0 0 1px var(--hairline); }
.kw-src__head { display: flex; justify-content: space-between; gap: 12px; padding-bottom: 8px; font-family: var(--font-mono); font-size: 11px; color: var(--ink-3); }
.kw-con__head { display: flex; align-items: center; gap: 10px; padding-bottom: 8px; }
.kw-con__head b { font-weight: 500; font-size: 16px; }
.kw-con__head small { margin-left: auto; font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-3); }
.kw-src .k-doc { box-shadow: none; background: var(--surface-2); }
.kw-note { margin: 8px 0 0; font-size: 14px; color: var(--ink-3); }

/* staged reveal: set --d on each piece, in reading order */
.kw-r { opacity: 0; animation: kw-in .45s var(--ease-out) forwards; animation-delay: var(--d, 0s); }
@keyframes kw-in { from { opacity: 0; transform: translateY(10px); filter: blur(4px); } to { opacity: 1; transform: none; filter: none; } }

/* a row whose mark resolves: working dots, then the mark pops in */
.kw-row { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 11px 0; border-top: 1px solid var(--line); font-size: 15px; }
.kw-row b { font-weight: 500; }
.kw-row small { display: block; margin-top: 1px; font-size: 13px; color: var(--ink-3); }
.kw-row__end { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-3); text-align: right; }
.kw-swap { display: grid; place-items: center; width: 18px; height: 18px; }
.kw-swap > * { grid-area: 1 / 1; }
.kw-dots { display: flex; gap: 2px; animation: kw-out .25s var(--ease-exit) forwards; animation-delay: var(--m, 1s); }
.kw-dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--ink-3); animation: kw-dot 1.1s var(--ease-out) infinite; }
.kw-dots i:nth-child(2) { animation-delay: .15s; }
.kw-dots i:nth-child(3) { animation-delay: .3s; }
.kw-swap .k-mk { opacity: 0; animation: kw-pop .45s var(--ease-spring) forwards; animation-delay: var(--m, 1s); }
@keyframes kw-dot { 0%, 55%, 100% { opacity: .5; transform: none; } 25% { opacity: 1; transform: translateY(-3px); } }
@keyframes kw-out { to { opacity: 0; transform: scale(.5); } }
@keyframes kw-pop { from { opacity: 0; transform: scale(.4); } to { opacity: 1; transform: none; } }

/* a phrase that lights up on cue */
.kw-hl { padding: 0 2px; margin: 0 -2px; border-radius: 3px; color: var(--ink); background-image: linear-gradient(var(--info-soft), var(--info-soft)); background-repeat: no-repeat; background-size: 0% 100%; animation: kw-sweep .7s var(--ease-glance) forwards; animation-delay: var(--d, 0s); }
@keyframes kw-sweep { to { background-size: 100% 100%; } }

/* a path through records: dots joined by a line that draws */
.kw-path__step { position: relative; display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: 12px; align-items: center; padding: 9px 0; font-size: 14.5px; }
.kw-path__step small { display: block; font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-3); }
.kw-path__step::before { content: ""; justify-self: center; width: 8px; height: 8px; border-radius: 50%; background: var(--surface-3); box-shadow: 0 0 0 2px var(--ink-3); }
.kw-path__step.is-end::before { background: var(--ink); box-shadow: 0 0 0 2px var(--ink); }
.kw-path__step i { position: absolute; left: 8.5px; bottom: 50%; width: 1px; height: 100%; background: var(--line-strong); transform: scaleY(0); transform-origin: top; animation: kw-up .35s var(--ease-out) forwards; animation-delay: var(--d, 0s); }

/* files: what the system was given */
.kw-files { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-2); }
.kw-files li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 10px; border-radius: 6px; }
.kw-files li.is-used { background: var(--surface-2); color: var(--ink); }
.kw-files em { font-style: normal; color: var(--ink-3); }

/* two sides and a word between: Agrees, Contradicts, Can't compare */
.kw-cmp { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 12px; align-items: center; padding: 11px 10px; margin: 0 -10px; border-top: 1px solid var(--line); border-radius: 0; font-size: 15px; font-variant-numeric: tabular-nums; }
.kw-cmp > :last-child { text-align: right; }
.kw-cmp small { display: block; font-size: 12px; color: var(--ink-3); }
.kw-cmp.is-key { border-top-color: transparent; border-radius: var(--radius-sm); background: var(--info-soft); }
.kw-cmp.is-key + .kw-cmp { border-top-color: transparent; }
.kw-cmp__word { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-3); }
.kw-cmp.is-key .kw-cmp__word { color: var(--ink); font-weight: 500; }
.kw-cmp__head { border-top: 0; padding-top: 0; font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-3); }

/* the record the system writes, field by field */
.kw-out { display: grid; gap: 2px; margin: 0; padding: 14px 16px; border-radius: var(--radius-sm); background: var(--surface-2); font-family: var(--font-mono); font-size: 12.5px; line-height: 1.55; color: var(--ink-3); overflow-x: auto; }
.kw-out span { display: block; white-space: nowrap; }
.kw-out b { font-weight: 500; color: var(--ink); }

/* the verdict: the last beat of a step */
.kw-verdict { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 16px; margin-top: 8px; border-radius: var(--radius-lg); background: var(--surface-2); }
.kw-verdict .k-chip { font-size: 14.5px; padding: 6px 12px; }
.kw-verdict code { font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-2); }
.kw-verdict.kw-r { animation: kw-land .6s var(--ease-spring) forwards; animation-delay: var(--d, 0s); }
@keyframes kw-land { from { opacity: 0; transform: scale(.94); } 60% { opacity: 1; transform: scale(1.02); } to { opacity: 1; transform: none; } }
.kw-reason { margin: 10px 0 0; font-size: 15px; line-height: 1.5; color: var(--ink-2); }

/* a queue that works itself: each case waits, is worked from --w, and gets its verdict at --m */
.kq-row { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); font-size: 15px; }
.kq-row:first-child { border-top: 0; }
.kq-row b { font-weight: 500; }
.kq-id { margin-left: 6px; font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-3); }
.kq-line { display: grid; margin-top: 2px; font-size: 13px; }
.kq-line > * { grid-area: 1 / 1; }
.kq-line .q { color: var(--ink-3); animation: kq-fade .2s var(--ease-exit) forwards; animation-delay: var(--w, 0s); }
.kq-line .a { opacity: 0; color: var(--ink-3); animation: kw-in .3s var(--ease-out) forwards, kq-fade .25s var(--ease-exit) forwards; animation-delay: var(--w, 0s), var(--m, 1s); }
.kq-line .b { opacity: 0; color: var(--ink-2); animation: kw-in .4s var(--ease-out) forwards; animation-delay: var(--m, 1s); }
.kq-row .kw-dots { opacity: 0; animation: kw-in .2s var(--ease-out) forwards, kw-out .25s var(--ease-exit) forwards; animation-delay: var(--w, 0s), var(--m, 1s); }
.kq-end { display: grid; justify-items: end; gap: 4px; opacity: 0; animation: kw-pop .45s var(--ease-spring) forwards; animation-delay: var(--m, 1s); }
.kq-end code { font-family: var(--font-mono); font-size: 11px; color: var(--ink-3); }
.kq-tally { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
@keyframes kq-fade { to { opacity: 0; } }
@media (max-width: 760px) {
  .kq-row { grid-template-columns: 18px minmax(0, 1fr); }
  .kq-end { grid-column: 2; justify-items: start; }
}

/* runs that agree: one mark per run */
.kw-runs { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 13px; color: var(--ink-3); }
.kw-runs .k-mk { opacity: 0; animation: kw-pop .4s var(--ease-spring) forwards; animation-delay: calc(var(--d, 0s) + var(--i, 0) * 120ms); }
.kw-runs span { margin-left: 4px; }

@keyframes kw-up { to { transform: none; } }

@media (min-width: 761px) {
  .kw-page { padding: 44px 40px 56px; }
  .kw { gap: 16px; }
  .kw-phases, .kw-tabs { gap: 10px; }
  .kw-stage { padding: 30px 28px 28px; min-height: 548px; }
  .kw-say { font-size: 26px; line-height: 1.2; margin-bottom: 26px; }
  .kw-panes { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 20px; }
  .kw-src, .kw-con { padding: 18px 20px 20px; min-height: 356px; }
}
@media (max-width: 760px) {
  .kw-page { padding: 24px 16px 40px; }
  .kw { gap: 12px; }
  .kw-phases { display: none; }
  .kw-tabs { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 132px; gap: 8px; margin: 0 -16px; padding: 0 16px 2px; overflow-x: auto; scrollbar-width: none; }
  .kw-tabs::-webkit-scrollbar { display: none; }
  .kw-stage { padding: 20px 14px 16px; }
  .kw-say { font-size: 20px; line-height: 1.25; margin-bottom: 16px; }
  .kw-panes { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .kw-src, .kw-con { padding: 14px 14px 16px; }
  .kw-cmp { font-size: 14px; gap: 8px; }
}

/* ---------- landing: three looping explanations, CSS only, so the canvas and the site play the same frames ----------
   Every loop rests on a readable frame, and with motion off every row, panel and verdict still shows. */

/* the three questions, asked in order: three cases walk down them and leave at their verdict (12 s) */
.kl-gates { display: grid; gap: 8px; }
.kl-case { display: grid; min-height: 22px; font-family: var(--font-mono); font-size: 12px; color: var(--ink-3); }
.kl-case > span { grid-area: 1 / 1; }
.kl-case b { color: var(--ink); font-weight: 500; }
.kl-gate { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 16px 18px; border-radius: var(--radius-lg); background: var(--surface); box-shadow: inset 0 0 0 1px var(--hairline); }
.kl-gate__n { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 999px; background: var(--surface-2); font-family: var(--font-mono); font-size: 13px; color: var(--ink-2); }
.kl-gate b { display: block; font-weight: 500; font-size: 16.5px; }
.kl-gate small { display: block; margin-top: 2px; font-size: 13.5px; color: var(--ink-3); }
.kl-gate .k-chip { font-size: 13.5px; }
.kl-case > span { opacity: 0; animation: kl-cap 12s linear infinite; }
.kl-case > span:nth-child(2) { animation-delay: -8s; }
.kl-case > span:nth-child(3) { animation-delay: -4s; }
.kl-gate { animation: 12s linear infinite; }
.kl-gate.g1 { animation-name: kl-g1; }
.kl-gate.g2 { animation-name: kl-g2; }
.kl-gate.g3 { animation-name: kl-g3; }
.kl-gate .k-chip { animation: 12s var(--ease-out) infinite; }
.kl-gate.g1 .k-chip { animation-name: kl-x1; }
.kl-gate.g2 .k-chip { animation-name: kl-x2; }
.kl-gate.g3 .k-chip { animation-name: kl-x3; 
}
@keyframes kl-cap { 0%, 31% { opacity: 1; } 33%, 100% { opacity: 0; } }
@keyframes kl-g1 { 0%, 2%, 30%, 35%, 43%, 68%, 75%, 100% { background: var(--surface); } 4%, 28% { background: var(--surface-3); } 37%, 41%, 70%, 73% { background: var(--surface-2); } }
@keyframes kl-g2 { 0%, 43%, 64%, 76%, 83%, 100% { background: var(--surface); } 46%, 62% { background: var(--surface-3); } 78%, 81% { background: var(--surface-2); } }
@keyframes kl-g3 { 0%, 84%, 99%, 100% { background: var(--surface); } 87%, 97% { background: var(--surface-3); } }
@keyframes kl-x1 { 0%, 6%, 31%, 100% { opacity: .38; transform: none; } 9% { opacity: 1; transform: scale(1.08); } 12%, 28% { opacity: 1; transform: none; } }
@keyframes kl-x2 { 0%, 49%, 64%, 100% { opacity: .38; transform: none; } 52% { opacity: 1; transform: scale(1.08); } 55%, 62% { opacity: 1; transform: none; } }
@keyframes kl-x3 { 0%, 88%, 99%, 100% { opacity: .38; transform: none; } 91% { opacity: 1; transform: scale(1.08); } 93%, 97% { opacity: 1; transform: none; } }

/* one case, four files on file, four verdicts: the panels take turns, 4 s each (16 s) */
.kl-files { display: flex; gap: 6px; flex-wrap: wrap; }
.kl-file { padding: 6px 12px; border-radius: 999px; background: var(--surface-2); color: var(--ink-3); font-size: 13px; animation: kl-pill 16s linear infinite; }
.kl-stack { display: grid; }
.kl-stack > .kl-panel { grid-area: 1 / 1; animation: kl-turn 16s linear infinite; }
.kl-files > :nth-child(2), .kl-stack > :nth-child(2) { animation-delay: -12s; }
.kl-files > :nth-child(3), .kl-stack > :nth-child(3) { animation-delay: -8s; }
.kl-files > :nth-child(4), .kl-stack > :nth-child(4) { animation-delay: -4s; }
.kl-panel { display: grid; gap: 4px; align-content: start; padding: 18px 20px; border-radius: var(--radius-lg); background: var(--surface); box-shadow: inset 0 0 0 1px var(--hairline); }
.kl-panel .k-doc { box-shadow: none; background: var(--surface-2); margin-bottom: 6px; }
.kl-panel .kw-verdict { margin-top: 10px; }
.kl-why { margin: 8px 0 0; font-size: 14.5px; color: var(--ink-2); }
@keyframes kl-turn { 0% { opacity: 0; transform: translateY(6px); } 2%, 23% { opacity: 1; transform: none; } 25%, 100% { opacity: 0; transform: none; } }
@keyframes kl-pill { 0%, 24.5% { background: var(--ink); color: var(--on-primary); } 25%, 100% { background: var(--surface-2); color: var(--ink-3); } }

/* the re-test: the money left once the letter explains £41,500 falls under the line (inside the first panel) */
.kl-meter .k-meter__fill { width: 6.2%; animation: kl-drop 16s var(--ease-out) infinite; }
.kl-meter .k-meter__val { display: grid; justify-items: end; }
.kl-meter .k-meter__val > span { grid-area: 1 / 1; }
.kl-meter .k-meter__val .v1 { opacity: 0; animation: kl-v1 16s linear infinite; }
.kl-meter .k-meter__val .v2 { animation: kl-v2 16s linear infinite; }
@keyframes kl-drop { 0%, 6% { width: 98.4%; background: var(--bad); } 14%, 100% { width: 6.2%; background: var(--ok); } }
@keyframes kl-v1 { 0%, 9% { opacity: 1; } 11%, 100% { opacity: 0; } }
@keyframes kl-v2 { 0%, 9% { opacity: 0; } 11%, 100% { opacity: 1; } }

/* the same answer every run: five runs land one after another and agree (10 s) */
.kl-runs { display: grid; gap: 2px; padding: 10px 16px; border-radius: var(--radius-lg); background: var(--surface); box-shadow: inset 0 0 0 1px var(--hairline); }
.kl-run { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto 18px; gap: 12px; align-items: center; padding: 9px 0; border-top: 1px solid var(--line); font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-2); animation: kl-run 10s var(--ease-out) infinite; }
.kl-run:first-child { border-top: 0; }
.kl-run b { font-weight: 500; color: var(--ink); }
.kl-run:nth-child(2) { animation-delay: .5s; } .kl-run:nth-child(3) { animation-delay: 1s; } .kl-run:nth-child(4) { animation-delay: 1.5s; } .kl-run:nth-child(5) { animation-delay: 2s; }
@keyframes kl-run { 0% { opacity: 0; transform: translateY(6px); } 6%, 92% { opacity: 1; transform: none; } 97%, 100% { opacity: 0; } }

/* the reason is built from the facts the check used: each fact lights in turn (8 s) */
.kl-reason { margin: 0; padding: 16px 18px; border-radius: var(--radius-lg); background: var(--surface-2); font-size: 15px; line-height: 1.6; color: var(--ink-2); }
.kl-reason .kw-hl { animation: kl-fact 8s var(--ease-glance) infinite; animation-delay: var(--d, 0s); }
@keyframes kl-fact { 0% { background-size: 0% 100%; } 10%, 88% { background-size: 100% 100%; } 96%, 100% { background-size: 0% 100%; } }

@media (max-width: 760px) {
  .kl-gate { grid-template-columns: 28px minmax(0, 1fr); padding: 14px; gap: 10px; }
  .kl-gate .k-chip { grid-column: 2; justify-self: start; }
  .kl-gate__n { width: 28px; height: 28px; }
  .kl-run { grid-template-columns: 48px minmax(0, 1fr) 18px; }
  .kl-run > :nth-child(3) { display: none; }
}

/* with the OS motion setting honoured (data-k-motion="system"), every loop shows its first, readable frame */
:root[data-k-motion="system"] .kl-case > span, :root[data-k-motion="system"] .kl-stack > .kl-panel { animation: none; opacity: 0; }
:root[data-k-motion="system"] .kl-case > span:first-child, :root[data-k-motion="system"] .kl-stack > .kl-panel:first-child { opacity: 1; }
:root[data-k-motion="system"] .kl-file, :root[data-k-motion="system"] .kl-gate, :root[data-k-motion="system"] .kl-gate .k-chip,
:root[data-k-motion="system"] .kl-run, :root[data-k-motion="system"] .kl-meter .k-meter__fill, :root[data-k-motion="system"] .kl-meter .k-meter__val > span { animation: none; }
:root[data-k-motion="system"] .kl-meter .k-meter__val .v1 { opacity: 0; }
:root[data-k-motion="system"] .kl-reason .kw-hl { animation: none; background-size: 100% 100%; }
