/* ==========================================================================
   Style commun du site — utilisable aussi par les jeux :
   <link rel="stylesheet" href="/css/style.css">
   ========================================================================== */

:root {
  --bg: #0e0f1f;
  --bg-glow-1: rgba(124, 92, 255, 0.18);
  --bg-glow-2: rgba(56, 217, 169, 0.10);
  --surface: #181a33;
  --surface-2: #222547;
  --surface-3: #2c2f58;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f2f2ff;
  --muted: #a1a4c8;
  --primary: #7c5cff;
  --primary-hover: #8f74ff;
  --accent: #38d9a9;
  --danger: #ff6b6b;
  --success: #51cf66;
  --warning: #ffd43b;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font: 'Fredoka', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(900px 500px at 10% -10%, var(--bg-glow-1), transparent 60%),
    radial-gradient(700px 500px at 110% 10%, var(--bg-glow-2), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 600; }
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); }
h2 { font-size: 1.15rem; }
p { margin: 0; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.hint { font-size: 0.85rem; color: var(--muted); }
.error { color: var(--danger); min-height: 1.5em; font-size: 0.95rem; }

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

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

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-weight: 500;
  color: var(--text);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}
.btn:hover { background: #363a6b; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--primary); border-color: transparent; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { background: transparent; color: var(--danger); border-color: rgba(255, 107, 107, 0.4); }
.btn.danger:hover { background: rgba(255, 107, 107, 0.12); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 6px 12px; font-size: 0.9rem; }
.btn.block { width: 100%; }

.link-btn {
  font: inherit;
  color: var(--muted);
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
}
.link-btn:hover { color: var(--text); text-decoration: underline; }

.icon-btn {
  font: inherit;
  font-size: 1.2rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Formulaires ---------- */

label { display: block; font-weight: 500; margin-bottom: 6px; }

.input {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--surface-3);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.15s;
}
.input:focus { border-color: var(--primary); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > .input { flex: 1; min-width: 0; }

/* ---------- Avatar ---------- */

.avatar {
  --size: 36px;
  flex: none;
  display: inline-grid;
  place-items: center;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  font-weight: 600;
  font-size: calc(var(--size) * 0.45);
  color: #14152b;
  background: var(--avatar-color, var(--primary));
  text-transform: uppercase;
}
.avatar.lg { --size: 64px; }
.avatar.sm { --size: 28px; }

/* ---------- Badge ---------- */

.badge {
  display: inline-block;
  min-width: 1.6em;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  text-align: center;
  background: var(--surface-3);
  color: var(--muted);
}

/* ---------- Notifications ---------- */

#toasts {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 1000;
  width: min(420px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  box-shadow: var(--shadow);
  animation: toast-in 0.25s ease-out;
  pointer-events: auto;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
.toast.leaving { animation: toast-out 0.25s ease-in forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(10px); } }

/* ---------- Fenêtres (dialog) ---------- */

dialog {
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(5, 5, 15, 0.65); backdrop-filter: blur(3px); }
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.dialog-body { padding: 20px; display: flex; flex-direction: column; gap: 20px; }

/* ---------- Chargement ---------- */

.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid var(--surface-3);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Pages du site
   ========================================================================== */

.screen { min-height: 100vh; }
.screen.center { display: grid; place-items: center; padding: 24px 16px; }

/* ---------- Connexion ---------- */

.login-card { width: min(400px, 100%); padding: 32px 28px; text-align: center; }
.login-card .logo { font-size: 3.5rem; line-height: 1; margin-bottom: 8px; }
.login-card h1 { margin-bottom: 4px; }
.login-card > .muted { margin-bottom: 24px; }
.login-card form { text-align: left; display: flex; flex-direction: column; gap: 12px; }
.login-card .error { text-align: center; margin-top: 8px; }
.login-email {
  display: block;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.9rem;
  word-break: break-all;
}
.code-input {
  text-align: center;
  font-size: 1.8rem;
  font-weight: 600;
  letter-spacing: 0.4em;
  padding-left: 0.4em; /* compense l'espace après le dernier chiffre */
}
.login-links { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ---------- Barre du haut ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px clamp(16px, 4vw, 32px);
  background: rgba(14, 15, 31, 0.8);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 14px 4px 4px;
  cursor: pointer;
}
.user-chip:hover { background: var(--surface-3); }
.user-chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Menu ---------- */

.menu-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 24px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px clamp(16px, 4vw, 32px) 48px;
}
.menu-head { margin-bottom: 20px; }
.menu-head p { margin-top: 4px; }

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
}

.game-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: transform 0.15s, border-color 0.15s;
}
.game-card::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: var(--game-color);
}
.game-card:hover { transform: translateY(-3px); border-color: var(--game-color); }
.game-card .emoji {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  font-size: 2rem;
  border-radius: 14px;
  background: color-mix(in srgb, var(--game-color) 20%, transparent);
}
.game-card h3 { font-size: 1.2rem; }
.game-card .desc { color: var(--muted); font-size: 0.95rem; flex: 1; }
.game-card .meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: 0.82rem; }
.game-card .meta span { padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.game-card .actions { display: flex; gap: 8px; margin-top: 4px; }
.game-card .actions .btn.primary { flex: 1; }

.empty {
  grid-column: 1 / -1;
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  border: 2px dashed var(--surface-3);
  border-radius: var(--radius);
}
.empty code { color: var(--text); }

/* ---------- Joueurs en ligne ---------- */

.online { align-self: start; position: sticky; top: 84px; }
.online h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.online-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.online-list li { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: var(--radius-sm); }
.online-list li:hover { background: var(--surface-2); }
.online-list .who { min-width: 0; }
.online-list .who strong { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.online-list .who small { color: var(--muted); }
.online-list .who small.in-game { color: var(--accent); }
.online-list .me-tag { color: var(--muted); font-weight: 400; }
.online-list .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); margin-left: auto; flex: none; }

/* ---------- Profil ---------- */

.profile-head { display: flex; align-items: center; gap: 14px; }
.profile-head .who strong { display: block; font-size: 1.2rem; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid transparent;
  background: var(--c);
  cursor: pointer;
}
.swatch[aria-pressed="true"] { border-color: var(--text); }

.section-title { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 8px; font-weight: 500; }

/* ---------- Tableaux (stats, classement) ---------- */

.table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.table th, .table td { padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 500; font-size: 0.82rem; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.me td { background: rgba(124, 92, 255, 0.12); }
.table .player { display: flex; align-items: center; gap: 8px; }
.rank { width: 2em; color: var(--muted); }

/* ---------- Pages de jeu ---------- */

.game-main {
  max-width: 900px;
  margin: 0 auto;
  padding: 28px clamp(16px, 4vw, 32px) 48px;
}

/* ---------- Téléphone ---------- */

@media (max-width: 860px) {
  .menu-layout { grid-template-columns: 1fr; }
  .online { position: static; }
}
@media (max-width: 480px) {
  .brand .label { display: none; }
  .games-grid { grid-template-columns: 1fr; }
}
