/* The story: a plain study chat turns into the lecture.
   It plays once by itself when it is on screen, so it does not depend on how fast somebody scrolls.
   The script walks through the steps and sets data-step; each step is a timed CSS transition.
   The default look without a step is the finished lecture. That is what visitors with reduced motion see.
   Steps: 0 chat, 1 the request is typed, 2 it is sent and read, 3 the lecture is ready, 4 the chat becomes
   the board and Iana walks in, 5 the circle, 6 the slices, 7 the slices lined up, 8 the result. */
.story {
  --typed: 1; --sent: 1; --read: 0; --gen: 1;
  --dim: 1; --walk: 1;
  --bar: 1; --prog: 1;
  --rail: 1;
  position: relative;
  padding-block: clamp(48px, 8vw, 104px);
}
.story[data-step="0"] { --typed: 0; --sent: 0; --read: 0; --gen: 0; --dim: 0; --walk: 0; --bar: 0; --prog: 0; --rail: .04; }
.story[data-step="1"] { --typed: 1; --sent: 0; --read: 0; --gen: 0; --dim: 0; --walk: 0; --bar: 0; --prog: 0; --rail: .36; }
.story[data-step="2"] { --typed: 1; --sent: 1; --read: 1; --gen: 0; --dim: 0; --walk: 0; --bar: 0; --prog: 0; --rail: .68; }
.story[data-step="3"] { --typed: 1; --sent: 1; --read: 0; --gen: 1; --dim: 0; --walk: 0; --bar: 0; --prog: 0; --rail: .68; }
/* Going back to the start must not play the story backwards. */
.story.st-reset, .story.st-reset * { transition: none !important; animation: none !important; }

.st-grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: clamp(28px, 5vw, 72px); align-items: center; }
.st-copy h2 { font-size: clamp(1.875rem, 3.6vw, 2.75rem); max-width: 14ch; }

/* The four steps double as a progress rail. Numbers sit in a fixed square with tabular figures,
   so every digit has the same width and centre. */
.st-rail { position: relative; display: grid; gap: 22px; margin: 28px 0 0; padding: 0; list-style: none; }
.st-rail::before, .st-rail::after { content: ""; position: absolute; left: 17px; top: 18px; bottom: 18px; width: 2px; border-radius: 1px; }
.st-rail::before { background: var(--rule); }
.st-rail::after { background: var(--gold); transform-origin: top; scale: 1 var(--rail); transition: scale 600ms ease; }
.st-rail li { position: relative; display: grid; grid-template-columns: 36px 1fr; gap: 16px; align-items: start; }
.st-n {
  position: relative; z-index: 1; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: var(--board); color: var(--chalk); font: 700 1rem/1 var(--sans); font-variant-numeric: tabular-nums;
  box-shadow: 0 0 0 4px var(--paper); transition: background-color 300ms ease, color 300ms ease;
}
.st-rail h3 { padding-top: 6px; font-size: 1.125rem; letter-spacing: 0; line-height: 1.25; }
.st-rail p { margin-top: 4px; color: var(--muted); max-width: 38ch; }
.st-rail code { padding: 1px 6px; border-radius: 6px; background: var(--sunken); font: 600 .9375em var(--sans); }
.st-rail li > div { transition: opacity 300ms ease; }
@media (prefers-reduced-motion: no-preference) {
  .story[data-step] .st-rail li > div { opacity: .45; }
  .story[data-step] .st-rail li[data-on] > div { opacity: 1; }
  .story[data-step] .st-rail li[data-on] .st-n { background: var(--gold); color: #1f2b28; }
}

/* The window. Its colour, frame and corners move from a chat app to a board in a wooden frame. */
.st-stage { padding: 12px; }
.st-subjects { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 16px; }
.st-subjects button {
  min-height: 36px; padding: 4px 14px; border: 1px solid var(--rule); border-radius: 999px; background: transparent; color: var(--muted);
  font: inherit; font-size: .875rem; cursor: pointer; transition: background-color 200ms ease, color 200ms ease, border-color 200ms ease;
}
.st-subjects button:hover:not([aria-pressed="true"]) { color: var(--ink); border-color: var(--muted); }
.st-subjects button[aria-pressed="true"] { border-color: var(--board); background: var(--board); color: var(--chalk); }
.st-win {
  position: relative; isolation: isolate; overflow: hidden; width: 100%; aspect-ratio: 5 / 4; max-height: min(70svh, 560px); margin-inline: auto;
  border-radius: calc(16px - var(--dim) * 6px);
  background-color: color-mix(in oklab, #e8ecef, var(--board) calc(var(--dim) * 100%));
  box-shadow: 0 0 0 calc(var(--dim) * 10px) color-mix(in oklab, #cdd3d8, var(--wood) calc(var(--dim) * 100%)), 0 22px 44px -20px #000a;
  transition: background-color 700ms ease, box-shadow 700ms ease, border-radius 700ms ease;
  color: #25313a; font: 14px/1.5 system-ui, "Segoe UI", sans-serif;
}
.st-win p { margin: 0; }
.st-below { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; margin-top: 18px; }
.st-try { color: var(--muted); font-size: .9375rem; opacity: 0; transition: opacity 500ms ease 400ms; }
.st-done .st-try, .story:not([data-step]) .st-try { opacity: 1; }
.st-replay {
  min-height: 36px; padding: 4px 16px; border: 1px solid var(--rule); border-radius: 999px;
  background: transparent; color: var(--muted); font: inherit; font-size: .875rem; cursor: pointer;
}
.st-replay:hover { color: var(--ink); border-color: var(--muted); }

/* The chat. When the request is sent the conversation scrolls up like a real chat. */
.st-bar { position: absolute; inset: 0 0 auto; z-index: 2; display: flex; align-items: center; gap: 6px; height: 34px; padding-inline: 14px; background: #fff; opacity: calc(1 - var(--dim)); transition: opacity 500ms ease; }
.st-bar i { width: 9px; height: 9px; border-radius: 50%; background: #c3cad0; }
.st-chat { position: absolute; inset: 44px 18px 74px; overflow: hidden; }
.st-flow {
  display: grid; gap: 10px; align-content: start; padding-top: 4px;
  opacity: calc(1 - var(--dim)); translate: 0 calc(var(--sent) * -56px - var(--dim) * 18px); transition: opacity 500ms ease, translate 600ms ease;
}
.st-user { justify-self: end; max-width: 78%; padding: 8px 13px; border-radius: 14px 14px 4px 14px; background: #cfe0ee; }
.st-reply { max-width: 94%; padding: 10px 14px; border-radius: 14px 14px 14px 4px; background: #fff; font-size: 13px; box-shadow: 0 0 0 calc(var(--read) * 2px) #efcb86; transition: box-shadow 400ms ease; }
.st-user b, .st-typed b { color: #2d6a9f; }
.st-sent { opacity: var(--sent); transition: opacity 400ms ease; }
.st-gen { position: relative; height: 92px; max-width: 94%; border-radius: 14px 14px 14px 4px; background: #fff; opacity: var(--sent); transition: opacity 400ms ease 250ms; }
.st-reading, .st-ready { position: absolute; inset: 0; display: grid; align-content: center; gap: 6px; padding: 12px 14px; transition: opacity 400ms ease; }
.st-reading { opacity: var(--read); }
.st-reading-head { display: flex; align-items: center; gap: 8px; color: #52606b; font-size: 13px; }
.st-dots { display: inline-flex; gap: 3px; }
.st-dots i { width: 6px; height: 6px; border-radius: 50%; background: #2d6a9f; }
.st-skel { display: block; height: 8px; border-radius: 4px; background: linear-gradient(90deg, #dfe5ea, #f4f6f8, #dfe5ea) 0 0 / 200% 100%; }
.st-short { width: 60%; }
.story[data-step="2"] .st-skel { animation: st-shimmer 1.3s linear infinite; }
.story[data-step="2"] .st-dots i { animation: st-bounce 900ms ease-in-out infinite; }
.story[data-step="2"] .st-dots i:nth-child(2) { animation-delay: 120ms; }
.story[data-step="2"] .st-dots i:nth-child(3) { animation-delay: 240ms; }
@keyframes st-shimmer { to { background-position: -200% 0; } }
@keyframes st-bounce { 50% { translate: 0 -4px; } }
.st-ready { grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; opacity: var(--gen); }
.st-playicon { position: relative; width: 38px; height: 38px; border-radius: 50%; background: var(--board); }
.st-playicon::after { content: ""; position: absolute; left: 15px; top: 11px; border-style: solid; border-width: 8px 0 8px 12px; border-color: transparent transparent transparent var(--chalk); }
.st-ready-text { display: grid; line-height: 1.3; }
.st-ready-text small { color: #66737d; font-size: 12px; }
.st-play { padding: 5px 14px; border-radius: 999px; background: #dfe5ea; color: #25313a; font-weight: 600; font-size: 13px; transition: background-color 300ms ease 500ms; }
.story[data-step="3"] .st-play { background: var(--board); color: var(--chalk); }
.st-composer {
  position: absolute; left: 14px; right: 14px; bottom: 14px; display: flex; align-items: center; height: 44px; padding-inline: 16px; border: 1px solid #cdd3d8; border-radius: 22px; background: #fff;
  opacity: calc(1 - var(--dim)); translate: 0 calc(var(--dim) * 44px); transition: opacity 500ms ease, translate 600ms ease;
}
.st-hint { color: #75828c; opacity: calc(1 - var(--typed) * (1 - var(--sent))); transition: opacity 200ms ease; }
.st-typed {
  position: absolute; left: 16px; right: 16px; overflow: hidden; white-space: nowrap; font-weight: 600;
  clip-path: inset(0 calc((1 - var(--typed)) * 100%) 0 0); opacity: calc(1 - var(--sent)); transition: clip-path 900ms steps(24, end), opacity 250ms ease;
}

/* The board. Every subject draws its own scene into the SVG; the shapes here are shared by all of them. */
.st-pie { position: absolute; left: 5%; right: 5%; top: 6%; bottom: 82px; width: 90%; height: calc(100% - 6% - 82px); overflow: visible; fill: none; color: var(--chalk); pointer-events: none; }
.st-scene { transition: opacity 300ms ease; }
.st-scene.sc-dim { opacity: .2; }
.st-scene text { stroke: none; }
.sc-text { fill: var(--chalk); font: 700 19px var(--hand); }
.sc-big { font-size: 23px; }
text.sc-gold { fill: var(--gold); }
text.sc-rose { fill: var(--rose); }
.sc-item { opacity: 0; transition: opacity 500ms ease; }
.sc-item.on { opacity: 1; }
.sc-line { fill: none; stroke: var(--chalk); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sc-line.sc-gold { stroke: var(--gold); }
.sc-line.sc-rose { stroke: var(--rose); }
.sc-dash { stroke-dasharray: 5 4; }
.sc-draw { fill: none; stroke: var(--chalk); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1; stroke-dashoffset: 1; transition: stroke-dashoffset 900ms ease-out; }
.sc-draw.on { stroke-dashoffset: 0; }
.sc-draw.sc-gold { stroke: var(--gold); }
.sc-draw.sc-rose { stroke: var(--rose); }
.sc-fill { fill: var(--chalk); stroke: none; }
.sc-fill-gold { fill: var(--gold); }
.sc-fill-rose { fill: var(--rose); }
.sc-area { fill: #efcb8622; stroke: none; }
.sc-dot { fill: var(--chalk); }
.sc-dot.sc-item { transition: opacity 500ms ease, fill 400ms ease; }
.sc-dot.sc-in { fill: var(--gold); }
.sc-dot.sc-out { fill: var(--rose); }
.sc-tube { fill: #efcb8626; stroke: var(--gold); stroke-width: 1.2; stroke-dasharray: 4 3; }
.sc-tube.sc-item { transition: opacity 500ms ease, y 600ms ease, height 600ms ease; }
.sc-region { fill: #efcb8630; opacity: 0; }
.sc-region.sc-flash { animation: sc-region 1500ms ease; }
.sc-bar { transform-box: view-box; transform-origin: 0 0; }
.sc-bar.sc-item { transition: opacity 500ms ease, transform 900ms cubic-bezier(.5, 0, .2, 1); }
.sc-bar rect { stroke: #213c34; stroke-width: .8; }
.sc-gold-fill { fill: var(--gold); }
.sc-rose-fill { fill: var(--rose); }
.sc-bar-text { fill: #1f2b28; font: 700 11px var(--sans); text-anchor: middle; }
.sc-flash { animation: sc-pulse 1500ms ease; }
@keyframes sc-pulse { 30%, 60% { filter: drop-shadow(0 0 5px var(--gold)); } }
@keyframes sc-region { 30% { opacity: 1; } }

.st-mira {
  position: absolute; right: -23%; bottom: calc(108px - 6.5%); z-index: 1; height: 84%; aspect-ratio: 600 / 260; pointer-events: none;
  --walk-distance: 24%;
  translate: calc((1 - var(--walk)) * var(--walk-distance)) 0; opacity: min(1, calc(var(--walk) * 20));
  transition: translate 1800ms cubic-bezier(.35, .13, .65, .87), opacity 150ms ease 100ms;
}
.st-bottom {
  position: absolute; inset: auto 0 0; z-index: 2; display: grid; gap: 6px; padding: 8px 14px 10px; border-top: 4px solid #b89468; background: #0d1a16;
  color: var(--chalk); opacity: var(--bar); translate: 0 calc((1 - var(--bar)) * 16px); transition: opacity 500ms ease, translate 500ms ease;
}
.st-sub { min-height: 2.9em; display: grid; place-items: center; text-align: center; font-size: .875rem; line-height: 1.4; transition: opacity 200ms ease; }
.st-sub.st-swap { opacity: 0; }
.st-controls { display: flex; align-items: center; gap: 12px; }
.st-track { flex: 1; height: 4px; border-radius: 2px; background: #ffffff33; overflow: hidden; }
.st-track i { display: block; width: 100%; height: 100%; border-radius: 2px; background: var(--gold); transform-origin: left; scale: var(--prog) 1; transition: scale 900ms ease; }
.st-ask {
  padding: 4px 14px; border: 1px solid #f5f0dc66; border-radius: 999px; background: transparent; color: var(--chalk); font: inherit; font-size: .8125rem; cursor: pointer;
}
.st-ask:disabled { opacity: .5; cursor: default; }
.st-ask:not(:disabled) { border-color: var(--gold); color: var(--gold); }
.st-ask:not(:disabled):hover { background: #efcb8622; }
.st-ask:focus-visible, .st-questions button:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
@media (prefers-reduced-motion: no-preference) {
  .story[data-step="8"] .st-ask:not(:disabled) { animation: st-invite 1800ms ease-out 2; }
}
@keyframes st-invite { 0% { box-shadow: 0 0 0 0 #efcb8688; } 100% { box-shadow: 0 0 0 10px #efcb8600; } }
.st-questions { position: absolute; left: 12px; right: 12px; bottom: 86px; z-index: 3; display: flex; flex-wrap: wrap; gap: 8px; }
.st-questions[hidden] { display: none; }
.st-questions button {
  padding: 7px 13px; border: 1px solid #f5f0dc88; border-radius: 999px; background: #0d1a16e6; color: var(--chalk); font: inherit; font-size: .8125rem; cursor: pointer;
}
.st-questions button:hover { border-color: var(--gold); color: var(--gold); }

/* Reduced motion: no moving parts. The finished lecture and the four steps stay on the page. */
@media (prefers-reduced-motion: reduce) {
  .story *, .story *::before, .story *::after { transition: none !important; animation: none !important; }
  .st-replay { display: none; }
}

@media (max-width: 859px) {
  .st-grid { grid-template-columns: 1fr; gap: 14px; }
  .st-copy h2 { max-width: none; font-size: 1.5rem; }
  .st-stage { order: 2; padding: 10px; }
  .st-rail { margin-top: 12px; }
  .st-rail::before, .st-rail::after { display: none; }
  .st-win { aspect-ratio: 1 / 1; max-height: none; }
  .st-chat { inset: 44px 14px 70px; }
  .st-pie { bottom: 112px; height: calc(100% - 6% - 112px); }
  .st-mira { right: -18%; height: 60%; bottom: calc(108px - 4.6%); }
  .st-questions { bottom: 116px; gap: 6px; }
  .st-questions button { padding: 5px 11px; font-size: .75rem; }
}
@media (max-width: 859px) and (prefers-reduced-motion: no-preference) {
  .story[data-step] .st-rail li:not([data-on]) { display: none; }
}
