/* The MRR waterfall chart: the MRR card of a made-up subscription analytics app on a dark page.
   Bars, bridges, ruler and figures are drawn in pixels by the script inside one SVG at every frame;
   here are the materials of the card, the glass label and the colours. */
:root {
  --page: #07080b;          /* the page */
  --card: #17181f;          /* the top of the card */
  --card-low: #0f1015;      /* the bottom of the card */
  --ink: #f2f3f7;           /* the words */
  --muted: #8a8d9b;         /* the small words */
  --faint: #545766;         /* the guides' figures */
  --line: rgba(255, 255, 255, 0.07); /* hairlines */
  --total: #8f94ff;         /* the two totals */
  --total-hi: #c3c6ff;      /* the light top of a total */
  --total-lo: #5a5fe6;      /* the foot of a total */
  --up: #3ddc97;            /* money coming in */
  --up-lo: #14a06c;
  --down: #ff7b6b;          /* money going out */
  --down-lo: #d94a3a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { touch-action: manipulation; }

html, body { height: 100%; overflow-x: clip; }

body {
  background:
    radial-gradient(80% 60% at 50% 38%, rgba(110, 116, 255, 0.07), transparent 70%),
    var(--page);
  color: var(--ink);
  font-family: 'Mona Sans Variable', 'Mona Sans', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.stage {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 12px;
}

/* ---- the card ---- */
.card {
  position: relative;
  width: min(92vw, 580px);
  border-radius: 22px;
  padding: clamp(14px, 3.4vh, 26px) clamp(14px, 4.4vw, 28px) clamp(8px, 2vh, 16px);
  background: linear-gradient(180deg, var(--card) 0%, var(--card-low) 100%);
  box-shadow:
    inset 0 0 0 1px var(--line),
    0 1px 1px rgba(0, 0, 0, 0.5),
    0 8px 20px -8px rgba(0, 0, 0, 0.6),
    0 40px 80px -30px rgba(40, 44, 140, 0.45);
  opacity: 0;
}

/* the top edge catches the light, brightest a little left of centre */
.card__rim {
  position: absolute;
  left: 14%;
  right: 14%;
  top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.34) 35%, rgba(195, 198, 255, 0.22) 65%, transparent);
  pointer-events: none;
}

.card__sheen {
  position: absolute;
  inset: 0 0 auto;
  height: 70%;
  border-radius: inherit;
  background: radial-gradient(110% 70% at 30% 0%, rgba(143, 148, 255, 0.09), transparent 70%);
  pointer-events: none;
}

.card__head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.card__id { display: flex; align-items: center; gap: 10px; min-width: 0; }

.card__mark { width: 28px; height: 28px; flex: none; }
.card__mark rect { fill: #24252e; stroke: rgba(255, 255, 255, 0.1); }
.card__mark path { fill: none; stroke: var(--total-hi); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.card__title {
  font-size: clamp(13px, 2.2vh, 15px);
  font-weight: 600;
  font-variation-settings: 'wdth' 104;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.card__sub {
  margin-top: 1px;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
}

.card__sep { color: var(--faint); margin: 0 2px; }

/* ---- the net pill ---- */
.net {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 620;
  padding: 4px 9px 4px 6px;
  border-radius: 999px;
  white-space: nowrap;
}

.net svg { width: 11px; height: 11px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.net__word { font-weight: 480; opacity: 0.72; margin-left: 2px; }

.is-up { color: var(--up); background: rgba(61, 220, 151, 0.1); box-shadow: inset 0 0 0 1px rgba(61, 220, 151, 0.16); }
.is-down { color: var(--down); background: rgba(255, 123, 107, 0.1); box-shadow: inset 0 0 0 1px rgba(255, 123, 107, 0.16); }
.is-flat { color: var(--total-hi); background: rgba(143, 148, 255, 0.1); box-shadow: inset 0 0 0 1px rgba(143, 148, 255, 0.16); }
.is-down svg { transform: scaleY(-1); }

/* ---- the total ---- */
.total { position: relative; margin-top: clamp(10px, 2.6vh, 20px); }

.total__label {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
}

.total__row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 4px;
}

.total__num {
  display: flex;
  font-size: clamp(28px, min(9vw, 8.6vh), 42px);
  line-height: 1;
  font-weight: 600;
  font-variation-settings: 'wdth' 96;
  letter-spacing: -0.03em;
}

/* each digit sits in its own window of the same width, so the figure never jumps as it rolls */
.roll { display: inline-block; width: 0.6em; height: 1em; overflow: hidden; text-align: center; }
.roll__col { display: flex; flex-direction: column; }
.roll__col span { height: 1em; line-height: 1; }
.roll__sign { display: inline-block; line-height: 1; }
.roll__sign.is-comma { width: 0.22em; text-align: center; }

.chip {
  display: inline-flex;
  align-items: center;
  font-size: 11.5px;
  font-weight: 620;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

/* ---- the chart ---- */
.chart {
  position: relative;
  height: clamp(116px, 34vh, 236px);
  margin-top: clamp(8px, 2vh, 16px);
  border-radius: 10px;
  touch-action: pan-y;
  cursor: crosshair;
}

.plot { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }

.plot .grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 4; }
.plot .grid.is-base { stroke: rgba(255, 255, 255, 0.12); stroke-dasharray: none; }
.plot .gridlab { fill: var(--faint); font-size: 10px; }
.plot .brk { fill: none; stroke: var(--faint); stroke-width: 1.1; stroke-linecap: round; stroke-linejoin: round; }

.plot .bridge { stroke: rgba(255, 255, 255, 0.22); stroke-width: 1; stroke-dasharray: 2 3; transition: stroke 0.3s; }
.plot .bridge.is-on { stroke: rgba(255, 255, 255, 0.7); stroke-dasharray: none; }

.plot .bar { transition: filter 0.35s; }
.plot .bar.is-on { filter: brightness(1.14) saturate(1.1); }
.plot .bar__ring { fill: none; stroke-width: 3; opacity: 0; transition: opacity 0.3s; }
.plot .bar.is-on .bar__ring { opacity: 0.22; }
.plot .bar__cap { fill: rgba(255, 255, 255, 0.55); }
.plot .bar__gloss { fill: url(#gloss); }
.plot .bar__shadow { opacity: 0.5; }

.plot .val { font-size: 10px; font-weight: 600; letter-spacing: -0.01em; }
.plot .val.is-up { fill: var(--up); }
.plot .val.is-down { fill: var(--down); }
.plot .val.is-total { fill: var(--total-hi); }
.plot .val { background: none; box-shadow: none; }

.plot .ruler { stroke: rgba(255, 255, 255, 0.5); stroke-width: 1; stroke-dasharray: 3 3; }
.plot .rtag rect { fill: #f2f3f7; }
.plot .rtag text { fill: #0b0c10; font-size: 9.5px; font-weight: 650; }

/* the pool of light on the floor under the step being read */
.glow {
  position: absolute;
  left: 0;
  bottom: -12px;
  width: 130px;
  height: 44px;
  margin-left: -65px;
  border-radius: 50%;
  background: radial-gradient(closest-side, var(--glow, rgba(143, 148, 255, 0.3)), transparent);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s;
}

.glow.is-on { opacity: 1; }

/* ---- the glass label ---- */
.tip {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  pointer-events: none;
  will-change: transform;
}

.tip__glass {
  min-width: 128px;
  padding: 9px 11px 9px;
  border-radius: 13px;
  background: linear-gradient(180deg, rgba(40, 42, 54, 0.78), rgba(24, 25, 33, 0.7));
  -webkit-backdrop-filter: blur(14px) saturate(1.6);
  backdrop-filter: blur(14px) saturate(1.6);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.09),
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    0 12px 28px -8px rgba(0, 0, 0, 0.7);
  opacity: 0;
  transform-origin: 50% 100%;
}

.tip__name { font-size: 10.5px; color: var(--muted); white-space: nowrap; }

.tip__num {
  margin-top: 2px;
  font-size: 17px;
  font-weight: 640;
  font-variation-settings: 'wdth' 96;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.tip__num.is-up { color: var(--up); }
.tip__num.is-down { color: var(--down); }
.tip__num.is-up, .tip__num.is-down { background: none; box-shadow: none; }

.tip__sub { margin-top: 1px; font-size: 10.5px; color: var(--muted); white-space: nowrap; }

.tip__vs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 7px;
  padding-top: 7px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
}

.tip__pill {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-weight: 640;
  padding: 1px 6px 1px 4px;
  border-radius: 999px;
}

.tip__pill i { font-style: normal; }
.tip__pill svg { width: 10px; height: 10px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---- the steps ---- */
.axis {
  position: relative;
  height: 24px;
}

.axis span {
  position: absolute;
  top: 8px;
  font-size: 10.5px;
  line-height: 1;
  color: var(--muted);
  white-space: nowrap;
  transform: translateX(-50%);
  font-variation-settings: 'wdth' 100;
  transition: color 0.3s, font-weight 0.3s, font-variation-settings 0.35s cubic-bezier(0.3, 1.4, 0.5, 1);
}

.axis span.is-on { color: var(--ink); font-weight: 640; font-variation-settings: 'wdth' 112; }
.axis span.is-path { color: #c4c6d2; }

.chart:focus-visible {
  outline: 2px solid var(--total);
  outline-offset: 3px;
}

/* ---- the drawn pointer of the preview ---- */
.pointer {
  position: absolute;
  left: 0;
  top: 0;
  width: 22px;
  height: 22px;
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.pointer path { fill: #ffffff; stroke: #0b0c10; stroke-width: 1.3; stroke-linejoin: round; }

@media (max-width: 420px) {
  .card__sub { font-size: 10.5px; }
  .net { font-size: 10.5px; padding-right: 7px; }
  .net__word { display: none; }
  .axis span { font-size: 9.5px; }
}

@media (prefers-reduced-motion: reduce) {
  .axis span { transition: color 0.3s; }
}
