/* fieldia.dev's front page, chapter 3: a stage pinned while the page scrolls past it, one record
   growing chapter by chapter (site/story.js). The stage is drawn at 900 × 600 and scaled to its
   column; each chapter's change moves things, never fades them, so every word keeps its contrast. */
.story-chapter { border-top: 1px solid var(--h-line); padding-top: 96px; }
.story-intro { padding-inline: var(--h-gutter); max-width: calc(760px + 2 * var(--h-gutter)); }
.story-scroll { position: relative; height: calc(var(--steps) * 80vh + 100vh); }
.story-sticky {
  position: sticky; top: 60px; height: calc(100vh - 60px); min-height: 560px;
  display: grid; grid-template-columns: minmax(240px, 0.7fr) minmax(0, 2fr) 18px; gap: 40px; align-items: center;
  padding-inline: var(--h-gutter);
}

/* ---- the captions: one shown, the next rising into its place ---- */
.story-captions { list-style: none; margin: 0; padding: 0; position: relative; min-height: 260px; }
.story-caption { position: absolute; inset: 0; display: grid; gap: 12px; align-content: center; visibility: hidden; transform: translateY(28px); }
/* The one going goes at once; only the one coming moves, so two captions are never on top of each other. */
.story-caption.is-on { visibility: visible; transform: none; transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s; }
.story-count { font: 600 13px/1 var(--h-mono); letter-spacing: 0.08em; color: var(--h-navy); }
.story-caption h3 { margin: 0; font: 700 clamp(26px, 2.6vw, 36px)/1.08 var(--h-display); letter-spacing: -0.02em; color: var(--h-ink); text-wrap: balance; }
.story-caption p { margin: 0; color: var(--h-muted); font-size: 17px; line-height: 1.6; }

/* ---- the rail: where the story stands, and a way to any chapter ---- */
/* Each a 24px target (WCAG 2.2's least), its dot drawn inside it. */
.story-rail { display: grid; gap: 0; justify-items: center; }
.story-rail button { display: grid; place-items: center; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%; background: none; cursor: pointer; }
.story-rail button::before { content: ""; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--h-navy); box-sizing: border-box; transition: transform 0.2s ease, background-color 0.2s ease; }
.story-rail button[aria-current="step"]::before { background: var(--h-navy); transform: scale(1.3); }
.story-rail button:focus-visible { outline: 2px solid var(--h-signal); outline-offset: 1px; }

/* ---- the stage ---- */
.story-stage { position: relative; aspect-ratio: 900 / 600; max-height: calc(100vh - 140px); min-width: 0; }
.story-screen { position: absolute; inset: 0 auto auto 0; width: 900px; height: 600px; transform: scale(var(--fit, 1)); transform-origin: 0 0; }
.story-window { position: absolute; inset: 0; display: grid; grid-template-rows: 34px minmax(0, 1fr); background: var(--h-surface); border: 1px solid var(--h-line); border-radius: 14px; box-shadow: 0 30px 70px rgba(16, 25, 43, 0.16); overflow: hidden; transition: transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1); transform-origin: 0 0; z-index: 2; }
.story-chrome { display: flex; align-items: center; gap: 7px; padding-inline: 14px; background: var(--h-chrome); border-bottom: 1px solid var(--h-line); font: 12px/1 var(--h-mono); color: var(--h-muted); }
.story-chrome span { width: 10px; height: 10px; border-radius: 50%; background: var(--h-chrome-dot); }
.story-chrome b { margin-inline-start: 14px; font-weight: 500; }
.story-app { display: grid; grid-template-columns: minmax(0, 1fr) 0; min-height: 0; transition: grid-template-columns 0.7s cubic-bezier(0.2, 0.8, 0.2, 1); }
.story-form { min-width: 0; overflow: hidden; }
.story-form .fd-form { --fd-page: var(--h-surface); }
.story-form .story-off { display: none !important; }
.story-form .story-arrive { animation: story-arrive 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
@keyframes story-arrive { from { transform: translateY(14px) scale(0.97); background-color: rgba(79, 157, 255, 0.16); } to { transform: none; background-color: transparent; } }

/* The chatter: closed, then beside the sheet from chapter 6. */
.story-chatter { min-width: 0; overflow: hidden; display: grid; gap: 10px; align-content: start; padding: 16px 0; background: var(--h-side); border-inline-start: 1px solid var(--h-line); font-size: 13px; color: var(--h-ink); }
.story-chatter p { margin: 0 14px; }
.story-chatter-bar { display: flex; gap: 6px; }
.story-chatter-bar > * { padding: 5px 9px; border: 1px solid var(--h-line); border-radius: 6px; background: var(--h-surface); font-weight: 500; }
.story-chatter-bar b { background: var(--h-fill); border-color: var(--h-fill); color: var(--h-on-fill); }
.story-activity { padding: 9px 10px; border: 1px solid var(--h-line); border-radius: 8px; background: var(--h-surface); }
.story-activity i { font-style: normal; font-weight: 700; color: var(--h-warn); margin-inline-end: 4px; }
.story-message { padding: 9px 10px; border-radius: 8px; background: var(--h-surface); line-height: 1.45; }
.story-message b { display: block; margin-bottom: 2px; }
.story-mine { background: var(--h-mine); }
.story-file { padding: 8px 10px; border: 1px dashed var(--h-line); border-radius: 8px; font: 12px var(--h-mono); color: var(--h-muted); }
.story-stage[data-step="5"] .story-app, .story-stage[data-step="6"] .story-app { grid-template-columns: minmax(0, 1fr) 250px; }
.story-stage[data-step="5"] .story-chatter p { animation: story-arrive 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.story-stage[data-step="5"] .story-chatter p:nth-child(3) { animation-delay: 0.25s; }
.story-stage[data-step="5"] .story-chatter p:nth-child(4) { animation-delay: 0.6s; }

/* The parts drawn around the record: each placed, and shown only in its chapter. */
.story-list, .story-toast, .story-rule, .story-theme, .story-server, .story-frameworks { position: absolute; visibility: hidden; transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.6s; }
/* At the foot of the window, as an app's toast is: never over the buttons and the stages it is about. */
.story-toast { inset-inline-start: 50%; bottom: 22px; margin: 0; padding: 10px 16px; border-radius: 10px; background: var(--h-saved); color: var(--h-on-saved); font-weight: 650; white-space: nowrap; transform: translate(-50%, 16px); z-index: 3; box-shadow: 0 10px 24px rgba(16, 25, 43, 0.2); }
.story-stage[data-step="3"] .story-toast { visibility: visible; transform: translate(-50%, 0); transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s; }
.story-rule { left: var(--x, 460px); top: var(--y, 330px); margin: 0; padding: 7px 11px; border-radius: 8px; background: var(--h-stage); color: var(--j-str); font: 13px/1 var(--h-mono); z-index: 3; transform: translateY(8px); }
.story-rule::before { content: ""; position: absolute; top: -6px; inset-inline-start: 18px; border: 6px solid transparent; border-top: 0; border-bottom-color: var(--h-stage); }
.story-stage[data-step="2"] .story-rule { visibility: visible; transform: none; transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s; }
.story-theme { inset-inline-end: 18px; bottom: 18px; margin: 0; padding: 6px 12px; border-radius: 999px; background: var(--h-stage); color: var(--h-stage-ink); font: 600 13px/1 var(--h-mono); z-index: 3; }
.story-stage[data-step="7"] .story-theme { visibility: visible; transition: visibility 0s; }

/* Chapter 7: the record shrinks into its row of a list. */
.story-list { inset: 18px auto auto 0; width: 560px; padding: 16px; background: var(--h-surface); border: 1px solid var(--h-line); border-radius: 14px; box-shadow: 0 20px 50px rgba(16, 25, 43, 0.12); transform: translateX(-30px); font-size: 14px; }
.story-search { margin: 0 0 12px; padding: 8px 10px; border: 1px solid var(--h-line); border-radius: 8px; color: var(--h-muted); }
.story-chip { margin-inline-end: 8px; padding: 3px 9px; border-radius: 999px; background: var(--h-chip); color: var(--h-navy); font-weight: 600; }
.story-list table { width: 100%; border-collapse: collapse; }
.story-list th { padding: 8px; text-align: start; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--h-muted); border-bottom: 1px solid var(--h-line); }
.story-list td { padding: 10px 8px; border-bottom: 1px solid var(--h-line); }
.story-ours td { background: var(--h-picked); font-weight: 650; }
.story-dim { display: none; }
.story-stage[data-step="6"] .story-list { visibility: visible; transform: none; transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s; }
.story-stage[data-step="6"] .story-window { transform: translate(520px, 250px) scale(0.42); }

/* Chapter 10: the record goes to your server and comes back saved. */
.story-server { inset: 210px 0 auto auto; width: 330px; display: grid; gap: 10px; color: var(--h-signal); transform: translateX(30px); z-index: 1; }
.story-server svg { width: 150px; height: 50px; }
.story-db { display: grid; gap: 6px; padding: 16px 18px; border-radius: 14px; background: var(--h-stage); color: var(--h-stage-ink); }
.story-db code { color: var(--j-key); font-size: 13px; background: none; padding: 0; }
.story-db span { color: var(--j-lit); font-weight: 700; }
.story-stage[data-step="9"] .story-server { visibility: visible; transform: none; transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s; }
.story-stage[data-step="9"] .story-window { transform: scale(0.62) translateY(150px); }

/* Chapter 11: one page, four frameworks around it. */
.story-frameworks { inset: 0; list-style: none; margin: 0; padding: 0; z-index: 3; }
.story-frameworks li { position: absolute; padding: 10px 18px; border-radius: 999px; background: var(--h-stage); color: var(--h-stage-ink); font: 700 17px/1 var(--h-display); box-shadow: 0 12px 30px rgba(16, 25, 43, 0.25); transform: scale(0.6); transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1); }
.story-frameworks li:nth-child(1) { left: 10px; top: 40px; }
.story-frameworks li:nth-child(2) { right: 10px; top: 70px; }
.story-frameworks li:nth-child(3) { left: 40px; bottom: 50px; }
.story-frameworks li:nth-child(4) { right: 30px; bottom: 30px; }
.story-stage[data-step="10"] .story-frameworks { visibility: visible; transition: visibility 0s; }
.story-stage[data-step="10"] .story-frameworks li { transform: none; }
.story-stage[data-step="10"] .story-frameworks li:nth-child(2) { transition-delay: 0.1s; }
.story-stage[data-step="10"] .story-frameworks li:nth-child(3) { transition-delay: 0.2s; }
.story-stage[data-step="10"] .story-frameworks li:nth-child(4) { transition-delay: 0.3s; }
.story-stage[data-step="10"] .story-window { transform: translate(135px, 60px) scale(0.7); }

/* The ten parts, after the story: each one to read about. */
.everything-h { font-size: clamp(24px, 2.4vw, 32px) !important; }

/* ---- a phone or a narrow window: the stage over its caption ---- */
@media (max-width: 900px) {
  .story-sticky { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto; align-content: center; gap: 22px; }
  .story-stage { order: -1; max-height: none; }
  .story-captions { min-height: 190px; }
  .story-rail { display: none; }
}

/* ---- a phone: the record drawn at a phone's own size, 440 × 600, so it reads at the scale it is shown; as tall as the
   screen leaves room for under the bar and over the caption; the conversation under the sheet, not beside it ---- */
@media (max-width: 640px) {
  .story-sticky { gap: 16px; }
  .story-stage { aspect-ratio: 440 / 600; width: min(100%, calc((100vh - 60px - 230px) * 440 / 600)); justify-self: center; }
  .story-screen { width: 440px; height: 600px; }
  .story-captions { min-height: 180px; }
  .story-caption h3 { font-size: 24px; }
  .story-caption p { font-size: 16px; line-height: 1.5; }
  .story-app { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) 0; transition: grid-template-rows 0.7s cubic-bezier(0.2, 0.8, 0.2, 1); }
  .story-stage[data-step="5"] .story-app, .story-stage[data-step="6"] .story-app { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) 236px; }
  .story-chatter { border-inline-start: 0; border-block-start: 1px solid var(--h-line); padding: 12px 0; }
  .story-list { inset: 12px auto auto 10px; width: 420px; padding: 12px; font-size: 13px; }
  .story-list :is(th, td) { padding-inline: 6px; white-space: nowrap; }
  .story-stage[data-step="6"] .story-window { transform: translate(200px, 290px) scale(0.5); }
  .story-server { inset: auto 10px 16px auto; width: 300px; }
  .story-stage[data-step="9"] .story-window { transform: scale(0.62); }
  .story-stage[data-step="10"] .story-window { transform: translate(66px, 90px) scale(0.7); }
}

/* ---- reduced motion: the chapters as a list, beside the stage at its sixth ---- */
.story-still .story-scroll { height: auto; }
.story-still .story-sticky { position: static; height: auto; padding-block: 40px 80px; align-items: start; }
.story-still .story-captions { min-height: 0; display: grid; gap: 22px; }
.story-still .story-caption { position: static; visibility: visible; transform: none; transition: none; }
.story-still .story-caption h3 { font-size: 22px; }
.story-still .story-rail { display: none; }
.story-still .story-stage { position: sticky; top: 80px; }
@media (prefers-reduced-motion: reduce) {
  .story-window, .story-app, .story-list, .story-toast, .story-rule, .story-server, .story-frameworks, .story-frameworks li, .story-caption, .story-rail button::before { transition: none !important; }
  .story-form .story-arrive, .story-chatter p { animation: none !important; }
  .story-packet { display: none; }
}
