/* ==========================================================================
   Focal IT Consulting: scroll stories (stories/*.html)
   Builds on styles.css and uses its Palette v1 tokens only.

   How it works
   - Without JavaScript, or with reduced motion, every scene is a normal
     block: text, then its figure in its finished state, in one centred
     column.
   - With motion allowed, the head script adds .story-anim to <html>.
     story.js then sets --p (0 to 1) on each figure as the reader scrolls,
     and every moving part below reads --p. Only opacity and transform
     change.
   - From 1100px wide the figures share one pinned panel beside the text.
     Only one figure shows at a time: the old one fades out, then the new
     one fades in. Inactive scene text is muted (colour, not opacity).
   - Sentence case throughout: nothing here sets text-transform.
   ========================================================================== */

/* ---------- Column width when the page is not pinned ----------
   Phones, tablets, reduced motion and no JavaScript all read as one
   centred column, so nothing sits against one side with a blank strip. */
.story-open > .container,
.story__body > .container,
.story-close > .container { max-width: calc(940px + var(--gutter) * 2); }

/* ---------- Opening ---------- */
.story-open {
  position: relative;
  padding: clamp(40px, 7vw, 96px) 0 clamp(48px, 7vw, 96px);
  overflow: hidden;
}
.story-open::before {
  content: "";
  position: absolute;
  inset: -20% -10% auto;
  height: 560px;
  pointer-events: none;
  background: radial-gradient(34% 46% at 18% 0%, rgba(242, 107, 29, .08), transparent 70%);
}
.story-open > .container { position: relative; }
.story-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin-bottom: clamp(20px, 4vw, 40px);
  color: var(--body);
  font-weight: 600;
  text-decoration: none;
}
.story-back:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 4px; }
.story-open__giant {
  margin-top: clamp(16px, 2.5vw, 28px);
  font-size: clamp(2.75rem, 9vw, 8rem);
  font-weight: 700;
  line-height: .95;
  letter-spacing: -0.045em;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.story-open__title {
  max-width: 860px;
  margin-top: clamp(20px, 3vw, 36px);
  font-size: clamp(1.625rem, 3.4vw, 2.75rem);
  font-weight: 600;
  line-height: 1.14;
  letter-spacing: -0.025em;
}
/* The scroll cue only makes sense where the panel is pinned. */
.story-open__cue {
  display: none;
  align-items: center;
  gap: 12px;
  margin-top: clamp(28px, 4vw, 48px);
  font-size: 1rem;
  color: var(--muted);
}
.story-open__cue::before {
  content: "";
  width: 32px;
  height: 1px;
  background: var(--line-strong);
}

/* ---------- Scenes (stacked by default) ---------- */
.story__body { border-top: 1px solid var(--line); }
.story__grid { padding: clamp(24px, 4vw, 48px) 0 clamp(48px, 7vw, 96px); }
.scene { padding: clamp(40px, 6vw, 72px) 0 0; }
.scene__text { max-width: 640px; }
.scene__kicker {
  margin-bottom: 12px;
  font-family: var(--mono);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--muted);
}
.scene__title {
  font-size: clamp(1.625rem, 3vw, 2.25rem);
  font-weight: 600;
  line-height: 1.15;
}
.scene__text p:not(.scene__kicker) { margin-top: 16px; max-width: 60ch; }
.scene__fig {
  --p: 1;
  margin: clamp(24px, 4vw, 36px) 0 0;
}

/* ---------- Figure frame (same family as the operations window) ---------- */
.fig {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #FFFFFF;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 1px 2px rgba(20, 22, 26, .04), 0 2px 6px rgba(20, 22, 26, .03), 0 30px 70px -36px rgba(20, 22, 26, .22);
  overflow: hidden;
}
.fig__bar {
  flex: 0 0 44px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-1);
  font-family: var(--mono);
  font-size: 0.8125rem;
  color: var(--body);
  white-space: nowrap;
}
.fig__dots { display: flex; gap: 6px; }
.fig__dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--line); box-shadow: inset 0 0 0 1px rgba(20, 22, 26, .06); }
.fig__state { margin-left: auto; color: var(--muted); }
.fig__body {
  container: fig / inline-size;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  padding: clamp(18px, 3vw, 28px);
}
.fig--draw .fig__body, .fig--cost .fig__body, .fig--changed .fig__body {
  background-image: radial-gradient(circle, var(--line) 1px, transparent 1.4px);
  background-size: 20px 20px;
  background-position: 10px 10px;
}
.fig__kick {
  font-family: var(--mono);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--muted);
}

/* ---------- Process map ----------
   A real ordered list. Rows (vertical) by default, which suits phones and
   the pinned panel; cards in a line once the figure is 820px wide. The
   connector into each step is that step's ::before. */
.map {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.node {
  --t: 1;
  position: relative;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 14px;
  min-height: 60px;
  padding: 12px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #FFFFFF;
  box-shadow: 0 1px 2px rgba(20, 22, 26, .05);
}
.node + .node::before {
  content: "";
  position: absolute;
  left: 30px;
  top: -19px;
  width: 2px;
  height: 18px;
  border-radius: 1px;
  background: var(--subtle);
  transform-origin: center top;
  transform: scaleY(var(--t));
}
.node__num {
  font-family: var(--mono);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
}
.node__txt { display: flex; flex-direction: column; min-width: 0; }
.node__name { color: var(--ink); font-size: 1.0625rem; font-weight: 600; line-height: 1.25; }
.node__sub { margin-top: 2px; font-size: 0.9375rem; line-height: 1.35; color: var(--muted); }
.node__foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  color: var(--body);
}
.chip--ok { color: var(--ok); background: var(--ok-bg); }
.chip--warn { color: var(--warn); background: var(--warn-bg); }

/* Friction (cost scene): red outline, a marker that pulses once, a note */
.node__flag {
  position: absolute;
  inset: -1px;
  border: 1.5px solid var(--err);
  border-radius: 12px;
  pointer-events: none;
}
.node__mark {
  position: absolute;
  right: -6px;
  top: -6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--err);
  box-shadow: 0 0 0 3px #FFFFFF;
}
.node__ring {
  position: absolute;
  inset: -2px;
  border: 2px solid var(--err);
  border-radius: 50%;
  opacity: 0;
}
.node__issue {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  font-size: 0.9375rem;
  line-height: 1.35;
  color: var(--err);
}

/* Narrow figures (phones): the tags drop under the text */
@container fig (max-width: 519px) {
  .node { grid-template-columns: 26px minmax(0, 1fr); row-gap: 8px; column-gap: 12px; }
  .node + .node::before { left: 28px; }
  .node__foot { grid-column: 2; justify-content: flex-start; }
}

/* Wide figures: cards in a line */
@container fig (min-width: 820px) {
  .map { flex-direction: row; gap: 26px; }
  .node {
    flex: 1 1 0;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto 1fr;
    align-items: start;
    row-gap: 8px;
    min-height: 176px;
    padding: 16px;
  }
  .node + .node::before {
    left: -27px;
    top: 50%;
    width: 26px;
    height: 2px;
    transform-origin: left center;
    transform: scaleX(var(--t));
  }
  .node__foot { align-self: end; justify-content: flex-start; }
}

/* Rows under the map */
.gate {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
  padding: 14px 16px;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  background: #FFFFFF;
  font-size: 1rem;
  line-height: 1.45;
  color: var(--body);
}
.gate svg { flex: 0 0 auto; width: 20px; height: 20px; }
.gate path, .gate rect { fill: none; stroke: var(--ink); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.before {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 18px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.before .fig__kick { flex: 1 0 100%; }
.before__fig {
  font-size: clamp(2.5rem, 10cqi, 4rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.035em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.before__label { font-size: 1.0625rem; color: var(--body); }

/* ---------- Result ---------- */
.fig--result .fig__body { justify-content: center; }
.res__fig {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 20px;
  margin-top: 12px;
}
.res__before {
  position: relative;
  font-size: clamp(2rem, 8cqi, 3.5rem);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.03em;
  color: var(--muted);
}
.res__before::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 52%;
  height: 3px;
  margin-top: -1.5px;
  border-radius: 2px;
  background: var(--subtle);
  transform-origin: left center;
  transform: scaleX(var(--k, 1));
}
.res__arrow { display: block; width: clamp(40px, 9cqi, 64px); height: 26px; overflow: visible; }
.res__arrow path { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1 1; stroke-dashoffset: 0; }
.res__after {
  font-size: clamp(3.25rem, 17cqi, 7rem);
  font-weight: 700;
  line-height: .95;
  letter-spacing: -0.045em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.res__after--solo { font-size: clamp(3rem, 14cqi, 6.25rem); }
.res__rows { list-style: none; margin-top: clamp(24px, 5cqi, 40px); border-top: 1px solid var(--line-strong); }
.res__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}
.res__rowfig {
  font-size: clamp(1.5rem, 4.8cqi, 2.25rem);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.res__rowfig .res__before { font-size: inherit; font-weight: 600; letter-spacing: inherit; }
.res__rowfig .arrow { margin: 0 .2em; }
.res__nw { white-space: nowrap; }
.res__rowlabel { display: block; font-size: 1.0625rem; color: var(--body); }
.res__note { display: block; margin-top: 2px; font-size: 1rem; color: var(--muted); }
@container fig (min-width: 580px) {
  .res__row { grid-template-columns: minmax(0, 6fr) minmax(0, 5fr); gap: 24px; align-items: baseline; }
}

/* Counting numbers: the final text keeps its space, the live one sits on top */
.count { position: relative; display: inline-block; }
.count__live { position: absolute; right: 0; top: 0; opacity: 0; }
.is-counting .count__final { opacity: 0; }
.is-counting .count__live { opacity: 1; }

/* ---------- Settings (usage alerts) ----------
   Each setting is drawn as the kind of control it is. The words are the
   case's own; no values are invented. */
.fig--settings .fig__body { justify-content: center; }
.sets__head { display: flex; align-items: baseline; gap: 16px; }
.sets__num {
  font-size: clamp(3rem, 12cqi, 4.5rem);
  font-weight: 700;
  line-height: .9;
  letter-spacing: -0.04em;
  color: var(--ink);
}
.sets__label { font-size: 1.125rem; font-weight: 600; line-height: 1.3; color: var(--ink); }
.sets { list-style: none; margin-top: clamp(16px, 4cqi, 28px); border-top: 1px solid var(--line); }
.set {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.set__name { font-size: 1.0625rem; font-weight: 600; color: var(--ink); }
.set__ctl {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #FFFFFF;
  font-size: 1rem;
  color: var(--body);
}
.set__val { flex: 1 1 auto; min-width: 0; }
.set__ctl svg { flex: 0 0 auto; width: 18px; height: 18px; }
.set__ctl svg path, .set__ctl svg circle { fill: none; stroke: var(--muted); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.set__ctl--bare { padding: 0; border: 0; background: none; }
/* Threshold: a slider */
.range { position: relative; flex: 0 0 38%; height: 22px; }
.range__track, .range__fill { position: absolute; left: 0; top: 9px; height: 4px; border-radius: 2px; }
.range__track { right: 0; background: var(--line-strong); }
.range__fill { width: 60%; background: var(--ink); transform-origin: left center; transform: scaleX(var(--v, 1)); }
.range__run { position: absolute; left: 0; top: 0; width: 60%; height: 22px; transform: translateX(calc((var(--v, 1) - 1) * 100%)); }
.range__knob {
  position: absolute;
  right: -11px;
  top: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #FFFFFF;
  border: 2px solid var(--ink);
}
/* Auto-restrict: a switch */
.switch { position: relative; flex: 0 0 auto; width: 46px; height: 26px; border-radius: 999px; background: var(--line-strong); }
.switch__on { position: absolute; inset: 0; border-radius: inherit; background: var(--ink); opacity: var(--v, 1); }
.switch__knob {
  position: absolute;
  left: 3px;
  top: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 3px rgba(20, 22, 26, .25);
  transform: translateX(calc(var(--v, 1) * 20px));
}
@container fig (min-width: 520px) {
  .set { grid-template-columns: 150px minmax(0, 1fr); align-items: center; gap: 20px; }
}

/* ---------- Close ---------- */
.story-close { padding: clamp(56px, 8vw, 104px) 0 clamp(24px, 4vw, 40px); border-top: 1px solid var(--line); }
.story-close .scene__title { max-width: 640px; }
.story-close p { margin-top: 16px; max-width: 68ch; color: var(--body); }
.story-cta { padding-bottom: var(--section-y); }
.story-cta .cta { margin-top: clamp(40px, 6vw, 64px); }
.story-cta .btn-row .link-arrow { padding: 0 8px; }

/* ==========================================================================
   Motion (only with .story-anim, which the head script adds when motion
   is allowed). Everything reads --p, set by story.js.
   ========================================================================== */
.story-anim .scene__fig { --p: 0; }

/* The old way and what we changed: the map draws itself, step by step */
.story-anim .fig--draw .node,
.story-anim .fig--changed .node {
  /* Step 1 is already in place when the scene arrives; the rest follow. */
  --t: clamp(0, (var(--p) + .14 - var(--i, 0) * .18) / .14, 1);
  opacity: var(--t);
  transform: translateY(calc((1 - var(--t)) * 12px));
}
.story-anim .fig--draw .chip { opacity: clamp(0, (var(--p) - .5) / .16, 1); }
.story-anim .fig--changed .node__foot { opacity: clamp(0, (var(--p) - .5) / .14, 1); }
.story-anim .fig--changed .gate {
  --t: clamp(0, (var(--p) - .66) / .16, 1);
  opacity: var(--t);
  transform: translateY(calc((1 - var(--t)) * 8px));
}

/* The cost: friction points light up and pulse once, the before figure lands */
.story-anim .fig--cost .node__flag,
.story-anim .fig--cost .node__mark { opacity: clamp(0, (var(--p) - .04 - var(--k, 0) * .1) / .12, 1); }
.story-anim .fig--cost .node__issue {
  --t: clamp(0, (var(--p) - .14 - var(--k, 0) * .1) / .14, 1);
  opacity: var(--t);
  transform: translateY(calc((1 - var(--t)) * 6px));
}
.story-anim .fig--cost.is-pulsed .node__ring { animation: storyRing 1.3s var(--ease) both; animation-delay: calc(var(--k, 0) * 200ms); }
@keyframes storyRing {
  0% { opacity: .7; transform: scale(1); }
  100% { opacity: 0; transform: scale(3.2); }
}
.story-anim .fig--cost .before {
  --t: clamp(0, (var(--p) - .42) / .18, 1);
  opacity: var(--t);
  transform: translateY(calc((1 - var(--t)) * 10px));
}

/* The result: the heading, the before figure and the metric rows are there
   when the scene arrives (with no before figure, the main figure counts
   up); then the strike, the arrow and the after figure play. */
.story-anim .fig--result .res__fig > .res__before { --k: clamp(0, var(--p) / .12, 1); }
.story-anim .fig--result .res__fig .res__arrow path { stroke-dashoffset: calc(1 - clamp(0, (var(--p) - .08) / .12, 1)); }
.story-anim .fig--result .res__fig > .res__after { opacity: clamp(0, (var(--p) - .16) / .08, 1); }
.story-anim .fig--result .res__fig > .res__after--solo { opacity: 1; }
.story-anim .fig--result .res__row .res__before { --k: clamp(0, (var(--p) - .26 - var(--i, 0) * .1) / .12, 1); }

/* Settings: all five controls are there when the scene arrives; the
   slider and the switch settle one after the other. */
.story-anim .fig--settings .set { --v: clamp(0, (var(--p) - .04 - var(--i, 0) * .1) / .2, 1); }

/* ---------- Pinned panel, wide screens with motion ---------- */
@media (min-width: 1100px) {
  .story-anim .story-open > .container,
  .story-anim .story__body > .container,
  .story-anim .story-close > .container { max-width: calc(var(--container) + var(--gutter) * 2); }
  .story-anim .story-open__cue { display: flex; }
  .story-anim .story__grid {
    display: grid;
    grid-template-columns: minmax(0, 4fr) minmax(0, 8fr);
    grid-template-rows: repeat(var(--scenes, 5), auto);
    column-gap: clamp(48px, 5vw, 80px);
    padding: 0;
  }
  .story-anim .scene { display: contents; }
  .story-anim .scene__text {
    grid-column: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 76vh;
    padding: 8vh 0;
    transition: color .35s ease-out;
  }
  /* Inactive scene text is muted, not faded, so it still passes AA. */
  .story-anim .scene__text:not(.is-active),
  .story-anim .scene__text:not(.is-active) .scene__title { color: var(--muted); transition: color .35s ease-out; }
  .story-anim .scene:nth-child(1) .scene__text { grid-row: 1; }
  .story-anim .scene:nth-child(2) .scene__text { grid-row: 2; }
  .story-anim .scene:nth-child(3) .scene__text { grid-row: 3; }
  .story-anim .scene:nth-child(4) .scene__text { grid-row: 4; }
  .story-anim .scene:nth-child(5) .scene__text { grid-row: 5; }
  .story-anim .scene:nth-child(6) .scene__text { grid-row: 6; }
  /* Extra room after the last scene so its figure finishes, and rests,
     while still pinned. The text stays centred in the same 72vh band. */
  .story-anim .scene:last-child .scene__text { min-height: 112vh; padding-bottom: 44vh; }
  .story-anim .scene__fig {
    --figh: min(calc(100vh - var(--nav-h) - 48px), 640px);
    grid-column: 2;
    grid-row: 1 / -1;
    position: sticky;
    top: calc(var(--nav-h) + (100vh - var(--nav-h) - var(--figh)) / 2);
    align-self: start;
    height: var(--figh);
    margin: 28px 0;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    /* Leaving: fade out quickly, then hide. */
    transition: opacity .2s ease-out, visibility 0s linear .2s;
  }
  /* Arriving: wait for the old figure to finish fading, then fade in. */
  .story-anim .scene__fig.is-active {
    opacity: 1;
    visibility: visible;
    transition: opacity .34s ease-out .2s, visibility 0s linear .2s;
  }
  /* The map grows to use the panel height */
  .story-anim .scene__fig .fig__body { justify-content: center; padding: 26px 28px; }
  .story-anim .scene__fig .map { flex: 1 1 auto; min-height: 0; max-height: calc(var(--n, 5) * 148px); }
  .story-anim .scene__fig .node { flex: 1 0 auto; }
  /* Results and settings sit larger so they hold the panel */
  .story-anim .fig--result .res__after { font-size: clamp(3.5rem, 19cqi, 8rem); }
  .story-anim .fig--result .res__after--solo { font-size: clamp(3.25rem, 15.5cqi, 7rem); }
  .story-anim .fig--result .res__fig > .res__before { font-size: clamp(2.25rem, 9cqi, 4rem); }
  .story-anim .fig--result .res__row { padding: 22px 0; }
  .story-anim .fig--result .res__rowfig { font-size: clamp(1.625rem, 5.4cqi, 2.5rem); }
  .story-anim .fig--settings .set { padding: 16px 0; }
}
/* Short screens with the pinned panel: tighter map so everything fits */
@media (min-width: 1100px) and (max-height: 780px) {
  .story-anim .scene__fig .fig__body { padding: 20px 24px; }
  .story-anim .scene__fig .map { gap: 14px; }
  .story-anim .scene__fig .node { min-height: 52px; padding-top: 9px; padding-bottom: 9px; }
  .story-anim .scene__fig .node + .node::before { top: -15px; height: 14px; }
  .story-anim .scene__fig .before { margin-top: 14px; padding-top: 12px; }
  .story-anim .scene__fig .before__fig { font-size: 2.75rem; }
  .story-anim .scene__fig .gate { margin-top: 14px; padding: 10px 14px; }
  .story-anim .fig--result .res__row { padding: 16px 0; }
}

/* ---------- Reduced motion: nothing moves, everything finished ---------- */
@media (prefers-reduced-motion: reduce) {
  .story-anim .scene__fig { --p: 1; }
  .node__ring { animation: none !important; }
}

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
  .fig__bar { padding: 0 12px; }
  .story-cta .btn-row .btn { flex: 1 1 100%; }
}
