/* The blood oxygen chart of a mountain run: one white card on a warm paper page. Under the SpO2 line sits the shape
   of the climb in warm grey; the line, its soft fill, the cursor and the pill above it are drawn in SVG and HTML and
   moved by the script. */
:root {
  --page: #f2f0eb;          /* the page */
  --card: #ffffff;          /* the card */
  --edge: rgba(24, 22, 18, 0.08); /* its 1px edge */
  --ink: #17171a;           /* the words */
  --muted: #8b8780;         /* the small words */
  --faint: rgba(24, 22, 18, 0.07); /* the grid lines */
  --accent: #2f5bff;        /* the oxygen line */
  --hill: #ebe7df;          /* the shape of the climb */
  --ridge: #d6d0c4;         /* its top edge */
}

* {
  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;
}

/* a fine paper grain over the page */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.35 0 0 0 0 0.32 0 0 0 0 0.28 0 0 0 0.09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

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

.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: min(16px, 3vh) 14px;
  overflow: hidden;
}

.card {
  position: relative;
  width: min(410px, 92vw);
  padding: clamp(14px, 3.4vh, 22px) clamp(14px, 4vw, 22px) clamp(12px, 3vh, 18px);
  border-radius: 22px;
  background: var(--card);
  box-shadow:
    0 0 0 1px var(--edge),
    0 1px 0 rgba(255, 255, 255, 0.9) inset,
    0 1px 2px rgba(24, 22, 18, 0.04),
    0 8px 18px -8px rgba(24, 22, 18, 0.1),
    0 34px 60px -28px rgba(24, 22, 18, 0.22);
  overflow: hidden;
  opacity: 0;
}

/* a soft light that follows the pointer along the card */
.card__shine {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  background: radial-gradient(260px circle at var(--sx, 70%) var(--sy, -10%), rgba(47, 91, 255, 0.06), transparent 70%);
}

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

.card__brand {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 560;
  font-stretch: 110%;
  letter-spacing: 0.01em;
  color: var(--muted);
}

.card__mark {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.card__name {
  margin: clamp(4px, 1.2vh, 8px) 0 2px;
  font-size: clamp(17px, 4.4vh, 21px);
  font-weight: 640;
  font-stretch: 104%;
  letter-spacing: -0.015em;
  line-height: 1.1;
}

.card__run {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.card__now {
  text-align: right;
}

.card__value {
  margin: 0;
  display: inline-flex;
  align-items: flex-start;
  font-size: clamp(32px, 9vh, 42px);
  font-weight: 600;
  font-stretch: 92%;
  letter-spacing: -0.035em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.card__pct {
  margin: 0.16em 0 0 0.04em;
  font-size: 0.46em;
  font-weight: 560;
  letter-spacing: 0;
  color: var(--muted);
}

/* the rolling digits: each column is a strip of 0-9 seen through a window one digit tall */
.odo {
  display: inline-flex;
  height: 1em;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(180deg, transparent, #000 18%, #000 82%, transparent);
  mask-image: linear-gradient(180deg, transparent, #000 18%, #000 82%, transparent);
}

.odo__col {
  display: block;
  width: 0.6em;
  text-align: center;
}

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

.odo__strip span {
  display: block;
  height: 1em;
  line-height: 1;
}

.card__label {
  margin: 6px 0 0;
  font-size: 11.5px;
  font-weight: 540;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.card__label sub {
  font-size: 0.75em;
  vertical-align: -0.15em;
}

.chart {
  position: relative;
  margin-top: clamp(8px, 2.6vh, 16px);
  height: clamp(110px, 30vh, 196px);
  touch-action: pan-y;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
}

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

.chart__grid {
  stroke: var(--faint);
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.chart__grid--mark {
  stroke: rgba(47, 91, 255, 0.28);
  stroke-dasharray: 2 3;
}

.chart__ylab {
  font-size: 10px;
  font-weight: 520;
  fill: var(--muted);
  font-variant-numeric: tabular-nums;
}

.chart__low {
  fill: url(#ox-hatch);
}

.chart__hill {
  fill: url(#ox-hill);
}

.chart__ridge {
  fill: none;
  stroke: var(--ridge);
  stroke-width: 1;
  stroke-dasharray: 1 3;
  stroke-linecap: round;
}

.chart__peak {
  font-size: 9.5px;
  font-weight: 560;
  font-stretch: 108%;
  fill: #a8a296;
  text-anchor: middle;
  opacity: 0;
}

.chart__fill {
  fill: url(#ox-fill);
}

.chart__line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 3px 4px rgba(47, 91, 255, 0.22));
}

.chart__min {
  opacity: 0;
}

.chart__min-ring {
  fill: var(--card);
  stroke: var(--accent);
  stroke-width: 1.5;
}

.chart__hair {
  stroke: rgba(23, 23, 26, 0.32);
  stroke-width: 1;
  stroke-dasharray: 2 3;
  opacity: 0;
}

.chart__dot {
  opacity: 0;
}

.chart__dot-halo {
  fill: rgba(47, 91, 255, 0.14);
}

.chart__dot-core {
  fill: var(--accent);
  stroke: #fff;
  stroke-width: 2;
  filter: drop-shadow(0 2px 3px rgba(23, 23, 40, 0.25));
}

/* the pill above the cursor */
.tip {
  position: absolute;
  left: 0;
  top: 0;
  opacity: 0;
  pointer-events: none;
  will-change: transform;
}

.tip__face {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 9px;
  border-radius: 999px;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 580;
  font-variant-numeric: tabular-nums;
  color: #fff;
  background: linear-gradient(180deg, #2b2b31, #17171a);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08) inset, 0 1px 0 rgba(255, 255, 255, 0.14) inset, 0 6px 14px -6px rgba(23, 23, 26, 0.5);
  transform: translate(-50%, -100%);
}

.tip__rule {
  width: 1px;
  height: 10px;
  background: rgba(255, 255, 255, 0.22);
}

/* the label of the lowest reading */
.lowest {
  position: absolute;
  left: 0;
  top: 0;
  opacity: 0;
  pointer-events: none;
}

.lowest__face {
  display: inline-block;
  transform: translate(-50%, 0);
  padding: 3px 8px;
  border-radius: 7px;
  white-space: nowrap;
  font-size: 10.5px;
  font-weight: 540;
  color: var(--accent);
  background: #eef2ff;
  box-shadow: 0 0 0 1px rgba(47, 91, 255, 0.16) inset;
}

.lowest__face b {
  font-weight: 680;
  font-variant-numeric: tabular-nums;
}

.axis {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -18px;
  height: 14px;
}

.axis span {
  position: absolute;
  top: 0;
  font-size: 10px;
  font-weight: 520;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  transform: translateX(-50%);
  white-space: nowrap;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: clamp(26px, 5.4vh, 34px);
  padding-top: clamp(8px, 2vh, 12px);
  border-top: 1px solid var(--faint);
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px;
  border-left: 1px solid var(--faint);
  transition: color 0.3s;
}

.stat:first-child {
  padding-left: 0;
  border-left: 0;
}

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

.stat__v {
  font-size: clamp(14px, 3.6vh, 16px);
  font-weight: 620;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.stat.is-on .stat__v {
  color: var(--accent);
}
