/* Échecs : ardoise verte, craie et vermillon. Contrainte : aucun cadre arrondi, des filets comme sur une feuille de partie. */
:root {
  --bg: #0f1412;
  --bg2: #151c19;
  --ink: #eef1ea;
  --muted: #a3afa8;
  --line: #2b3631;
  --accent: #e8573c;
  --light: #e4e8df;
  --dark: #6f8a7d;
  --last: rgba(236, 190, 72, .55);
  --hint: rgba(232, 87, 60, .5);
  --serif: Charter, 'Bitstream Charter', 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
  --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; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink); font: 17px/1.5 var(--sans);
  padding: var(--sat) var(--sar) var(--sab) var(--sal);
  -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none;
  overscroll-behavior: none; display: flex; flex-direction: column; min-height: 100dvh;
}
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* Barre */
.bar { display: flex; align-items: center; justify-content: space-between; padding: 6px 16px; border-bottom: 1px solid var(--line); min-height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 6px 4px; min-height: 44px; font: 600 22px/1 var(--serif); letter-spacing: .01em; }
.brand-k { width: 26px; height: 26px; --pf: var(--ink); --ps: var(--ink); --pd: var(--bg); }
.bar-right { display: flex; gap: 8px; align-items: center; }
.lang select { background: var(--bg2); border: 1px solid var(--line); border-radius: 0; height: 44px; padding: 0 10px; font-weight: 600; letter-spacing: .04em; }
.icon-btn { width: 44px; height: 44px; background: none; border: 1px solid var(--line); display: grid; place-items: center; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#btnSound .snd-off { display: none; }
#btnSound[aria-pressed="true"] .snd-on { display: none; }
#btnSound[aria-pressed="true"] .snd-off { display: inline; }
#btnSound[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* Accueil */
.home-grid { display: grid; gap: 28px; padding: 28px 16px 32px; max-width: 1100px; width: 100%; margin: 0 auto; grid-template-columns: 1fr; }
.home-head h1 { font: 600 clamp(56px, 16vw, 112px)/.92 var(--serif); margin: 0; letter-spacing: -.02em; }
.tagline { color: var(--muted); margin: 12px 0 0; max-width: 34ch; text-wrap: pretty; }
.menu { display: flex; flex-direction: column; border-top: 1px solid var(--ink); }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; text-align: left; width: 100%; min-height: 56px; padding: 12px 2px; background: none; border: 0; border-bottom: 1px solid var(--line); font: 500 20px/1.25 var(--serif); }
.row small { font: 14px/1.3 var(--sans); color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.row:hover span, .row:focus-visible span { color: var(--accent); }
.row#goContinue span { color: var(--accent); }
.row#goOther span { color: var(--muted); font-size: 17px; }
.aj-link { background: none; border: 0; padding: 6px 0; min-height: 44px; font: inherit; color: var(--muted); text-decoration: underline; text-underline-offset: 4px; cursor: pointer; }
.aj-link:hover { color: var(--accent); }
.daily { margin: 0; }
.daily-btn { display: block; width: 100%; background: none; border: 0; padding: 0; text-align: left; }
.daily-btn figcaption { display: flex; justify-content: space-between; gap: 12px; padding-top: 10px; border-top: 1px solid var(--line); margin-top: 10px; }
.daily-btn strong { font: 600 18px var(--serif); }
.daily-btn figcaption span { color: var(--muted); font-size: 15px; }
.daily-btn:hover strong { color: var(--accent); }
.mini { display: grid; grid-template-columns: repeat(8, 1fr); aspect-ratio: 1; width: 100%; max-width: 420px; }
.mini > div { position: relative; }
.mini svg { position: absolute; inset: 6%; width: 88%; height: 88%; }

@media (min-width: 760px) {
  .home-grid { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); grid-template-areas: 'head daily' 'menu daily'; align-items: start; padding-top: 48px; column-gap: 56px; }
  .home-head { grid-area: head; } .menu { grid-area: menu; } .daily { grid-area: daily; }
}

/* Feuilles (réglages, stats) */
.sheet { padding: 24px 16px 32px; max-width: 560px; width: 100%; margin: 0 auto; }
.sheet.wide { max-width: 760px; }
.sheet h2 { font: 600 34px/1.1 var(--serif); margin: 0 0 18px; }
fieldset { border: 0; padding: 0; margin: 0 0 22px; }
legend { font-size: 14px; color: var(--muted); padding: 0; margin-bottom: 6px; letter-spacing: .02em; }
.levels label { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 10px; min-height: 52px; border-bottom: 1px solid var(--line); cursor: pointer; }
.levels label:first-of-type { border-top: 1px solid var(--line); }
.levels .lname { font: 500 19px var(--serif); }
.levels .lelo { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 15px; }
.levels input, .seg input { appearance: none; width: 20px; height: 20px; border: 2px solid var(--muted); border-radius: 50%; margin: 0; }
.levels input:checked, .seg input:checked { border-color: var(--accent); background: radial-gradient(var(--accent) 45%, transparent 50%); }
.seg { display: flex; flex-wrap: wrap; gap: 0; }
.seg legend { width: 100%; }
.seg label { flex: 1; display: flex; align-items: center; gap: 8px; justify-content: center; min-height: 48px; border: 1px solid var(--line); margin-left: -1px; cursor: pointer; padding: 0 10px; }
.seg label:has(input:checked) { border-color: var(--accent); position: relative; z-index: 1; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 56px; border-bottom: 1px solid var(--line); cursor: pointer; }
.switch input { appearance: none; width: 50px; height: 28px; background: var(--line); position: relative; flex: none; margin: 0; transition: background .15s; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; background: var(--muted); transition: transform .15s, background .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(22px); background: var(--ink); }
.fine { color: var(--muted); font-size: 15px; max-width: 62ch; text-wrap: pretty; }
.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; flex-wrap: wrap; }
.btn { min-height: 48px; padding: 0 20px; border: 1px solid var(--ink); background: none; font-weight: 600; }
.btn.primary { background: var(--ink); color: var(--bg); }
.btn.primary:hover { background: var(--accent); border-color: var(--accent); color: #1a0d09; }
.btn.ghost { border-color: var(--line); }
.btn.ghost:hover { border-color: var(--ink); }
.btn.danger { color: #ff8e78; }

/* Statistiques */
.stat-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; margin-bottom: 24px; }
.stat-table th, .stat-table td { padding: 10px 6px; border-bottom: 1px solid var(--line); text-align: right; }
.stat-table th:first-child, .stat-table td:first-child { text-align: left; }
.stat-table th { font-weight: 500; color: var(--muted); font-size: 14px; }
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); border-top: 1px solid var(--ink); margin-bottom: 26px; }
.figures div { padding: 14px 0 12px; border-bottom: 1px solid var(--line); }
.figures b { display: block; font: 600 34px/1.1 var(--serif); font-variant-numeric: tabular-nums; }
.figures span { color: var(--muted); font-size: 14px; }

/* Partie */
.game { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 8px 16px 12px; gap: 10px; min-height: 0; }
.board-col { display: flex; flex-direction: column; gap: 6px; --bs: min(calc(100vw - 32px - var(--sal) - var(--sar)), calc(100dvh - 330px - var(--sat) - var(--sab)), 760px); width: var(--bs); }
.board-wrap { width: var(--bs); height: var(--bs); position: relative; }
#board { display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); width: 100%; height: 100%; box-shadow: 0 0 0 1px #000, 0 18px 40px -18px #000; touch-action: none; }
.sq { position: relative; border: 0; padding: 0; margin: 0; background: var(--light); min-width: 0; min-height: 0; }
.sq.dk { background: var(--dark); }
.sq.last::before { content: ''; position: absolute; inset: 0; background: var(--last); }
.sq.sel::before { content: ''; position: absolute; inset: 0; background: rgba(232, 87, 60, .42); }
.sq.hint::after { content: ''; position: absolute; inset: 3px; border: 3px dashed var(--accent); pointer-events: none; }
.sq.dot::after { content: ''; position: absolute; left: 50%; top: 50%; width: 26%; height: 26%; margin: -13% 0 0 -13%; border-radius: 50%; background: rgba(20, 28, 24, .38); pointer-events: none; }
.sq.ring::after { content: ''; position: absolute; inset: 4%; border-radius: 50%; border: 4px solid rgba(20, 28, 24, .38); pointer-events: none; }
.sq.check { background-image: radial-gradient(circle, rgba(232,87,60,.95) 0, rgba(232,87,60,.6) 40%, transparent 72%); }
.sq:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; z-index: 2; }
.sq .pc { position: absolute; inset: 5%; width: 90%; height: 90%; pointer-events: none; z-index: 1; transition: transform .14s ease-out; }
.pc.w { --pf: #fbf9f3; --ps: #121514; --pd: #121514; }
.pc.b { --pf: #1b201e; --ps: #050606; --pd: #c9d2cc; }
svg.pc use, .mini svg use, .caps svg use, .promo-row svg use, .brand-k use { fill: var(--pf); stroke: var(--ps); stroke-width: 3.2px; stroke-linejoin: round; }
symbol .d { stroke: var(--pd); stroke-width: 3px; stroke-linecap: round; }
symbol .e { fill: var(--pd); stroke: none; }
.sq .co { position: absolute; font: 600 11px/1 var(--sans); z-index: 2; pointer-events: none; color: var(--dark); }
.sq.dk .co { color: var(--light); }
.co.f { right: 3px; bottom: 2px; } .co.r { left: 3px; top: 3px; }
.hide-coords .co { display: none; }
.ghost-pc { position: fixed; pointer-events: none; z-index: 50; filter: drop-shadow(0 8px 10px rgba(0,0,0,.45)); }
.ghost-pc svg { width: 100%; height: 100%; }
.sq.dragging .pc { opacity: .25; }

.player { display: flex; justify-content: space-between; align-items: center; min-height: 30px; gap: 10px; }
.pname { font: 600 17px var(--serif); display: flex; align-items: center; gap: 8px; }
.pname::before { content: ''; width: 12px; height: 12px; border: 1.5px solid var(--ink); }
.player.w .pname::before { background: var(--ink); }
.player.turn .pname { color: var(--accent); }
.player.turn .pname::before { border-color: var(--accent); }
.caps { display: flex; align-items: center; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; min-height: 22px; }
.caps svg { width: 20px; height: 20px; margin-right: -6px; }
.caps b { margin-left: 10px; font-weight: 600; }

.panel { width: var(--pw, 100%); max-width: 760px; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.game > .panel { width: min(100%, var(--bsw, 100%)); }
.status { margin: 0; font: 500 18px/1.3 var(--serif); min-height: 24px; }
.status.alert { color: var(--accent); }
.puzzle-bar { display: flex; gap: 8px; }
.moves-head { display: none; font-size: 14px; color: var(--muted); border-bottom: 1px solid var(--ink); padding-bottom: 4px; }
.moves { list-style: none; margin: 0; padding: 4px 0; display: flex; overflow-x: auto; gap: 2px 14px; font: 15px/1.6 var(--mono); font-variant-numeric: tabular-nums; scrollbar-width: none; min-height: 32px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); -webkit-user-select: text; user-select: text; }
.moves li { white-space: nowrap; display: flex; gap: 8px; }
.moves .n { color: var(--muted); }
.moves .cur { color: var(--accent); }
.moves .empty { color: var(--muted); font-family: var(--sans); }
.tools { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 0; border-top: 1px solid var(--line); }
.tool { background: none; border: 0; border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 58px; font-size: 12px; color: var(--muted); padding: 4px; }
.tool:last-child { border-right: 0; }
.tool svg { width: 24px; height: 24px; fill: none; stroke: var(--ink); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tool:hover:not(:disabled) svg, .tool:focus-visible svg { stroke: var(--accent); }
.tool:disabled { opacity: .35; cursor: default; }

/* Paysage et tablettes : plateau à gauche, feuille de partie à droite */
.game > .panel { flex: 1; }
.tools { margin-top: auto; }
@media (orientation: landscape) and (min-width: 640px) {
  .game { flex-direction: row; align-items: stretch; justify-content: center; gap: 28px; padding: 14px 20px; }
  .board-col { --bs: min(calc(100dvh - 140px - var(--sat) - var(--sab)), calc(100vw - 420px - var(--sal) - var(--sar)), 900px); }
  .game > .panel { width: 340px; max-width: 340px; }
  .moves-head { display: block; }
  .moves { flex-direction: column; overflow-x: hidden; overflow-y: auto; flex: 1; border: 0; display: grid; grid-template-columns: 1fr; align-content: start; }
  .moves li { display: grid; grid-template-columns: 42px 1fr 1fr; border-bottom: 1px solid var(--line); padding: 2px 0; }
  .status { min-height: 48px; font-size: 21px; }
}
@media (orientation: portrait) and (min-width: 700px) {
  .board-col { --bs: min(calc(100vw - 64px), calc(100dvh - 380px), 900px); }
  .moves { flex-wrap: wrap; max-height: 120px; overflow-y: auto; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .bar { min-height: 48px; padding-top: 2px; padding-bottom: 2px; }
  .board-col { --bs: min(calc(100dvh - 110px - var(--sat) - var(--sab)), calc(100vw - 400px)); }
  .tool span { display: none; }
}

/* Dialogues */
dialog { background: var(--bg2); color: var(--ink); border: 1px solid var(--ink); padding: 22px 20px 18px; max-width: min(520px, calc(100vw - 32px)); width: 100%; }
dialog::backdrop { background: rgba(5, 8, 7, .72); }
dialog h3 { font: 600 26px/1.15 var(--serif); margin: 0 0 12px; }
.promo-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.promo-row button { aspect-ratio: 1; background: var(--light); border: 1px solid var(--line); min-height: 64px; padding: 6px; }
.promo-row button:hover, .promo-row button:focus-visible { background: #f3c86a; }
.promo-row svg { width: 100%; height: 100%; }
.dlg-list { border-top: 1px solid var(--ink); }
.mono { font-family: var(--mono); font-size: 14px; width: 100%; background: var(--bg); border: 1px solid var(--line); padding: 10px; margin-bottom: 8px; -webkit-user-select: text; user-select: text; border-radius: 0; }
textarea.mono { resize: vertical; }
.err { color: #ff8e78; min-height: 1em; margin: 4px 0; font-size: 15px; }
.tuto-board { display: grid; grid-template-columns: repeat(4, 1fr); width: 160px; aspect-ratio: 1; margin: 0 0 14px; }
.tuto-board > div { position: relative; }
.tuto-board svg { position: absolute; inset: 8%; width: 84%; height: 84%; }
#tutoText { font: 19px/1.45 var(--serif); min-height: 4.4em; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
.caps .pc.b { --ps: #9aa79f; }

/* Ouverture reconnue, analyse, en ligne, thèmes */
.opening { margin: 0; font: italic 15px/1.3 var(--serif); color: var(--muted); min-height: 1.3em; }
.review { border-top: 1px solid var(--ink); padding-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.review-sum { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.review-sum b { display: block; font: 600 26px/1 var(--serif); font-variant-numeric: tabular-nums; }
.review-sum span { color: var(--muted); font-size: 13px; display: block; }
.review-sum small { font: 13px var(--mono); color: var(--muted); }
.mk { font-style: normal; font-weight: 700; margin: 0 2px 0 1px; }
.mk.inaccuracy { color: #e9c46a; } .mk.mistake { color: #f4a259; } .mk.blunder { color: #ff6b57; }
.eval-graph { width: 100%; height: 64px; background: #2a332f; display: block; }
.eval-graph .g-area { fill: var(--light); opacity: .85; }
.eval-graph .g-line { fill: none; stroke: var(--ink); stroke-width: 1; vector-effect: non-scaling-stroke; }
.eval-graph .g-mid { stroke: var(--dark); stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.eval-graph .g-cur { stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.eval-graph .g-mistake { fill: #f4a259; } .eval-graph .g-blunder { fill: #ff6b57; }
.review-note { margin: 0; font: 16px/1.35 var(--serif); min-height: 2.7em; }
.review-nav { display: flex; gap: 8px; }
.review-nav .btn { min-height: 44px; padding: 0 14px; }
.review-nav #rvClose { margin-left: auto; }
.moves.nav span[data-ply] { cursor: pointer; }
.moves .k-blunder { color: #ff6b57; } .moves .k-mistake { color: #f4a259; }
.moves .cur { text-decoration: underline; text-underline-offset: 4px; }
.player { position: relative; }
.clock { font: 600 20px/1 var(--mono); font-variant-numeric: tabular-nums; padding: 4px 8px; border: 1px solid var(--line); margin-left: auto; }
.clock.run { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.clock.low.run { background: var(--accent); border-color: var(--accent); color: #1a0d09; }
.bubble { position: absolute; left: 45%; top: 50%; transform: translateY(-50%); background: var(--ink); color: var(--bg); font: 600 15px var(--sans); padding: 6px 10px; z-index: 5; white-space: nowrap; animation: pop .2s ease-out; }
@keyframes pop { from { opacity: 0; } to { opacity: 1; } }
.toast { position: fixed; left: 50%; bottom: calc(24px + var(--sab)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 12px 16px; z-index: 60; font-weight: 600; max-width: calc(100vw - 32px); }
.end-extra { display: flex; gap: 8px; flex-wrap: wrap; }
.end-extra .btn { min-height: 44px; }
.emote-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sub { font: 600 22px/1.2 var(--serif); margin: 26px 0 8px; padding-top: 10px; border-top: 1px solid var(--ink); }
.net-state { color: var(--accent); }
.prof { display: flex; align-items: center; gap: 14px; padding: 6px 0 4px; }
.prof b { font: 600 22px var(--serif); display: block; }
.prof span:not(.av) { color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }
.prof .btn { margin-left: auto; min-height: 44px; }
.av { display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none; background: var(--light); }
.av.avb { background: var(--dark); }
.av svg { width: 36px; height: 36px; }
.av-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.av-pick { background: none; border: 2px solid transparent; padding: 2px; display: grid; place-items: center; min-height: 52px; }
.av-pick.on { border-color: var(--accent); }
.fld { display: block; margin: 10px 0; } .fld span { display: block; font-size: 14px; color: var(--muted); }
.tc-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; }
.tc { background: none; border: 1px solid var(--line); margin-left: -1px; min-height: 84px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.tc b { font: 600 22px var(--serif); } .tc span { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.tc:hover b, .tc:focus-visible b { color: var(--accent); }
.priv { display: flex; gap: 8px; margin-top: 8px; }
.priv select, .priv input { flex: 1; min-height: 48px; background: var(--bg2); border: 1px solid var(--line); border-radius: 0; padding: 0 10px; margin: 0; }
.code-in { text-transform: uppercase; letter-spacing: .2em; font-size: 18px; -webkit-user-select: text; user-select: text; }
.wide-btn { width: 100%; margin: 14px 0; }
.seek { border: 1px solid var(--ink); padding: 14px 16px; margin: 16px 0; }
.seek p { margin: 0 0 8px; }
.seek .code { font: 600 44px/1 var(--mono); letter-spacing: .18em; color: var(--accent); -webkit-user-select: text; user-select: text; }
.lb { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.lb li { display: grid; grid-template-columns: 28px 36px 1fr auto 44px; align-items: center; gap: 10px; min-height: 48px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.lb .av { width: 34px; height: 34px; } .lb .av svg { width: 28px; height: 28px; }
.lb .rk { color: var(--muted); text-align: right; } .lb .el { color: var(--muted); font-size: 14px; } .lb b { text-align: right; }
.lb li.me .nm { color: var(--accent); }
.blk { margin-top: 18px; } .blk summary, .fam summary { min-height: 48px; display: flex; align-items: center; justify-content: space-between; cursor: pointer; border-bottom: 1px solid var(--line); }
.blk-row { display: flex; justify-content: space-between; align-items: center; min-height: 52px; border-bottom: 1px solid var(--line); }
.fam summary { font: 500 20px var(--serif); list-style: none; }
.fam summary::-webkit-details-marker { display: none; }
.fam summary small { color: var(--muted); font: 14px var(--sans); }
.fam[open] summary span { color: var(--accent); }
.row.op { padding-left: 14px; }
.row.op > span { display: flex; flex-direction: column; gap: 2px; font-size: 17px; }
.mono-s { font: 13px/1.3 var(--mono); color: var(--muted); }
.theme-list { border-top: 1px solid var(--ink); }
