:root {
  --bg: #f6f7fb;
  --bg-glow: #fdeed3;
  --panel: #ffffff;
  --line: rgba(15, 23, 42, 0.09);
  --track: #e8ecf4;
  --text: #1a2233;
  --muted: #5c6675;
  --accent: #f59e0b;
  --accent-deep: #e07f0e;
  --accent-text: #9c4309;   /* 6.1:1 on --bg, so it still passes AA composited over the overlay scrim */
  --accent-soft: rgba(245, 158, 11, 0.14);
  --btn-text: #241a02;
  --shadow: rgba(15, 23, 42, 0.05);
  --scrim: rgba(246, 247, 251, 0.94);
  --btn-size: clamp(120px, 18vh, 170px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420;
    --bg-glow: #2a2011;
    --panel: #171d2b;
    --line: rgba(226, 232, 240, 0.12);
    --track: #232b3d;
    --text: #eef1f7;
    --muted: #9aa5b8;
    --accent: #f6b53c;
    --accent-deep: #e08a12;
    --accent-text: #fbbf24;
    --accent-soft: rgba(246, 181, 60, 0.16);
    --btn-text: #23190a;
    --shadow: rgba(0, 0, 0, 0.4);
    --scrim: rgba(15, 20, 32, 0.95);
  }
}

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

html { -webkit-text-size-adjust: 100%; color-scheme: light dark; }

body {
  background: radial-gradient(1100px 500px at 50% -10%, var(--bg-glow) 0%, var(--bg) 62%) fixed var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  text-align: center;
  min-height: 100vh;
  min-height: 100dvh;
}

main {
  max-width: 1020px;
  margin: 0 auto;
  padding: clamp(0.8rem, 2vh, 2rem) 1rem clamp(0.8rem, 2vh, 1.5rem);
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
}

.mono { font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

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

.noscript { text-align: center; padding: 2rem; }

.label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.28em;
  color: var(--muted);
}
.accent { color: var(--accent-text); }

:focus-visible { outline: 3px solid var(--accent-text); outline-offset: 3px; }

/* global counter */
.global { margin-bottom: clamp(0.8rem, 2.5vh, 2rem); }
/* The counter is the one element whose content grows without bound — thirteen
   digits at a height-derived size overflows a phone. --fit is measured in
   script whenever the digit count changes, so the number always fits. */
.giant {
  font-size: calc(clamp(2.2rem, 7vh, 4.5rem) * var(--fit, 1));
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1.08;
  white-space: nowrap;
}
.global .label { margin-top: 0.25rem; }

/* challenge */
.challenge {
  max-width: 640px;
  margin: 0 auto;
  padding: clamp(0.9rem, 2vh, 1.6rem) clamp(1rem, 3vw, 1.8rem);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 8px 30px var(--shadow);
}
.challenge h2 {
  font-size: clamp(1.3rem, 3.4vh, 2rem);
  font-weight: 800;
  margin: 0.4rem 0 0.15rem;
  text-wrap: balance;
}
.blurb { color: var(--muted); font-size: 0.92rem; }

.bar {
  height: 13px;
  margin: clamp(0.6rem, 1.6vh, 1.1rem) 0 0.5rem;
  background: var(--track);
  border-radius: 999px;
  overflow: hidden;
}
/* the width is eased in script, so no CSS transition to fight it */
#bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-deep));
  box-shadow: 0 0 14px rgba(245, 158, 11, 0.45);
  position: relative;
}
#bar-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 30%, rgba(255,255,255,0.45) 50%, transparent 70%);
  background-size: 220% 100%;
  animation: sheen 2.6s linear infinite;
}
@keyframes sheen {
  from { background-position: 200% 0; }
  to { background-position: -20% 0; }
}

.progress-row {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  font-size: clamp(0.88rem, 2.4vw, 1rem);
}
.remaining {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 0.25rem;
  min-height: 1.2em;
}

/* button */
.button-zone {
  position: relative;
  margin: clamp(0.9rem, 2.4vh, 2rem) auto clamp(0.5rem, 1.2vh, 1rem);
  width: calc(var(--btn-size) + 10px);
  height: calc(var(--btn-size) + 10px);
}
#click-btn {
  width: var(--btn-size);
  height: var(--btn-size);
  margin: 5px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font: inherit;
  font-size: clamp(1.05rem, 2.2vh, 1.3rem);
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--btn-text);
  background: radial-gradient(circle at 32% 28%, #ffe08a, var(--accent) 45%, var(--accent-deep) 100%);
  box-shadow: 0 10px 30px rgba(224, 127, 14, 0.35), inset 0 -6px 16px rgba(120, 60, 0, 0.28), inset 0 4px 10px rgba(255,255,255,0.5);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.06s ease;
}
#click-btn:active { transform: scale(0.94); }
#click-btn:focus-visible { outline: 3px solid var(--text); outline-offset: 4px; }

#particles { position: absolute; inset: -40px; pointer-events: none; overflow: visible; }
.pop {
  position: absolute;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--accent-text);
  animation: pop 0.8s ease-out forwards;
  will-change: transform, opacity;
}
@keyframes pop {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(-70px) scale(1.25); }
}

/* separators are spacing rather than glyphs, so a wrapped row never leaves a
   dangling dot at the end of a line */
.live-stats {
  color: var(--muted);
  font-size: 0.9rem;
  display: flex;
  gap: 0.3rem 1.35rem;
  justify-content: center;
  flex-wrap: wrap;
}
.live-stats b { color: var(--text); font-weight: 700; }

.status {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--accent-text);
  min-height: 1.1em;
}
.status[hidden] { display: none; }

/* below the fold */
.below {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-top: clamp(1rem, 3vh, 2.5rem);
  text-align: left;
}
@media (max-width: 820px) { .below { grid-template-columns: 1fr; } }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: clamp(0.8rem, 1.6vh, 1.1rem) 1.1rem;
  box-shadow: 0 4px 18px var(--shadow);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.4rem 0.5rem;
  margin-bottom: 0.6rem;
}
.card h2 { font-size: 0.98rem; font-weight: 700; letter-spacing: 0.02em; }
.pill {
  background: var(--accent-soft);
  color: var(--accent-text);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-size: 0.78rem;
  font-weight: 700;
}
.note { color: var(--muted); font-size: 0.72rem; margin-top: 0.7rem; }

.toggle { display: flex; gap: 0.3rem; }
.toggle button {
  font: inherit;
  font-size: 0.7rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.14rem 0.55rem;
  cursor: pointer;
  white-space: nowrap;
}
.toggle button.on {
  color: var(--accent-text);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.rows { list-style: none; display: flex; flex-direction: column; gap: 0.3rem; }
.rows li {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  font-size: 0.87rem;
  padding: 0.2rem 0;
  border-bottom: 1px solid var(--line);
}
.rows li:last-child { border-bottom: none; }
.rows .rank { color: var(--muted); font-size: 0.72rem; width: 1.2rem; }
.rows .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .val { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.82rem; }
.rows .meta { color: var(--muted); font-size: 0.72rem; }
.empty { color: var(--muted); font-size: 0.85rem; padding: 0.5rem 0; }

.you { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(0.5rem, 1.4vh, 1rem) 0.5rem; }
.you > div, .ov-stats > div { display: flex; flex-direction: column; }
.big { font-size: clamp(1.1rem, 2.4vh, 1.35rem); font-weight: 800; }
.sub { color: var(--muted); font-size: 0.73rem; margin-top: 0.1rem; }

/* overlay */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--scrim);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  overflow-y: auto;
}
#overlay[hidden] { display: none; }
.overlay-inner {
  max-width: 460px;
  animation: rise 0.5s ease;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: none; }
}
 /* pinned to the overlay corner, not the card, so it never crowds the copy */
.ov-close {
  position: fixed;
  top: max(0.9rem, env(safe-area-inset-top));
  right: max(0.9rem, env(safe-area-inset-right));
  width: 2.4rem;
  height: 2.4rem;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}
.ov-emoji { font-size: 4.5rem; margin: 1rem 0 0.4rem; }
.overlay-inner h2 { font-size: 2rem; font-weight: 800; margin-bottom: 0.4rem; text-wrap: balance; }
.ov-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.1rem 0.6rem;
  margin: 1.6rem 0;
}
.ov-next { color: var(--muted); font-size: 0.85rem; }

@media (prefers-reduced-motion: reduce) {
  .pop, #bar-fill::after, .overlay-inner { animation: none; }
  .pop { opacity: 0; }
  #click-btn { transition: none; }
}
