/* ===================================================================
   iriskids-ui.css — Design system partagé IrisKids
   Servi depuis https://iriskids.fr/static/iriskids-ui.css
   Inclure dans chaque jeu via <link> + ajouter <header class="ik-header">

   Sprint Brand Book 2026-05-09 :
   - Palette officielle complète (couleurs IrisKids + accents par jeu)
   - Système typographique (échelle Baloo 2)
   - Composants standards (button, card, hero)
   - Variables d'espacement et radius
   =================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@400;500;600;700;800&display=swap');

/* ════════════════════════════════════════════════════════════════════
   1. PALETTE OFFICIELLE
   ════════════════════════════════════════════════════════════════════ */
:root {
  /* ── Couleur de marque IrisKids (violet iris) ── */
  --ik-brand:        #7b3fe4;
  --ik-brand-dark:   #6d28d9;
  --ik-brand-light:  #a78bfa;

  /* ── Accents officiels par jeu (override par chaque service via --ik-accent) ── */
  --ik-accent-home:       #7b3fe4;  /* 🌈 home — iris */
  --ik-accent-memory:     #22c55e;  /* 🧠 memory — vert prairie */
  --ik-accent-chess:      #eab308;  /* ♟️ echec — jaune doré */
  --ik-accent-2048:       #f59e0b;  /* 🎮 2048 — orange */
  --ik-accent-pong:       #ef4444;  /* 🏓 pong — rouge */
  --ik-accent-quiz:       #eab308;  /* ❓ quiz — jaune doré */
  --ik-accent-comptines:  #06b6d4;  /* 🎵 comptines — cyan veilleuse */

  /* ── Variable accent locale (override par chaque jeu) ── */
  --ik-accent:       var(--ik-brand);
  --ik-accent-dark:  #6d28d9;

  /* ── Couleurs neutres ── */
  --ik-bg:           #fffafc;
  --ik-bg-alt:       #f9f5fb;
  --ik-text:         #1a1033;
  --ik-text-soft:    #4b3a72;
  --ik-muted:        #6b7280;
  --ik-border:       rgba(0, 0, 0, .07);
  --ik-border-strong:rgba(0, 0, 0, .14);

  /* ── Couleurs sémantiques ── */
  --ik-success:      #16a34a;
  --ik-warning:      #d97706;
  --ik-danger:       #dc2626;
  --ik-info:         #0284c7;

  /* ── Typo ── */
  --ik-font:         'Baloo 2', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --ik-fs-xs:        12px;
  --ik-fs-sm:        14px;
  --ik-fs-base:      16px;
  --ik-fs-lg:        18px;
  --ik-fs-xl:        24px;
  --ik-fs-2xl:       32px;
  --ik-fs-3xl:       42px;
  --ik-fs-hero:      56px;

  /* ── Espacement ── */
  --ik-space-1:      4px;
  --ik-space-2:      8px;
  --ik-space-3:      12px;
  --ik-space-4:      16px;
  --ik-space-5:      24px;
  --ik-space-6:      32px;
  --ik-space-7:      48px;

  /* ── Radius ── */
  --ik-radius-sm:    8px;
  --ik-radius:       16px;
  --ik-radius-lg:    24px;
  --ik-radius-pill:  9999px;

  /* ── Shadows ── */
  --ik-shadow:       0 2px 12px rgba(0, 0, 0, .12);
  --ik-shadow-lg:    0 8px 24px rgba(123, 63, 228, .18);
  --ik-shadow-card:  0 1px 4px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .06);

  /* ── Header ── */
  --ik-header-h:     52px;
}

/* ════════════════════════════════════════════════════════════════════
   2. HEADER PARTAGÉ
   ════════════════════════════════════════════════════════════════════ */
.ik-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--ik-header-h);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* Sprint UX.PATCH : gap entre logo / games-btn / user-zone (sinon les
     boutons injectés par iriskids-header.js se touchent sur mobile,
     rendant le 🎮 partiellement non-cliquable car l'avatar empiète). */
  gap: 8px;
  padding: 0 12px;
  background: var(--ik-accent, #7b3fe4); /* AUDIT.1 RC2 fallback */
  box-shadow: var(--ik-shadow);
  font-family: var(--ik-font);
  -webkit-tap-highlight-color: transparent;
}

.ik-header-title {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  flex: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 8px;
  letter-spacing: .01em;
}

/* Bouton retour accueil */
.ik-back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .15);
  color: #fff;
  text-decoration: none;
  font-size: 18px;
  font-weight: 700;
  flex-shrink: 0;
  transition: background .15s, transform .12s;
  border: none;
  cursor: pointer;
  font-family: var(--ik-font);
}
.ik-back-btn:hover  { background: rgba(255, 255, 255, .25); }
.ik-back-btn:active { transform: scale(.90); background: rgba(255, 255, 255, .3); }

/* Décalage pour le contenu */
.ik-page-content { padding-top: var(--ik-header-h); }

/* ════════════════════════════════════════════════════════════════════
   3. COMPOSANTS STANDARDS
   ════════════════════════════════════════════════════════════════════ */

/* ── Hero (écran d'accueil de chaque jeu) ── */
.ik-hero {
  text-align: center;
  padding: 12px 0 8px;
}
.ik-hero-emoji {
  font-size: 64px;
  line-height: 1;
  display: inline-block;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, .15));
  animation: ik-bob 2.4s ease-in-out infinite;
}
@keyframes ik-bob {
  0%, 100% { transform: translateY(0)    rotate(-3deg); }
  50%      { transform: translateY(-6px) rotate(3deg); }
}
.ik-hero-title {
  font-family: var(--ik-font);
  font-size: var(--ik-fs-3xl);
  font-weight: 800;
  margin: 8px 0 4px;
  background: linear-gradient(135deg, var(--ik-accent) 0%, var(--ik-accent-dark, #6d28d9) 100%);
  -webkit-background-clip: text;
          background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -.01em;
}
.ik-hero-sub {
  color: var(--ik-text-soft);
  font-size: var(--ik-fs-base);
  margin: 4px 0 24px;
}

/* ── Boutons ── */
.ik-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--ik-font);
  font-size: var(--ik-fs-base);
  font-weight: 600;
  padding: 10px 20px;
  border-radius: var(--ik-radius-pill);
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: transform .12s, box-shadow .15s;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;        /* a11y : tap target ≥ 44px */
}
.ik-btn-primary {
  background: var(--ik-accent);
  color: #fff;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--ik-accent) 30%, transparent);
}
.ik-btn-primary:hover  { transform: translateY(-1px); box-shadow: 0 4px 12px color-mix(in srgb, var(--ik-accent) 40%, transparent); }
.ik-btn-primary:active { transform: scale(.97); }

.ik-btn-secondary {
  background: #fff;
  color: var(--ik-text);
  border: 2px solid var(--ik-border-strong);
}
.ik-btn-secondary:hover  { border-color: var(--ik-accent); color: var(--ik-accent); }

.ik-btn-ghost {
  background: transparent;
  color: var(--ik-accent);
}
.ik-btn-ghost:hover { background: color-mix(in srgb, var(--ik-accent) 8%, transparent); }

/* ── Cards ── */
.ik-card {
  background: #fff;
  border-radius: var(--ik-radius);
  padding: var(--ik-space-5);
  box-shadow: var(--ik-shadow-card);
  border: 1px solid var(--ik-border);
}
.ik-card-interactive {
  cursor: pointer;
  transition: transform .15s, box-shadow .2s;
}
.ik-card-interactive:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px color-mix(in srgb, var(--ik-accent) 18%, transparent);
}

/* ── Badges ── */
.ik-badge {
  display: inline-flex;
  align-items: center;
  font-family: var(--ik-font);
  font-size: var(--ik-fs-xs);
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--ik-radius-pill);
  background: color-mix(in srgb, var(--ik-accent) 14%, transparent);
  color: var(--ik-accent-dark, var(--ik-accent));
}

/* ── Inputs ── */
.ik-input {
  font-family: var(--ik-font);
  font-size: var(--ik-fs-base);
  padding: 10px 14px;
  border-radius: var(--ik-radius-sm);
  border: 2px solid var(--ik-border-strong);
  background: #fff;
  color: var(--ik-text);
  outline: none;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.ik-input:focus {
  border-color: var(--ik-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ik-accent) 20%, transparent);
}

/* ── Background pattern (subtil) ── */
.ik-bg-soft {
  background:
    radial-gradient(circle at 15% -10%, color-mix(in srgb, var(--ik-accent) 14%, transparent) 0%, transparent 45%),
    radial-gradient(circle at 100% 100%, color-mix(in srgb, var(--ik-accent) 10%, transparent) 0%, transparent 50%),
    var(--ik-bg);
  min-height: 100vh;
}

/* ── Animations utilitaires ── */
@keyframes ik-screen-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.ik-anim-in { animation: ik-screen-in .3s cubic-bezier(.34, 1.56, .64, 1); }

@keyframes ik-float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}

/* ════════════════════════════════════════════════════════════════════
   4. ACCESSIBILITÉ
   ════════════════════════════════════════════════════════════════════ */
.ik-sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .ik-hero-emoji,
  .ik-anim-in {
    animation: none !important;
  }
  * { transition-duration: 0.01ms !important; }
}

/* ── Compatibilité pour anciens jeux qui utilisaient juste --ik-accent ── */
.ik-font { font-family: var(--ik-font) !important; }

/* ════════════════════════════════════════════════════════════════════
   5. RESPONSIVE
   ════════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  :root {
    --ik-header-h: 48px;
    --ik-fs-3xl: 32px;
    --ik-fs-hero: 40px;
  }
  .ik-header-title { font-size: 14px; }
  .ik-hero-emoji   { font-size: 56px; }
}

/* ════════════════════════════════════════════════════════════════════
   6. RESPONSIVE SAFETY — Sprint Cohérence visuelle 2026-05-09
   Règles défensives appliquées à TOUS les jeux qui importent ce CSS.
   ════════════════════════════════════════════════════════════════════ */

/* Plus jamais de scroll horizontal accidentel */
html, body { overflow-x: hidden; max-width: 100vw; }

/* Médias toujours fluides (jamais plus larges que leur conteneur) */
img, video, canvas, svg, iframe {
  max-width: 100%;
  height: auto;
}
canvas { /* Spécial canvas : on garde le contrôle de la hauteur */
  height: revert;
}

/* AUDIT.1 RC3 : libs tierces qui gèrent leur propre sizing (chessboard-js,
   board games, etc.). Sans cette exception, max-width:100% + height:auto
   écrasent les pièces SVG positionnées en absolu par la lib. */
#board img, #board svg,
.game-board img, .game-board svg,
[role="grid"] img, [role="grid"] svg {
  max-width: none;
  height: revert;
}

/* Tap target a11y : tout bouton/lien interactif ≥ 44×44 px (WCAG 2.5.5) */
button, [role="button"], .button, a.btn, input[type="submit"], input[type="button"] {
  min-height: 44px;
}
/* Exception : les .ik-back-btn sont 36px ronds par design (assez grand) */
.ik-back-btn { min-height: auto; }

/* Tap target pour formulaires : inputs lisibles + cliquables */
select, input:not([type="checkbox"]):not([type="radio"]) {
  min-height: 40px;
  font-size: 16px; /* iOS Safari : empêche le zoom auto sur focus */
}

/* Sur mobile, jamais de double-tap zoom intrusif sur les UI cliquables */
button, [role="button"], a, .ik-card-interactive, .level-btn, .card {
  touch-action: manipulation;
}

/* Safe area iOS (notch + home indicator) */
@supports (padding: max(0px)) {
  body {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }
}

/* ════════════════════════════════════════════════════════════════════
   7. ACCESSIBILITY — UX.2 focus visible + UX.3 loader
   ════════════════════════════════════════════════════════════════════ */

/* UX.2 — Focus visible accessible (WCAG 2.4.7)
   Affiche un outline clair uniquement quand la navigation se fait au
   clavier (pas au clic souris, qui n'a pas besoin de feedback visuel). */
*:focus { outline: none; }  /* reset par défaut */
*:focus-visible {
  outline: 3px solid var(--ik-accent, #7b3fe4);
  outline-offset: 2px;
  border-radius: 4px;
  box-shadow: 0 0 0 6px rgba(123, 63, 228, .15);
}
/* Liens et boutons ronds : on adapte le radius */
a:focus-visible,
.ik-back-btn:focus-visible,
.ik-logo-btn:focus-visible,
.ik-games-btn:focus-visible,
.ik-user-avatar-btn:focus-visible {
  outline-offset: 3px;
}

/* UX.3 — Composant Loader
   Usage : <div class="ik-loader" aria-label="Chargement"></div>
   Pour overlay full-screen :
     <div class="ik-loader-overlay">
       <div class="ik-loader-spinner"></div>
       <p class="ik-loader-label">Chargement…</p>
     </div>
*/
.ik-loader {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(123, 63, 228, .15);
  border-top-color: var(--ik-accent, #7b3fe4);
  border-radius: 50%;
  animation: ik-spin .8s linear infinite;
  display: inline-block;
}
.ik-loader-sm { width: 20px; height: 20px; border-width: 2px; }
.ik-loader-lg { width: 56px; height: 56px; border-width: 4px; }

@keyframes ik-spin {
  to { transform: rotate(360deg); }
}

/* Overlay plein écran (au-dessus de tout) */
.ik-loader-overlay {
  position: fixed;
  inset: 0;
  z-index: 9998;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(255, 250, 252, 0.92);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  font-family: var(--ik-font, 'Baloo 2', system-ui, sans-serif);
  color: var(--ik-text, #1a1033);
  animation: ik-loader-fade-in .2s ease;
}
.ik-loader-overlay .ik-loader-spinner {
  width: 56px;
  height: 56px;
  border: 4px solid rgba(123, 63, 228, .15);
  border-top-color: var(--ik-accent, #7b3fe4);
  border-radius: 50%;
  animation: ik-spin .8s linear infinite;
}
.ik-loader-label {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: #4b3a72;
}

@keyframes ik-loader-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Variante inline : centré dans un conteneur */
.ik-loader-inline {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px 16px;
  color: #4b3a72;
}

@media (prefers-reduced-motion: reduce) {
  .ik-loader,
  .ik-loader-overlay .ik-loader-spinner {
    animation-duration: 2s; /* ralenti, pas désactivé pour rester perceptible */
  }
  .ik-loader-overlay { animation: none; }
}

/* ════════════════════════════════════════════════════════════════════════
   Sprint GAMIF.6 — Toast "Nouveau badge !" partagé entre tous les jeux
   Servi via https://iriskids.fr/static/iriskids-ui.css déjà importé par
   chaque service (memory, chess, 2048, etc.) → zéro duplication.
   ════════════════════════════════════════════════════════════════════════ */

.ik-badge-toast {
  position: fixed;
  top: 80px;
  left: 50%;
  z-index: 9999;
  background: linear-gradient(135deg, #7b3fe4 0%, #a855f7 100%);
  color: #ffffff;
  padding: 12px 20px 12px 16px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 8px 24px rgba(123, 63, 228, 0.5);
  font-family: 'Baloo 2', system-ui, sans-serif;
  min-width: 240px;
  max-width: calc(100vw - 32px);
  pointer-events: none;
  transform: translateX(-50%) translateY(-20px) scale(0.9);
  opacity: 0;
  animation: ik-badge-toast-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
.ik-badge-toast-leaving {
  animation: ik-badge-toast-out 0.4s ease forwards;
}
.ik-badge-toast-emoji {
  font-size: 36px;
  line-height: 1;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}
.ik-badge-toast-body { flex: 1; min-width: 0; }
.ik-badge-toast-title {
  font-size: 11px;
  font-weight: 600;
  opacity: 0.9;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 2px;
}
.ik-badge-toast-label {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@keyframes ik-badge-toast-in {
  0%   { opacity: 0; transform: translateX(-50%) translateY(-30px) scale(0.85); }
  60%  {              transform: translateX(-50%) translateY(2px)  scale(1.05); }
  100% { opacity: 1; transform: translateX(-50%) translateY(0)    scale(1); }
}
@keyframes ik-badge-toast-out {
  to { opacity: 0; transform: translateX(-50%) translateY(-20px) scale(0.92); }
}

@media (max-width: 480px) {
  .ik-badge-toast {
    min-width: auto;
    width: calc(100vw - 24px);
    padding: 10px 16px;
  }
  .ik-badge-toast-emoji { font-size: 28px; }
  .ik-badge-toast-label { font-size: 14px; }
}

/* Respecte les préférences "réduire les animations" */
@media (prefers-reduced-motion: reduce) {
  .ik-badge-toast {
    animation: none;
    opacity: 1;
    transform: translateX(-50%);
  }
  .ik-badge-toast-leaving { animation: none; opacity: 0; }
}

/* =========================================================================
 * Sprint KID.PROFILE.OVERLAY (GAMIF.6.ALL) — Badge "🏆 Ton record" sur les
 * pages de jeu. Injecté par iriskids-header.js quand l'utilisateur est
 * loggué et a déjà un best_score sur le jeu courant.
 * ========================================================================= */
.ik-record-overlay {
  position: fixed;
  top: 78px;
  right: 14px;
  z-index: 9998;             /* sous les badge-toast (9999) */
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 8px 12px;
  border-radius: 9999px;
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  color: #78350f;
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-weight: 800;
  font-size: 0.92rem;
  letter-spacing: -0.01em;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.4);
  animation: ik-record-overlay-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  cursor: default;
  user-select: none;
}
.ik-record-overlay-trophy {
  font-size: 1.15rem;
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(120, 53, 15, 0.25));
}
.ik-record-overlay-label {
  font-size: 0.78rem;
  font-weight: 700;
  opacity: 0.85;
  letter-spacing: 0.02em;
}
.ik-record-overlay-value {
  font-size: 1.05rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.ik-record-overlay-new {
  animation: ik-record-overlay-pulse 1.6s ease-out;
}
@keyframes ik-record-overlay-in {
  from { transform: translateX(40px) scale(0.85); opacity: 0; }
  to   { transform: translateX(0)    scale(1);    opacity: 1; }
}
@keyframes ik-record-overlay-pulse {
  0%   { box-shadow: 0 4px 14px rgba(245, 158, 11, 0.4); }
  30%  { box-shadow: 0 0 0 8px rgba(245, 158, 11, 0.35),
                     0 8px 24px rgba(245, 158, 11, 0.6);
         transform: scale(1.06); }
  100% { box-shadow: 0 4px 14px rgba(245, 158, 11, 0.4);
         transform: scale(1); }
}

@media (max-width: 480px) {
  .ik-record-overlay {
    top: auto;
    bottom: 14px;
    right: 50%;
    transform: translateX(50%);
    font-size: 0.88rem;
    padding: 7px 12px;
  }
  @keyframes ik-record-overlay-in {
    from { transform: translateX(50%) translateY(20px) scale(0.85); opacity: 0; }
    to   { transform: translateX(50%) translateY(0)    scale(1);    opacity: 1; }
  }
}
@media (prefers-reduced-motion: reduce) {
  .ik-record-overlay { animation: none; }
  .ik-record-overlay-new { animation: none; }
}
