/* Ludo — feuille de styles unique, sans framework CSS. */

:root {
  --bg: #0f141c;
  --bg-soft: #161d28;
  --card: #1b2330;
  --card-2: #212b3a;
  --line: #2c3849;
  --text: #e8eef6;
  --muted: #93a1b5;
  --accent: #35c46f;
  --accent-dark: #1f9c53;
  --danger: #e5484d;

  --red: #e5484d;
  --green: #30a46c;
  --yellow: #e2b53d;
  --blue: #3b82f6;

  --cell: #d9e2ec;
  --cell-line: #9fb0c4;
  --radius: 14px;
  --shadow: 0 10px 30px rgb(0 0 0 / 35%);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2532, var(--bg));
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  min-height: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2 { line-height: 1.2; margin: 0 0 0.6rem; }
h2 { font-size: 1.05rem; letter-spacing: 0.01em; }

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

/* ---------- accueil ---------- */

.hero { text-align: center; padding: 1.5rem 0 1rem; }
.hero h1 {
  font-size: clamp(2.2rem, 6vw, 3.2rem);
  background: linear-gradient(120deg, var(--red), var(--yellow) 40%, var(--green) 70%, var(--blue));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 0.3rem;
}
.tagline { color: var(--muted); margin: 0; }

.columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.card {
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.field { display: block; margin-bottom: 0.9rem; }
.field > span { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.3rem; }
.field input {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0e141d;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.modes { border: 0; padding: 0; margin: 0 0 0.9rem; }
.modes legend { font-size: 0.85rem; color: var(--muted); padding: 0; margin-bottom: 0.4rem; }

.mode {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 0.4rem;
  cursor: pointer;
  background: #131a24;
}
.mode:hover { border-color: var(--accent); }
.mode:has(input:checked) { border-color: var(--accent); background: #16281f; }
.mode input { accent-color: var(--accent); }
.mode-body { display: flex; flex-direction: column; }
.mode-label { font-weight: 600; }
.mode-hint { font-size: 0.78rem; color: var(--muted); }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 0.6rem 0.9rem;
  transition: filter 0.15s ease, background 0.15s ease;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }

.primary { background: var(--accent); color: #06210f; font-weight: 600; width: 100%; }
.primary:hover:not(:disabled) { filter: brightness(1.08); }

.secondary {
  background: #232e3d;
  color: var(--text);
  border-color: var(--line);
  width: 100%;
}
.secondary:hover:not(:disabled) { background: #2b3849; }
.secondary.small { width: auto; padding: 0.3rem 0.6rem; font-size: 0.82rem; }

.or { text-align: center; color: var(--muted); font-size: 0.85rem; margin: 0.7rem 0; }
.hint { color: var(--muted); font-size: 0.8rem; margin: 0.7rem 0 0; }

.badge {
  display: inline-block;
  background: #232e3d;
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.games { list-style: none; margin: 0; padding: 0; }
.game {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
  padding: 0.55rem 0.2rem;
  border-bottom: 1px solid var(--line);
}
.game:last-child { border-bottom: 0; }
.game-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--accent);
}
.game-mode { color: var(--text); }
.game-players, .game-host { color: var(--muted); font-size: 0.85rem; }
.game .join-game { margin-left: auto; }
.empty { color: var(--muted); font-size: 0.9rem; margin: 0.3rem 0 0; }

.foot { text-align: center; padding: 1rem 0; color: var(--muted); }

/* ---------- plateau ---------- */

.game-page { max-width: 1400px; }

.game-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.game-header h1 { font-size: 1.3rem; margin: 0; display: flex; align-items: center; gap: 0.6rem; }
.game-header .back { color: var(--muted); }
.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.14em;
  color: var(--accent);
}
.mode-tag {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
}
.game-header .secondary { margin-left: auto; width: auto; }

/* Le plateau occupe l'essentiel de la largeur : la colonne de droite est
   réduite au strict nécessaire (joueurs + dé). */
.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 190px;
  gap: 0.9rem;
  align-items: start;
}
@media (max-width: 900px) {
  .game-layout { grid-template-columns: 1fr; }
}

.side { display: flex; flex-direction: column; gap: 0.7rem; }

.players { list-style: none; margin: 0; padding: 0; }
.player {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.22rem 0.35rem;
  border-radius: 7px;
  border: 1px solid transparent;
  border-left: 3px solid transparent;
  font-size: 0.86rem;
}
.player.active { border-color: #2c3849; border-left-color: var(--accent); background: #16281f; }
.player.offline { opacity: 0.45; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.player-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-meta { margin-left: auto; font-size: 0.72rem; color: var(--muted); }
.tag {
  font-size: 0.6rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 0.28rem;
  color: var(--muted);
  flex: none;
}

.dice-panel {
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.7rem;
  text-align: center;
}

/* Le plateau (WebGL) prend toute la largeur disponible, mais reste borné par la
   hauteur de la fenêtre : il est carré, et sans cette limite il dépasserait
   l'écran et forcerait à faire défiler pour voir son propre camp. */
.board-wrap {
  position: relative;
  width: 100%;
  max-width: calc(100vh - 150px);
  margin: 0 auto;
  aspect-ratio: 1;
}
#board3d {
  width: 100%;
  height: 100%;
  display: block;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  /* le plateau est interactif (pions, dé) mais ne tourne plus */
  touch-action: none;
  cursor: pointer;
}

.webgl-error {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 1rem;
  text-align: center;
  background: rgb(9 13 18 / 88%);
  border-radius: var(--radius);
  color: var(--muted);
}

.banner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.6rem;
  background: rgb(9 13 18 / 82%);
  border-radius: var(--radius);
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
  padding: 1rem;
}
.banner small { font-weight: 400; font-size: 0.9rem; color: var(--muted); }

.turn { font-weight: 600; font-size: 0.88rem; margin: 0 0 0.6rem; }

/* Le dé est le bouton : on clique dessus pour lancer. Grille 3x3 dont on
   allume certains points selon la face. */
.dice {
  width: 62px;
  height: 62px;
  margin: 0 auto;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(160deg, #f7fafc, #d7dfe9);
  border: 1px solid #9fb0c4;
  box-shadow: inset 0 -2px 0 rgb(0 0 0 / 12%), 0 4px 10px rgb(0 0 0 / 35%);
  transform-origin: center;
  cursor: not-allowed;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.dice-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 3px;
  width: 44px;
  height: 44px;
}
.pip { border-radius: 50%; background: transparent; }
.pip.on {
  background: #1b2330;
  box-shadow: inset 0 -1px 1px rgb(255 255 255 / 35%);
}

/* Le liseré reprend la couleur du joueur dont c'est le tour : le dé garde le
   numéro du dernier lancer, mais c'est la main en cours qu'il faut voir. */
.dice.current {
  border-color: var(--turn-color, #9fb0c4);
  outline: 2px solid var(--turn-color, transparent);
  outline-offset: 2px;
}

/* À vous de jouer : le dé invite au clic. */
.dice.ready {
  cursor: pointer;
  animation: dice-ready 1.6s ease-in-out infinite;
}
.dice.ready:hover { transform: translateY(-1px) scale(1.04); }
@keyframes dice-ready {
  0%, 100% { box-shadow: inset 0 -2px 0 rgb(0 0 0 / 12%), 0 0 0 3px rgb(53 196 111 / 22%), 0 4px 10px rgb(0 0 0 / 35%); }
  50% { box-shadow: inset 0 -2px 0 rgb(0 0 0 / 12%), 0 0 0 9px rgb(53 196 111 / 10%), 0 4px 10px rgb(0 0 0 / 35%); }
}

/* Le dé tourne tant que le serveur n'a pas répondu… */
.dice.rolling { animation: tumble 0.5s ease-in-out infinite; }
@keyframes tumble {
  0%, 100% { transform: rotate(-14deg) scale(1); }
  25% { transform: rotate(10deg) scale(1.08); }
  50% { transform: rotate(16deg) scale(0.96); }
  75% { transform: rotate(-8deg) scale(1.05); }
}

/* …puis claque sur la valeur tirée. */
.dice.settled { animation: dice-pop 0.42s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes dice-pop {
  0% { transform: scale(0.65) rotate(-10deg); }
  55% { transform: scale(1.18) rotate(4deg); }
  100% { transform: scale(1) rotate(0); }
}

/* La surbrillance de la zone active et des pions jouables est désormais gérée
   dans la scène 3D (émission de la base, anneaux sous les pions). */

/* ---------- règles ---------- */

.prose { max-width: 780px; margin: 0 auto 1rem; }
.prose h2 { margin-top: 1.3rem; color: var(--accent); font-size: 1rem; }
.prose ul { padding-left: 1.1rem; }
.prose li { margin-bottom: 0.3rem; }
.prose .warn {
  border-left: 3px solid var(--yellow);
  padding-left: 0.7rem;
  color: #f3d99a;
}

/* ---------- divers ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgb(5 8 12 / 75%);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 30;
}
.modal .card { width: min(420px, 100%); margin: 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  background: #2a1a1d;
  border: 1px solid var(--danger);
  color: #ffd9db;
  padding: 0.6rem 1rem;
  border-radius: 10px;
  z-index: 40;
  max-width: min(560px, 92vw);
  text-align: center;
}
.toast.ok { background: #14281c; border-color: var(--accent); color: #cdf3dd; }

[hidden] { display: none !important; }
