/* The split case study with the border that follows the cursor: the case study card of an invented branding studio,
   split into Story (a real photo of tea leaves) and Proof (the numbers). One CSS variable, --split, written by the
   script every frame, moves the border: the columns go from 50/50 to 60/40 either way, the photo breathes, the big
   name grows and stretches with the wdth axis of Mona Sans, the chip of the bigger half fills with colour. */
:root {
  --page: #e7e4dc;          /* the page */
  --paper: #f8f6f1;         /* the Proof half */
  --ink: #15170f;           /* the words */
  --muted: #6c6e62;         /* the small words */
  --accent: #3d6b2c;        /* tea green: chips, bars, the knob's light */
  --line: rgba(21, 23, 15, 0.1); /* hairlines on the paper */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

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

body {
  min-height: 100svh;
  background: radial-gradient(120% 80% at 50% 0%, #f1efe9 0%, var(--page) 60%);
  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: 14px;
  overflow: hidden;
}

/* ---------------------------------------------------------------- the card */
.case {
  --split: 0;
  --cw: 640px;              /* the card's width and height in pixels, written by the script on resize */
  --ch: 420px;
  --story-on: clamp(0, var(--split) * 7 - 0.15, 1);
  --proof-on: clamp(0, var(--split) * -7 - 0.15, 1);
  position: relative;
  width: min(660px, 92vw);
  height: min(430px, 74vh);
  border-radius: 22px;
  overflow: hidden;
  background: var(--paper);
  box-shadow:
    0 0 0 1px rgba(21, 23, 15, 0.07),
    0 1px 2px rgba(21, 23, 15, 0.05),
    0 10px 22px -10px rgba(21, 23, 15, 0.14),
    0 44px 80px -36px rgba(32, 44, 20, 0.34);
  touch-action: pan-y;
  opacity: 0;
}

/* the top edge catches the light */
.case::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55), inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  pointer-events: none;
  z-index: 4;
}

.case__split {
  display: grid;
  grid-template-columns: calc(50% + var(--split) * 50%) minmax(0, 1fr);
  height: 100%;
}

.case__grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  opacity: 0.07;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

.half {
  position: relative;
  min-width: 0;
  height: 100%;
}

/* ---------------------------------------------------------------- Story: the photo */
.half--story {
  container: story / inline-size;
  overflow: hidden;
  background: #233a1c;
  color: #fff;
}

.story__photo {
  position: absolute;
  inset: 0;
}

/* wider than the column at its widest, so the border reveals the photo instead of squashing it */
.story__img {
  position: absolute;
  top: 0;
  left: 50%;
  width: calc(var(--cw) * 0.64);
  height: 100%;
  object-fit: cover;
  object-position: 50% 60%;
  transform: translateX(-50%) scale(calc(1.07 + var(--split) * 0.2));
  transform-origin: 50% 60%;
}

.story__veil {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(12, 20, 8, 0.28) 0%, rgba(12, 20, 8, 0) 26%, rgba(12, 20, 8, 0) 46%, rgba(10, 16, 6, 0.72) 100%);
}

.chip {
  position: absolute;
  top: clamp(12px, calc(var(--ch) * 0.05), 22px);
  left: clamp(12px, calc(var(--cw) * 0.04), 26px);
  z-index: 2;
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 10px;
  border-radius: 999px;
  overflow: hidden;
  font-size: 11px;
  font-weight: 560;
  font-variation-settings: 'wdth' 104;
  letter-spacing: 0.01em;
}

.chip__fill {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--accent);
}

.chip__text {
  position: relative;
}

.chip--story {
  color: #fff;
  background: rgba(14, 22, 10, 0.26);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28), 0 4px 12px -6px rgba(0, 0, 0, 0.4);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.chip--story .chip__fill {
  opacity: var(--story-on);
}

.story__copy {
  position: absolute;
  left: clamp(12px, calc(var(--cw) * 0.04), 26px);
  right: clamp(12px, calc(var(--cw) * 0.04), 26px);
  bottom: clamp(12px, calc(var(--ch) * 0.055), 24px);
  z-index: 2;
}

.story__quote {
  margin: 0;
  max-width: 17em;
  font-size: clamp(13px, 7.4cqi, 22px);
  line-height: 1.12;
  font-weight: 580;
  font-variation-settings: 'wdth' calc(100 + var(--split) * 60);
  letter-spacing: -0.015em;
  text-wrap: balance;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.25);
}

.story__meta {
  margin: 8px 0 0;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.72);
  white-space: nowrap;
  transition: opacity 0.35s ease;
}

@container story (max-width: 190px) {
  .story__meta {
    opacity: 0;
  }
}

/* ---------------------------------------------------------------- Proof: the numbers */
.half--proof {
  container: proof / inline-size;
  display: flex;
  flex-direction: column;
  padding: clamp(12px, calc(var(--ch) * 0.05), 22px) clamp(12px, calc(var(--cw) * 0.045), 28px) clamp(12px, calc(var(--ch) * 0.055), 24px);
  background:
    radial-gradient(90% 60% at 100% 0%, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0) 70%),
    var(--paper);
}

.proof__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 22px;
}

.chip--proof {
  position: relative;
  flex: none;
  top: auto;
  left: auto;
  color: color-mix(in srgb, #ffffff calc(var(--proof-on) * 100%), var(--ink));
  box-shadow: inset 0 0 0 1px var(--line);
}

.chip--proof .chip__fill {
  opacity: var(--proof-on);
}

.studio {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 520;
  color: var(--muted);
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
  transition: opacity 0.35s ease;
}

.studio__mark {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
}

@container proof (max-width: 250px) {
  .studio {
    opacity: 0;
  }
}

.proof__name {
  margin-top: auto;
}

.proof__over {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 520;
  color: var(--muted);
}

/* the formula of the original: (180 - split * 200), here as a share of a base size taken from the card */
.proof__title {
  --base: min(calc(var(--cw) * 0.096), calc(var(--ch) * 0.16));
  margin: 0;
  font-size: calc(var(--base) * (180 - var(--split) * var(--grow, 200)) / 180);
  line-height: 0.9;
  font-weight: 620;
  font-variation-settings: 'wdth' clamp(75, calc(100 - var(--split) * var(--stretch, 125)), 125);
  letter-spacing: -0.035em;
  white-space: nowrap;
}

.stats {
  margin: clamp(10px, calc(var(--ch) * 0.045), 22px) 0 0;
  display: grid;
  gap: clamp(7px, calc(var(--ch) * 0.024), 12px);
}

.stat {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  column-gap: 8px;
  row-gap: 5px;
}

.stat dt {
  grid-row: 1;
  font-size: clamp(10px, 6cqi, 12px);
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}

.stat dd {
  grid-row: 1;
  margin: 0;
  font-size: clamp(14px, 9cqi, 21px);
  line-height: 1;
  font-weight: 600;
  font-variation-settings: 'wdth' clamp(75, calc(100 - var(--split) * 90), 125);
  letter-spacing: -0.02em;
}

.stat__bar {
  grid-column: 1 / -1;
  position: relative;
  height: 2px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}

.stat__bar i {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--accent);
  transform-origin: 0 50%;
}

@container proof (max-width: 170px) {
  .stat {
    grid-template-columns: minmax(0, 1fr);
  }
  .stat dd {
    grid-row: 1;
  }
  .stat dt {
    grid-row: 2;
  }
}

@media (max-height: 520px) {
  .stat--extra {
    display: none;
  }
}

/* ---------------------------------------------------------------- the button */
.open {
  margin-top: clamp(10px, calc(var(--ch) * 0.045), 20px);
  width: 100%;
  height: clamp(30px, calc(var(--ch) * 0.088), 38px);
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.open__face {
  position: relative;
  display: grid;
  place-items: center;
  height: 100%;
  border-radius: 999px;
  overflow: hidden;
  background: linear-gradient(180deg, #2a2d22 0%, var(--ink) 100%);
  color: var(--paper);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), 0 1px 2px rgba(21, 23, 15, 0.25), 0 8px 16px -8px rgba(21, 23, 15, 0.5);
}

.open__shine {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 40%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.22), transparent);
  transform: translateX(-120%);
}

.open__row {
  grid-area: 1 / 1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: clamp(10.5px, 7cqi, 13px);
  font-weight: 560;
  white-space: nowrap;
}

.open__row[data-row='done'] {
  opacity: 0;
}

.open__arrow,
.open__tick {
  width: 13px;
  height: 13px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.open__tick {
  color: #b9d99a;
  stroke-dasharray: 1;
}

/* ---------------------------------------------------------------- the border */
.border {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(50% + var(--split) * 50%);
  width: 0;
  z-index: 5;
  pointer-events: none;
}

.border__line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -0.5px;
  width: 1px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.85) 50%, rgba(255, 255, 255, 0.2));
  box-shadow: 1px 0 0 rgba(21, 23, 15, 0.06);
}

.border__knob {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
}

/* a brighter stretch of the hairline that travels with the knob */
.border__glint {
  position: absolute;
  left: -1px;
  top: -80px;
  width: 2px;
  height: 160px;
  border-radius: 2px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), #ffffff 50%, rgba(255, 255, 255, 0));
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.45);
}

.border__handle {
  position: absolute;
  left: -16px;
  top: -16px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(250, 249, 245, 0.78);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    inset 0 0 0 1px rgba(255, 255, 255, 0.6),
    0 0 0 1px rgba(21, 23, 15, 0.06),
    0 2px 4px rgba(21, 23, 15, 0.1),
    0 10px 20px -8px rgba(21, 23, 15, 0.35);
}

.border__handle svg {
  width: 20px;
  height: 10px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.border__readout {
  position: absolute;
  left: -60px;
  bottom: 24px;
  width: 120px;
  display: flex;
  justify-content: center;
  opacity: 0;
  transform-origin: 50% 100%;
}

.border__pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(21, 23, 15, 0.82);
  color: #f3f1ea;
  font-size: 10.5px;
  font-weight: 560;
  white-space: nowrap;
  box-shadow: 0 6px 14px -6px rgba(0, 0, 0, 0.45);
}

.border__readout b {
  display: inline-block;
  min-width: 2.1ch;
  text-align: center;
  font-weight: inherit;
}

.border__readout i {
  width: 1px;
  height: 9px;
  background: rgba(255, 255, 255, 0.35);
}

/* ---------------------------------------------------------------- the drawn pointer */
.pointer {
  position: absolute;
  left: 0;
  top: 0;
  width: 20px;
  height: 20px;
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  fill: var(--ink);
  stroke: #fff;
  stroke-width: 1.3;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.25));
}

@media (prefers-reduced-motion: reduce) {
  .story__img {
    transform: translateX(-50%) scale(1.07);
  }
}
