/* 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 {
  /* =========================================================
     ONE font for the whole page.
     ========================================================= */
  --game-font: "Knewave", "Segoe UI", system-ui, sans-serif;

  /* Text outline (drawn behind the fill via paint-order).
     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            */
}

* { 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 */
  --img-radius: 16px;              /* rounded corners of the image frame */
  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-label {
  font-size: 0.95rem;
  letter-spacing: 1px;
  color: var(--text-dim);
}
.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: 999px;
  background: var(--surface-2);
}
.mode-badge:empty { display: none; }
.hud-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* ---------- Play area: image in the middle, button below ---------- */
.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), with the button centred under 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; }
.click-button { grid-column: 1; grid-row: 2; justify-self: center; }
.finish-button { grid-column: 1; grid-row: 3; justify-self: center; margin-top: -4px; }

/* ---------- Stage image (floats on the background) ---------- */
.image-wrap {
  position: relative;   /* for the effect-area overlays */
  display: flex;
  min-height: 0;
  border-radius: var(--img-radius);
  background: var(--surface-2);
  overflow: hidden;
  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);
}

/* Sized to the image's aspect ratio (--ar, set from JS): as big as the play
   area allows, leaving room for the HUD, the button and the bar. */
.stage-image {
  --max-h: calc(var(--vh) - var(--hud-h) - env(safe-area-inset-top, 0px) - 156px);   /* room for both buttons */
  --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;
  /* `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(--img-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(--img-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%; }
.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: 12px;
  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: 8px;
  background: var(--surface-2);
}
.click-bar-fill {
  position: relative;
  height: 100%;
  border-radius: 8px;
  background: var(--primary);
  box-shadow: 0 0 12px rgba(10, 117, 168, 0.6);
  transform: scaleY(0);
  transform-origin: bottom;
  transition-property: transform;   /* duration is set from JS (admin config) */
  transition-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
  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: 50%;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, color 0.12s ease;
}
.hud-button:hover { background: var(--border); }
.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: three mode buttons ---------- */
.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-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 18px;
}
.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 220px;
  max-width: 100%;
  padding: 26px 20px 28px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3), 0 16px 40px rgba(0, 0, 0, 0.45);
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
.mode-btn:hover {
  transform: translateY(-3px);
  border-color: var(--primary);
}
.mode-btn:active { transform: scale(0.97); }
.mode-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.mode-sub {
  font-size: 0.8rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-dim);
}
.mode-name {
  font-size: 2.1rem;
  line-height: 1;
  color: var(--text);
  text-shadow: var(--text-shadow);
}
.mode-price { color: var(--accent); }

@media (max-width: 520px) {
  .counter-label { display: none; }
  .mode-btn { width: 100%; padding: 18px 20px 20px; }
  .mode-list { flex-direction: column; width: min(100%, 320px); }
}

/* ---------- The click button ---------- */
.click-button {
  font-family: inherit;
  font-size: 15px;
  letter-spacing: 2px;
  color: #fff;
  background: var(--primary);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  height: 40px;
  min-width: 160px;
  padding: 0 32px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 4px 14px rgba(10, 117, 168, 0.35), 0 1px 2px rgba(0, 0, 0, 0.4);
  transition: transform 0.05s ease, background 0.12s ease, box-shadow 0.12s ease;
}
.click-button:hover { background: var(--primary-l); }
.click-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.click-button.pressed,
.click-button:active {
  transform: scale(0.96);
  background: var(--primary-d);
  box-shadow: 0 2px 6px rgba(10, 117, 168, 0.3);
}

/* Phone: big full-width pill button under the image + bar
   (after the base button rules so it wins). */
@media (max-width: 520px) {
  .click-button {
    grid-column: 1 / -1;
    justify-self: stretch;
    width: 100%;
    height: 56px;
    font-size: 18px;
    border-radius: 500px;
  }
  .finish-button {
    grid-column: 1 / -1;
    justify-self: stretch;
    width: 100%;
    height: 46px;
    border-radius: 500px;
  }
  /* Tighter spacing so the image gets more room */
  .game { padding-left: 10px; padding-right: 10px; }
  .play { column-gap: 10px; }
  .side-col, .hearts { width: 44px; }

  /* Taller image: the frame may be up to 1.4x taller than the image's own shape
     (fills the free height; 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) - 180px);   /* room for both taller buttons */
    --max-w: calc(100vw - 20px - 54px);   /* page padding + side column + gap */
    --fit-w: min(var(--max-w), var(--max-h) * var(--ar, 1));
    width: var(--fit-w);
    height: min(var(--max-h), var(--fit-w) / var(--ar, 1) * 1.4);
    aspect-ratio: auto;
  }
}

/* ---------- Finish button: hold for 2 s ---------- */
.finish-button {
  position: relative;
  overflow: hidden;
  height: 36px;
  min-width: 160px;
  padding: 0 24px;
  font-family: inherit;
  font-size: 13px;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  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:hover { color: var(--text); border-color: var(--primary); }
.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; }

/* ---------- 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: 20px;
  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: 500px;
  box-shadow: 0 4px 14px rgba(10, 117, 168, 0.35);
  transition: background 0.12s ease;
}
.finish-link:hover { background: var(--primary-l); }
@keyframes finishFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes finishPop {
  from { transform: scale(0.9); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* ---------- 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: 2.2rem;
  font-weight: 700;
  color: var(--accent);
  filter: drop-shadow(var(--text-shadow));
  -webkit-text-stroke: var(--outline-w) var(--outline-color);
  paint-order: stroke fill;
  will-change: transform;
  /* duration is set per-element from JS */
  animation-name: flyAcross;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}

@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);
  -webkit-text-stroke: var(--outline-w) var(--outline-color);
  paint-order: stroke fill;
  text-shadow: 0 0.04em 0 var(--primary), 0 0.08em 0.3em rgba(0, 0, 0, 0.6);
  will-change: transform, opacity;
  animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
  animation-fill-mode: both;
}
.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; }
.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; }
}
