/* Chess Famous Games — styles. Thème : html[data-theme="light" | "dark"], choisi avant l'affichage (index.html). */
:root {
  --bg: #f4f1ea; --bg2: #ebe6dc; --card: #ffffff; --text: #1f2328; --muted: #5c6470; --line: #ddd6c8;
  --accent: #2f6f4f; --accent-2: #3f8f66; --accent-ink: #ffffff; --gold: #b7791f; --danger: #c0392b; --ok: #2f855a;
  --shadow: 0 6px 24px rgba(40, 30, 10, .12); --radius: 12px;
  --sq-l: #f0d9b5; --sq-d: #b58863; --hl: rgba(255, 214, 64, .55); --sel: rgba(46, 125, 210, .55);
  --frame: #6b4f36;
  color-scheme: light;
}
html[data-theme="dark"] {
  --bg: #12151b; --bg2: #191d25; --card: #1e232c; --text: #e6e8ec; --muted: #9aa3b2; --line: #2e3441;
  --accent: #4fb37f; --accent-2: #63c792; --accent-ink: #0d1a12; --gold: #e2b356; --danger: #ef6b5b; --ok: #63c792;
  --shadow: 0 8px 28px rgba(0, 0, 0, .45);
  --sq-l: #cbb796; --sq-d: #8f6b4c; --hl: rgba(255, 200, 40, .45); --sel: rgba(90, 160, 240, .55);
  --frame: #2a2f3a;
  color-scheme: dark;
}
/* couleurs de l'échiquier (Affichage) : chaque palette a sa version de nuit, moins lumineuse */
body.b-green { --sq-l: #eeeed2; --sq-d: #769656; }
body.b-blue { --sq-l: #dee3e6; --sq-d: #8ca2ad; }
body.b-grey { --sq-l: #e3e3e3; --sq-d: #9a9a9a; }
html[data-theme="dark"] body.b-green { --sq-l: #b9bba0; --sq-d: #5b7a43; }
html[data-theme="dark"] body.b-blue { --sq-l: #aab3ba; --sq-d: #627884; }
html[data-theme="dark"] body.b-grey { --sq-l: #a9a9a9; --sq-d: #6c6c6c; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; font-size: 15px; line-height: 1.45;
  background: var(--bg); color: var(--text); min-height: 100vh; transition: background .25s, color .25s;
}
button, select, input, textarea { font: inherit; color: inherit; }
button {
  cursor: pointer; border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 6px 11px;
  transition: background .15s, border-color .15s, transform .05s;
}
button:hover { border-color: var(--accent); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover { background: var(--accent-2); }
select, input[type="text"], input[type="search"], textarea {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; max-width: 100%;
}
textarea { width: 100%; resize: vertical; }
a { color: var(--accent); }
kbd { font: 12px ui-monospace, Consolas, monospace; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--bg2); }

/* ---------- barre du haut */
#topbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 16px;
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: baseline; gap: 8px; margin-right: auto; white-space: nowrap; }
.brand .logo { font-size: 26px; line-height: 1; align-self: center; font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", serif; }
.brand b { font-size: 18px; letter-spacing: -.01em; }
.brand small { color: var(--muted); }
#topbar .actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.theme-btn { width: 38px; padding: 6px 0; }

/* ---------- mise en page */
#main {
  display: grid; grid-template-columns: auto minmax(320px, 440px); gap: 22px;
  justify-content: center; align-items: start; padding: 18px 16px 30px; max-width: 1180px; margin: 0 auto;
}
#left { display: flex; flex-direction: column; gap: 8px; width: clamp(320px, calc(100vh - 200px), 660px); }
#right { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- joueurs */
.player { display: flex; align-items: center; gap: 8px; min-height: 32px; padding: 2px 4px; }
.player .dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); flex: none; }
.player .dot.w { background: #fff; } .player .dot.b { background: #222; }
.player.turn .dot { box-shadow: 0 0 0 3px var(--accent); border-color: var(--accent); }
.player .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player .caps { display: flex; flex-wrap: wrap; align-items: center; font-size: 19px; line-height: 1; color: var(--muted); margin-left: 4px; font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", serif; }
.player .caps .adv { font: 600 13px "Segoe UI", system-ui, sans-serif; margin-left: 5px; color: var(--muted); }
.player .res { margin-left: auto; font-weight: 700; font-size: 13px; padding: 1px 8px; border-radius: 99px; background: var(--bg2); }
.player .res.win { background: var(--accent); color: var(--accent-ink); }

/* ---------- échiquier */
#board-wrap { position: relative; padding: 6px; border-radius: 10px; background: var(--frame); box-shadow: var(--shadow); }
#board { position: relative; width: 100%; aspect-ratio: 1; container-type: inline-size; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
#squares { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); border-radius: 4px; overflow: hidden; }
.sq { position: relative; background: var(--sq-l); }
.sq.d { background: var(--sq-d); }
.sq.last::after, .sq.sel::after, .sq.hint::after, .sq.check::after, .sq.wrong::after { content: ""; position: absolute; inset: 0; }
.sq.last::after { background: var(--hl); }
.sq.sel::after { background: var(--sel); }
.sq.hint::after { box-shadow: inset 0 0 0 5px var(--gold); animation: pulse 1s ease-in-out infinite alternate; }
.sq.check::after { background: radial-gradient(circle, rgba(230, 30, 30, .9) 0%, rgba(230, 30, 30, .45) 45%, transparent 72%); }
.sq.wrong::after { background: rgba(220, 40, 40, .45); animation: fade 0.9s forwards; }
.sq.dot::before { content: ""; position: absolute; left: 50%; top: 50%; width: 28%; height: 28%; transform: translate(-50%, -50%); border-radius: 50%; background: rgba(20, 60, 40, .38); z-index: 3; pointer-events: none; }
.sq.dot.cap::before { width: 86%; height: 86%; background: transparent; border: 0.9cqw solid rgba(20, 60, 40, .42); }
body.guessing .sq { cursor: pointer; }
@keyframes pulse { from { opacity: .45; } to { opacity: 1; } }
@keyframes fade { to { opacity: 0; } }
.coord { position: absolute; font-size: 2.1cqw; font-weight: 700; pointer-events: none; opacity: .85; z-index: 1; }
.coord.f { right: 4%; bottom: 1%; } .coord.r { left: 4%; top: 2%; }
.sq .coord { color: var(--sq-d); } .sq.d .coord { color: var(--sq-l); }
body.no-coords .coord { display: none; }

#pieces { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.pc {
  position: absolute; left: 0; top: 0; width: 12.5%; height: 12.5%; display: grid; place-items: center;
  transition: transform .28s cubic-bezier(.3, .7, .3, 1), opacity .25s;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", "Apple Symbols", serif; font-size: 11.6cqw; line-height: 1;
}
.pc i { grid-area: 1 / 1; font-style: normal; display: block; }
.pc.w .fill { color: #fbfaf6; }
.pc.w .line { color: #1b1b1b; }
.pc.b .fill { color: #1c1c1c; text-shadow: 0 0 1px rgba(255, 255, 255, .35); }
.pc { filter: drop-shadow(0 .25cqw .25cqw rgba(0, 0, 0, .28)); }
.pc.gone { opacity: 0; }
.pc.born { opacity: 0; }
#board.noanim .pc { transition: none; }
#arrows { position: absolute; inset: 0; z-index: 4; pointer-events: none; }

/* ---------- commandes */
#controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#controls .nav { display: flex; gap: 5px; }
#controls .nav button { min-width: 42px; font-size: 16px; padding: 6px 10px; }
#controls #btn-play { min-width: 112px; }
#controls .counter { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
#slider { width: 100%; accent-color: var(--accent); }

/* ---------- en-tête de la partie */
#game-head { padding: 14px 16px; }
#game-head h1 { margin: 0 0 2px; font-size: 21px; line-height: 1.2; letter-spacing: -.01em; }
#game-head .meta { color: var(--muted); font-size: 13.5px; }
#game-head .meta b { color: var(--text); font-weight: 600; }
#game-head .desc { margin: 8px 0 0; font-size: 14px; }

/* ---------- commentaire du coup */
#note { padding: 12px 16px; border-left: 5px solid var(--gold); min-height: 64px; display: flex; flex-direction: column; justify-content: center; gap: 4px; }
#note .lbl { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--gold); display: flex; align-items: center; gap: 8px; }
#note .lbl .mv { text-transform: none; letter-spacing: 0; color: var(--text); font-size: 14px; }
#note .txt { font-size: 15px; }
#note.empty { border-left-color: var(--line); color: var(--muted); }
#note .jump { align-self: flex-start; padding: 3px 9px; font-size: 13px; }
#note .nav-moments { margin-left: auto; display: flex; gap: 4px; }
#note .nav-moments button { padding: 0 7px; font-size: 12px; }

/* ---------- onglets */
.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 6px; }
.tabs button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; padding: 10px 12px 8px; color: var(--muted); font-weight: 600; flex: 1; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.tabpanel { padding: 12px 14px 14px; }
.tabpanel[hidden] { display: none; }
#panel { overflow: hidden; }

/* liste des coups */
#movelist { max-height: 300px; overflow-y: auto; font-variant-numeric: tabular-nums; border: 1px solid var(--line); border-radius: 8px; background: var(--bg2); }
#movelist .row { display: grid; grid-template-columns: 46px 1fr 1fr; }
#movelist .row:nth-child(even) { background: color-mix(in srgb, var(--bg2) 70%, var(--card)); }
#movelist .num { color: var(--muted); padding: 4px 8px; text-align: right; font-size: 13px; }
#movelist .mv { padding: 4px 8px; cursor: pointer; border-radius: 4px; position: relative; font-family: "Segoe UI", "Segoe UI Symbol", system-ui, sans-serif; }
#movelist .mv:hover { background: color-mix(in srgb, var(--accent) 18%, transparent); }
#movelist .mv.cur { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
#movelist .mv.star::after { content: "★"; color: var(--gold); font-size: 11px; margin-left: 4px; vertical-align: super; }
#movelist .mv.cur.star::after { color: var(--accent-ink); }
#movelist .start { padding: 4px 10px; cursor: pointer; color: var(--muted); font-size: 13px; }
#movelist .start.cur { color: var(--accent); font-weight: 700; }
#movelist .result { padding: 6px 10px; text-align: center; font-weight: 700; color: var(--muted); }
body.guessing #movelist .mv.future { visibility: hidden; }
body.guessing #movelist .result { visibility: hidden; }
.tools { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tools button { font-size: 13px; padding: 5px 9px; }
.hint-txt { color: var(--muted); font-size: 13px; margin: 6px 0 0; }

/* devinez */
#guess .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
#guess-msg { min-height: 52px; padding: 10px 12px; border-radius: 8px; background: var(--bg2); font-weight: 600; }
#guess-msg.ok { background: color-mix(in srgb, var(--ok) 18%, var(--card)); color: var(--ok); }
#guess-msg.ko { background: color-mix(in srgb, var(--danger) 14%, var(--card)); color: var(--danger); }
#guess-score { color: var(--muted); font-size: 13px; margin-top: 8px; }

/* IA */
#ai textarea { font: 12.5px/1.45 ui-monospace, Consolas, monospace; min-height: 190px; margin: 8px 0; }
#ai .row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
#ai select { width: 100%; }
.warn { font-size: 13px; color: var(--muted); background: var(--bg2); border-radius: 8px; padding: 8px 10px; margin: 10px 0 0; }
.warn b { color: var(--gold); }

/* affichage */
#settings label.line { display: flex; align-items: center; gap: 8px; margin: 9px 0; }
#settings .field { margin: 10px 0; }
#settings .field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
#settings select { width: 100%; }
#settings input[type="range"] { width: 100%; accent-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; }
.seg button.active { background: var(--accent); color: var(--accent-ink); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button { display: flex; align-items: center; gap: 6px; padding: 4px 9px 4px 4px; }
.swatches button.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.swatches i { width: 26px; height: 26px; border-radius: 4px; display: block; background: linear-gradient(135deg, var(--a) 50%, var(--b) 50%); }

/* ---------- fenêtres */
#modal { position: fixed; inset: 0; background: rgba(10, 12, 16, .55); z-index: 50; display: grid; place-items: center; padding: 16px; backdrop-filter: blur(2px); }
#modal[hidden] { display: none; }
#modal .dialog { position: relative; background: var(--card); border-radius: 14px; box-shadow: var(--shadow); width: min(980px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 20px 22px; border: 1px solid var(--line); }
#modal .dialog.small { width: min(620px, 100%); }
#modal .close { position: absolute; right: 12px; top: 10px; font-size: 22px; line-height: 1; padding: 2px 10px; border: 0; background: none; }
#modal h2 { margin: 0 0 12px; font-size: 21px; }
#modal h3 { margin: 18px 0 8px; font-size: 16px; }
.lib-tools { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; }
.lib-tools input { flex: 1; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 12px; }
.lib-card { display: grid; grid-template-columns: 96px 1fr; gap: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg2); cursor: pointer; text-align: left; }
.lib-card:hover { border-color: var(--accent); }
.lib-card.cur { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.lib-card h4 { margin: 0; font-size: 15px; line-height: 1.25; }
.lib-card .who { font-size: 12.5px; color: var(--muted); margin: 2px 0 4px; }
.lib-card .badges { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }
.badge { font-size: 11.5px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--card); border: 1px solid var(--line); }
.lib-card .acts { display: flex; gap: 5px; margin-top: 6px; flex-wrap: wrap; }
.lib-card .acts button { font-size: 12px; padding: 2px 8px; }
.mini { display: grid; grid-template-columns: repeat(8, 1fr); width: 96px; height: 96px; border-radius: 4px; overflow: hidden; container-type: inline-size; box-shadow: 0 1px 4px rgba(0, 0, 0, .25); }
.mini span { background: var(--sq-l); display: grid; place-items: center; font-size: 11cqw; line-height: 1; font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", serif; position: relative; }
.mini span.d { background: var(--sq-d); }
.mini span.l::after { content: ""; position: absolute; inset: 0; background: var(--hl); }
.mini .w { color: #fbfaf6; text-shadow: 0 0 1px #000, 0 0 1px #000, 0 0 1px #000; }
.mini .b { color: #1c1c1c; }
.import-box { margin-top: 8px; display: grid; gap: 8px; }
.import-box .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.import-box .err { color: var(--danger); font-weight: 600; min-height: 1.2em; }
.share-list { display: grid; gap: 10px; }
.share-item span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 3px; }
.share-item div { display: flex; gap: 6px; }
.share-item input { flex: 1; font: 13px ui-monospace, Consolas, monospace; }
.help-grid { display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; align-items: center; font-size: 14px; }
.help-grid code { font-size: 13px; }
code { font: 13px ui-monospace, Consolas, monospace; background: var(--bg2); padding: 1px 5px; border-radius: 4px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 99px; font-weight: 600; opacity: 0; pointer-events: none; transition: .25s; z-index: 60; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- téléphone et tablette */
@media (max-width: 900px) {
  #main { grid-template-columns: 1fr; padding: 10px 8px 24px; gap: 12px; }
  #left { width: min(100%, 640px); margin: 0 auto; }
  #right { width: min(100%, 640px); margin: 0 auto; }
  #movelist { max-height: 240px; }
  #note { order: -1; }
}
@media (max-width: 560px) {
  #topbar { padding: 6px 8px; gap: 6px; }
  .brand small, #topbar .lbl { display: none; }
  .brand b { font-size: 16px; }
  #controls .nav button { min-width: 0; padding: 6px 8px; }
  #controls #btn-play { min-width: 84px; }
  #controls .counter { width: 100%; text-align: center; margin: 0; }
  #game-head h1 { font-size: 18px; }
  .lib-grid { grid-template-columns: 1fr; }
}
