:root {
  color-scheme: dark;
  --bg: #080b1b;
  --panel: rgba(20, 25, 53, 0.84);
  --panel-edge: rgba(255, 255, 255, 0.1);
  --text: #f8f8ff;
  --muted: #abb2d1;
  --x: #ff5f86;
  --o: #5de1dc;
  --accent: #8b78ff;
  --accent-2: #6550e8;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.35);
  --page-glow-1: rgba(93, 225, 220, 0.15);
  --page-glow-2: rgba(255, 95, 134, 0.13);
  --page-glow-3: rgba(139, 120, 255, 0.2);
  --cell: rgba(255, 255, 255, 0.12);
  --cell-edge: rgba(255, 255, 255, 0.39);
  --cell-hover: rgba(255, 255, 255, 0.18);
  --cell-edge-hover: rgba(255, 255, 255, 0.58);
  --cell-win: rgba(255, 255, 255, 0.2);
  --cell-shadow: 0 2px 8px rgba(0, 0, 0, 0.32);
  /* La lueur des symboles porte sur fond sombre ; sur blanc elle bave. */
  --mark-glow: 0 0 18px currentColor;
  --mark-inset: inset 1px 1px 0 rgba(255, 255, 255, 0.16);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f4fb;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-edge: rgba(35, 42, 77, 0.12);
  --text: #171a31;
  --muted: #68708e;
  --shadow: 0 28px 70px rgba(53, 58, 97, 0.14);
  --page-glow-1: rgba(93, 225, 220, 0.22);
  --page-glow-2: rgba(255, 95, 134, 0.14);
  --page-glow-3: rgba(139, 120, 255, 0.16);
  /* Cases franchement blanches, posees sur le panneau par la bordure et l'ombre
     plutot que par leur remplissage : c'est le seul moyen de les detacher d'un
     panneau lui-meme quasi blanc. */
  --cell: #ffffff;
  --cell-edge: rgba(35, 42, 77, 0.54);
  --cell-hover: #ffffff;
  --cell-edge-hover: var(--accent);
  --cell-win: #ffffff;
  --cell-shadow: 0 2px 7px rgba(53, 58, 97, 0.16);
  --mark-glow: none;
  --mark-inset: none;
  /* #ff5f86 et #5de1dc sont lisibles sur fond sombre, delaves sur blanc. */
  --x: #db1e51;
  --o: #0b7b76;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 20%, var(--page-glow-1), transparent 30rem),
    radial-gradient(circle at 88% 10%, var(--page-glow-2), transparent 28rem),
    radial-gradient(circle at 50% 100%, var(--page-glow-3), transparent 34rem),
    var(--bg);
}

button { font: inherit; }

.shell {
  width: min(100% - 32px, 560px);
  margin: 0 auto;
  padding: 42px 0 56px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 26px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
}

.brand-mark {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid var(--panel-edge);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  font-weight: 900;
}

.brand-mark span:first-child { color: var(--x); }
.brand-mark span:last-child { color: var(--o); }
.brand h1 { margin: 0; font-size: 1.55rem; letter-spacing: -0.04em; }
.eyebrow { margin: 0 0 3px; color: var(--muted); font-size: 0.68rem; font-weight: 800; letter-spacing: 0.18em; }

.header-controls { display: flex; align-items: center; gap: 7px; }
.language-switcher,
.theme-switcher,
.sound-switcher {
  display: flex;
  gap: 3px;
  padding: 4px;
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
}
.language-switcher button,
.theme-switcher button,
.sound-switcher button {
  width: 34px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 0.68rem;
  font-weight: 850;
}
.theme-switcher button { font-size: 0.92rem; }
.language-switcher button.active,
.theme-switcher button.active,
.sound-switcher button:not(.muted) { color: var(--text); background: rgba(139, 120, 255, 0.18); }
.sound-switcher button { display: grid; place-items: center; }
.sound-switcher svg { width: 17px; height: 17px; }
/* Une seule des deux icones est dans le flux ; `muted` les echange. */
.sound-switcher .icon-sound-off,
.sound-switcher button.muted .icon-sound-on { display: none; }
.sound-switcher button.muted .icon-sound-off { display: block; }

.panel {
  position: relative;
  overflow: hidden;
  padding: clamp(26px, 6vw, 44px);
  border: 1px solid var(--panel-edge);
  border-radius: 28px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.055), transparent), var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.intro { text-align: center; }
.hero-symbols { color: rgba(255, 255, 255, 0.13); font-family: "Comic Sans MS", "Bradley Hand", cursive; font-size: clamp(4rem, 18vw, 7.5rem); font-weight: 950; font-style: italic; letter-spacing: -0.13em; line-height: 0.9; transform: rotate(-2deg); }
.hero-symbols.small { font-size: clamp(3.2rem, 14vw, 5.5rem); }
.intro h2 { margin: 18px 0 12px; font-size: clamp(2rem, 9vw, 3.45rem); line-height: 0.98; letter-spacing: -0.065em; }
.intro > p:not(.fine-print) { max-width: 390px; margin: 0 auto 28px; color: var(--muted); font-size: 1.03rem; line-height: 1.6; }
.fine-print { margin: 17px 0 0; color: #858dab; font-size: 0.75rem; }
.name-form { display: grid; width: min(100%, 330px); gap: 9px; margin: 0 auto; text-align: left; }
.name-form label { color: var(--muted); font-size: 0.76rem; font-weight: 800; }
.name-form input {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  border: 1px solid var(--panel-edge);
  border-radius: 14px;
  outline: none;
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  font: inherit;
  font-size: 1rem;
}
.name-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(139, 120, 255, 0.15); }
.name-form .button { margin-top: 5px; }
.choice-divider { display: flex; align-items: center; gap: 10px; margin: 3px 0 -2px; color: var(--muted); font-size: 0.72rem; text-align: center; }
.choice-divider::before, .choice-divider::after { content: ""; flex: 1; height: 1px; background: var(--panel-edge); }

.button {
  border: 0;
  border-radius: 15px;
  cursor: pointer;
  font-weight: 800;
  transition: transform 160ms ease, filter 160ms ease, background 160ms ease;
}
.button:hover { transform: translateY(-2px); filter: brightness(1.08); }
.button:active { transform: translateY(0); }
.button:disabled { cursor: wait; filter: grayscale(0.6); opacity: 0.65; }
.button-primary { min-height: 54px; padding: 0 25px; color: white; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 12px 30px rgba(101, 80, 232, 0.32); }
.button-secondary { min-height: 45px; padding: 0 17px; color: var(--text); background: rgba(255, 255, 255, 0.09); border: 1px solid var(--panel-edge); }
.button-match { display: flex; min-height: 54px; align-items: center; justify-content: center; gap: 10px; padding: 0 22px; border: 1px solid rgba(93, 225, 220, 0.35); color: var(--text); background: linear-gradient(135deg, rgba(93, 225, 220, 0.13), rgba(139, 120, 255, 0.14)); }
.match-radar { position: relative; width: 12px; height: 12px; border-radius: 50%; background: var(--o); box-shadow: 0 0 12px var(--o); }
.match-radar::after { content: ""; position: absolute; inset: -5px; border: 1px solid var(--o); border-radius: 50%; animation: radar 1.4s ease-out infinite; }
.compact { font-size: 0.84rem; }

.game-view { padding: clamp(22px, 5vw, 34px); }
.game-topline { text-align: center; }
.game-names { margin: 0; font-size: clamp(1.35rem, 6vw, 2rem); font-weight: 900; letter-spacing: -0.045em; }
.players { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; margin: 28px 0 21px; }
.player-card { position: relative; display: flex; align-items: center; gap: 9px; min-width: 0; padding: 11px 12px; border: 1px solid transparent; border-radius: 15px; color: var(--muted); background: rgba(255, 255, 255, 0.04); transition: border-color 180ms ease, background 180ms ease, transform 180ms ease; }
.player-card.active { border-color: var(--accent); background: rgba(139, 120, 255, 0.15); color: var(--text); animation: active-player 1.25s ease-in-out infinite; }
.player-card.active::before { content: ""; position: absolute; top: -5px; right: -5px; width: 11px; height: 11px; border: 3px solid var(--panel); border-radius: 50%; background: var(--o); box-shadow: 0 0 14px var(--o); }
.player-card.me::after { content: attr(data-me-label); color: var(--o); font-size: 0.7rem; font-weight: 800; }
/* Tirage au sort : la surbrillance qui alterne, puis le rebond du gagnant.
   `active` est suspendu pendant ce temps (voir render), donc les deux
   animations ne se disputent pas la carte. */
.player-card.tirage { border-color: var(--accent); background: rgba(139, 120, 255, 0.22); color: var(--text); }
.player-card.tirage-gagnant { border-color: var(--o); background: rgba(93, 225, 220, 0.2); color: var(--text); animation: tirage-rebond 620ms cubic-bezier(.2, .9, .3, 1.4) both; }
@keyframes tirage-rebond {
  0% { transform: scale(1); }
  35% { transform: scale(1.13); }
  62% { transform: scale(0.98); }
  100% { transform: scale(1.04); }
}
.player-symbol { position: relative; display: grid; flex: 0 0 33px; height: 33px; place-items: center; border-radius: 10px; background: rgba(0, 0, 0, 0.22); font-size: 0; }
.player-symbol.x { color: var(--x); }
.player-symbol.o { color: var(--o); }
.player-symbol.x::before, .player-symbol.x::after { content: ""; position: absolute; width: 20px; height: 4px; border-radius: 80% 45% 70% 40%; background: currentColor; box-shadow: 0 0 9px currentColor; }
.player-symbol.x::before { transform: rotate(43deg); }
.player-symbol.x::after { width: 22px; height: 3px; transform: rotate(-48deg); }
.player-symbol.o::before { content: ""; width: 16px; height: 17px; border: 3px solid currentColor; border-radius: 48% 55% 46% 53%; box-shadow: 0 0 8px currentColor; transform: rotate(-8deg); }
.player-label { min-width: 0; overflow: hidden; font-size: 0.8rem; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.versus { color: #747c9e; font-size: 0.65rem; font-weight: 900; }
.status { min-height: 31px; margin: 0 0 18px; text-align: center; color: var(--muted); font-weight: 800; }
.status.your-turn { color: var(--text); font-size: 1.06rem; }
.status.your-turn::before { content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 9px; border-radius: 50%; background: var(--o); box-shadow: 0 0 16px var(--o); animation: turn-dot 900ms ease-in-out infinite; }
.status.searching::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 9px; border: 2px solid rgba(93, 225, 220, 0.25); border-top-color: var(--o); border-radius: 50%; animation: spin 850ms linear infinite; }

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  width: min(100%, 390px);
  margin: 0 auto;
  transition: filter 180ms ease, transform 180ms ease;
}
.board.your-turn { filter: drop-shadow(0 0 18px rgba(139, 120, 255, 0.2)); }

.cell {
  position: relative;
  display: grid;
  aspect-ratio: 1;
  place-items: center;
  border: 1px solid var(--cell-edge);
  border-radius: 19px;
  color: var(--text);
  background: var(--cell);
  box-shadow: var(--cell-shadow);
  cursor: pointer;
  font-size: 0;
  line-height: 1;
  transition: transform 130ms ease, background 130ms ease, border-color 130ms ease;
}
.cell:not(:disabled):hover { transform: scale(1.035); border-color: var(--cell-edge-hover); background: var(--cell-hover); }
.cell:disabled { cursor: default; }
.cell.x { color: var(--x); text-shadow: 0 0 28px rgba(255, 95, 134, 0.25); }
.cell.o { color: var(--o); text-shadow: 0 0 28px rgba(93, 225, 220, 0.25); }
.cell.x::before, .cell.x::after { content: ""; position: absolute; width: 60%; height: 8%; border-radius: 90% 38% 75% 46%; background: currentColor; box-shadow: var(--mark-glow); }
.cell.x::before { transform: rotate(42deg) translateY(1px); }
.cell.x::after { width: 63%; height: 7%; transform: rotate(-47deg) translateX(1px); opacity: 0.94; }
.cell.o::before { content: ""; width: 48%; height: 51%; border: clamp(6px, 1.7vw, 9px) solid currentColor; border-radius: 47% 54% 45% 57%; box-shadow: var(--mark-glow), var(--mark-inset); transform: rotate(-7deg); }
.cell.win { animation: winner 700ms ease both; border-color: currentColor; background: var(--cell-win); }

@keyframes winner {
  0%, 100% { transform: scale(1); }
  45% { transform: scale(1.08) rotate(2deg); }
}

@keyframes active-player {
  0%, 100% { transform: translateY(0); box-shadow: 0 0 0 rgba(139, 120, 255, 0); }
  50% { transform: translateY(-3px); box-shadow: 0 8px 26px rgba(139, 120, 255, 0.3); }
}

@keyframes turn-dot {
  0%, 100% { transform: scale(0.75); opacity: 0.55; }
  50% { transform: scale(1.25); opacity: 1; }
}

@keyframes radar { from { transform: scale(0.5); opacity: 1; } to { transform: scale(1.7); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }

.game-actions { display: flex; flex-direction: column; align-items: center; gap: 15px; margin-top: 24px; }
.text-button { padding: 6px; border: 0; color: #9da5c5; background: none; cursor: pointer; font-size: 0.82rem; text-decoration: underline; text-underline-offset: 4px; }
.toast { position: fixed; left: 50%; bottom: 25px; z-index: 10; transform: translate(-50%, 20px); padding: 12px 18px; border: 1px solid var(--panel-edge); border-radius: 999px; color: white; background: #252b52; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity 180ms ease, transform 180ms ease; font-size: 0.86rem; font-weight: 750; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.ad-slot { z-index: 40; border: 1px solid rgba(139,120,255,.45); border-radius: 18px; background: rgba(8,11,27,.94); box-shadow: 0 22px 70px rgba(0,0,0,.48); }
.ad-slot.image-mode { display: block; padding: 7px; text-align: center; }
.ad-slot.popup-mode { position: fixed; left: 50%; bottom: 18px; width: min(920px, calc(100vw - 36px)); margin: 0; opacity: 0; transform: translate(-50%, calc(100% + 55px)); transition: opacity 420ms ease, transform 520ms cubic-bezier(.2,.85,.2,1); }
.ad-slot.popup-mode.show { opacity: 1; transform: translate(-50%, 0); }
.ad-slot.inline-mode { width: 100%; margin-top: 18px; }
.ad-image-link { display: block; width: 100%; margin: 0 auto; overflow: hidden; border-radius: 13px; transition: filter 160ms ease; }
.ad-image-link:hover { filter: brightness(1.08); }
.ad-image-link img { display: block; width: 100%; height: auto; }
.ad-close { position: absolute; top: -12px; right: -12px; z-index: 2; display: grid; width: 29px; height: 29px; place-items: center; border: 1px solid rgba(255,255,255,.2); border-radius: 50%; color: white; background: #202541; box-shadow: 0 5px 15px rgba(0,0,0,.3); cursor: pointer; font-size: 1rem; line-height: 1; }
.ad-copy { display: contents; }
.ad-slot h2 { margin: 2px 0 4px; color: var(--text); font-size: 1rem; }
.ad-slot > div > p:last-child { margin: 0; color: var(--muted); font-size: 0.8rem; line-height: 1.45; }
.ad-link { flex: 0 0 auto; padding: 10px 14px; border-radius: 11px; color: white; background: var(--ad-accent, var(--accent)); font-size: 0.78rem; font-weight: 850; text-decoration: none; }
.footer { margin: 25px auto 0; color: var(--muted); font-size: 0.68rem; line-height: 1.7; text-align: center; }
.footer a { color: inherit; text-decoration: none; }
.footer a:hover { color: var(--text); }
.footer nav { display: flex; justify-content: center; flex-wrap: wrap; gap: 5px 14px; margin-top: 5px; }
.hidden { display: none !important; }

@media (max-width: 430px) {
  .shell { width: min(100% - 20px, 560px); padding-top: 22px; }
  .site-header { margin-bottom: 16px; }
  .brand h1 { font-size: 1.25rem; }
  .brand-mark { width: 42px; height: 42px; }
  .site-header { align-items: flex-start; }
  .header-controls { flex-direction: column; align-items: flex-end; }
  .ad-slot.popup-mode { bottom: 10px; width: calc(100vw - 20px); border-radius: 14px; }
  .ad-slot.image-mode { padding: 5px; }
  .ad-image-link { border-radius: 10px; }
  .panel { border-radius: 23px; }
  .player-label { font-size: 0.72rem; }
  .player-card { padding: 9px 8px; gap: 5px; }
  .cell { border-radius: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
