/* Gravity — a full-screen generative piece. Just the background + a title that pops in and fades. */
:root { --bg: #0f1729; color-scheme: dark; }   /* declared dark → no forced-dark inversion of the white UI */
* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background: transparent;
  overflow: hidden;
  cursor: default;
  touch-action: none;              /* two fingers is a control → no pinch-zoom / pan */
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

/* the title: big, modern, high-contrast, NO glow — it must read cleanly over the animation.
   .milestone shares the exact same typography: a milestone must read as the title coming back. */
.intro, .milestone {
  position: fixed;
  inset: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 10;
  /* light, wide-tracked, uppercase — a calm gallery-style title (no external font, no glow) */
  font-family: system-ui, "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  font-weight: 200;
  text-transform: uppercase;
  letter-spacing: 0.42em;
  text-indent: 0.42em;            /* compensate the trailing tracking so it stays centred */
  font-size: clamp(1.6rem, 11vw, 9rem);
  line-height: 1;
  white-space: nowrap;
  color: rgba(234, 240, 252, 0.9);
  opacity: 0;                       /* stays hidden until the piece is started */
}
.intro.go { animation: intro 3.6s cubic-bezier(.2, .7, .2, 1) forwards; }

/* the piece is shared — say so, quietly, under the title. Fades in after the title has settled. */
.intro-sub {
  margin-top: 1.3em;
  font-size: clamp(0.72rem, 2.4vw, 1.15rem);
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  color: rgba(226, 236, 252, 0.92);
  text-shadow: 0 1px 20px rgba(10, 18, 40, 0.55);
  opacity: 0;
}
/* the goal of the whole piece, in the same green CALM wears everywhere else (milestone + frieze).
   It lives OUTSIDE the title so it can outlive it — and it peaks exactly as the title fades away. */
.intro-calm {
  position: fixed;
  left: 0; right: 0;
  top: 50%;
  transform: translateY(clamp(78px, 13vh, 190px));
  z-index: 11;
  pointer-events: none;
  text-align: center;
  font-family: system-ui, "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  font-weight: 200;
  text-transform: uppercase;
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  font-size: clamp(1.05rem, 3.6vw, 2.1rem);
  color: rgba(150, 235, 205, 0.92);
  opacity: 0;
}
/* 14s total. Percentages are chosen against that: the glow peaks at 26% = 3.64s, which is when the
   title's own fade ends — it lights up exactly as the title leaves. Then it HOLDS at full for ~5s
   before a 5.5s stepped dissolve, so it lingers well into the how-to rather than rushing off. */
.intro-calm.go { animation: calmIn 14s linear forwards; }
@keyframes calmIn {
  /* held invisible first, then eased in over ~1.4s — a linear fade from t=0 read as a hard appearance */
  0%   { opacity: 0; text-shadow: none; }
  5%   { opacity: 0; text-shadow: none; animation-timing-function: cubic-bezier(.4, 0, .5, 1); }
  15%  { opacity: 1; text-shadow: 0 0 22px rgba(90, 210, 170, 0.3); }
  20%  { opacity: 1; text-shadow: 0 0 26px rgba(110, 225, 185, 0.45); }
  26%  { opacity: 1; color: #eafff8;
         text-shadow: 0 0 12px rgba(255, 255, 255, 0.95), 0 0 44px rgba(120, 255, 215, 0.9),
                      0 0 95px rgba(90, 220, 180, 0.6); }
  40%  { opacity: 1; text-shadow: 0 0 26px rgba(110, 225, 185, 0.45); }
  62%  { opacity: 1; text-shadow: 0 0 22px rgba(90, 210, 170, 0.3); }
  74%  { opacity: .85; text-shadow: 0 0 20px rgba(90, 210, 170, 0.26); }
  86%  { opacity: .5;  text-shadow: 0 0 15px rgba(90, 210, 170, 0.18); }
  94%  { opacity: .2;  text-shadow: 0 0 9px rgba(90, 210, 170, 0.09); }
  100% { opacity: 0;   text-shadow: none; }
}
/* fades in and HOLDS — the title's own fade-out carries it off, so it isn't gone before it's read */
.intro.go .intro-sub { animation: subIn 1.4s ease .5s forwards; }
@keyframes subIn {
  0%   { opacity: 0; }
  100% { opacity: 1; }
}

/* The verdict. Only ever seen at |total| ≥ VERDICT_AT, where the world runs at ~15% and is visibly
   grinding to a halt. Slow, solemn fade — at that speed anything quick would feel out of place. */
.verdict {
  position: fixed;
  left: 0; right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 12;
  pointer-events: none;
  text-align: center;
  padding: 0 8vw;
  font-family: system-ui, "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  font-weight: 200;
  text-transform: uppercase;
  letter-spacing: 0.26em;
  text-indent: 0.26em;
  line-height: 1.9;
  font-size: clamp(0.85rem, 2.6vw, 1.6rem);
  opacity: 0;
  transition: opacity 3.2s ease;
  /* The swarm ERASES it. difference() against the backdrop means a bright particle crossing a bright
     letter cancels it to near-black, so the text is eaten wherever the field passes over and returns
     as it moves on. Nothing to compute per frame — the compositor does it. */
  mix-blend-mode: difference;
  isolation: auto;
}
.verdict.show { opacity: 1; }
/* no glow here: a text-shadow would be blended too and smear a halo across the letters */
.verdict.chaos { color: rgb(255, 150, 150); }
.verdict.calm  { color: rgb(165, 245, 215); }
@media (prefers-reduced-motion: reduce) { .verdict { transition: none; } }

/* frieze of unlocked words, pinned top-centre. Only the explored span is rendered (see drawFrieze),
   so it grows outward as the world pushes the records further in either direction. */
.frieze {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 0; right: 0;
  z-index: 9;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 0.35em 1.15em;
  padding: 0 4vw;
  pointer-events: none;
  font-family: system-ui, "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  font-weight: 200;
  text-transform: uppercase;
  letter-spacing: 0.28em;
  text-indent: 0.28em;
  font-size: clamp(0.44rem, 1.4vw, 0.68rem);
  opacity: 0;
  transition: opacity .8s ease;
}
.frieze.show { opacity: 1; }
.frieze-w { color: rgba(150, 170, 205, 0.22); }              /* still locked — a silhouette of what's ahead */
.frieze-w.on { color: rgba(190, 215, 255, 0.72); }           /* unlocked by someone, ever */
.frieze-w.dark.on { color: rgba(255, 130, 130, 0.62); }      /* the abyss side */
.frieze-w.zero.on { color: rgba(150, 235, 205, 0.85); }      /* CALM */
/* where the world stands RIGHT NOW — the last threshold crossed, lit against the rest */
/* three classes so this beats .frieze-w.dark.on / .frieze-w.zero.on, which are also three and would
   otherwise keep the current word red or green. It is ALWAYS bright white, whichever side it's on. */
.frieze-w.cur,
.frieze-w.on.cur,
.frieze-w.dark.on.cur,
.frieze-w.zero.on.cur {
  color: #fff;
  text-shadow:
    0 0 6px rgba(255, 255, 255, 0.95),
    0 0 16px rgba(225, 240, 255, 0.9),
    0 0 34px rgba(200, 225, 255, 0.65),
    0 0 70px rgba(180, 210, 255, 0.45);
  transition: color .6s ease, text-shadow .6s ease;
}

/* milestones sit a notch below the title's scale so they never feel like a second intro */
.milestone {
  font-size: clamp(1.3rem, 8vw, 6rem);
  font-variant-numeric: tabular-nums;
}
.milestone.go { animation: intro 3.2s cubic-bezier(.2, .7, .2, 1) forwards; }
.milestone.calm { color: rgba(150, 235, 205, 0.92); }   /* back to zero — the war is even again */
.milestone.down { color: rgba(255, 120, 120, 0.9); }    /* losing ground */

/* start gate: appears once the how-to has shown both gestures; the whole screen is the
   button, but the label sits in the lower third (below the centred how-to demo) */
.start {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;           /* label toward the bottom… */
  justify-content: center;         /* …horizontally centred */
  padding: 0 8vw 22vh;             /* lift it off the very bottom; keep clear of side edges */
  text-align: center;
  cursor: pointer;
  color: rgba(234, 240, 252, 0.92);
  font-family: system-ui, "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  font-weight: 200;
  text-transform: uppercase;
  letter-spacing: 0.34em;
  text-indent: 0.34em;
  font-size: clamp(1rem, 4.5vw, 2rem);
  text-shadow: 0 1px 22px rgba(10, 18, 40, 0.6);
  opacity: 0;
  pointer-events: none;            /* inert until revealed */
}
.start.show {
  pointer-events: auto;
  animation: startIn .8s ease forwards, startPulse 2.4s ease-in-out .8s infinite;
}
/* dropping the animation and forcing opacity:0 made this SNAP — a transition can't ease a value the
   animation was holding. It fades out with its own animation instead. */
.start.go { animation: startOut .7s ease forwards; pointer-events: none; }
@keyframes startOut { from { opacity: .8; } to { opacity: 0; } }
@keyframes startIn { from { opacity: 0; } to { opacity: .5; } }
@keyframes startPulse { 0%, 100% { opacity: .5; } 50% { opacity: 1; } }

/* per-keyframe timing: the animation's own cubic-bezier(.2,.7,.2,1) applies to EVERY interval, and it
   spends 70% of its progress in the first 20% of the time. On the fade-OUT that read as a hard cut, so
   the exit gets its own symmetric ease instead — calm in, calm out. */
@keyframes intro {
  0%   { opacity: 0; transform: scale(1.06); }
  18%  { opacity: 1; transform: scale(1); }
  62%  { opacity: 1; transform: scale(1); animation-timing-function: cubic-bezier(.4, 0, .5, 1); }
  100% { opacity: 0; transform: scale(.99); }
}

@media (prefers-reduced-motion: reduce) {
  .intro, .intro.go, .milestone, .milestone.go, .intro-calm, .intro-calm.go { animation: none; opacity: 0; }
  .start.show { animation: none; opacity: 1; }
}

/* centred, white, animated how-to — plays where the title was; cycles the gesture (no words on the effect) */
.hint {
  position: fixed;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #f2f6ff;
  opacity: 0;
  transition: opacity .9s ease;
}
.hint.show { opacity: 1; }
.hint.hide { opacity: 0 !important; transition: opacity .9s ease; }   /* out as slow as the .9s in */
/* how-to: each gesture NAMED with what it does, in the piece's own vocabulary. Replaced the mimed
   animation — a visitor shouldn't have to decode a pantomime to learn three controls. */
.howto { display: flex; flex-direction: column; align-items: center; gap: .95em; }
.howto-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: baseline;
  gap: 1.1em;
  width: min(86vw, 30em);
  font-family: system-ui, "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  font-weight: 200;
  text-transform: uppercase;
  font-size: clamp(.72rem, 2.1vw, 1.05rem);
  opacity: 0;
  animation: howtoIn .9s ease forwards;   /* per-row delay is set inline, so they arrive in order */
}
.howto-k {                                 /* the gesture */
  text-align: right;
  letter-spacing: .2em;
  color: rgba(238, 244, 255, .92);
}
.howto-arr { color: rgba(190, 205, 235, .45); font-size: .9em; }
.howto-v {                                 /* what it does */
  text-align: left;
  letter-spacing: .24em;
  font-weight: 300;
}
.howto-v.calm  { color: rgba(150, 235, 205, .95); text-shadow: 0 0 20px rgba(90, 210, 170, .35); }
.howto-v.chaos { color: rgba(255, 120, 120, .95); text-shadow: 0 0 20px rgba(220, 70, 70, .35); }
.howto-v.hold  { color: rgba(190, 215, 255, .9);  text-shadow: 0 0 20px rgba(120, 170, 255, .28); }
@keyframes howtoIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .howto-row { animation: none; opacity: 1; } }

/* shared "particles freed" counter — discreet, bottom-centre */
.counter {
  position: fixed;
  left: 50%;
  /* keep clear of the mobile browser toolbar / iOS home indicator (viewport-fit=cover) */
  bottom: calc(clamp(18px, 4vh, 44px) + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 5;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  white-space: nowrap;
  font-family: system-ui, "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  color: rgba(228, 236, 251, 0.92);
  text-shadow: 0 1px 18px rgba(10, 18, 40, 0.6);
  opacity: 0;                                  /* hidden during the title phase… */
}
.counter.show { opacity: 1; }                  /* …fades in once the title has left */
.counter-num {
  font-size: clamp(1.7rem, 5vw, 3rem);
  font-weight: 300;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}
.counter-label {
  /* a long phrase kept on ONE line: the font shrinks with the viewport (vw) and the
     tracking is tight enough that it still fits on narrow phones */
  font-size: clamp(0.46rem, 2.5vw, 0.8rem);
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  text-indent: 0.16em;
  color: rgba(170, 190, 225, 0.75);
  white-space: nowrap;
  text-align: center;
}
/* all-time records: highest (life) and lowest (abyss) the shared total has ever reached */
.counter-ext {
  display: flex;
  flex-wrap: wrap;             /* three stats now — let them fall to a second line rather than overflow */
  justify-content: center;
  gap: 0.4em 1.6em;
  margin-top: 5px;
  font-family: system-ui, "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  font-size: clamp(0.5rem, 1.5vw, 0.72rem);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.counter-stat { display: inline-flex; align-items: baseline; gap: 0.5em; }
.counter-stat-k {
  text-transform: uppercase;
  letter-spacing: 0.22em;
  font-size: 0.82em;
  color: rgba(170, 190, 225, 0.5);
}
#counterMax { color: rgba(150, 200, 255, 0.85); }   /* the best the war has ever been */
#counterMin { color: rgba(255, 120, 120, 0.8); }    /* the deepest into the red */
/* live head-count, split by side. Nobody picks a team: you are counted with whichever way your own
   recent contributions have been pushing the total. */
#counterLive { color: rgba(170, 190, 225, 0.55); font-variant-numeric: tabular-nums; }
#counterLive i { font-style: normal; opacity: 0.5; }
#counterLive b { font-weight: 400; }
.live-calm  { color: rgba(150, 235, 205, 0.95); }
.live-chaos { color: rgba(255, 120, 120, 0.95); }

/* live rate — which way the war is going right now; neutral until it's measured */
#counterRate { color: rgba(170, 190, 225, 0.55); font-variant-numeric: tabular-nums; }
#counterRate.up   { color: rgba(140, 235, 190, 0.9); }
#counterRate.down { color: rgba(255, 120, 120, 0.85); }

/* narrow phones: tighter, smaller — the wide tracking reads as broken at this size */
@media (max-width: 480px) {
  .counter { gap: 0; }
  .counter-num { font-size: 1.35rem; font-weight: 400; }
  .counter-label { letter-spacing: 0.12em; text-indent: 0.12em; }
}

/* sound on/off — small, discreet, bottom-right; created by audio.js once the piece starts */
.mute {
  position: fixed;
  right: calc(14px + env(safe-area-inset-right, 0px));
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  z-index: 25;
  width: 40px; height: 40px;
  padding: 0; margin: 0;
  display: none;                 /* flipped to flex once sound has started */
  align-items: center; justify-content: center;
  border: none; border-radius: 50%;
  background: rgba(20, 28, 48, 0.35);
  color: rgba(228, 236, 251, 0.85);
  cursor: pointer;
  opacity: 0;
  -webkit-tap-highlight-color: transparent;
  transition: opacity .3s ease, background .2s ease;
}
.mute.show { display: flex; opacity: .65; }
.mute:hover { opacity: 1; background: rgba(28, 38, 64, 0.5); }
.mute svg { width: 20px; height: 20px; display: block; }

/* negative → the war is lost: red */
.counter { transition: opacity .8s ease, color .5s ease; }
.counter.neg { color: #ff5a5a; text-shadow: 0 1px 22px rgba(120, 12, 20, .6); }
.counter.neg .counter-num { color: #ff5a5a; }
.counter.neg .counter-label { color: rgba(255, 140, 140, .8); }
