/* Morpion : une colonne centrée, plateau carré, score dessous.
   Les couleurs sont toutes en haut du fichier (clair par défaut, sombre selon l'appareil
   ou le bouton). */
:root {
  --bg: #F4F5F8; --surface: #FFFFFF; --fg: #1A1E29; --muted: #667085; --line: #D6DAE3;
  --x: #2D5BE3; --o: #E2552B; --win-bg: #E6EDFF; --ok: #1F8A5B;
  --font: 'DM Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151C; --surface: #1B2030; --fg: #E8EAF0; --muted: #98A2B3; --line: #2C3345;
    --x: #7C9BFF; --o: #FF8A65; --win-bg: #26304F; --ok: #5FD3A0; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12151C; --surface: #1B2030; --fg: #E8EAF0; --muted: #98A2B3; --line: #2C3345;
  --x: #7C9BFF; --o: #FF8A65; --win-bg: #26304F; --ok: #5FD3A0; color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--fg); font: 400 16px/1.4 var(--font);
  padding-block: 20px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.wrap { max-width: 360px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
button, a { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--x); outline-offset: 2px; }
h1, h2, p { margin: 0; }

.retour { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: .875rem; }
.retour a { color: var(--muted); text-decoration: none; }
.retour a:hover { color: var(--fg); }
.solde { font-variant-numeric: tabular-nums; font-weight: 700; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h1 { font-size: 1.5rem; font-weight: 700; text-wrap: balance; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; font-size: .875rem; color: var(--muted); }
.ghost:hover { color: var(--fg); border-color: var(--muted); }

.carte { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.carte h2 { font-size: 1.125rem; }
.carte p { color: var(--muted); }
.carte[hidden], #jeu[hidden], [hidden] { display: none !important; }
#jeu { display: flex; flex-direction: column; gap: 18px; }

.levels { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.levels button { background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: .875rem; color: var(--muted); }
.levels button.on { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.levels #fantome { border-style: dashed; }
.levels #fantome.on { background: var(--x); border-color: var(--x); border-style: solid; color: var(--bg); }
.levels button:disabled { opacity: .5; cursor: default; }

#status { min-height: 1.5em; font-weight: 500; text-align: center; }
.gainline { text-align: center; font-weight: 700; color: var(--ok); margin-top: -10px; }

.board { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 8px; width: 100%; aspect-ratio: 1; }
.cell {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0;
  display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 0; overflow: hidden;
  transition: border-color .15s;
}
.cell:not(:disabled):hover { border-color: var(--muted); }
.cell:disabled { cursor: default; }
.cell.win { background: var(--win-bg); }
.cell.old svg, .cell.old .pion-cosmetique { opacity: .35; }
.cell svg { width: 58%; height: auto; }
.pion-cosmetique { display: block; font-size: clamp(2.4rem, 15vw, 4rem); line-height: 1;
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, .18)); }
.pion-cosmetique.neon { filter: drop-shadow(0 0 7px #7c9bff); }
.mark-x, .mark-o { fill: none; stroke-width: 9; stroke-linecap: round; }
.mark-x { stroke: var(--x); }
.mark-o { stroke: var(--o); }

.actions { display: flex; justify-content: center; }
.primary { display: inline-block; background: var(--fg); color: var(--bg); border: 0; border-radius: 10px; padding: 10px 20px; font-weight: 700; text-align: center; text-decoration: none; }
.primary:hover { opacity: .9; }
.primary:disabled { opacity: .5; cursor: default; }

.score { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.score div { border-top: 2px solid var(--line); padding-top: 8px; }
.score .n { display: block; font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.score .l { font-size: .8125rem; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.score .x { border-top-color: var(--x); }
.score .o { border-top-color: var(--o); }
.note { font-size: .8125rem; color: var(--muted); text-align: center; margin-top: -8px; }

.legal { display: flex; flex-wrap: wrap; gap: 4px 14px; justify-content: center; font-size: .8125rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: 14px; }
.legal p { flex-basis: 100%; text-align: center; }
.legal a { color: var(--muted); }

@media (prefers-reduced-motion: reduce) { .cell { transition: none; } }
