/* ==========================================================================
   QI-GAME — CHÂSSIS COMMUN
   ========================================================================== */

:root {
  --kidio-card-bg: #ffffff;
  --kidio-surface: #f8fafc;
  --kidio-track: #f1f5f9;
  --kidio-border: #e2e8f0;
  --kidio-border-soft: #eef1f6;
  --kidio-ink-strong: #1e293b;
  --kidio-ink: #334155;
  --kidio-ink-2: #64748b;
  --kidio-ink-soft: #94a3b8;
  --kidio-accent: #6366f1;
  --kidio-accent-strong: #4f46e5;
}

html, body {
  height: 100%;
  overflow: hidden;
  background-color: #ffffff;
  color: #334155;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* BARRE D'EN-TÊTE FIXE */
.top-inset-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  width: 100%; height: 48px;
  z-index: 50;
  background: #ffffff;
  box-shadow: 0 4px 24px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  border-bottom: 1px solid #e2e8f0;
}

.neu-logo-box {
  background: #ffffff;
  border-radius: 0.375rem;
  border: 1px solid #e2e8f0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05), inset 0 1px 1px rgba(255, 255, 255, 1);
}

/* CONTENEUR À GAUCHE (z-index ajusté à 10) */
.left-sidebar-container {
  position: fixed;
  top: 58px; 
  left: 0.75rem;
  bottom: 0.75rem;
  width: 265px;
  z-index: 10;
  display: flex; 
  flex-direction: column; 
  gap: 0.75rem;
}

.left-detached-sidebar {
  background: #ffffff;
  border-radius: 0.5rem;
  border: 1px solid #e2e8f0;
  box-shadow: 0 4px 24px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  min-height: 0;
}

.left-sidebar-container > .left-detached-sidebar:first-child { flex: 1 1 auto; }
.left-sidebar-container > .left-detached-sidebar:last-child  { flex: 0 0 auto; }

#leaderboard-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
#leaderboard-list::-webkit-scrollbar { display: none; }

.leaderboard-empty {
  margin: 0;
  padding: 0.5rem 0.25rem;
  font-size: 11px;
  color: #94a3b8;
  text-align: center;
}

/* ESPACE DE TRAVAIL WORKSPACE (z-index: 10) */
.workspace {
  position: fixed;
  top: 58px;
  left: 0.75rem;
  right: 0.75rem;
  bottom: 0.75rem;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background-color: #ffffff;
  border-radius: 0.5rem;
  border: 1px solid #e2e8f0;
  box-shadow: 0 4px 24px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

@media (min-width: 1024px) {
  .workspace { left: calc(0.75rem + 265px + 0.75rem); }
}

/* EN-TÊTE DU JEU */
.game-head {
  position: absolute;
  top: 1rem;
  left: 1.2rem;
  z-index: 5;
  max-width: 320px;
  text-align: left;
}

.game-head-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.game-head-icon {
  width: 34px; height: 34px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.5rem;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.06), inset 0 1px 1px rgba(255, 255, 255, 1);
  color: #4f46e5;
  font-size: 15px;
}

.game-head h2 {
  margin: 0;
  font-size: 21px;
  font-weight: 900;
  letter-spacing: -0.025em;
  line-height: 1.15;
  color: #1e293b;
}

.game-head h2 span { color: #4f46e5; }

.game-head p {
  margin: 0.5rem 0 0;
  max-width: 34ch;
  font-size: 12px;
  line-height: 1.6;
  color: #94a3b8;
}

@media (max-width: 900px) {
  .workspace { flex-direction: column; }
  .game-head {
    position: static;
    text-align: center;
    margin-bottom: 1rem;
    max-width: 420px;
  }
  .game-head-row { justify-content: center; }
  .game-head p { margin: 0.5rem auto 0; }
}

/* BOÎTIER 3D DU JEU */
.unified-3d-box {
  background: #ffffff;
  border-radius: 0.75rem;
  border: 1px solid #f1f5f9;
  box-shadow: inset 4px 4px 10px rgba(0, 0, 0, 0.05), inset -4px -4px 10px rgba(255, 255, 255, 1), 0 8px 20px -4px rgba(0, 0, 0, 0.04);
}

/* CLASSEMENT */
.leader-row {
  background: #ffffff;
  border-radius: 0.375rem;
  border: 1px solid #f1f5f9;
  box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.03), inset 0 1px 1px rgba(255, 255, 255, 1);
  transition: transform 0.2s ease, border-color 0.2s ease;
}
.leader-row:hover {
  transform: translateX(4px);
  border-color: #cbd5e1;
}

.rank-badge {
  width: 22px; height: 22px;
  flex: none;
  border-radius: 0.25rem;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
.rank-1 { background: #fef3c7; color: #d97706; border: 1px solid #fde68a; }
.rank-2 { background: #f1f5f9; color: #64748b; border: 1px solid #e2e8f0; }
.rank-3 { background: #ffedd5; color: #c2410c; border: 1px solid #fed7aa; }
.rank-other { background: #ffffff; color: #94a3b8; border: 1px solid #f1f5f9; }

/* BOÎTE STATS EN RELIEF */
.stats-section-v2 {
  background: #ffffff;
  border-radius: 0.5rem;
  border: 1px solid #e2e8f0;
  box-shadow: 0 6px 12px -2px rgba(15, 23, 42, 0.08), 0 3px 6px -2px rgba(15, 23, 42, 0.04), inset 0 1px 0 rgba(255, 255, 255, 1);
}

/* BOUTONS */
.neu-white-btn {
  background: #ffffff; border: 1px solid #e2e8f0; border-radius: 0.375rem;
  box-shadow: 0 4px 10px -2px rgba(0, 0, 0, 0.06), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.neu-white-btn:hover {
  transform: translateY(-2px) scale(1.03);
  border-color: #cbd5e1;
}

.neu-white-btn:active {
  transform: translateY(0) scale(0.97);
}

.neu-white-pressed {
  background: #f8fafc; border-radius: 0.25rem;
  box-shadow: inset 2px 2px 4px rgba(0, 0, 0, 0.1), inset -1px -1px 2px rgba(255, 255, 255, 1);
}

.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

.game-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  color: #94a3b8;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.game-loader-spinner {
  width: 32px; height: 32px;
  border-radius: 999px;
  border: 3px solid #e2e8f0;
  border-top-color: #6366f1;
  animation: gameLoaderSpin 0.7s linear infinite;
}
@keyframes gameLoaderSpin { to { transform: rotate(360deg); } }

.game-loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.94);
}
body.game-loading .game-loading-overlay { display: flex; }
body.game-loading #game-host { opacity: 0; }
#game-host { transition: opacity 0.25s ease; }

.is-embedded .top-inset-bar,
.is-embedded .left-sidebar-container {
  display: none;
}

.is-embedded body {
  padding-top: 0;
  padding-bottom: 0;
  background: transparent;
}

.is-embedded .workspace {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

@media (min-width: 1024px) {
  .is-embedded .workspace { left: 0; }
}

.avatar-bubble {
  aspect-ratio: 1 / 1;
  border: 2px solid #e2e8f0;
  border-radius: 0.75rem;
  background: var(--kidio-card-bg, #ffffff);
  display: flex; align-items: center; justify-content: center;
  padding: 0.15rem;
  cursor: pointer;
  overflow: hidden;
  transition: all 0.2s ease;
}
.avatar-bubble img { width: 100%; height: 100%; object-fit: contain; }
.avatar-bubble:hover { transform: translateY(-2px); }
.avatar-bubble.is-selected {
  border-color: #10b981;
  background: #f0fdf4;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
  transform: scale(1.02);
}

.kidio-splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  background: rgba(255, 255, 255, 0.62);
  backdrop-filter: blur(12px) saturate(1.08);
  -webkit-backdrop-filter: blur(12px) saturate(1.08);
  opacity: 1;
  transition: opacity 0.45s ease;
  visibility: visible;
}

.kidio-splash.is-gone {
  opacity: 0;
  pointer-events: none;
}

.kidio-splash-logo {
  width: 240px;
  max-width: 62vw;
  height: auto;
  animation:
    splashPop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both,
    splashPulse 2.4s ease-in-out 0.6s infinite;
}

@keyframes splashPop {
  from { opacity: 0; transform: scale(0.82) translateY(10px); }
  to   { opacity: 1; transform: none; }
}
@keyframes splashPulse {
  0%, 100% { transform: scale(1);    filter: drop-shadow(0 10px 26px rgba(79, 70, 229, 0.20)); }
  50%      { transform: scale(1.04); filter: drop-shadow(0 16px 40px rgba(79, 70, 229, 0.36)); }
}

.kidio-splash-bar {
  width: 200px;
  max-width: 60vw;
  height: 4px;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.15);
  overflow: hidden;
  animation: splashPop 0.6s ease 0.15s both;
}
.kidio-splash-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #818cf8, #4f46e5);
  transition: width 0.35s ease;
}

.kidio-splash-status {
  min-height: 14px;
  margin-top: -0.5rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  letter-spacing: 0.4px;
  color: #64748b;
  transition: color 0.3s ease;
  animation: splashPop 0.6s ease 0.25s both;
}
.kidio-splash-status.is-done {
  color: #10b981;
  font-weight: 700;
}

html[data-theme="neu"] .kidio-splash {
  background: rgba(240, 243, 248, 0.75);
}

.kidio-tip {
  position: fixed;
  z-index: 200;
  max-width: 240px;
  padding: 0.5rem 0.7rem;
  border-radius: 0.625rem;
  background: var(--kidio-card-bg, #ffffff);
  border: 1px solid var(--kidio-border, #e2e8f0);
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.14), 0 2px 6px rgba(15, 23, 42, 0.06);
  color: var(--kidio-ink, #334155);
  font-size: 11px;
  line-height: 1.45;
  pointer-events: none;
  opacity: 0;
  transform: translateY(5px) scale(0.97);
  transition: opacity 0.16s ease, transform 0.16s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.kidio-tip.is-open { opacity: 1; transform: none; }

.kidio-tip-title {
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  font-weight: 800;
  color: var(--kidio-ink-strong, #1e293b);
}
.kidio-tip-sub {
  display: block;
  margin-top: 0.15rem;
  color: var(--kidio-ink-2, #64748b);
}
.kidio-tip-lock {
  display: block;
  margin-top: 0.15rem;
  color: var(--kidio-ink-soft, #94a3b8);
}

.confetti {
  position: fixed;
  top: 0;
  width: 8px; height: 8px;
  border-radius: 2px;
  pointer-events: none;
  animation: confettiFall 2.5s ease-out forwards;
  z-index: 100;
}

@keyframes confettiFall {
  0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* THÈME NEUMORPHIQUE DE BASE */
html[data-theme="neu"] {
  --bg-main: #f0f3f8;
  --card-bg: #f8fafc;
  --text-primary: #0f172a;
  --border-light: rgba(255, 255, 255, 0.9);
  --border-subtle: rgba(203, 213, 225, 0.4);

  --shadow-raised-lg: 6px 6px 14px rgba(166, 180, 200, 0.35), -6px -6px 14px rgba(255, 255, 255, 0.9);
  --shadow-raised-sm: 4px 4px 10px rgba(166, 180, 200, 0.35), -4px -4px 10px rgba(255, 255, 255, 0.9);
  --shadow-inset: inset 3px 3px 6px rgba(166, 180, 200, 0.4), inset -3px -3px 6px rgba(255, 255, 255, 0.9);

  --kidio-card-bg: var(--card-bg);
}

html[data-theme="neu"],
html[data-theme="neu"] body {
  background-color: var(--bg-main);
}

html[data-theme="neu"] .top-inset-bar {
  background: var(--card-bg);
  box-shadow: var(--shadow-raised-sm);
  border-bottom: 0;
}

html[data-theme="neu"] .neu-logo-box {
  background: var(--card-bg);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-raised-sm);
}

html[data-theme="neu"] .left-detached-sidebar {
  background: var(--card-bg);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  box-shadow: var(--shadow-raised-lg);
}

html[data-theme="neu"] .workspace {
  background-color: var(--bg-main);
  background-image: none;
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-inset);
}

html[data-theme="neu"] .game-head h2 {
  color: var(--text-primary);
}

html[data-theme="neu"] .game-head-icon {
  background: var(--card-bg);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-raised-sm);
}

html[data-theme="neu"] .unified-3d-box {
  background: var(--card-bg);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  box-shadow: var(--shadow-raised-lg);
}

html[data-theme="neu"] .leader-row {
  background: var(--card-bg);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-raised-sm);
}

html[data-theme="neu"] .stats-section-v2 {
  background: var(--card-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  box-shadow: var(--shadow-inset);
}

html[data-theme="neu"] .neu-white-btn {
  background: var(--card-bg);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  box-shadow: var(--shadow-raised-sm);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
html[data-theme="neu"] .neu-white-btn:active {
  box-shadow: var(--shadow-inset);
  transform: translateY(1px);
}

html[data-theme="neu"] .neu-white-pressed {
  background: var(--card-bg);
  box-shadow: var(--shadow-inset);
}

html[data-theme="neu"] .game-loading-overlay {
  background: rgba(240, 243, 248, 0.94);
}

/* ==========================================================================
   LOGO ANIMÉ DU HEADER (SVG inline, voir index.html — .kidio-logo)
   Couleurs pilotées par --kidio-accent / --kidio-accent-strong / --kidio-border /
   --kidio-card-bg : suit automatiquement le thème choisi par l'enfant, comme
   n'importe quel autre élément du châssis. Sur login.html/page_parent_stats.html,
   ces variables gardent leur valeur "base" (aucun data-theme posé sur ces pages),
   donc le logo y garde son apparence d'origine — cohérent avec la règle B3.
   Perf : uniquement transform / opacity / filter (composés par le GPU), pour
   ne pas peser sur les mini-jeux — jamais de propriété qui redéclenche la
   mise en page.

   SYNCHRONISATION avec la vague de couleur des tuiles (assets/levels.css,
   .level-tile::before / tileTint, DÉCALAGE ajouté là-bas de 2.97s pour que
   les tuiles ne démarrent qu'une fois l'éclat du logo terminé — voir le
   commentaire "SYNCHRO LOGO" dans levels.css). tileTint dure 9s par tuile :
   le logo boucle donc aussi sur un cycle de 9s, actif sur les 2,97
   premières secondes de chaque cycle (0,7s d'apparition + 2,27s de reflet/
   néon), calme le reste du temps — les deux restent alignés indéfiniment,
   pas seulement au premier passage, sans dérive possible puisque les deux
   durées sont fixes. Pourcentages ci-dessous = fractions de 9s
   (2,97s = 33 %, 0,7s = 7,8 %).

   Le survol (inclinaison légère) est posé sur .kidio-logo, PAS sur
   .kidio-logo-svg : une animation infinie qui touche `transform` sur le
   même élément qu'une règle :hover bloquerait ce :hover en permanence
   (l'animation "possède" la propriété tant qu'elle tourne). En séparant
   les deux éléments, le survol reste toujours utilisable. */

.kidio-logo {
  display: inline-flex;
  align-items: center;
  background: transparent;
  line-height: 0;
  cursor: pointer;
  transform-origin: 50% 60%;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.kidio-logo:hover,
.kidio-logo:focus-within {
  transform: perspective(600px) rotateX(-6deg) rotateY(6deg) scale(1.05);
}

.kidio-logo-svg {
  height: 34px;
  width: auto;
  max-width: 44vw;
  display: block;
  overflow: visible;
  will-change: filter, transform;
}

/* Déclenchée par JS (playLogoIntro() dans assets/levels.js) au même
   instant que renderLevels() pose --tint-delay sur les tuiles : la classe
   est retirée puis reposée (avec un reflow forcé entre les deux) à chaque
   rendu de la grille pour que le cycle de 9s reste calé sur celui des
   tuiles, qui repart lui aussi de zéro à chaque renderLevels(). Pas de
   rebond d'apparition (scale/opacity) : rejoué à chaque cycle de 9s, il
   faisait rétrécir et disparaître le logo un instant avant de rebondir —
   perçu comme une saute, retiré. Le logo reste visible en continu, seuls
   le reflet et le néon (ci-dessous) l'animent. */
.kidio-logo-svg.is-playing {
  animation: kidio-logo-glow 9s ease-in-out infinite;
}

/* Impulsion néon, une fois par cycle de 9s, synchronisée avec le passage
   du reflet (voir .kidio-logo-shimmer-band). */
@keyframes kidio-logo-glow {
  0%      { filter: drop-shadow(0 0 0px var(--kidio-accent, #6366f1)); }
  7.8%    { filter: drop-shadow(0 0 0px var(--kidio-accent, #6366f1)); }
  16.6%   { filter: drop-shadow(0 0 7px var(--kidio-accent, #6366f1)); }
  33%     { filter: drop-shadow(0 0 0px var(--kidio-accent, #6366f1)); }
  100%    { filter: drop-shadow(0 0 0px var(--kidio-accent, #6366f1)); }
}

@media (prefers-reduced-motion: reduce) {
  .kidio-logo-svg.is-playing { animation: none; }
  .kidio-logo:hover, .kidio-logo:focus-within { transform: none; }
  .kidio-logo-svg.is-playing .kidio-logo-shimmer-band { animation: none; }
}

.kidio-logo-text {
  font-family: 'Fredoka', 'Arial Rounded MT Bold', 'Nunito', system-ui, sans-serif;
  font-weight: 900;
  font-size: 118px;
  letter-spacing: -6px;
}

/* Contour "sticker" épais : reprend la couleur de carte du thème actif. */
.kidio-logo-white-border {
  stroke: var(--kidio-card-bg, #ffffff);
  stroke-width: 22px;
  stroke-linejoin: round;
  stroke-linecap: round;
}

/* Ombre interne douce, remplace un contour noir : suit la couleur de bordure du thème. */
.kidio-logo-inner-depth {
  stroke: var(--kidio-border, #e2e8f0);
  stroke-width: 28px;
  stroke-linejoin: round;
  stroke-linecap: round;
}

/* Dégradés des lettres — par défaut (thème "base", sans attribut
   data-theme) : couleurs vraies d'origine du fichier logo/logo.svg,
   inchangées. C'est assets/themes.css qui remplace ce remplissage sur les
   autres thèmes (une seule teinte tirée de --kidio-accent, ou blanc sur le
   thème sombre) — rien ici ne dépend du thème, cette règle EST l'apparence
   d'origine (cohérent avec B3/B4 : themes.css scope tout sous
   html[data-theme], jamais l'inverse). */
.kidio-logo-role-blue { fill: url(#kidioLogoGradBlue); }
.kidio-logo-role-orange { fill: url(#kidioLogoGradOrange); }

/* Reflet lumineux (shimmer) : bande blanche translucide, découpée à la
   forme exacte des lettres (clip-path SVG, voir index.html). Position de
   repos hors du texte à gauche (translateX en unités du viewBox 0-540 —
   le rectangle lui-même est posé à x="0" dans le SVG, translateX est la
   SEULE source de position). */
.kidio-logo-shimmer-band {
  transform: translateX(-150px);
}

/* Balayage continu sur la même fenêtre active que kidio-logo-glow
   (7,8 %-33 % du cycle de 9s) : le reflet part de -150 (bande hors champ
   à gauche, juste avant le début du texte ~x=20), traverse les lettres
   jusqu'à 660 (bande hors champ à droite, bien après la fin du texte
   ~x=510), puis revient instantanément à -150 juste après — le saut ne se
   voit pas, la bande est invisible aux deux positions (hors des lettres),
   prête pour le prochain passage. */
.kidio-logo-svg.is-playing .kidio-logo-shimmer-band {
  animation: kidio-logo-shimmer 9s ease-in-out infinite;
}

@keyframes kidio-logo-shimmer {
  0%      { transform: translateX(-150px); }
  7.8%    { transform: translateX(-150px); }
  33%     { transform: translateX(660px); }
  33.1%   { transform: translateX(-150px); }
  100%    { transform: translateX(-150px); }
}