/*
 * Hero story (assets/js/fl-story.js). Without JS the figure shows the finished Bill Audit
 * scene; .fl-story--live (added by the script) is the only thing that hides parts of it.
 */
.fl-story {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 20px 16px;
  border-radius: var(--fl-radius-lg);
}

/* ---------- Journey stepper ---------- */
.fl-story__journey {
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin: 0;
  padding: 0 0 30px;
  list-style: none;
}
.fl-story__journey li[data-stage-item] {
  position: relative;
  padding-top: 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--fl-muted);
  text-align: center;
  transition: color 0.3s ease;
}
.fl-story__journey li[data-stage-item]::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  border-radius: 4px;
  background: rgba(23, 37, 59, 0.1);
  transition: background 0.4s ease;
}
.fl-story[data-stage="consult"] [data-stage-item="consult"],
.fl-story[data-stage="counsel"] [data-stage-item="counsel"],
.fl-story[data-stage="stay"] [data-stage-item="stay"],
.fl-story[data-stage="bill"] [data-stage-item="bill"],
.fl-story[data-stage="discharge"] [data-stage-item="discharge"] {
  color: var(--fl-ink);
}
.fl-story[data-stage="consult"] [data-stage-item="consult"]::before,
.fl-story[data-stage="counsel"] [data-stage-item="counsel"]::before,
.fl-story[data-stage="stay"] [data-stage-item="stay"]::before,
.fl-story[data-stage="bill"] [data-stage-item="bill"]::before,
.fl-story[data-stage="discharge"] [data-stage-item="discharge"]::before {
  background: linear-gradient(90deg, #17253b, #22a6b3);
}
.fl-story__pin {
  position: absolute;
  bottom: 0;
  left: 80%;
  display: none;
  transform: translateX(-50%);
  white-space: nowrap;
  transition: left 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.fl-story[data-scene="audit"] .fl-story__pin {
  display: block;
}
.fl-story[data-pin="after"] .fl-story__pin {
  left: 100%;
  transform: translateX(-100%);
}
.fl-story__pin span {
  display: none;
  padding: 3px 10px;
  border-radius: var(--fl-radius-pill);
  font-size: 12px;
  font-weight: 500;
}
.fl-story[data-pin="after"] [data-pin-show="after"] {
  display: inline-block;
  background: rgba(223, 61, 51, 0.12);
  color: var(--fl-danger);
}
.fl-story[data-pin="before"] [data-pin-show="before"] {
  display: inline-block;
  background: rgba(34, 166, 179, 0.16);
  color: #0e6670;
}

/* ---------- Stage: sources | hub | results ---------- */
.fl-story__stage {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 28px;
}
.fl-story__sources {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.fl-story__sources li {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 6px;
  border-radius: var(--fl-radius-sm);
  background: var(--fl-glass-bg);
  border: 1px solid var(--fl-glass-border);
  box-shadow: 0 8px 24px -14px rgba(var(--fl-glass-shadow-rgb), 0.3);
  text-align: center;
  opacity: 0.55;
  transition: opacity 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease;
}
.fl-story__sources li.is-used {
  opacity: 1;
}
.fl-story__sources li.is-reading {
  transform: translateY(-2px);
  box-shadow: 0 0 0 2px rgba(34, 166, 179, 0.55), 0 10px 28px -12px rgba(34, 166, 179, 0.6);
}
.fl-story__sources strong {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--fl-ink);
  line-height: 1.25;
}
.fl-story__sources small {
  display: none;
  font-size: 12px;
  color: var(--fl-muted);
}
.fl-story__icon {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 10px;
}
.fl-story svg path,
.fl-story svg circle,
.fl-story svg rect {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.fl-story__icon svg {
  width: 16px;
  height: 16px;
}

.fl-story__hub {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 12px;
  align-items: center;
  align-self: center;
  padding: 16px;
  border-radius: var(--fl-radius-md);
  background: linear-gradient(140deg, #17253b, #3a506b 55%, #4a8db7);
  color: #fff;
  box-shadow: 0 18px 40px -18px rgba(23, 37, 59, 0.6);
}
.fl-story--live .fl-story__hub::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: calc(var(--fl-radius-md) + 6px);
  border: 2px solid rgba(34, 166, 179, 0.45);
  animation: fl-story-pulse 2.4s ease-out infinite;
  pointer-events: none;
}
@keyframes fl-story-pulse {
  0% {
    opacity: 0.9;
    transform: scale(0.98);
  }
  100% {
    opacity: 0;
    transform: scale(1.06);
  }
}
.fl-story__hub-icon {
  grid-row: span 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.14);
}
.fl-story__hub-icon svg {
  display: none;
  width: 22px;
  height: 22px;
}
.fl-story[data-scene="consult"] [data-hub-for="consult"],
.fl-story[data-scene="counsel"] [data-hub-for="counsel"],
.fl-story[data-scene="stay"] [data-hub-for="stay"],
.fl-story[data-scene="audit"] [data-hub-for="audit"],
.fl-story[data-scene="discharge"] [data-hub-for="discharge"] {
  display: block;
}
.fl-story__hub-eyebrow {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
}
.fl-story__hub-name {
  min-height: 2.5em;
  white-space: pre-line;
  line-height: 1.25;
  font-size: 17px;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.fl-story__hub-status {
  min-height: 2.8em;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.74);
}

.fl-story__out {
  position: relative;
  z-index: 2;
  display: grid;
  padding: 18px;
  border-radius: var(--fl-radius-md);
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--fl-glass-border);
  box-shadow: 0 12px 40px -16px rgba(var(--fl-glass-shadow-rgb), 0.3);
}
/* All panels share one grid cell, so the box keeps the tallest panel's height across scenes. */
.fl-story__panel {
  grid-area: 1 / 1;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.35s ease;
}
.fl-story[data-scene="consult"] [data-out="consult"],
.fl-story[data-scene="counsel"] [data-out="counsel"],
.fl-story[data-scene="stay"] [data-out="stay"],
.fl-story[data-scene="audit"] [data-out="audit"],
.fl-story[data-scene="discharge"] [data-out="discharge"] {
  visibility: visible;
  opacity: 1;
}
.fl-story [data-phase-show] {
  display: none;
}
.fl-story[data-phase="problem"] [data-phase-show="problem"],
.fl-story[data-phase="fix"] [data-phase-show="fix"] {
  display: block;
}
.fl-story__example {
  position: absolute;
  top: 14px;
  right: 14px;
  padding: 2px 8px;
  border-radius: var(--fl-radius-pill);
  background: var(--fl-surface-2);
  font-size: 11px;
  color: var(--fl-muted);
}
.fl-story__eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 64px 12px 0;
  font-size: 15px;
  font-weight: 500;
  color: var(--fl-ink);
}
.fl-story__time {
  padding: 2px 8px;
  border-radius: var(--fl-radius-pill);
  background: rgba(34, 166, 179, 0.14);
  font-size: 12px;
  color: #0e6670;
}
.fl-story__rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.fl-story__rows li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: baseline;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--fl-surface);
  font-size: 13.5px;
  color: var(--fl-ink-2);
  transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.fl-story__rows em {
  font-style: normal;
  font-size: 11.5px;
  color: var(--fl-muted);
}
/* Text results are too long to sit beside the label: they get their own line. */
.fl-story__rows--text li {
  grid-template-columns: minmax(0, 1fr) auto;
  row-gap: 2px;
}
.fl-story__rows.fl-story__rows--text b {
  grid-column: 1 / -1;
  text-align: left;
}
.fl-story__rows--text .fl-story__ok {
  color: #17724b;
}
.fl-story__rows--text em.fl-story__st {
  padding: 1px 8px;
  border-radius: var(--fl-radius-pill);
  background: var(--fl-surface-2);
}
.fl-story__rows--text em.fl-story__st--ok {
  background: rgba(29, 138, 91, 0.13);
  color: #17724b;
}
.fl-story__rows--text em.fl-story__st--open {
  background: rgba(223, 61, 51, 0.1);
  color: var(--fl-danger);
}
.fl-story__rows--gaps li {
  grid-template-columns: minmax(0, 1fr) auto;
}
.fl-story__rows--gaps b {
  color: var(--fl-danger);
}
.fl-story__rows b {
  font-weight: 500;
  color: var(--fl-ink);
  text-align: right;
}
.fl-story__split {
  background: rgba(34, 166, 179, 0.1) !important;
}
.fl-story--live .fl-story__rows li[data-row]:not(.is-on) {
  opacity: 0;
  transform: translateY(6px);
}
.fl-story__compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.fl-story__compare div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px;
  border-radius: 12px;
  background: var(--fl-surface);
  font-size: 13px;
  color: var(--fl-muted);
}
.fl-story__compare strong {
  font-size: clamp(20px, 5.4vw, 26px);
  font-weight: 500;
  color: var(--fl-ink);
}
.fl-story__compare .is-bad {
  background: rgba(223, 61, 51, 0.08);
}
.fl-story__compare .is-bad strong {
  color: var(--fl-danger);
}
.fl-story__total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--fl-line);
  font-size: 13.5px;
  color: var(--fl-ink-2);
}
.fl-story__total strong {
  font-size: 26px;
  font-weight: 500;
  color: var(--fl-ink);
  font-variant-numeric: tabular-nums;
}
.fl-story__total.is-good strong {
  color: #0e7490;
}
.fl-story__note {
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--fl-muted);
}

/* Wires and bots sit under the cards (z-index 2) so routes tuck behind them. */
.fl-story__wires {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}
.fl-story .fl-story__wires path {
  stroke: rgba(34, 166, 179, 0.5);
  stroke-width: 1.5;
  stroke-dasharray: 4 5;
}
.fl-story__bots {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}
.fl-story__bot {
  position: absolute;
  top: 0;
  left: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22a6b3;
  box-shadow: 0 0 0 4px rgba(34, 166, 179, 0.22), 0 0 12px rgba(34, 166, 179, 0.6);
  opacity: 0;
}

/* ---------- Controls ---------- */
.fl-story__controls {
  display: flex;
  align-items: center;
  gap: 10px;
}
.fl-story__tabs {
  display: flex;
  flex: 1;
  gap: 6px;
  overflow-x: auto;
}
.fl-story__tabs button,
.fl-story__pause {
  position: relative;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--fl-glass-border);
  border-radius: var(--fl-radius-pill);
  background: rgba(255, 255, 255, 0.55);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--fl-ink-2);
  white-space: nowrap;
  overflow: hidden;
  cursor: pointer;
}
.fl-story__tabs button.is-active {
  background: #fff;
  color: var(--fl-ink);
}
/* Progress bar under the running scene's button. */
.fl-story__tabs button::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 0;
  background: #22a6b3;
}
.fl-story__tabs button.is-running::after {
  animation: fl-story-progress var(--dur, 8s) linear forwards;
}
@keyframes fl-story-progress {
  to {
    width: 100%;
  }
}
.fl-story__pause {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 6px;
}
.fl-story__pause svg {
  width: 14px;
  height: 14px;
}
.fl-story__pause .fl-story__play-icon,
.fl-story__pause[aria-pressed="true"] .fl-story__pause-icon {
  display: none;
}
.fl-story__pause[aria-pressed="true"] .fl-story__play-icon {
  display: inline;
}
.fl-story:not(.fl-story--live) .fl-story__controls {
  display: none;
}

/* ---------- Wide: sources | hub | results ---------- */
@media (min-width: 900px) {
  .fl-story {
    padding: 28px 32px;
  }
  .fl-story__stage {
    grid-template-columns: minmax(0, 0.78fr) minmax(200px, 0.62fr) minmax(0, 1.25fr);
    gap: 56px;
    align-items: center;
  }
  .fl-story__sources {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }
  .fl-story__sources li {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    text-align: left;
  }
  .fl-story__sources small {
    display: block;
  }
  .fl-story__icon {
    width: 34px;
    height: 34px;
  }
  .fl-story__hub {
    grid-template-columns: 1fr;
    justify-items: start;
    row-gap: 4px;
    padding: 20px;
  }
  .fl-story__hub-icon {
    grid-row: auto;
    margin-bottom: 8px;
  }
  .fl-story__journey li[data-stage-item] {
    font-size: 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .fl-story *,
  .fl-story *::before,
  .fl-story *::after {
    transition: none !important;
    animation: none !important;
  }
}

/* Narrow: keep the audit pin inside the box, right-aligned, in both states. */
@media (max-width: 899px) {
  /* Sources sit in two rows here, so bots travel under the cards rather than across them. */
  .fl-story__bots {
    z-index: 1;
  }
  /* Two rows of sources: wires to the top row would cut through the bottom row, so the bots alone show the reading. */
  .fl-story__wires {
    display: none;
  }
  .fl-story__controls {
    flex-wrap: wrap;
  }
  .fl-story__tabs {
    display: grid;
    flex-basis: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .fl-story__tabs button:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
  .fl-story__journey {
    gap: 4px;
  }
  .fl-story__journey li[data-stage-item] {
    font-size: 10.5px;
    letter-spacing: -0.01em;
    overflow-wrap: anywhere;
  }
  .fl-story__pause {
    margin-left: auto;
  }
  .fl-story__pin,
  .fl-story[data-pin="after"] .fl-story__pin {
    left: auto;
    right: 0;
    transform: none;
  }
}
