/* The weekly sales chart with last week to compare: the sales card of a made-up online store on a white page.
   The bars, the dashed outlines of last week, the changes on top and the glass label are placed in pixels by the
   script at every frame; here are their materials. */
:root {
  --page: #ffffff;          /* the page */
  --card: #ffffff;          /* the top of the card */
  --card-low: #f7f7fa;      /* the bottom of the card */
  --ink: #101118;           /* the words */
  --muted: #6b6d7a;         /* the small words */
  --faint: #a7a9b4;         /* the guides' figures */
  --line: rgba(16, 17, 24, 0.075); /* hairlines */
  --accent: #5457f2;        /* this week's bars */
  --accent-hi: #8486ff;     /* the light top of a bar */
  --accent-lo: #3b3ed6;     /* the foot of a bar */
  --then: rgba(16, 17, 24, 0.26); /* last week's dashed outline */
  --then-fill: #dcdee8;     /* last week's bar when compared */
  --up: #16835a;            /* a rise */
  --up-soft: rgba(22, 131, 90, 0.1);
  --down: #c25441;          /* a fall */
  --down-soft: rgba(194, 84, 65, 0.1);
}

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

html { touch-action: manipulation; }

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

body {
  background: 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, 560px);
  border-radius: 22px;
  padding: clamp(14px, 3.4vh, 26px) clamp(15px, 4.4vw, 28px) clamp(10px, 2.4vh, 18px);
  background: linear-gradient(180deg, var(--card) 0%, var(--card-low) 100%);
  box-shadow:
    inset 0 0 0 1px var(--line),
    inset 0 1px 0 rgba(255, 255, 255, 1),
    0 1px 1px rgba(16, 17, 24, 0.04),
    0 4px 10px -4px rgba(16, 17, 24, 0.06),
    0 24px 48px -20px rgba(40, 42, 90, 0.2);
  opacity: 0;
}

/* a soft light across the top, as if the card were lit from above */
.card__sheen {
  position: absolute;
  inset: 0 0 auto;
  height: 60%;
  border-radius: inherit;
  background: radial-gradient(120% 70% at 30% 0%, rgba(132, 134, 255, 0.07), 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: var(--ink); }
.card__mark path { fill: none; stroke: #ffffff; stroke-width: 1.7; stroke-linecap: 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;
}

/* ---- the Compare switch ---- */
.cmp {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: inherit;
  font-size: 12px;
  font-weight: 520;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.9);
  border: 0;
  border-radius: 999px;
  padding: 5px 5px 5px 11px;
  box-shadow: inset 0 0 0 1px var(--line), 0 1px 2px rgba(16, 17, 24, 0.05);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.25s, box-shadow 0.25s;
}

.cmp__label { font-variation-settings: 'wdth' 100; transition: font-variation-settings 0.35s cubic-bezier(0.3, 1.4, 0.5, 1); }

.cmp__track {
  position: relative;
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: #e6e7ee;
  box-shadow: inset 0 1px 2px rgba(16, 17, 24, 0.14);
  transition: background-color 0.3s;
}

.cmp__knob {
  position: absolute;
  left: 2px;
  top: 2px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffffff, #f1f1f5);
  box-shadow: 0 1px 2px rgba(16, 17, 24, 0.22), 0 3px 6px -2px rgba(16, 17, 24, 0.2), inset 0 0 0 0.5px rgba(16, 17, 24, 0.06);
}

.cmp[aria-checked='true'] { color: var(--ink); }
.cmp[aria-checked='true'] .cmp__track { background: var(--accent); box-shadow: inset 0 1px 2px rgba(20, 20, 90, 0.35); }

@media (hover: hover) {
  .cmp:hover { color: var(--ink); box-shadow: inset 0 0 0 1px rgba(16, 17, 24, 0.12), 0 2px 6px -2px rgba(16, 17, 24, 0.12); }
  .cmp:hover .cmp__label { font-variation-settings: 'wdth' 110; }
}

.cmp.is-hover { color: var(--ink); }
.cmp.is-hover .cmp__label { font-variation-settings: 'wdth' 110; }

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

/* ---- the total ---- */
.total {
  position: relative;
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: clamp(10px, 2.6vh, 20px);
}

.total__num {
  display: flex;
  font-size: clamp(30px, min(9vw, 9vh), 44px);
  line-height: 1;
  font-weight: 600;
  font-variation-settings: 'wdth' 96;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
}

.roll { display: inline-block; height: 1em; overflow: hidden; }
.roll__col { display: flex; flex-direction: column; }
.roll__col span { height: 1em; line-height: 1; }
.roll__sign { display: inline-block; line-height: 1; }

.total__side { display: flex; align-items: center; gap: 8px; padding-bottom: 3px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 3px 7px 3px 5px;
  border-radius: 999px;
}

.pill svg { width: 11px; height: 11px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.is-up { color: var(--up); background: var(--up-soft); }
.is-down { color: var(--down); background: var(--down-soft); }
.is-down svg { transform: scaleY(-1); }

.total__vs { font-size: 11.5px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---- the key ---- */
.legend {
  display: flex;
  gap: 14px;
  margin-top: clamp(8px, 2vh, 14px);
  font-size: 11px;
  color: var(--muted);
}

.legend__item { display: inline-flex; align-items: center; gap: 6px; }
.legend__now, .legend__then { width: 10px; height: 10px; border-radius: 3px; }
.legend__now { background: linear-gradient(180deg, var(--accent-hi), var(--accent)); }
.legend__then { border: 1.2px dashed var(--then); transition: background-color 0.4s; }
.is-cmp .legend__then { background: var(--then-fill); }

/* ---- the chart ---- */
.chart {
  position: relative;
  height: clamp(112px, 34vh, 232px);
  margin-top: clamp(6px, 1.6vh, 12px);
  border-radius: 10px;
  touch-action: pan-y;
  cursor: crosshair;
}

.grid { position: absolute; inset: 0; pointer-events: none; }

.grid__line {
  position: absolute;
  left: 30px;
  right: 0;
  height: 1px;
  background: repeating-linear-gradient(90deg, var(--line) 0 3px, transparent 3px 6px);
}

.grid__line.is-base { background: rgba(16, 17, 24, 0.12); }

.grid__label {
  position: absolute;
  left: 0;
  font-size: 10px;
  line-height: 1;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  transform: translateY(-50%);
}

/* the pool of light on the floor under the day being read */
.glow {
  position: absolute;
  left: 0;
  bottom: -10px;
  width: 120px;
  height: 40px;
  margin-left: -60px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(84, 87, 242, 0.26), transparent);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s;
}

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

.bars { position: absolute; inset: 0; pointer-events: none; }

.bar, .then, .delta { position: absolute; left: 0; bottom: 0; will-change: transform; }

/* this week: a glossy bar, light at the top, deep at the foot */
.bar {
  border-radius: 7px 7px 3px 3px;
  background: linear-gradient(180deg, var(--accent-hi) 0%, var(--accent) 48%, var(--accent-lo) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), inset 1px 0 0 rgba(255, 255, 255, 0.14), 0 6px 14px -8px rgba(59, 62, 214, 0.6);
  overflow: hidden;
  transition: box-shadow 0.35s, filter 0.35s;
}

.bar__gloss {
  position: absolute;
  inset: 0 auto 0 0;
  width: 42%;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.26), rgba(255, 255, 255, 0));
}

.bar__sweep {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 60%;
  background: linear-gradient(0deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.42) 50%, rgba(255, 255, 255, 0));
  opacity: 0;
}

.bar.is-on {
  filter: saturate(1.12) brightness(1.05);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), inset 1px 0 0 rgba(255, 255, 255, 0.2), 0 0 0 3px rgba(84, 87, 242, 0.14), 0 14px 26px -10px rgba(59, 62, 214, 0.75);
}

/* last week: a dashed outline open at the foot that fills when compared */
.then {
  border: 1.4px dashed var(--then);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
}

.then__fill {
  position: absolute;
  inset: -1.4px -1.4px 0;
  border-radius: 7px 7px 3px 3px;
  background:
    repeating-linear-gradient(135deg, rgba(16, 17, 24, 0.085) 0 1.5px, transparent 1.5px 4.5px),
    linear-gradient(180deg, #eceef4, var(--then-fill));
  box-shadow: inset 0 0 0 1px rgba(16, 17, 24, 0.07), inset 0 1px 0 rgba(255, 255, 255, 0.9);
  opacity: 0;
}

.then.is-on { border-color: rgba(16, 17, 24, 0.45); }

/* the change on top of a pair */
.delta { z-index: 2; }

.delta__in {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 640;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  padding: 2px 5px;
  border-radius: 999px;
  white-space: nowrap;
  opacity: 0;
  box-shadow: inset 0 0 0 1px currentColor;
}

.is-compact .delta__in { font-size: 9px; padding: 1px 4px; letter-spacing: -0.02em; }

.delta__in.is-up { box-shadow: inset 0 0 0 1px rgba(22, 131, 90, 0.18); }
.delta__in.is-down { box-shadow: inset 0 0 0 1px rgba(194, 84, 65, 0.18); }

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

.tip__glass {
  min-width: 108px;
  padding: 8px 10px 8px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.56));
  -webkit-backdrop-filter: blur(12px) saturate(1.7);
  backdrop-filter: blur(12px) saturate(1.7);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.9),
    inset 0 1px 0 rgba(255, 255, 255, 1),
    0 0 0 1px rgba(16, 17, 24, 0.06),
    0 10px 24px -8px rgba(30, 32, 80, 0.28);
  opacity: 0;
  transform-origin: 50% 100%;
}

.tip__day { 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;
  font-variant-numeric: tabular-nums;
}

.tip__delta {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-top: 3px;
  font-size: 10.5px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.tip__delta svg { width: 10px; height: 10px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tip__delta b { font-weight: 640; }
.tip__delta span { margin-left: 3px; color: var(--muted); }
.tip__delta.is-up, .tip__delta.is-down { background: none; }

/* ---- the days ---- */
.axis {
  position: relative;
  height: 22px;
  margin-left: 30px;
}

.axis span {
  position: absolute;
  top: 7px;
  font-size: 10.5px;
  line-height: 1;
  color: var(--muted);
  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; }

/* ---- 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 3px rgba(16, 17, 24, 0.28));
}

.pointer path { fill: var(--ink); stroke: #ffffff; stroke-width: 1.4; stroke-linejoin: round; }

@media (max-width: 420px) {
  .card__sub { font-size: 10.5px; }
  .cmp { padding-left: 9px; gap: 6px; }
  .legend { gap: 10px; }
}

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