:root {
  --bg-a: #ffe9f1;
  --bg-b: #ece6ff;
  --bg-c: #dff2ff;
  --ink: #3b2a4a;
  --muted: #7c6b8c;
  --card: rgba(255, 255, 255, 0.78);
  --card-border: rgba(255, 255, 255, 0.9);
  --shadow: 0 10px 30px rgba(120, 80, 160, 0.16);
  --louis: #2b86cf;
  --louis-soft: #def0fc;
  --eglantine: #e8478a;
  --eglantine-soft: #ffe0ec;
  --danger: #c0264f;
  --radius: 22px;
  --font: 'Fredoka', ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

:root:not([data-theme='light']) {
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-a: #2a1a3d;
    --bg-b: #1f1730;
    --bg-c: #16213d;
    --ink: #f6eeff;
    --muted: #b6a6c9;
    --card: rgba(255, 255, 255, 0.08);
    --card-border: rgba(255, 255, 255, 0.14);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    --louis: #5db4f2;
    --louis-soft: rgba(93, 180, 242, 0.18);
    --eglantine: #ff7eb0;
    --eglantine-soft: rgba(255, 126, 176, 0.18);
    --danger: #ff8aa8;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg-a), var(--bg-b) 55%, var(--bg-c));
  background-attachment: fixed;
  overflow-x: hidden;
}

.blobs i {
  position: fixed;
  z-index: 0;
  border-radius: 50%;
  filter: blur(50px);
  opacity: 0.45;
  pointer-events: none;
}
.blobs i:nth-child(1) { width: 260px; height: 260px; background: var(--louis); top: -80px; left: -90px; }
.blobs i:nth-child(2) { width: 300px; height: 300px; background: var(--eglantine); bottom: -110px; right: -100px; }
.blobs i:nth-child(3) { width: 180px; height: 180px; background: #ffd37a; top: 45%; left: 55%; opacity: 0.25; }

.shell {
  position: relative;
  z-index: 1;
  max-width: 480px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---------- En-tête ---------- */
.brand { text-align: center; padding: 8px 0 14px; }
.logo {
  margin: 0;
  font-size: 40px;
  font-weight: 700;
  letter-spacing: 4px;
  line-height: 1;
}
.logo {
  background: linear-gradient(90deg, var(--eglantine), #f0a020 50%, var(--louis));
  -webkit-background-clip: text; background-clip: text;
  color: transparent; -webkit-text-fill-color: transparent;
}

main { flex: 1; display: flex; flex-direction: column; gap: 16px; }

/* ---------- Cartes ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 20px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: rise 0.45s ease both;
}
.card h2 { margin: 0 0 6px; font-size: 26px; line-height: 1.15; }
.card p { margin: 0 0 12px; line-height: 1.45; }
.center { text-align: center; }
.muted { color: var(--muted); }
.big-emoji { font-size: 56px; line-height: 1; margin-bottom: 8px; display: block; }

@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ---------- Boutons et champs ---------- */
.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  width: 100%;
  min-height: 54px;
  padding: 14px 22px;
  border-radius: 999px;
  font: inherit;
  font-size: 19px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--louis), var(--eglantine));
  box-shadow: 0 8px 20px rgba(232, 71, 138, 0.28);
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.ghost {
  background: transparent;
  color: var(--ink);
  box-shadow: none;
  border: 2px solid var(--card-border);
  font-size: 16px;
  min-height: 46px;
}

.field {
  width: 100%;
  min-height: 60px;
  padding: 14px 20px;
  border-radius: 18px;
  border: 2px solid transparent;
  background: rgba(255, 255, 255, 0.9);
  color: #3b2a4a;
  font: inherit;
  font-size: 22px; /* ≥ 16 px : pas de zoom automatique sur mobile */
  text-align: center;
  outline: none;
  box-shadow: inset 0 2px 6px rgba(120, 80, 160, 0.1);
}
.field::placeholder { color: #a898b8; }
.field:focus { border-color: var(--eglantine); }

form { display: flex; flex-direction: column; gap: 12px; }
.error { color: var(--danger); min-height: 1.3em; margin: 0 !important; font-weight: 500; text-align: center; }

/* ---------- Mots ---------- */
.chip {
  display: inline-block;
  max-width: 100%;
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 20px;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.chip.louis { background: var(--louis-soft); color: var(--louis); }
.chip.eglantine { background: var(--eglantine-soft); color: var(--eglantine); }
.chip.me { box-shadow: 0 0 0 2px currentColor; }

.pair { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; margin: 10px 0 18px; }
.pair .plus { font-size: 22px; color: var(--muted); }

.round-tag {
  display: inline-block;
  margin-bottom: 10px;
  padding: 4px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.5);
}

/* ---------- Attente ---------- */
.dots { display: inline-flex; gap: 6px; margin-left: 4px; vertical-align: middle; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: 0.4; } 40% { transform: translateY(-7px); opacity: 1; } }

/* ---------- Chemin / historique ---------- */
.path { list-style: none; margin: 14px 0 6px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.path li { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; }
.path .link { color: var(--muted); font-size: 20px; }
.path li:last-child .link.win { color: #f0a020; font-weight: 700; }

details.game { border-top: 1px solid var(--card-border); padding: 10px 0; }
details.game summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; justify-content: space-between; gap: 10px; min-height: 36px; align-items: center; }
details.game summary::-webkit-details-marker { display: none; }
details.game summary small { color: var(--muted); font-weight: 400; }

/* ---------- Révélation ---------- */
.reveal-stage { display: flex; gap: 12px; justify-content: center; perspective: 900px; margin: 12px 0 18px; }
.flip { position: relative; flex: 1 1 0; min-width: 0; height: 190px; transform-style: preserve-3d; transition: transform 0.85s cubic-bezier(0.3, 1.3, 0.5, 1); }
.flip.flipped { transform: rotateY(180deg); }
.flip .face {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 20px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 12px;
  box-shadow: var(--shadow);
  text-align: center;
}
.flip .front { font-size: 64px; font-weight: 700; color: #fff; }
.flip.louis .front { background: linear-gradient(145deg, #6ec0f7, var(--louis)); }
.flip.eglantine .front { background: linear-gradient(145deg, #ff9cc4, var(--eglantine)); }
.flip .back { transform: rotateY(180deg); background: rgba(255, 255, 255, 0.95); color: #3b2a4a; }
.flip.louis .back { border: 3px solid var(--louis); }
.flip.eglantine .back { border: 3px solid var(--eglantine); }
.flip .who { font-size: 14px; font-weight: 600; opacity: 0.85; }
.flip .back .who { color: var(--muted); }
.flip .word { font-size: clamp(20px, 6vw, 28px); font-weight: 700; line-height: 1.1; overflow-wrap: anywhere; word-break: break-word; max-width: 100%; }

.reveal-after { opacity: 0; transform: translateY(10px); transition: opacity 0.5s ease, transform 0.5s ease; pointer-events: none; }
.reveal-after.show { opacity: 1; transform: none; pointer-events: auto; }

/* ---------- Décompte plein écran ---------- */
.countdown {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  background: linear-gradient(160deg, var(--bg-a), var(--bg-b) 55%, var(--bg-c));
  cursor: pointer;
  user-select: none; -webkit-user-select: none;
  transition: opacity 0.35s ease;
}
.countdown[hidden] { display: none; }
.countdown.leaving { opacity: 0; }
.countdown-ring {
  position: absolute;
  width: min(70vw, 360px); height: min(70vw, 360px);
  border-radius: 50%;
  background: conic-gradient(var(--louis), #f0a020, var(--eglantine), var(--louis));
  opacity: 0.22;
  filter: blur(6px);
  animation: spin 3s linear infinite;
}
.count-num {
  position: relative;
  font-size: min(48vw, 260px);
  font-weight: 700;
  line-height: 1;
  background: linear-gradient(135deg, var(--louis), var(--eglantine));
  -webkit-background-clip: text; background-clip: text;
  color: transparent; -webkit-text-fill-color: transparent;
}
.count-num.pop { animation: pop 1.3s cubic-bezier(0.2, 1.4, 0.4, 1) both; }
@keyframes pop { 0% { transform: scale(0.3); opacity: 0; } 35% { transform: scale(1.12); opacity: 1; } 70% { transform: scale(1); opacity: 1; } 100% { transform: scale(0.92); opacity: 0.2; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Confettis ---------- */
.confetti { position: fixed; inset: 0; z-index: 40; pointer-events: none; overflow: hidden; }
.confetti span { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ---------- Divers ---------- */
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 60; background: #3b2a4a; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 15px; }

button:focus-visible, .field:focus-visible, summary:focus-visible { outline: 3px solid var(--louis); outline-offset: 2px; }

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