/* =========================================================
   Dilemme Parfait — theme cartoon facon Gartic Phone
   Contours noirs epais, couleurs vives, ombres dures, fun.
   ========================================================= */

:root {
  --ink: #1b1b2f;
  --paper: #fff8ee;
  --pink: #ff5fa2;
  --pink-d: #e8307f;
  --yellow: #ffd23f;
  --yellow-d: #f2b705;
  --blue: #4dc4ff;
  --blue-d: #2196d6;
  --green: #4ade80;
  --green-d: #22b85f;
  --red: #ff6b6b;
  --red-d: #e84545;
  --purple: #a78bfa;
  --orange: #ff9f43;

  --shadow: 4px 4px 0 var(--ink);
  --shadow-lg: 6px 6px 0 var(--ink);
  --radius: 22px;
  --border: 4px solid var(--ink);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: 'Baloo 2', system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 20%, #ffe3f1 0%, transparent 45%),
    radial-gradient(circle at 80% 30%, #d9f3ff 0%, transparent 45%),
    radial-gradient(circle at 50% 90%, #fff3cf 0%, transparent 50%),
    #ffeede;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- blobs de fond animes ---------- */
.bg-blobs { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.blob {
  position: absolute; border-radius: 50%;
  border: var(--border); opacity: 0.5;
  animation: float 9s ease-in-out infinite;
}
.b1 { width: 120px; height: 120px; background: var(--pink); top: 8%; left: 6%; animation-delay: 0s; }
.b2 { width: 90px; height: 90px; background: var(--yellow); top: 70%; left: 12%; animation-delay: 1.5s; }
.b3 { width: 140px; height: 140px; background: var(--blue); top: 18%; right: 8%; animation-delay: 0.8s; }
.b4 { width: 70px; height: 70px; background: var(--green); bottom: 12%; right: 14%; animation-delay: 2.2s; }
@keyframes float {
  0%,100% { transform: translateY(0) rotate(0); }
  50% { transform: translateY(-26px) rotate(8deg); }
}

#app { position: relative; z-index: 1; min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 18px; }

/* ---------- ecrans ---------- */
.screen { display: none; width: 100%; max-width: 560px; flex-direction: column; align-items: center; animation: pop 0.35s cubic-bezier(.18,1.2,.4,1); }
.screen.active { display: flex; }
@keyframes pop { from { opacity: 0; transform: scale(.92) translateY(14px); } to { opacity: 1; transform: scale(1) translateY(0); } }

/* ---------- carte ---------- */
.card {
  background: var(--paper);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 28px 26px 26px;
  width: 100%;
  text-align: center;
  position: relative;
}

.screen-title {
  font-size: 30px; font-weight: 800; letter-spacing: .5px;
  margin-bottom: 6px; text-transform: uppercase;
}
.sub { font-size: 16px; opacity: .8; margin: 8px 0 18px; font-weight: 600; }

/* ---------- logo / hero ---------- */
.hero-card { padding-top: 34px; }
.logo {
  font-size: 56px; font-weight: 800; line-height: .9; text-transform: uppercase;
  color: var(--pink); -webkit-text-stroke: 3px var(--ink);
  text-shadow: 5px 5px 0 var(--ink);
  transform: rotate(-3deg); margin-bottom: 8px;
}
.logo span { color: var(--yellow); }
.tagline { font-size: 17px; font-weight: 600; margin: 14px 4px 22px; }

/* ---------- champs ---------- */
.field { margin-bottom: 16px; text-align: left; }
.field label { display: block; font-weight: 700; margin-bottom: 6px; font-size: 15px; }
input[type=text], textarea {
  width: 100%; font-family: inherit; font-size: 18px; font-weight: 600;
  padding: 14px 16px; border: var(--border); border-radius: 16px;
  background: #fff; color: var(--ink); outline: none;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.06);
}
textarea { resize: none; line-height: 1.4; }
input:focus, textarea:focus { border-color: var(--pink); box-shadow: 0 0 0 3px var(--pink); }
input::placeholder, textarea::placeholder { color: #b9b3a8; }

.char-count { text-align: right; font-size: 13px; font-weight: 700; opacity: .55; margin-top: 4px; }

/* ---------- boutons ---------- */
.btn {
  font-family: inherit; font-weight: 800; font-size: 18px; cursor: pointer;
  border: var(--border); border-radius: 16px; padding: 13px 22px;
  background: #fff; color: var(--ink); box-shadow: var(--shadow);
  transition: transform .08s, box-shadow .08s, background .15s;
  text-transform: uppercase; letter-spacing: .3px;
  -webkit-user-select: none; user-select: none;
}
.btn:hover { transform: translate(-1px,-1px); box-shadow: 5px 5px 0 var(--ink); }
.btn:active { transform: translate(3px,3px); box-shadow: 1px 1px 0 var(--ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: var(--shadow); }
.btn-big { width: 100%; font-size: 20px; padding: 16px; }
.btn-primary { background: var(--yellow); }
.btn-primary:hover { background: var(--yellow-d); }
.btn-secondary { background: var(--blue); color: #fff; }
.btn-secondary:hover { background: var(--blue-d); }
.btn-ghost { background: transparent; box-shadow: none; border-color: transparent; opacity: .75; font-size: 15px; padding: 8px 14px; }
.btn-ghost:hover { box-shadow: none; opacity: 1; background: rgba(0,0,0,.05); }
.btn-leave { margin-top: 16px; }
.btn-copy { font-size: 14px; padding: 7px 12px; margin-top: 8px; background: #fff; }

/* ---------- divider ---------- */
.divider { display: flex; align-items: center; gap: 12px; margin: 20px 0; opacity: .6; }
.divider::before, .divider::after { content: ''; flex: 1; height: 3px; background: var(--ink); border-radius: 3px; }
.divider span { font-weight: 800; }

/* ---------- rejoindre ---------- */
.join-field { display: flex; gap: 10px; align-items: stretch; }
.code-input { text-transform: uppercase; letter-spacing: 8px; text-align: center; font-size: 26px; font-weight: 800; }
.join-field .btn { white-space: nowrap; }

.error-msg { color: var(--red-d); font-weight: 700; min-height: 22px; margin-top: 6px; }

.credits { margin-top: 18px; font-weight: 600; opacity: .65; font-family: 'Patrick Hand', cursive; font-size: 18px; }

/* ---------- code du salon ---------- */
.room-code-box { background: var(--blue); border: var(--border); border-radius: 18px; padding: 14px; margin: 6px 0 8px; box-shadow: var(--shadow); }
.room-code-box .label { font-weight: 700; color: #fff; text-transform: uppercase; font-size: 13px; letter-spacing: 1px; }
.code-big { font-size: 46px; font-weight: 800; letter-spacing: 10px; color: #fff; -webkit-text-stroke: 2px var(--ink); }
.code-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.room-code-box-sm { margin: 14px 0; padding: 12px; }
.room-code-box-sm .code-big { font-size: 34px; letter-spacing: 7px; }
.code-hint { color: #fff; opacity: .85; font-size: 13px; font-weight: 600; margin-top: 6px; }

/* ---------- indice de lien de partage (accueil) ---------- */
.join-hint { background: var(--yellow); border: var(--border); border-radius: 14px; padding: 8px 12px; font-weight: 700; font-size: 14px; margin-top: 8px; box-shadow: var(--shadow); }

/* Petit credit discret sous la carte d'accueil */
.credit-note { margin: 16px auto 0; max-width: 420px; font-size: 12px; line-height: 1.5; font-weight: 600; color: rgba(27,27,47,.6); text-align: center; }
.credit-note a { color: var(--pink-d); text-decoration: underline; font-weight: 700; }

/* ---------- accueil simplifie quand on arrive via un lien ---------- */
/* On ne montre que : pseudo + bouton Rejoindre (+ l'indice de salon). */
.join-via-link #btn-create,
.join-via-link .divider,
.join-via-link .code-input { display: none; }
.join-via-link .join-field { display: block; }
.join-via-link .join-field .btn {
  width: 100%;
  font-size: 20px;
  padding: 16px 22px;
  background: var(--yellow);
}
.join-via-link .join-field .btn:hover { background: var(--yellow-d); }

/* ---------- grille de joueurs ---------- */
.players-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px,1fr)); gap: 12px; margin: 18px 0; }
.player-chip {
  display: flex; align-items: center; gap: 8px; background: #fff; border: var(--border);
  border-radius: 14px; padding: 9px 11px; box-shadow: 3px 3px 0 var(--ink);
  font-weight: 700; animation: pop .3s; position: relative; text-align: left;
}
.player-chip .pa { font-size: 26px; line-height: 1; }
.player-chip .pn { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.player-chip.host { background: var(--yellow); }
.player-chip.disconnected { opacity: .4; filter: grayscale(1); }
.player-chip .crown { position: absolute; top: -12px; right: -6px; font-size: 20px; transform: rotate(18deg); }
.player-chip .tick { position: absolute; top: -10px; left: -8px; font-size: 18px; }
.player-chip .score-badge { background: var(--ink); color: #fff; border-radius: 10px; padding: 1px 8px; font-size: 13px; }
.give-lead {
  font-family: inherit; cursor: pointer; font-size: 15px; line-height: 1;
  border: 2px solid var(--ink); border-radius: 9px; background: #fff;
  padding: 3px 6px; box-shadow: 2px 2px 0 var(--ink); transition: transform .08s, background .15s;
  filter: grayscale(1); opacity: .7;
}
.give-lead:hover { background: var(--yellow); filter: none; opacity: 1; transform: translate(-1px,-1px); }
.give-lead:active { transform: translate(1px,1px); box-shadow: 1px 1px 0 var(--ink); }
.score-row .give-lead { margin-right: 4px; }

.lobby-actions { margin-top: 8px; }
.waiting-host { font-weight: 700; opacity: .7; font-style: italic; }

/* ---------- round pill ---------- */
.round-pill { display: inline-block; background: var(--purple); color: #fff; border: var(--border); border-radius: 999px; padding: 5px 18px; font-weight: 800; box-shadow: 3px 3px 0 var(--ink); margin-bottom: 12px; text-transform: uppercase; }

/* ---------- prompt preview ---------- */
.prompt-preview { margin-top: 12px; background: #fff; border: 3px dashed var(--ink); border-radius: 14px; padding: 12px; font-size: 17px; font-weight: 700; }
.prompt-preview b { color: var(--pink-d); }
.prompt-buttons { display: flex; gap: 10px; }
.prompt-buttons .btn-big { flex: 1; }

/* ---------- attente ---------- */
.wait-block { padding: 24px 0; }
.big-emoji { font-size: 64px; animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 0%,100%{ transform: translateY(0);} 50%{ transform: translateY(-10px);} }
.dots { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }
.dots span { width: 12px; height: 12px; border-radius: 50%; background: var(--ink); animation: dots 1.2s infinite; }
.dots span:nth-child(2){ animation-delay: .2s; } .dots span:nth-child(3){ animation-delay: .4s; }
@keyframes dots { 0%,100%{ transform: scale(.6); opacity:.4; } 50%{ transform: scale(1.1); opacity:1; } }
.wait-inline { font-weight: 700; font-style: italic; opacity: .7; margin-top: 14px; }

/* ---------- phrase a completer ---------- */
.phrase-display { background: #fff; border: var(--border); border-radius: 18px; padding: 18px; margin: 8px 0 20px; box-shadow: var(--shadow); font-size: 22px; font-weight: 700; line-height: 1.4; }
.phrase-mais { display: inline-block; background: var(--pink); color: #fff; border-radius: 8px; padding: 1px 10px; margin: 0 4px; transform: rotate(-2deg); border: 2px solid var(--ink); }
.phrase-blank { color: var(--pink-d); }

.ready-track { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 16px; font-weight: 700; opacity: .85; }

/* ---------- vote ---------- */
.vote-card { overflow: hidden; }
.vote-counter { font-weight: 800; color: var(--purple); font-size: 18px; margin-bottom: 8px; }
.vote-phrase-card { background: #fff; border: var(--border); border-radius: 18px; padding: 26px 18px; margin-bottom: 20px; box-shadow: var(--shadow); min-height: 120px; display: flex; align-items: center; justify-content: center; animation: pop .3s; }
.vote-phrase { font-size: 22px; font-weight: 700; line-height: 1.45; }
.vote-phrase .m { background: var(--pink); color:#fff; border-radius:8px; padding:1px 9px; border:2px solid var(--ink); }
.vote-buttons { display: flex; gap: 14px; }
.vote-buttons .btn { flex: 1; font-size: 22px; padding: 20px; }
.vote-yes { background: var(--green); color: #fff; }
.vote-yes:hover { background: var(--green-d); }
.vote-no { background: var(--red); color: #fff; }
.vote-no:hover { background: var(--red-d); }

/* ---------- resultats / suspense ---------- */
.results-card { overflow: hidden; }
.result-counter { font-weight: 800; color: var(--purple); margin-bottom: 6px; }
.result-avatar { font-size: 58px; animation: bob 1.6s ease-in-out infinite; }
.result-phrase { font-size: 20px; font-weight: 700; line-height: 1.4; margin: 6px 0; background:#fff; border:var(--border); border-radius:16px; padding:14px; box-shadow: var(--shadow); }
.result-phrase .m { background: var(--pink); color:#fff; border-radius:8px; padding:1px 9px; border:2px solid var(--ink); }
.result-author { font-weight: 700; opacity: .75; margin-bottom: 18px; font-style: italic; }

.meter { margin: 16px 0; }
.meter-bar {
  position: relative; height: 42px; border: var(--border); border-radius: 999px;
  overflow: hidden; box-shadow: var(--shadow);
  background: linear-gradient(90deg, var(--red) 0%, var(--red) 100%);
}
.meter-fill {
  position: absolute; inset: 0; right: auto; width: 50%;
  background: var(--green);
  border-right: 4px solid var(--ink);
  transition: width .12s linear;
}
.meter-mid { position: absolute; top: -6px; bottom: -6px; left: 50%; width: 4px; background: var(--ink); transform: translateX(-50%); opacity: .35; }
.meter-labels { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; font-weight: 800; }
.meter-percent { font-size: 26px; background: var(--yellow); border: var(--border); border-radius: 12px; padding: 2px 14px; box-shadow: 3px 3px 0 var(--ink); }
.non-label { color: var(--red-d); } .oui-label { color: var(--green-d); }

.result-verdict { font-size: 19px; font-weight: 800; min-height: 30px; margin: 14px 0 8px; }
.result-verdict.win { color: var(--green-d); animation: shake .5s; }
@keyframes shake { 0%,100%{ transform: rotate(0);} 25%{ transform: rotate(-3deg) scale(1.05);} 75%{ transform: rotate(3deg) scale(1.05);} }

/* ---------- scoreboard ---------- */
.scoreboard { display: flex; flex-direction: column; gap: 12px; margin: 18px 0; }
.score-row {
  display: flex; align-items: center; gap: 14px; background: #fff; border: var(--border);
  border-radius: 16px; padding: 12px 16px; box-shadow: 3px 3px 0 var(--ink); animation: pop .35s;
}
.score-row .rank { font-size: 22px; font-weight: 800; width: 36px; }
.score-row .pa { font-size: 32px; }
.score-row .pn { flex: 1; text-align: left; font-weight: 700; font-size: 18px; }
.score-row .pts { font-size: 24px; font-weight: 800; background: var(--yellow); border: 3px solid var(--ink); border-radius: 12px; padding: 2px 12px; }
.score-row .delta { font-size: 15px; font-weight: 800; color: #fff; background: var(--green-d); border: 2px solid var(--ink); border-radius: 999px; padding: 1px 9px; animation: pop .4s; }
.score-row.first { background: var(--yellow); transform: scale(1.03); }
.score-row.first .rank::after { content: ' 👑'; }

/* ---------- bandeau spectateur ---------- */
.spectator-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 80;
  background: var(--purple); color: #fff; text-align: center;
  font-weight: 800; padding: 8px 70px 8px 14px; font-size: 15px;
  border-bottom: var(--border); box-shadow: 0 3px 0 rgba(0,0,0,.15);
  letter-spacing: .3px; animation: pop .3s;
}
body.is-spectator #app { padding-top: 54px; }

/* ---------- bandeau de connexion ---------- */
.conn-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 120;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--red); color: #fff; text-align: center;
  font-weight: 800; padding: 9px 14px; font-size: 15px;
  border-bottom: var(--border); box-shadow: 0 3px 0 rgba(0,0,0,.15);
  letter-spacing: .3px; animation: pop .3s;
}
.conn-banner.ok { background: var(--green-d); }
.conn-spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.4); border-top-color: #fff;
  animation: conn-spin .7s linear infinite; flex: 0 0 auto;
}
.conn-banner.ok .conn-spinner { display: none; }
@keyframes conn-spin { to { transform: rotate(360deg); } }
body.conn-down #app { padding-top: 50px; }

.spec-badge {
  font-size: 12px; font-weight: 800; color: #fff; background: var(--purple);
  border: 2px solid var(--ink); border-radius: 999px; padding: 1px 8px; letter-spacing: .3px;
}
.player-chip.spectator { background: #efe9fb; }
.player-chip .spec-tag { position: absolute; top: -10px; left: -8px; font-size: 16px; }

/* ---------- controles son ---------- */
.sound-controls { position: fixed; top: 14px; right: 14px; z-index: 90; display: flex; gap: 8px; }
.snd-btn {
  width: 46px; height: 46px; font-size: 22px; line-height: 1; cursor: pointer;
  border: var(--border); border-radius: 14px; background: var(--paper);
  box-shadow: 3px 3px 0 var(--ink); transition: transform .08s, box-shadow .08s, background .15s;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.snd-btn:hover { transform: translate(-1px,-1px); background: var(--yellow); }
.snd-btn:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 var(--ink); }
.snd-btn.off { filter: grayscale(1); opacity: .55; background: #e9e2d6; }
@media (max-width: 480px) { .snd-btn { width: 40px; height: 40px; font-size: 19px; } }

/* ---------- timer de phase ---------- */
.phase-timer { display: flex; align-items: center; gap: 10px; margin: 4px auto 16px; max-width: 320px; }
.timer-bar { flex: 1; height: 16px; border: 3px solid var(--ink); border-radius: 999px; background: #fff; overflow: hidden; box-shadow: 2px 2px 0 var(--ink); }
/* Le fondu ne porte que sur la largeur : la couleur (vert/orange/rouge) change
   instantanement pour ne pas laisser l'orange « trainer » au passage au rouge. */
.timer-fill { height: 100%; width: 100%; background: var(--green); border-right: 3px solid var(--ink); transition: width .25s linear; }
/* Les couleurs sont de simples changements de fond, sans animation sur la barre :
   animer l'opacite du remplissage le promeut en couche GPU et laisse un fantome
   fige de la couleur precedente (orange « freeze ») sur certains navigateurs.
   L'effet d'urgence est porte par le chiffre, qui lui ne peut pas laisser de trace. */
.timer-fill.warn { background: var(--orange); }
.timer-fill.danger { background: var(--red); }
.timer-num { font-weight: 800; font-size: 20px; min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
.timer-num.danger { color: var(--red-d); animation: pulse-num .6s infinite; transform-origin: center; }
@keyframes pulse-num { 0%,100%{ transform: scale(1); opacity: 1; } 50%{ transform: scale(1.22); opacity: .6; } }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 150; display: none;
  align-items: center; justify-content: center; padding: 20px;
  background: rgba(27,27,47,.55); backdrop-filter: blur(2px);
}
.modal-overlay.show { display: flex; animation: pop .25s; }
.modal {
  background: var(--paper); border: var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 28px 24px; max-width: 380px; width: 100%; text-align: center;
}
.modal-emoji { font-size: 52px; }
.modal-msg { font-size: 18px; font-weight: 700; margin: 12px 0 20px; line-height: 1.4; }
.modal-actions { display: flex; gap: 12px; }
.modal-actions .btn { flex: 1; }
.modal-actions .btn-ghost { border: var(--border); box-shadow: var(--shadow); opacity: 1; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(120px);
  background: var(--ink); color: #fff; padding: 12px 22px; border-radius: 14px;
  font-weight: 700; z-index: 100; transition: transform .3s; box-shadow: var(--shadow); border: 3px solid #fff;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ---------- helpers ---------- */
.hidden { display: none !important; }

/* ---------- responsive ---------- */

/* Les overlays (modales) peuvent defiler si l'ecran est trop court (paysage mobile). */
.modal-overlay { overflow-y: auto; }

@media (max-width: 480px) {
  #app { padding: 12px; }
  .card { padding: 22px 16px; }
  .logo { font-size: 46px; }
  .screen-title { font-size: 24px; }
  .code-big { font-size: 36px; letter-spacing: 6px; }
  .phrase-display, .vote-phrase, .result-phrase { font-size: 18px; }
  .vote-buttons .btn { font-size: 18px; padding: 16px; }
  .meter-percent { font-size: 22px; padding: 2px 10px; }
  .result-avatar { font-size: 48px; }
  .spectator-banner { font-size: 13px; padding: 7px 56px 7px 12px; }
}

/* Tres petits ecrans (≈320px) : on empile le champ code et le bouton Rejoindre,
   et on resserre les actions de la modale. */
@media (max-width: 360px) {
  .join-field { flex-direction: column; }
  .join-field .btn { width: 100%; }
  .code-input { letter-spacing: 6px; font-size: 22px; }
  .prompt-buttons { flex-direction: column; }
  .modal-actions { flex-direction: column-reverse; }
  .players-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
}

/* Paysage sur petit ecran (peu de hauteur) : on aere moins verticalement et on
   permet le defilement plutot que de centrer un contenu trop grand. */
@media (max-height: 480px) and (orientation: landscape) {
  #app { align-items: flex-start; padding: 10px; }
  .hero-card { padding-top: 18px; }
  .logo { font-size: 38px; }
  .big-emoji { font-size: 44px; }
  .wait-block { padding: 12px 0; }
}
