/*
 * sd-story — homepage systems animation (Session 4.1a; Blueprint 5.9, 6.5–6.10, 7.6, 8.13, 8.14, 8.20, 8.21)
 * A scroll-driven story in five steps that follows one real chain of the SisuDent model (Blueprint 6.10):
 * Knowledge → Services → Products → Clinic operations → Better operation. At the end SisuDent is connected
 * to every part. The parts are visible from the start (gray); the Blue Line reveals how they connect.
 *
 * Markup: <section class="sd-story" data-sd-component="system-story">
 *   .sd-story__layout > figure.sd-story__visual (SVG map, ≥ 1024px only) + ol.sd-story__steps (text, all tiers)
 *   When a step is reached by scrolling, the Blue Line travels to its node in one calm movement (1.2 s) and waits
 *   there; the node is reached when the line arrives (8.14). Owner change request: the line does not follow the
 *   scroll speed, so slow scrolling never makes it jump.
 *
 * States (set by shared/components.js):
 *   static (no data-state)   — complete map, all nodes reached; also no JS, reduced motion, and short
 *                              landscape screens (height ≤ 560px)
 *   data-state="play"        — scroll-triggered, time-based movement per step (≤ 1.2 s, reversible when
 *                              scrolling back, never locks or slows scrolling — 8.21); desktop map is sticky
 * Phones and tablets (< 1024px): the map is not shown — at that width its labels would fall below 12px.
 * The steps carry the story with a vertical Blue Line that travels from step to step (8.20: simplified,
 * not removed). All information is in the text; the map is a visual summary with a text alternative.
 */

.sd-story__layout {
  display: grid;
  gap: var(--sd-space-6);
}

@media (min-width: 1024px) {
  .sd-story__layout {
    grid-template-columns: 5fr 7fr;
    column-gap: var(--sd-space-8);
    align-items: start;
  }
  .sd-story__visual { grid-column: 2; grid-row: 1; }
  .sd-story__steps { grid-column: 1; grid-row: 1; }
}

/* ---------- Map (desktop) ---------- */

.sd-story__visual { display: none; margin: 0; }

@media (min-width: 1024px) {
  .sd-story__visual { display: grid; place-items: center; }
}

.sd-story__visual svg {
  width: 100%;
  max-width: 48rem;
  height: auto;
  overflow: visible;
}

.sd-story__seg {
  fill: none;
  stroke: var(--sd-color-line-primary);
  stroke-width: var(--sd-line-width);
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
}

/* The secondary lines from each part to SisuDent were removed by owner request (F-07, Session 5.2):
   the Blue Line connecting the parts is the only line. */

.sd-story__halo {
  fill: var(--sd-color-blue-050);
  opacity: 0;
  transition: opacity var(--sd-duration-base) var(--sd-ease-out);
}

.sd-story__ring {
  fill: var(--sd-color-white);
  stroke: var(--sd-color-line-primary);
  stroke-width: 2;
  transition: stroke var(--sd-duration-base) var(--sd-ease-out);
}

.sd-story__node--end .sd-story__ring { stroke: var(--sd-color-line-emphasis); }

.sd-story__core {
  fill: var(--sd-color-brand-blue);
  transition: fill var(--sd-duration-base) var(--sd-ease-out);
}

.sd-story__label,
.sd-story__sub,
.sd-story__center {
  font-family: var(--sd-font-family-base);
  paint-order: stroke;
  stroke: var(--sd-color-white);
  stroke-width: 6px;
  stroke-linejoin: round;
}

.sd-story__label {
  font-size: 20px;
  font-weight: 600;
  fill: var(--sd-color-text-heading);
  transition: fill var(--sd-duration-base) var(--sd-ease-out);
}

.sd-story__node--end .sd-story__label { fill: var(--sd-color-brand-blue); }

.sd-story__sub {
  font-size: 15px;
  font-weight: 400;
  fill: var(--sd-color-gray-600);
}

.sd-story__center {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.01em;
  fill: var(--sd-color-brand-blue);
}

/* ---------- Steps (all tiers) ---------- */

.sd-story__steps {
  display: grid;
  gap: var(--sd-space-6);
  margin: 0;
  padding: 0;
  list-style: none;
}

.sd-story__step {
  position: relative;
  display: grid;
  grid-template-columns: 2.75rem minmax(0, 1fr);
  column-gap: var(--sd-space-4);
  align-items: start;
}

/* Number node (approved stages pattern, D-026 item 5); the last one has the copper ring (end of a process) */
.sd-story__marker {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border: var(--sd-border-width-strong) solid var(--sd-color-brand-blue);
  border-radius: 50%;
  background: var(--sd-color-brand-blue);
  color: var(--sd-color-white);
  font-size: var(--sd-font-size-small);
  font-weight: var(--sd-font-weight-semibold);
  font-variant-numeric: tabular-nums;
  transition:
    background-color var(--sd-duration-base) var(--sd-ease-out),
    border-color var(--sd-duration-base) var(--sd-ease-out),
    color var(--sd-duration-base) var(--sd-ease-out);
}

.sd-story__step:last-child .sd-story__marker {
  border-color: var(--sd-color-accent-copper);
  background: var(--sd-color-white);
  color: var(--sd-color-brand-blue);
}

/* Vertical Blue Line to the next step (phones and tablets) */
.sd-story__step:not(:last-child)::after {
  content: "";
  position: absolute;
  left: calc(1.375rem - var(--sd-line-width) / 2);
  top: 2.75rem;
  bottom: calc(-1 * var(--sd-space-6));
  width: var(--sd-line-width);
  background: var(--sd-color-line-primary);
  transform-origin: top;
}

@media (min-width: 1024px) {
  .sd-story__step:not(:last-child)::after { display: none; }  /* the map carries the line on desktop */
}

.sd-story__body {
  display: grid;
  gap: var(--sd-space-3);
  justify-items: start;
  min-width: 0;
  padding-top: 0.5rem;
}

.sd-story__title {
  font-size: var(--sd-font-size-h3);
  line-height: var(--sd-line-height-h3);
  max-width: 22ch;
}

.sd-story__text { max-width: 34rem; }

/* ---------- Play state (scroll-triggered, time-based movement; owner change request) ---------- */

/* Each step stays on screen long enough to read and observe (8.14); the section is about 3–4 hero heights (5.9) */
.sd-story[data-state="play"] .sd-story__step { min-height: 62svh; }
.sd-story[data-state="play"] .sd-story__step:last-child { min-height: 50svh; }

@media (min-width: 1024px) {
  .sd-story[data-state="play"] .sd-story__step { min-height: 72svh; }
  .sd-story[data-state="play"] .sd-story__step:last-child { min-height: 60svh; }

  .sd-story[data-state="play"] .sd-story__visual {
    position: sticky;
    top: calc(var(--sd-scroll-offset) + var(--sd-space-4));
    height: calc(100svh - var(--sd-scroll-offset) - var(--sd-space-8));
    max-height: 44rem;
  }
}

/* The Blue Line travels to the reached node in one calm movement (duration set by the script: 1.2 s forward, 0.5 s back) */
.sd-story[data-state="play"] .sd-story__seg {
  stroke-dashoffset: 1;
  transition: stroke-dashoffset var(--sd-story-duration, 1200ms) var(--sd-ease-line);
}
.sd-story[data-state="play"] .sd-story__seg.is-drawn { stroke-dashoffset: 0; }

.sd-story[data-state="play"] .sd-story__step:not(:last-child)::after {
  transform: scaleY(0);
  transition: transform var(--sd-story-duration, 1200ms) var(--sd-ease-line);
}
.sd-story[data-state="play"] .sd-story__step.is-linked::after { transform: scaleY(1); }

/* Not yet reached: the part exists but its relationship is not yet visible */
.sd-story[data-state="play"] .sd-story__node:not(.is-reached) .sd-story__ring { stroke: var(--sd-color-gray-300); }
.sd-story[data-state="play"] .sd-story__node:not(.is-reached) .sd-story__core { fill: var(--sd-color-gray-300); }
.sd-story[data-state="play"] .sd-story__node:not(.is-reached) .sd-story__label { fill: var(--sd-color-gray-600); }
.sd-story[data-state="play"] .sd-story__node.is-current .sd-story__halo { opacity: 1; }

.sd-story[data-state="play"] .sd-story__step:not(.is-reached) .sd-story__marker {
  border-color: var(--sd-color-gray-300);
  background: var(--sd-color-white);
  color: var(--sd-color-gray-600);
}

@media (prefers-reduced-motion: reduce) {
  .sd-story__halo,
  .sd-story__ring,
  .sd-story__core,
  .sd-story__label,
  .sd-story__marker { transition: none; }
}
