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

:root {
  --bg-1: #f4f2fb;
  --bg-2: #e9e4fb;
  --surface: #ffffff;
  --surface-alt: #f6f4fd;
  --text: #211b3a;
  --text-dim: #6a6380;
  --primary: #6d5bd0;
  --primary-dark: #5847b8;
  --primary-contrast: #ffffff;
  --accent: #ff8fa3;
  --success: #2fb380;
  --success-bg: #e4f8f0;
  --danger: #e6566f;
  --danger-bg: #fdeaee;
  --border: #e4e0f5;
  --shadow: 0 8px 24px rgba(80, 60, 160, 0.12);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-1: #17132a;
    --bg-2: #1f1a38;
    --surface: #251f42;
    --surface-alt: #2b2450;
    --text: #f1eefc;
    --text-dim: #b3aacf;
    --primary: #9d8bff;
    --primary-dark: #b3a4ff;
    --primary-contrast: #1a1533;
    --accent: #ff9db2;
    --success: #4fd6a2;
    --success-bg: #17362d;
    --danger: #ff7a90;
    --danger-bg: #3a1c26;
    --border: #362e5c;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
  }
}

* { 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; /* évite le zoom automatique sur iOS Safari */
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
  min-height: 100dvh;
}

.view { display: none; animation: fade-in .25s ease; }
.view.active { display: flex; flex-direction: column; gap: 16px; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.hidden { display: none !important; }

/* ---------- En-tête / branding ---------- */

.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; }

/* ---------- Cartes ---------- */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.card h2 {
  margin: 0 0 12px;
  font-size: 16px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---------- Champs ---------- */

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

.field-inline {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; color: var(--text-dim);
  margin: 14px 0;
}
.field-inline input { width: 20px; height: 20px; }

input[type="text"], select {
  padding: 13px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  outline: none;
  transition: border-color .15s ease;
}
input[type="text"]:focus, select:focus { border-color: var(--primary); }
#input-code { text-transform: uppercase; letter-spacing: 0.15em; font-weight: 700; }

.settings-row { display: flex; gap: 12px; }
.settings-row .field { flex: 1; }

/* ---------- Boutons ---------- */

.btn {
  border: none;
  border-radius: 14px;
  padding: 13px 18px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  transition: transform .08s ease, opacity .15s ease, box-shadow .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn[disabled] { opacity: .5; cursor: default; transform: none; }

.btn-primary { background: var(--primary); color: var(--primary-contrast); box-shadow: 0 6px 16px rgba(109, 91, 208, 0.35); }
.btn-secondary { background: var(--surface-alt); color: var(--primary); border: 1.5px solid var(--primary); width: 100%; }
.btn-ghost { background: transparent; color: var(--text-dim); border: 1.5px solid var(--border); }
.btn-big { width: 100%; padding: 16px; font-size: 17px; }

.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 / lobby ---------- */

.topbar { display: flex; align-items: center; justify-content: space-between; }

.icon-btn {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  width: 42px; height: 42px; font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  text-decoration: none; color: var(--text);
}
.icon-btn.small { width: 32px; height: 32px; font-size: 14px; }

.room-code-badge {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 8px 12px;
}
.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: 18px; color: var(--primary); }

/* 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 { 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);
}

.player-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.player-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; 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 .wins-tag { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.player-row .score-tag { font-weight: 800; color: var(--primary); 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); }

/* ---------- Manche : lettre + timer ---------- */

.round-header { display: flex; align-items: center; gap: 14px; }

.letter-badge {
  width: 68px; height: 68px; border-radius: 20px;
  background: linear-gradient(145deg, var(--primary), var(--primary-dark));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 34px; font-weight: 800; box-shadow: var(--shadow); flex-shrink: 0;
}
.letter-badge.small { width: 46px; height: 46px; font-size: 22px; border-radius: 14px; }

.round-meta { flex: 1; min-width: 0; }
.round-progress { font-weight: 700; font-size: 15px; }
.round-timer { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--primary); }
.round-timer.low { color: var(--danger); animation: pulse 1s infinite; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }

.stop-banner {
  background: var(--danger-bg); color: var(--danger); border-radius: 14px;
  padding: 10px 14px; font-weight: 700; text-align: center;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}

.answer-form { display: flex; flex-direction: column; gap: 12px; }
.answer-field { display: flex; flex-direction: column; gap: 6px; }
.answer-field label { font-size: 13px; font-weight: 700; color: var(--text-dim); }
.answer-field input {
  padding: 14px; border-radius: 12px; border: 1.5px solid var(--border);
  background: var(--surface); font-size: 17px;
}
.answer-field input:focus { border-color: var(--primary); outline: none; }

.round-footer { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.others-progress { font-size: 13px; color: var(--text-dim); text-align: center; }

/* ---------- Validation ---------- */

.validation-grid { display: flex; flex-direction: column; gap: 18px; }
.validation-category { background: var(--surface); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.validation-category h3 { margin: 0 0 10px; font-size: 14px; text-transform: uppercase; letter-spacing: .03em; color: var(--text-dim); }

.answer-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px; margin-bottom: 8px;
  background: var(--success-bg); border: 1.5px solid transparent; cursor: pointer;
}
.answer-chip:last-child { margin-bottom: 0; }
.answer-chip.invalid { background: var(--danger-bg); }
.answer-chip.empty { background: var(--surface-alt); opacity: .6; cursor: default; }
.answer-chip .who { font-size: 12px; color: var(--text-dim); min-width: 74px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.answer-chip .word { flex: 1; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.answer-chip .mark { font-size: 18px; flex-shrink: 0; }
.answer-chip .pts { font-size: 12px; font-weight: 800; color: var(--primary); flex-shrink: 0; }

/* ---------- Résultats ---------- */

.section-title { margin: 4px 0 0; font-size: 20px; }
.section-title.center { text-align: center; }

.results-list { display: flex; flex-direction: column; gap: 10px; }
.result-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border-radius: 14px; padding: 12px 14px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
}
.result-row .rank { font-weight: 800; color: var(--text-dim); width: 22px; text-align: center; flex-shrink: 0; }
.result-row.first { border-color: var(--primary); }
.result-row .name { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-row .round-pts { font-size: 13px; color: var(--success); font-weight: 700; white-space: nowrap; }
.result-row .total-pts { font-weight: 800; color: var(--primary); font-size: 18px; white-space: nowrap; }

.confetti-emoji { text-align: center; font-size: 52px; }

/* ---------- Barre d'emoji ---------- */

/* Bouton flottant "Réagir" + popup d'emoji (plutôt qu'une barre fixe en bas,
   qui mangeait de la place utile à l'écran). */
.react-fab {
  position: fixed; right: calc(14px + env(safe-area-inset-right, 0px)); bottom: calc(14px + var(--safe-bottom));
  width: 48px; height: 48px; border-radius: 50%; border: none;
  background: var(--primary); color: var(--primary-contrast); font-size: 22px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  box-shadow: 0 6px 18px rgba(0,0,0,.25); z-index: 45;
}
.react-fab:active { transform: scale(0.92); }

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

/* ---------- Réactions flottantes ---------- */

#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); }
}

/* ---------- Toast / erreurs ---------- */

.toast {
  position: fixed; top: calc(14px + var(--safe-top)); left: 50%; transform: translateX(-50%) translateY(-140%);
  background: var(--danger); 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.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);
}

/* Laisse de la place pour le bouton flottant "Réagir" en bas à droite */
.app { padding-bottom: calc(76px + var(--safe-bottom)); }

@media (min-width: 640px) {
  .brand h1 { font-size: 38px; }
}
