/* Centralized Gamification — site-wide HUD, toasts, juice. Theme-agnostic via CSS vars. */
:root {
  --game-bg: rgba(15,18,24,0.92);
  --game-fg: #f4f1ea;
  --game-muted: #9aa1ad;
  --game-accent: #ffb547;
  --game-accent-2: #ff6b6b;
  --game-good: #5dd39e;
  --game-blue: #5aa9ff;
  --game-radius: 14px;
  --game-shadow: 0 12px 40px -12px rgba(0,0,0,0.55), 0 2px 8px rgba(0,0,0,0.2);
}

#game-hud {
  position: fixed;
  top: 12px; right: 12px;
  z-index: 99998;
  display: flex; flex-direction: column; gap: 8px;
  font: 500 13px/1.3 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--game-fg);
  user-select: none;
  max-width: 240px;
}
@media (max-width: 640px) {
  #game-hud {
    top: 6px; right: 6px;
    max-width: 150px;
    transform: scale(0.86);
    transform-origin: top right;
    opacity: 0.92;
  }
  #game-hud .gh-card { padding: 6px 8px; border-radius: 10px; }
  #game-hud .gh-quest { padding: 4px 8px; font-size: 11px; }
  #game-hud .gh-badges { display: none; }
  /* Évite collision avec bottom nav React (h-16 = 64px) */
  #game-toasts { bottom: 84px; }
}
#game-hud .gh-card {
  position: relative;
  background: var(--game-bg);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--game-radius);
  padding: 10px 12px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--game-shadow);
  cursor: pointer;
  transition: transform .18s ease, border-color .18s ease;
}
#game-hud .gh-card:hover { transform: translateY(-1px); border-color: rgba(255,255,255,0.18); }
#game-hud .gh-row { display: flex; align-items: center; gap: 8px; }
#game-hud .gh-lvl {
  background: linear-gradient(135deg, var(--game-accent), var(--game-accent-2));
  color: #1a1410; font-weight: 800;
  border-radius: 8px; padding: 2px 8px; font-size: 12px; letter-spacing: .02em;
}
#game-hud .gh-streak { display: flex; align-items: center; gap: 4px; font-weight: 700; color: var(--game-accent); }
#game-hud .gh-streak .gh-flame { font-size: 14px; filter: drop-shadow(0 0 6px rgba(255,181,71,0.6)); }
#game-hud .gh-bar { margin-top: 8px; height: 6px; background: rgba(255,255,255,0.08); border-radius: 999px; overflow: hidden; }
#game-hud .gh-bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--game-blue), var(--game-good));
  transition: width .5s cubic-bezier(.2,.7,.2,1);
}
#game-hud .gh-xp { font-size: 11px; color: var(--game-muted); margin-top: 4px; display: flex; justify-content: space-between; }
#game-hud .gh-quest {
  display: flex; align-items: center; gap: 6px; font-size: 12px;
  padding: 6px 10px; background: rgba(90,169,255,0.12);
  border: 1px solid rgba(90,169,255,0.25);
  border-radius: 999px; color: var(--game-blue); cursor: pointer;
}
#game-hud .gh-quest .gh-q-count { font-weight: 700; color: var(--game-fg); }
#game-hud .gh-mute {
  position: absolute; top: 8px; right: 8px;
  background: rgba(255,255,255,0.06); border: none; color: var(--game-fg);
  width: 24px; height: 24px; border-radius: 50%; font-size: 11px;
  cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0;
}
#game-hud .gh-badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
#game-hud .gh-badge { font-size: 10px; padding: 2px 6px; background: rgba(255,255,255,0.08); border-radius: 6px; }

/* Toasts */
#game-toasts {
  position: fixed; bottom: 16px; left: 50%;
  transform: translateX(-50%); z-index: 99999;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.game-toast {
  background: var(--game-bg); color: var(--game-fg);
  padding: 10px 16px; border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.12);
  font: 500 13px/1.3 system-ui, sans-serif;
  box-shadow: var(--game-shadow);
  display: flex; align-items: center; gap: 10px;
  animation: gameToastIn .35s cubic-bezier(.2,.7,.2,1);
  pointer-events: auto; max-width: min(440px, 90vw);
}
.game-toast.kind-good { border-color: rgba(93,211,158,0.45); }
.game-toast.kind-epic {
  border-color: var(--game-accent);
  background: linear-gradient(135deg, rgba(255,181,71,0.18), rgba(255,107,107,0.18)), var(--game-bg);
}
.game-toast .gt-icon { font-size: 18px; }
.game-toast .gt-title { font-weight: 700; }
.game-toast .gt-body { color: var(--game-muted); font-size: 12px; }
.game-toast.leaving { animation: gameToastOut .28s ease forwards; }

@keyframes gameToastIn {
  from { opacity: 0; transform: translateY(20px) scale(.9); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes gameToastOut { to { opacity: 0; transform: translateY(20px) scale(.95); } }

/* Level-up overlay */
#game-levelup {
  position: fixed; inset: 0; z-index: 99997;
  display: none; align-items: center; justify-content: center;
  background: radial-gradient(circle at center, rgba(0,0,0,0.55), rgba(0,0,0,0.85));
  pointer-events: none;
  animation: gameOverlayIn .4s ease;
}
#game-levelup.show { display: flex; }
#game-levelup .gl-card {
  background: linear-gradient(135deg, #1a1410, #2a1a08);
  color: #fff; padding: 32px 48px; border-radius: 20px;
  border: 2px solid var(--game-accent);
  text-align: center;
  box-shadow: 0 0 80px rgba(255,181,71,0.4);
  animation: gameLevelPop .6s cubic-bezier(.2,.9,.3,1.4);
}
#game-levelup .gl-title {
  font-size: 14px; letter-spacing: .3em;
  color: var(--game-accent); text-transform: uppercase; font-weight: 700;
}
#game-levelup .gl-num {
  font-size: 72px; font-weight: 900; margin: 8px 0;
  background: linear-gradient(135deg, var(--game-accent), var(--game-accent-2));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  font-family: "Cinzel", "Fraunces", Georgia, serif;
}
#game-levelup .gl-sub { color: var(--game-muted); font-size: 13px; }

@keyframes gameOverlayIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes gameLevelPop {
  0%   { transform: scale(.5) rotate(-8deg); opacity: 0; }
  60%  { transform: scale(1.08) rotate(2deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* Confetti canvas */
#game-confetti { position: fixed; inset: 0; z-index: 99996; pointer-events: none; }

/* Floating XP +N */
.game-xp-float {
  position: fixed; z-index: 99995; pointer-events: none;
  font: 700 14px/1 system-ui, sans-serif;
  color: var(--game-good);
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
  animation: gameXpFloat 1s ease-out forwards;
}
@keyframes gameXpFloat {
  0%   { opacity: 0; transform: translateY(0) scale(.8); }
  20%  { opacity: 1; transform: translateY(-10px) scale(1.1); }
  100% { opacity: 0; transform: translateY(-60px) scale(.9); }
}

/* Hold-to-charge ring */
[data-game-hold] { position: relative; }
.game-hold-ring {
  position: absolute; inset: 0; pointer-events: none;
  border-radius: inherit;
  background: conic-gradient(var(--game-accent) calc(var(--p, 0) * 1%), transparent 0);
  opacity: .35; transition: opacity .2s;
}

/* Drag-to-claim coin */
.game-coin {
  position: fixed; z-index: 99994;
  width: 56px; height: 56px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff2c2, var(--game-accent) 60%, #b07a14);
  border: 2px solid #fff; cursor: grab;
  box-shadow: 0 6px 20px rgba(255,181,71,0.5), inset 0 -4px 8px rgba(0,0,0,0.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; color: #6b3a00; font-weight: 900;
  user-select: none; touch-action: none;
  animation: gameCoinPulse 1.5s ease-in-out infinite;
}
.game-coin:active { cursor: grabbing; animation: none; }
@keyframes gameCoinPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }

/* Idle nudge */
#game-nudge {
  position: fixed; bottom: 16px; left: 16px; z-index: 99993;
  background: var(--game-bg); color: var(--game-fg);
  padding: 10px 14px 10px 50px; border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: var(--game-shadow);
  font: 500 13px/1.3 system-ui, sans-serif;
  display: none; align-items: center; gap: 8px; cursor: pointer;
  animation: gameNudgeIn .4s cubic-bezier(.2,.7,.2,1);
}
#game-nudge.show { display: flex; }
#game-nudge::before {
  content: "🧙";
  position: absolute; left: 6px; top: 50%; transform: translateY(-50%);
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--game-accent), var(--game-accent-2));
  display: flex; align-items: center; justify-content: center; font-size: 18px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
@keyframes gameNudgeIn {
  from { opacity: 0; transform: translateX(-20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* Quest log modal */
#game-modal {
  position: fixed; inset: 0; z-index: 99999;
  background: rgba(0,0,0,0.6);
  display: none; align-items: center; justify-content: center;
  padding: 16px;
  animation: gameOverlayIn .25s ease;
}
#game-modal.show { display: flex; }
#game-modal .gm-card {
  background: var(--game-bg); color: var(--game-fg);
  border-radius: 16px; border: 1px solid rgba(255,255,255,0.12);
  padding: 24px; max-width: 480px; width: 100%;
  max-height: 85vh; overflow-y: auto;
  box-shadow: var(--game-shadow);
}
#game-modal h2 { margin: 0 0 16px; font-family: "Cinzel", serif; font-size: 22px; }
#game-modal .gm-quest {
  display: flex; align-items: center; gap: 12px;
  padding: 10px; border-radius: 10px;
  background: rgba(255,255,255,0.04);
  margin-bottom: 8px;
}
#game-modal .gm-quest.done { background: rgba(93,211,158,0.12); border-left: 3px solid var(--game-good); }
#game-modal .gm-quest .gm-q-icon { font-size: 22px; }
#game-modal .gm-quest .gm-q-meta { color: var(--game-muted); font-size: 11px; }
#game-modal button.gm-close {
  background: rgba(255,255,255,0.08); border: none; color: var(--game-fg);
  padding: 8px 16px; border-radius: 8px; cursor: pointer;
  margin-top: 12px; width: 100%;
}
#game-modal button.gm-close:hover { background: rgba(255,255,255,0.14); }

/* Signature pad */
#game-sigpad-wrap {
  background: rgba(255,255,255,0.04);
  border: 1px dashed rgba(255,255,255,0.2);
  border-radius: 10px;
  padding: 8px;
  margin: 8px 0;
}
#game-sigpad {
  display: block; width: 100%; height: 140px;
  background: rgba(255,255,255,0.06);
  border-radius: 8px; cursor: crosshair;
  touch-action: none;
}

/* Shake / pulse helpers */
@keyframes gameShake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.game-shake { animation: gameShake .4s ease; }

@keyframes gamePulse {
  0%   { box-shadow: 0 0 0 0 rgba(93,211,158,0.6); }
  70%  { box-shadow: 0 0 0 12px rgba(93,211,158,0); }
  100% { box-shadow: 0 0 0 0 rgba(93,211,158,0); }
}
.game-pulse { animation: gamePulse .9s ease-out; }

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .game-toast, #game-levelup, .game-coin, .game-xp-float,
  #game-nudge, #game-modal, .game-shake, .game-pulse,
  #game-hud .gh-card, #game-hud .gh-bar-fill {
    animation: none !important;
    transition: none !important;
  }
}

/* ===== v2 additions ===== */
#game-hud .gh-page {
  position: absolute; top: 8px; right: 38px;
  background: rgba(255,255,255,0.06); color: var(--game-fg);
  width: 24px; height: 24px; border-radius: 50%; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  text-decoration: none; font-weight: 700;
}
#game-hud .gh-page:hover { background: rgba(255,255,255,0.14); }

/* Tabs */
#game-modal .gm-tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid rgba(255,255,255,0.08); }
#game-modal .gm-tab {
  flex: 1; background: transparent; border: none; color: var(--game-muted);
  padding: 8px 4px; font: 600 12px/1.2 system-ui, sans-serif; cursor: pointer;
  border-bottom: 2px solid transparent; transition: color .18s, border-color .18s;
}
#game-modal .gm-tab:hover { color: var(--game-fg); }
#game-modal .gm-tab.active { color: var(--game-accent); border-bottom-color: var(--game-accent); }
#game-modal .gm-link { margin-top: 12px; text-align: center; font-size: 12px; }
#game-modal .gm-link a { color: var(--game-blue); text-decoration: none; }

/* Badge grid */
.gm-badge-grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}
.gm-badge-card {
  position: relative;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px; padding: 12px 10px 10px;
  text-align: center; transition: transform .18s, border-color .18s;
}
.gm-badge-card.locked { filter: grayscale(1) opacity(.55); }
.gm-badge-card.owned:hover { transform: translateY(-2px); border-color: var(--game-accent); }
.gm-badge-card .gm-bb-emoji { font-size: 32px; margin-bottom: 4px; filter: drop-shadow(0 2px 6px rgba(0,0,0,0.4)); }
.gm-badge-card .gm-bb-name { font-weight: 700; font-size: 13px; margin-bottom: 2px; }
.gm-badge-card .gm-bb-rarity {
  display: inline-block; font-size: 9px; text-transform: uppercase; letter-spacing: .12em;
  padding: 2px 6px; border-radius: 4px; margin-bottom: 6px; font-weight: 700;
  background: rgba(255,255,255,0.08); color: var(--game-muted);
}
.gm-badge-card.rarity-rare .gm-bb-rarity { background: rgba(90,169,255,0.2); color: var(--game-blue); }
.gm-badge-card.rarity-epic .gm-bb-rarity { background: rgba(255,181,71,0.2); color: var(--game-accent); }
.gm-badge-card.rarity-legendary .gm-bb-rarity {
  background: linear-gradient(135deg, var(--game-accent), var(--game-accent-2));
  color: #1a1410;
}
.gm-badge-card .gm-bb-desc { font-size: 11px; color: var(--game-muted); line-height: 1.4; margin-bottom: 6px; }
.gm-badge-card .gm-bb-date { font-size: 10px; color: var(--game-muted); margin-bottom: 6px; font-style: italic; }
.gm-badge-card .gm-bb-share {
  background: rgba(90,169,255,0.16); color: var(--game-blue);
  border: 1px solid rgba(90,169,255,0.3); border-radius: 6px;
  padding: 4px 10px; font-size: 11px; font-weight: 600; cursor: pointer;
  transition: background .15s;
}
.gm-badge-card .gm-bb-share:hover { background: rgba(90,169,255,0.28); }

/* Streak heatmap */
.gm-streak-info { font-size: 13px; color: var(--game-muted); margin-bottom: 10px; }
.gm-streak-info strong { color: var(--game-accent); }
.gm-heatmap {
  display: grid; gap: 4px;
  grid-template-columns: repeat(10, 1fr);
  margin: 8px 0 4px;
}
.gm-hm-cell {
  aspect-ratio: 1; border-radius: 4px;
  background: rgba(255,255,255,0.06); transition: transform .15s;
}
.gm-hm-cell.on {
  background: linear-gradient(135deg, var(--game-good), var(--game-blue));
  box-shadow: 0 0 8px rgba(93,211,158,0.35);
}
.gm-hm-cell:hover { transform: scale(1.15); }

/* Mute global hooks */
html[data-muted="true"] .game-coin { animation: none; }
