/* GameKit v1 — shared look for every static kids' game on this site.
   Bright-green PITCH theme (it REPLACES the old slate/orange MERSEN tokens);
   orange survives ONLY as the primary action / CTA colour.

   Two ways this file is used:
   1. A game that wants the full theme adds `gk-theme` (+ usually `grad-bg`) to
      <body>; that is the only place page-level look (background, legacy --brand
      etc.) is changed, so loading this file never restyles a page that did not
      opt in.
   2. Every component class is `gk-` prefixed and self-contained, so it is safe
      to drop any single component onto a page without the theme class.

   Load order in a game page: gamekit.css BEFORE the game's own css, so the game
   can still override. See ../_GAMES_CONTRACT.md §10. */

/* ---------- palette (the single source of truth) ---------- */
:root {
  --gk-green-900: #14532d;   /* deepest green — headings, header text */
  --gk-green-700: #1f7a3f;   /* secondary green */
  --gk-green: #2E9E4F;       /* correct / success */
  --gk-pitch: #59b25f;       /* bright pitch green (accents, gradients) */
  --gk-bg-top: #eaf8ee;
  --gk-bg-bottom: #d3efda;
  --gk-card: #fff;
  --gk-ink: #16291c;
  --gk-muted: #4b6b57;
  --gk-accent: #E84E0F;      /* orange — PRIMARY ACTION ONLY */
  --gk-gold: #FFD700;
  --gk-danger: #D2434D;
  --gk-radius: 18px;
  --gk-shadow: 0 6px 18px rgba(20,83,45,.16);
}

/* Opt-in page theme: aliases the legacy token names the existing games already
   use, so a game can adopt GameKit by adding one class. */
body.gk-theme {
  --brand: var(--gk-green-900);
  --brand-2: var(--gk-green-700);
  --accent: var(--gk-accent);
  --green: var(--gk-green);
  --gold: var(--gk-gold);
  --danger: var(--gk-danger);
  --bg: var(--gk-bg-top);
  --card: var(--gk-card);
  --ink: var(--gk-ink);
  --radius: var(--gk-radius);
  --shadow: var(--gk-shadow);
  background: linear-gradient(180deg, var(--gk-bg-top), var(--gk-bg-bottom));
  min-height: 100vh;
}

body.gk-theme.grad-bg {
  background: linear-gradient(180deg, var(--gk-bg-top), var(--gk-bg-bottom));
}

/* ---------- header: ONE row, never wraps ---------- */
.gk-header {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, .86);
  border-radius: var(--gk-radius);
  box-shadow: var(--gk-shadow);
}

.gk-back {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 6px;
  font-size: 16px;
  font-weight: 800;
  color: var(--gk-green-900);
  text-decoration: none;
  white-space: nowrap;
}
.gk-back:active { opacity: .6; }

.gk-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  text-align: center;
  font-size: 19px;
  font-weight: 800;
  color: var(--gk-green-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gk-sound {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  min-width: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: var(--gk-green-900);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--gk-shadow);
  -webkit-tap-highlight-color: transparent;
}
.gk-sound:active { transform: scale(.94); }
.gk-sound[aria-pressed="false"] {
  background: #fff;
  color: var(--gk-green-900);
  box-shadow: inset 0 0 0 2px var(--gk-green-900);
}

/* ---------- pills (score / progress / streak / found / best) ---------- */
.gk-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: center;
}
.gk-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--gk-card);
  border-radius: 999px;
  box-shadow: var(--gk-shadow);
  font-size: 15px;
  font-weight: 800;
  color: var(--gk-green-900);
  white-space: nowrap;
}
.gk-pill--progress { color: var(--gk-green-700); }
.gk-pill--found { color: var(--gk-green-700); }
.gk-pill--score { color: var(--gk-accent); }
.gk-pill--streak { background: #fff3e8; color: var(--gk-accent); }
.gk-pill--best { background: #fffbe6; color: #7a6000; }

/* ---------- progress bar (12px: clearly visible) ---------- */
.gk-progress {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: rgba(20, 83, 45, .14);
  box-shadow: inset 0 1px 2px rgba(20, 83, 45, .18);
  overflow: hidden;
}
.gk-progress-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gk-green), var(--gk-pitch));
  transition: width .35s ease;
}

/* ---------- answer marking: GREEN = right, RED = wrong. Always + a badge. ---------- */
.gk-correct,
.gk-reveal,
.gk-wrong { position: relative; }

.gk-correct,
.gk-reveal {
  border-color: var(--gk-green) !important;
  background-color: #eefaf1 !important;
}
.gk-wrong {
  border-color: var(--gk-danger) !important;
  background-color: #fdeef0 !important;
}

.gk-badge {
  position: absolute;
  top: -9px;
  right: -9px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--gk-green);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 2px 6px rgba(20, 83, 45, .3);
  z-index: 2;
  pointer-events: none;
}
.gk-wrong .gk-badge { background: var(--gk-danger); }

.gk-pulse { animation: gk-pulse .3s ease; }
.gk-shake { animation: gk-shake .32s ease; }

@keyframes gk-pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
@keyframes gk-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* ---------- verdict line ---------- */
.gk-verdict {
  border-radius: var(--gk-radius);
  padding: 14px 16px;
  text-align: center;
  font-size: 17px;
  font-weight: 800;
  box-shadow: var(--gk-shadow);
}
.gk-verdict--ok {
  background: #eefaf1;
  border: 2px solid var(--gk-green);
  color: var(--gk-green-900);
}
.gk-verdict--bad {
  background: #fdeef0;
  border: 2px solid var(--gk-danger);
  color: #7d2230;
}
.gk-verdict-line { margin: 0; font-size: 18px; font-weight: 800; }
.gk-why {
  margin: 6px 0 0;
  font-size: 16px;
  font-weight: 700;
  opacity: .92;
}
.gk-missed {
  margin: 4px 0 0;
  font-size: 16px;
  font-weight: 700;
  opacity: .92;
}

/* ---------- next button: the primary CTA (orange) ---------- */
.gk-next {
  display: block;
  width: 100%;
  min-height: 58px;
  padding: 12px 20px;
  border: none;
  border-radius: 14px;
  background: var(--gk-accent);
  color: #fff;
  font: inherit;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--gk-shadow);
  -webkit-tap-highlight-color: transparent;
}
.gk-next:active { transform: scale(.98); }
.gk-next[disabled] { opacity: .5; pointer-events: none; }

/* ---------- confetti ---------- */
.gk-confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  overflow: hidden;
}
.gk-confetti-piece {
  position: absolute;
  top: -20px;
  display: block;
  border-radius: 3px;
  animation: gk-fall linear forwards;
}
/* reduced-motion fallback: a few static flecks, no falling/rotating */
.gk-confetti-piece--still {
  animation: none;
  top: auto;
  opacity: .9;
}

@keyframes gk-fall {
  0% { transform: translateY(-30px) rotate(0); opacity: 1; }
  100% { transform: translateY(105vh) rotate(720deg); opacity: 0; }
}

/* ---------- accessibility: honour the OS reduced-motion setting ---------- */
@media (prefers-reduced-motion: reduce) {
  .gk-pulse,
  .gk-shake,
  .gk-confetti-piece { animation: none !important; }
  .gk-progress-fill { transition: none !important; }
  .gk-back:active,
  .gk-sound:active,
  .gk-next:active { transform: none !important; }
}

/* ==================================================================
   §11 — the shared REWARD layer: mascot + speech bubble + sticker pop +
   sticker chips + the end-of-run reward card. Drawn by
   js/gamekit-stickers.js (window.Stickers / window.Mascot); mirrors the
   reward look of football/css/style.css in the green pitch palette.
   ================================================================== */

/* ---------- mascot: a small companion chip the game mounts itself ---------- */
.gk-mascot {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--gk-card);
  border: 2px solid var(--gk-green);
  border-radius: 999px;
  box-shadow: var(--gk-shadow);
  max-width: 100%;
}
.gk-mascot-emoji {
  display: block;
  font-size: 30px;
  line-height: 1;
  transition: transform .25s ease;
}
.gk-mascot-name {
  font-size: 14px;
  font-weight: 800;
  color: var(--gk-green-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* moods: the emoji changes pose — never colour alone, the bubble says why */
.gk-mascot--cheer .gk-mascot-emoji { transform: scale(1.14) rotate(-8deg); }
.gk-mascot--think .gk-mascot-emoji { transform: rotate(10deg); }
.gk-mascot--oops  .gk-mascot-emoji { transform: rotate(-14deg) scale(.94); }
.gk-mascot--wow   .gk-mascot-emoji { transform: scale(1.24); }
.gk-mascot--wave  .gk-mascot-emoji { transform: rotate(12deg); }
.gk-mascot--bounce { animation: gk-mascot-bounce .55s ease; }

@keyframes gk-mascot-bounce {
  0%   { transform: translateY(0); }
  35%  { transform: translateY(-8px); }
  70%  { transform: translateY(2px); }
  100% { transform: translateY(0); }
}

/* ---------- speech bubble (auto-hides after 2.5s) ---------- */
/* The chip is mounted in the TOP area of a page in every game that uses it —
   the pills / strip / stage-head row right under the header (border-chain,
   flag-detective, var-ref, world-cup-history) — except shape-shifter, which
   pins it to the bottom-right corner and overrides this anchor in its own css.
   The bubble used to open UPWARD (bottom:100%), which from a top-area host put
   it straight over the header's own controls: measured on var-ref at 390x844,
   the greet line sat at y27-65 while the sound button is y18-62, i.e. the
   bubble covered the mute toggle (the reporter saw it on the shootout page
   too). The shared default now opens DOWNWARD — below the host — so a bubble
   can never reach above the header's bottom edge no matter where a game mounts
   the chip, and it is width-clamped to the phone viewport so a long line can
   never run off-screen. Bumping ?v= on this file invalidates the cached copy. */
.gk-bubble {
  display: none;
  position: absolute;
  left: 50%;
  top: calc(100% + 10px);      /* downward: under the chip, clear of the header */
  bottom: auto;
  transform: translateX(-50%);
  z-index: 5;
  width: max-content;          /* hug the line, then wrap at the clamp below */
  max-width: min(260px, calc(100vw - 24px));
  overflow-wrap: normal;       /* wrap at spaces, never mid-word */
  word-break: normal;
  pointer-events: none;        /* a transient bubble can never swallow a tap */
  padding: 8px 12px;
  background: #fff;
  color: var(--gk-green-900);
  border: 2px solid var(--gk-green);
  border-radius: 14px;
  box-shadow: var(--gk-shadow);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
}
/* the tail now points UP at the chip (the bubble hangs below it) */
.gk-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  top: auto;
  bottom: 100%;
  width: 0;
  height: 0;
  margin-left: -7px;
  border: 7px solid transparent;
  border-bottom-color: var(--gk-green);
}
.gk-bubble--show { display: block; animation: gk-bubble-in .2s ease; }

@keyframes gk-bubble-in {
  0%   { opacity: 0; transform: translateX(-50%) translateY(4px) scale(.96); }
  100% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

/* ---------- the sticker pop (pack opening: common / rare / shiny) ---------- */
.gk-sticker-pop {
  width: 150px;
  margin: 14px auto 8px;
  padding: 14px;
  background: #fff;
  border: 3px solid var(--gk-green);
  border-radius: 16px;
  box-shadow: var(--gk-shadow);
  text-align: center;
  animation: gk-sticker-pop-in .4s cubic-bezier(.2,.9,.3,1.3) 1;
}
.gk-sticker-pop-emoji { display: block; font-size: 54px; line-height: 1; }
.gk-sticker-pop-label { margin-top: 6px; font-size: 18px; font-weight: 800; color: var(--gk-green-900); }
.gk-sticker-pop-rarity {
  font-size: 14px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--gk-green-700);
}
.gk-sticker-pop--common { border-color: var(--gk-green); }
.gk-sticker-pop--rare { border-color: #b06ab3; }
.gk-sticker-pop--shiny { border-color: var(--gk-gold); animation: gk-sticker-pop-in .4s cubic-bezier(.2,.9,.3,1.3) 1, gk-glow 1.4s ease-in-out infinite; }

@keyframes gk-sticker-pop-in {
  0%   { transform: scale(.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes gk-glow {
  0%, 100% { box-shadow: 0 0 6px var(--gk-gold); }
  50%      { box-shadow: 0 0 20px var(--gk-gold); }
}

/* ---------- sticker chips + the album grid ---------- */
.gk-sticker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 10px;
}
.gk-sticker {
  min-height: 48px;
  min-width: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 6px;
  background: #fff;
  border: 2px solid rgba(20, 83, 45, .16);
  border-radius: 12px;
  box-shadow: var(--gk-shadow);
}
.gk-sticker-emoji { font-size: 30px; line-height: 1; }
.gk-sticker-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--gk-green-900);
  text-align: center;
  overflow-wrap: anywhere;
}
.gk-sticker--rare { border-color: #b06ab3; }
.gk-sticker--shiny { border-color: var(--gk-gold); animation: gk-glow 1.6s ease-in-out infinite; }
/* a sticker you have not collected yet: greyed out, shows "?" not an emoji */
.gk-sticker--locked {
  background: #eef3ef;
  border-color: #cfe0d4;
  box-shadow: none;
  filter: grayscale(1);
  opacity: .72;
  animation: none;
}
.gk-sticker--locked .gk-sticker-emoji { color: #7f9b8a; font-weight: 900; }
.gk-sticker--locked .gk-sticker-label { color: #7f9b8a; }

/* ---------- the end-of-run reward card ---------- */
.gk-reward {
  background: var(--gk-card);
  border: 2px solid var(--gk-green);
  border-radius: var(--gk-radius);
  padding: 14px;
  box-shadow: var(--gk-shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.gk-reward-count {
  font-size: 16px;
  font-weight: 800;
  color: var(--gk-green-900);
  text-align: center;
}
.gk-reward-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.gk-reward-chips .gk-sticker { min-width: 84px; }
.gk-reward-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
/* the ghost "Play Hub" link (opts.onHome) */
.gk-reward-home {
  display: block;
  min-height: 48px;
  line-height: 48px;
  text-align: center;
  border: 2px solid var(--gk-green);
  border-radius: 14px;
  color: var(--gk-green-900);
  font-size: 16px;
  font-weight: 800;
  text-decoration: none;
  background: #fff;
}

@media (prefers-reduced-motion: reduce) {
  .gk-mascot--bounce,
  .gk-sticker-pop,
  .gk-sticker-pop--shiny,
  .gk-sticker--shiny,
  .gk-bubble--show { animation: none !important; }
  .gk-mascot-emoji { transition: none !important; }
}
