/* DN-MOPD project page, p5b_scrolly: scrollytelling Method section (one training iteration in five steps).
   Loaded after style.css. Everything here is scoped to .sy* classes or #method, so it can merge with other directions.
   Without JS (no html.sy-js) the step cards stack as plain content and the diagram shows every stage at full strength.
   Motion only animates transform, opacity and stroke-dashoffset, and only while .sy-play is set by scrolly.js
   (section on screen, tab visible, no reduced-motion preference).
   Merge (p5_all): the narrow-screen zoom moves one wrapper group (.sy-cam, created by scrolly.js) with a CSS transform
   transition instead of rewriting the viewBox every frame. */

.sy-hint { display: none; }
.sy-js .sy-hint {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 16px;
  font-size: .9rem; font-weight: 500; color: var(--teal-ink);
}

/* ------------------------------------------------------------------ layout */
.sy { margin-top: 52px; display: grid; grid-template-columns: minmax(0, .92fr) minmax(0, 1.08fr); gap: 48px; }
.sy-fig-col { order: 2; min-width: 0; }
.sy-sticky { position: sticky; top: calc(var(--nav-h) + 18px); }
.sy-fig {
  margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 22px;
  box-shadow: var(--shadow-lg); padding: 16px 16px 12px;
}
.sy-svg { display: block; width: 100%; height: auto; max-height: calc(100vh - var(--nav-h) - 156px); margin: 0 auto; overflow: hidden; }
.sy-cap {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px; padding: 10px 4px 0;
  border-top: 1px solid var(--border-soft); margin-top: 8px; font-size: .84rem; line-height: 1.45; color: var(--muted);
}
.sy-count b { color: var(--heading); font-weight: 650; }
.sy-prog { display: none; gap: 4px; }
.sy-js .sy-prog { display: inline-flex; }
.sy-prog i { width: 16px; height: 4px; border-radius: 2px; background: var(--surface-3); transition: background-color .3s; }
.sy-prog i.done { background: color-mix(in srgb, var(--teal) 40%, var(--surface-3)); }
.sy-prog i.on { background: var(--teal); }
.sy-note { flex-basis: 100%; font-size: .8rem; }

.sy-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 20px; min-width: 0; }
.sy-js .sy-steps { gap: 0; }
.sy-js .sy-step { min-height: min(92vh, 900px); display: flex; align-items: center; padding: 7vh 0; }
.sy-js .sy-step:first-child { min-height: min(78vh, 760px); align-items: flex-start; padding-top: 0; }
.sy-js .sy-step:last-child { min-height: min(86vh, 820px); }

/* ------------------------------------------------------------------ step cards */
.sy-card {
  width: 100%; min-width: 0; display: grid; gap: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 24px 26px;
  box-shadow: var(--shadow-sm); transition: border-color .3s ease, box-shadow .3s ease;
}
.sy-js .sy-step.is-active .sy-card {
  border-color: color-mix(in srgb, var(--teal) 60%, var(--border));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--teal) 60%, transparent), var(--shadow);
}
.sy-kick {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  font-size: 12.5px; font-weight: 650; letter-spacing: .09em; text-transform: uppercase; color: var(--muted);
}
.sy-n {
  width: 28px; height: 28px; border-radius: 9px; display: inline-grid; place-items: center; flex: none;
  font-family: var(--font-mono); font-size: 13px; letter-spacing: 0; background: var(--heading); color: var(--surface);
}
.sy-step.sy-dn .sy-n { background: var(--btn-bg); color: var(--btn-fg); }
.sy-tag {
  margin-left: auto; text-transform: none; letter-spacing: 0; font-size: 12px; font-weight: 600;
  color: var(--teal-ink); background: var(--teal-wash); padding: 3px 10px; border-radius: 999px;
}
.sy-card h3 { font-family: var(--font-display); font-weight: 700; font-size: 1.32rem; line-height: 1.25; letter-spacing: -.015em; text-wrap: balance; }
.sy-card p { font-size: .98rem; line-height: 1.65; color: var(--text-2); }
.sy-card p b { color: var(--heading); font-weight: 650; white-space: nowrap; }
.sy-card .sy-fine { font-size: .9rem; color: var(--muted); }
.sy-card .tex-display { margin: -4px 0; }

/* Algorithm 1, split over the cards */
.sy-algo { border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border-soft); padding: 10px 10px 8px; }
.sy-algo-tag { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); padding: 0 6px 6px; }
.sy-card .sy-algo-tag { font-size: 11.5px; line-height: 1.4; color: var(--muted); }
.sy-algo ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.sy-algo ol > li {
  display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 10px; align-items: start;
  padding: 6px 8px; border-radius: 9px; border-left: 2px solid transparent; font-size: .93rem; line-height: 1.55; color: var(--text);
}
.sy-algo ol > li.sy-dn { background: var(--teal-wash); border-left-color: var(--teal); }
.sy-algo .sy-ln {
  width: 22px; height: 22px; border-radius: 6px; display: inline-grid; place-items: center; margin-top: 1px;
  font-family: var(--font-mono); font-size: 11.5px; background: var(--surface-3); color: var(--heading);
}
.sy-algo li.sy-dn .sy-ln { background: var(--btn-bg); color: var(--btn-fg); font-weight: 600; }
.sy-algo ul { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 2px; }
.sy-algo ul li { position: relative; padding-left: 14px; }
.sy-algo ul li::before { content: ""; position: absolute; left: 0; top: .78em; width: 6px; height: 1.5px; background: var(--muted); }

/* first-batch numbers */
.sy-data { display: grid; gap: 10px; border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px 8px; background: var(--surface); }
.sy-size { display: flex; align-items: center; gap: 10px; font-size: .85rem; color: var(--muted); }
.sy-size[hidden] { display: none; }
.sy-seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-3); border-radius: 10px; }
.sy-seg button {
  font: 600 13px/1 var(--font-body); color: var(--text-2); background: transparent; border: 0; border-radius: 7px;
  min-width: 44px; min-height: 30px; padding: 0 12px; cursor: pointer; transition: background-color .15s, color .15s;
}
.sy-seg button:hover { color: var(--heading); }
.sy-seg button[aria-pressed="true"] { background: var(--surface); color: var(--heading); box-shadow: var(--shadow-sm); }
.sy-tbl { width: 100%; border-collapse: collapse; font-size: .92rem; font-variant-numeric: tabular-nums; }
.sy-tbl caption { caption-side: top; text-align: left; font-size: .82rem; color: var(--muted); padding: 0 0 6px; }
.sy-tbl th, .sy-tbl td { padding: 6px 6px; border-bottom: 1px solid var(--border-soft); text-align: right; font-weight: 500; color: var(--text); }
.sy-tbl thead th { font-size: .82rem; color: var(--muted); font-weight: 600; border-bottom-color: var(--border); }
.sy-tbl th:first-child { text-align: left; }
.sy-tbl tbody th { font-weight: 600; color: var(--heading); white-space: nowrap; }
.sy-tbl tbody th i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: 1px; background: var(--dc); }
.sy-tbl td { font-family: var(--font-mono); font-size: .86rem; }
.sy-tbl td.sy-wcell { font-weight: 600; color: var(--heading); }
.sy-tbl td.is-clipped::after { content: " floor"; font-family: var(--font-body); font-size: .74rem; font-weight: 600; color: var(--purple-ink); }
.sy-tbl tbody tr:last-child th, .sy-tbl tbody tr:last-child td { border-bottom: 0; color: var(--muted); }

.sy-math { --dc: var(--gold); --dk: var(--gold-ink); }
.sy-code { --dc: var(--blue); --dk: var(--blue-ink); }
.sy-if { --dc: var(--purple); --dk: var(--purple-ink); }
.sy-all { --dc: var(--heading); --dk: var(--heading); }

/* ------------------------------------------------------------------ the diagram */
.sy-svg text { font-family: var(--font-body); fill: var(--text); }
.sy-svg .sy-hd { font-size: 12.5px; font-weight: 700; letter-spacing: .08em; fill: var(--heading); }
.sy-svg .sy-bn { font-size: 12px; font-weight: 700; fill: var(--surface); }
.sy-b-ink { fill: var(--heading); }
.sy-b-teal { fill: var(--btn-bg); }
.sy-svg .sy-b-teal + .sy-bn { fill: var(--btn-fg); }
.sy-paper { fill: var(--surface); stroke: var(--border-strong); stroke-width: 1.3; }
.sy-strong { stroke: var(--heading); stroke-width: 1.6; }
.sy-dash { stroke: var(--muted); stroke-dasharray: 4 3; }
.sy-svg .sy-lb { font-size: 13px; font-weight: 650; fill: var(--heading); }
.sy-svg .sy-lb-lg { font-size: 14.5px; }
.sy-svg .sy-mi { font-family: KaTeX_Math, "Times New Roman", serif; font-style: italic; font-weight: 400; }
.sy-svg .sy-mx { font-family: KaTeX_Main, "Times New Roman", serif; font-size: 15px; fill: var(--heading); }
.sy-svg .sy-mx-sm { font-size: 14px; }
.sy-svg .sy-sub, .sy-svg .sy-sup { font-size: 11px; }
.sy-svg .sy-sm { font-size: 12px; fill: var(--muted); }
.sy-svg .sy-sm2 { font-size: 12.5px; fill: var(--text-2); }
.sy-svg .sy-teal-t { fill: var(--teal-ink); }
.sy-chip { fill: var(--dc); fill-opacity: .12; stroke: var(--dc); stroke-width: 1.2; }
.sy-svg .sy-chip-t { font-size: 12px; font-weight: 650; fill: var(--dk); }
.sy-dfill { fill: var(--dc); }
.sy-tok { fill: var(--dc); fill-opacity: .3; stroke: var(--dc); stroke-width: 1; }
.sy-teacher { fill: var(--dc); fill-opacity: .1; stroke: var(--dc); stroke-width: 1.6; }
.sy-svg .sy-tt { font-size: 13px; font-weight: 650; fill: var(--dk); }
.sy-lock-s { fill: none; stroke: var(--dc); stroke-width: 1.8; }
.sy-arr { fill: none; stroke: var(--heading); stroke-width: 1.5; }
.sy-route { fill: none; stroke: var(--dc); stroke-width: 1.8; }
.sy-cache { stroke: var(--muted); }
.sy-svg .sy-flow { stroke-dasharray: 5 4; }
.sy-sc { fill: var(--dc); }
.sy-roll { fill: var(--muted); fill-opacity: .5; }
.sy-fchip { fill: var(--teal); fill-opacity: .1; stroke: var(--teal); stroke-width: 1.3; }
.sy-svg .sy-dl { font-size: 12.5px; font-weight: 650; fill: var(--dk); }
.sy-axis { stroke: var(--border-strong); stroke-width: 1; }
.sy-guide { fill: none; stroke: var(--teal); stroke-width: 1.4; stroke-dasharray: 3 3; }
.sy-band { stroke: var(--dc); stroke-opacity: .22; stroke-width: 12; }
.sy-end { stroke: var(--dc); stroke-width: 1.8; }
.sy-tick { stroke: var(--dc); stroke-width: 1.3; }
.sy-svg .sy-num { font-family: var(--font-mono); font-size: 12.5px; fill: var(--heading); }
.sy-wbox { fill-opacity: .14; }
.sy-wchip.is-clipped .sy-wbox { stroke-dasharray: 3 2; }
.sy-rule { stroke: var(--border); stroke-width: 1; }
.sy-base { stroke: var(--border-strong); stroke-width: 1; }
.sy-ghost rect { fill: none; stroke: var(--dc); stroke-width: 1; stroke-dasharray: 2 2; }
.sy-solid rect { fill: var(--dc); fill-opacity: .85; }
.sy-sz, .sy-norm, .sy-solid, .sy-pulse, .sy-cam { transform-box: view-box; transform-origin: 0 0; }
.sy-sz { transition: transform .6s cubic-bezier(.2, .7, .2, 1); }
.sy-solid { transform: scaleY(var(--w)); transition: transform .6s cubic-bezier(.2, .7, .2, 1); }
.sy-ph-b, .sy-ph-d { opacity: 0; }
.sy-upd { fill: var(--heading); }
.sy-svg .sy-upd-t { font-size: 14.5px; font-weight: 650; fill: var(--surface); }
.sy-ring { fill: none; stroke: var(--teal); stroke-width: 2; }
.sy-pulse { opacity: 0; }
.sy-loop { fill: none; stroke: var(--heading); stroke-width: 1.5; }
.sy-dnbox { fill: var(--teal); fill-opacity: .045; stroke: var(--teal); stroke-opacity: .5; stroke-width: 1.3; }
.sy-dntag { fill: var(--btn-bg); }
.sy-svg .sy-dntag-t { font-size: 12px; font-weight: 700; letter-spacing: .03em; fill: var(--btn-fg); }
.sy-mk-ink { fill: var(--heading); }
.sy-mk-teal { fill: var(--teal); }
.sy-mk-mut { fill: var(--muted); }
.sy-mk-math { fill: var(--gold); }
.sy-mk-code { fill: var(--blue); }
.sy-mk-if { fill: var(--purple); }

/* active step: its part stays, the rest fades */
.sy-js .sy-svg[data-step] .sy-hl { opacity: .16; }
.sy-js .sy-svg[data-step="1"] .sy-s1, .sy-js .sy-svg[data-step="2"] .sy-s2, .sy-js .sy-svg[data-step="3"] .sy-s3,
.sy-js .sy-svg[data-step="4"] .sy-s4, .sy-js .sy-svg[data-step="5"] .sy-s5 { opacity: 1; }

@media (prefers-reduced-motion: no-preference) {
  .sy-js .sy-svg .sy-hl { transition: opacity .45s ease; }
  /* camera zoom into the active stage (narrow screens): same 620 ms ease-in-out cubic as p5b's viewBox tween */
  .sy-cam.sy-cam-on { transition: transform .62s cubic-bezier(.65, 0, .35, 1); }

  /* dashes flow along the connectors of the active part */
  .sy-play .sy-svg[data-step="1"] .sy-s1 .sy-flow, .sy-play .sy-svg[data-step="2"] .sy-s2 .sy-flow, .sy-play .sy-svg[data-step="3"] .sy-s3 .sy-flow,
  .sy-play .sy-svg[data-step="4"] .sy-s4 .sy-flow, .sy-play .sy-svg[data-step="5"] .sy-s5 .sy-flow { animation: sy-flow .9s linear infinite; }

  /* 1. tokens stream out of the student */
  .sy-play .sy-svg[data-step="1"] .sy-tok {
    animation: sy-type 4.4s linear infinite backwards;
    animation-delay: calc(var(--i) * 110ms + var(--r) * 280ms);
  }
  /* 2. the teachers score token by token */
  .sy-play .sy-svg[data-step="2"] .sy-sc { animation: sy-blink 1.8s ease-in-out infinite backwards; animation-delay: calc(var(--i) * 95ms); }
  /* 3. each band moves between its raw spread and w_d times it (the pooled spread, unless clipped) */
  .sy-play .sy-svg[data-step="3"] .sy-norm { animation: sy-norm 5.6s ease-in-out infinite; }
  .sy-play .sy-svg[data-step="3"] .sy-ph-a { animation: sy-pa 5.6s ease-in-out infinite; }
  .sy-play .sy-svg[data-step="3"] .sy-ph-b { animation: sy-pb 5.6s ease-in-out infinite; }
  /* 4. advantages move between A and w_d A; signs never flip */
  .sy-play .sy-svg[data-step="4"] .sy-solid { animation: sy-resc 5.2s ease-in-out infinite; }
  .sy-play .sy-svg[data-step="4"] .sy-ph-c { animation: sy-pc 5.2s ease-in-out infinite; }
  .sy-play .sy-svg[data-step="4"] .sy-ph-d { animation: sy-pd 5.2s ease-in-out infinite; }
  /* 5. the update fires and the loop carries it to the next iteration */
  .sy-play .sy-svg[data-step="5"] .sy-pulse { animation: sy-pulse 2.2s ease-out infinite; }
}
@keyframes sy-flow { to { stroke-dashoffset: -18; } }
@keyframes sy-type { 0% { opacity: .1; } 7% { opacity: 1; } 78% { opacity: 1; } 90%, 100% { opacity: .1; } }
@keyframes sy-blink { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
@keyframes sy-norm { 0%, 26% { transform: scaleX(1); } 46%, 82% { transform: scaleX(var(--w)); } 100% { transform: scaleX(1); } }
@keyframes sy-pa { 0%, 30% { opacity: 1; } 40%, 86% { opacity: 0; } 96%, 100% { opacity: 1; } }
@keyframes sy-pb { 0%, 30% { opacity: 0; } 40%, 86% { opacity: 1; } 96%, 100% { opacity: 0; } }
@keyframes sy-resc { 0%, 24% { transform: scaleY(1); } 44%, 82% { transform: scaleY(var(--w)); } 100% { transform: scaleY(1); } }
@keyframes sy-pc { 0%, 28% { opacity: 0; } 38%, 86% { opacity: 1; } 96%, 100% { opacity: 0; } }
@keyframes sy-pd { 0%, 28% { opacity: 1; } 38%, 86% { opacity: 0; } 96%, 100% { opacity: 1; } }
@keyframes sy-pulse { 0% { opacity: .75; transform: scale(1, 1); } 100% { opacity: 0; transform: scale(1.05, 1.5); } }

@media (prefers-reduced-motion: reduce) {
  .sy-sz, .sy-solid, .sy-card, .sy-prog i { transition: none; }
}

/* ------------------------------------------------------------------ below the scrolly */
#method .practice { margin-top: 24px; }
#method .sy-full { margin-top: 40px; }

/* ------------------------------------------------------------------ narrow: diagram sticks to the top, cards scroll under it,
   and scrolly.js zooms the viewBox into the active stage (data-vb) so labels stay legible */
@media (max-width: 980px) {
  .sy { grid-template-columns: minmax(0, 1fr); gap: 20px; margin-top: 40px; }
  .sy-fig-col { order: 0; }
  .sy-sticky { position: static; }
  .sy-fig { max-width: 640px; margin: 0 auto; }
  .sy-js .sy { gap: 0; }
  .sy-js .sy-fig-col {
    position: sticky; top: var(--nav-h); z-index: 6; padding: 8px 0 20px;
    background: linear-gradient(to bottom, var(--bg-alt) 84%, transparent);
  }
  .sy-js .sy-fig { padding: 8px 8px 6px; border-radius: 16px; }
  .sy-js .sy-svg { height: min(40vh, 340px); max-height: none; }
  .sy-js .sy-cap { margin-top: 4px; padding: 6px 4px 0; font-size: 12px; }
  .sy-js .sy-note { display: none; }
  .sy-js .sy-prog { margin-left: auto; }
  .sy-js .sy-step, .sy-js .sy-step:first-child, .sy-js .sy-step:last-child { min-height: 0; padding: 11vh 0; }
  .sy-js .sy-step:first-child { padding-top: 12px; }
  .sy-js .sy-step:last-child { padding-bottom: 22vh; }
  .sy-card { box-shadow: var(--shadow); }
}
@media (max-width: 980px) and (max-height: 520px) {
  .sy-js .sy-fig-col { position: static; }
}
@media (max-width: 680px) {
  .sy-card { padding: 20px 16px; gap: 12px; border-radius: 18px; }
  .sy-card h3 { font-size: 1.18rem; }
  .sy-tag { margin-left: 0; }
  .sy-data { padding: 10px 10px 6px; }
  .sy-tbl th, .sy-tbl td { padding: 6px 4px; }
  .sy-algo ol > li { padding: 6px 6px; gap: 8px; }
}
@media print {
  .sy-js .sy-svg[data-step] .sy-hl { opacity: 1; }
  .sy-cam { transform: none !important; }
  .sy-js .sy-fig-col { position: static; }
}
