:root {
  --bg: #0f1226;
  --bg-soft: #171a35;
  --panel: #1e2245;
  --panel-2: #262b57;
  --line: #333a6b;
  --text: #eef1ff;
  --muted: #9aa2d4;
  --primary: #6c5ce7;
  --primary-2: #8b7bff;
  --accent: #00d2a8;
  --warn: #ffb020;
  --error: #ff5c7a;
  --ok: #35d07f;
  --gold: #ffd23f;
  --radius: 16px;
  --shadow: 0 12px 30px rgba(0, 0, 0, .35);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 15% -10%, #2a2260 0%, transparent 60%),
    radial-gradient(1000px 600px at 110% 10%, #12325a 0%, transparent 55%),
    var(--bg);
  min-height: 100dvh;
}

#app { min-height: 100dvh; }

.screen { display: none; min-height: 100dvh; }
.screen.is-active { display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ---------- Cartes ---------- */
.card {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-soft) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card--home {
  margin: auto;
  width: min(560px, 92vw);
  padding: 40px 34px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.logo { font-size: 56px; line-height: 1; }
.title {
  font-size: clamp(30px, 6vw, 44px);
  letter-spacing: -.5px;
  background: linear-gradient(90deg, var(--primary-2), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subtitle { color: var(--muted); margin-top: -10px; }

.field { text-align: left; display: flex; flex-direction: column; gap: 10px; }
.field > label { font-weight: 600; color: var(--muted); font-size: 14px; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 700;
  transition: transform .08s ease, background .15s ease, opacity .15s;
  border: 1px solid transparent;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn--primary { background: linear-gradient(180deg, var(--primary-2), var(--primary)); color: #fff; box-shadow: 0 8px 18px rgba(108, 92, 231, .4); }
.btn--primary:hover { filter: brightness(1.06); }
.btn--ghost { background: rgba(255, 255, 255, .06); border-color: var(--line); color: var(--text); }
.btn--ghost:hover { background: rgba(255, 255, 255, .12); }
.btn--big { padding: 16px 26px; font-size: 18px; }
.btn--small { padding: 8px 14px; font-size: 14px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Choix disposition ---------- */
.layout-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.layout-option {
  padding: 14px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: var(--panel-2);
  text-align: center;
  transition: border-color .15s, background .15s;
}
.layout-option strong { display: block; font-size: 16px; }
.layout-option span { color: var(--muted); font-size: 12px; }
.layout-option.is-selected { border-color: var(--accent); background: rgba(0, 210, 168, .12); }

/* ---------- Nom + avatar ---------- */
.name-row { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; }
.input {
  flex: 1 1 200px;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: var(--panel-2);
  outline: none;
}
.input:focus { border-color: var(--accent); }
.avatar-picker {
  flex: 1 1 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.avatar-option {
  width: 44px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: var(--panel-2);
  font-size: 22px;
  display: grid;
  place-items: center;
}
.avatar-option.is-selected { border-color: var(--accent); background: rgba(0, 210, 168, .12); }

/* ---------- Joueurs (slots) ---------- */
.slot-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.slot {
  flex: 1 1 calc(50% - 4px);
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: var(--panel-2);
  text-align: left;
  color: var(--text);
  font-weight: 600;
  transition: border-color .15s, background .15s;
}
.slot:hover { border-color: var(--primary-2); }
.slot.is-active { border-color: var(--accent); background: rgba(0, 210, 168, .12); }
.slot--empty { color: var(--muted); border-style: dashed; font-weight: 500; }
.slot__avatar { font-size: 22px; line-height: 1; }
.slot__plus { font-size: 18px; line-height: 1; }
.slot__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}
.slot .stars-row { flex: none; font-size: 12px; }
.slot-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.slot-actions .btn { flex: 1 1 auto; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 18, 38, .6);
  backdrop-filter: blur(6px);
}
.topbar__title { flex: 1; text-align: center; font-size: 18px; }
.topbar__player { font-size: 15px; color: var(--muted); }
.topbar__spacer { width: 90px; }

/* ---------- Carte des missions ---------- */
.map {
  padding: 26px clamp(16px, 4vw, 48px) 60px;
  display: flex;
  flex-direction: column;
  gap: 30px;
  overflow-y: auto;
}
.chapter { display: flex; flex-direction: column; gap: 14px; }
.chapter__head { display: flex; align-items: baseline; gap: 12px; }
.chapter__badge {
  display: inline-grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--primary);
  font-weight: 800;
}
.chapter__title { font-size: 20px; }
.chapter__sub { color: var(--muted); font-size: 14px; }
.mission-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.mission {
  text-align: left;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform .1s, border-color .15s;
}
.mission:hover:not(.mission--locked) { transform: translateY(-2px); border-color: var(--accent); }
.mission--locked { opacity: .5; cursor: not-allowed; }
.mission__top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.mission__name { font-weight: 700; }
.mission__keys { display: flex; gap: 4px; flex-wrap: wrap; }
.key-chip {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.stars-row { letter-spacing: 2px; font-size: 15px; }
.star { color: #4a4f7a; }
.star.on { color: var(--gold); }

/* ---------- HUD ---------- */
.hud {
  display: flex;
  gap: 12px;
  padding: 14px 20px;
  flex-wrap: wrap;
}
.stat {
  flex: 1;
  min-width: 110px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 14px;
}
.stat__label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.stat__value { font-size: 24px; font-weight: 800; }
.stat__value small { font-size: 13px; color: var(--muted); font-weight: 600; }
.stat--progress { flex: 2; }
.progress-bar { height: 10px; border-radius: 999px; background: var(--panel-2); overflow: hidden; margin-top: 12px; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--primary-2)); transition: width .12s linear; }

/* ---------- Zone de frappe ---------- */
.stage { flex: 1; display: grid; place-items: center; padding: 20px; }
.typing {
  width: min(900px, 94vw);
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: clamp(22px, 3.4vw, 38px);
  line-height: 1.7;
  letter-spacing: .5px;
  word-break: break-word;
  outline: none;
  padding: 24px;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, .18);
  border: 1px solid var(--line);
}
.typing:focus { border-color: var(--primary-2); box-shadow: 0 0 0 3px rgba(139, 123, 255, .2); }
.ch { position: relative; border-radius: 4px; transition: color .05s, background .05s; }
.ch--pending { color: #8389b8; }
.ch--done { color: var(--ok); }
.ch--current { color: #fff; background: rgba(139, 123, 255, .35); box-shadow: inset 0 -3px 0 var(--primary-2); }
.ch--space.ch--current { background: rgba(139, 123, 255, .35); }
.ch--wrong { color: #fff; background: var(--error); }
.ch--error { color: var(--error); text-decoration: underline wavy var(--error); }

.tip { text-align: center; color: var(--muted); font-size: 13px; padding: 6px 0 16px; }
.hand-hint { text-align: center; font-weight: 700; color: var(--muted); padding: 8px; min-height: 22px; }

/* ---------- Résultat ---------- */
.card--result {
  margin: auto;
  width: min(520px, 92vw);
  padding: 36px 30px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.result__title { font-size: 26px; }
.stars { font-size: 52px; letter-spacing: 6px; }
.stars .star { color: #3a3f68; }
.stars .star.on { color: var(--gold); text-shadow: 0 0 18px rgba(255, 210, 63, .5); }
.result__stats { display: flex; justify-content: center; gap: 26px; }
.result__stat b { display: block; font-size: 28px; }
.result__stat span { color: var(--muted); font-size: 13px; }
.result__actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- Points / indicateurs ---------- */
.map-points {
  font-size: 13px;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--line);
}
.mission__hint {
  color: var(--muted);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .05);
  border: 1px dashed var(--line);
  align-self: flex-start;
}

/* ---------- Crédits ---------- */
.card--credits {
  margin: auto;
  width: min(600px, 92vw);
  padding: 34px 30px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: left;
}
.card--credits .logo { text-align: center; font-size: 40px; }
.credits__title { text-align: center; font-size: 26px; margin-bottom: 4px; }
.credits__section h3 {
  font-size: 13px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .8px;
  margin-bottom: 4px;
}
.credits__section p { color: var(--text); }
.credits__list { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
.credits__list li::before { content: "• "; color: var(--primary-2); }
.credits__note {
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}
.card--credits .btn { align-self: center; }

/* ---------- Liens de pied de page (accueil) ---------- */
.site-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 16px;
  margin-top: 8px;
  font-size: 13px;
}
.link {
  background: none;
  border: none;
  padding: 0;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link:hover { color: var(--text); }

/* ---------- Informations légales ---------- */
.legal {
  width: min(760px, 92vw);
  margin: 0 auto;
  padding: 30px clamp(16px, 4vw, 40px) 60px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}
.legal__block {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
  scroll-margin-top: 80px;
}
.legal__block h3 { font-size: 22px; color: var(--accent); }
.legal__block h4 { font-size: 16px; margin-top: 10px; }
.legal__block p, .legal__dl dd { color: var(--text); line-height: 1.6; }
.legal__block a { color: var(--primary-2); }
.legal__dl { display: flex; flex-direction: column; gap: 6px; }
.legal__dl dt {
  font-weight: 700;
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .6px;
}
.legal__dl dd { margin: 0 0 8px; }
.legal__list { display: flex; flex-direction: column; gap: 6px; padding-left: 4px; color: var(--text); }
.legal__list li::before { content: "• "; color: var(--primary-2); }
.legal code {
  background: rgba(255, 255, 255, .08);
  padding: 1px 6px;
  border-radius: 6px;
  font-size: .9em;
}
.legal .btn { align-self: center; margin-top: 4px; }

/* ---------- Bandeau stockage local ---------- */
.cookie-notice {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 50;
  width: min(680px, 92vw);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(30, 34, 69, .96);
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}
.cookie-notice[hidden] { display: none; }
.cookie-notice p { flex: 1; font-size: 13px; color: var(--muted); margin: 0; }
.cookie-notice .btn { flex: none; }
@media (max-width: 520px) {
  .cookie-notice { flex-direction: column; align-items: stretch; text-align: center; }
}

/* ---------- Défi de vitesse ---------- */
.challenge {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 18px 40px;
  overflow-y: auto;
}
.challenge__panel {
  width: min(560px, 94vw);
  margin: auto;
  padding: 32px 28px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-soft) 100%);
  box-shadow: var(--shadow);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.challenge__hero { font-size: 52px; line-height: 1; }
.challenge__title { font-size: 26px; }
.challenge__desc { color: var(--muted); }
.challenge__best {
  align-self: center;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 210, 63, .12);
  border: 1px solid rgba(255, 210, 63, .35);
  color: var(--gold);
  font-weight: 700;
  font-size: 14px;
}
.challenge__panel .btn { align-self: center; }
.challenge__top-title {
  font-size: 15px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-top: 6px;
}

.challenge__play {
  width: min(760px, 96vw);
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: center;
}
.challenge__stats { display: flex; gap: 12px; width: 100%; }
.challenge__stats .stat { flex: 1; text-align: center; }
.challenge__area {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 22px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, .18);
}
.challenge__letter {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: clamp(80px, 24vw, 180px);
  font-weight: 800;
  line-height: 1;
  color: #fff;
  text-shadow: 0 0 30px rgba(139, 123, 255, .6);
  text-transform: lowercase;
}
.challenge__letter.is-pop { animation: letter-pop .18s ease-out; }
@keyframes letter-pop {
  0% { transform: scale(.6); opacity: .4; }
  100% { transform: scale(1); opacity: 1; }
}

/* Compte à rebours avant la première lettre */
.challenge__count {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: clamp(72px, 20vw, 150px);
  font-weight: 800;
  color: var(--gold);
  text-shadow: 0 0 34px rgba(255, 210, 63, .55);
  background: rgba(15, 18, 38, .94);
  border-radius: var(--radius);
  z-index: 2;
  pointer-events: none;
}
.challenge__count.is-on { display: flex; }
.challenge__count.is-pop { animation: count-pop .32s ease-out; }
@keyframes count-pop {
  0% { transform: scale(.35); opacity: 0; }
  55% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.challenge__bar {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
}
.challenge__bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--accent), var(--primary-2));
  transition: width .05s linear, background .15s;
}
.challenge__bar-fill.is-low { background: linear-gradient(90deg, var(--error), var(--warn)); }

.challenge__record {
  align-self: center;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(0, 210, 168, .15);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-weight: 800;
}
.challenge__summary { display: flex; flex-direction: column; gap: 4px; }
.challenge__score-final { font-size: 40px; font-weight: 800; color: var(--gold); }
.challenge__sub { color: var(--muted); }
.challenge__rank { color: var(--accent); font-weight: 700; }
.challenge__actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.top-list { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.top-list__row {
  display: grid;
  grid-template-columns: 40px 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 14px;
}
.top-list__row.is-new { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(255, 210, 63, .25); }
.top-list__rank { font-weight: 800; color: var(--muted); }
.top-list__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-list__meta { color: var(--muted); font-size: 12px; }
.top-list__score { font-weight: 800; color: var(--gold); }
.top-list__empty { color: var(--muted); font-size: 14px; text-align: center; padding: 10px; }

@media (max-width: 560px) {
  .topbar__spacer { display: none; }
  .result__stats { flex-direction: column; gap: 12px; }
  .challenge__stats { flex-direction: column; }
  .top-list__row { grid-template-columns: 32px 1fr auto; }
  .top-list__meta { display: none; }
}
