/* ==========================================================================
   CERVINO Management Group — story.css
   Scroll-story homepage: rail + train layer, stations, route indicator,
   floating call CTA, and the Schedule a Call card. Builds on main.css tokens.
   ========================================================================== */

.story {
  position: relative;
  --gutter: clamp(72px, 8vw, 124px);
}

/* Content sits above the rail layer; section backgrounds sit below it */
.story .st-inner {
  position: relative;
  z-index: 2;
  padding-left: var(--gutter);
}

.story-page .hero { min-height: 100vh; min-height: 100svh; }
.story-page .hero-inner { z-index: 2; }

/* ---------- Rail + train layer ---------- */

.rail-layer {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  pointer-events: none;
  overflow: visible;
}

.rail-ghost {
  stroke: var(--steel);
  stroke-opacity: 0.4;
  stroke-width: 1.6;
  stroke-dasharray: 0.5 9;
  stroke-linecap: round;
}

.rail-ties {
  stroke: var(--copper);
  stroke-opacity: 0.42;
  stroke-width: 15;
  stroke-dasharray: 2.4 8;
}

.rail-steel {
  stroke: var(--copper);
  stroke-width: 9;
  stroke-linejoin: round;
}

.terminus .term-platform { fill: var(--copper); fill-opacity: 0.16; stroke: var(--copper); stroke-opacity: 0.45; }
.terminus .term-buffer { stroke: var(--copper-soft); stroke-width: 3; stroke-linecap: round; fill: none; }
.terminus .term-label {
  fill: var(--copper-soft);
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2em;
}

/* Train (top-down) */
.car-body { fill: #1B2F47; stroke: var(--copper-soft); stroke-width: 1.1; }
.car-box .car-body { fill: #2A3F58; }
.car-walk { stroke: var(--copper-soft); stroke-width: 1.2; stroke-dasharray: 3 3; opacity: 0.8; }
.car-tank .car-body { fill: #3A4D63; }
.car-line { stroke: rgba(255, 255, 255, 0.28); stroke-width: 1.4; }
.car-dome { fill: var(--copper-soft); }
.car-deck { fill: #22364D; stroke: var(--copper-soft); stroke-width: 1; }
.car-container { fill: var(--copper); stroke: #8E6F40; stroke-width: 1; }
.car-ribs { stroke: rgba(14, 27, 44, 0.22); stroke-width: 1; }
.loco-cab { fill: #2B4666; stroke: var(--copper-soft); stroke-width: 1; }
.loco-grille { stroke: rgba(255, 255, 255, 0.3); stroke-width: 1; }
.loco-lamp { fill: #F6E3BA; }
.loco-beam { opacity: 0.9; transition: opacity 0.6s var(--ease); }
.loco-brake { fill: #6E7884; transition: fill 0.4s var(--ease); }

.story.arrived .loco-beam { opacity: 0.25; }
.story.arrived .loco-brake { fill: #F0B45E; }

/* ---------- Station markers ---------- */

.st-marker {
  position: absolute;
  left: calc(var(--gutter) * 0.4 - 10px);
  top: 0.05rem;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--copper);
  transition: background 0.4s var(--ease), box-shadow 0.4s var(--ease), transform 0.4s var(--ease);
}

.st-marker::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: var(--copper);
  transform: scale(0);
  transition: transform 0.4s var(--ease);
}

.section-white .st-marker { background: var(--bg-white); }
.section-dark .st-marker,
.arrival .st-marker { background: var(--navy); }

.station.is-passed .st-marker::after { transform: scale(1); }
.station.is-active .st-marker {
  box-shadow: 0 0 0 6px rgba(176, 141, 87, 0.18), 0 0 22px rgba(176, 141, 87, 0.45);
  transform: scale(1.08);
}

/* Arrival uses the terminus instead of a lane marker */
.arrival .st-marker { display: none; }

.terminus-anchor {
  position: absolute;
  left: calc(var(--gutter) * 0.4);
  top: calc(-1 * clamp(150px, 16vw, 200px));
  width: 1px;
  height: 1px;
}

/* ---------- Station layouts ---------- */

.story .cap-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }

/* ---------- Interludes: the rail sweeps across these bands ---------- */

.interlude {
  min-height: clamp(320px, 62vh, 600px);
  display: flex;
  align-items: center;
  position: relative;
}
.interlude .st-inner { width: min(var(--container), 100% - 3rem); }
.interlude-light { background: var(--bg); }
.section-white + .interlude-light { background: var(--bg-white); }
.interlude-dark { background: linear-gradient(180deg, var(--bg-white) 0%, var(--navy) 58%); }

.interlude-line {
  font-family: var(--font-display);
  font-size: clamp(2rem, 4.6vw, 3.6rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--navy);
  max-width: 11em;
}
.interlude-line em { color: var(--copper); font-style: italic; }
.interlude-dark .interlude-line { color: #fff; }
.interlude-dark .interlude-line em { color: var(--copper-soft); }

/* ---------- Cargo marquee ---------- */

.cargo-marquee {
  position: relative;
  z-index: 2;
  display: grid;
  gap: 0.9rem;
  overflow: hidden;
  margin-left: calc((100% - min(var(--container), 100% - 3rem)) / 2 + var(--gutter));
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 6%, #000 88%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 6%, #000 88%, transparent);
}

.cargo-row {
  display: flex;
  width: max-content;
  animation: cargoRoll 46s linear infinite;
}
.cargo-row-rev { animation-direction: reverse; animation-duration: 52s; }
.cargo-marquee:hover .cargo-row { animation-play-state: paused; }

.cargo-track { display: flex; gap: 0.8rem; padding-right: 0.8rem; }

@keyframes cargoRoll {
  to { transform: translateX(-50%); }
}

/* ---------- Departure hint ---------- */

.departure-hint {
  position: absolute;
  z-index: 2;
  left: max(1.5rem, (100% - var(--container)) / 2);
  bottom: 96px;
  display: inline-flex;
  align-items: center;
  gap: 0.8rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--on-dark-muted);
  transition: opacity 0.4s var(--ease);
}
.departure-hint span {
  width: 36px;
  height: 1px;
  background: var(--copper);
  transform-origin: left;
  animation: hintPulse 2.2s var(--ease) infinite;
}
@keyframes hintPulse {
  0% { transform: scaleX(0); opacity: 1; }
  70% { transform: scaleX(1); opacity: 1; }
  100% { transform: scaleX(1); opacity: 0; }
}
.story-scrolled .departure-hint { opacity: 0; }

/* ---------- Arrival ---------- */

/* Room above the content for the train's terminus */
.story .arrival { padding-top: calc(var(--section-pad) + clamp(150px, 16vw, 200px)); }

.story.arrived .arrival .call-card { animation: cardArrive 1.2s var(--ease) 1; }
@keyframes cardArrive {
  0% { box-shadow: 0 0 0 0 rgba(176, 141, 87, 0.55), 0 40px 80px -40px rgba(0, 0, 0, 0.55); }
  100% { box-shadow: 0 0 0 18px rgba(176, 141, 87, 0), 0 40px 80px -40px rgba(0, 0, 0, 0.55); }
}

/* ---------- Route indicator (desktop) ---------- */

.route {
  position: fixed;
  right: 22px;
  top: 50%;
  z-index: 90;
  transform: translate(12px, -50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s var(--ease), transform 0.4s var(--ease);
}
.route.visible { opacity: 1; transform: translate(0, -50%); pointer-events: auto; }

.route ol {
  position: relative;
  display: grid;
  gap: 14px;
  padding: 14px 10px;
  border-radius: 999px;
  background: rgba(14, 27, 44, 0.62);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.route ol::before {
  content: "";
  position: absolute;
  top: 22px; bottom: 22px;
  left: 50%;
  width: 1px;
  background: rgba(176, 141, 87, 0.35);
}

.route a { position: relative; display: block; width: 12px; height: 12px; }
.route i {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--navy);
  border: 1.5px solid var(--copper-soft);
  transition: background 0.3s var(--ease), transform 0.3s var(--ease);
}
.route a.passed i { background: var(--copper); }
.route a.current i { transform: scale(1.35); background: var(--copper-soft); box-shadow: 0 0 12px rgba(197, 165, 114, 0.7); }

.route span {
  position: absolute;
  right: calc(100% + 18px);
  top: 50%;
  transform: translate(6px, -50%);
  white-space: nowrap;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: #fff;
  background: rgba(14, 27, 44, 0.9);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
}
.route a:hover span,
.route a:focus-visible span,
.route a.current span { opacity: 1; transform: translate(0, -50%); }

/* Mobile route: thin progress line + station chip */
.route-mobile { display: none; }

/* ---------- Floating Schedule a Call ---------- */

.call-float {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 95;
  box-shadow: 0 18px 40px -16px rgba(14, 27, 44, 0.55);
  opacity: 0;
  transform: translateY(16px);
  pointer-events: none;
  transition: opacity 0.35s var(--ease), transform 0.35s var(--ease), background var(--speed) var(--ease);
}
.call-float.show { opacity: 1; transform: none; pointer-events: auto; }

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .route { display: none; }

  .route-mobile {
    display: block;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 3px;
    z-index: 120;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s var(--ease);
  }
  .route-mobile.visible { opacity: 1; }
  .route-mobile-fill {
    display: block;
    height: 100%;
    width: 100%;
    background: var(--copper);
    transform-origin: left;
    transform: scaleX(var(--progress, 0));
  }
  .route-mobile-label {
    position: absolute;
    top: 74px;
    right: 16px;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #fff;
    background: rgba(14, 27, 44, 0.85);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 0.35s var(--ease), transform 0.35s var(--ease);
  }
  .route-mobile.flash .route-mobile-label { opacity: 1; transform: none; }
}

@media (max-width: 900px) {
  .story .cap-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .story { --gutter: 40px; }
  .story .cap-grid { grid-template-columns: 1fr; }
  .st-marker { width: 16px; height: 16px; left: calc(var(--gutter) * 0.4 - 8px); top: 0.1rem; }
  .interlude { min-height: 64vh; align-items: flex-start; padding-top: 3rem; }
  .interlude-line { font-size: clamp(1.7rem, 7vw, 2.3rem); }
  .departure-hint { display: none; }
  .call-float { left: 16px; right: 16px; bottom: 16px; }
  .call-embed iframe { height: 720px; }
}

/* ---------- Reduced motion: a static timeline ---------- */

@media (prefers-reduced-motion: reduce) {
  .cargo-row { animation: none; width: auto; flex-wrap: wrap; }
  .cargo-row .cargo-track { flex-wrap: wrap; row-gap: 0.8rem; }
  .cargo-row .cargo-track[aria-hidden="true"] { display: none; }
  .cargo-marquee { -webkit-mask-image: none; mask-image: none; }
  .departure-hint span { animation: none; transform: none; }
  .story.arrived .arrival .call-card { animation: none; }
}
