/* =========================================================================
   Campaign Engine — core stylesheet
   Nothing here is client-specific. Every colour, radius and background is a
   CSS variable that js/main.js writes from the campaign config file.
   Reskinning = editing campaigns/<client>.js. Never this file.
   ========================================================================= */

:root {
  /* --- overwritten at runtime by the campaign config --- */
  --brand:        #e4002b;
  --brand-ink:    #ffffff;
  --brand-2:      #ff7a00;
  --accent:       #ff2d55;
  --bg:           #b8151f;
  --surface:      rgba(24, 16, 18, .88);
  --surface-2:    rgba(40, 28, 30, .92);
  --text:         #ffffff;
  --muted:        rgba(255, 255, 255, .62);
  --board:        #0b0b0f;
  --page-bg:      #b8151f;

  /* --- structural, campaign-independent --- */
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-pill: 999px;
  --topbar-h: 60px;
  --shadow-1: 0 4px 16px rgba(0, 0, 0, .28);
  --shadow-2: 0 18px 48px rgba(0, 0, 0, .45);
  --ease: cubic-bezier(.4, 0, .2, 1);
}

* { box-sizing: border-box; }

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

body {
  font-family: "Heebo", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background-color: var(--page-bg);
  background-image: var(--page-bg-image, none);
  background-size: var(--page-bg-size, cover);
  background-position: center;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  overscroll-behavior-y: none;
}

/* A dark vignette keeps foreground copy legible over any brand background. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 42%, transparent 38%, rgba(0, 0, 0, .55) 100%);
  z-index: 0;
}

img { max-width: 100%; }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }

.ico { width: 20px; height: 20px; fill: currentColor; stroke: currentColor; }
.ico-sm { width: 16px; height: 16px; }

/* =========================================================================
   Top bar — persistent across every screen
   ========================================================================= */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  min-height: var(--topbar-h);
}

.topbar__tools { display: flex; gap: 8px; }

.iconbtn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--text);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-1);
  transition: transform .15s var(--ease), background .15s var(--ease);
}
.iconbtn:hover { transform: translateY(-1px); background: var(--surface-2); }
.iconbtn:active { transform: scale(.94); }

/* Sound button swaps its glyph via the data-on attribute. */
.iconbtn .ico-sound-off { display: none; }
.iconbtn[data-on="false"] .ico-sound-on { display: none; }
.iconbtn[data-on="false"] .ico-sound-off { display: block; }

.topbar__ticker {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 5px 5px 5px 18px;
  border-radius: var(--r-pill);
  background: var(--surface);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-1);
}

.topbar__msg {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 900;
  font-size: 18px;
  letter-spacing: -.02em;
  line-height: 1;
  text-shadow: 0 2px 10px rgba(0, 0, 0, .5);
}
.topbar__brand .brand-kicker {
  display: block;
  font-size: 8px;
  font-weight: 500;
  letter-spacing: .18em;
  opacity: .8;
  margin-bottom: 3px;
}
.topbar__brand .brand-mark { font-size: 26px; line-height: 1; }

/* =========================================================================
   Buttons
   ========================================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: var(--r-pill);
  font-weight: 700;
  font-size: 15px;
  text-decoration: none;
  color: var(--text);
  transition: transform .15s var(--ease), box-shadow .15s var(--ease), filter .15s var(--ease);
  white-space: nowrap;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0) scale(.98); }

.btn--primary {
  background: var(--brand);
  color: var(--brand-ink);
  box-shadow: 0 6px 20px -6px var(--brand), inset 0 1px 0 rgba(255, 255, 255, .22);
}
.btn--primary:hover { filter: brightness(1.08); box-shadow: 0 10px 28px -6px var(--brand); }

.btn--ghost {
  background: var(--surface-2);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-1);
}
.btn--ghost:hover { background: rgba(255, 255, 255, .14); }

.btn--link {
  background: none;
  color: var(--muted);
  font-weight: 500;
  font-size: 14px;
  text-decoration: underline;
  text-underline-offset: 4px;
  padding: 10px;
}
.btn--link:hover { color: var(--text); transform: none; }

.btn--sm  { padding: 8px 18px; font-size: 14px; }
.btn--lg  { padding: 15px 30px; font-size: 17px; }
.btn--block { width: 100%; }

.btn__arrow { font-size: 1.1em; transition: transform .2s var(--ease); }
.btn:hover .btn__arrow { transform: translateX(-4px); }   /* RTL: arrow points ← */

/* =========================================================================
   Screens
   ========================================================================= */

.stage {
  position: relative;
  z-index: 1;
  min-height: calc(100dvh - var(--topbar-h));
  display: flex;
  flex-direction: column;
  padding: 8px 12px 4px;
}

.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  animation: screen-in .4s var(--ease) both;
}
.screen.is-active { display: flex; }

@keyframes screen-in {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- Screen 1: intro ---------- */

.intro {
  width: 100%;
  max-width: 560px;
  text-align: center;
  padding: 12px 0 24px;
}

.intro__hero {
  font-size: clamp(64px, 18vw, 104px);
  line-height: 1;
  filter: drop-shadow(0 18px 26px rgba(0, 0, 0, .5));
  animation: float 3.6s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50%      { transform: translateY(-16px) rotate(4deg); }
}

.intro__title {
  margin: 14px 0 18px;
  font-size: clamp(40px, 12vw, 68px);
  font-weight: 900;
  letter-spacing: -.03em;
  line-height: 1.05;
  text-shadow: 0 6px 26px rgba(0, 0, 0, .55);
}

.card-dark {
  background: var(--surface);
  backdrop-filter: blur(10px);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
}

.intro__sub {
  margin: 0 auto 22px;
  padding: 18px 22px;
  max-width: 460px;
  font-size: 16px;
  line-height: 1.65;
  color: rgba(255, 255, 255, .92);
}
.intro__sub b { color: var(--brand-2); font-weight: 700; }

.intro__actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.intro__peek {
  display: block;
  margin: 20px auto 0;
  padding: 14px 40px;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  background: var(--surface);
  backdrop-filter: blur(10px);
  color: var(--muted);
  font-weight: 500;
  font-size: 15px;
}
.intro__peek:hover { color: var(--text); }

/* ---------- Screen 2: game ---------- */

.screen--game { justify-content: flex-start; padding-top: 4px; }

.hud {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 700px;
  margin-bottom: 8px;
}

.hud__tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 6px 9px;
  border-radius: var(--r-md);
  background: var(--surface);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-1);
  min-height: 62px;
}
.hud__tile--time { background: var(--surface-2); }
.hud__tile--score {
  background: var(--brand);
  color: var(--brand-ink);
  box-shadow: 0 6px 22px -8px var(--brand);
}

.hud__label { font-size: 11px; font-weight: 500; opacity: .72; }
.hud__value { font-size: 24px; font-weight: 900; line-height: 1.12; font-variant-numeric: tabular-nums; }
.hud__meta  { font-size: 10px; font-weight: 700; color: var(--brand-2); }
.hud__tile--score .hud__label { opacity: .85; }

/* Pulse the score tile when points land. */
.hud__tile.is-bump { animation: bump .3s var(--ease); }
@keyframes bump {
  50% { transform: scale(1.08); }
}
.hud__tile--time.is-urgent .hud__value { color: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }

.progress {
  width: 100%;
  max-width: 700px;
  height: 5px;
  border-radius: var(--r-pill);
  background: rgba(0, 0, 0, .35);
  overflow: hidden;
  margin-bottom: 10px;
}
.progress__fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  transition: width .35s var(--ease);
}

.board {
  position: relative;
  width: 100%;
  max-width: 700px;
  aspect-ratio: 3 / 4;
  max-height: 62dvh;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: var(--board);
  box-shadow: var(--shadow-2), inset 0 0 0 1px rgba(255, 255, 255, .07);
  touch-action: none;              /* swipes drive the game, not the page */
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.board.is-shaking { animation: shake .3s var(--ease); }
@keyframes shake {
  20% { transform: translate(-6px, 3px); }
  50% { transform: translate(5px, -3px); }
  80% { transform: translate(-3px, 2px); }
}

#canvas { display: block; width: 100%; height: 100%; }

.pausebtn {
  position: absolute;
  top: 10px;
  inset-inline-start: 10px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, .12);
  backdrop-filter: blur(8px);
  font-size: 13px;
  font-weight: 700;
}
.pausebtn:hover { background: rgba(255, 255, 255, .2); }

.board__watermark {
  position: absolute;
  bottom: 10px;
  inset-inline-end: 14px;
  z-index: 2;
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, .35);
  pointer-events: none;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(6, 6, 10, .78);
  backdrop-filter: blur(4px);
}
.overlay.is-active { display: flex; }

.overlay__panel { text-align: center; display: grid; gap: 10px; padding: 24px; }
.overlay__panel h2 { margin: 0 0 6px; font-size: 22px; }

.countdown {
  font-size: clamp(80px, 22vw, 140px);
  font-weight: 900;
  color: var(--brand-2);
  text-shadow: 0 0 40px var(--brand);
  animation: pop .6s var(--ease);
}
@keyframes pop {
  0%   { transform: scale(.4); opacity: 0; }
  60%  { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

.combo {
  position: absolute;
  top: 22%;
  inset-inline: 0;
  z-index: 4;
  text-align: center;
  font-size: clamp(26px, 7vw, 40px);
  font-weight: 900;
  color: var(--brand-2);
  text-shadow: 0 0 24px rgba(0, 0, 0, .8);
  opacity: 0;
  pointer-events: none;
}
.combo.is-on { animation: combo-pop .8s var(--ease); }
@keyframes combo-pop {
  0%   { opacity: 0; transform: scale(.6); }
  25%  { opacity: 1; transform: scale(1.1); }
  70%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1) translateY(-24px); }
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 10px;
  width: 100%;
  max-width: 700px;
}

.legend__pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--r-pill);
  background: var(--surface);
  backdrop-filter: blur(6px);
  font-size: 12px;
  font-weight: 700;
  box-shadow: var(--shadow-1);
}
.legend__pill i { font-style: normal; font-size: 16px; line-height: 1; }
.legend__art { display: block; width: 28px; height: 28px; margin: -4px 0; }
.legend__pill.is-bad  { color: #ff8a8a; }
.legend__pill.is-star { color: #ffd166; box-shadow: 0 0 0 1px rgba(255, 209, 102, .35); }
.legend__pill.is-rule { color: var(--brand-2); }

/* ---------- Screens 3 & 4: form + reward ---------- */

.panel {
  width: 100%;
  max-width: 440px;
  padding: 26px 24px 22px;
  border-radius: var(--r-lg);
  background: var(--surface);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow-2);
  margin: 12px 0 24px;
}
.panel--center { text-align: center; }

.panel__score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, .1);
  font-size: 14px;
  color: var(--muted);
}
.panel__score strong {
  font-size: 34px;
  font-weight: 900;
  color: var(--brand-2);
  font-variant-numeric: tabular-nums;
}

.panel__title { margin: 0 0 8px; font-size: 24px; font-weight: 900; letter-spacing: -.02em; }
.panel__sub   { margin: 0 0 18px; font-size: 15px; line-height: 1.6; color: var(--muted); }

.form { display: grid; gap: 14px; }

.field { display: grid; gap: 6px; }
.field__label { font-size: 13px; font-weight: 700; color: var(--muted); }

.field input {
  width: 100%;
  padding: 13px 15px;
  border-radius: var(--r-sm);
  border: 1px solid rgba(255, 255, 255, .14);
  background: rgba(0, 0, 0, .3);
  font-size: 16px;                 /* 16px stops iOS zoom-on-focus */
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.field input::placeholder { color: rgba(255, 255, 255, .3); }
.field input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 28%, transparent);
}
.field.is-invalid input { border-color: #ff6b6b; }

.field__err { display: none; font-size: 12px; font-style: normal; color: #ff8a8a; }
.field.is-invalid .field__err,
.field__err--block.is-shown { display: block; }

.consent {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--muted);
  cursor: pointer;
}
.consent input {
  flex: none;
  width: 20px;
  height: 20px;
  margin-top: 1px;
  accent-color: var(--brand);
}

.form__legal { margin: 2px 0 0; font-size: 11px; line-height: 1.5; color: rgba(255, 255, 255, .38); text-align: center; }

.reward__icon { font-size: 66px; line-height: 1; margin-bottom: 8px; animation: pop .5s var(--ease); }

.coupon {
  display: grid;
  gap: 6px;
  justify-items: center;
  margin: 4px 0 18px;
  padding: 16px;
  border-radius: var(--r-md);
  border: 2px dashed color-mix(in srgb, var(--brand-2) 55%, transparent);
  background: rgba(0, 0, 0, .28);
}
.coupon__label { font-size: 12px; color: var(--muted); }
.coupon__code {
  font-size: 26px;
  font-weight: 900;
  letter-spacing: .12em;
  color: var(--brand-2);
  direction: ltr;
}
.coupon__copy {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.coupon__copy:hover { color: var(--text); }

/* =========================================================================
   Powered-by footer — the PLG loop
   ========================================================================= */

.powered {
  position: relative;
  z-index: 1;
  padding: 10px 0 16px;
  text-align: center;
}
.powered a {
  font-size: 12px;
  color: rgba(255, 255, 255, .45);
  text-decoration: none;
  transition: color .15s var(--ease);
}
.powered a:hover { color: rgba(255, 255, 255, .85); }
.powered strong { font-weight: 700; }

/* =========================================================================
   Modal
   ========================================================================= */

.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(4, 4, 8, .72); backdrop-filter: blur(4px); }

.modal__box {
  position: relative;
  width: 100%;
  max-width: 420px;
  padding: 26px 24px;
  border-radius: var(--r-lg);
  background: #16161c;
  box-shadow: var(--shadow-2);
  animation: screen-in .3s var(--ease) both;
}
.modal__box h2 { margin: 0 0 14px; font-size: 22px; }
.modal__x {
  position: absolute;
  top: 10px;
  inset-inline-end: 14px;
  font-size: 26px;
  line-height: 1;
  color: var(--muted);
}

.howto { margin: 0 0 20px; padding-inline-start: 20px; display: grid; gap: 10px; font-size: 15px; line-height: 1.55; color: rgba(255, 255, 255, .85); }
.howto li::marker { color: var(--brand); font-weight: 900; }

/* =========================================================================
   Responsive
   ========================================================================= */

@media (min-width: 720px) {
  .stage { padding: 16px 24px 8px; }
  .board { aspect-ratio: 16 / 10; max-height: 56dvh; }
  .hud, .progress, .legend, .board { max-width: 760px; }
  .hud__value { font-size: 28px; }
  .topbar { padding: 12px 22px; }
  .topbar__msg { font-size: 15px; }
  .topbar__brand { font-size: 22px; }
}

@media (max-width: 380px) {
  .intro__actions .btn { width: 100%; }
  .legend__pill { font-size: 11px; padding: 4px 9px; }
}

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

/* Control hint under the legend — set per campaign from copy.controlHint. */
.hint {
  margin: 8px 0 0;
  width: 100%;
  max-width: 700px;
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}
.hint:empty { display: none; }

/* ---- Retention layer (js/progress.js, js/social.js) ----
   Every line is optional and hidden until a campaign's retention config fills
   it. Colours come from the brand variables like everything else. */
.loop { margin: 0 0 12px; font-size: 14px; font-weight: 600; line-height: 1.5; text-align: center; color: var(--muted); }
.loop[hidden] { display: none; }
.loop--best  { color: var(--brand-2); font-weight: 800; }
.loop--ghost {
  margin: 0 auto 14px;
  padding: 8px 14px;
  max-width: 460px;
  border: 1px dashed var(--brand-2);
  border-radius: 12px;
  color: var(--text);
}
.loop--scarcity { color: var(--brand-2); font-weight: 700; }
.loop--tier { font-size: 16px; font-weight: 800; color: var(--brand-2); }
.loop--share { margin: 14px 0 6px; }
.loop--share p { margin: 0 0 8px; }
