/* Gagner Play: design tokens and shared components.
   Brand colours come from the Gagner Play brand sheet; use the tokens, not hex values. */

@font-face {
  font-family: "Bricolage Grotesque";
  src: url("../fonts/bricolage-grotesque-latin.woff2") format("woff2");
  font-weight: 200 800;
  font-stretch: 75% 100%;
  font-display: swap;
}

:root {
  /* Brand palette */
  --violet: #3b1fa8;      /* Gagner Violet: primary */
  --violet-700: #2a1180;  /* deep end of the icon gradient */
  --electric: #5b3bf5;    /* icon highlight, splash */
  --volt: #c6f432;        /* "the play": main calls to action */
  --midnight: #14083f;    /* ink & dark grounds */
  --mist: #f5f3ff;        /* light ground */

  --brand: var(--violet);
  --brand-600: var(--violet-700);
  --brand-100: #eae5ff;
  --accent: var(--volt);
  --on-accent: var(--midnight);
  --link: var(--violet);

  /* Answer colors: all pass WCAG AA for large bold white text */
  --a0: #c8102e; /* red / triangle */
  --a1: #1257b8; /* blue / diamond */
  --a2: #a87400; /* gold / circle */
  --a3: #1e7a12; /* green / square */

  --ok: #1e7a12;
  --bad: #c8102e;

  --bg: var(--mist);
  --surface: #ffffff;
  --surface-2: #efebff;
  --text: var(--midnight);
  --text-muted: #5a5485;
  --border: #ddd6fa;
  --focus: var(--electric);
  --shadow: 0 1px 2px rgb(20 8 63 / .06), 0 4px 16px rgb(20 8 63 / .08);

  --radius: 12px;
  --radius-sm: 8px;
  --gutter: clamp(16px, 4vw, 32px);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--midnight);
    --surface: #1e1252;
    --surface-2: #291a69;
    --text: var(--mist);
    --text-muted: #b8afe6;
    --border: #3a2a84;
    --brand: var(--electric);
    --brand-100: #2d1d74;
    --link: #b9a9ff;
    --focus: var(--volt);
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 4px 16px rgb(0 0 0 / .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: var(--midnight); --surface: #1e1252; --surface-2: #291a69; --text: var(--mist);
  --text-muted: #b8afe6; --border: #3a2a84; --brand: var(--electric); --brand-100: #2d1d74;
  --link: #b9a9ff; --focus: var(--volt); color-scheme: dark;
}

/* ───── Reset ───── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
img, svg { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 800; letter-spacing: -.02em; line-height: 1.15; margin: 0 0 .5em; }
p { margin: 0 0 1em; }
a { color: var(--link); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 1000;
  background: var(--surface); color: var(--text); padding: 10px 14px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow); text-decoration: none; font-weight: 600;
}
.skip-link:focus { top: calc(8px + var(--safe-top)); }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
[hidden] { display: none !important; }

/* ───── Logo lockup: icon + "gagner" + "play" pill (logo_html) ───── */
.logo {
  --logo-word: var(--text); --logo-pill: var(--violet); --logo-pill-text: var(--mist);
  display: inline-flex; align-items: center; gap: .32em; font-size: 1.25rem; line-height: 1;
  font-family: var(--font-display); font-weight: 800; color: var(--logo-word); text-decoration: none; white-space: nowrap;
  font-variation-settings: "opsz" 96; /* the chunky display cut used in the brand lockups */
}
.logo__mark { width: 1.65em; height: 1.65em; flex: none; margin-right: .1em; }
.logo__word { font-size: 1.12em; letter-spacing: -.045em; padding-bottom: .12em; }
.logo__pill {
  font-size: .8em; letter-spacing: -.03em; padding: .1em .42em .2em; border-radius: 999px;
  background: var(--logo-pill); color: var(--logo-pill-text);
}
/* On violet / game backgrounds (the splash lockup) */
.logo--light { --logo-word: #fff; --logo-pill: var(--volt); --logo-pill-text: var(--midnight); }
/* On dark host pages (the Midnight lockup) */
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .logo:not(.logo--light) { --logo-pill: var(--mist); --logo-pill-text: var(--midnight); } }
:root[data-theme="dark"] .logo:not(.logo--light) { --logo-pill: var(--mist); --logo-pill-text: var(--midnight); }

/* ───── Launch splash (installed app, first page of a launch) ─────
   Same Electric as the manifest background_color, so the system splash
   hands over to this one seamlessly; it then fades out on its own. */
.splash { display: none; }
html.is-launching .splash {
  position: fixed; inset: 0; z-index: 3000; display: grid; place-content: center; justify-items: center; gap: 28px;
  background: var(--electric); pointer-events: none;
  animation: splash-out .4s ease 1.3s forwards;
}
.splash__icon { width: min(36vw, 190px); height: auto; border-radius: 22.6%; box-shadow: 0 24px 60px rgb(20 8 63 / .35); animation: splash-pop .6s cubic-bezier(.2, 1.4, .4, 1) both; }
.splash__logo { font-size: clamp(2.2rem, 10vw, 3.2rem); animation: splash-up .5s ease .2s both; }
@keyframes splash-out { to { opacity: 0; visibility: hidden; } }
@keyframes splash-pop { from { transform: scale(.6); opacity: 0; } }
@keyframes splash-up { from { transform: translateY(14px); opacity: 0; } }

/* ───── Buttons ───── */
.btn {
  --btn-bg: var(--brand); --btn-fg: #fff; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  min-height: 48px; padding: .6em 1.25em; border: 2px solid transparent; border-radius: var(--radius-sm);
  background: var(--btn-bg); color: var(--btn-fg); font-weight: 700; text-decoration: none; cursor: pointer;
  transition: transform .08s ease, filter .15s ease, background .15s ease;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; filter: none; transform: none; }
.btn--accent { --btn-bg: var(--accent); --btn-fg: var(--on-accent); box-shadow: inset 0 -3px 0 rgb(20 8 63 / .14); }
.btn--danger { --btn-bg: var(--bad); }
.btn--ghost { --btn-bg: transparent; --btn-fg: var(--text); border-color: var(--border); }
.btn--ghost:hover { background: var(--surface-2); filter: none; }
.btn--light { --btn-bg: #fff; --btn-fg: var(--brand); }
.btn--sm { min-height: 40px; padding: .35em .9em; font-size: .9rem; }
.btn--lg { min-height: 60px; padding: .75em 1.75em; font-size: 1.2rem; }
.btn--block { display: flex; width: 100%; white-space: normal; }
.btn--icon { min-width: 48px; padding: .5em; }

/* ───── Forms ───── */
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label, .label { font-weight: 600; font-size: .95rem; }
.hint { color: var(--text-muted); font-size: .875rem; }
.input, .select, .textarea {
  width: 100%; min-height: 48px; padding: .6em .85em;
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius-sm);
  transition: border-color .15s ease;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px rgb(91 59 245 / .25); }
.textarea { resize: vertical; min-height: 96px; }
.input[aria-invalid="true"] { border-color: var(--bad); }
.form-error {
  background: #fde8ec; color: #8c0b20; border: 1px solid #f5b5c1; border-radius: var(--radius-sm);
  padding: .65em .9em; margin-bottom: 16px; font-weight: 600;
}
.switch { display: inline-flex; align-items: center; gap: .6em; cursor: pointer; font-weight: 600; }
.switch input { width: 1.4em; height: 1.4em; accent-color: var(--brand); }

/* ───── Cards / layout ───── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: clamp(16px, 3vw, 28px); }
.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 calc(var(--gutter) + var(--safe-right)) 0 calc(var(--gutter) + var(--safe-left)); }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.muted { color: var(--text-muted); }

/* ───── Top bar (host pages) ───── */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50; padding-top: var(--safe-top); }
.topbar__inner { display: flex; align-items: center; gap: 16px; min-height: 64px; max-width: 1120px; margin: 0 auto; padding: 0 var(--gutter); flex-wrap: wrap; }
.topbar__brand { text-decoration: none; }
.topbar__nav { display: flex; gap: 4px; }
.topbar__nav a { padding: .5em .8em; border-radius: var(--radius-sm); color: var(--text-muted); font-weight: 600; text-decoration: none; }
.topbar__nav a:hover { background: var(--surface-2); color: var(--text); }
.topbar__nav a[aria-current="page"] { color: var(--brand); background: var(--brand-100); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .topbar__nav a[aria-current="page"] { color: #fff; } }
:root[data-theme="dark"] .topbar__nav a[aria-current="page"] { color: #fff; }
.topbar__user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.topbar__install { margin-left: auto; }
.topbar__install:not([hidden]) + .topbar__user { margin-left: 0; }
.topbar__name { color: var(--text-muted); font-size: .9rem; max-width: 16ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 560px) {
  .topbar__inner { gap: 8px; padding-block: 8px; }
  .topbar__nav { order: 3; width: 100%; }
  .topbar__nav a { flex: 1; text-align: center; }
  .topbar__name { display: none; }
}

/* ───── Toasts ───── */
.toasts { position: fixed; left: 50%; bottom: calc(16px + var(--safe-bottom)); transform: translateX(-50%); z-index: 2000; display: grid; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--midnight); color: #fff; padding: .75em 1em; border-radius: var(--radius-sm); box-shadow: 0 6px 24px rgb(0 0 0 / .3); font-weight: 600; animation: toast-in .2s ease; pointer-events: auto; }
.toast--error { background: #8c0b20; }
.toast--ok { background: #145c0b; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ───── Dialog ───── */
dialog.modal { border: 0; border-radius: var(--radius); padding: 0; width: min(92vw, 480px); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / .35); }
dialog.modal::backdrop { background: rgb(20 8 63 / .6); }
.modal__body { padding: 24px; }
.modal__actions { display: flex; gap: 10px; justify-content: flex-end; padding: 0 24px 24px; flex-wrap: wrap; }

/* ───── Notification banners (notify.js) ───── */
.banners {
  position: fixed; left: 50%; top: calc(12px + var(--safe-top)); transform: translateX(-50%); z-index: 2100;
  display: grid; gap: 8px; width: min(calc(100vw - 32px), 440px); pointer-events: none;
}
.banner {
  display: flex; align-items: center; gap: 12px; padding: 12px 8px 12px 14px; border-radius: 16px;
  color: #fff; background: rgb(20 8 63 / .92); border: 1px solid rgb(255 255 255 / .14);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  box-shadow: 0 12px 40px rgb(0 0 0 / .35); pointer-events: auto;
  animation: banner-in .35s cubic-bezier(.2, 1.3, .4, 1);
}
.banner--good { background: var(--volt); color: var(--midnight); border-color: transparent; }
.banner--good .banner__action { background: var(--midnight); color: var(--volt); }
.banner--bad { background: rgb(125 10 28 / .94); }
.banner--out { opacity: 0; transform: translateY(-8px); transition: opacity .2s, transform .2s; }
.banner__icon { display: grid; place-items: center; flex: none; }
.banner__icon svg.icon { width: 1.5rem; height: 1.5rem; }
.banner__text { display: grid; gap: 2px; flex: 1; min-width: 0; }
.banner__title { font-weight: 800; line-height: 1.25; }
.banner__body { font-size: .9rem; opacity: .85; overflow-wrap: anywhere; }
.banner__action {
  flex: none; min-height: 36px; padding: 0 14px; border: 0; border-radius: 999px; cursor: pointer;
  font: inherit; font-weight: 700; color: var(--on-accent); background: var(--accent);
}
.banner__close {
  flex: none; width: 36px; height: 36px; border: 0; border-radius: 50%; cursor: pointer;
  font-size: 1.4rem; line-height: 1; color: inherit; background: transparent; opacity: .7;
}
.banner__close:hover { opacity: 1; background: rgb(127 127 127 / .15); }
@keyframes banner-in { from { opacity: 0; transform: translateY(-16px) scale(.97); } }

/* ───── Host messages (shout.js) ─────
   A warm card that blooms in near the top, holds while a thin bar runs down,
   then drifts away. Stays light on the dark game screens so it reads at a glance. */
.shout {
  position: fixed; z-index: 2050; left: 50%; top: calc(64px + var(--safe-top)); translate: -50% 0;
  width: min(calc(100vw - 32px), 460px); padding: 14px 18px 18px; border-radius: 20px; overflow: hidden;
  color: var(--midnight); background: linear-gradient(150deg, #fff 30%, var(--mist));
  box-shadow: 0 18px 50px rgb(20 8 63 / .45), 0 0 60px rgb(91 59 245 / .35);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  animation: shout-in .75s cubic-bezier(.2, 1.15, .35, 1) both;
}
.shout__head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 4px;
  font-size: .78rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: var(--violet);
}
.shout__icon { display: inline-grid; font-size: 1.35em; letter-spacing: 0; animation: shout-wave 1.2s ease .5s 2; transform-origin: 70% 80%; }
.shout__body { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: 1.25rem; line-height: 1.3; letter-spacing: -.01em; overflow-wrap: anywhere; }
.shout__tag { color: var(--violet); background: #eae5ff; border-radius: 6px; padding: 0 .22em; white-space: nowrap; }
.shout__tag--me { color: var(--midnight); background: var(--volt); }
.shout__time {
  position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: var(--electric);
  transform-origin: left; animation: shout-time linear forwards;
}
/* Tagged player: Volt ring and glow */
.shout--me { background: linear-gradient(150deg, #fff 30%, #f3ffd0); box-shadow: 0 0 0 3px var(--volt), 0 18px 50px rgb(20 8 63 / .45), 0 0 70px rgb(198 244 50 / .45); }
.shout--me .shout__head { color: var(--midnight); }
.shout--me .shout__time { background: #9fcc16; }
/* Presenter / big screen */
.shout--big { top: calc(84px + var(--safe-top)); width: min(calc(100vw - 48px), 920px); padding: 20px 30px 26px; border-radius: 26px; }
.shout--big .shout__head { font-size: clamp(.85rem, 1.2vw, 1.1rem); }
.shout--big .shout__body { font-size: clamp(1.5rem, 3vw, 2.8rem); }
.shout--big .shout__time { height: 6px; }
.shout--out { animation: shout-out .45s ease forwards; }
@keyframes shout-in {
  0% { opacity: 0; transform: translateY(-22px) scale(.9); filter: blur(8px); }
  55% { opacity: 1; filter: blur(0); }
  100% { opacity: 1; transform: none; }
}
@keyframes shout-out { to { opacity: 0; transform: translateY(-12px) scale(.96); filter: blur(4px); } }
@keyframes shout-time { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@keyframes shout-wave { 25% { transform: rotate(14deg); } 75% { transform: rotate(-10deg); } }

/* "Turn on notifications" card (permissionCard) */
.notif-card {
  display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; align-items: center; text-align: left;
  width: min(100%, 380px); margin: 8px auto 0; padding: 14px 16px; border-radius: 16px;
  background: rgb(255 255 255 / .1); border: 1px solid rgb(255 255 255 / .18);
}
.notif-card__icon { grid-row: span 2; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: rgb(255 255 255 / .14); }
.notif-card__icon svg.icon { width: 1.4rem; height: 1.4rem; }
.notif-card__text { margin: 0; font-size: .95rem; }
.notif-card__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.notif-card .btn { margin: 0; }

/* ───── Install app ───── */
[data-install][hidden], .is-standalone [data-install] { display: none !important; }
.install-help__head { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.install-help__head img { border-radius: 14px; flex: none; }
.install-help__head h2 { margin: 0 0 2px; font-size: 1.2rem; }
.install-help__head p { margin: 0; font-size: .92rem; }
.install-help__steps { margin: 0; padding-left: 1.3em; display: grid; gap: 10px; }
.install-help__share { display: inline-grid; place-items: center; width: 1.6em; height: 1.6em; vertical-align: -.35em; border-radius: 6px; background: var(--surface-2); }
.install-help__share svg { width: 1.1em; height: 1.1em; fill: none; stroke: #0a84ff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ───── Icons (icon() in PHP/JS: Lucide sprite, outline, takes the text colour) ───── */
svg.icon {
  display: inline-block; width: 1.2em; height: 1.2em; flex: none; vertical-align: -.22em;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.btn > svg.icon { margin-inline: -.1em; }
.btn--icon > svg.icon { width: 1.25em; height: 1.25em; }
/* Lucide check as a CSS mask, for ticks drawn by CSS (::before / ::after) */
:root { --icon-check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E"); }

/* ───── Answer shapes ───── */
.shape { width: 1.4em; height: 1.4em; flex: none; fill: currentColor; }

/* ───── Motion preferences ───── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
