/* ============================================================================
   FLOWLY — Passe esthétique premium. Nuit bleu-indigo avec accent doré,
   harmonisé avec CB-ARCADE design system. Tokens CSS premium, animations,
   dark/light mode, RTL arabe, safe-areas iPhone, WCAG AAA.
   Mobile d'abord : 520px max, responsive jusqu'à 2560px.
   ========================================================================== */
:root {
  /* --- PALETTE FLOWLY (harmonisée CB-ARCADE premium — tokens directs du kit) --- */
  --fl-bg: #0e1219;           /* Fond nuit (#cb-neutral-1000) */
  --fl-bg2: #1a2029;          /* Fond gradient light (#cb-neutral-900) */
  --fl-panel: #151d2a;        /* Panneau #cb-surface-0 */
  --fl-panel2: #1a2332;       /* Panneau secondaire #cb-surface-2 */
  --fl-cell: #0f131a;         /* Cellule plateau (#cb-surface-1, ultra-sombre) */
  --fl-line: rgba(255, 255, 255, 0.14);  /* Border #cb-border-medium */
  --fl-accent: #ffc107;       /* Accent or vif #cb-accent (kit-design premium) */
  --fl-accent-ink: #0a0f22;   /* Texte sur accent #cb-text-on-accent (WCAG AA+) */
  --fl-ink: #f0f4fa;          /* Texte primaire #cb-text-primary (AAA 16.6:1) */
  --fl-muted: #9aa8bd;        /* Texte secondaire #cb-text-secondary (7:1) */
  --fl-good: #3aff8f;         /* Succès vert vif #cb-primary (kit premium ultra-lumineux) */
  --fl-bad: #ff5252;          /* Erreur rouge #cb-danger (WCAG AAA) */

  /* --- TOKENS CB-ARCADE PREMIUM (harmonisé kit-design exact) --- */
  --cb-radius-xs: 4px;
  --cb-radius-sm: 8px;
  --cb-radius-md: 12px;
  --cb-radius-lg: 16px;
  --cb-radius-xl: 20px;
  --cb-radius-2xl: 24px;
  --cb-radius-pill: 999px;
  /* Ombres bokeh premium — amples, profondeur 3D soutenue */
  --cb-shadow-xs: 0 2px 6px rgba(0, 0, 0, 0.16);
  --cb-shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.20);
  --cb-shadow-md: 0 8px 24px rgba(0, 0, 0, 0.22);
  --cb-shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.30);
  --cb-shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.40);
  --cb-shadow-2xl: 0 32px 80px rgba(0, 0, 0, 0.60);
  --cb-shadow-inset: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  /* Timings cohérents — respecte prefers-reduced-motion */
  --cb-duration-instant: 0.08s;
  --cb-duration-fast: 0.14s;
  --cb-duration-normal: 0.20s;
  --cb-duration-slow: 0.35s;
  --cb-easing-in-out: cubic-bezier(0.38, 0.1, 0.2, 1);
  --cb-easing-bounce: cubic-bezier(0.175, 0.885, 0.32, 1.275);
  --cb-easing-ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  /* --- ALIAS LOCAUX (compatibilité + clarté) --- */
  --r: var(--cb-radius-lg);
  --shadow: var(--cb-shadow-lg);
  --bg: var(--fl-bg);
  --bg2: var(--fl-bg2);
  --panel: var(--fl-panel);
  --panel2: var(--fl-panel2);
  --cell: var(--fl-cell);
  --line: var(--fl-line);
  --ink: var(--fl-ink);
  --muted: var(--fl-muted);
  --accent: var(--fl-accent);
  --accent-ink: var(--fl-accent-ink);
  --good: var(--fl-good);
  --bad: var(--fl-bad);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1100px 700px at 50% -12%, #1d3a72 0%, rgba(10, 18, 38, 0) 62%),
    radial-gradient(700px 500px at 12% 108%, #2a1a5e 0%, rgba(10, 18, 38, 0) 60%),
    var(--bg);
  overscroll-behavior: none;
  touch-action: manipulation;
}

body[dir="rtl"] {
  direction: rtl;
}

/* Respecter prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Mode clair premium (harmonisé CB-ARCADE light tokens) */
@media (prefers-color-scheme: light) {
  :root {
    --fl-bg: #f8f9fb;          /* Blanc très clair (#cb-neutral-50 — optimize contrast) */
    --fl-bg2: #e5ebf3;         /* Bleu très clair (#cb-neutral-200 — subtle accent) */
    --fl-panel: #f0f3f7;       /* Panneau surface (#cb-neutral-100 — readable contrast) */
    --fl-panel2: #e5ebf3;      /* Panneau secondaire (#cb-neutral-200 — consistency) */
    --fl-cell: #d8e0ec;        /* Cellule plateau (#cb-neutral-300 — board contrast) */
    --fl-line: rgba(0, 0, 0, 0.12);  /* Divider clair (#cb-border-light approx) */
    --fl-ink: #0a1428;         /* Texte primaire dark-blue (WCAG AAA 14:1+) */
    --fl-muted: #556682;       /* Texte secondaire (#cb-text-secondary approx, 6.8:1) */
    --fl-accent-ink: #3d2f00;  /* Texte or (inchangé, bon contraste sur or clair) */
    --fl-bad: #c41c3b;         /* Erreur rouge (#cb-danger-dark — AAA sur light) */
    --fl-good: #2ed97f;        /* Succès vert clair (#cb-primary-light — vif sur light) */
  }
}

#wrap {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: calc(max(12px, env(safe-area-inset-top)) + 4px)
           max(12px, env(safe-area-inset-right))
           max(12px, env(safe-area-inset-bottom))
           max(12px, env(safe-area-inset-left));
}

/* ---- En-tete + marque ---------------------------------------------------- */
header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand {
  font-weight: 900;
  letter-spacing: 0.05em;
  font-size: 21px;
  text-shadow: 0 6px 16px rgba(255, 193, 7, 0.28);
}

.brand b {
  color: var(--accent);
}

.icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  margin: 0;
  border-radius: var(--cb-radius-md);
  font-size: 17px;
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  color: var(--ink);
  border: 1px solid var(--line);
  flex: 0 0 auto;
  box-shadow: var(--cb-shadow-inset), var(--cb-shadow-sm);
  cursor: pointer;
  transition: transform var(--cb-duration-fast) var(--cb-easing-in-out),
              filter var(--cb-duration-fast),
              box-shadow var(--cb-duration-fast);
}

.icon-btn:active:not(:disabled) {
  transform: scale(0.94);
  box-shadow: var(--cb-shadow-inset), 0 2px 6px rgba(0, 0, 0, 0.3);
}

@media (hover: hover) {
  .icon-btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.08);
    box-shadow: var(--cb-shadow-inset), var(--cb-shadow-lg);
  }
}

.head-btns {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}

/* Le « ? » se voit : c'est la porte de secours d'un debutant. */
.icon-btn.help {
  background: linear-gradient(180deg, #5fb8ff, #2a72c9);
  color: #fff;
  font-weight: 900;
  border-color: transparent;
  box-shadow: var(--cb-shadow-inset) rgba(255, 255, 255, 0.3), 0 6px 16px rgba(77, 171, 255, 0.35);
  animation: glow-pulse-blue 2.4s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes glow-pulse-blue {
  0%, 100% {
    box-shadow: var(--cb-shadow-inset) rgba(255, 255, 255, 0.4), 0 8px 24px rgba(77, 171, 255, 0.42);
  }
  50% {
    box-shadow: var(--cb-shadow-inset) rgba(255, 255, 255, 0.5), 0 12px 32px rgba(77, 171, 255, 0.65);
  }
}

@media (hover: hover) {
  .icon-btn.help:hover {
    transform: translateY(-2px);
    animation: none;
    box-shadow: var(--cb-shadow-inset) rgba(255, 255, 255, 0.4), 0 10px 28px rgba(77, 171, 255, 0.65);
  }
}

/* ---- HUD : vies, pieces, niveau, coups ----------------------------------- */
/* Porte-monnaie mutualisé CB-Arcade (2 soldes : Jouer 🪙 + Gagner ◆) */
.wallet-hud {
  width: 100%;
  display: flex;
  gap: 8px;
  justify-content: center;
}
.wchip {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 700;
  font-size: 0.8125rem;
  letter-spacing: 0.02em;
  color: var(--ink);
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--cb-radius-md);
  padding: 6px 12px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.wchip .ic { font-size: 0.875rem; line-height: 1; }
.wchip.earn {
  color: var(--accent);
  border-color: rgba(255, 193, 7, 0.28);
  background: rgba(255, 193, 7, 0.08);
}

.hud {
  width: 100%;
  display: flex;
  gap: 6px;
  align-items: stretch;
}

.chip {
  flex: 1;
  margin: 0;
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--cb-radius-md);
  padding: 8px 10px;
  text-align: center;
  color: var(--ink);
  font-family: inherit;
  min-width: 0;
  box-shadow: var(--cb-shadow-inset),
              inset 0 -3px 8px rgba(0, 0, 0, 0.22),
              0 2px 6px rgba(0, 0, 0, 0.12),
              0 4px 12px rgba(0, 0, 0, 0.15);
  transition: transform var(--cb-duration-fast) var(--cb-easing-bounce),
              box-shadow var(--cb-duration-fast),
              filter var(--cb-duration-fast);
}

.chip.low {
  background: linear-gradient(180deg, rgba(255, 91, 87, 0.20), rgba(255, 91, 87, 0.12));
  border-color: rgba(255, 91, 87, 0.6);
  box-shadow: var(--cb-shadow-inset),
              inset 0 -3px 8px rgba(255, 91, 87, 0.18),
              0 4px 12px rgba(255, 91, 87, 0.20);
}

@media (prefers-color-scheme: light) {
  .chip {
    box-shadow: var(--cb-shadow-inset),
                inset 0 -3px 8px rgba(0, 0, 0, 0.08),
                0 2px 6px rgba(0, 0, 0, 0.08),
                0 4px 12px rgba(0, 0, 0, 0.10);
  }
}

.chip-btn {
  cursor: pointer;
}

@media (hover: hover) {
  .chip-btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
    box-shadow: var(--cb-shadow-inset), inset 0 -3px 8px rgba(0, 0, 0, 0.2),
                var(--cb-shadow-lg);
  }
}

.chip .k {
  display: block;
  font-size: 9px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 700;
}

.chip .v {
  display: block;
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  margin-top: 2px;
}

.chip.low .v {
  color: var(--bad);
}

.chip .v small {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  margin-inline-start: 4px;
}

.chip-btn {
  cursor: pointer;
}

@media (hover: hover) {
  .chip-btn:hover {
    filter: brightness(1.1);
  }
}

/* ---- Consigne : l'objectif, toujours a l'ecran --------------------------- */
.goal {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.3;
  background: linear-gradient(180deg, #2b3768, #1a2244);
  border: 1px solid var(--line);
  box-shadow: var(--cb-shadow-inset), inset 0 -4px 8px rgba(0, 0, 0, 0.32),
              0 2px 6px rgba(0, 0, 0, 0.2), 0 6px 16px rgba(0, 0, 0, 0.28);
  transition: all var(--cb-duration-normal) var(--cb-easing-in-out);
}

@media (prefers-color-scheme: light) {
  .goal {
    background: linear-gradient(180deg, #e5ecf8, #dce5f3);
    border-color: rgba(255, 193, 7, 0.12);
    box-shadow: var(--cb-shadow-inset), inset 0 -4px 8px rgba(0, 0, 0, 0.08),
                0 2px 6px rgba(0, 0, 0, 0.08), 0 6px 16px rgba(0, 0, 0, 0.12);
  }
}

.goal-ico {
  font-size: 16px;
  flex: 0 0 auto;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.goal-txt {
  flex: 1;
  min-width: 0;
}

.goal-prog {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 900;
  padding: 4px 10px;
  border-radius: var(--cb-radius-pill);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  background: linear-gradient(180deg, #41539a, #232c56);
  border: 1px solid var(--line);
  box-shadow: var(--cb-shadow-inset);
  letter-spacing: 0.02em;
  transition: all var(--cb-duration-fast);
}

.goal.done {
  background: linear-gradient(180deg, #4dffc8, #12a97a);
  border-color: transparent;
  color: #04291f;
  box-shadow: 0 8px 24px rgba(77, 255, 200, 0.25),
              inset 0 -2px 6px rgba(0, 0, 0, 0.15);
}

.goal.done .goal-prog {
  background: rgba(255, 255, 255, 0.35);
  border-color: transparent;
  color: #04291f;
}

/* ---- Plateau ------------------------------------------------------------- */
canvas#c {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 20px;
  touch-action: none;
  background: linear-gradient(160deg, #1a2a48, #0d1520);
  border: 1px solid rgba(255, 193, 7, 0.12);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2),
              0 8px 24px rgba(0, 0, 0, 0.35),
              0 20px 56px rgba(0, 0, 0, 0.42),
              inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition: transform var(--cb-duration-fast) var(--cb-easing-ease-out),
              box-shadow var(--cb-duration-normal);
}

@media (hover: hover) {
  canvas#c:hover {
    transform: translateY(-2px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25),
                0 12px 32px rgba(0, 0, 0, 0.4),
                0 24px 64px rgba(0, 0, 0, 0.50),
                inset 0 1px 0 rgba(255, 255, 255, 0.1);
  }
}

@media (prefers-color-scheme: light) {
  canvas#c {
    background: linear-gradient(160deg, #e5ecf8, #dce5f3);
    border-color: rgba(255, 193, 7, 0.16);
  }
}

/* ---- Barre d'outils ------------------------------------------------------ */
.toolbar {
  width: 100%;
  display: flex;
  gap: 8px;
}

.tool {
  position: relative;
  flex: 1;
  margin: 0;
  padding: 10px 6px 8px;
  font-size: 20px;
  line-height: 1.1;
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--cb-radius-md);
  font-family: inherit;
  box-shadow: var(--cb-shadow-inset), 0 4px 12px rgba(0, 0, 0, 0.15);
  cursor: pointer;
  transition: transform var(--cb-duration-fast) var(--cb-easing-in-out),
              box-shadow var(--cb-duration-fast),
              filter var(--cb-duration-fast);
}

.tool .nm {
  display: block;
  font-size: 9px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tool .n {
  position: absolute;
  top: -7px;
  inset-inline-end: -5px;
  min-width: 24px;
  height: 24px;
  border-radius: var(--cb-radius-pill);
  background: linear-gradient(180deg, #ffd54f, var(--accent));
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 4px 12px rgba(255, 193, 7, 0.32);
  letter-spacing: 0.02em;
}

.tool.empty {
  opacity: 0.65;
}

.tool.empty .n {
  background: var(--line);
  color: var(--muted);
  box-shadow: none;
}

.tool:active:not(:disabled) {
  transform: scale(0.95);
}

@media (hover: hover) {
  .tool:hover:not(.empty) {
    filter: brightness(1.08);
  }
}

footer {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  padding-bottom: 4px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ---- Boutons ------------------------------------------------------------- */
button {
  border: 0;
  border-radius: var(--cb-radius-md);
  padding: 14px 18px;
  font-size: 16px;
  font-weight: 800;
  width: 100%;
  cursor: pointer;
  margin-top: 10px;
  font-family: inherit;
  transition: transform var(--cb-duration-fast) var(--cb-easing-in-out),
              filter var(--cb-duration-fast),
              box-shadow var(--cb-duration-fast);
  letter-spacing: 0.02em;
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

button:active:not(:disabled) {
  transform: scale(0.97);
}

@media (hover: hover) {
  button:hover:not(:disabled) {
    filter: brightness(1.06);
  }
}

/* Relief « bonbon » premium : dégradé or vif, reflet clair ultra-saturé, ombre bokeh 3-layer */
.btn-primary {
  background: linear-gradient(180deg, #ffd54f, var(--accent));
  color: var(--accent-ink);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12),
              0 8px 24px rgba(255, 193, 7, 0.35),
              0 16px 56px rgba(255, 193, 7, 0.40),
              inset 0 2px 0 rgba(255, 255, 255, 0.80),
              inset 0 -4px 0 rgba(200, 140, 0, 0.45);
  transition: transform var(--cb-duration-fast) var(--cb-easing-ease-out),
              box-shadow var(--cb-duration-fast),
              filter var(--cb-duration-fast);
}

@media (hover: hover) {
  .btn-primary:hover:not(:disabled) {
    transform: translateY(-4px);
    filter: brightness(1.15);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.16),
                0 16px 40px rgba(255, 193, 7, 0.50),
                0 24px 72px rgba(255, 193, 7, 0.65),
                inset 0 2px 0 rgba(255, 255, 255, 0.90),
                inset 0 -4px 0 rgba(200, 140, 0, 0.45);
  }
}

.btn-primary:active:not(:disabled) {
  transform: scale(0.94);
  box-shadow: 0 2px 8px rgba(255, 193, 7, 0.25),
              inset 0 2px 0 rgba(255, 255, 255, 0.78),
              inset 0 -4px 0 rgba(200, 140, 0, 0.50);
}

@media (prefers-color-scheme: light) {
  .btn-primary {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12),
                0 8px 20px rgba(255, 193, 7, 0.24),
                0 16px 48px rgba(255, 193, 7, 0.28),
                inset 0 2px 0 rgba(255, 255, 255, 0.8),
                inset 0 -3px 0 rgba(140, 100, 0, 0.35);
  }
}

.btn-ghost {
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: var(--cb-shadow-inset), 0 2px 8px rgba(0, 0, 0, 0.12);
  transition: transform var(--cb-duration-fast) var(--cb-easing-ease-out),
              box-shadow var(--cb-duration-fast),
              filter var(--cb-duration-fast);
}

@media (hover: hover) {
  .btn-ghost:hover:not(:disabled) {
    transform: translateY(-2px);
    filter: brightness(1.1);
    box-shadow: var(--cb-shadow-inset), 0 6px 16px rgba(0, 0, 0, 0.18);
  }
}

.btn-ghost:active:not(:disabled) {
  transform: scale(0.94);
  box-shadow: var(--cb-shadow-inset), 0 1px 4px rgba(0, 0, 0, 0.1);
}

@media (prefers-color-scheme: light) {
  .btn-ghost {
    box-shadow: var(--cb-shadow-inset), 0 2px 8px rgba(0, 0, 0, 0.08);
  }
}

.btn-rewarded {
  background: linear-gradient(180deg, #88d4ff, #5db8ff 50%, #b066ff);
  color: #ffffff;
  box-shadow: 0 8px 28px rgba(100, 120, 255, 0.35),
              inset 0 2px 0 rgba(255, 255, 255, 0.55),
              inset 0 -4px 0 rgba(50, 30, 120, 0.4);
  transition: transform var(--cb-duration-fast) var(--cb-easing-in-out),
              box-shadow var(--cb-duration-fast),
              filter var(--cb-duration-fast);
  animation: glow-pulse-rewarded 2.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes glow-pulse-rewarded {
  0%, 100% {
    box-shadow: 0 8px 28px rgba(100, 120, 255, 0.35),
                inset 0 2px 0 rgba(255, 255, 255, 0.55),
                inset 0 -4px 0 rgba(50, 30, 120, 0.4);
  }
  50% {
    box-shadow: 0 10px 36px rgba(100, 120, 255, 0.55),
                inset 0 2px 0 rgba(255, 255, 255, 0.65),
                inset 0 -4px 0 rgba(50, 30, 120, 0.4);
  }
}

@media (hover: hover) {
  .btn-rewarded:hover:not(:disabled) {
    transform: translateY(-2px);
    filter: brightness(1.1);
    animation: none;
    box-shadow: 0 12px 40px rgba(100, 120, 255, 0.65),
                inset 0 2px 0 rgba(255, 255, 255, 0.65),
                inset 0 -4px 0 rgba(50, 30, 120, 0.4);
  }
}

.btn-rewarded:active:not(:disabled) {
  transform: scale(0.96);
}

.btn-rewarded small,
.btn-primary small,
.btn-ghost small {
  display: block;
  font-weight: 600;
  opacity: 0.82;
  font-size: 11px;
  margin-top: 2px;
  letter-spacing: 0.02em;
}

.btn-row {
  display: flex;
  gap: 8px;
}

.btn-row button {
  margin-top: 10px;
}

/* ---- Overlays (glassmorphism premium) ------------------------------------ */
.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(6, 9, 14, 0.68);
  backdrop-filter: blur(8px) saturate(1.15);
  -webkit-backdrop-filter: blur(8px) saturate(1.15);
  z-index: 5;
  padding: max(12px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-right))
           max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-top));
  animation: fade-in var(--cb-duration-normal) var(--cb-easing-ease-out);
}

.overlay.show {
  display: flex;
}

@keyframes fade-in {
  from {
    opacity: 0;
    backdrop-filter: blur(0px) saturate(1.0);
    -webkit-backdrop-filter: blur(0px) saturate(1.0);
  }
  50% {
    backdrop-filter: blur(4px) saturate(1.08);
    -webkit-backdrop-filter: blur(4px) saturate(1.08);
  }
  to {
    opacity: 1;
    backdrop-filter: blur(8px) saturate(1.15);
    -webkit-backdrop-filter: blur(8px) saturate(1.15);
  }
}

.card {
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid rgba(255, 193, 7, 0.06);
  border-radius: var(--cb-radius-xl);
  padding: 24px 22px;
  width: min(390px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.55),
              inset 0 1px 0 rgba(255, 255, 255, 0.08);
  animation: card-rise var(--cb-duration-normal) var(--cb-easing-bounce);
  backdrop-filter: blur(3px);
}

@keyframes card-rise {
  from {
    transform: translateY(24px) scale(0.92);
    opacity: 0;
    filter: blur(6px);
  }
  40% {
    filter: blur(3px);
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
    filter: blur(0px);
  }
}

.card h2 {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.card .sub {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 14px;
  line-height: 1.5;
  font-weight: 600;
}

.card .big {
  font-size: 56px;
  font-weight: 900;
  color: var(--accent);
  margin: 8px 0 2px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 8px 24px rgba(255, 194, 14, 0.35);
  letter-spacing: 0.02em;
}

.card .gain {
  font-size: 17px;
  font-weight: 800;
  color: var(--good);
  min-height: 24px;
  line-height: 1.4;
  letter-spacing: 0.02em;
}

/* ---- Accueil ------------------------------------------------------------- */
.logo {
  font-weight: 900;
  letter-spacing: 0.05em;
  font-size: 40px;
  line-height: 1.1;
  text-shadow: 0 8px 32px rgba(255, 193, 7, 0.32);
  margin-bottom: 2px;
}

.logo b {
  color: var(--accent);
}

.logo-art {
  width: 140px;
  height: 140px;
  display: block;
  margin: 4px auto 12px;
  filter: drop-shadow(0 8px 28px rgba(0, 0, 0, 0.35));
}

.stats {
  display: flex;
  gap: 8px;
  margin: 16px 0 6px;
}

.stat {
  flex: 1;
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 6px;
  box-shadow: var(--cb-shadow-inset);
  transition: transform var(--cb-duration-fast), filter var(--cb-duration-fast);
}

@media (hover: hover) {
  .stat:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
    box-shadow: var(--cb-shadow-inset), var(--cb-shadow-md);
  }
}

.stat .k {
  font-size: 9px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}

.stat .v {
  font-size: 22px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  margin-top: 3px;
  color: var(--accent);
}

.menu-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.menu-row button {
  margin-top: 0;
  padding: 12px 8px;
  font-size: 12px;
  flex: 1 1 calc(50% - 4px);
  min-width: 0;
}

.menu-row .em {
  display: block;
  font-size: 20px;
  margin-bottom: 3px;
}

/* ---- Tutoriel ------------------------------------------------------------ */
/* Gros bouton d'accueil : la porte des règles ne se cherche pas. */
.btn-help {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  letter-spacing: 0.02em;
}

.btn-help .em {
  font-size: 18px;
}

/* La carte du tutoriel respire un peu plus : elle porte un plateau. */
.card.tuto {
  width: min(400px, 92vw);
}

.tuto-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.tdot {
  width: 24px;
  height: 6px;
  border-radius: var(--cb-radius-pill);
  background: var(--line);
  box-shadow: var(--cb-shadow-inset);
  transition: all var(--cb-duration-normal) var(--cb-easing-in-out);
}

.tdot.done {
  background: #4dabff;
  box-shadow: 0 0 8px rgba(77, 171, 255, 0.4);
}

.tdot.on {
  background: var(--accent);
  box-shadow: 0 0 12px rgba(255, 194, 14, 0.6);
  transform: scaleX(1.2);
}

.tuto-step {
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.05em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 8px;
  font-variant-numeric: tabular-nums;
}

.tuto-board {
  display: block;
  width: 240px;
  max-width: 78%;
  height: auto;
  margin: 4px auto 14px;
  border-radius: 18px;
  touch-action: none;
  background: linear-gradient(160deg, #1a2a48, #0d1520);
  border: 1px solid rgba(255, 193, 7, 0.08);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32),
              inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.tuto-hud {
  text-align: start;
  margin: 4px 0 14px;
}

.tuto-line {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 13px;
  margin-bottom: 6px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid var(--line);
  box-shadow: var(--cb-shadow-inset);
}

.tuto-line .em {
  font-size: 20px;
  flex: 0 0 26px;
  text-align: center;
}

.tuto-nav {
  display: flex;
  gap: 8px;
}

.tuto-nav .btn-ghost {
  flex: 0 0 32%;
}

.tuto-nav .btn-primary {
  flex: 1;
}

.tuto-skip {
  margin-top: 10px;
  padding: 10px;
  font-size: 13px;
  background: none;
  border: 0;
  color: var(--muted);
  box-shadow: none;
  cursor: pointer;
  transition: color var(--cb-duration-fast);
}

@media (hover: hover) {
  .tuto-skip:hover {
    color: var(--accent);
    transform: scale(1.04);
  }
}

/* ---- Vestiaire (Looks) ----------------------------------------------------- */
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  text-align: start;
  transition: background var(--cb-duration-fast);
}

@media (hover: hover) {
  .row:hover {
    background: rgba(255, 194, 14, 0.08);
  }
}

.row .em {
  font-size: 28px;
  width: 36px;
  text-align: center;
  flex: 0 0 auto;
}

.row .info {
  flex: 1;
  font-size: 14px;
  font-weight: 800;
  min-width: 0;
  letter-spacing: 0.02em;
}

.row .info small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  margin-top: 3px;
  letter-spacing: 0.02em;
}

.row .buys {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 0 0 auto;
}

.row .buys button {
  margin: 0;
  padding: 8px 12px;
  font-size: 12px;
  width: auto;
  white-space: nowrap;
  font-weight: 700;
}

.row .buys button:disabled {
  opacity: 0.5;
}

/* Mentions honnêtes (cosmétique = zéro effet, achats restaurables). */
.fine {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
  margin: 12px 0 4px;
  text-align: start;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* Titre de rayon à l'intérieur d'un onglet (Plateaux / Couleurs). */
.group-title {
  margin: 14px 0 4px;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: start;
}

/* Aperçu d'un cosmétique : le tapis à gauche, les couleurs à droite. Ce qu'on
   voit ici est exactement ce qui sera peint sur le plateau. */
.swatch {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 1px solid var(--line);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.swatch i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: block;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.row.worn {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  background: rgba(255, 194, 14, 0.08);
}

/* ---- Daily --------------------------------------------------------------- */
.dots {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin: 14px 0 8px;
  flex-wrap: wrap;
}

.dot {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  box-shadow: var(--cb-shadow-inset);
  transition: all var(--cb-duration-fast) var(--cb-easing-bounce);
  font-variant-numeric: tabular-nums;
}

.dot.on {
  background: linear-gradient(180deg, #ffd54f, var(--accent));
  color: var(--accent-ink);
  border-color: transparent;
  box-shadow: 0 4px 12px rgba(255, 193, 7, 0.32);
  transform: scale(1.05);
}

.dot.now {
  outline: 2px solid var(--good);
  outline-offset: 2px;
  animation: pulse-accent 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  box-shadow: 0 0 12px rgba(56, 224, 139, 0.4);
}

/* ---- Notes fugaces (toasts) ---------------------------------------------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(max(22px, env(safe-area-inset-bottom)) + 12px);
  transform: translateX(-50%) translateY(16px) scale(0.95);
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--cb-radius-pill);
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35),
              inset 0 1px 0 rgba(255, 255, 255, 0.08);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--cb-duration-normal), transform var(--cb-duration-normal);
  z-index: 9;
  max-width: 88vw;
  text-align: center;
  letter-spacing: 0.02em;
  backdrop-filter: blur(3px);
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
  pointer-events: auto;
}

/* ---- Animations & Micro-interactions (premium, satisfaisantes) --- */
/* Rebond sur gain de points/victoire */
.pop {
  animation: pop var(--cb-duration-slow) var(--cb-easing-bounce);
}

@keyframes pop {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  12% {
    transform: scale(1.42);
    text-shadow: 0 12px 36px rgba(255, 193, 7, 0.75);
  }
  32% {
    transform: scale(1.32);
    text-shadow: 0 16px 48px rgba(255, 193, 7, 0.85);
  }
  65% {
    transform: scale(1.05);
    text-shadow: 0 8px 20px rgba(255, 193, 7, 0.55);
  }
  100% {
    transform: scale(1);
    opacity: 1;
    text-shadow: 0 6px 16px rgba(255, 193, 7, 0.40);
  }
}

/* Micro animation : chip gagne des points (rotation subtle + scale, plus vif) */
.chip-gain {
  animation: chip-pop var(--cb-duration-normal) var(--cb-easing-bounce);
}

@keyframes chip-pop {
  0% {
    transform: scale(1) rotateZ(-5deg);
    opacity: 1;
    box-shadow: var(--cb-shadow-inset), inset 0 -3px 8px rgba(0, 0, 0, 0.22);
  }
  32% {
    transform: scale(1.30) rotateZ(4deg);
    box-shadow: 0 10px 28px rgba(255, 193, 7, 0.50);
  }
  68% {
    transform: scale(1.08) rotateZ(-2deg);
    box-shadow: 0 5px 14px rgba(255, 193, 7, 0.32);
  }
  100% {
    transform: scale(1) rotateZ(0deg);
    opacity: 1;
    box-shadow: var(--cb-shadow-inset), inset 0 -3px 8px rgba(0, 0, 0, 0.22);
  }
}

/* Pulse doré pour highlights (discret, premium) */
.pulse-accent {
  animation: pulse-accent 2.8s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse-accent {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(255, 193, 7, 0.48);
  }
  50% {
    box-shadow: 0 0 0 12px rgba(255, 193, 7, 0);
  }
}

@media (prefers-color-scheme: light) {
  .pulse-accent {
    animation: pulse-accent-light 2.8s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  }

  @keyframes pulse-accent-light {
    0%, 100% {
      box-shadow: 0 0 0 0 rgba(255, 193, 7, 0.35);
    }
    50% {
      box-shadow: 0 0 0 10px rgba(255, 193, 7, 0);
    }
  }
}

/* Fade pour les icônes qui disparaissent (fluide) */
@keyframes fade-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

/* Slide in depuis le bas (entrée douce) */
@keyframes slide-up {
  from {
    transform: translateY(16px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Victoire : scale + fade pour modal */
@keyframes victory-pop {
  0% {
    transform: scale(0.85) translateY(12px);
    opacity: 0;
  }
  100% {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

/* Pulse discret pour éléments actifs */
@keyframes pulse-subtle {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.85;
  }
}

/* Responsive petit écran : on serre un peu pour que le plateau reste roi. */
@media (max-height: 680px) {
  .logo {
    font-size: 32px;
  }

  .logo-art {
    width: 100px;
    height: 100px;
    margin: 2px auto 6px;
  }

  .card {
    padding: 18px 16px;
  }

  .card .big {
    font-size: 42px;
    margin-top: 2px;
  }

  .card h2 {
    font-size: 20px;
  }

  .tuto-board {
    width: 180px;
  }

  .tuto-line {
    padding: 8px 10px;
    font-size: 12px;
    gap: 8px;
  }

  #wrap {
    gap: 6px;
  }

  .hud {
    gap: 4px;
  }

  .chip {
    padding: 6px 8px;
  }

  .chip .v {
    font-size: 16px;
  }

  button {
    padding: 12px 14px;
    font-size: 15px;
    margin-top: 6px;
  }
}

/* Écrans très petits (< 360px) */
@media (max-width: 360px) {
  :root {
    --r: 14px;
  }

  .brand {
    font-size: 18px;
  }

  .logo {
    font-size: 28px;
  }

  .logo-art {
    width: 90px;
    height: 90px;
  }

  .menu-row button {
    padding: 10px 4px;
    font-size: 11px;
  }

  .card {
    padding: 16px 14px;
    border-radius: 18px;
  }

  button {
    padding: 12px 14px;
    font-size: 15px;
  }

  #wrap {
    padding-left: 8px;
    padding-right: 8px;
    gap: 6px;
  }

  .hud {
    gap: 5px;
  }

  .chip {
    padding: 6px 8px;
    border-radius: 10px;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
  }
}

/* Tablettes et grands écrans : on laisse plus de respiration */
@media (min-width: 768px) {
  #wrap {
    gap: 10px;
    max-width: 540px;
  }

  canvas#c {
    border-radius: 24px;
  }

  .card {
    width: min(420px, 94vw);
    border-radius: 24px;
    padding: 28px 26px;
  }

  .logo {
    font-size: 44px;
  }

  .logo-art {
    width: 160px;
    height: 160px;
  }

  button {
    padding: 16px 20px;
    font-size: 16px;
    margin-top: 12px;
    border-radius: 16px;
  }
}

/* Dark mode explicite (futur support) */
@media (prefers-color-scheme: dark) {
  :root {
    /* déjà en dark par défaut */
  }
}

/* Light mode complet */
@media (prefers-color-scheme: light) {
  /* Déjà défini en haut */
}

/* Respecter reduced-motion : déjà appliqué globalement */
/* Optimisation pour appareils with-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .pop,
  .chip-gain,
  .pulse-accent,
  .chip,
  .tool,
  .dot,
  .tdot,
  #toast {
    animation: none !important;
    transition: none !important;
  }

  .card {
    animation: none;
  }
}

/* RTL : support arabe (direction déjà en body, mais quelques ajustements) */
body[dir="rtl"] .lb .rank {
  text-align: start;
}

body[dir="rtl"] #wrap {
  direction: rtl;
}

/* Focus visible pour accessibilité (CB-ARCADE high contrast) */
button:focus-visible,
input:focus-visible,
.tabs button:focus-visible,
.lang:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(255, 193, 7, 0.18);
}

@media (prefers-contrast: more) {
  button:focus-visible,
  input:focus-visible,
  .tabs button:focus-visible,
  .lang:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
    box-shadow: 0 0 0 6px rgba(255, 193, 7, 0.22);
  }
}

/* Print styles (optionnel) */
@media print {
  body {
    background: white;
  }

  #wrap {
    max-width: 100%;
  }
}
