:root {
  --bg: #0a0d14;
  --bg-2: #10141f;
  --panel: #141926;
  --panel-2: #1b2233;
  --panel-3: #212a3f;
  --border: #252d42;
  --border-2: #333d57;
  --text: #e7eaf3;
  --muted: #8b93a9;
  --faint: #5c6478;
  --accent: #7d6df7;
  --accent-2: #9a8cff;
  --accent-soft: rgba(125, 109, 247, .14);
  --gold: #d9a94e;
  --danger: #e0656e;
  --danger-soft: rgba(224, 101, 110, .12);
  --good: #57c784;
  --good-soft: rgba(87, 199, 132, .12);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 16px 40px rgba(0, 0, 0, .5);
  --shadow-sm: 0 4px 14px rgba(0, 0, 0, .35);
  --font-head: "Space Grotesk", "Inter", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, Roboto, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;
}

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

html, body { min-height: 100%; }

body {
  font-family: var(--font-body);
  background:
    radial-gradient(900px 520px at 85% -10%, rgba(125, 109, 247, .12) 0%, transparent 60%),
    radial-gradient(700px 420px at -10% 0%, rgba(216, 169, 78, .06) 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  color-scheme: dark;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------- Header ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(10, 13, 20, .82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(37, 45, 66, .8);
}

.topbar-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  font-weight: 600;
}

.brand-logo { width: 30px; height: 30px; display: block; filter: drop-shadow(0 0 10px rgba(125, 109, 247, .35)); }

.brand-name {
  font-family: var(--font-head);
  font-size: 16px;
  letter-spacing: .2px;
  color: var(--text);
}

.room-badge {
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: 3px;
  font-size: 14px;
  color: var(--accent-2);
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: 5px 13px;
  border-radius: 999px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .03);
}

/* ---------- Layout ---------- */
#app {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 22px 16px 28px;
}

.view { animation: fade .28s ease; }

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

.panel {
  background: linear-gradient(180deg, rgba(27, 34, 51, .72), rgba(20, 25, 38, .92));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, .03);
}

.panel.center {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
}

/* ---------- Hero / Accueil ---------- */
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 14px 8px 26px;
}

.hero-logo { width: 74px; height: 74px; margin-bottom: 14px; filter: drop-shadow(0 8px 24px rgba(125, 109, 247, .4)); }

.home-title {
  font-family: var(--font-head);
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -.5px;
  margin-bottom: 8px;
}

.home-sub {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
  max-width: 34em;
}

.hero-chips { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 16px; }

.chip {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 500;
}

/* ---------- Champs ---------- */
.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .3px; }
.field-full { grid-column: 1 / -1; }

input, select, textarea {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  width: 100%;
  transition: border-color .15s, box-shadow .15s, background .15s;
}

input:hover, select:hover, textarea:hover { border-color: var(--border-2); }

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: #121725;
}

textarea { resize: vertical; min-height: 70px; font-family: var(--font-mono); font-size: 13px; }

select { appearance: none; }

/* ---------- Boutons ---------- */
.btn {
  border: 1px solid var(--border);
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-body);
  transition: transform .06s ease, filter .15s ease, background .15s ease, border-color .15s, box-shadow .15s;
  color: var(--text);
  background: var(--panel-2);
}

.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

.btn-primary {
  background: linear-gradient(180deg, #8a7bff 0%, #6b5aee 100%);
  border-color: rgba(138, 123, 255, .5);
  color: #fff;
  box-shadow: 0 6px 20px rgba(107, 90, 238, .35);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.07); }

.btn-secondary { background: var(--bg-2); }
.btn-secondary:hover:not(:disabled) { border-color: var(--border-2); background: #151a29; }

.btn-ghost { background: transparent; }
.btn-ghost:hover:not(:disabled) { color: var(--accent-2); border-color: var(--border-2); }

.btn-danger { background: var(--danger); border-color: transparent; color: #fff; }
.btn-accent { background: var(--gold); border-color: transparent; color: #201705; }

.btn-block { width: 100%; }

/* ---------- Accueil actions ---------- */
.home-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.or-divider {
  text-align: center;
  color: var(--faint);
  font-size: 12px;
  letter-spacing: .3px;
  margin: 4px 0;
  display: flex;
  align-items: center;
  gap: 12px;
}
.or-divider::before, .or-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.join-row { display: flex; gap: 10px; }
.join-row .code-input {
  text-transform: uppercase;
  text-align: center;
  letter-spacing: 6px;
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  flex: 1;
}

.settings-toggle { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.settings-toggle summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  list-style: none;
  user-select: none;
}
.settings-toggle summary::-webkit-details-marker { display: none; }
.settings-toggle summary::before { content: "＋"; margin-right: 8px; color: var(--accent-2); }
.settings-toggle[open] summary { color: var(--text); }
.settings-toggle[open] summary::before { content: "－"; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; margin-top: 12px; }

/* ---------- Titres de section ---------- */
.section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.6px;
  color: var(--faint);
  margin: 22px 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title::before { content: ""; width: 14px; height: 1px; background: var(--accent); opacity: .8; }
.section-title span { color: var(--muted); letter-spacing: 0; font-size: 12px; }

/* ---------- Lobby ---------- */
.lobby-head { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; }
.room-code-label { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: 1.6px; }
.room-code {
  font-size: 34px;
  font-weight: 600;
  letter-spacing: 9px;
  font-family: var(--font-mono);
  color: var(--accent-2);
  text-shadow: 0 0 22px rgba(125, 109, 247, .35);
  margin-top: 2px;
}
.lobby-meta { margin-top: 8px; font-size: 13px; color: var(--muted); line-height: 1.6; }
.lobby-meta b { color: var(--text); font-weight: 600; }

.qr-wrap {
  background: #f3f4f8;
  padding: 6px;
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}
.qr-wrap img { display: block; width: 92px; height: 92px; border-radius: 6px; }

/* ---------- Joueurs ---------- */
.player-list { list-style: none; display: flex; flex-direction: column; gap: 7px; }

.player-row {
  display: flex;
  align-items: center;
  gap: 11px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  transition: border-color .15s;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-head);
  font-size: 13px;
  font-weight: 700;
  color: #eef0fb;
  background: linear-gradient(160deg, #2a3350, #1b2233);
  border: 1px solid var(--border-2);
  flex-shrink: 0;
}

.player-dot { width: 8px; height: 8px; border-radius: 50%; background: #5a6178; flex-shrink: 0; }
.player-dot.on { background: var(--good); box-shadow: 0 0 8px rgba(87, 199, 132, .6); }

.player-name { flex: 1; font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-tag { font-size: 10px; font-weight: 600; color: var(--accent-2); background: var(--accent-soft); border: 1px solid rgba(125, 109, 247, .3); padding: 2px 8px; border-radius: 999px; letter-spacing: .4px; }
.player-score { font-family: var(--font-mono); font-weight: 600; color: var(--gold); font-size: 13px; min-width: 44px; text-align: right; }

.player-row.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 18px rgba(125, 109, 247, .18); }
.player-row.mine { background: #161b2b; }

/* ---------- Indications ---------- */
.hint { color: var(--muted); font-size: 13px; line-height: 1.6; }
.custom-wrap { display: flex; flex-direction: column; gap: 9px; }
.btn-row { display: flex; gap: 10px; margin-top: 14px; }
.btn-row-spread { justify-content: space-between; }
.btn-row-spread .btn { flex: 1; }
.host-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; justify-content: center; }
.host-actions .btn { font-size: 13px; padding: 10px 14px; }

.round-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--faint);
  font-weight: 600;
}

/* ---------- Carte flip ---------- */
.flip-card {
  width: min(86vw, 320px);
  height: 402px;
  perspective: 1200px;
  cursor: pointer;
  margin: 8px auto;
}
.flip-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform .7s cubic-bezier(.4, .15, .2, 1);
}
.flip-card.flipped .flip-card-inner { transform: rotateY(180deg); }
.flip-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 18px;
  border: 1px solid var(--border-2);
  overflow: hidden;
}

.flip-front {
  background:
    radial-gradient(420px 260px at 50% 110%, rgba(125, 109, 247, .18) 0%, transparent 65%),
    linear-gradient(160deg, #1c2340 0%, #141927 55%, #101420 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.card-emblem { width: 52px; height: 52px; opacity: .85; filter: drop-shadow(0 6px 18px rgba(125, 109, 247, .45)); }
.card-badge { font-size: 11px; letter-spacing: 3px; text-transform: uppercase; color: var(--faint); }

.card-shape {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 1px dashed rgba(125, 109, 247, .5);
  background: repeating-conic-gradient(from 0deg, rgba(125,109,247,.08) 0deg 10deg, transparent 10deg 20deg);
  animation: spin 26s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.card-tap { font-size: 13px; color: var(--accent-2); font-weight: 600; animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }

.flip-back {
  transform: rotateY(180deg);
  background:
    radial-gradient(400px 240px at 50% -10%, rgba(125, 109, 247, .14) 0%, transparent 60%),
    linear-gradient(160deg, #151a2b 0%, #0e1220 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 26px;
  text-align: center;
  gap: 12px;
}
.card-civil, .card-spy { display: flex; flex-direction: column; align-items: center; gap: 10px; }

.card-role-label { font-size: 11px; text-transform: uppercase; letter-spacing: 2.2px; color: var(--faint); font-weight: 600; }
.card-word { font-size: 30px; font-weight: 700; font-family: var(--font-head); color: var(--accent-2); line-height: 1.15; text-align: center; }

.spy-eyebrow { font-size: 11px; letter-spacing: 3px; text-transform: uppercase; color: var(--danger); font-weight: 600; }
.spy-title { font-size: 30px; font-weight: 700; font-family: var(--font-head); color: var(--danger); line-height: 1.15; }
.spy-sub { color: var(--muted); font-size: 14px; line-height: 1.6; max-width: 24em; }

.spy-warning {
  margin-top: 6px;
  font-size: 12px;
  color: var(--gold);
  background: rgba(217, 169, 78, .08);
  border: 1px solid rgba(217, 169, 78, .28);
  padding: 7px 14px;
  border-radius: 999px;
  font-weight: 500;
}

.seen-progress { color: var(--muted); font-size: 13px; }

/* ---------- Minuteur ---------- */
.timer-box { text-align: center; margin: 12px 0 16px; }
.timer-num {
  font-size: 62px;
  font-weight: 700;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: 2px;
  color: var(--text);
}
.timer-num.low { color: var(--danger); text-shadow: 0 0 22px rgba(224, 101, 110, .4); }
.timer-bar { height: 6px; border-radius: 999px; background: var(--bg-2); overflow: hidden; margin-top: 12px; }
.timer-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .3s linear;
}
.timer-fill.low { background: var(--danger); }
.timer-status { color: var(--faint); font-size: 12px; margin-top: 8px; letter-spacing: .4px; text-transform: uppercase; }

.turn-banner {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  text-align: center;
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 6px;
}
.turn-banner.mine { border-color: var(--accent); color: var(--accent-2); box-shadow: 0 0 0 1px var(--accent); }

/* ---------- Vote ---------- */
.vote-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 10px; }
.vote-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 10px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: border-color .12s, background .12s, box-shadow .12s, transform .06s;
  text-align: center;
}
.vote-card:hover { border-color: var(--border-2); transform: translateY(-1px); }
.vote-card.selected { background: var(--accent-soft); border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 18px rgba(125, 109, 247, .2); }
.vote-card.abstain { grid-column: 1 / -1; border-style: dashed; color: var(--muted); }
.voted-progress { margin-top: 14px; color: var(--muted); font-size: 13px; text-align: center; }

/* ---------- Résultats ---------- */
.result-banner {
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  font-family: var(--font-head);
  padding: 14px;
  border-radius: 12px;
  margin: 10px 0 4px;
}
.result-banner.civils { background: var(--good-soft); color: var(--good); border: 1px solid rgba(87, 199, 132, .35); }
.result-banner.espions { background: var(--danger-soft); color: var(--danger); border: 1px solid rgba(224, 101, 110, .35); }

.result-lieu { text-align: center; margin: 10px 0 4px; }
.result-lieu-label { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: 1.8px; }
.result-lieu-value { font-size: 34px; font-weight: 700; font-family: var(--font-head); color: var(--accent-2); line-height: 1.2; }
.result-lieu.spy .result-lieu-value { color: var(--danger); }
.result-guess { text-align: center; color: var(--muted); font-size: 14px; margin: 8px 0; }

.desc-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.desc-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 13px;
}
.desc-name { font-weight: 600; color: var(--accent-2); flex-shrink: 0; }
.desc-text { color: var(--muted); }
.desc-composer { display: flex; gap: 8px; margin-bottom: 14px; }
.desc-composer input { flex: 1; min-width: 0; }

.role-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.role-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 14px;
}
.role-row.spy { border-color: rgba(224, 101, 110, .45); background: rgba(224, 101, 110, .06); }
.role-row.spy .player-name { color: var(--danger); }
.role-role { margin-left: auto; font-weight: 500; color: var(--muted); font-size: 13px; }
.role-row.spy .role-role { color: var(--danger); font-weight: 600; }
.role-badge { font-size: 10px; background: var(--danger); color: #fff; padding: 2px 8px; border-radius: 999px; font-weight: 700; letter-spacing: .4px; }

.tally-list, .score-list { display: flex; flex-direction: column; gap: 6px; }
.tally-row, .score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 14px;
}
.tally-count { font-family: var(--font-mono); font-weight: 600; color: var(--gold); }
.score-num { font-family: var(--font-mono); font-weight: 700; color: var(--gold); }

.final-winner { font-size: 24px; font-weight: 700; font-family: var(--font-head); color: var(--good); }

.ranking-list { list-style: none; display: flex; flex-direction: column; gap: 6px; width: 100%; }
.ranking-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-weight: 500;
}
.ranking-pos { font-family: var(--font-mono); font-weight: 700; color: var(--accent-2); width: 26px; }
.ranking-score { margin-left: auto; font-family: var(--font-mono); font-weight: 700; color: var(--gold); }
.ranking-row.winner { border-color: rgba(87, 199, 132, .4); background: var(--good-soft); }
.ranking-row.winner .ranking-pos { color: var(--good); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1d2233;
  color: var(--text);
  border: 1px solid var(--border-2);
  border-left: 3px solid var(--danger);
  padding: 13px 18px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 500;
  z-index: 50;
  max-width: 90vw;
  animation: fade .2s ease;
}
.toast.ok { border-left-color: var(--good); }

/* ---------- Footer ---------- */
.footer {
  text-align: center;
  padding: 18px 16px 30px;
  color: var(--faint);
  font-size: 12px;
  letter-spacing: .4px;
}

@media (min-width: 520px) {
  .brand-name { font-size: 17px; }
  #app { padding-top: 30px; }
}
