/* ===========================================================
   Slam en ligne — styles
   Mobile-first, compatible iOS Safari / Android Chrome & Firefox
   =========================================================== */

:root {
  --bg-1: #fff3ea; --bg-2: #ffe3cf; --surface: #ffffff; --surface-alt: #fff6ef;
  --text: #2a1a10; --text-dim: #8a6a55; --primary: #c2410c; --primary-dark: #9a330a;
  --primary-contrast: #ffffff; --accent: #d9a441; --success: #2c9d63; --success-bg: #e2f5ea;
  --danger: #d13a3a; --danger-bg: #fdeaea; --border: #f2d9c4; --shadow: 0 8px 24px rgba(120, 60, 10, .14);
  --radius: 18px; --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  --cell-empty: #f4e4d4; --slam-glow: #ff7a1a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-1: #1c1108; --bg-2: #241608; --surface: #2a1c10; --surface-alt: #322213;
    --text: #fbead9; --text-dim: #cbab8f; --primary: #f0793a; --primary-dark: #ff9a5e;
    --primary-contrast: #201205; --accent: #e8bd6a; --success: #57c98a; --success-bg: #133a26;
    --danger: #ff7a7a; --danger-bg: #3a1c1c; --border: #40291a; --shadow: 0 8px 28px rgba(0,0,0,.5);
    --cell-empty: #3a2716;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text); background: radial-gradient(circle at 20% -10%, var(--bg-2), var(--bg-1) 60%);
  -webkit-font-smoothing: antialiased; touch-action: manipulation; overscroll-behavior-y: contain;
}
button, input, select { font-family: inherit; font-size: 16px; }

.app { max-width: 560px; margin: 0 auto; padding: calc(14px + var(--safe-top)) 12px calc(100px + var(--safe-bottom)); min-height: 100dvh; }
.view { display: none; animation: fade-in .25s ease; }
.view.active { display: flex; flex-direction: column; gap: 12px; }
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.hidden { display: none !important; }

.brand { text-align: center; margin-top: 8px; }
.brand-emoji { font-size: 48px; line-height: 1; }
.brand h1 { margin: 4px 0 2px; font-size: 32px; letter-spacing: -0.02em; }
.subtitle { margin: 0; color: var(--text-dim); font-size: 15px; }

.card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.card h2 { margin: 0 0 12px; font-size: 15px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field > span { font-size: 13px; color: var(--text-dim); font-weight: 600; }

/* Case à cocher inline (Mode Bénéficiaire AAH, voir public/shared/AAH_MODE.md
   — motif dupliqué depuis games/petit-bac/public/style.css, chaque jeu de
   cette plateforme restant autonome pour son propre CSS). */
.field-inline { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text-dim); margin: 12px 0; }
.field-inline input { width: 20px; height: 20px; flex-shrink: 0; }
input[type="text"], select {
  padding: 12px 13px; border-radius: 12px; border: 1.5px solid var(--border);
  background: var(--surface-alt); color: var(--text); outline: none; transition: border-color .15s ease; width: 100%;
}
input:focus, select:focus { border-color: var(--primary); }
#input-code { text-transform: uppercase; letter-spacing: 0.15em; font-weight: 700; }

.btn {
  border: none; border-radius: 14px; padding: 12px 16px; font-weight: 700; font-size: 14.5px;
  cursor: pointer; transition: transform .08s ease, opacity .15s ease; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn[disabled] { opacity: .45; cursor: default; transform: none; }
.btn-primary { background: var(--primary); color: var(--primary-contrast); box-shadow: 0 6px 16px rgba(194,65,12,.35); }
.btn-secondary { background: var(--surface-alt); color: var(--primary); border: 1.5px solid var(--primary); }
.btn-ghost { background: transparent; color: var(--text-dim); border: 1.5px solid var(--border); }
.btn-slam { background: linear-gradient(135deg, #ff7a1a, #d13a3a); color: #fff; box-shadow: 0 6px 16px rgba(209,58,58,.35); }
.btn-big { width: 100%; padding: 15px; font-size: 16px; }
.btn-sm { padding: 8px 12px; font-size: 13px; border-radius: 10px; }

.landing-actions { display: flex; flex-direction: column; }
.landing-actions .btn-primary { margin-bottom: 4px; }
.divider { text-align: center; color: var(--text-dim); font-size: 13px; margin: 14px 0; position: relative; }
.divider::before, .divider::after { content: ""; position: absolute; top: 50%; width: 40%; height: 1px; background: var(--border); }
.divider::before { left: 0; } .divider::after { right: 0; }
.hint { color: var(--text-dim); font-size: 13px; text-align: center; line-height: 1.5; margin: 0; }
.hint.tight { text-align: left; margin-top: 4px; }

.topbar { display: flex; align-items: center; justify-content: space-between; }
.icon-btn { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; width: 40px; height: 40px; font-size: 17px; cursor: pointer; display: flex; align-items: center; justify-content: center; text-decoration: none; color: var(--text); }
.icon-btn.small { width: 30px; height: 30px; font-size: 13px; }
.room-code-badge { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 7px 11px; }
.room-code-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; }
.room-code-value { font-weight: 800; letter-spacing: 0.15em; font-size: 17px; color: var(--primary); }

.player-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.player-row { display: flex; align-items: center; gap: 9px; padding: 9px 11px; border-radius: 12px; background: var(--surface-alt); }
.player-row .dot { width: 9px; height: 9px; border-radius: 50%; background: #bbb; flex-shrink: 0; }
.player-row .dot.online { background: var(--success); }
.player-row .name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-row .host-tag { font-size: 11px; background: var(--primary); color: var(--primary-contrast); padding: 2px 7px; border-radius: 20px; }
.player-row .stats-tag { font-size: 12px; color: var(--text-dim); white-space: nowrap; }

.chip-toggle-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 8px 14px; border-radius: 20px; border: 1.5px solid var(--border); background: var(--surface-alt); color: var(--text-dim); font-size: 14px; font-weight: 600; cursor: pointer; user-select: none; }
.chip.active { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.settings-row { display: flex; flex-direction: column; gap: 12px; margin-top: 4px; }

.section-title { margin: 4px 0 0; font-size: 20px; }
.section-title.center { text-align: center; }
.confetti-emoji { text-align: center; font-size: 52px; }
.round-footer { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }

.event-log { font-size: 12px; color: var(--text-dim); line-height: 1.7; max-height: 130px; overflow-y: auto; }
.log-entry:first-child { color: var(--text); font-weight: 600; }
.log-entry-enter { animation: logIn .32s cubic-bezier(.22,1,.36,1); }
@keyframes logIn { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* ---------- En-tête de partie ---------- */

.slam-header { display: flex; flex-direction: column; gap: 8px; }
.slam-header-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; flex-wrap: wrap; }
.level-badge { font-size: 12.5px; font-weight: 700; padding: 6px 11px; border-radius: 20px; background: var(--surface); border: 1px solid var(--border); }
.score-badge { font-size: 13.5px; font-weight: 800; padding: 6px 12px; border-radius: 20px; background: var(--accent); color: #2a1a10; border: 1px solid var(--accent); }
.game-progress { font-size: 12.5px; font-weight: 700; color: var(--text-dim); }
.timer-bar-wrap { height: 8px; border-radius: 6px; background: var(--surface-alt); overflow: hidden; border: 1px solid var(--border); }
.timer-bar { height: 100%; background: var(--primary); width: 100%; transition: width .2s linear; }
.timer-bar.low { background: var(--danger); }
.game-timer-text { text-align: center; font-size: 12px; color: var(--text-dim); }

/* ---------- Parcours (paliers / grilles) ---------- */

.tier-block { margin-bottom: 16px; }
.tier-block:last-child { margin-bottom: 0; }
.tier-block h3 { margin: 0 0 8px; font-size: 14px; }
.tier-grid-list { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.tier-grid-tile {
  position: relative; aspect-ratio: 1; border-radius: 10px; border: 1.5px solid var(--border);
  background: var(--surface-alt); color: var(--text-dim); font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.tier-grid-tile.active { border-color: var(--primary); background: var(--surface); color: var(--primary); box-shadow: 0 0 0 2px rgba(194,65,12,.18); }
.tier-grid-tile.done { border-color: var(--success); }
.tier-grid-tile.readonly { cursor: default; }
.tier-grid-tile .done-mark { position: absolute; top: -5px; right: -5px; font-size: 12px; background: var(--success); color: #fff; border-radius: 50%; width: 16px; height: 16px; display: flex; align-items: center; justify-content: center; }

/* ---------- Grille ---------- */

.slam-grid-wrap { display: flex; justify-content: center; overflow-x: auto; padding: 6px 0; }
.slam-grid { display: grid; gap: 4px; background: transparent; }
.slam-cell {
  width: 38px; height: 38px; background: var(--surface); border: 1.5px solid var(--border); border-radius: 7px;
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 17px; position: relative;
  transition: box-shadow .15s ease, border-color .15s ease, transform .1s ease;
}
.slam-cell.empty { background: var(--cell-empty); color: transparent; border-color: transparent; }
.slam-cell.filled { background: var(--success-bg); border-color: var(--success); color: var(--success); }
.slam-cell.active-word { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(194,65,12,.25); }
.slam-cell.has-number { cursor: pointer; }
/* Case dont un mot est actuellement sélectionnable : c'est ici que l'œil
   doit être attiré (demande explicite de lisibilité) — halo pulsant. */
.slam-cell.selectable { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(217,164,65,.35); animation: cell-pulse 1.8s ease-in-out infinite; }
.slam-cell.selectable:active { transform: scale(0.92); }
@keyframes cell-pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(217,164,65,.35); }
  50% { box-shadow: 0 0 0 5px rgba(217,164,65,.15); }
}
.slam-cell.wrong-flash { animation: cell-shake .4s ease; }
@keyframes cell-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}
.slam-cell .cell-number { position: absolute; top: 1px; left: 2px; font-size: 8px; font-weight: 800; color: var(--text-dim); line-height: 1; }
.slam-cell .cell-arrow { position: absolute; font-size: 9px; font-weight: 900; color: var(--border); line-height: 1; }
.slam-cell .cell-arrow.dir-h { top: 2px; right: 2px; }
.slam-cell .cell-arrow.dir-v { bottom: 2px; right: 2px; }
.slam-cell .cell-arrow.ready { color: var(--primary); }

/* ---------- Panneau de phase ---------- */

#phase-panel h3 { margin: 0 0 8px; font-size: 15.5px; }
.question-text { font-size: 16px; font-weight: 600; margin: 0 0 12px; line-height: 1.4; }
.answer-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.answer-row > span { font-size: 12px; color: var(--text-dim); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }

.fill-clue { font-size: 15px; font-weight: 700; margin: 0 0 4px; }
.fill-meta { font-size: 12.5px; color: var(--text-dim); margin: 0 0 10px; }
.fill-input-row { display: flex; gap: 8px; }
.fill-input-row input { flex: 1; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.slam-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 800; color: var(--slam-glow); }

/* Bouton "valider ma réponse" + indicateur prêt (phase question) */
.lock-row { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.lock-row .btn { flex: 1; }
.ready-indicator { font-size: 12.5px; font-weight: 700; color: var(--text-dim); white-space: nowrap; }
.ready-indicator.ready { color: var(--success); }

/* Bandeau SLAM (phase 'slam') */
.slam-banner {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px; margin-bottom: 12px;
  background: linear-gradient(135deg, rgba(255,122,26,.16), rgba(209,58,58,.16)); border: 1.5px solid var(--slam-glow);
}
.slam-banner .icon { font-size: 22px; }
.slam-banner b { color: var(--slam-glow); }

/* ---------- Fin de partie ---------- */

.summary-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.summary-row:last-child { border-bottom: none; }
.summary-row b { font-size: 16px; }

/* ---------- Emoji / réactions / toast ---------- */

.react-fab {
  position: fixed; right: calc(14px + env(safe-area-inset-right, 0px)); bottom: calc(14px + var(--safe-bottom));
  width: 46px; height: 46px; border-radius: 50%; border: none;
  background: var(--primary); color: var(--primary-contrast); font-size: 20px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  box-shadow: 0 6px 18px rgba(0,0,0,.3); z-index: 45;
}
.react-fab:active { transform: scale(0.92); }

/* Bouton SLAM unique, en bas à gauche pour ne jamais gêner les réactions
   (bas à droite) — halo animé pour rester bien visible sans être criard. */
.slam-fab {
  position: fixed; left: calc(14px + env(safe-area-inset-left, 0px)); bottom: calc(14px + var(--safe-bottom));
  display: flex; align-items: center; gap: 6px; border: none; border-radius: 26px; padding: 11px 16px 11px 12px;
  background: linear-gradient(135deg, #ff7a1a, #d13a3a); color: #fff; font-weight: 800; font-size: 14px;
  cursor: pointer; box-shadow: 0 6px 18px rgba(209,58,58,.45); z-index: 45;
  animation: slam-fab-glow 2.4s ease-in-out infinite;
}
.slam-fab-icon { font-size: 18px; }
.slam-fab:active { transform: scale(0.94); }
.slam-fab[disabled] { opacity: .5; animation: none; cursor: default; }
@keyframes slam-fab-glow {
  0%, 100% { box-shadow: 0 6px 18px rgba(209,58,58,.45); }
  50% { box-shadow: 0 6px 26px rgba(255,122,26,.65); }
}

.reaction-picker {
  position: fixed; right: calc(14px + env(safe-area-inset-right, 0px)); bottom: calc(68px + var(--safe-bottom));
  background: rgba(30, 18, 10, 0.92); border-radius: 22px; padding: 8px;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 4px;
  max-width: min(80vw, 230px); z-index: 46; box-shadow: var(--shadow);
}
.reaction-choice { border: none; background: none; font-size: 20px; padding: 6px; cursor: pointer; border-radius: 50%; line-height: 1; }
.reaction-choice:active { background: rgba(255,255,255,0.18); transform: scale(1.15); }

#reaction-layer { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 60; }
.floating-reaction { position: absolute; bottom: 90px; display: flex; flex-direction: column; align-items: center; animation: float-up 2.6s ease-out forwards; }
.floating-reaction .emoji { font-size: 40px; filter: drop-shadow(0 4px 8px rgba(0,0,0,.25)); }
.floating-reaction .who { font-size: 11px; font-weight: 700; color: var(--text-dim); background: var(--surface); padding: 2px 8px; border-radius: 20px; margin-top: 2px; }
@keyframes float-up {
  0% { opacity: 0; transform: translateY(20px) scale(.6) rotate(-6deg); }
  15% { opacity: 1; transform: translateY(-10px) scale(1.05) rotate(3deg); }
  85% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-260px) scale(1) rotate(-4deg); }
}

/* ---------- Retour visuel bonne/mauvaise réponse + victoire ---------- */

.flash-overlay {
  position: fixed; inset: 0; pointer-events: none; z-index: 70; opacity: 0;
}
.flash-overlay.flash-correct { background: radial-gradient(circle, rgba(44,157,99,.28), transparent 70%); animation: flash-pop .55s ease-out; }
.flash-overlay.flash-wrong { background: radial-gradient(circle, rgba(209,58,58,.3), transparent 70%); animation: flash-pop .5s ease-out; }
@keyframes flash-pop {
  0% { opacity: 0; }
  20% { opacity: 1; }
  100% { opacity: 0; }
}

.confetti-layer { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 71; }
.confetti-piece {
  position: absolute; top: -20px; width: 9px; height: 14px; opacity: 0;
  animation: confetti-fall 2.4s ease-in forwards;
}
@keyframes confetti-fall {
  0% { opacity: 1; transform: translateY(0) rotate(0deg); }
  100% { opacity: 0.9; transform: translateY(110vh) rotate(540deg); }
}

/* Feux d'artifice : particules qui partent en éventail depuis un point puis
   s'estompent (distinct des confettis qui tombent) — décalage --dx/--dy posé
   en JS par burst. */
.firework-particle {
  position: absolute; width: 6px; height: 6px; border-radius: 50%; opacity: 0;
  animation: firework-burst 1s ease-out forwards;
}
@keyframes firework-burst {
  0% { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(.3); }
}

.toast { position: fixed; top: calc(14px + var(--safe-top)); left: 50%; transform: translateX(-50%) translateY(-140%); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow); z-index: 80; transition: transform .25s ease; max-width: 90%; text-align: center; }
.toast.toast-danger { background: var(--danger); }
.toast.toast-success { background: var(--success); }
.toast.show { transform: translateX(-50%) translateY(0); }
.connection-banner { position: fixed; top: calc(14px + var(--safe-top)); left: 50%; transform: translateX(-50%); background: #333; color: #fff; padding: 8px 16px; border-radius: 20px; font-size: 13px; z-index: 80; box-shadow: var(--shadow); }

/* ---------- Pop-up de révélation (réponse invalidée) ----------
   Plus visible qu'un simple toast en haut d'écran (jugé "trop discret" par
   l'utilisateur) : carte centrée avec fond assombri, reste affichée le temps
   configuré par l'hôte (`revealPopupMs`, voir app.js) plutôt qu'une durée
   fixe et courte. */
/* pointer-events: none en permanence — la question suivante démarre
   souvent immédiatement (une réponse ratée ne passe plus par la phase
   choix, voir DESIGN.md v5) : le pop-up ne doit jamais bloquer la saisie
   du tour déjà en cours en dessous, juste rester visible le temps de lire. */
.reveal-popup {
  position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: rgba(0, 0, 0, .45); opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.reveal-popup.show { opacity: 1; }
.reveal-popup-card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px 24px; max-width: 420px; width: 100%; text-align: center;
  border-top: 6px solid var(--danger); transform: scale(.92); transition: transform .2s ease;
}
.reveal-popup.show .reveal-popup-card { transform: scale(1); }
.reveal-popup.reveal-success .reveal-popup-card { border-top-color: var(--success); }
.reveal-popup-title { font-size: 15px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 8px; }
.reveal-popup-answer { font-size: 22px; font-weight: 800; color: var(--text); margin-bottom: 6px; }
.reveal-popup-explanation { font-size: 15px; color: var(--text-dim); line-height: 1.4; }

@media (min-width: 640px) {
  .brand h1 { font-size: 38px; }
  .slam-cell { width: 36px; height: 36px; font-size: 16px; }
}

/* Salon d'attente unifié visuellement sur le modèle du 8-américain */
.lobby-card { text-align: center; }
.lobby-card h2 { text-transform: none; font-size: 20px; color: var(--text); letter-spacing: normal; }
.lobby-card .room-code-label {
  text-align: center; color: var(--text-dim); margin: 10px 0 6px;
  font-size: 13px; text-transform: none;
}
.lobby-card .room-code-badge { justify-content: center; margin: 0 auto 4px; width: fit-content; }
.players-title {
  margin: 20px 0 10px; font-size: 13px; font-weight: 700; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .04em; text-align: left;
}
.lobby-card .player-list,
.lobby-card #host-settings,
.lobby-card #guest-waiting,
.lobby-card #path-picker { text-align: left; }
.lobby-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }
.lobby-actions .icon-btn {
  width: auto; height: auto; padding: 13px 18px; border-radius: 14px;
  font-size: 15px; font-weight: 700; background: transparent; color: var(--text-dim);
  border: 1.5px solid var(--border);
}
