/* The Sankey chart of the money flow between accounts: the card of a banking app on a near black page with two soft lights and a
   fine grain. The card is moved only by GSAP; its body, edge and pointer light are CSS. The diagram is an SVG laid
   out in pixels by script.js (re-measured on resize); the tooltip is HTML over it. */
:root {
  --page: #08080a;            /* the page */
  --card: #111114;            /* the body of the card */
  --edge: rgba(255, 255, 255, 0.075); /* the edge of the card */
  --ink: #eeedf3;             /* the words */
  --muted: #8b8a96;           /* the small words */
  --income: #49d6b0;          /* the money coming in */
  --save: #9b8cff;            /* savings and investing */
  --spend: #f0b469;           /* the money spent */
  --hub: #dcdbe6;             /* the checking account in the middle */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Mona Sans Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.stage {
  position: relative;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: hidden;
  isolation: isolate;
}

/* two soft lights on the page, the colours of the money in and the money saved */
.stage::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(40% 36% at 26% 22%, color-mix(in srgb, var(--income) 13%, transparent), transparent 70%),
    radial-gradient(42% 40% at 76% 82%, color-mix(in srgb, var(--save) 14%, transparent), transparent 72%);
}

/* the grain */
.stage::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  opacity: 0.05;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.6 0'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)'/%3E%3C/svg%3E");
}

.flow {
  --mx: 30%;
  --my: 0%;
  position: relative;
  width: min(100%, 440px);
  padding: clamp(14px, 3.6vh, 22px) clamp(14px, 4.4vw, 22px) clamp(12px, 3vh, 18px);
  border-radius: 22px;
  background: linear-gradient(180deg, #16161a, var(--card) 40%);
  box-shadow:
    inset 0 0 0 1px var(--edge),
    inset 0 1px 0 rgba(255, 255, 255, 0.07),
    0 1px 2px rgba(0, 0, 0, 0.6),
    0 18px 40px -18px rgba(0, 0, 0, 0.9),
    0 50px 90px -40px rgba(0, 0, 0, 0.8);
  opacity: 0;
}

/* the top edge catches the light in one pixel, brightest where the pointer is */
.flow::before {
  content: '';
  position: absolute;
  left: 18px;
  right: 18px;
  top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.28) var(--mx), transparent);
  pointer-events: none;
}

/* a soft light inside the card that follows the pointer */
.flow__light {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(260px 200px at var(--mx) var(--my), rgba(255, 255, 255, 0.045), transparent 70%);
}

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

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

.flow__mark {
  width: 26px;
  height: 26px;
  padding: 5px;
  border-radius: 8px;
  background: linear-gradient(160deg, #23232a, #17171b);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  fill: none;
  stroke: var(--income);
  stroke-width: 1.7;
  stroke-linecap: round;
  flex: none;
}

.flow__mark path + path {
  stroke: var(--save);
}

.flow__title {
  font-size: 14px;
  font-weight: 600;
  font-variation-settings: 'wdth' 106;
  letter-spacing: 0.005em;
  white-space: nowrap;
}

/* Sep and Oct: a pill slides under the chosen month */
.flow__seg {
  position: relative;
  display: flex;
  padding: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  flex: none;
}

.flow__seg-pill {
  position: absolute;
  left: 3px;
  top: 3px;
  bottom: 3px;
  width: 44px;
  border-radius: 999px;
  background: linear-gradient(180deg, #2c2c33, #222228);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 2px 6px -2px rgba(0, 0, 0, 0.8);
}

.flow__seg-btn {
  position: relative;
  width: 44px;
  height: 28px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 560;
  cursor: pointer;
  border-radius: 999px;
  transition: color 0.3s ease;
  -webkit-tap-highlight-color: transparent;
}

.flow__seg-btn.is-on {
  color: var(--ink);
}

.flow__seg-btn:focus-visible {
  outline: 2px solid var(--save);
  outline-offset: 1px;
}

@media (hover: hover) {
  .flow__seg-btn:hover {
    color: var(--ink);
  }
}

.flow__sum {
  position: relative;
  margin-top: clamp(10px, 2.6vh, 16px);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
}

.flow__total {
  margin: 0;
  font-size: clamp(28px, min(9vw, 8.4vh), 36px);
  line-height: 1;
  font-weight: 620;
  font-variation-settings: 'wdth' 94;
  letter-spacing: -0.025em;
}

.flow__meta {
  margin: 0 0 3px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
}

.flow__chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 8px 3px 5px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: var(--income);
  background: color-mix(in srgb, var(--income) 10%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--income) 22%, transparent);
}

.flow__chip svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

/* rolling figures: every digit is a column of 0 to 9 that slides */
.roll {
  display: inline-flex;
}

.roll__col {
  display: inline-block;
  height: 1em;
  line-height: 1;
  overflow: hidden;
  vertical-align: top;
}

.roll__strip {
  display: flex;
  flex-direction: column;
}

.roll__strip span,
.roll__char {
  display: block;
  height: 1em;
  line-height: 1;
}

.flow__chart {
  position: relative;
  height: clamp(140px, 46vh, 236px);
  margin-top: clamp(12px, 3vh, 20px);
}

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

.flow__svg text {
  font-family: inherit;
  font-size: 10.5px;
  fill: var(--muted);
}

.flow__svg .amt {
  font-size: 11px;
  font-weight: 600;
  fill: var(--ink);
}

.flow__svg [data-link] {
  cursor: pointer;
  outline: none;
}

.flow__svg [data-node] {
  cursor: pointer;
}

.flow__mark-on line {
  stroke: #ffffff;
  stroke-width: 1;
  stroke-linecap: round;
}

.flow__tip {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  display: grid;
  gap: 2px;
  padding: 8px 11px 9px;
  border-radius: 12px;
  background: rgba(24, 24, 29, 0.72);
  -webkit-backdrop-filter: blur(12px) saturate(1.3);
  backdrop-filter: blur(12px) saturate(1.3);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.09),
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 12px 28px -10px rgba(0, 0, 0, 0.9);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
}

.flow__tip-path {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10.5px;
  color: var(--muted);
}

.flow__tip-path svg {
  width: 11px;
  height: 11px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.flow__tip-value {
  font-size: 15px;
  font-weight: 640;
  font-variation-settings: 'wdth' 96;
  letter-spacing: -0.01em;
}

.flow__tip-share {
  font-size: 10.5px;
  color: var(--muted);
}

.flow__foot {
  position: relative;
  margin-top: clamp(12px, 3vh, 18px);
  padding-top: clamp(10px, 2.4vh, 14px);
  display: flex;
  align-items: center;
  gap: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 12px;
}

.flow__foot-name {
  color: var(--muted);
  white-space: nowrap;
}

.flow__track {
  position: relative;
  flex: 1;
  height: 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.flow__fill {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, color-mix(in srgb, var(--save) 50%, transparent), var(--save));
  box-shadow: 0 0 10px color-mix(in srgb, var(--save) 60%, transparent);
  transform-origin: 0 50%;
  transform: scaleX(0);
}

.flow__foot-value {
  display: inline-flex;
  align-items: flex-start;
  line-height: 1;
  font-weight: 600;
}

/* a smaller glass on narrow cards, so it never hides the diagram */
@media (max-width: 420px) {
  .flow__tip {
    padding: 6px 9px 7px;
    border-radius: 10px;
  }

  .flow__tip-path,
  .flow__tip-share {
    font-size: 9.5px;
  }

  .flow__tip-value {
    font-size: 13px;
  }
}
