/* ===== Jetons ===== */
:root {
  --bg: #edf0fa;
  --surface: #ffffff;
  --surface-2: #f5f6fc;
  --ink: #1d1a3f;
  --muted: #5d5a7e;
  --line: #d8dbec;
  --royal: #2f4bd8;
  --royal-deep: #1f35a8;
  --royal-ink: #ffffff;
  --sun: #ffc53d;
  --sun-deep: #d99a00;
  --berry: #e0446a;
  --mint: #16a673;
  --shadow: 0 1px 0 rgba(29, 26, 63, .06), 0 8px 24px -12px rgba(29, 26, 63, .28);
  --font-display: "Bricolage Grotesque", "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  --font-ui: "Atkinson Hyperlegible", "Segoe UI", system-ui, -apple-system, sans-serif;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141230; --surface: #1e1b3e; --surface-2: #26234a; --ink: #eeebff; --muted: #aaa6d2; --line: #37335f;
    --royal: #7086ff; --royal-deep: #4b5fd6; --royal-ink: #0f0d26; --sun: #ffd45e; --sun-deep: #c99a1c;
    --berry: #ff6f8e; --mint: #3dd49b; --shadow: 0 1px 0 rgba(0,0,0,.3), 0 10px 30px -14px rgba(0,0,0,.7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141230; --surface: #1e1b3e; --surface-2: #26234a; --ink: #eeebff; --muted: #aaa6d2; --line: #37335f;
  --royal: #7086ff; --royal-deep: #4b5fd6; --royal-ink: #0f0d26; --sun: #ffd45e; --sun-deep: #c99a1c;
  --berry: #ff6f8e; --mint: #3dd49b; --shadow: 0 1px 0 rgba(0,0,0,.3), 0 10px 30px -14px rgba(0,0,0,.7);
  color-scheme: dark;
}

/* ===== Base ===== */
:root { box-sizing: border-box; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
html { scroll-padding-top: env(safe-area-inset-top, 0px); -webkit-text-size-adjust: 100%; }
*, *::before, *::after { box-sizing: inherit; }
body {
  margin: 0; min-height: 100%; background: var(--bg); color: var(--ink);
  font-family: var(--font-ui); font-size: 16px; line-height: 1.45;
  background-image:
    linear-gradient(45deg, rgba(47, 75, 216, .035) 25%, transparent 25%, transparent 75%, rgba(47, 75, 216, .035) 75%),
    linear-gradient(45deg, rgba(47, 75, 216, .035) 25%, transparent 25%, transparent 75%, rgba(47, 75, 216, .035) 75%);
  background-size: 64px 64px; background-position: 0 0, 32px 32px;
}
button { font: inherit; color: inherit; }
img, svg, canvas { max-width: 100%; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; border-radius: 8px; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.1; margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }

.app { max-width: 1180px; margin: 0 auto; padding: 14px clamp(12px, 3vw, 28px) 28px; }
.screen { display: none; }
.screen.active { display: block; animation: screen-in .28s ease-out; }
@keyframes screen-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ===== Boutons « à socle » ===== */
.btn {
  --b: var(--surface); --bd: var(--line); --fg: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  min-height: 44px; padding: .55em 1.1em; border-radius: 999px;
  background: var(--b); color: var(--fg); border: 2px solid var(--bd);
  box-shadow: 0 3px 0 var(--bd); font-weight: 700; cursor: pointer;
  transition: transform .08s ease, box-shadow .08s ease, background-color .15s;
  -webkit-tap-highlight-color: transparent; user-select: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.03); }
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--bd); }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; box-shadow: 0 3px 0 var(--bd); }
.btn-primary { --b: var(--royal); --bd: var(--royal-deep); --fg: var(--royal-ink); }
.btn-sun { --b: var(--sun); --bd: var(--sun-deep); --fg: #2a1f00; }
.btn-danger { --b: var(--surface); --bd: var(--berry); --fg: var(--berry); }
.btn-small { min-height: 38px; padding: .35em .9em; font-size: .92rem; }
.btn-wide { width: 100%; }
.btn .ico { width: 1.25em; height: 1.25em; flex: none; }
.link { background: none; border: 0; padding: .3em .2em; color: var(--royal); font-weight: 700; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

.seg { display: inline-flex; flex-wrap: wrap; gap: 6px; padding: 5px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; padding: .5em .9em; border-radius: 11px; font-weight: 700; cursor: pointer; color: var(--muted); min-height: 40px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 2px 0 var(--line), 0 0 0 2px var(--royal) inset; }

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; cursor: pointer; }
.toggle input { appearance: none; width: 50px; height: 30px; border-radius: 999px; background: var(--line); position: relative; cursor: pointer; flex: none; transition: background .15s; margin: 0; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s; }
.toggle input:checked { background: var(--mint); }
.toggle input:checked::after { transform: translateX(20px); }

/* ===== Barre du haut ===== */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; min-height: 48px; }
.topbar h2 { font-size: clamp(1.25rem, 3vw, 1.6rem); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--line); background: var(--surface); display: inline-grid; place-items: center; cursor: pointer; box-shadow: 0 3px 0 var(--line); flex: none; }
.icon-btn:active { transform: translateY(3px); box-shadow: none; }
.icon-btn svg { width: 22px; height: 22px; }

/* ===== Accueil ===== */
.hero { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: clamp(18px, 4vw, 48px); align-items: center; padding: clamp(8px, 3vw, 28px) 0 clamp(18px, 3vw, 30px); }
.wordmark { padding-top: .2em; font-family: var(--font-display); font-weight: 800; font-size: clamp(3.2rem, 11vw, 7.4rem); line-height: .86; letter-spacing: -0.045em; margin: 0; color: var(--ink); }
.wordmark .acc { display: inline-block; color: var(--royal); transform: translateY(-.04em) rotate(-6deg); }
.tagline { font-family: var(--font-display); font-weight: 600; font-size: clamp(1.1rem, 2.6vw, 1.5rem); color: var(--muted); margin-top: 14px; max-width: 30ch; }
.hero-strip { display: grid; grid-template-columns: repeat(6, 1fr); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); max-width: 460px; justify-self: end; width: 100%; }
.hero-strip .sq { aspect-ratio: 1; display: grid; place-items: center; }
.hero-strip .piece { position: static; width: 92%; height: 92%; transform: none; animation: wave .7s cubic-bezier(.3,1.6,.5,1) both; }
.hero-strip .sq:nth-child(2) .piece { animation-delay: .08s; } .hero-strip .sq:nth-child(3) .piece { animation-delay: .16s; }
.hero-strip .sq:nth-child(4) .piece { animation-delay: .24s; } .hero-strip .sq:nth-child(5) .piece { animation-delay: .32s; }
.hero-strip .sq:nth-child(6) .piece { animation-delay: .4s; }
@keyframes wave { 0% { transform: translateY(40%) scale(.6); opacity: 0; } 60% { transform: translateY(-14%) scale(1.05); opacity: 1; } 100% { transform: none; } }

.home-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.modes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.mode {
  position: relative; display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 14px;
  text-align: left; padding: 16px 18px; border-radius: 20px; cursor: pointer;
  background: var(--surface); border: 2px solid var(--line); box-shadow: 0 4px 0 var(--line);
  transition: transform .1s ease, box-shadow .1s ease, border-color .15s;
}
.mode:hover { border-color: var(--royal); }
.mode:active { transform: translateY(4px); box-shadow: none; }
.mode .m-ico { width: 64px; height: 64px; border-radius: 16px; display: grid; place-items: center; background: var(--surface-2); }
.mode .m-ico .piece { position: static; width: 54px; height: 54px; transform: none; }
.mode h3 { font-size: 1.22rem; }
.mode p { color: var(--muted); font-size: .95rem; margin-top: 2px; }
.mode.primary { grid-column: 1 / -1; padding: 20px 22px; background: var(--royal); border-color: var(--royal-deep); box-shadow: 0 5px 0 var(--royal-deep); color: var(--royal-ink); grid-template-columns: 76px 1fr auto; }
.mode.primary p { color: inherit; opacity: .85; }
.mode.primary .m-ico { width: 76px; height: 76px; background: rgba(255,255,255,.16); }
.mode.primary .m-ico .piece { width: 64px; height: 64px; }
.mode.primary h3 { font-size: 1.5rem; }
.opp-chip { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 14px; background: rgba(255,255,255,.16); font-weight: 700; font-size: .92rem; }
.opp-chip .emo { font-size: 1.5rem; line-height: 1; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 18px; box-shadow: var(--shadow); }
.player-card h3 { font-size: 1.35rem; }
.player-card .rank-sub { color: var(--muted); font-size: .92rem; }
.xpbar { height: 12px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; margin: 12px 0 6px; }
.xpbar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--sun), #ff9f43); border-radius: 999px; transition: width .6s ease; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.stat { background: var(--surface-2); border-radius: 14px; padding: 10px; text-align: center; }
.stat b { display: block; font-family: var(--font-display); font-size: 1.35rem; }
.stat span { font-size: .8rem; color: var(--muted); }
.home-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.stars { color: var(--sun-deep); letter-spacing: 1px; white-space: nowrap; }
:root[data-theme="dark"] .stars { color: var(--sun); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .stars { color: var(--sun); } }
.stars .off { opacity: .25; }

/* ===== Réglages de partie ===== */
.setup { display: grid; gap: 16px; max-width: 760px; }
.field h3 { font-size: 1.08rem; margin-bottom: 8px; font-family: var(--font-ui); font-weight: 700; }
.field .hint { color: var(--muted); font-size: .9rem; margin-top: 6px; }
.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.choice { text-align: left; padding: 12px 14px; border-radius: 16px; border: 2px solid var(--line); background: var(--surface); cursor: pointer; box-shadow: 0 3px 0 var(--line); }
.choice[aria-pressed="true"] { border-color: var(--royal); box-shadow: 0 3px 0 var(--royal-deep); }
.choice b { display: block; font-size: 1rem; }
.choice span { display: block; color: var(--muted); font-size: .86rem; margin-top: 2px; line-height: 1.35; }
.choice .emo { font-size: 1.6rem; display: block; margin-bottom: 4px; }

/* ===== Écran de partie ===== */
.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.board-col { width: min(100%, calc(100vh - 190px)); min-width: 280px; justify-self: center; }
@supports (height: 100dvh) { .board-col { width: min(100%, calc(100dvh - 190px)); } }
.pbar { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 4px 2px; }
.pbar .av { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--surface); border: 2px solid var(--line); font-size: 1.4rem; flex: none; }
.pbar .who { flex: 1; min-width: 0; }
.pbar .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pbar .who small { color: var(--muted); display: flex; align-items: center; gap: 6px; min-height: 1.2em; }
.pbar.turn .av { border-color: var(--royal); box-shadow: 0 0 0 3px color-mix(in srgb, var(--royal) 30%, transparent); }
.captured { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 0; }
.captured .piece { position: static; width: 18px; height: 18px; transform: none; margin-right: -5px; }
.captured .adv { margin-left: 8px; font-weight: 700; color: var(--muted); font-size: .85rem; }
.clock { font-family: var(--font-display); font-weight: 800; font-size: 1.3rem; padding: 4px 12px; border-radius: 12px; background: var(--surface); border: 2px solid var(--line); min-width: 84px; text-align: center; font-variant-numeric: tabular-nums; }
.clock.run { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.clock.low { background: var(--berry); color: #fff; border-color: var(--berry); }

.side { display: grid; gap: 14px; }
.coach { display: grid; grid-template-columns: 64px 1fr; gap: 10px; align-items: start; }
.owl { width: 64px; height: 64px; }
.owl .lid { transform-box: fill-box; transform-origin: center; transform: scaleY(0); }
.owl.blink .lid { animation: blink .18s ease 2; }
@keyframes blink { 50% { transform: scaleY(1); } }
.owl.happy .pupil { transform: translateY(-1px); }
.owl.worried .brow { opacity: 1; }
.owl .brow { opacity: 0; transition: opacity .2s; }
.bubble { position: relative; background: var(--surface); border: 2px solid var(--line); border-radius: 16px; padding: 10px 14px; min-height: 64px; display: flex; align-items: center; font-size: .98rem; }
.bubble::before { content: ""; position: absolute; left: -9px; top: 20px; width: 14px; height: 14px; background: var(--surface); border-left: 2px solid var(--line); border-bottom: 2px solid var(--line); transform: rotate(45deg); }
.bubble.warn { border-color: var(--berry); }
.bubble.warn::before { border-color: var(--berry); }
.bubble.good { border-color: var(--mint); }
.bubble.good::before { border-color: var(--mint); }
.bubble.pop { animation: bubble-pop .3s ease; }
@keyframes bubble-pop { 0% { transform: scale(.96); } 60% { transform: scale(1.02); } 100% { transform: none; } }
.actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.actions .btn { min-width: 0; }
.status-line { font-weight: 700; display: flex; align-items: center; gap: 8px; min-height: 28px; }
.dot-turn { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink); flex: none; }
.dot-turn.w { background: #fff; } .dot-turn.b { background: #111; }
.vbox { padding: 12px 14px; border-radius: 16px; background: var(--surface-2); border: 1px dashed var(--line); font-size: .92rem; }
.vbox b { font-family: var(--font-display); }
.checks-row { display: flex; gap: 14px; margin-top: 6px; }
.checks-row span { display: inline-flex; gap: 3px; align-items: center; }
.pip { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--berry); display: inline-block; }
.pip.on { background: var(--berry); }
.moves { max-height: 260px; overflow-y: auto; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); padding: 6px; font-variant-numeric: tabular-nums; }
.moves ol { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 2.4em 1fr 1fr; gap: 2px 4px; }
.moves li { display: contents; }
.moves .num { color: var(--muted); padding: 4px 2px; text-align: right; font-size: .9rem; }
.moves button { text-align: left; border: 0; background: transparent; padding: 4px 8px; border-radius: 8px; cursor: pointer; font-variant-emoji: text; display: flex; align-items: center; gap: 6px; }
.moves button:hover { background: var(--surface-2); }
.moves button.cur { background: var(--royal); color: var(--royal-ink); }
.q { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.q.best { background: var(--mint); } .q.ok { background: #8bc34a; } .q.inacc { background: var(--sun); } .q.blunder { background: var(--berry); }
.moves .empty { color: var(--muted); padding: 8px; font-size: .92rem; }
.review-bar { display: none; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-radius: 14px; background: var(--sun); color: #2a1f00; font-weight: 700; margin-top: 8px; }
.review-bar.show { display: flex; }

/* ===== Plateau ===== */
.board { position: relative; width: 100%; aspect-ratio: 1; border-radius: 12px; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; box-shadow: var(--shadow); container-type: inline-size; }
.board .squares { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); }
.board .sq { position: relative; background: var(--sq-l); }
.board .sq.d { background: var(--sq-d); }
.board .coord { position: absolute; font-size: clamp(8px, 2.3cqi, 13px); font-weight: 700; line-height: 1; pointer-events: none; opacity: .85; }
.board .coord.f { right: 4%; bottom: 4%; }
.board .coord.r { left: 4%; top: 4%; }
.board .sq.l .coord { color: var(--sq-d-text, var(--sq-d)); }
.board .sq.d .coord { color: var(--sq-l-text, var(--sq-l)); }
.board .layer { position: absolute; inset: 0; pointer-events: none; }
.board .mark { position: absolute; top: 0; left: 0; width: 12.5%; height: 12.5%; }
.mark.last { background: var(--hl-last); }
.mark.sel { background: var(--hl-sel); }
.mark.check { background: radial-gradient(circle, rgba(255, 40, 70, .85) 0%, rgba(255, 40, 70, .45) 40%, transparent 72%); animation: pulse 1.1s ease-in-out infinite; }
.mark.hint { box-shadow: inset 0 0 0 4px var(--sun); animation: pulse 1s ease-in-out infinite; border-radius: 6px; }
.mark.threat { box-shadow: inset 0 0 0 4px var(--berry); animation: pulse .9s ease-in-out 3; border-radius: 6px; }
.mark.hill { background: repeating-linear-gradient(45deg, rgba(255, 197, 61, .32) 0 6px, rgba(255, 197, 61, .12) 6px 12px); }
.mark.dot::after { content: ""; position: absolute; left: 50%; top: 50%; width: 30%; height: 30%; transform: translate(-50%, -50%); border-radius: 50%; background: var(--dot); }
.mark.ring::after { content: ""; position: absolute; inset: 6%; border-radius: 50%; border: 5px solid var(--dot); }
.mark.wrong { background: rgba(224, 68, 106, .5); animation: fade-out .8s ease forwards; }
.mark.right { background: rgba(22, 166, 115, .5); animation: fade-out .9s ease forwards; }
@keyframes fade-out { to { opacity: 0; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
.board .pieces { position: absolute; inset: 0; }
.piece { position: absolute; top: 0; left: 0; width: 12.5%; height: 12.5%; will-change: transform; pointer-events: none; }
.piece svg { width: 100%; height: 100%; display: block; overflow: visible; }
.piece .o { fill: var(--po); stroke: var(--po); stroke-width: 7px; stroke-linejoin: round; }
.piece .f { fill: var(--pf); }
.piece .d { fill: none; stroke: var(--pd); stroke-width: 3px; stroke-linecap: round; stroke-linejoin: round; }
.piece .dd { fill: var(--pd); }
.piece .face { display: var(--face, none); }
.piece.w { --po: var(--w-o); --pf: var(--w-f); --pd: var(--w-d); filter: var(--w-filter, none); }
.piece.b { --po: var(--b-o); --pf: var(--b-f); --pd: var(--b-d); filter: var(--b-filter, none); }
.piece.dragging { z-index: 10; transition: none !important; }
.piece.dragging svg { transform: scale(1.14) translateY(-6%); filter: drop-shadow(0 8px 6px rgba(0,0,0,.28)); }
.piece.land svg { animation: land .22s ease-out; }
@keyframes land { 0% { transform: scale(1.1, .9); } 60% { transform: scale(.97, 1.04); } 100% { transform: none; } }
.piece.promote svg { animation: promote .45s cubic-bezier(.3,1.7,.5,1); }
@keyframes promote { 0% { transform: scale(.3) rotate(-30deg); } 100% { transform: none; } }
.board .arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.board canvas.fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.board.shake { animation: shake .35s ease; }
@keyframes shake { 20% { transform: translate(-4px, 2px); } 40% { transform: translate(4px, -2px); } 60% { transform: translate(-3px, 1px); } 80% { transform: translate(2px, 0); } }
.board.locked { cursor: default; }
.board .promo { position: absolute; inset: 0; background: rgba(15, 12, 40, .55); display: none; place-items: center; z-index: 20; }
.board .promo.show { display: grid; }
.promo .box { background: var(--surface); border-radius: 18px; padding: 12px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: min(88%, 380px); box-shadow: var(--shadow); }
.promo .box p { grid-column: 1 / -1; text-align: center; font-weight: 700; }
.promo button { aspect-ratio: 1; border-radius: 12px; border: 2px solid var(--line); background: var(--sq-l); cursor: pointer; position: relative; padding: 0; }
.promo button .piece { width: 100%; height: 100%; }

/* Effets de capture sur la pièce prise */
.piece.fx-splat svg { animation: fx-splat .42s ease-in forwards; transform-origin: 50% 90%; }
@keyframes fx-splat { 0% { transform: none; } 35% { transform: scale(1.18, .78); } 100% { transform: scale(1.7, .05); opacity: 0; } }
.piece.fx-glitch svg { animation: fx-glitch .42s steps(2) forwards; }
@keyframes fx-glitch {
  0% { transform: none; }
  20% { transform: translate(-6%, 2%); filter: drop-shadow(4px 0 0 #ff2bd6) drop-shadow(-4px 0 0 #2bf3ff); }
  40% { transform: translate(5%, -3%); clip-path: inset(10% 0 40% 0); }
  60% { transform: translate(-3%, 4%); clip-path: inset(50% 0 5% 0); opacity: .8; }
  100% { transform: scale(.2); opacity: 0; clip-path: inset(45% 0 45% 0); }
}
.piece.fx-dust svg { animation: fx-dust .45s ease-in forwards; }
@keyframes fx-dust { to { transform: translateY(12%) scale(.7); opacity: 0; } }

/* ===== Thèmes de plateau ===== */
.th-classique {
  --face: none;
  --sq-l: #ecd6b3; --sq-d: #b4825a; --sq-l-text: #f3e3c8; --sq-d-text: #8b5f3d;
  --hl-last: rgba(255, 214, 92, .45); --hl-sel: rgba(255, 214, 92, .7); --dot: rgba(40, 24, 12, .32);
  --w-o: #3a2a1e; --w-f: url(#g-cl-w); --w-d: #9a7a58;
  --b-o: #120c08; --b-f: url(#g-cl-b); --b-d: #c9a47a;
}
.th-potager {
  --face: inline;
  --sq-l: #e9f4c9; --sq-d: #9dcb63; --sq-l-text: #eef7d6; --sq-d-text: #6a9a35;
  --hl-last: rgba(255, 200, 60, .5); --hl-sel: rgba(255, 170, 40, .62); --dot: rgba(46, 80, 20, .36);
  --w-o: #5a2a0c; --w-f: url(#g-po-w); --w-d: #2e8f45;
  --b-o: #22103d; --b-f: url(#g-po-b); --b-d: #47c065;
}
.th-neon {
  --face: none;
  --sq-l: #1c2554; --sq-d: #0d1331; --sq-l-text: #2e3a78; --sq-d-text: #4c5aa8;
  --hl-last: rgba(70, 243, 255, .22); --hl-sel: rgba(255, 82, 220, .32); --dot: rgba(160, 230, 255, .45);
  --w-o: #46f3ff; --w-f: url(#g-ne-w); --w-d: #46f3ff; --w-filter: drop-shadow(0 0 2px #46f3ff) drop-shadow(0 0 6px rgba(70, 243, 255, .55));
  --b-o: #ff52dc; --b-f: url(#g-ne-b); --b-d: #ff52dc; --b-filter: drop-shadow(0 0 2px #ff52dc) drop-shadow(0 0 6px rgba(255, 82, 220, .55));
}
body.th-neon .board .sq { box-shadow: inset 0 0 0 .5px rgba(90, 120, 255, .35); }
body.th-neon .board { box-shadow: 0 0 0 2px #2b3a8a, 0 0 28px -6px rgba(70, 243, 255, .5); }

/* ===== Puzzles ===== */
.pz-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.pz-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.tag { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: .84rem; font-weight: 700; color: var(--muted); }
.storm-hud { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.storm-hud .big { font-family: var(--font-display); font-weight: 800; font-size: 2.4rem; line-height: 1; font-variant-numeric: tabular-nums; }
.storm-hud .lbl { color: var(--muted); font-size: .85rem; }
.combo { height: 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.combo > span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--mint), var(--sun)); transition: width .25s; }
.time-bonus { color: var(--mint); font-weight: 800; }

/* ===== Fenêtres ===== */
.modal-wrap { position: fixed; inset: 0; z-index: 100; display: none; align-items: center; justify-content: center; padding: max(16px, env(safe-area-inset-top, 0px)) 16px max(16px, env(safe-area-inset-bottom, 0px)); background: rgba(15, 12, 40, .5); }
.modal-wrap.show { display: flex; animation: fade-in .18s ease; }
@keyframes fade-in { from { opacity: 0; } }
.modal { background: var(--surface); color: var(--ink); border-radius: 24px; padding: 22px; width: min(520px, 100%); max-height: 100%; overflow-y: auto; box-shadow: 0 30px 60px -20px rgba(0,0,0,.5); animation: modal-in .28s cubic-bezier(.2,1.3,.5,1); }
@keyframes modal-in { from { transform: translateY(14px) scale(.97); opacity: 0; } }
.modal h2 { font-size: 1.7rem; margin-bottom: 6px; }
.modal .lead { color: var(--muted); }
.modal .row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.modal .row .btn { flex: 1 1 140px; }
.result-title { font-size: clamp(2.2rem, 7vw, 3.2rem) !important; }
.result-title.win { color: var(--mint); } .result-title.loss { color: var(--berry); }
.gains { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.gain { padding: 8px 12px; border-radius: 12px; background: var(--surface-2); font-weight: 700; }
.moments { display: grid; gap: 8px; margin-top: 14px; }
.moment { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface-2); font-size: .94rem; }
.level-list { display: grid; gap: 10px; margin-top: 16px; }
.level-list .choice { width: 100%; }
.help-list { display: grid; gap: 10px; margin-top: 12px; }
.help-item { display: grid; grid-template-columns: 48px 1fr; gap: 12px; align-items: center; }
.help-item .piece { position: static; width: 48px; height: 48px; transform: none; }
.help-item p { font-size: .95rem; }
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.theme-card { text-align: left; border: 2px solid var(--line); border-radius: 18px; background: var(--surface); padding: 10px; cursor: pointer; box-shadow: 0 3px 0 var(--line); }
.theme-card[aria-pressed="true"] { border-color: var(--royal); box-shadow: 0 3px 0 var(--royal-deep); }
.theme-card .mini { display: grid; grid-template-columns: repeat(4, 1fr); border-radius: 10px; overflow: hidden; margin-bottom: 8px; }
.theme-card .mini div { aspect-ratio: 1; display: grid; place-items: center; }
.theme-card .mini .piece { position: static; width: 90%; height: 90%; transform: none; }
.theme-card b { display: block; }
.theme-card span { color: var(--muted); font-size: .86rem; }
.toast { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom, 0px)); transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 14px; font-weight: 700; opacity: 0; transition: .25s; z-index: 200; pointer-events: none; max-width: 92vw; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.credits { color: var(--muted); font-size: .86rem; margin-top: 18px; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .game-layout { grid-template-columns: minmax(0, 1fr) minmax(250px, 300px); gap: 14px; }
  .home-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  .game-layout { grid-template-columns: minmax(0, 1fr); }
  .board-col { width: min(100%, 620px, calc(100vh - 210px)); min-width: 260px; }
  .side { max-width: 620px; width: 100%; justify-self: center; }
}
@supports (height: 100dvh) {
  @media (max-width: 720px) { .board-col { width: min(100%, 620px, calc(100dvh - 210px)); } }
}
@media (max-width: 640px) {
  .hero { grid-template-columns: minmax(0, 1fr); }
  .hero-strip { justify-self: stretch; max-width: none; }
  .modes { grid-template-columns: minmax(0, 1fr); }
  .mode.primary { grid-template-columns: 64px 1fr; }
  .mode.primary .m-ico { width: 64px; height: 64px; }
  .mode.primary .opp-chip { grid-column: 1 / -1; justify-self: start; }
  .app { padding-top: 8px; }
  .moves { max-height: 180px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

.mode.primary .stars { color: var(--sun) !important; }
.mode.primary .stars .off { opacity: .35; }
.opp-chip > span:last-child { line-height: 1.25; }
.board.locked .piece { cursor: default; }
.board:not(.locked) { cursor: pointer; }
.side .btn .ico { width: 1.1em; height: 1.1em; }
.actions .btn span { overflow: hidden; text-overflow: ellipsis; }
.review-bar .icon-btn { width: 38px; height: 38px; box-shadow: none; }
.player-card .stat b { font-size: 1.25rem; }

.piece.mini { position: relative; display: inline-block; width: 1.6em; height: 1.6em; vertical-align: -0.42em; transform: none; margin-right: 1px; }
.san { white-space: nowrap; }
.moves button.cur .piece.mini { filter: drop-shadow(0 0 1px #fff); }

/* ===== V2 : canard, roque, étoiles, académie, distance ===== */
.piece.duck { --po: #6b4300; --pf: url(#g-duck); --pd: #b8740a; filter: drop-shadow(0 3px 2px rgba(0,0,0,.25)); }
.mark.castle { background: rgba(255, 197, 61, .3); }
.mark.castle::after { content: ""; position: absolute; inset: 9%; border-radius: 50%; border: 4px dashed #d99a00; }
.mark.duckable { background: rgba(255, 214, 64, .2); }
.mark.duckable::after { content: ""; position: absolute; left: 50%; top: 50%; width: 18%; height: 18%; transform: translate(-50%, -50%); border-radius: 50%; background: rgba(214, 150, 0, .6); }
.mark.star::after { content: ""; position: absolute; inset: 18%; background: linear-gradient(#ffe27a, #ffb300); clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); animation: star-bob 1.6s ease-in-out infinite; filter: drop-shadow(0 2px 2px rgba(0,0,0,.25)); }
@keyframes star-bob { 50% { transform: translateY(-7%) scale(1.07); } }
.isle { display: grid; gap: 10px; }
.isle h3 { font-size: 1.3rem; }
.lessons { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.lesson-btn { text-align: left; padding: 12px 14px; border-radius: 16px; border: 2px solid var(--line); background: var(--surface); cursor: pointer; box-shadow: 0 3px 0 var(--line); display: grid; gap: 4px; }
.lesson-btn:active { transform: translateY(3px); box-shadow: none; }
.lesson-btn.done { border-color: var(--mint); box-shadow: 0 3px 0 var(--mint); }
.code-box { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-radius: 16px; background: var(--surface-2); border: 2px dashed var(--royal); }
.code-box .code { font-family: var(--font-display); font-weight: 800; font-size: 1.9rem; letter-spacing: .14em; line-height: 1.1; }
.code-box .lbl { color: var(--muted); font-size: .85rem; }
.code-box .code-btns { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.code-input.pseudo-input { width: 100%; max-width: 22ch; letter-spacing: .02em; text-transform: none; font-size: 1.15rem; }
.code-input { font: inherit; font-family: var(--font-display); font-weight: 800; font-size: 1.4rem; letter-spacing: .22em; text-transform: uppercase; padding: 8px 12px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); color: var(--ink); width: 9ch; }
.online { width: 9px; height: 9px; border-radius: 50%; background: var(--mint); display: inline-block; }
.online.offline { background: var(--line); }
.av img { width: 100%; height: 100%; border-radius: 10px; object-fit: cover; }
.ask-note { font-size: .8rem; color: var(--muted); }
#game-remote { display: grid; gap: 8px; }
#game-remote[hidden], #ac-lesson[hidden], #ac-map[hidden] { display: none; }
