/* =====================================================================
   W.C.J — service-story.css · "HOW WE BUILD IT" scroll-driven build story
   (STORY_SPEC.md). Loaded on service pages only.
   1. Scene palette (s-* classes used by templates/scenes/*.svg)
   2. Layout: blueprint sheet stage + numbered steps
   3. JS states (.is-live / .is-scrub set by service-story.js; no JS → finished drawing)
   ===================================================================== */

/* ---------- 1. Scene palette ----------
   Colours/weights only. Never font-size here: a CSS font-size would beat a scene's
   font-size attribute (presentation attributes lose to any author rule). */
.scene {
  display: block; width: 100%; height: auto; overflow: hidden;
  font-family: var(--f-body); font-size: 14px; fill: var(--navy);
  stroke-linejoin: round;
}
.scene text:not([stroke]) { stroke: none; }   /* a stroke attribute = deliberate halo (paint-order) */

/* base shell */
.s-struct { fill: none; stroke: #24336F; stroke-width: 2; }
.s-slab { fill: #C9D1DE; stroke-width: 1.5; }
.s-thin { fill: none; stroke: #24336F; stroke-width: 1; stroke-opacity: .4; }
.s-hatch { fill: none; stroke: #24336F; stroke-width: 1; stroke-opacity: .35; }
.s-room { fill: #F3F5F8; stroke: none; }
.s-glass { fill: #EAF3FC; stroke: #24336F; stroke-width: 1; stroke-opacity: .35; }
.s-shaft { fill: rgba(42, 134, 214, .05); stroke-dasharray: 6 4; }
.s-plant { fill: rgba(36, 51, 111, .03); stroke-dasharray: 4 4; }
.s-floor-tag { fill: #5A6372; letter-spacing: .12em; }

/* drawing layers */
.s-line { fill: none; stroke: #24336F; stroke-width: 2; }
.s-blueprint { fill: none; stroke: #2A86D6; stroke-width: 1.2; stroke-dasharray: 6 5; }
.s-dim { fill: none; stroke: #2A86D6; stroke-width: 1; }
.scene text.s-blueprint, .scene text.s-dim, .scene .s-blueprint text, .scene .s-dim text { fill: #1D6AB3; stroke: none; }

/* services */
.s-pipe-chw { fill: none; stroke: #2A86D6; stroke-width: 4; }
.s-pipe-chwr { fill: none; stroke: #7FB7EA; stroke-width: 4; }
.s-pipe-fire { fill: none; stroke: #D7372F; stroke-width: 4; }
.s-pipe-water { fill: none; stroke: #2A86D6; stroke-width: 3; }
.s-pipe-waste { fill: none; stroke: #6B7380; stroke-width: 4; }
.s-duct { fill: #E3E8EF; stroke: #24336F; stroke-width: 1.5; }
.s-tray { fill: none; stroke: #F2A516; stroke-width: 3; }
.s-cable { fill: none; stroke: #F2A516; stroke-width: 2; }
.s-signal { fill: none; stroke: #2A86D6; stroke-width: 2; }

/* equipment & accents */
.s-equip { fill: #FFFFFF; stroke: #24336F; stroke-width: 2; }
.s-equip-dark { fill: #24336F; stroke: #24336F; }
.s-accent { fill: #F2A516; }
.s-ok { fill: #1E9E6A; }
.s-check { fill: none; stroke: #FFFFFF; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.s-tint-cool { fill: rgba(42, 134, 214, .15); stroke: none; }
.s-tint-warm { fill: rgba(242, 165, 22, .16); stroke: none; }

/* flows: dash pattern + colour (service-story.js moves the dashes once the step is reached) */
.s-flow-cool, .s-flow-water, .s-flow-power, .s-flow-air, .s-flow-signal, .s-flow-fire {
  fill: none; stroke-linecap: round;
}
.s-flow-cool { stroke: #4FA8EE; stroke-width: 3; stroke-dasharray: 10 12; }
/* water/test flow runs ON TOP of a pipe: light dashes read as moving water inside it */
.s-flow-water { stroke: #FFFFFF; stroke-opacity: .95; stroke-width: 2; stroke-dasharray: 8 10; }
.s-flow-power { stroke: #F2A516; stroke-width: 3; stroke-dasharray: 6 14; }
.s-flow-air { stroke: #7D93B5; stroke-width: 2.5; stroke-dasharray: 14 10; }
.s-flow-signal { stroke: #2A86D6; stroke-width: 2; stroke-dasharray: 3 9; }
.s-flow-fire { stroke: #D7372F; stroke-width: 3; stroke-dasharray: 10 10; }

/* text */
.s-text { font-family: var(--f-body); font-weight: 600; fill: #24336F; }
.s-text-mono { font-family: var(--f-mono); font-weight: 500; letter-spacing: .06em; }

/* small stage: hairlines would vanish at ~0.36 scale */
@media (max-width: 599.98px) {
  .s-thin, .s-hatch, .s-glass, .s-dim { stroke-width: 1.8; }
  .s-blueprint { stroke-width: 2; }
  .s-struct { stroke-width: 2.6; }
}

/* ---------- 2. Layout ---------- */
.bstory { overflow-x: clip; }
.bstory__head { max-width: 46rem; }
.bstory__lead { margin-top: 4px; color: var(--sub); }

/* steps (also the static timeline when no scene / no JS) */
.bstory__steps { position: relative; display: grid; gap: 0; counter-reset: none; }
.bstory__steps::before { /* timeline spine */
  content: ""; position: absolute; left: 27px; top: 28px; bottom: 28px; width: 2px;
  background: repeating-linear-gradient(to bottom, var(--azure) 0 6px, transparent 6px 11px); opacity: .45;
}
.bstory-step {
  position: relative; display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 18px;
  padding-block: 14px 22px; outline: none;
}
.bstory-step:focus-visible .bstory-step__title { outline: 3px solid var(--amber); outline-offset: 4px; border-radius: 2px; }
.bstory-step__num {
  position: relative; z-index: 1; width: 56px; height: 56px; display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--navy); border-radius: 50%; background: var(--white);
  font-family: var(--f-display); font-weight: 800; font-size: 1.6rem; line-height: 1; color: var(--navy);
  transition: background-color .35s var(--ease), color .35s var(--ease), border-color .35s var(--ease);
}
.bstory-step__body { padding-top: 6px; min-width: 0; }
.bstory-step__title { font-size: clamp(1.15rem, 1.05rem + .5vw, 1.4rem); line-height: 1.4; color: var(--navy); }
.bstory-step__en {
  margin-top: 2px; font-family: var(--f-mono); font-weight: 500; font-size: .75rem; letter-spacing: .2em;
  text-transform: uppercase; color: var(--azure-ink);
}
.bstory-step__text { margin-top: 10px; color: var(--ink); max-width: 34rem; }

/* blueprint sheet */
.bstory__stage { margin: 0; }
.bstory__sheet {
  position: relative; background-color: var(--white);
  border: 1px solid #C7D0DD; border-radius: var(--r-sm);
  box-shadow: var(--shadow-sm);
  padding: 14px 14px 0;
}
.bstory__drawing {
  position: relative; padding: 4px; overflow: hidden;
  background-image:
    linear-gradient(rgba(42, 134, 214, .10) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42, 134, 214, .10) 1px, transparent 1px),
    linear-gradient(rgba(42, 134, 214, .05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42, 134, 214, .05) 1px, transparent 1px);
  background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;
  background-position: -1px -1px;
  border: 1px solid rgba(36, 51, 111, .5);
}
/* corner crop ticks around the drawing border */
.bstory__ticks { position: absolute; inset: 4px; pointer-events: none; z-index: 1; }
.bstory__ticks::before, .bstory__ticks::after {
  content: ""; position: absolute; left: 0; right: 0; height: 12px;
  background:
    linear-gradient(var(--navy), var(--navy)) left top / 12px 2px no-repeat,
    linear-gradient(var(--navy), var(--navy)) left top / 2px 12px no-repeat,
    linear-gradient(var(--navy), var(--navy)) right top / 12px 2px no-repeat,
    linear-gradient(var(--navy), var(--navy)) right top / 2px 12px no-repeat;
}
.bstory__ticks::before { top: 0; }
.bstory__ticks::after { bottom: 0; transform: scaleY(-1); }

/* title block (drawing sheet footer) */
.bstory__titleblock {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: stretch;
  margin: 10px -14px 0; border-top: 2px solid var(--navy);
  font-family: var(--f-mono); font-weight: 500; font-size: .6875rem; letter-spacing: .14em; text-transform: uppercase; color: var(--navy);
}
.bstory__tb-cell { display: flex; align-items: center; gap: 8px; padding: 8px 12px; min-width: 0; border-left: 1px solid var(--line); }
.bstory__tb-cell:first-child { border-left: 0; }
.bstory__tb-brand { font-family: var(--f-display); font-weight: 800; font-size: 1rem; letter-spacing: .06em; background: var(--navy); color: var(--white); }
.bstory__tb-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; line-height: 2; }
.bstory__tb-sheet b { font-weight: 500; color: var(--azure-ink); }
.bstory__tb-scale { display: none; }
.bstory__scalebar {
  width: 64px; height: 6px; border: 1px solid var(--navy);
  background: linear-gradient(90deg, var(--navy) 0 25%, transparent 25% 50%, var(--navy) 50% 75%, transparent 75%);
}

/* caption + progress rail (hidden until JS drives them) */
.bstory__caption, .bstory__rail { display: none; }
.bstory__caption {
  align-items: baseline; gap: 12px; padding: 10px 2px 0; min-height: 2.2em;
}
.bstory__cap-no { font-family: var(--f-mono); font-weight: 500; font-size: .75rem; letter-spacing: .16em; color: var(--sub); white-space: nowrap; }
.bstory__cap-no b { font-weight: 500; color: var(--azure-ink); }
.bstory__cap-title { font-weight: 700; color: var(--navy); line-height: 1.4; min-width: 0; }
.bstory__rail { position: relative; padding: 12px 0 2px; }
.bstory__rail-track {
  position: absolute; left: 22px; right: 22px; top: 33px; height: 2px; background: var(--line);
}
.bstory__rail-fill { position: absolute; inset: 0; background: var(--amber); transform-origin: left; transform: scaleX(0); }
.bstory__rail-list { position: relative; display: flex; justify-content: space-between; }
.bstory__node {
  display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px;
  text-decoration: none; border-radius: 50%;
}
.bstory__node span {
  display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid #B9C3D3; background: var(--white);
  font-family: var(--f-mono); font-weight: 500; font-size: .6875rem; letter-spacing: .02em; color: var(--sub);
  transition: background-color .3s var(--ease), border-color .3s var(--ease), color .3s var(--ease), transform .3s var(--ease);
}
.bstory__node:hover span { border-color: var(--navy); color: var(--navy); }
.bstory__node.is-done span { border-color: var(--navy); background: var(--navy); color: var(--white); }
.bstory__node.is-active span { border-color: var(--amber); background: var(--amber); color: var(--navy-deep); transform: scale(1.12); }

/* desktop: drawing beside the steps */
@media (min-width: 900px) {
  .bstory--scene .bstory__layout {
    display: grid; grid-template-columns: minmax(0, 46fr) minmax(0, 54fr); gap: clamp(32px, 2rem + 2.5vw, 72px); align-items: start;
  }
  .bstory--scene .bstory__stage-wrap { position: sticky; top: calc(var(--header-h) + 20px); }
  .bstory__tb-scale { display: flex; }
  .bstory__titleblock { grid-template-columns: auto minmax(0, 1fr) auto auto; }
  /* whole sheet (drawing + title block + caption + rail) stays within ~82vh */
  .bstory__drawing .scene { max-height: calc(82vh - 170px); }
}
@media (min-width: 1080px) {
  .bstory-step { grid-template-columns: 72px minmax(0, 1fr); gap: 22px; }
  .bstory-step__num { width: 72px; height: 72px; font-size: 2.1rem; }
  .bstory__steps::before { left: 35px; top: 36px; bottom: 36px; }
}

/* mobile, no JS: drawing sits above the list */
@media (max-width: 899.98px) {
  .bstory--scene .bstory__stage-wrap { margin-bottom: 24px; }
  .bstory__sheet { padding: 8px 8px 0; }
  .bstory__titleblock { margin-inline: -8px; font-size: .625rem; letter-spacing: .1em; }
  .bstory__tb-cell { padding: 6px 8px; }
  .bstory__tb-brand { font-size: .875rem; }
}

/* ---------- 3. JS states ----------
   .is-live  — service-story.js is running (both motion branches)
   .is-scrub — full-motion branch: master timeline scrubbed by scroll
   Hidden states exist only under html.js-motion + .is-live, so no-JS / failsafe /
   a script error always leave the finished drawing on screen. */
.js-motion .bstory.is-live .bstory__caption { display: flex; }
.js-motion .bstory.is-live .bstory__rail { display: block; }

/* steps: spaced out so each one owns a stretch of scroll; inactive ones dimmed */
.js-motion .bstory.is-live .bstory-step {
  min-height: 62vh; align-content: start; padding-block: 0 24px; cursor: pointer;
  transition: opacity .45s var(--ease);
}
.js-motion .bstory.is-live .bstory-step:last-child { min-height: 52vh; }
.js-motion .bstory.is-live .bstory__steps { padding-bottom: 18vh; }
.js-motion .bstory.is-live .bstory__steps::before { display: none; }
.js-motion .bstory.is-live.has-active .bstory-step:not(.is-active) { opacity: .38; }
.js-motion .bstory.is-live .bstory-step.is-active .bstory-step__num { background: var(--amber); border-color: var(--amber); color: var(--navy-deep); }
.js-motion .bstory.is-live .bstory-step.is-done .bstory-step__num { background: var(--navy); color: var(--white); }

/* desktop: header hides on scroll-down (motion.js) → sheet slides up with it */
@media (min-width: 900px) {
  .js-motion .bstory.is-live .bstory__steps { padding-top: 8vh; }
  .js-motion .bstory.is-live .bstory__stage-wrap { transition: top .45s cubic-bezier(.2, .7, .2, 1); }
  .js-motion .bstory.is-live.is-hdr-off .bstory__stage-wrap { top: 20px; }
}

/* mobile: sheet sticks under the header, steps scroll beneath it */
@media (max-width: 899.98px) {
  .js-motion .bstory.is-live .bstory__stage-wrap {
    position: sticky; top: var(--header-h); z-index: 2; margin-bottom: 0;
    padding-block: 8px 10px; background: var(--paper);
    box-shadow: 0 10px 14px -12px rgba(13, 26, 58, .35);
    margin-inline: calc(var(--gutter) * -1); padding-inline: var(--gutter);
    transition: top .45s cubic-bezier(.2, .7, .2, 1);
  }
  .js-motion .bstory.is-live.is-hdr-off .bstory__stage-wrap { top: 0; }
  .js-motion .bstory.is-live .bstory__steps { padding-top: 28px; }
  .js-motion .bstory.is-live .bstory-step, .js-motion .bstory.is-live .bstory-step:last-child { min-height: 40vh; }
  .js-motion .bstory.is-live .bstory__caption { padding-top: 6px; gap: 8px; min-height: 0; }
  .js-motion .bstory.is-live .bstory__cap-title { font-size: .9375rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .js-motion .bstory.is-live .bstory__rail { padding-top: 2px; }
  .js-motion .bstory.is-live .bstory__rail-track { top: 23px; }
  /* sheet capped at ~56vh: drawing + ~130px of title block / caption / rail */
  .js-motion .bstory.is-live .bstory__drawing .scene { max-height: calc(56vh - 130px); }
}
@media (max-width: 899.98px) and (max-height: 640px) {
  .js-motion .bstory.is-live .bstory__titleblock { display: none; }
}

/* full motion: everything after the base shell starts hidden until its step plays */
.js-motion .bstory.is-scrub .scene .step,
.js-motion .bstory.is-scrub .scene .a-draw, .js-motion .bstory.is-scrub .scene .a-drop,
.js-motion .bstory.is-scrub .scene .a-pop, .js-motion .bstory.is-scrub .scene .a-fade,
.js-motion .bstory.is-scrub .scene .a-flow, .js-motion .bstory.is-scrub .scene .a-glow,
.js-motion .bstory.is-scrub .scene .a-label, .js-motion .bstory.is-scrub .scene .halo { visibility: hidden; opacity: 0; }

/* finished room without JS (failsafe, script error): show the last frame, not every step's
   scaffolding — no halos / transient tags; camera-driven scenes (data-cams) also drop the step-1
   blueprint (except [data-keep]) and earlier steps' callouts, like the artist's final frame. */
.bstory:not(.is-live) .scene .halo, .bstory:not(.is-live) .scene [data-transient] { display: none; }
.bstory:not(.is-live) .scene[data-cams] .step:not([data-step="5"]) .a-label,
.bstory:not(.is-live) .scene[data-cams] .step[data-step="1"] > :not([data-keep]) { display: none; }
/* separate rule so a browser without :has() keeps the rules above */
.bstory:not(.is-live) .scene[data-cams] .step[data-step="1"] > :has([data-keep]) { display: inline; }

/* reduced motion: whole steps cross-fade (JS); the elements themselves are never transformed.
   A centred fill-box origin is only for non-GSAP use — GSAP bakes its own SVG origin and would
   be thrown off by transform-box: fill-box, so it is not applied in the full-motion branch. */
.bstory:not(.is-scrub) .scene .a-pop, .bstory:not(.is-scrub) .scene .a-drop { transform-box: fill-box; transform-origin: center; }

@media (prefers-reduced-motion: reduce) {
  html:not(.motion-full) .bstory-step, html:not(.motion-full) .bstory__node span { transition: none; }
}
