/* Kaimei AI — scrollytelling option: The fare in pence (css/scrolly/incident.css)
   js/scrolly/incident.js adds .is-live (the section pins and scrolling down pans along a long
   incident timeline) or .is-still (reduced motion and short screens: the scenes stacked, each with
   a finished figure). Without either, the scenes read as a plain list with their cards. */

.in {
  --in-calm: #4f63f2;
  --in-shadow: #7a55f0;
  --in-hot: #d02f80;
  --in-ok: #0f8f5b;
  --in-warn: #9a6700;
  --in-bad: #d14b7a;
  --in-info: #4566e8;
  --in-ok-soft: rgba(15, 143, 91, 0.12);
  --in-bad-soft: rgba(209, 75, 122, 0.12);
  --in-info-soft: rgba(107, 140, 255, 0.14);
  --in-stage: #f5f6fa;
  position: relative;
}
html[data-theme="dark"] .in {
  --in-calm: #93a4ff;
  --in-shadow: #b69cff;
  --in-hot: #ff8cc6;
  --in-ok: #3dd68c;
  --in-warn: #ffc857;
  --in-bad: #ff6b8a;
  --in-info: #8aa4ff;
  --in-ok-soft: rgba(61, 214, 140, 0.14);
  --in-bad-soft: rgba(255, 107, 138, 0.15);
  --in-info-soft: rgba(107, 140, 255, 0.16);
  --in-stage: #0c0d13;
}

.in-head { padding-top: clamp(72px, 9vw, 128px); padding-bottom: clamp(36px, 4.5vw, 56px); }
.in-head .h2 { max-width: 760px; }
.in-head .lead { max-width: 700px; margin-top: 20px; }
.in-foot { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 14px 32px; padding-top: 28px; padding-bottom: clamp(72px, 9vw, 128px); }
.in-note { max-width: 780px; font-size: 13px; line-height: 1.55; color: var(--ink-3); text-wrap: pretty; }
.in-foot .btn-link { font-size: 14.5px; white-space: nowrap; }

.in-bar, .in-stage { display: none; }

/* ---------- Scenes: a plain list (no JS) or stacked with figures (.is-still) ---------- */
.in-steps { display: grid; gap: clamp(44px, 6vw, 80px); padding-block: 8px 12px; }
.in-step { display: grid; grid-template-columns: minmax(0, 1fr); gap: 28px; }
.in-step > * { min-width: 0; }
.in-step.has-fig { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: clamp(28px, 5vw, 72px); align-items: center; }
.in-step:not(.has-fig) .in-text { max-width: 640px; }
.in-fig:empty { display: none; }
.in-when { display: flex; align-items: center; gap: 10px; font-family: var(--font-mono); font-size: 12px; font-weight: 500; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3); }
.in-when span { display: inline-grid; place-items: center; min-width: 26px; height: 20px; padding: 0 6px; border-radius: 6px; color: var(--ink); background: var(--bg-sunken); border: 1px solid var(--line); letter-spacing: 0.04em; }
.in-h { margin-top: 12px; font-size: clamp(1.35rem, 2vw, 1.7rem); font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; text-wrap: balance; }
.in-p { margin-top: 12px; font-size: 1rem; line-height: 1.6; color: var(--ink-2); text-wrap: pretty; }
.in-still { display: block; width: 100%; height: 280px; border-radius: 16px; border: 1px solid var(--line); background: var(--in-stage); }
@media (max-width: 760px) {
  .in-step.has-fig { grid-template-columns: minmax(0, 1fr); }
  .in-still { height: 270px; }
}

/* ---------- Cards (in the list, or riding the timeline when live) ---------- */
.in-card {
  position: relative; max-width: 560px; padding: 16px 18px 18px; border-radius: 16px;
  font-size: 13px; line-height: 1.45; color: var(--ink);
  background: var(--bg-elev); border: 1px solid var(--line-strong); box-shadow: var(--shadow-md);
}
.in-card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 10px; margin-bottom: 12px; border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 600; letter-spacing: -0.005em; color: var(--ink-2); }
.in-card-head > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.in-mono { font-family: var(--font-mono); font-size: 11px; font-weight: 400; letter-spacing: 0; color: var(--ink-3); white-space: nowrap; }
.in-card-lead { font-size: 13px; color: var(--ink-2); }
.in-card-sub { margin: -2px 0 10px; font-family: var(--font-mono); font-size: 11px; color: var(--ink-3); }

.in-badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 11.5px; font-weight: 500; white-space: nowrap; color: var(--ink-2); background: var(--bg-sunken); border: 1px solid var(--line); }
.in-badge i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.in-badge.bad { color: var(--in-bad); background: var(--in-bad-soft); border-color: transparent; }
.in-badge.info { color: var(--in-info); background: var(--in-info-soft); border-color: transparent; }
.in-badge.mono { font-family: var(--font-mono); font-size: 11px; font-weight: 400; }
.in-badges { display: flex; flex-wrap: wrap; gap: 6px; }

/* the clean check on day 14 */
.in-check { max-width: 320px; }
.in-check-title { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; color: var(--in-ok); }
.in-check-title svg { width: 18px; height: 18px; flex: none; padding: 2px; border-radius: 50%; background: var(--in-ok-soft); }

/* PSI per input: columns that rise from zero */
.in-psi { --ch: 172px; --nh: 40px; --g: 1; max-width: 680px; }
.in-cols { position: relative; display: grid; grid-template-columns: 30px repeat(10, minmax(0, 1fr)) minmax(0, 1.35fr); gap: 5px; align-items: end; padding-top: 16px; }
.in-axis { position: relative; height: calc(var(--ch) + var(--nh)); }
.in-axis i { position: absolute; right: 4px; bottom: calc(var(--nh) + var(--ch) * var(--at) / 1.6); transform: translateY(50%); font-family: var(--font-mono); font-size: 10.5px; font-style: normal; line-height: 1; color: var(--ink-4); }
.in-axis i.is-th { color: var(--ink-3); }
.in-lines { position: absolute; left: 35px; right: 0; bottom: var(--nh); height: var(--ch); pointer-events: none; }
.in-lines i { position: absolute; left: 0; right: 0; bottom: calc(var(--ch) * var(--at) / 1.6); border-top: 1px solid var(--line); }
.in-lines i.is-mod { border-top: 1px dashed color-mix(in srgb, var(--in-warn) 70%, transparent); }
.in-lines i.is-sig { border-top: 1px dashed color-mix(in srgb, var(--in-bad) 70%, transparent); }
.in-col { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; min-width: 0; height: calc(var(--ch) + var(--nh)); }
.in-col-bar { width: 100%; max-width: 30px; height: calc(var(--ch) * min(var(--v) * var(--g, 1), 1.6) / 1.6); min-height: 1px; border-radius: 3px 3px 0 0; background: var(--in-ok); }
.in-col.is-warn .in-col-bar { background: var(--in-warn); }
.in-col.is-bad .in-col-bar { background: var(--in-bad); }
.in-col.is-bad:not(.is-out) .in-col-bar { box-shadow: 0 0 22px -2px color-mix(in srgb, var(--in-bad) 55%, transparent); }
.in-col-val { margin-bottom: 4px; font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.in-col.is-bad .in-col-val { color: var(--in-bad); font-weight: 500; font-size: 11.5px; }
.in-col-name { display: flex; flex-direction: column; align-items: center; gap: 2px; height: var(--nh); padding-top: 7px; font-family: var(--font-mono); font-size: 10px; line-height: 1.2; color: var(--ink-2); white-space: nowrap; }
.in-col-name small { font-size: 10px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.in-psi-note { display: none; margin-top: 8px; font-family: var(--font-mono); font-size: 11px; color: var(--ink-3); }
.in-col.is-out { padding-left: 6px; }
.in-col.is-out::before { content: ""; position: absolute; left: 0; bottom: var(--nh); height: var(--ch); border-left: 1px dashed var(--line-strong); }
.in-col.is-out .in-col-bar { max-width: 40px; opacity: 0.85; }
.in-cols::after { content: ""; position: absolute; left: 35px; right: 0; bottom: var(--nh); border-top: 1px solid var(--line-strong); }
.in-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; font-size: 11.5px; color: var(--ink-3); }
.in-legend span { display: inline-flex; align-items: center; gap: 6px; }
.in-legend span::before { content: ""; width: 10px; height: 8px; border-radius: 2px; background: var(--in-ok); }
.in-legend .warn::before { background: var(--in-warn); }
.in-legend .bad::before { background: var(--in-bad); }

/* the alert, as the dashboard shows it */
.in-alert { padding: 0; overflow: hidden; }
.in-attn { padding: 14px 18px 14px; border-bottom: 1px solid var(--line); background: var(--bg-sunken); }
.in-attn-k { margin-bottom: 8px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.in-attn-row { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--bg-elev); border: 1px solid var(--line); }
.in-attn-ico { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line); color: var(--in-bad); }
.in-attn-ico svg { width: 15px; height: 15px; }
.in-attn-t { min-width: 0; }
.in-attn-t b, .in-attn-t small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.in-attn-t b { font-size: 12.5px; font-weight: 600; }
.in-attn-t small { font-size: 11.5px; color: var(--ink-3); }
.in-insight { padding: 14px 18px 18px; }
.in-insight-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 10.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.in-insight-head .in-mono { text-transform: none; letter-spacing: 0; overflow: hidden; text-overflow: ellipsis; }
.in-insight-title { margin-bottom: 8px; font-size: 20px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.2; }
.in-insight .in-badges { margin-bottom: 10px; }
.in-insight .in-card-lead { margin-bottom: 10px; }

/* the explanation: diverging bars from the reference average */
.in-exp { --g: 1; }
.in-exp-who { margin-bottom: 12px; font-size: 12.5px; color: var(--ink-3); }
.in-exp-who b { color: var(--in-hot); font-weight: 600; }
.in-rows { display: grid; gap: 4px; }
.in-row { display: grid; grid-template-columns: minmax(96px, 1.15fr) minmax(0, 1.6fr) 44px; align-items: center; gap: 10px; padding: 4px 8px; margin: 0 -8px; border-radius: 8px; font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-2); }
.in-row-k { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.in-row-v { text-align: right; font-variant-numeric: tabular-nums; }
.in-row-bar { position: relative; height: 12px; }
.in-row-bar::before { content: ""; position: absolute; left: 50%; top: -4px; bottom: -4px; border-left: 1px solid var(--line-strong); }
.in-row-bar i { position: absolute; top: 1px; bottom: 1px; right: 50%; width: calc(var(--v) * -1 / 15 * 50% * var(--g, 1)); border-radius: 3px 0 0 3px; background: var(--away); }
.in-row.is-up .in-row-bar i { right: auto; left: 50%; width: calc(var(--v) / 15 * 50% * var(--g, 1)); border-radius: 0 3px 3px 0; background: var(--toward); }
.in-row.is-key { color: var(--ink); background: var(--in-info-soft); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--in-info) 30%, transparent); }
.in-row.is-key .in-row-k, .in-row.is-key .in-row-v { font-weight: 500; }
.in-exp-foot { display: flex; justify-content: space-between; gap: 12px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-3); }
.in-exp-foot b { color: var(--ink); font-weight: 500; }

/* the fix */
.in-fix-pair { display: grid; grid-template-columns: minmax(0, 1fr) 22px minmax(0, 1fr); align-items: center; gap: 10px; }
.in-fix-side { padding: 10px 12px; border-radius: 12px; background: var(--bg-sunken); border: 1px solid var(--line); }
.in-fix-side small { display: block; font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); }
.in-fix-side b { display: block; margin: 2px 0 6px; font-size: 1.5rem; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.in-fix-side.is-bad b { color: var(--in-hot); }
.in-fix-side span { display: block; position: relative; padding-top: 9px; font-family: var(--font-mono); font-size: 11px; color: var(--ink-2); }
.in-fix-side span::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px; border-radius: 4px; background: var(--line-strong); }
.in-fix-side span::after { content: ""; position: absolute; left: 50%; top: -2px; height: 8px; border-left: 1px solid var(--ink-3); }
.in-fix-side i { position: absolute; left: 0; top: 0; height: 4px; width: calc(var(--p) * 100%); border-radius: 4px; background: var(--ink-3); z-index: 1; }
.in-fix-side.is-bad i { background: var(--in-hot); }
.in-fix-side.is-ok i { background: var(--in-calm); }
.in-fix-arrow { width: 22px; height: 22px; color: var(--ink-4); }
.in-fix-canvas { display: none; width: 100%; height: 104px; margin-top: 12px; }
.in.is-live .in-fix-canvas, .in.is-still .in-fix-canvas { display: block; }
.in-fix-list { display: grid; gap: 4px; margin-top: 12px; counter-reset: in-fix; font-size: 12.5px; color: var(--ink-2); }
.in-fix-list li { display: flex; align-items: center; gap: 9px; counter-increment: in-fix; }
.in-fix-list li::before { content: counter(in-fix); display: grid; place-items: center; width: 18px; height: 18px; flex: none; border-radius: 50%; font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-2); border: 1px solid var(--line-strong); }
.in-code { display: block; margin-top: 12px; padding: 8px 10px; border-radius: 8px; font-size: 11px; line-height: 1.5; color: var(--ink-2); background: var(--bg-sunken); border: 1px solid var(--line); overflow-wrap: anywhere; }

/* ---------- Live: the section pins and the timeline pans sideways ---------- */
.in.is-live .in-track { height: calc(100vh + 8 * 70vh); }
.in.is-live .in-pin { position: sticky; top: 0; height: 100vh; height: 100svh; padding-top: 60px; display: flex; flex-direction: column; overflow: hidden; }
.in.is-live .in-bar { display: block; flex: none; padding-top: 12px; padding-bottom: 8px; }
.in-map { position: relative; }
.in-map-canvas { display: block; width: 100%; height: 34px; cursor: pointer; }
.in-map-labels { position: relative; height: 20px; }
.in-map-labels button {
  position: absolute; top: 4px; transform: translateX(-50%); padding: 0 4px; border-radius: 4px;
  font-family: var(--font-mono); font-size: 11px; line-height: 16px; letter-spacing: 0.02em; white-space: nowrap;
  color: var(--ink-4); transition: color 0.25s;
}
.in-map-labels button:hover, .in-map-labels button.is-on { color: var(--ink); }
.in.is-live .in-stage {
  display: block; position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden;
  background: var(--in-stage); border-block: 1px solid var(--line);
}
.in-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
/* soft edges: cards slide in and out of light rather than being cut */
.in.is-live .in-stage::before, .in.is-live .in-stage::after { content: ""; position: absolute; top: 0; bottom: 0; z-index: 2; width: 56px; pointer-events: none; }
.in.is-live .in-stage::before { left: 0; opacity: var(--in-lf, 0); background: linear-gradient(90deg, var(--in-stage), transparent); }
.in.is-live .in-stage::after { right: 0; background: linear-gradient(270deg, var(--in-stage), transparent); }
.in-flag { display: none; }
.in.is-live .in-flag { display: block; position: absolute; z-index: 3; bottom: 46px; right: 20px; font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-4); pointer-events: none; }
.in-strip { position: absolute; left: 0; top: 0; width: 1px; height: 100%; will-change: transform; }
.in-strip .in-card { position: absolute; left: 0; top: 0; max-width: none; margin: 0; transform-origin: 50% 0; }
.in-strip .in-check { width: 300px; }
.in-strip .in-psi { width: 680px; }
.in-strip .in-alert { width: 470px; }
.in-strip .in-exp { width: 470px; }
.in-strip .in-fix { width: 440px; }
.in.is-live .in-steps { flex: none; display: grid; gap: 0; padding-block: 20px 64px; }
.in.is-live .in-step { grid-area: 1 / 1; display: block; opacity: 0; transform: translateY(8px); visibility: hidden; transition: opacity 0.4s var(--ease), transform 0.55s var(--ease), visibility 0.4s; }
.in.is-live .in-step.is-active { opacity: 1; transform: none; visibility: visible; }
.in.is-live .in-fig { display: none; }
.in.is-live .in-text { display: grid; grid-template-columns: minmax(0, 4fr) minmax(0, 7fr); grid-template-rows: auto 1fr; column-gap: clamp(24px, 5vw, 72px); max-width: none; }
.in.is-live .in-when { grid-column: 1; grid-row: 1; }
.in.is-live .in-h { grid-column: 1; grid-row: 2; align-self: start; margin-top: 8px; font-size: clamp(1.3rem, 2vw, 1.65rem); }
.in.is-live .in-p { grid-column: 2; grid-row: 1 / span 2; margin-top: 0; font-size: 1rem; max-width: 640px; }

@media (max-width: 760px) {
  .in-psi { --ch: 168px; --nh: 66px; }
  .in-cols { grid-template-columns: 28px repeat(10, minmax(0, 1fr)) minmax(0, 1.35fr); gap: 4px; }
  .in-lines, .in-cols::after { left: 32px; }
  .in-psi .in-col-name { display: block; height: var(--nh); padding: 0 0 6px; text-align: right; writing-mode: vertical-rl; transform: rotate(180deg); }
  .in-psi .in-col-name small { display: none; }
  .in-psi-note { display: block; }
  .in-psi .in-col.is-out { padding-left: 3px; }
  .in.is-live .in-text { display: block; }
  .in.is-live .in-h { margin-top: 8px; font-size: 1.22rem; }
  .in.is-live .in-p { margin-top: 8px; font-size: 0.94rem; line-height: 1.55; }
  .in.is-live .in-steps { padding-block: 14px 62px; }
  .in.is-live .in-bar { padding-top: 10px; padding-bottom: 4px; }
  .in-map-canvas { height: 28px; }
  .in-map-labels { display: none; }
  .in.is-live .in-flag { display: none; }
  .in-hide-sm { display: none; }
  .in-foot { padding-top: 22px; }
}
@media (max-height: 820px) {
  .in-strip .in-fix .in-code { display: none; }
  .in-strip .in-fix-canvas { height: 88px; }
}
@media (max-height: 740px) {
  .in-strip .in-fix .in-fix-list { display: none; }
}
