/* The page font: Knewave (bold brush display face). */
@font-face {
  font-family: "Knewave";
  src: url("fonts/Knewave-Regular.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  /* The page is always dark: stops phone browsers in dark mode (Chrome auto-dark,
     Samsung Internet) from recolouring it, e.g. turning the dark text outlines light. */
  color-scheme: dark only;

  /* =========================================================
     ONE font for the whole page.
     ========================================================= */
  --game-font: "Knewave", "Segoe UI", system-ui, sans-serif;

  /* Text outline (drawn behind the text, see .text-outline).
     Width is in em so it scales with each text size. */
  --outline-w:     0.08em;
  --outline-color: #0b0d10;
  --text-shadow:   0 0.06em 0.18em rgba(0, 0, 0, 0.55);

  /* =========================================================
     Dark grey palette with a blue primary. Solid colors only.
     ========================================================= */
  --bg:         #111316;  /* page background             */
  --surface:    #1c1f24;  /* raised game card            */
  --surface-2:  #24282e;  /* image well inside the card  */
  --primary:    #0a75a8;  /* rgb(10, 117, 168)           */
  --primary-d:  #085d86;  /* pressed                     */
  --primary-l:  #0c88c3;  /* hover                       */
  --accent:     #4fb3e3;  /* light blue for text accents */
  --text:       #eef1f4;  /* main text                   */
  --text-dim:   #9aa3ad;  /* secondary text              */
  --border:     #2c3138;  /* hairline borders            */

  /* Corner rounding for every box, button and popup (0 = square corners).
     Try 2px or 4px for a slightly softer look. */
  --radius: 4px;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

/* Game, not a document: no double-tap zoom (fast taps on the button would
   zoom on iPhone), no text selection, no long-press menu, no grey tap flash. */
html {
  --vh: 100vh;                     /* full screen height ... */
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

/* ... but on phones use the VISIBLE height (iPhone's 100vh includes the area
   behind Safari's address bar, which hid the bottom of the game). */
@supports (height: 100dvh) {
  html { --vh: 100dvh; }
}

body {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  --hud-h: 64px;                   /* height of the top strip */
  background: var(--bg);
  color: var(--text);
  font-family: var(--game-font);   /* everything inherits this one font */
  height: var(--vh);
  overflow: hidden;                /* HUD + play area only, no scroll */
}

/* ---------- HUD top strip ---------- */
.hud-top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 8;
  height: calc(var(--hud-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 16px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.hud-counter {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
.counter {
  font-size: 1.8rem;
  line-height: 1;
  letter-spacing: 1px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-shadow: var(--text-shadow);
}
.counter-currency {
  margin-right: 2px;
  color: var(--accent);
}
.mode-badge {
  align-self: center;
  margin-left: 6px;
  padding: 3px 10px;
  font-size: 0.75rem;
  letter-spacing: 1px;
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.mode-badge:empty { display: none; }
.hud-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* ---------- Play area: image in the middle (it IS the click button) ---------- */
.game {
  position: relative;
  z-index: 1;
  height: var(--vh);
  padding: calc(var(--hud-h) + env(safe-area-inset-top, 0px) + 16px) 16px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Image | side column (bar + hearts); the finish button floats over the image */
.play {
  display: grid;
  grid-template-columns: auto auto;
  column-gap: 14px;
  row-gap: 16px;
}
.image-wrap  { grid-column: 1; grid-row: 1; }
.side-col    { grid-column: 2; grid-row: 1; }
.source-link {
  grid-column: 1; grid-row: 1;           /* same cell as the image, top-left corner */
  align-self: start; justify-self: start;
  margin: 10px 0 0 10px;
  z-index: 2;
}
.finish-button {
  grid-column: 1; grid-row: 1;           /* same cell as the image, on top of it */
  align-self: end; justify-self: center;
  margin-bottom: 16px;
  z-index: 2;
}

/* ---------- Stage image (floats on the background) ---------- */
.image-wrap {
  position: relative;   /* for the effect-area overlays */
  display: flex;
  min-height: 0;
  border-radius: var(--radius);
  background: var(--surface-2);
  overflow: hidden;
  cursor: pointer;
  outline: none;
  box-shadow:
    0 0 0 1px var(--border),
    0 2px 6px rgba(0, 0, 0, 0.3),
    0 24px 64px rgba(0, 0, 0, 0.55);
}
.image-wrap:focus-visible {
  box-shadow:
    0 0 0 2px var(--accent),
    0 2px 6px rgba(0, 0, 0, 0.3),
    0 24px 64px rgba(0, 0, 0, 0.55);
}

/* Sized to the image's aspect ratio (--ar, set from JS): as big as the play
   area allows, leaving room for the HUD and the bar. */
.stage-image {
  --max-h: calc(var(--vh) - var(--hud-h) - env(safe-area-inset-top, 0px) - 40px);   /* page padding */
  --max-w: calc(100vw - 32px - 70px);   /* minus page padding + side column */
  height: min(var(--max-h), var(--max-w) / var(--ar, 1));
  width: auto;
  aspect-ratio: var(--ar, 1);
  object-fit: cover;
  display: block;
  pointer-events: none;   /* clicks go to the frame; no image drag / long-press save */
  /* `filter: blur(...)` is set from JS based on click count */
  transition: filter 0.15s ease;
  /* Round the image itself, AFTER the blur: Safari (iPhone) draws a filtered
     image on its own layer and ignores the frame's rounded overflow clip,
     so its square corners showed past the frame. */
  clip-path: inset(0 round var(--radius));
}

/* Pixelate effect renders through a canvas; keep its pixels crisp. */
canvas.stage-image {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Effect areas: overlays (in % of the image) that blur or pixelate just that part */
.fx-regions {
  position: absolute;
  inset: 0;
  pointer-events: none;
  clip-path: inset(0 round var(--radius));   /* same Safari corner fix */
}
.fx-region {
  position: absolute;   /* left/top/width/height in px, set from JS */
  overflow: hidden;
}
.fx-region--ellipse { border-radius: 50%; }

/* Image events with rings: a blurred copy of the image (plain CSS filter, set
   from JS) and a sharp copy inside each ring, clipped to its oval. No
   backdrop-filter or masks on purpose: phone browsers' forced dark modes can
   drop those. The copies are placed in px from JS, like the rings. */
.mark-blur,
.mark-holes {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  clip-path: inset(0 round var(--radius));
}
.mark-blur img,
.mark-hole img {
  position: absolute;
  display: block;
  max-width: none;
  user-select: none;
}
.mark-blur img { will-change: filter; }
.mark-hole {
  position: absolute;
  border-radius: 50%;
  overflow: hidden;
}

/* Image events: rings around spots on the image (left/top/size in px, from JS) */
.mark-rings {
  position: absolute;
  inset: 0;
  pointer-events: none;
  clip-path: inset(0 round var(--radius));
}
.mark-rings[hidden] { display: none; }
.mark-ring {
  position: absolute;
  box-sizing: border-box;
  border-radius: 50%;
  border: var(--ring-w, 4px) solid var(--ring-color, #000);
  /* a thin dark edge inside and out, so the ring shows on light and dark images */
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(0, 0, 0, 0.45);
  animation: ringIn 350ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes ringIn {
  from { transform: scale(1.35); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .mark-ring { animation: none; }
}
.fx-region canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Show either the <img> (blur/none) or the <canvas> (pixelate), never both. */
.is-hidden { display: none !important; }

/* ---------- Side column: click bar on top, hearts below (beside the image) ---------- */
.side-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 56px;
}

/* ---------- Click bar ---------- */
.click-bar {
  position: relative;
  flex: 1 1 auto;       /* takes the column height above the hearts */
  width: 22px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.45);
}
.click-bar::before {   /* the empty track */
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: var(--radius);
  background: var(--surface-2);
}
.click-bar-fill {
  position: relative;
  height: 100%;
  border-radius: var(--radius);
  background: var(--primary);
  box-shadow: 0 0 12px rgba(10, 117, 168, 0.6);
  transform: scaleY(var(--fill, 0));   /* --fill (0..1) animated from JS (a spring, see game.js) */
  transform-origin: bottom;
  will-change: transform;
}

/* ---------- Hearts (below the bar) ---------- */
.hearts {
  width: 56px;
  height: auto;
  flex: 0 0 auto;
  overflow: visible;     /* room for the beat to grow past the box */
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.5));
}
.heart-shape {
  fill: var(--primary);
  stroke: #000;
  stroke-width: 1.6;
  stroke-linejoin: round;
  transform-box: fill-box;
  transform-origin: 50% 60%;   /* beat from the heart's centre */
}

/* ---------- Mute button (in the HUD) ---------- */
.hud-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, color 0.12s ease;
}
.hud-button:active { transform: scale(0.94); }
.hud-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.hud-button svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.mute-button .mute-speaker { fill: currentColor; }
.mute-button .mute-cross { display: none; }
.mute-button.is-muted { color: var(--text-dim); }
.mute-button.is-muted .mute-waves { display: none; }
.mute-button.is-muted .mute-cross { display: inline; }

/* Autoplay: play icon when off, pause icon (accent) while auto-clicking */
.auto-button path { fill: currentColor; stroke: none; }
.auto-button .auto-pause { display: none; }
.auto-button.is-on { color: var(--accent); border-color: var(--accent); }
.auto-button.is-on .auto-play { display: none; }
.auto-button.is-on .auto-pause { display: inline; }

/* ---------- Start screen: mode slider + Start ---------- */
.start-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: var(--bg);
}
.start-screen[hidden] { display: none; }
.mode-picker {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 22px;
  width: min(100%, 440px);
  padding: 30px 28px 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3), 0 16px 40px rgba(0, 0, 0, 0.45);
}
.mode-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}
.mode-sub {
  font-size: 0.8rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-dim);
}
.mode-name {
  font-size: 2.4rem;
  line-height: 1;
  color: var(--text);
  text-shadow: var(--text-shadow);
}
.mode-price { color: var(--accent); }
.mode-rate {
  margin: -8px 0 0;
  font-size: 0.9rem;
  text-align: center;
  color: var(--text-dim);
}

/* The slider: blue fill up to the thumb (--pct set from JS), heart thumb */
.mode-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 34px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  touch-action: none;   /* dragging must not scroll the page */
}
.mode-slider:focus { outline: none; }
.mode-slider:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.mode-slider::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: var(--radius);
  background: linear-gradient(to right, var(--primary) var(--pct, 0%), var(--surface-2) var(--pct, 0%));
  border: 1px solid var(--border);
}
.mode-slider::-moz-range-track {
  height: 8px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.mode-slider::-moz-range-progress {
  height: 8px;
  border-radius: var(--radius);
  background: var(--primary);
}
.mode-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 34px;
  height: 34px;
  margin-top: -14px;    /* centre on the 8px track (minus its border) */
  border: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23eef1f4' stroke='%230b0d10' stroke-width='1.5' d='M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z'/%3E%3C/svg%3E") center / contain no-repeat;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
  transition: transform 0.12s ease;
}
.mode-slider::-moz-range-thumb {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23eef1f4' stroke='%230b0d10' stroke-width='1.5' d='M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z'/%3E%3C/svg%3E") center / contain no-repeat;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
  transition: transform 0.12s ease;
}
.mode-slider:active::-webkit-slider-thumb { transform: scale(1.15); }
.mode-slider:active::-moz-range-thumb { transform: scale(1.15); }

/* Stop labels under the track: first left, middle centred, last right */
.mode-stops {
  display: flex;
  justify-content: space-between;
  margin-top: -12px;
}
.mode-stop {
  flex: 1 1 0;
  padding: 4px 0;
  font-family: inherit;
  font-size: 0.85rem;
  letter-spacing: 1px;
  color: var(--text-dim);
  background: none;
  border: none;
  cursor: pointer;
  transition: color 0.15s ease;
}
.mode-stop:first-child { text-align: left; }
.mode-stop:last-child { text-align: right; }
.mode-stop.is-active { color: var(--accent); }
.mode-stop:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.mode-start {
  padding: 14px 20px;
  font-family: inherit;
  font-size: 1.1rem;
  letter-spacing: 1.5px;
  color: #fff;
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  box-shadow: 0 4px 14px rgba(10, 117, 168, 0.35);
  cursor: pointer;
  transition: transform 0.12s ease;
}
.mode-start:active { transform: scale(0.97); }
.mode-start:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

@media (max-width: 520px) {
  .mode-picker { padding: 24px 20px 22px; }
  .mode-name { font-size: 2rem; }
}

/* Phone: tighter spacing + a taller image. */
@media (max-width: 520px) {
  /* Tighter spacing so the image gets more room */
  .game { padding-left: 10px; padding-right: 10px; align-items: flex-start; }   /* image + bar at the top, like desktop */

  /* Bar row ABOVE the image: hearts on the left, then a horizontal bar. */
  .play { grid-template-columns: auto; row-gap: 10px; }
  .side-col { grid-column: 1; grid-row: 1; flex-direction: row; width: auto; height: 36px; gap: 10px; }
  .image-wrap, .finish-button, .source-link { grid-row: 2; }
  .hearts { order: -1; width: 44px; }
  .click-bar { align-self: stretch; width: auto; padding: 4px; }
  .click-bar-fill { transform: scaleX(var(--fill, 0)); transform-origin: left; }

  /* Full-height image: the frame fills the free width and height and the image
     covers it (object-fit: cover; the sides are trimmed, centred). Effect areas
     and pop-up text spots follow the image (see imageBox() in game.js). */
  .stage-image {
    --max-h: calc(var(--vh) - var(--hud-h) - env(safe-area-inset-top, 0px) - 40px - 46px);   /* page padding + bar row + gap */
    --max-w: calc(100vw - 20px);   /* page padding */
    width: var(--max-w);
    height: var(--max-h);
    aspect-ratio: auto;
  }
}

/* ---------- Source link: small and faint over the image's corner ---------- */
.source-link {
  padding: 3px 8px;
  font-size: 11px;
  letter-spacing: 0.5px;
  color: var(--text);
  text-decoration: none;
  background: rgba(17, 19, 22, 0.55);
  border-radius: 6px;
  opacity: 0.45;
  transition: opacity 0.15s ease;
}
.source-link[hidden] { display: none; }
.source-link::after { content: " \2197"; }   /* ↗ */
.source-link:hover, .source-link:focus-visible { opacity: 1; }
.source-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Finish button: hold for 2 s (floating over the image) ---------- */
.finish-button {
  position: relative;
  overflow: hidden;
  height: 40px;
  min-width: 170px;
  padding: 0 26px;
  font-family: inherit;
  font-size: 13px;
  letter-spacing: 1.5px;
  color: var(--text);
  background: rgba(17, 19, 22, 0.72);   /* dark glass so it reads on any image */
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  user-select: none;
  touch-action: none;      /* a long press must not scroll or zoom */
  transition: color 0.12s ease, border-color 0.12s ease;
}
.finish-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.finish-fill {   /* sweeps across while held; snaps back when released */
  position: absolute;
  inset: 0;
  background: var(--primary);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.15s ease-out;
}
.finish-button.holding { color: #fff; border-color: var(--primary); }
.finish-button.holding .finish-fill {
  transform: scaleX(1);
  transition: transform var(--hold-ms, 2000ms) linear;
}
.finish-label { position: relative; }
/* Locked by a failed task: greyed out, can't be held */
.finish-button.is-locked {
  color: var(--text-dim);
  border-color: var(--border);
  cursor: not-allowed;
}

/* ---------- Focus event: blur layer with holes (mask set from JS) ---------- */
.focus-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  -webkit-backdrop-filter: blur(0px);
  backdrop-filter: blur(0px);
  /* the blur strength ramps up / down over 2 s */
  transition: opacity 0.35s ease, backdrop-filter 2s ease, -webkit-backdrop-filter 2s ease;
  mask-mode: alpha;                /* opaque = blurred, transparent = the sharp holes */
  mask-size: 100% 100%;
  -webkit-mask-size: 100% 100%;
  mask-repeat: no-repeat;
  -webkit-mask-repeat: no-repeat;
}
.focus-fx.is-on {
  opacity: 1;
  -webkit-backdrop-filter: blur(var(--focus-blur, 20px));   /* --focus-blur set from JS */
  backdrop-filter: blur(var(--focus-blur, 20px));
}

/* ---------- Event countdowns (under the HUD) ---------- */
.event-timers {
  position: fixed;
  top: calc(var(--hud-h) + env(safe-area-inset-top, 0px) + 10px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 7;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.event-timer {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 16px;
  font-size: 14px;
  letter-spacing: 1px;
  color: var(--text);
  background: rgba(17, 19, 22, 0.82);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
}
.event-timer-time {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.event-timer--free { border-color: var(--accent); }

/* ---------- Event popup (same look as the finish popup) ---------- */
.event-screen {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: rgba(8, 10, 12, 0.45);   /* light dim: the image stays visible */
  animation: finishFade 0.6s ease-out;
}
.event-screen[hidden] { display: none; }
/* The card waits for .is-shown (added from JS after a short pause). */
.event-screen:not(.is-shown) .event-card { visibility: hidden; }
.event-screen.is-shown .event-card { animation: finishPop 0.6s cubic-bezier(0.2, 0.8, 0.2, 1); }
.event-card {
  width: min(460px, 100%);
  padding: 28px 24px 24px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
}
.event-title {
  margin: 0 0 10px;
  font-size: 1.8rem;
  font-weight: normal;
  line-height: 1.15;
  color: var(--accent);
  text-shadow: var(--text-shadow);
}
.event-title[hidden], .event-message[hidden] { display: none; }
.event-message {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.3;
  color: var(--text);
  white-space: pre-line;    /* keep line breaks from the admin */
}
.event-note {
  margin: 6px 0 0;
  font-size: 0.9rem;
  font-weight: normal;
  color: var(--text-dim);
}
.event-input {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 20px auto 0;
  width: min(220px, 100%);
  padding: 0 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.event-input:focus-within { border-color: var(--accent); }
.event-input.is-invalid { border-color: #d9534f; animation: shake 0.3s; }
.event-input-cur { font-size: 1.3rem; color: var(--accent); }
.event-input-note {   /* "= 25 seconds of free clicks" under the amount */
  margin: 8px 0 0;
  font-size: 0.95rem;
  color: var(--text-dim);
}
.event-input input {
  flex: 1;
  min-width: 0;
  height: 48px;
  font-family: inherit;
  font-size: 1.3rem;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}
.event-buttons {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 22px;
}
.event-btn {
  flex: 1 1 0;
  max-width: 200px;
  padding: 13px 20px;
  font-family: inherit;
  font-size: 1rem;
  letter-spacing: 1px;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.event-btn--primary {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 4px 14px rgba(10, 117, 168, 0.35);
}
.event-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
@keyframes shake {
  25% { transform: translateX(-6px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

/* ---------- Finish popup ---------- */
.finish-screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: rgba(8, 10, 12, 0.78);
  animation: finishFade 0.25s ease-out;
}
.finish-screen[hidden] { display: none; }
.finish-card {
  width: min(460px, 100%);
  padding: 28px 24px 24px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
  animation: finishPop 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.finish-message {
  margin: 0;
  font-size: 1.6rem;
  line-height: 1.25;
  color: var(--text);
  white-space: pre-line;    /* keep line breaks from the admin */
  text-shadow: var(--text-shadow);
}
.finish-links {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 22px;
}
.finish-links:empty { display: none; }
.finish-link {
  display: block;
  padding: 14px 20px;
  font-size: 1rem;
  letter-spacing: 1px;
  color: #fff;
  text-decoration: none;
  background: var(--primary);
  border-radius: var(--radius);
  box-shadow: 0 4px 14px rgba(10, 117, 168, 0.35);
  transition: background 0.12s ease;
}
@keyframes finishFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes finishPop {
  from { transform: scale(0.9); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* ---------- Hover: a heart fills out from the centre ---------- */
/* The heart sits behind the content (isolation + z-index -1) and is clipped
   to the rounded box. It's sized from the box width, big enough to cover it. */
.hud-button,
.mode-start,
.finish-button,
.event-btn,
.finish-link {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}
.hud-button::before,
.mode-start::before,
.finish-button::before,
.event-btn::before,
.finish-link::before {
  content: "";
  position: absolute;
  z-index: -1;
  left: 50%;
  top: 50%;
  width: 320%;
  aspect-ratio: 1;
  background: var(--heart-fill, var(--primary));
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z'/%3E%3C/svg%3E") center / contain no-repeat;
  transform: translate(-50%, -50%) scale(0);
  transition: transform 0.8s cubic-bezier(0.2, 0.7, 0.2, 1);
  pointer-events: none;
}
/* Already-blue buttons fill with the lighter blue */
.event-btn--primary,
.finish-link,
.mode-start { --heart-fill: var(--primary-l); }

/* Only on devices that really hover (a tap on a phone would leave it stuck) */
@media (hover: hover) {
  .hud-button:hover::before,
  .mode-start:hover::before,
  .finish-button:not(.is-locked):hover::before,
  .event-btn:hover::before,
  .finish-link:hover::before {
    transform: translate(-50%, -50%) scale(1);
  }
}
@media (prefers-reduced-motion: reduce) {
  .hud-button::before,
  .mode-start::before,
  .finish-button::before,
  .event-btn::before,
  .finish-link::before { transition-duration: 0.01s; }
}

/* ---------- Flying text layer ---------- */
.fly-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;   /* never blocks the button */
  z-index: 5;
}
.flying-text {
  position: absolute;
  left: 0;
  white-space: nowrap;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  filter: drop-shadow(var(--text-shadow));
  will-change: transform;
  /* duration is set per-element from JS */
  animation-name: flyAcross;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}

/* Text outline, drawn as the same text again BEHIND the letters (from data-text).
   The outline is a BACKGROUND clipped to the stroked letter shape, not a text
   colour: phone browsers' forced dark modes (old Samsung Internet / Chrome /
   WebView, which ignore color-scheme) lighten dark text colours but always keep
   dark backgrounds dark, so this outline stays dark everywhere. */
.text-outline {
  isolation: isolate;   /* keeps the z-index:-1 outline just behind this text */
}
/* The outline is placed against its text, so that must be positioned. Not set on
   .text-outline itself: it would override .flying-text's position: absolute. */
.flying-text-pulse { position: relative; }
.text-outline::before {
  content: attr(data-text);
  position: absolute;
  /* Reaches past the text on every side (the background only paints inside this
     box, and the outline sticks out of the letters); padding puts the text back. */
  top: -0.5em; right: -0.5em; bottom: -0.5em; left: -0.5em;   /* not inset: old Android lacks it */
  padding: 0.5em;
  z-index: -1;
  -webkit-text-fill-color: transparent;
  -webkit-text-stroke: var(--outline-w) transparent;   /* same visible width as before */
  background: var(--outline-color);
  -webkit-background-clip: text;
  background-clip: text;
}
/* Event texts get a white outline. White must stay a text colour (forced dark
   would darken a white background), and light text colours are left alone. */
.flying-text--event .text-outline::before {
  background: none;
  -webkit-text-stroke-color: #fff;
}

/* The text of a "flying text" event: the only clickable one. Like the other
   flying texts, but with a white outline and a gentle sway + pulse. */
.flying-text--event {
  pointer-events: auto;
  cursor: pointer;
  padding: 0.3em 0.5em;   /* a bit more to hit while it moves */
  z-index: 1;             /* above the normal flying texts */
}
.flying-text-pulse {
  display: inline-block;
  animation: flyTextSway 1.6s ease-in-out infinite;
}
/* Tilts a little left and right, growing a touch at each tilt */
@keyframes flyTextSway {
  0%, 50%, 100% { transform: rotate(0deg) scale(1); }
  25%           { transform: rotate(-4deg) scale(1.06); }
  75%           { transform: rotate(4deg) scale(1.06); }
}
@media (prefers-reduced-motion: reduce) {
  .flying-text-pulse { animation: none; }
}

@keyframes flyAcross {
  from { transform: translateX(-100%); }   /* just off the left edge  */
  to   { transform: translateX(100vw); }   /* just off the right edge */
}

/* ---- Pop-up texts (centre of the screen) ----
   Font size and animation duration are set per element from JS. */
.pop-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;   /* never blocks the button */
  z-index: 9;             /* above the HUD */
}
/* Anchor = the point the text is centred on: the screen centre by default, or
   a spot on the image (positioned from JS in px). The text animates inside it. */
.pop-anchor {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: max-content;
  max-width: 90vw;
}
.pop-text {
  max-width: 90vw;
  text-align: center;
  line-height: 1.05;
  overflow-wrap: anywhere;
  font-weight: 700;
  color: var(--text);
  position: relative;
  will-change: transform, opacity;   /* also a stacking context, for the outline below */
  animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
  animation-fill-mode: both;
}
/* The outline: the same text again, stroked, BEHIND the text. (Safari ignores
   paint-order on HTML text and would stroke over the letters; this way no line's
   outline can cover another line's letters either.) */
.pop-text::before {
  content: attr(data-text);
  position: absolute;
  /* Reaches past the text on every side (the background only paints inside this
     box, and the outline sticks out of the letters); padding puts the text back. */
  top: -0.5em; right: -0.5em; bottom: -0.5em; left: -0.5em;   /* not inset: old Android lacks it */
  padding: 0.5em;
  z-index: -1;
  -webkit-text-fill-color: transparent;
  -webkit-text-stroke: var(--stroke-w, calc(var(--outline-w) * 2)) transparent;
  background: var(--outline-color);   /* the outline colour, see .text-outline */
  -webkit-background-clip: text;
  background-clip: text;
  /* blue edge + soft shadow under the outline's shape */
  filter: drop-shadow(0 0.04em 0 var(--primary)) drop-shadow(0 0.06em 0.2em rgba(0, 0, 0, 0.85));
}
.pop-zoom  { animation-name: popZoom; }
.pop-slam  { animation-name: popSlam; animation-timing-function: ease-out; }
.pop-drop  { animation-name: popDrop; animation-timing-function: ease-out; }
.pop-spin  { animation-name: popSpin; }
.pop-focus { animation-name: popFocus; animation-timing-function: ease-out; }
/* One-line texts ("Random £ added"): never wrap, lighter than other pop-up texts. */
.pop-text--line { white-space: nowrap; overflow-wrap: normal; font-weight: 400; }
/* Image event texts: as light as the one-line texts, but long ones may wrap. */
.pop-text--event { font-weight: 400; }
.pop-text.pop-out {
  animation: popOut 350ms ease-in forwards;
}

/* Zoom: from the centre, size 0 + invisible -> full size + opaque */
@keyframes popZoom {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
/* Slam: starts huge and see-through, slams down with a small bounce */
@keyframes popSlam {
  0%   { transform: scale(4);    opacity: 0; }
  60%  { transform: scale(0.9);  opacity: 1; }
  80%  { transform: scale(1.06); }
  100% { transform: scale(1);    opacity: 1; }
}
/* Drop: falls from above the screen and bounces */
@keyframes popDrop {
  0%   { transform: translateY(-60vh); opacity: 0; }
  55%  { transform: translateY(0);     opacity: 1; }
  72%  { transform: translateY(-8%); }
  86%  { transform: translateY(0); }
  93%  { transform: translateY(-2%); }
  100% { transform: translateY(0);     opacity: 1; }
}
/* Spin: two turns while growing from nothing */
@keyframes popSpin {
  from { transform: scale(0) rotate(-720deg); opacity: 0; }
  to   { transform: scale(1) rotate(0);       opacity: 1; }
}
/* Focus: sharpens out of a heavy blur while settling */
@keyframes popFocus {
  from { transform: scale(1.4); filter: blur(30px); opacity: 0; }
  to   { transform: scale(1);   filter: blur(0);    opacity: 1; }
}
/* Exit (all animations): fade out while growing slightly */
@keyframes popOut {
  from { transform: scale(1);   opacity: 1; }
  to   { transform: scale(1.2); opacity: 0; }
}
