/* Styles for assets/story.js, the visual storytelling layer on top of viz.js. story.js loads this file itself.
   Colours come only from the --calc-* variables (see viz.css). This file is the source: edit it directly.
   .story-* the story panel, .sl-* the story line chart and its callouts, .units-* the dot chart, .yd-* you draw it. */

/* story: one panel (chart, words, Back/Next) in the text column. The steps share one grid cell, so the panel is as
   tall as its longest step and the words fade from one to the next without anything moving. With .pinned (set by
   story.js when the panel fits the screen) the panel sticks while its track, as tall as the steps need, scrolls by.
   Figures are cards: a tinted surface (--calc-surface) that sets them apart from the prose, bleeding a little into
   the margin so their contents line up with the text. Inside a card --calc-bg is the surface, so label halos,
   buttons and callouts match it. Spacing: 40px above a card, 72px below it, more than a heading's own 48px, so each
   figure closes its section clearly. */
.story { margin: 40px 0 72px; }
.story-panel, .yd, .story-card {
  --calc-bg: var(--calc-surface);
  background: var(--calc-surface);
  padding: 22px 24px 18px;
  border: 1px solid color-mix(in srgb, var(--calc-rule) 80%, transparent);
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.03);
  box-sizing: border-box;
}
.story-panel { margin-inline: -24px; }
.yd, .story-card { margin: 40px -24px 72px; }   /* .story-card: any other figure, styled to match */
@media (max-width: 560px) {
  .story-panel, .yd, .story-card { padding: 16px 14px 14px; }
  .story-panel { margin-inline: -14px; }
  .yd, .story-card { margin-inline: -14px; }
}
.yd .viz-note { margin: 14px 0 0; }
.story:focus { outline: 0; }
.story-panel { display: flex; flex-direction: column; gap: 14px; }
.story.pinned .story-panel { position: sticky; }
.story-steps { display: grid; }
/* a new step's words rise into place, so the change is seen even with eyes on the chart */
/* A change of step has to be seen, or the reader watches the chart and misses the words. So: the old words leave
   quickly the way the reader is travelling, the new ones slide in behind them, the rule beside them draws itself
   from the top, and the opening bold phrase is swept once by a highlighter. --dir (1 on, -1 back) is set by story.js. */
.story-step { grid-area: 1 / 1; position: relative; padding-left: 15px; opacity: 0; pointer-events: none;
  font-size: .94rem; line-height: 1.55; color: var(--calc-text); }
.story-step.on { opacity: 1; pointer-events: auto; animation: story-in .46s .17s cubic-bezier(.2, .7, .2, 1) backwards; }
.story-step.was { animation: story-out .15s ease-in both; }
.story-step::before { content: ""; position: absolute; left: 0; top: .3em; bottom: .25em; width: 3px; background: var(--calc-accent); transform-origin: top; }
.story-step.on::before { animation: story-rule .55s .17s cubic-bezier(.2, .7, .2, 1) backwards; }
.story-step.on > p:first-child > :is(b, strong):first-child {
  background: linear-gradient(color-mix(in srgb, var(--calc-accent) 24%, transparent) 0 0) no-repeat left / 0% 100%;
  animation: story-mark 1.7s .3s ease-in-out both; }
@keyframes story-in { from { opacity: 0; transform: translateY(calc(var(--dir, 1) * 26px)); } }
@keyframes story-out { from { opacity: 1; } to { opacity: 0; transform: translateY(calc(var(--dir, 1) * -14px)); } }
@keyframes story-rule { from { transform: scaleY(0); } }
@keyframes story-mark {
  0% { background-size: 0% 100%; background-position: left; }
  30%, 62% { background-size: 100% 100%; background-position: left; }
  62.01% { background-size: 100% 100%; background-position: right; }
  100% { background-size: 0% 100%; background-position: right; } }
.story-step p:last-child { margin-bottom: 0; }
.story-step :is(b, strong) { color: var(--calc-ink); font-weight: 600; }
.story-nav { display: flex; align-items: center; gap: 8px; padding-top: 12px; border-top: 1px solid var(--calc-rule); font-size: .82rem; }
.story-nav > button { font: inherit; white-space: nowrap; padding: 6px 14px; border: 1px solid var(--calc-rule); border-radius: 0;
  cursor: pointer; background: var(--calc-bg); color: var(--calc-ink); }
.story-nav > .story-next { margin-left: auto; background: var(--calc-accent); border-color: var(--calc-accent); color: var(--calc-bg); }
.story-nav > button:disabled { opacity: .35; cursor: default; }
.story-nav button:focus-visible { outline: 2px solid var(--calc-accent); outline-offset: 2px; }
.story-dots { display: flex; }
.story-dots button { width: 18px; height: 22px; padding: 0; border: 0; background: none; cursor: pointer; position: relative; }
.story-dots button::after { content: ""; position: absolute; inset: 7px 5px; border-radius: 50%; background: var(--calc-rule); transition: background .3s; }
.story-dots button::after { transition: background .3s, inset .3s, border-radius .3s; }
.story-dots button.on::after { background: var(--calc-accent); inset: 7px 1px; border-radius: 4px; }   /* the step you are on is a pill */
.story-head { margin: 0 0 6px; }
@media (max-width: 760px) { .story-head { min-height: 4.4em; } }   /* titles may wrap: room for two lines, so the chart holds still */
.story-head .viz-kicker { margin-bottom: 2px; }
.story-head .viz-title { margin: 0; font-size: 1.05rem; }
.story .units-key { gap: 2px 12px; font-size: .7rem; margin-top: 6px; }
@media (max-width: 560px) {
  .story-head { min-height: 4.8em; }
  .units-labels .units-row-label, .units-labels .units-row-value { font-size: .66rem; line-height: 1.15; }
  .story .units-key { flex-wrap: nowrap; overflow-x: auto; white-space: nowrap; scrollbar-width: none; }   /* one row to swipe */
  .story-nav > button { padding: 6px 10px; }
  .story-dots button { width: 13px; }
  .story-dots button::after { inset: 8px 3px; }
}
@media (prefers-reduced-motion: reduce) { .story-step, .story-step::before, .story-step :is(b, strong) { animation: none !important; } .story-dots button::after { transition: none; } }

.sl, .yd-stage {
  position: relative;
}

.sl {
  user-select: none;
}

.sl-svg {
  touch-action: pan-y;
}

.sl-notes {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.sl-note {
  position: absolute;
  font-size: 0.74rem;
  line-height: 1.38;
  color: var(--calc-ink);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.5s, transform 0.5s;
}
.sl-note span {
  background: color-mix(in srgb, var(--calc-bg) 86%, transparent);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  padding: 1px 3px;
}
.sl-note b {
  font-weight: 400;
  color: var(--calc-accent);
}

.sl-notes.on .sl-note {
  opacity: 1;
  transform: none;
}

.sl-note-marks g {
  opacity: 0;
  transition: opacity 0.5s;
}

.sl-note-marks.on g {
  opacity: 1;
}

.sl-leader {
  fill: none;
  stroke: var(--calc-ink);
  stroke-opacity: 0.7;
  stroke-width: 1;
}

.sl-ring {
  fill: none;
  stroke: var(--calc-ink);
  stroke-width: 1.5;
}

.sl-ring-dot {
  fill: var(--calc-ink);
}

.sl-pen {
  stroke: var(--calc-bg);
  stroke-width: 2;
}

@media (prefers-reduced-motion: reduce) {
  .sl-note, .sl-note-marks g {
    transition: none;
  }
}
.units-stage {
  position: relative;
}

.units-canvas {
  display: block;
  max-width: 100%;   /* before its first paint a canvas has its own width, which can be wider than a phone */
  touch-action: pan-y;
}

.units-labels {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.45s;
}

.units-labels.on {
  opacity: 1;
}

.units-labels > div {
  position: absolute;
  font-size: 0.76rem;
  line-height: 1.25;
  color: var(--calc-muted);
}

.units-labels .units-set-label {
  font-size: 0.84rem;
  color: var(--calc-ink);
}

.units-labels .units-set-total {
  font-size: 1.1rem;
  color: var(--calc-ink);
  font-variant-numeric: tabular-nums;
}

.units-labels .units-row-label {
  color: var(--calc-ink);
}

.units-labels .units-row-value {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.units-key {
  margin-top: 12px;
}
.units-key button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 2px 0;
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: default;
}
.units-key button.viz-pick {
  cursor: pointer;
}
.units-key button:focus-visible {
  outline: 2px solid var(--calc-accent);
  outline-offset: 2px;
}
.units-key i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.yd {
  user-select: none;
  -webkit-user-select: none;
}

.yd svg {
  touch-action: none;
  cursor: crosshair;
}

.yd.revealed svg {
  touch-action: pan-y;
  cursor: default;
}

.yd .yd-zone {
  fill: var(--calc-accent);
  fill-opacity: 0.06;
  stroke: var(--calc-accent);
  stroke-opacity: 0.35;
  stroke-dasharray: 3 4;
}

.yd .yd-zone.done {
  fill-opacity: 0;
  stroke-opacity: 0;
}

.yd .yd-known-area {
  stroke: none;
}

.yd .yd-diff {
  fill: var(--calc-accent);
  fill-opacity: 0.14;
  stroke: none;
}

.yd .yd-known {
  fill: none;
  stroke: var(--calc-ink);
  stroke-width: 2.5;
  stroke-linejoin: round;
}

.yd .yd-known-dot {
  fill: var(--calc-ink);
}

.yd .yd-guess {
  fill: none;
  stroke: var(--calc-accent);
  stroke-width: 2.5;
  stroke-dasharray: 7 5;
  stroke-linejoin: round;
}

.yd .yd-guess-dot {
  fill: var(--calc-accent);
}

.yd .yd-actual {
  fill: none;
  stroke: var(--calc-ink);
  stroke-width: 3;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.yd .yd-actual-dot {
  fill: var(--calc-ink);
  stroke: var(--calc-bg);
  stroke-width: 1.5;
}

.yd text.yd-value {
  fill: var(--calc-ink);
  font-size: 12px;
  paint-order: stroke;
  stroke: var(--calc-bg);
  stroke-width: 3px;
}

.yd text.yd-guess-label {
  fill: var(--calc-accent);
}

/* the cue: once the chart is in view the drawing area glows a few times and a ring pulses on the point to start
   from, until the reader draws (story.js removes .cue) */
.yd text.yd-draw-here { fill: var(--calc-ink); font-size: 17px; }
.yd text.yd-draw-how { fill: var(--calc-muted); font-size: 12.5px; }
.yd .yd-start { fill: none; stroke: var(--calc-accent); stroke-width: 2; vector-effect: non-scaling-stroke; opacity: 0;
  transform-box: fill-box; transform-origin: center; }
.yd.cue .yd-start { animation: yd-ring 1.6s ease-out infinite; }
.yd.cue .yd-zone { animation: yd-glow 1.8s ease-in-out 4; }
.yd.cue text.yd-draw-here { animation: yd-pulse 1.8s ease-in-out infinite; }
@keyframes yd-ring { from { transform: scale(1); opacity: .9; } to { transform: scale(4.5); opacity: 0; } }
@keyframes yd-glow { 50% { fill-opacity: .13; stroke-opacity: .95; } }
@keyframes yd-pulse { 50% { opacity: .6; } }
.yd-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin-top: 8px;
}

.yd-hint {
  font-size: 0.8rem;
  color: var(--calc-muted);
  margin: 0;
}

.yd-btn {
  font: inherit;
  font-size: 0.85rem;
  padding: 7px 16px;
  border: 1px solid var(--calc-accent);
  background: var(--calc-accent);
  color: var(--calc-bg);
  border-radius: 0;
  cursor: pointer;
}
.yd-btn:disabled {
  opacity: 0.35;
  cursor: default;
}
.yd-btn:focus-visible {
  outline: 2px solid var(--calc-accent);
  outline-offset: 2px;
}

.yd-verdict {
  font-size: 0.95rem;
  line-height: 1.5;
  margin: 10px 0 0;
  color: var(--calc-text);
}
.yd-verdict b {
  color: var(--calc-ink);
  font-weight: 400;
}

@media (prefers-reduced-motion: reduce) {
  .yd.cue :is(.yd-zone, .yd-start, text.yd-draw-here) { animation: none; }
  .yd.cue .yd-zone { fill-opacity: .14; stroke-opacity: .8; }
  .yd.cue .yd-start { opacity: .8; transform: scale(2.2); }
}

/* youDraw's events: numbered markers under the axis, and a key that uses the same numbers */
.yd .yd-event line { stroke: var(--calc-muted); stroke-opacity: .55; stroke-dasharray: 2 3; }
.yd .yd-event circle { fill: var(--calc-bg); stroke: var(--calc-muted); }
.yd .yd-event text { fill: var(--calc-ink); font-size: 10.5px; }
.yd .yd-event:is(:hover, :focus-visible) circle { fill: var(--calc-ink); stroke: var(--calc-ink); }
.yd .yd-event:is(:hover, :focus-visible) text { fill: var(--calc-bg); }
.yd .yd-event { outline: 0; cursor: default; }
.yd-events { counter-reset: ev; list-style: none; margin: 8px 0 4px; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 18px;
  font-size: .76rem; line-height: 1.35; color: var(--calc-muted); }
.yd-events li { counter-increment: ev; display: flex; align-items: baseline; gap: 6px; }
.yd-events li::before { content: counter(ev); flex: none; width: 18px; height: 18px; border: 1px solid var(--calc-muted); border-radius: 50%;
  font-size: .66rem; line-height: 16px; text-align: center; color: var(--calc-ink); }

/* the label a units chart puts over its highlighted dots */
.units-labels .units-callout { font-size: .95rem; line-height: 1.3; color: var(--calc-ink); text-align: center; max-width: 92%;
  background: color-mix(in srgb, var(--calc-bg) 90%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--calc-rule); border-radius: 6px; padding: 5px 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .14); }
@media (max-width: 560px) { .units-labels .units-callout { font-size: .8rem; padding: 3px 8px; } }

/* ---- Time map: areas that come and go, on canvas (timeMap) ---- */
.tm-stage {
  position: relative;
  overflow: hidden;
  border-radius: 6px;
}

.tm-canvas {
  display: block;
  max-width: 100%;
  touch-action: pan-y;
}

.tm-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.tm-labels span {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 0.7rem;
  line-height: 1.15;
  text-align: center;
  color: var(--calc-muted);
  white-space: nowrap;
  text-shadow: 0 0 3px var(--calc-bg), 0 0 3px var(--calc-bg);
}

/* the clock: the year large, a number or two beneath it */
.tm-readout {
  position: absolute;
  left: 10px;
  top: 10px;
  padding: 8px 14px;
  pointer-events: none;
  font-size: 0.76rem;
  line-height: 1.35;
  color: var(--calc-muted);
  font-variant-numeric: tabular-nums;
  background: color-mix(in srgb, var(--calc-bg, #fff) 80%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid color-mix(in srgb, var(--calc-rule) 75%, transparent);
  border-radius: 7px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.08);
}

.tm-readout b {
  display: block;
  font-weight: 400;
  font-size: 2.2rem;
  line-height: 1;
  color: var(--calc-ink);
}

.tm-readout span {
  display: block;
}

.tm-key {
  margin-top: 8px;
}

@media (max-width: 560px) {
  .tm-readout { left: 6px; top: 6px; padding: 5px 9px; }
  .tm-readout b { font-size: 1.5rem; }
  .tm-labels span { font-size: 0.62rem; }
}
