/* =============================================================================
   One Million I Love Yous — viewer page
   One stylesheet for both render modes (site + artifact).

   Everything is styled through tokens. The full light palette is defined on a
   bare :root; dark is a *considered* palette (not an inversion) redefined twice:
   once for the system preference, once for an explicit data-theme="dark".
   ========================================================================== */

:root {
  color-scheme: light dark;

  /* ---- light (base) ---- */
  --bg:            #FBF7F8;
  --bg-sink:       #F5EDF0;  /* recessed strips: rails, progress track */
  --surface:       #FFFFFF;
  --ink:           #241B20;
  --muted:         #5E4F57;
  --line:          #E8DCE0;
  --line-strong:   #D8C6CD;
  --accent:        #D42A4E;  /* fills, bars, marks */
  --accent-text:   #B21F40;  /* accent used as small text (6.2:1 on --bg) */
  --accent-soft:   #FBE3E8;
  --accent-line:   #F1C8D2;
  --on-accent:     #FFFFFF;
  --focus:         #8C1533;
  --shade:         rgba(36, 27, 32, .06);

  /* ---- type ---- */
  --display: "Fraunces", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --body: "Source Sans 3", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* ---- metrics ---- */
  --pad: 20px;
  --rule: 1px solid var(--line);
  --radius: 4px;
  --radius-media: 14px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #191316;
    --bg-sink:     #221A1E;
    --surface:     #221A1E;
    --ink:         #F5ECEF;
    --muted:       #B9A6AE;
    --line:        #3A2E33;
    --line-strong: #4C3C43;
    --accent:      #FF6B87;
    --accent-text: #FF8CA1;
    --accent-soft: #3A2129;
    --accent-line: #5A3540;
    --on-accent:   #23090F;
    --focus:       #FFA8B9;
    --shade:       rgba(0, 0, 0, .35);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:          #191316;
  --bg-sink:     #221A1E;
  --surface:     #221A1E;
  --ink:         #F5ECEF;
  --muted:       #B9A6AE;
  --line:        #3A2E33;
  --line-strong: #4C3C43;
  --accent:      #FF6B87;
  --accent-text: #FF8CA1;
  --accent-soft: #3A2129;
  --accent-line: #5A3540;
  --on-accent:   #23090F;
  --focus:       #FFA8B9;
  --shade:       rgba(0, 0, 0, .35);
}

/* =============================== base ==================================== */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.15; }
p { margin: 0; }
ol, ul, dl, dd { margin: 0; padding: 0; list-style: none; }
img { display: block; max-width: 100%; }

a { color: inherit; text-decoration-color: var(--accent-line); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
  border-radius: 3px;
}

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

.boot {
  max-width: 34rem;
  margin: 18vh auto;
  padding: 0 var(--pad);
  color: var(--muted);
  font-size: 1.05rem;
  text-align: center;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 var(--pad) 64px;
}

/* Digits line up everywhere they can be compared. */
.count-num, .tally dd, .lb-love, .said-day, .tile-stats, .day-num, .pace b, .bar-pct {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ============================== masthead ================================= */

.masthead {
  display: grid;
  /* minmax(0, 1fr), never bare 1fr/auto: an auto track is sized to max-content, and
     the edge-bleeding rails below would then widen the whole page. */
  grid-template-columns: minmax(0, 1fr);
  gap: 34px;
  padding: 28px 0 30px;
  border-bottom: var(--rule);
}

/* ------------------------------- hero ----------------------------------- */

.hero { position: relative; min-width: 0; }

.eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .8125rem;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--accent-text);
}
.eyebrow a { text-decoration: none; color: inherit; border-bottom: 1px solid var(--accent-line); }
.eyebrow a:hover { border-bottom-color: var(--accent); }
.eyebrow .sep { color: var(--line-strong); }

/* The heart-hands mark: two halves with a seam, so it reads as two hands. */
.mark { display: block; width: 17px; height: 17px; color: var(--accent); flex: none; }

/* A big, very quiet heart bleeding off the hero on wide screens. */
.hero-watermark {
  position: absolute;
  right: -110px; top: -30px;
  width: 340px; height: 340px;
  color: var(--accent);
  opacity: .07;
  pointer-events: none;
  display: none;
}

.count {
  margin: 10px 0 0;
  font-family: var(--display);
  font-size: clamp(4.2rem, 21vw, 9.5rem);
  font-weight: 700;
  font-variation-settings: "opsz" 144, "SOFT" 100, "WONK" 1;
  line-height: .86;
  letter-spacing: -.025em;
  color: var(--ink);
  transition: color .4s ease, opacity .4s ease;
}
.count-num { display: inline-block; }

/* Stale rule: the number is dimmed, never hidden. */
.is-stale .count { opacity: .55; }

.count-of {
  margin-top: 6px;
  font-family: var(--display);
  font-size: 1.0625rem;
  font-variation-settings: "opsz" 20, "SOFT" 60, "WONK" 0;
  color: var(--muted);
  letter-spacing: .01em;
}

.bar {
  margin-top: 18px;
  height: 9px;
  background: var(--bg-sink);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  min-width: 3px;
  background: var(--accent);
  border-radius: 999px;
  transition: width .9s cubic-bezier(.2, .7, .3, 1);
}

.bar-note {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  margin-top: 9px;
  font-size: .9375rem;
  color: var(--muted);
}
.bar-pct { color: var(--accent-text); font-weight: 700; }
.fresh { margin-left: auto; font-size: .875rem; }
.is-stale .fresh { color: var(--accent-text); font-weight: 600; }

.health-note {
  margin-top: 8px;
  font-size: .875rem;
  color: var(--accent-text);
}

.tallies {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 28px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: var(--rule);
}
.tally dt {
  font-size: .8125rem;
  color: var(--muted);
  letter-spacing: .02em;
}
.tally dd {
  font-family: var(--display);
  font-variation-settings: "opsz" 30, "SOFT" 40, "WONK" 0;
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.1;
}

/* -------------------------------- day ----------------------------------- */

.day {
  min-width: 0;
  padding: 20px 20px 18px;
  background: var(--surface);
  border: var(--rule);
  border-radius: var(--radius);
}

.day-num {
  font-family: var(--display);
  font-variation-settings: "opsz" 48, "SOFT" 80, "WONK" 1;
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -.01em;
}
.day-num span { color: var(--muted); font-weight: 400; }

.day-left {
  margin-top: 2px;
  font-size: .9375rem;
  color: var(--accent-text);
  font-weight: 600;
}

.pace {
  margin-top: 12px;
  font-size: .9375rem;
  line-height: 1.45;
  color: var(--muted);
  text-wrap: pretty;
}
.pace b { color: var(--ink); font-weight: 700; }

/* ----------------------------- sparkline -------------------------------- */

.spark { margin: 16px 0 0; }
.spark svg { display: block; width: 100%; height: auto; overflow: visible; }
.spark-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark-area { fill: var(--accent); opacity: .11; stroke: none; }
.spark-base { stroke: var(--line); stroke-width: 1; }
.spark-dot { fill: var(--accent); }
.spark-halo { fill: var(--accent); opacity: .22; }

.spark-caption {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
  font-size: .75rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}
.spark-caption b { color: var(--ink); font-weight: 600; }

/* ============================== columns ================================== */

/* Phone: one column, straight down the DOM — videos, leaderboard, just said.
   Desktop: the leaderboard moves beside the other two. Same DOM, no duplication. */
.columns { display: grid; grid-template-columns: minmax(0, 1fr); gap: 40px; }

section.block { min-width: 0; padding-top: 32px; border-top: var(--rule); }
.vgroup { min-width: 0; }
.columns > section.block:first-child { padding-top: 30px; border-top: 0; }

.sec-head { margin-bottom: 18px; }
.sec-head h2 {
  font-family: var(--display);
  font-variation-settings: "opsz" 48, "SOFT" 70, "WONK" 1;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -.01em;
}
.sec-sub { margin-top: 3px; font-size: .9375rem; color: var(--muted); }

/* ============================== videos =================================== */

.vgroup + .vgroup { margin-top: 26px; }

.vlabel {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}
.vlabel::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

/* Phone: rows scroll inside themselves, bleeding to the page edge. */
.rail {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  margin: 0 calc(var(--pad) * -1);
  padding: 2px var(--pad) 10px;
}
.rail > * { scroll-snap-align: start; flex: 0 0 47%; max-width: 260px; }
.rail--today { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; }
.rail--today > * { flex: 0 0 calc(50% - 6px); max-width: none; }
.rail--today > .tile--featured { flex-basis: 100%; }

.tile {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tile-media {
  position: relative;
  display: block;
  aspect-ratio: 9 / 16;
  border-radius: var(--radius-media);
  overflow: hidden;
  background: var(--bg-sink);
  border: 1px solid var(--line);
  padding: 0;
  width: 100%;
  color: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: transform .18s ease, border-color .18s ease;
}
.tile-media img { width: 100%; height: 100%; object-fit: cover; }
button.tile-media { font: inherit; -webkit-appearance: none; appearance: none; }
.tile-media:hover { border-color: var(--accent-line); transform: translateY(-2px); }
.tile-media:active { transform: translateY(0); }

.tile--featured .tile-media { aspect-ratio: 16 / 11; }

.tile-day {
  position: absolute;
  left: 8px; top: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: .6875rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.tile-cue {
  position: absolute;
  right: 8px; bottom: 8px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(20, 12, 15, .68);
  color: #fff;
  font-size: .6875rem;
  font-weight: 600;
  letter-spacing: .02em;
  backdrop-filter: blur(3px);
}

.tile-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  font-size: .8125rem;
  color: var(--muted);
}
.tile-love { color: var(--accent-text); font-weight: 700; }

.tile-out {
  font-size: .8125rem;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid var(--line);
  align-self: flex-start;
}
.tile-out:hover { color: var(--accent-text); border-bottom-color: var(--accent); }

/* An opened embed takes over its slot and widens it. */
.rail > .tile.is-playing { flex: 0 0 min(92vw, 340px); max-width: none; }
.tile.is-playing .tile-media {
  aspect-ratio: auto;
  cursor: default;
  background: var(--bg-sink);
  padding: 0;
}
.tile.is-playing .tile-media:hover { transform: none; }
.tile-close {
  margin-top: 2px;
  align-self: flex-start;
  padding: 3px 9px;
  font: inherit;
  font-size: .75rem;
  color: var(--muted);
  background: var(--bg-sink);
  border: var(--rule);
  border-radius: 999px;
  cursor: pointer;
}
.tile-close:hover { color: var(--ink); border-color: var(--line-strong); }

/* ============================ leaderboard ================================ */

.find { position: relative; margin-bottom: 12px; }
.find input {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  font-size: .9375rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}
.find input::placeholder { color: var(--muted); opacity: 1; }
.find input:focus-visible { border-color: var(--accent); }

.board { border-top: var(--rule); }

.lb-row {
  display: grid;
  grid-template-columns: 2rem 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 9px 4px;
  border-bottom: var(--rule);
}
.lb-row.is-top { background: linear-gradient(90deg, var(--accent-soft), transparent 70%); }

.lb-rank {
  justify-self: start;
  min-width: 1.75rem;
  padding: 2px 0;
  font-family: var(--display);
  font-variation-settings: "opsz" 20, "SOFT" 40, "WONK" 0;
  font-size: 1rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--muted);
}
.lb-rank.is-1, .lb-rank.is-2, .lb-rank.is-3 {
  border-radius: 999px;
  color: var(--accent-text);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
}
.lb-rank.is-1 { color: var(--on-accent); background: var(--accent); border-color: var(--accent); }

.lb-av {
  width: 34px; height: 34px;
  border-radius: 999px;
  object-fit: cover;
  background: var(--bg-sink);
  border: 1px solid var(--line);
}

.lb-who { min-width: 0; }
.lb-user {
  display: inline-block;
  max-width: 100%;
  font-weight: 600;
  font-size: .9375rem;
  overflow-wrap: anywhere;
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.lb-user:hover { border-bottom-color: var(--accent); }
.lb-nick {
  display: block;              /* the nickname sits under the @, never beside it */
  font-size: .8125rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.lb-chip {
  display: inline-block;
  margin-left: 6px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  color: var(--accent-text);
  font-size: .6875rem;
  font-weight: 700;
  white-space: nowrap;
}

.lb-stat { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.lb-love {
  font-family: var(--display);
  font-variation-settings: "opsz" 24, "SOFT" 50, "WONK" 0;
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.15;
}
.lb-days { font-size: .75rem; color: var(--muted); white-space: nowrap; }

.board-empty {
  padding: 22px 4px;
  color: var(--muted);
  font-size: .9375rem;
}

/* ============================== just said ================================ */

.said-list { border-top: var(--rule); }

.said-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 12px;
  padding: 10px 4px;
  border-bottom: var(--rule);
}
.said-user {
  font-size: .8125rem;
  font-weight: 700;
  color: var(--accent-text);
  overflow-wrap: anywhere;
}
.said-day {
  grid-row: 1 / span 2;
  grid-column: 2;
  align-self: center;
  font-size: .75rem;
  color: var(--muted);
  white-space: nowrap;
}
.said-text {
  grid-column: 1;
  font-size: .9375rem;
  overflow-wrap: anywhere;
  text-wrap: pretty;
}

/* ================================ footer ================================= */

.foot {
  margin-top: 44px;
  padding-top: 26px;
  border-top: var(--rule);
  display: grid;
  gap: 14px;
  max-width: 46rem;
}
.foot p { font-size: .9375rem; color: var(--muted); text-wrap: pretty; }
.foot .foot-sign {
  font-family: var(--display);
  font-variation-settings: "opsz" 24, "SOFT" 90, "WONK" 1;
  font-size: 1.125rem;
  color: var(--ink);
}

/* ============================== motion =================================== */

@keyframes ily-rise {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: none; }
}
.said-row.is-new { animation: ily-rise .5s cubic-bezier(.2, .7, .3, 1) both; }

@keyframes ily-pulse {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.035); }
  100% { transform: scale(1); }
}
.count.is-bumping { animation: ily-pulse .7s ease-out; transform-origin: left center; }

/* ============================== desktop ================================== */

@media (min-width: 900px) {
  :root { --pad: 40px; }

  .masthead {
    grid-template-columns: minmax(0, 1.3fr) minmax(300px, .7fr);
    gap: 48px;
    align-items: end;
    padding: 44px 0 40px;
  }
  .hero-watermark { display: block; }

  .columns {
    grid-template-columns: minmax(0, 1fr) minmax(340px, 400px);
    grid-template-areas:
      "videos who"
      "said   who";
    gap: 44px 52px;
    align-items: start;
  }
  #videos { grid-area: videos; }
  #who    { grid-area: who; border-top: 0; padding-top: 30px; }
  #said   { grid-area: said; }

  .rail {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    overflow: visible;
    margin: 0;
    padding: 0;
  }
  .rail > * { max-width: none; }
  .rail--today { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rail--today > .tile--featured { grid-column: 1 / -1; }
  .tile--featured .tile-media { aspect-ratio: 16 / 9; }
  .rail > .tile.is-playing { grid-column: span 2; }

  .count { font-size: clamp(5.5rem, 8.4vw, 8.5rem); }
  .tallies { gap: 10px 40px; }
}

@media (min-width: 1120px) {
  .rail:not(.rail--today) { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ========================== reduced motion =============================== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
