/* Kaimei AI — scrollytelling option: What leaves your network (css/scrolly/private.css)
   A sticky diagram with stepping text. js/scrolly/private.js draws an SVG of your environment and Kaimei
   with the network boundary between them, and adds .is-live: the diagram pins beside the steps (above
   them on narrow screens) and re-states itself for each one. Under reduced motion and on short screens
   it adds .is-still instead: every step gets a finished frame of its own. Without JS the steps read as
   a plain list and the summary table follows them. */

.pv {
  --pv-h: clamp(460px, calc(100vh - 116px), 680px);
  --pv-gut: clamp(20px, 5vw, 40px); /* the .container padding, for the full-bleed sticky band on phones */
  --pv-yes: #4f63f2;
  --pv-hot: #c2307a;
  overflow-x: clip;
}
html[data-theme="dark"] .pv { --pv-yes: #93a4ff; --pv-hot: #ff8fc8; }

/* ---------- Intro ---------- */
.pv-intro { max-width: 640px; margin-bottom: clamp(36px, 4.5vw, 56px); }
.pv-intro .lead { margin-top: 20px; }

/* ---------- Steps: a plain list until JS takes over ---------- */
.pv-stage-col { display: none; }
.pv-steps { display: grid; gap: 20px; }
.pv-step { display: grid; gap: 20px; min-width: 0; }
.pv-card {
  position: relative; padding: 24px 26px 26px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--bg-elev); min-width: 0;
}
.pv-num {
  display: flex; align-items: center; gap: 12px;
  font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3);
}
.pv-num b { font-weight: 500; color: var(--ink); letter-spacing: 0.04em; }
.pv-num b::after { content: ""; display: inline-block; width: 14px; height: 1px; margin-left: 12px; vertical-align: middle; background: var(--line-strong); }
.pv-card h3 { margin-top: 12px; font-size: clamp(1.2rem, 1.6vw, 1.4rem); font-weight: 600; letter-spacing: -0.02em; line-height: 1.25; text-wrap: balance; }
.pv-card p { margin-top: 10px; color: var(--ink-2); font-size: 15.5px; line-height: 1.6; text-wrap: pretty; }
.pv-card p.pv-num { margin-top: 0; font-size: 12px; color: var(--ink-3); }
.pv-card p.pv-aside { font-size: 14px; color: var(--ink-3); }
.pv-card p code, .pv-mx-cap code {
  font-size: 0.86em; padding: 1px 5px; border-radius: 5px;
  background: var(--bg-sunken); border: 1px solid var(--line); color: var(--ink); white-space: nowrap;
}
.pv-card pre {
  margin: 14px 0 0; padding: 11px 14px; border-radius: 10px; background: var(--bg-code); color: #d7dbe8;
  font-size: 12.5px; line-height: 1.6; overflow-x: auto; white-space: pre;
}
.pv-card pre code { font-size: inherit; }
@media (min-width: 901px) {
  /* without JS: two steps a row, the summary beside its table */
  .pv:not(.is-live):not(.is-still) .pv-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pv:not(.is-live):not(.is-still) .pv-step:last-child { grid-column: 1 / -1; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); align-items: start; }
}
.pv-note { margin-top: clamp(28px, 4vw, 44px); max-width: 760px; font-size: 13px; line-height: 1.55; color: var(--ink-3); }

/* ---------- Summary matrix (a real table; JS also clones it into the stage) ---------- */
.pv-matrix { min-width: 0; padding: 22px 22px 18px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--bg-elev); }
.pv-matrix table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 13.5px; }
.pv-matrix th, .pv-matrix td { padding: 9px 6px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
.pv-matrix thead th { padding-top: 0; vertical-align: bottom; font-weight: 600; font-size: 13.5px; letter-spacing: -0.01em; color: var(--ink); line-height: 1.25; }
.pv-matrix thead th:first-child { width: 25%; }
.pv-mx-corner { font-family: var(--font-mono); font-size: 10.5px; font-weight: 500; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3); }
.pv-matrix tbody th { font-weight: 500; color: var(--ink-2); line-height: 1.3; }
.pv-matrix td { font-family: var(--font-mono); font-size: 12px; color: var(--ink-2); line-height: 1.3; white-space: nowrap; }
.pv-matrix td::before {
  content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 6px; vertical-align: -2px; border-radius: 99px;
}
.pv-matrix td.y { color: var(--ink); }
.pv-matrix td.y::before { width: 8px; height: 8px; margin: 0 8px 0 2px; vertical-align: 0; background: var(--grad); }
.pv-matrix td.o { color: var(--ink-3); }
.pv-matrix td.o::before { width: 8px; height: 8px; margin: 0 8px 0 2px; vertical-align: 0; box-sizing: border-box; border: 1.5px solid var(--ink-4); }
.pv-matrix td.n, .pv-matrix td.s { color: var(--ink); }
.pv-matrix td.n::before, .pv-matrix td.s::before {
  border-radius: 0; background: currentColor;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='black' stroke-width='1.4' stroke-linecap='round'><rect x='2.2' y='5.2' width='7.6' height='5.6' rx='1.3'/><path d='M3.9 5.2V3.8a2.1 2.1 0 0 1 4.2 0v1.4'/></svg>") center / contain no-repeat;
  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='black' stroke-width='1.4' stroke-linecap='round'><rect x='2.2' y='5.2' width='7.6' height='5.6' rx='1.3'/><path d='M3.9 5.2V3.8a2.1 2.1 0 0 1 4.2 0v1.4'/></svg>") center / contain no-repeat;
}
.pv-matrix td.s { color: var(--ink-2); }
.pv-matrix td.k, .pv-matrix td.x { font-family: var(--font-sans); font-size: 13px; white-space: normal; }
.pv-matrix td.k { color: var(--ink); font-weight: 500; }
.pv-matrix td.x { color: var(--ink-3); }
.pv-matrix td.k::before, .pv-matrix td.x::before { display: none; }
.pv-mx-runs th, .pv-mx-runs td { border-bottom: 0; padding-top: 12px; }
.pv-mx-runs tr { border-top: 1px solid var(--line-strong); }
.pv-mx-cap { margin-top: 12px; font-size: 12.5px; line-height: 1.5; color: var(--ink-3); }

/* ---------- The diagram (shared by the pinned stage and the still frames) ---------- */
.pv-svg { display: block; width: 100%; height: 100%; overflow: visible; }
.pv-svg text { font-family: var(--font-sans); }
.pv-zone-y { fill: var(--bg-sunken); stroke: var(--line-strong); }
.pv-zone-k { fill: var(--bg-elev); stroke: var(--line-strong); }
.pv-hatch { stroke: var(--line); stroke-width: 1; }
.pv-zlabel { font-family: var(--font-mono) !important; font-size: 10.5px; font-weight: 500; letter-spacing: 0.12em; fill: var(--ink-2); }
.pv-zsub { font-family: var(--font-mono) !important; font-size: 10.5px; fill: var(--ink-3); }
.pv-bline { stroke: var(--ink-4); stroke-width: 1; stroke-dasharray: 2 5; }
.pv-bglow { stroke-width: 1; opacity: 0.55; }
.pv-bpill { fill: var(--bg); stroke: var(--line-strong); }
.pv-btext { font-family: var(--font-mono) !important; font-size: 9.5px; font-weight: 500; letter-spacing: 0.1em; fill: var(--ink-2); }

.pv-cardbg { fill: var(--bg-elev); stroke: var(--line-strong); }
.pv-cardring { fill: none; stroke-width: 1.25; }
.pv-ctitle { font-size: 13px; font-weight: 600; letter-spacing: -0.01em; fill: var(--ink); }
.pv-csub { font-family: var(--font-mono) !important; font-size: 10.5px; fill: var(--ink-3); }
.pv-icon { fill: none; stroke: var(--ink-2); stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }
.pv-badgebg { fill: var(--bg-sunken); stroke: var(--line-strong); }
.pv-badget { font-family: var(--font-mono) !important; font-size: 9.5px; letter-spacing: 0.02em; fill: var(--ink-2); }
.pv-lockbody { fill: none; stroke: var(--ink-2); stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }

.pv-glyph-w { stroke: var(--line-strong); stroke-width: 0.8; }
.pv-glyph-n { fill: var(--bg-elev); stroke: var(--ink-3); stroke-width: 1.1; }
.pv-glyph-b { fill: var(--ink-4); opacity: 0.7; }

.pv-slabel { font-family: var(--font-mono) !important; font-size: 9.5px; font-weight: 500; letter-spacing: 0.1em; fill: var(--ink-3); }
.pv-sval { font-family: var(--font-mono) !important; font-size: 11px; fill: var(--ink); }
.pv-sval.is-muted { fill: var(--ink-4); }
.pv-sval.is-hot:not(.is-muted) { fill: var(--pv-hot); font-weight: 500; }
.pv-sring { fill: var(--bg-elev); stroke: var(--line-strong); stroke-width: 1.25; }
.pv-srule { stroke: var(--line); }

.pv-lane { fill: none; stroke-width: 1.4; stroke-linecap: round; }
.pv-llabel { font-family: var(--font-mono) !important; font-size: 9.5px; fill: var(--ink-2); paint-order: stroke; stroke: var(--bg); stroke-width: 4px; stroke-linejoin: round; }

.pv-tokbg { fill: var(--bg-elev); stroke-width: 1.25; }
.pv-tokt { font-family: var(--font-mono) !important; font-size: 11px; fill: var(--ink); }
.pv-staybg { fill: var(--bg-sunken); stroke: var(--ink-3); stroke-width: 1.1; stroke-dasharray: 3 2.5; }
.pv-stayt { font-family: var(--font-mono) !important; font-size: 11px; fill: var(--ink-2); }
.pv-lockc { fill: var(--bg-elev); stroke: var(--ink-3); stroke-width: 1.1; }
.pv-attrt { font-family: var(--font-mono) !important; font-size: 10.5px; fill: var(--ink-2); }
.pv-attrv { font-family: var(--font-mono) !important; font-size: 10.5px; fill: var(--ink); }
.pv-attrh { font-family: var(--font-mono) !important; font-size: 9px; letter-spacing: 0.04em; fill: var(--ink-3); }
.pv-attrbar { fill: #e86bff; }
html[data-theme="dark"] .pv-attrbar { fill: #ff7cc4; }

.pv-stlabel { font-family: var(--font-mono) !important; font-size: 9.5px; font-weight: 500; letter-spacing: 0.1em; fill: var(--ink-3); }
.pv-stval { font-size: 12.5px; font-weight: 500; fill: var(--ink); letter-spacing: -0.005em; }
.pv-stval.is-muted { fill: var(--ink-3); }
.pv-legt { font-size: 11.5px; fill: var(--ink-3); }

/* ---------- Pinned layout (.is-live) ---------- */
.pv.is-live .pv-stage-col { display: block; }
.pv-stage { position: relative; }
.pv.is-live .pv-step > .pv-matrix {
  /* the table stays in the DOM for assistive technology; the stage shows a copy */
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.pv-stage .pv-matrix {
  position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%);
  padding: clamp(18px, 2.2vw, 26px); box-shadow: var(--shadow-lg); visibility: hidden; opacity: 0;
}
.pv.is-live .pv-card { transition: opacity 0.45s var(--ease), border-color 0.45s var(--ease), box-shadow 0.45s var(--ease); }
.pv.is-live .pv-step:not(.is-active) .pv-card { opacity: 0.32; }
.pv.is-live .pv-card pre { transition: opacity 0.45s var(--ease); }
.pv.is-live .pv-step:not(.is-active) .pv-card pre { opacity: 0.3; }
.pv.is-live .pv-step.is-active .pv-card { border-color: var(--line-strong); box-shadow: var(--shadow-md); }

@media (min-width: 901px) {
  .pv.is-live .pv-grid {
    display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); grid-template-rows: auto auto;
    column-gap: clamp(36px, 5vw, 80px);
  }
  .pv.is-live .pv-intro { grid-column: 1; grid-row: 1; min-height: 64vh; margin: 0; display: flex; flex-direction: column; justify-content: center; padding-bottom: 6vh; }
  .pv.is-live .pv-steps { grid-column: 1; grid-row: 2; display: block; }
  .pv.is-live .pv-stage-col { grid-column: 2; grid-row: 1 / span 2; }
  .pv.is-live .pv-stage { position: sticky; top: calc(60px + (100vh - 60px - var(--pv-h)) / 2); height: var(--pv-h); }
  .pv.is-live .pv-step { min-height: 78vh; display: flex; align-items: center; }
  .pv.is-live .pv-step:last-child { min-height: 92vh; }
  .pv.is-live .pv-card { width: 100%; }
}

/* narrow: the diagram is a sticky band under the header and the steps scroll up beneath it */
@media (max-width: 900px) {
  .pv { --pv-h: clamp(320px, 40svh, 440px); }
  .pv.is-live .pv-grid { display: flex; flex-direction: column; }
  .pv.is-live .pv-intro { order: 0; }
  .pv.is-live .pv-stage-col {
    order: 1; position: sticky; top: 60px; z-index: 3;
    margin-inline: calc(-1 * var(--pv-gut)); padding: 8px var(--pv-gut) 10px; background: var(--bg);
  }
  .pv.is-live .pv-stage-col::after {
    content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 28px; pointer-events: none;
    background: linear-gradient(var(--bg), color-mix(in srgb, var(--bg) 0%, transparent));
  }
  .pv.is-live .pv-stage { height: var(--pv-h); max-width: 720px; margin-inline: auto; }
  .pv.is-live .pv-steps { order: 2; display: block; position: relative; z-index: 1; padding-top: 26vh; }
  .pv.is-live .pv-step { min-height: 62vh; display: flex; align-items: center; }
  .pv.is-live .pv-step:last-child { min-height: 70vh; }
  .pv.is-live .pv-card { width: 100%; max-width: 640px; margin-inline: auto; padding: 20px 20px 22px; }
  .pv.is-live .pv-card p { font-size: 15px; }
  .pv.is-live .pv-card p.pv-aside { font-size: 13.5px; }
  .pv.is-live .pv-step:not(.is-active) .pv-card { opacity: 0.4; }
}
/* tablets: room for the side-by-side drawing above the text */
@media (max-width: 900px) and (min-width: 600px) and (min-height: 900px) {
  .pv { --pv-h: clamp(480px, 50svh, 560px); }
}
/* under the sticky diagram the text has about half a phone screen: the code waits for the static list */
@media (max-width: 640px), (max-width: 900px) and (max-height: 760px) {
  .pv.is-live .pv-card pre { display: none; }
}

/* ---------- Still frames (.is-still: reduced motion, short screens) ---------- */
.pv-still { display: none; }
.pv.is-still .pv-still { display: block; min-width: 0; border-radius: var(--radius); overflow: hidden; }
.pv.is-still .pv-still svg { height: 580px; }
@media (min-width: 901px) {
  .pv.is-still .pv-step { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: clamp(28px, 4vw, 56px); align-items: center; }
  .pv.is-still .pv-step .pv-card { grid-column: 1; grid-row: 1; }
  .pv.is-still .pv-step .pv-still { grid-column: 2; grid-row: 1; }
  .pv.is-still .pv-step > .pv-matrix { grid-column: 2; grid-row: 1; }
  .pv.is-still .pv-steps { gap: 40px; }
}
@media (max-width: 900px) {
  .pv.is-still .pv-still { order: -1; }
  .pv.is-still .pv-still svg { height: 400px; }
}
@media (max-width: 900px) and (min-width: 560px) {
  .pv.is-still .pv-still svg { height: 470px; }
}

.pv-s { display: none; }

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
  /* the table in the page keeps its type size and scrolls sideways inside its card */
  .pv-step > .pv-matrix { overflow-x: auto; padding: 16px 14px 14px; }
  .pv-step > .pv-matrix table { min-width: 560px; }
  /* the copy in the pinned stage is a compact summary of that table */
  .pv-stage .pv-matrix { padding: 10px 10px 8px; }
  .pv-stage .pv-matrix table { font-size: 12px; }
  .pv-stage .pv-matrix th, .pv-stage .pv-matrix td { padding: 6px 3px; }
  .pv-stage .pv-matrix thead th { font-size: 11.5px; padding-bottom: 7px; }
  .pv-stage .pv-matrix thead th:first-child { width: 29%; }
  .pv-stage .pv-mx-corner { font-size: 8.5px; letter-spacing: 0.06em; display: block; line-height: 1.35; }
  .pv-stage .pv-matrix td { font-size: 11.5px; }
  /* "optional" is too wide for four phone columns; the full table outside the stage keeps the word */
  .pv-stage .pv-matrix td.o { font-size: 0; }
  .pv-stage .pv-matrix td.o::after { content: "opt."; font-size: 11.5px; }
  .pv-stage .pv-matrix td::before { display: none; }
  .pv-stage .pv-matrix td.y { font-weight: 500; }
  .pv-stage .pv-matrix td.o { color: var(--ink-4); }
  .pv-stage .pv-matrix td.k, .pv-stage .pv-matrix td.x { font-size: 11.5px; }
  /* the cards under the pinned band must fit the space left below it */
  .pv.is-live .pv-card { padding: 16px 16px 18px; }
  .pv.is-live .pv-card p { font-size: 14.5px; line-height: 1.55; }
  .pv.is-live .pv-card p.pv-aside { font-size: 13px; }
  .pv-stage .pv-matrix tbody th { font-size: 11.5px; white-space: nowrap; }
  .pv-stage .pv-l { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
  .pv-stage .pv-s { display: inline; }
  .pv-stage .pv-mx-cap { display: none; }
}
