/* Dames Tomette : terre cuite, buis et ébène sur fond cyprès.
   Contrainte : pas de cartes, des filets ; une seule couleur d'accent (terre cuite), l'ocre réservé au jeu. */
:root {
  --bg: #1c2621;
  --bg-2: #232f29;
  --line: #3a4a41;
  --ink: #f1ece2;
  --muted: #b7b2a5;
  --accent: #c9653c;
  --accent-ink: #1b110b;
  --ochre: #f0b84a;
  --sq-light: #ebe4d6;
  --sq-dark: #9b4a2c;
  --frame: #2a1b13;
  --p-light: #ecdcb6;
  --p-light-edge: #b99c63;
  --p-dark: #241b17;
  --p-dark-edge: #5b463b;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { font: 17px/1.5 var(--sans); overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-text-size-adjust: 100%; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--ochre); outline-offset: 2px; }

.screen { min-height: 100dvh; padding: calc(var(--sat) + 12px) calc(var(--sar) + 16px) calc(var(--sab) + 12px) calc(var(--sal) + 16px); }

/* ---------- Accueil ---------- */
#home { display: flex; flex-direction: column; max-width: 560px; margin: 0 auto; }
.home-head { padding: 6vh 0 3vh; }
.mark { display: grid; grid-template-columns: repeat(2, 14px); gap: 0; width: 28px; margin-bottom: 18px; }
.mark i { width: 14px; height: 14px; background: var(--sq-light); }
.mark i:nth-child(2), .mark i:nth-child(3) { background: var(--accent); }
h1 { font: 600 clamp(64px, 18vw, 104px)/0.95 var(--serif); margin: 0; letter-spacing: -0.02em; }
.tagline { font: italic 20px/1.3 var(--serif); color: var(--muted); margin: 10px 0 0; }
.home-body { flex: 1; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { font-size: 14px; color: var(--muted); padding: 0; margin: 18px 0 8px; }

.variants { border-top: 1px solid var(--line); }
.variant { display: flex; align-items: center; gap: 16px; padding: 14px 4px; border-bottom: 1px solid var(--line); cursor: pointer; min-height: 72px; }
.variant input { position: absolute; opacity: 0; }
.v-txt { display: flex; flex-direction: column; }
.v-txt b { font: 600 24px/1.15 var(--serif); }
.v-txt small { color: var(--muted); font-size: 15px; }
.variant:has(input:checked) .v-txt b { color: var(--accent); }
.variant:has(input:checked) .mini { outline: 2px solid var(--accent); outline-offset: 3px; }
.variant:has(input:focus-visible) { outline: 3px solid var(--ochre); }
.mini { flex: none; width: 44px; height: 44px; background-color: var(--sq-light); }
.mini10 { background-image: conic-gradient(var(--sq-dark) 25%, transparent 0 50%, var(--sq-dark) 0 75%, transparent 0); background-size: 8.8px 8.8px; }
.mini8 { background-image: conic-gradient(var(--sq-dark) 25%, transparent 0 50%, var(--sq-dark) 0 75%, transparent 0); background-size: 11px 11px; }

.seg { display: flex; gap: 0; flex-wrap: wrap; }
.seg legend { width: 100%; }
.seg label { flex: 1 1 0; position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg label > span:last-child, .seg label > span:only-of-type { display: flex; }
.seg label span { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 6px 10px; text-align: center; font-size: 15px; line-height: 1.2; }
.seg label { display: flex; align-items: center; justify-content: center; border: 1px solid var(--line); margin-left: -1px; min-height: 48px; }
.seg label:first-of-type { margin-left: 0; }
.seg label:has(input:checked) { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.seg label:has(input:focus-visible) { outline: 3px solid var(--ochre); outline-offset: 1px; z-index: 1; }
.seg .dot { width: 18px; height: 18px; min-height: 0; padding: 0; border-radius: 50%; flex: none; }
.dot.light { background: var(--p-light); box-shadow: inset 0 0 0 2px var(--p-light-edge); }
.dot.dark { background: var(--p-dark); box-shadow: inset 0 0 0 2px var(--p-dark-edge), 0 0 0 1px #6d5a4f; }
#f-mode { margin-top: 22px; }

.cta { display: flex; flex-direction: column; gap: 10px; margin-top: 28px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 0 22px; border: 1px solid var(--line); background: transparent; cursor: pointer; font-size: 17px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 650; font-size: 18px; }
.btn.primary:active { transform: translateY(1px); }
.btn.ghost { border-color: var(--ink); }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.home-foot { display: flex; justify-content: space-between; border-top: 1px solid var(--line); margin-top: 32px; padding-top: 6px; }
.link { background: none; border: 0; min-height: 48px; padding: 0 6px; cursor: pointer; color: var(--muted); text-decoration: underline; text-underline-offset: 4px; text-decoration-color: var(--line); }
.link:hover { color: var(--ink); }

/* ---------- Partie ---------- */
#game { display: flex; flex-direction: column; padding-top: calc(var(--sat) + 6px); }
.bar { display: flex; align-items: center; gap: 8px; min-height: 52px; }
#status { flex: 1; margin: 0; text-align: center; font: 600 19px/1.2 var(--serif); }
#status small { display: block; font: 14px var(--sans); color: var(--ochre); margin-top: 2px; }
.icon { width: 48px; height: 48px; display: grid; place-items: center; background: none; border: 1px solid var(--line); cursor: pointer; }
.icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#b-sound .cross { display: none; }
#b-sound.muted .wave { display: none; }
#b-sound.muted .cross { display: inline; }

.stage { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 14px; --bs: min(calc(100vw - var(--sal) - var(--sar) - 24px), calc(100dvh - var(--sat) - var(--sab) - 250px), 900px); }
.board-wrap { width: var(--bs); }
.side-tag { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); min-height: 26px; }
.side-tag .dot { width: 14px; height: 14px; border-radius: 50%; }
.side-tag .count { margin-left: auto; font-variant-numeric: tabular-nums; }
.side-tag.on { color: var(--ink); }
.side-tag.on::after { content: ""; width: 8px; height: 8px; background: var(--ochre); border-radius: 50%; order: 1; }
.frame { position: relative; padding: calc(var(--bs) * 0.022); background: var(--frame); box-shadow: 0 1px 0 #4a3326 inset, 0 14px 30px #0006; }
#board { display: grid; aspect-ratio: 1; touch-action: manipulation; }
.sq { position: relative; border: 0; padding: 0; margin: 0; background: var(--sq-light); }
.sq.d { background: var(--sq-dark); cursor: pointer; }
.sq.d:focus-visible { outline: 3px solid var(--ochre); outline-offset: -3px; z-index: 2; }
.sq .num { position: absolute; left: 3px; top: 1px; font-size: clamp(7px, 1.25vmin, 11px); color: #f6d9c766; pointer-events: none; }
.coords-off .sq .num { display: none; }
.sq.last { background: #b05a37; }
.sq.target::after { content: ""; position: absolute; inset: 34%; border-radius: 50%; background: var(--ochre); box-shadow: 0 0 0 3px #0003; }
.sq.step::after { content: ""; position: absolute; inset: 40%; border-radius: 50%; border: 3px solid var(--ochre); }

.piece { position: absolute; inset: 9%; border-radius: 50%; pointer-events: none; transition: transform .12s; will-change: transform; }
.piece.l { background: radial-gradient(circle at 50% 50%, transparent 52%, #0000000f 53% 56%, transparent 57%), var(--p-light); box-shadow: inset 0 0 0 calc(var(--bs) * .006) var(--p-light-edge), inset 0 -3px 0 #0000001c, 0 2px 0 #00000055, 0 4px 6px #0004; }
.piece.dk { background: radial-gradient(circle at 50% 50%, transparent 52%, #ffffff12 53% 56%, transparent 57%), var(--p-dark); box-shadow: inset 0 0 0 calc(var(--bs) * .006) var(--p-dark-edge), inset 0 -3px 0 #0006, 0 2px 0 #000a, 0 4px 6px #0005; }
.piece.k svg { position: absolute; inset: 22%; width: 56%; height: 56%; }
.piece.l.k svg { fill: var(--sq-dark); }
.piece.dk.k svg { fill: var(--ochre); }
.sq.must .piece { box-shadow: 0 0 0 3px var(--ochre), 0 2px 0 #0006; }
.sq.sel .piece { transform: translateY(-6%) scale(1.06); box-shadow: 0 0 0 3px var(--ochre), 0 8px 12px #0007; }
.piece.taken { opacity: .35; filter: grayscale(1); transition: opacity .2s; }
.piece.mark-x::before { content: ""; position: absolute; inset: 30%; border: 3px solid var(--ochre); border-radius: 50%; }
#overlay { position: absolute; pointer-events: none; overflow: visible; }
#overlay path { fill: none; stroke: var(--ochre); stroke-width: 3; stroke-dasharray: 6 6; stroke-linecap: round; stroke-linejoin: round; opacity: .9; }

.panel { width: var(--bs); display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.actions { display: flex; gap: 8px; }
.actions .btn { flex: 1; min-height: 46px; font-size: 15px; padding: 0 8px; }
.btn:disabled { opacity: .4; cursor: default; }
.h-moves { font: 600 15px var(--sans); color: var(--muted); margin: 6px 0 0; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
#moves { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 2px 14px; font: 15px/1.6 ui-monospace, "SF Mono", Menlo, Consolas, monospace; max-height: 4.8em; overflow-y: auto; }
#moves li { white-space: nowrap; }
#moves li b { color: var(--muted); font-weight: 400; margin-right: 6px; }
#moves .empty { color: var(--muted); font-family: var(--sans); }

@media (orientation: landscape) and (min-width: 700px) {
  .stage { flex-direction: row; justify-content: center; align-items: flex-start; gap: 28px; --bs: min(calc(100dvh - var(--sat) - var(--sab) - 120px), calc(100vw - var(--sal) - var(--sar) - 360px)); }
  .panel { width: 300px; height: var(--bs); margin-top: 26px; }
  #moves { max-height: none; flex: 1; align-content: flex-start; }
  #game { padding-left: calc(var(--sal) + 20px); padding-right: calc(var(--sar) + 20px); }
}
@media (orientation: landscape) and (max-height: 500px) {
  .stage { flex-direction: row; justify-content: center; align-items: flex-start; --bs: calc(100dvh - var(--sat) - var(--sab) - 110px); }
  .panel { width: min(260px, 40vw); margin-top: 26px; height: var(--bs); }
  #moves { max-height: none; flex: 1; align-content: flex-start; }
  .home-head { padding-top: 2vh; }
}
@media (min-width: 900px) and (orientation: portrait) {
  .stage { --bs: min(calc(100vw - 80px), calc(100dvh - 330px)); }
  #moves { max-height: 6.4em; }
}

/* ---------- Fenêtres ---------- */
.modal { position: fixed; inset: 0; background: #0b100dcc; display: grid; place-items: end center; z-index: 20; padding: 16px calc(var(--sar) + 16px) calc(var(--sab) + 16px) calc(var(--sal) + 16px); }
.sheet { width: min(560px, 100%); max-height: calc(100dvh - var(--sat) - 40px); overflow-y: auto; background: var(--bg-2); border-top: 4px solid var(--accent); padding: 22px 22px 18px; animation: up .22s ease-out; }
@media (min-width: 700px) { .modal { place-items: center; } }
@keyframes up { from { transform: translateY(20px); opacity: 0; } }
.sheet h2 { font: 600 28px/1.15 var(--serif); margin: 0 0 12px; }
.sheet p { margin: 0 0 12px; max-width: 66ch; line-height: 1.55; }
.sheet h3 { font: 600 19px var(--serif); margin: 16px 0 6px; color: var(--accent); }
.m-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.m-actions .btn { flex: 1; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; border-bottom: 1px solid var(--line); }
.row select, .toggle { min-height: 44px; min-width: 120px; background: var(--bg); color: var(--ink); border: 1px solid var(--line); padding: 0 10px; font: inherit; cursor: pointer; }
.toggle[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.stats-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.stats-table th, .stats-table td { text-align: left; padding: 8px 4px; border-bottom: 1px solid var(--line); font-weight: 400; }
.stats-table th[scope=col] { color: var(--muted); font-size: 14px; }
.stats-table td { text-align: right; }
.tuto-step { color: var(--muted); font-size: 14px; }
.small-note { color: var(--muted); font-size: 14px; }

/* ---------- Variantes 8x8 supplémentaires, en ligne, problèmes, relecture ---------- */
.variant { min-height: 62px; padding: 10px 4px; }
.v-txt b { font-size: 22px; }
.mini8.alt { background-color: #e3d5bd; }
.mini8.alt2 { background-color: #efe0c8; background-image: conic-gradient(#b5583a 25%, transparent 0 50%, #b5583a 0 75%, transparent 0); }
@media (min-width: 620px) {
  .variants { display: grid; grid-template-columns: 1fr 1fr; column-gap: 18px; }
}
.seg label > span { white-space: nowrap; }
#f-mode label > span { white-space: normal; font-size: 14px; padding: 4px 6px; }
#online-opts { margin-top: 4px; }
.me-row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 64px; margin-top: 18px; padding: 8px 4px; background: none; border: 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: left; cursor: pointer; }
.me-txt { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.me-txt b { font: 600 20px/1.2 var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-txt small { color: var(--muted); font-size: 14px; min-height: 1.4em; }
.me-edit { color: var(--muted); font-size: 14px; text-decoration: underline; text-underline-offset: 4px; text-decoration-color: var(--line); }
.home-foot { flex-wrap: wrap; }
.top-link { padding-left: 0; margin-top: 2px; }
.ai-note { color: var(--muted); font-size: 13px; line-height: 1.45; margin: 12px 0 0; }
.cta-row { display: flex; gap: 10px; }
.cta-row .btn { flex: 1; font-size: 15px; padding: 0 10px; min-height: 48px; }
.puzzles-btn { justify-content: flex-start; gap: 14px; min-height: 60px; border-color: var(--line); text-align: left; }
.pz-txt { display: flex; flex-direction: column; line-height: 1.2; }
.pz-txt b { font: 600 19px var(--serif); }
.pz-txt small { color: var(--muted); font-size: 13px; }
.pz-ico { display: grid; grid-template-columns: repeat(2, 12px); flex: none; }
.pz-ico i { width: 12px; height: 12px; background: var(--sq-light); position: relative; }
.pz-ico i:nth-child(2), .pz-ico i:nth-child(3) { background: var(--sq-dark); }
.pz-ico i:nth-child(3)::after { content: ""; position: absolute; inset: 2px; border-radius: 50%; background: var(--p-light); }

.av { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 2px #0003; }
.av svg { width: 76%; height: 76%; }
.av.big { width: 52px; height: 52px; }
.me-row .av { width: 44px; height: 44px; }
.side-tag { position: relative; gap: 7px; }
.side-tag .who { color: inherit; font: inherit; background: none; border: 0; padding: 0; min-height: 26px; max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-tag button.who { cursor: pointer; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line); }
.side-tag .rt { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.side-tag .clk { font: 600 15px ui-monospace, "SF Mono", Menlo, Consolas, monospace; padding: 1px 7px; border: 1px solid var(--line); order: 3; min-width: 58px; text-align: center; }
.side-tag.on .clk { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.side-tag .clk.low { color: #fff; background: var(--accent); border-color: var(--accent); }
.side-tag.on::after { order: 2; }
.bubble { position: absolute; left: 34px; bottom: calc(100% + 2px); z-index: 6; background: var(--ink); color: var(--bg); font-size: 14px; padding: 4px 10px; white-space: nowrap; animation: pop .18s ease-out; pointer-events: none; }
.bubble::after { content: ""; position: absolute; left: 12px; top: 100%; border: 6px solid transparent; border-top-color: var(--ink); }
#tag-top .bubble { bottom: auto; top: calc(100% + 4px); }
#tag-top .bubble::after { top: auto; bottom: 100%; border-top-color: transparent; border-bottom-color: var(--ink); }
@keyframes pop { from { transform: scale(.8); opacity: 0; } }

.review { display: flex; align-items: center; gap: 6px; }
.review span { flex: 1; text-align: center; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.review .icon:disabled { opacity: .35; }
#moves .cur { background: var(--ochre); color: var(--accent-ink); }

#toast { position: fixed; left: 50%; bottom: calc(var(--sab) + 22px); transform: translateX(-50%); z-index: 30; background: var(--ink); color: var(--bg); padding: 10px 16px; max-width: calc(100vw - 32px); font-size: 15px; box-shadow: 0 8px 20px #0006; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.field span, .lbl { color: var(--muted); font-size: 14px; margin: 0; }
.field input { min-height: 48px; background: var(--bg); color: var(--ink); border: 1px solid var(--line); padding: 0 12px; font: 18px var(--sans); -webkit-user-select: text; user-select: text; }
#join-code { text-transform: uppercase; letter-spacing: .3em; font: 600 24px ui-monospace, Menlo, Consolas, monospace; }
.err { color: #f2a07a; font-size: 14px; }
.av-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-top: 6px; }
.av-pick { background: none; border: 2px solid transparent; padding: 3px; cursor: pointer; display: grid; place-items: center; }
.av-pick[aria-pressed="true"] { border-color: var(--ochre); }
.av-pick .av.big { width: 100%; height: auto; aspect-ratio: 1; }
.emote-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.emote-grid .btn { min-height: 48px; font-size: 16px; }
.pcard { display: flex; align-items: center; gap: 14px; }
.pcard b { display: block; font: 600 22px var(--serif); }
.pcard small { color: var(--muted); }
.code-big { font: 600 44px/1.1 ui-monospace, Menlo, Consolas, monospace; letter-spacing: .25em; color: var(--ochre); text-align: center; margin: 10px 0 !important; -webkit-user-select: text; user-select: text; }
.spinner { display: grid; grid-template-columns: repeat(2, 18px); width: 36px; margin: 6px auto 14px; animation: spin 1.6s steps(4) infinite; }
.spinner i { width: 18px; height: 18px; background: var(--sq-light); }
.spinner i:nth-child(2), .spinner i:nth-child(3) { background: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }
.top-list { list-style: none; margin: 8px 0; padding: 0; }
.top-list li { display: flex; align-items: center; gap: 10px; min-height: 44px; border-bottom: 1px solid var(--line); }
.top-list li.me { background: #c9653c22; }
.top-list .rk { width: 2em; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.top-list .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-list .sc { font-variant-numeric: tabular-nums; font-weight: 600; padding-right: 6px; }
.tabs { display: flex; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin: 6px 0 4px; }
.tabs button { flex: 1 1 auto; background: none; border: 0; border-bottom: 3px solid transparent; min-height: 44px; padding: 0 8px; cursor: pointer; color: var(--muted); font-size: 15px; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.pz-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 6px; }
.pz-tile { aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--bg); border: 1px solid var(--line); cursor: pointer; }
.pz-tile b { font: 600 20px var(--serif); }
.pz-tile small { color: var(--ochre); font-size: 9px; letter-spacing: 2px; }
.pz-tile.ok { background: var(--sq-dark); border-color: var(--sq-dark); }
.pz-tile.ok small { color: var(--p-light); }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (max-width: 420px) { .tabs { display: grid; grid-template-columns: 1fr 1fr; } }
