/* ============================================================================
 * Chess Arena — feuille de style
 * ==========================================================================*/

/* --- Jetons ---------------------------------------------------------------- */
:root {
  --bg: #14110e;
  --bg-2: #1a1613;
  --panel: #221d19;
  --panel-2: #2b251f;
  --panel-3: #352d26;
  --line: #3b332b;
  --line-soft: #2e2822;
  --text: #efe8dc;
  --text-2: #c6bcac;
  --muted: #948a7b;
  --accent: #dda63f;
  --accent-soft: rgba(221, 166, 63, .14);
  --accent-ink: #1a1409;
  --green: #77bd8a;
  --green-soft: rgba(119, 189, 138, .14);
  --red: #dd6048;
  --red-soft: rgba(221, 96, 72, .14);
  --blue: #6ba7d8;
  --purple: #a98cd8;

  --sq-light: #f0d9b5;
  --sq-dark: #b58863;
  --sq-sel: rgba(255, 213, 79, .58);
  --sq-last: rgba(205, 210, 106, .55);
  --sq-hint: rgba(30, 26, 22, .22);
  --sq-check: radial-gradient(circle, rgba(232, 74, 58, .95) 12%, rgba(232, 74, 58, .45) 48%, transparent 72%);
  --arrow: #e79a2f;

  --r-sm: 7px;
  --r: 12px;
  --r-lg: 18px;
  --shadow: 0 2px 4px rgba(0, 0, 0, .22), 0 12px 32px rgba(0, 0, 0, .3);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .2), 0 4px 12px rgba(0, 0, 0, .18);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(.2, .9, .3, 1);
  --panel-blur: 0px;
  --head-tracking: -.012em;
  --head-transform: none;
  --glow: none;
  --sq-grid: transparent;
  --board-max: 660px;
}

/* --- Base ------------------------------------------------------------------ */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
h1, h2, h3, h4 { margin: 0; font-weight: 620; letter-spacing: -.012em; }
h2, h3 { letter-spacing: var(--head-tracking); text-transform: var(--head-transform); }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.18rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .7em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent-soft); }
.hidden, [hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* --- Barre supérieure ------------------------------------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 16px;
  padding: 10px clamp(12px, 3vw, 26px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.02em; font-size: 1.06rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px; display: grid; place-items: center;
  background: linear-gradient(150deg, var(--accent), color-mix(in srgb, var(--accent) 70%, #000));
  color: var(--accent-ink); border-radius: 9px; font-size: 19px; line-height: 1;
  box-shadow: var(--shadow-sm);
}
.brand small { display: block; font-size: .64rem; font-weight: 500; color: var(--muted); letter-spacing: .1em; text-transform: uppercase; }
.nav { display: flex; gap: 2px; }
.nav a {
  padding: 7px 13px; border-radius: 9px; color: var(--text-2);
  font-weight: 520; font-size: .92rem; transition: background .16s, color .16s;
}
.nav a:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }

.user-chip {
  display: flex; align-items: center; gap: 9px; padding: 5px 12px 5px 5px;
  background: var(--panel); border: 1px solid var(--line-soft);
  border-radius: 999px; cursor: pointer; transition: border-color .16s;
}
.user-chip:hover { border-color: var(--line); }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(150deg, var(--panel-3), var(--panel-2));
  font-weight: 700; font-size: .76rem; color: var(--accent); border: 1px solid var(--line);
}
.user-chip .u-name { font-weight: 580; font-size: .88rem; }
.user-chip .u-elo { font-size: .74rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* --- Boutons --------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text);
  font-weight: 560; font-size: .91rem; cursor: pointer;
  transition: transform .12s var(--ease), background .16s, border-color .16s, opacity .16s;
  white-space: nowrap; user-select: none;
}
.btn:hover:not(:disabled) { background: var(--panel-3); border-color: var(--muted); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(160deg, var(--accent), color-mix(in srgb, var(--accent) 72%, #000));
  border-color: transparent; color: var(--accent-ink); font-weight: 640;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .18) inset, var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); border-color: transparent; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--panel-2); color: var(--text); }
.btn-danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 35%, transparent); background: var(--red-soft); }
.btn-danger:hover:not(:disabled) { background: color-mix(in srgb, var(--red) 22%, transparent); border-color: var(--red); }
.btn-sm { padding: 6px 11px; font-size: .84rem; border-radius: 8px; }
.btn-lg { padding: 13px 24px; font-size: 1rem; border-radius: 12px; }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; width: 36px; height: 36px; }

/* --- Champs ---------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: .8rem; font-weight: 580; color: var(--text-2); }
.input, select.input, textarea.input {
  width: 100%; padding: 10px 13px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg-2); color: var(--text);
  transition: border-color .16s, box-shadow .16s;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 5px; border-radius: 3px; background: var(--panel-3); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 17px; height: 17px; border-radius: 50%; background: var(--accent); margin-top: -6px; box-shadow: var(--shadow-sm); }
input[type=range]::-moz-range-track { height: 5px; border-radius: 3px; background: var(--panel-3); }
input[type=range]::-moz-range-thumb { width: 17px; height: 17px; border: none; border-radius: 50%; background: var(--accent); }

.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--panel-3); border-radius: 999px; transition: background .18s; cursor: pointer; }
.switch span::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: var(--text-2); border-radius: 50%; transition: transform .18s var(--ease), background .18s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); background: var(--accent-ink); }

/* --- Cartes ---------------------------------------------------------------- */
.card {
  background: var(--panel); border: 1px solid var(--line-soft);
  border-radius: var(--r); box-shadow: var(--shadow-sm);
}
.card-pad { padding: clamp(14px, 2.4vw, 22px); }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line-soft); }
.card-head h2, .card-head h3 { flex: 1; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px; font-size: .76rem; font-weight: 580;
  background: var(--panel-2); border: 1px solid var(--line-soft); color: var(--text-2);
}
.chip.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.green { background: var(--green-soft); color: var(--green); border-color: transparent; }
.chip.red { background: var(--red-soft); color: var(--red); border-color: transparent; }

/* --- Grille principale ----------------------------------------------------- */
.page { position: relative; z-index: 1; max-width: 1340px; margin: 0 auto; padding: clamp(14px, 2.6vw, 30px); }
.screen { display: none; animation: fade .22s var(--ease); }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ==========================================================================
 * Plateau
 * ========================================================================*/
.board {
  position: relative; width: 100%; aspect-ratio: 1;
  border-radius: var(--r); overflow: hidden;
  box-shadow: var(--shadow); touch-action: none; user-select: none;
  background: var(--sq-light);
}
.board.locked { cursor: default; }
.board-squares { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); }
.sq { position: relative; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.last::after, .sq.sel::after, .sq.pre::after {
  content: ''; position: absolute; inset: 0;
}
.sq.last::after { background: var(--sq-last); }
.sq.sel::after { background: var(--sq-sel); }
.sq.pre::after { background: rgba(120, 160, 255, .45); }
.sq.check { background-image: var(--sq-check); }
.sq.over { box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .55); }
.sq .coord {
  position: absolute; font-size: clamp(8px, 1.35vmin, 11px); font-weight: 700;
  opacity: .62; pointer-events: none; z-index: 3;
}
.sq.light .coord { color: var(--sq-dark); }
.sq.dark .coord { color: var(--sq-light); }
.sq .coord.file { right: 3px; bottom: 1px; }
.sq .coord.rank { left: 3px; top: 1px; }
.sq.hint::before {
  content: ''; position: absolute; left: 50%; top: 50%; width: 30%; height: 30%;
  transform: translate(-50%, -50%); border-radius: 50%; background: var(--sq-hint); z-index: 2;
  animation: pop .16s var(--ease);
}
.sq.hint-cap::before {
  content: ''; position: absolute; inset: 6%; border-radius: 50%;
  border: .5vmin solid var(--sq-hint); z-index: 2; animation: pop .16s var(--ease);
}
@keyframes pop { from { transform: translate(-50%, -50%) scale(.4); } }
.sq.hint-cap::before { animation: none; }

.board-pieces { position: absolute; inset: 0; pointer-events: none; }
.pc {
  position: absolute; left: 0; top: 0; width: 12.5%; height: 12.5%;
  will-change: transform; z-index: 5;
}
.pc .piece-svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .28)); }
.pc.moving { z-index: 8; }
.pc.dragging { z-index: 20; transform-origin: center; }
.pc.dragging .piece-svg { transform: scale(1.1); filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .45)); cursor: grabbing; }
.pc.captured { animation: capOut .16s var(--ease) forwards; }
@keyframes capOut { to { opacity: 0; transform: scale(.7) translate(var(--tx, 0), var(--ty, 0)); } }
.board-shapes { position: absolute; inset: 0; z-index: 9; pointer-events: none; overflow: visible; }
.board-glow .pc .piece-svg { filter: drop-shadow(0 0 5px rgba(94, 234, 212, .35)) drop-shadow(0 1px 1px rgba(0, 0, 0, .4)); }

.board-promo {
  position: absolute; z-index: 30; width: 12.5%;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); overflow: hidden;
}
.promo-btn, .promo-cancel {
  display: block; width: 100%; aspect-ratio: 1; padding: 6%; border: 0;
  background: transparent; cursor: pointer; transition: background .14s;
}
.promo-btn:hover { background: var(--accent-soft); }
.promo-cancel { aspect-ratio: 2.6; color: var(--muted); font-size: .9rem; }
.promo-cancel:hover { background: var(--red-soft); color: var(--red); }
.board-promo.up { display: flex; flex-direction: column-reverse; }

/* --- Barre d'évaluation ---------------------------------------------------- */
.evalbar {
  position: relative; width: 22px; border-radius: 7px; overflow: hidden;
  background: #2a2724; flex: none; box-shadow: var(--shadow-sm);
}
.evalbar .white-part {
  position: absolute; left: 0; right: 0; bottom: 0; background: #efe9dd;
  transition: height .5s var(--ease); height: 50%;
}
.evalbar .val {
  position: absolute; left: 0; right: 0; text-align: center; font-size: .58rem;
  font-weight: 800; font-family: var(--mono); z-index: 2; padding: 3px 0;
}
.evalbar .val.top { top: 0; color: #efe9dd; }
.evalbar .val.bottom { bottom: 0; color: #22201d; }
.evalbar .mid { position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: rgba(140, 130, 115, .5); z-index: 3; }

/* ==========================================================================
 * Écran de jeu
 * ========================================================================*/
.play-layout {
  display: grid; gap: clamp(12px, 2vw, 22px);
  grid-template-columns: minmax(0, 1fr) minmax(300px, 372px);
  align-items: start;
}
.board-column {
  display: flex; flex-direction: column; gap: 10px; min-width: 0;
  width: 100%; max-width: min(calc(100dvh - 236px), 660px); margin-inline: auto;
}
.board-with-bar { display: flex; gap: 10px; align-items: stretch; }
.board-with-bar > .board-wrap { flex: 1; min-width: 0; }

.player-bar {
  display: flex; align-items: center; gap: 11px; padding: 9px 13px;
  background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--r);
}
.player-bar.turn { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-soft); }
.player-bar .p-name { font-weight: 600; }
.player-bar .p-sub { font-size: .76rem; color: var(--muted); }
.captured-row { display: flex; gap: 1px; align-items: center; flex-wrap: wrap; max-width: 190px; }
.captured-row svg { width: 17px; height: 17px; opacity: .8; margin-right: -5px; }
.captured-row .adv { font-size: .76rem; color: var(--muted); margin-left: 8px; font-weight: 600; }

.clock {
  font-family: var(--mono); font-size: 1.42rem; font-weight: 700; letter-spacing: -.01em;
  padding: 5px 13px; border-radius: 9px; background: var(--panel-2);
  border: 1px solid var(--line-soft); min-width: 104px; text-align: center;
  transition: background .2s, color .2s;
  font-variant-numeric: tabular-nums;
}
.clock.active { background: var(--panel-3); color: var(--text); border-color: var(--muted); }
.clock.low { color: var(--red); background: var(--red-soft); border-color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .62; } }

.side-panel { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 74px; }
.tabs { display: flex; gap: 2px; padding: 4px; background: var(--panel-2); border-radius: 11px; border: 1px solid var(--line-soft); }
.tabs button {
  flex: 1; padding: 7px 10px; border: 0; background: transparent; color: var(--muted);
  border-radius: 8px; cursor: pointer; font-weight: 570; font-size: .86rem; transition: background .16s, color .16s;
}
.tabs button:hover { color: var(--text-2); }
.tabs button.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow-sm); }

.movelist {
  max-height: min(46vh, 420px); overflow-y: auto; padding: 6px;
  font-family: var(--mono); font-size: .87rem; scroll-behavior: smooth;
}
.movelist .mrow { display: grid; grid-template-columns: 34px 1fr 1fr; gap: 3px; align-items: stretch; }
.movelist .mrow:nth-child(odd) { background: color-mix(in srgb, var(--panel-2) 55%, transparent); border-radius: 6px; }
.movelist .num { color: var(--muted); padding: 4px 6px; font-size: .8rem; }
.movelist .mv {
  padding: 4px 7px; border-radius: 6px; cursor: pointer; display: flex; align-items: center; gap: 5px;
  transition: background .14s;
}
.movelist .mv:hover { background: var(--panel-3); }
.movelist .mv.current { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.movelist .empty { padding: 22px 10px; text-align: center; color: var(--muted); font-family: var(--font); }
.mv .tag { font-size: .78rem; font-weight: 800; }
.tag-brillant { color: #4fc3d9; }
.tag-best { color: var(--green); }
.tag-excellent { color: #8fd07a; }
.tag-bon { color: var(--muted); }
.tag-imprecision { color: #e0b53f; }
.tag-erreur { color: #e08a3f; }
.tag-gaffe { color: var(--red); }

.game-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 12px; }
.game-actions .btn { width: 100%; }
.nav-buttons { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 0 12px 12px; }

.status-banner {
  padding: 13px 16px; border-radius: var(--r); text-align: center;
  background: var(--panel-2); border: 1px solid var(--line-soft);
}
.status-banner.win { background: var(--green-soft); border-color: color-mix(in srgb, var(--green) 40%, transparent); }
.status-banner.loss { background: var(--red-soft); border-color: color-mix(in srgb, var(--red) 40%, transparent); }
.status-banner .r-title { font-size: 1.14rem; font-weight: 700; }
.status-banner .r-sub { font-size: .86rem; color: var(--text-2); }
.elo-delta { font-weight: 800; font-family: var(--mono); }
.elo-delta.up { color: var(--green); }
.elo-delta.down { color: var(--red); }

.chatbox { display: flex; flex-direction: column; height: 220px; }
.chat-log { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; font-size: .86rem; }
.chat-log .who { font-weight: 650; color: var(--accent); margin-right: 5px; }
.chat-form { display: flex; gap: 6px; padding: 9px; border-top: 1px solid var(--line-soft); }

/* ==========================================================================
 * Accueil
 * ========================================================================*/
.hero { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr); gap: clamp(18px, 3vw, 42px); align-items: center; margin-bottom: 30px; }
.hero h1 { font-size: clamp(1.9rem, 4.4vw, 3rem); line-height: 1.06; letter-spacing: -.028em; }
.hero h1 em { font-style: normal; color: var(--accent); }
.hero p.lead { font-size: clamp(.98rem, 1.6vw, 1.1rem); color: var(--text-2); max-width: 52ch; margin: 14px 0 22px; }
.hero-board { max-width: 400px; margin-left: auto; width: 100%; }
.stats-row { display: flex; gap: 22px; flex-wrap: wrap; margin-top: 24px; }
.stat .n { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { font-size: .76rem; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }

.mode-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(268px, 1fr)); gap: 14px; }
.mode-card {
  display: flex; flex-direction: column; gap: 8px; padding: 20px; text-align: left;
  background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--r-lg);
  cursor: pointer; transition: transform .18s var(--ease), border-color .18s, background .18s;
  color: inherit;
}
.mode-card:hover { transform: translateY(-3px); border-color: var(--accent); background: var(--panel-2); text-decoration: none; }
.mode-card .ic { font-size: 1.7rem; line-height: 1; }
.mode-card h3 { font-size: 1.04rem; }
.mode-card p { font-size: .86rem; color: var(--muted); margin: 0; }

/* --- Sélecteur de niveau --------------------------------------------------- */
.level-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(112px, 1fr)); gap: 9px; }
.level-btn {
  position: relative; padding: 13px 9px; border-radius: var(--r);
  border: 1px solid var(--line-soft); background: var(--panel-2); cursor: pointer;
  text-align: center; transition: transform .14s var(--ease), border-color .16s, background .16s;
}
.level-btn:hover { transform: translateY(-2px); border-color: var(--muted); }
.level-btn.selected { border-color: var(--accent); background: var(--accent-soft); }
.level-btn .lv { font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.level-btn .nm { font-weight: 640; font-size: .92rem; margin: 2px 0; }
.level-btn .el { font-size: .76rem; color: var(--accent); font-variant-numeric: tabular-nums; }
.level-btn .bars { display: flex; gap: 2px; justify-content: center; margin-top: 6px; }
.level-btn .bars i { width: 4px; height: 9px; border-radius: 1px; background: var(--line); }
.level-btn .bars i.on { background: var(--accent); }
.level-btn .crown { position: absolute; top: 5px; right: 7px; font-size: .74rem; }

.tc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
.tc-btn {
  padding: 11px 8px; border-radius: 10px; border: 1px solid var(--line-soft);
  background: var(--panel-2); cursor: pointer; text-align: center; transition: border-color .16s, background .16s;
}
.tc-btn:hover { border-color: var(--muted); }
.tc-btn.selected { border-color: var(--accent); background: var(--accent-soft); }
.tc-btn .t { font-weight: 680; font-variant-numeric: tabular-nums; }
.tc-btn .c { font-size: .72rem; color: var(--muted); }

.color-picker { display: flex; gap: 8px; }
.color-picker button {
  flex: 1; padding: 11px; border-radius: 10px; border: 1px solid var(--line-soft);
  background: var(--panel-2); cursor: pointer; display: grid; place-items: center; gap: 4px;
  transition: border-color .16s, background .16s;
}
.color-picker button.selected { border-color: var(--accent); background: var(--accent-soft); }
.color-picker svg { width: 30px; height: 30px; }
.color-picker span { font-size: .76rem; color: var(--muted); }

/* ==========================================================================
 * Puzzles
 * ========================================================================*/
.puzzle-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 350px); gap: clamp(12px, 2vw, 22px); align-items: start; }
.puzzle-verdict { padding: 14px 16px; border-radius: var(--r); text-align: center; font-weight: 600; }
.puzzle-verdict.ok { background: var(--green-soft); color: var(--green); }
.puzzle-verdict.ko { background: var(--red-soft); color: var(--red); }
.puzzle-verdict.go { background: var(--accent-soft); color: var(--accent); }
.streak-dots { display: flex; gap: 4px; flex-wrap: wrap; }
.streak-dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--panel-3); }
.streak-dots i.ok { background: var(--green); }
.streak-dots i.ko { background: var(--red); }
.rating-big { font-size: 2.2rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }

/* ==========================================================================
 * Tableaux, classement, historique
 * ========================================================================*/
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th {
  text-align: left; padding: 9px 12px; font-size: .72rem; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted); font-weight: 640; border-bottom: 1px solid var(--line-soft);
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .14s; }
.table tbody tr:hover { background: var(--panel-2); }
.table .num { font-variant-numeric: tabular-nums; text-align: right; }
.rank-1 { color: #e8c153; font-weight: 800; }
.rank-2 { color: #c8ccd2; font-weight: 750; }
.rank-3 { color: #cd8f56; font-weight: 750; }
.result-badge { display: inline-block; width: 20px; height: 20px; line-height: 20px; text-align: center; border-radius: 5px; font-size: .72rem; font-weight: 800; }
.result-badge.w { background: var(--green-soft); color: var(--green); }
.result-badge.l { background: var(--red-soft); color: var(--red); }
.result-badge.d { background: var(--panel-3); color: var(--muted); }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 11px; }
.kpi { padding: 15px; background: var(--panel-2); border-radius: var(--r); border: 1px solid var(--line-soft); }
.kpi .v { font-size: 1.55rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi .k { font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-top: 3px; }

/* --- Réglages -------------------------------------------------------------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(268px, 1fr)); gap: 14px; }
.setting-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line-soft); }
.setting-row:last-child { border-bottom: 0; }
.setting-row .lbl { flex: 1; }
.setting-row .lbl .t { font-weight: 570; }
.setting-row .lbl .d { font-size: .78rem; color: var(--muted); }
.theme-swatches { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 9px; }
.swatch { border: 2px solid transparent; border-radius: 10px; padding: 0; overflow: hidden; cursor: pointer; background: none; transition: transform .14s var(--ease); }
.swatch:hover { transform: translateY(-2px); }
.swatch.selected { border-color: var(--accent); }
.swatch .mini { display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); aspect-ratio: 1; }
.swatch .mini.flat { grid-template-columns: 1fr; grid-template-rows: 1fr; aspect-ratio: 3 / 1; }
.swatch .mini i { display: block; }
.swatch .nm { display: block; font-size: .7rem; padding: 4px 2px; color: var(--text-2); background: var(--panel-2); }
.pieceset-preview { display: flex; gap: 2px; justify-content: center; padding: 8px; }
.pieceset-preview svg { width: 30px; height: 30px; }

/* --- Modale ---------------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: rgba(8, 6, 5, .68); backdrop-filter: blur(4px); padding: 18px;
  animation: fade .16s var(--ease);
}
.modal {
  width: min(460px, 100%); max-height: 88vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow);
  animation: modalIn .2s var(--ease);
}
.modal.wide { width: min(760px, 100%); }
@keyframes modalIn { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 17px 20px; border-bottom: 1px solid var(--line-soft); }
.modal-head h2 { flex: 1; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; gap: 9px; justify-content: flex-end; padding: 15px 20px; border-top: 1px solid var(--line-soft); }
.close-x { background: none; border: 0; color: var(--muted); font-size: 1.3rem; cursor: pointer; line-height: 1; padding: 2px 6px; border-radius: 6px; }
.close-x:hover { background: var(--panel-2); color: var(--text); }

.form-error { padding: 9px 12px; border-radius: 9px; background: var(--red-soft); color: var(--red); font-size: .86rem; }
.form-note { padding: 9px 12px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); font-size: .84rem; }

/* --- Notifications --------------------------------------------------------- */
.toasts { position: fixed; bottom: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 9px; pointer-events: none; }
.toast {
  padding: 11px 16px; border-radius: 11px; background: var(--panel);
  border: 1px solid var(--line); box-shadow: var(--shadow); font-size: .89rem;
  animation: toastIn .22s var(--ease); max-width: 340px; pointer-events: auto;
}
.toast.error { border-color: var(--red); color: var(--red); }
.toast.success { border-color: var(--green); color: var(--green); }
@keyframes toastIn { from { opacity: 0; transform: translateX(24px); } }
.toast.out { animation: toastOut .2s var(--ease) forwards; }
@keyframes toastOut { to { opacity: 0; transform: translateX(24px); } }

/* --- Divers ---------------------------------------------------------------- */
.spinner {
  width: 17px; height: 17px; border-radius: 50%; flex: none;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress { height: 6px; border-radius: 3px; background: var(--panel-3); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .25s var(--ease); }
.thinking { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); }
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); flex: none; }
.badge-dot.off { background: var(--muted); }
.divider { height: 1px; background: var(--line-soft); margin: 4px 0; }
.accuracy-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--panel-3); }
.accuracy-bar i { display: block; height: 100%; }

.eval-graph { width: 100%; height: 82px; display: block; background: var(--panel-2); border-radius: var(--r-sm); cursor: crosshair; }

/* --- Responsive ------------------------------------------------------------ */
@media (max-width: 1080px) {
  .play-layout, .puzzle-layout { grid-template-columns: minmax(0, 1fr); }
  .board-column { max-width: min(94vw, 560px); }
  .side-panel { position: static; }
  .hero { grid-template-columns: minmax(0, 1fr); }
  .hero-board { max-width: 340px; margin: 0 auto; }
}
@media (max-width: 760px) {
  body { font-size: 14.5px; }
  .topbar { gap: 8px; padding: 8px 12px; }
  .brand small { display: none; }
  .nav { order: 3; width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .nav::-webkit-scrollbar { display: none; }
  .topbar { flex-wrap: wrap; }
  .page { padding: 12px; }
  .clock { font-size: 1.2rem; min-width: 86px; padding: 4px 9px; }
  .captured-row { max-width: 120px; }
  .game-actions { grid-template-columns: repeat(2, 1fr); }
  .movelist { max-height: 200px; }
  .modal { border-radius: var(--r); }
  .stats-row { gap: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Barres de défilement discrètes */
* { scrollbar-width: thin; scrollbar-color: var(--panel-3) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 5px; }
*::-webkit-scrollbar-thumb:hover { background: var(--line); }
*::-webkit-scrollbar-track { background: transparent; }

/* ==========================================================================
 * Univers visuels — couche d'arrière-plan et effets
 * ========================================================================*/
.fx-layer {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
  background:
    radial-gradient(1100px 620px at 12% -8%, color-mix(in srgb, var(--accent) 8%, transparent), transparent 60%),
    radial-gradient(900px 520px at 100% 0%, color-mix(in srgb, var(--blue) 6%, transparent), transparent 55%);
}

/* --- Grille en perspective (Néon) --- */
body.fx-grid .fx-layer::before {
  content: ''; position: absolute; left: -50%; right: -50%; bottom: -20%; height: 78%;
  background-image:
    linear-gradient(color-mix(in srgb, var(--accent) 22%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--accent) 22%, transparent) 1px, transparent 1px);
  background-size: 56px 56px;
  transform: perspective(320px) rotateX(66deg);
  transform-origin: bottom center;
  mask-image: linear-gradient(to top, #000 0%, transparent 88%);
  opacity: .5;
  animation: gridDrift 14s linear infinite;
}
@keyframes gridDrift { to { background-position: 0 56px, 56px 0; } }

/* --- Lignes de balayage --- */
body.fx-scanlines .fx-layer::after {
  content: ''; position: absolute; inset: 0;
  background: repeating-linear-gradient(to bottom, rgba(255, 255, 255, .028) 0 1px, transparent 1px 3px);
  mix-blend-mode: overlay;
}

/* --- Aurore (Verre) --- */
body.fx-aurora .fx-layer {
  background:
    radial-gradient(760px 520px at 18% 8%, rgba(124, 92, 255, .40), transparent 62%),
    radial-gradient(680px 480px at 84% 18%, rgba(46, 168, 255, .30), transparent 60%),
    radial-gradient(720px 560px at 52% 96%, rgba(255, 92, 168, .26), transparent 62%);
  filter: blur(12px);
  animation: auroraShift 26s ease-in-out infinite alternate;
}
@keyframes auroraShift {
  0%   { transform: translate3d(-2%, -1%, 0) scale(1.04); }
  50%  { transform: translate3d(2%, 2%, 0) scale(1.1); }
  100% { transform: translate3d(-1%, 1%, 0) scale(1.05); }
}

/* --- Soleil et grille au sol (Synthwave) --- */
body.fx-sun .fx-layer::before {
  content: ''; position: absolute; left: 50%; top: 6%;
  width: min(560px, 74vw); aspect-ratio: 1; transform: translateX(-50%);
  border-radius: 50%;
  background: linear-gradient(180deg, #ffd166 0%, #ff7ac6 52%, #ff3ea5 100%);
  mask-image: repeating-linear-gradient(to bottom, #000 0 12px, transparent 12px 17px),
              linear-gradient(to bottom, #000 42%, transparent 88%);
  mask-composite: intersect;
  -webkit-mask-image: repeating-linear-gradient(to bottom, #000 0 12px, transparent 12px 17px),
                      linear-gradient(to bottom, #000 42%, transparent 88%);
  -webkit-mask-composite: source-in;
  opacity: .5;
}
body.fx-floorgrid .fx-layer::after {
  content: ''; position: absolute; left: -50%; right: -50%; bottom: -12%; height: 56%;
  background-image:
    linear-gradient(rgba(255, 62, 165, .34) 1px, transparent 1px),
    linear-gradient(90deg, rgba(34, 211, 238, .26) 1px, transparent 1px);
  background-size: 62px 62px;
  transform: perspective(300px) rotateX(72deg);
  transform-origin: bottom center;
  mask-image: linear-gradient(to top, #000 10%, transparent 92%);
  animation: gridDrift 11s linear infinite;
}

/* --- Panneaux en verre --- */
.card, .topbar, .player-bar, .modal, .tabs, .clock, .mode-card, .kpi, .level-btn, .tc-btn {
  backdrop-filter: blur(var(--panel-blur));
  -webkit-backdrop-filter: blur(var(--panel-blur));
}
body.fx-blur .card, body.fx-blur .modal, body.fx-blur .player-bar {
  border-color: var(--line);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, .09);
}

/* --- Halo lumineux --- */
body.fx-glow .btn-primary,
body.fx-glow .chip.accent,
body.fx-glow .nav a.active { box-shadow: var(--glow); }
body.fx-glow .board { box-shadow: var(--shadow), 0 0 42px -10px color-mix(in srgb, var(--accent) 55%, transparent); }
body.fx-glow .clock.active { box-shadow: 0 0 12px -2px color-mix(in srgb, var(--accent) 60%, transparent); }
body.fx-glow .player-bar.turn { box-shadow: 0 0 0 1px var(--accent), var(--glow); }
body.fx-glow .rating-big, body.fx-glow .stat .n { text-shadow: 0 0 18px color-mix(in srgb, var(--accent) 45%, transparent); }

/* --- Chasse fixe (HUD) --- */
body.fx-mono h2, body.fx-mono h3, body.fx-mono .btn, body.fx-mono .chip,
body.fx-mono .nav a, body.fx-mono .kpi .k, body.fx-mono .stat .l,
body.fx-mono .tabs button, body.fx-mono .level-btn .lv, body.fx-mono .brand {
  font-family: var(--mono);
  font-weight: 600;
}
body.fx-mono .table th { font-family: var(--mono); }

/* --- Équerres d'angle (HUD) --- */
body.fx-brackets .card { position: relative; }
body.fx-brackets .card::before, body.fx-brackets .card::after {
  content: ''; position: absolute; width: 13px; height: 13px; pointer-events: none;
  border-color: var(--accent); opacity: .75;
}
body.fx-brackets .card::before { top: -1px; left: -1px; border-top: 2px solid; border-left: 2px solid; }
body.fx-brackets .card::after { bottom: -1px; right: -1px; border-bottom: 2px solid; border-right: 2px solid; }

/* --- Quadrillage des cases --- */
.board-grid .sq { box-shadow: inset 0 0 0 1px var(--sq-grid); }

/* ==========================================================================
 * Effets de jeu
 * ========================================================================*/
.board.shake { animation: boardShake .34s var(--ease); }
@keyframes boardShake {
  0%, 100% { transform: translateX(0); }
  18% { transform: translateX(-6px); }
  38% { transform: translateX(5px); }
  58% { transform: translateX(-3px); }
  78% { transform: translateX(2px); }
}
.trail {
  position: absolute; z-index: 4; border-radius: 999px; pointer-events: none;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--arrow) 70%, transparent));
  transform-origin: left center; opacity: .85;
  animation: trailFade .52s var(--ease) forwards;
}
@keyframes trailFade { to { opacity: 0; filter: blur(3px); } }
.spark {
  position: absolute; width: 5px; height: 5px; border-radius: 50%; z-index: 12;
  background: var(--arrow); pointer-events: none;
  animation: sparkOut .5s var(--ease) forwards;
}
@keyframes sparkOut { to { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(.3); } }
.board-flash {
  position: absolute; inset: 0; z-index: 25; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at center, color-mix(in srgb, var(--accent) 40%, transparent), transparent 70%);
  animation: flashOut .7s var(--ease) forwards;
}
@keyframes flashOut { 30% { opacity: 1; } 100% { opacity: 0; } }

/* ==========================================================================
 * Appareils : tactile, paysage, grands écrans
 * ========================================================================*/
.board-column { max-width: min(calc(100dvh - 236px), var(--board-max)); }

/* Pièce agrandie sous le doigt */
.pc.dragging.touch .piece-svg { transform: scale(1.55) translateY(-16%); }

/* Mode une main : commandes ramenées en bas de l'écran */
@media (max-width: 760px) {
  body.one-hand .play-layout { display: flex; flex-direction: column; }
  body.one-hand .side-panel { order: 2; }
  body.one-hand .board-column { order: 1; }
  body.one-hand .game-actions { position: sticky; bottom: 0; z-index: 20; background: var(--panel); }
  .game-actions .btn { min-height: 44px; }
  .nav-buttons .btn { min-height: 40px; }
  .tabs button { min-height: 38px; }
}

/* Tablette et téléphone en paysage : plateau à gauche, panneaux à droite */
@media (orientation: landscape) and (max-height: 620px) {
  .topbar { position: static; }
  .page { padding: 8px; }
  .play-layout, .puzzle-layout { grid-template-columns: minmax(0, auto) minmax(240px, 1fr); align-items: start; }
  .board-column { max-width: calc(100dvh - 118px); }
  .side-panel { position: static; }
  .movelist { max-height: calc(100dvh - 330px); }
  .hero { grid-template-columns: minmax(0, 1fr) minmax(0, 320px); }
}
@media (orientation: landscape) and (min-height: 621px) and (max-width: 1180px) {
  .play-layout, .puzzle-layout { grid-template-columns: minmax(0, 1fr) minmax(280px, 340px); }
  .board-column { max-width: min(calc(100dvh - 210px), 620px); }
}

/* Très grands écrans */
@media (min-width: 1700px) {
  :root { --board-max: 820px; }
  .page { max-width: 1660px; }
  .play-layout { grid-template-columns: minmax(0, 1fr) minmax(340px, 420px); }
  body { font-size: 16px; }
}
@media (min-width: 2400px) {
  :root { --board-max: 1000px; }
  .page { max-width: 2100px; }
  body { font-size: 18px; }
}

/* Encoches et barres système */
@supports (padding: max(0px)) {
  .topbar { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .page { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
}

/* ==========================================================================
 * Éditeur de thème
 * ========================================================================*/
.color-rows { display: grid; gap: 2px; }
.color-row {
  display: flex; align-items: center; gap: 12px; padding: 9px 0;
  border-bottom: 1px solid var(--line-soft);
}
.color-row:last-child { border-bottom: 0; }
.color-row .cr-label { flex: 1; }
.color-row .cr-label .t { font-weight: 560; }
.color-row .cr-label .d { font-size: .76rem; color: var(--muted); }
.color-row input[type=color] {
  width: 46px; height: 32px; padding: 0; border: 1px solid var(--line);
  border-radius: 8px; background: none; cursor: pointer;
}
.color-row input[type=color]::-webkit-color-swatch-wrapper { padding: 3px; }
.color-row input[type=color]::-webkit-color-swatch { border: none; border-radius: 5px; }
.color-row .cr-hex {
  font-family: var(--mono); font-size: .78rem; color: var(--muted);
  width: 74px; text-align: right;
}
.editor-preview {
  display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr);
  width: 100%; max-width: 220px; aspect-ratio: 1; border-radius: var(--r);
  overflow: hidden; box-shadow: var(--shadow-sm); margin: 0 auto;
}
.editor-preview i { display: block; position: relative; }
.editor-preview svg { position: absolute; inset: 8%; width: 84%; height: 84%; }
.share-code {
  font-family: var(--mono); font-size: .74rem; word-break: break-all;
  background: var(--bg-2); border: 1px solid var(--line-soft);
  border-radius: var(--r-sm); padding: 9px 11px; color: var(--text-2);
  max-height: 92px; overflow-y: auto;
}
.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(126px, 1fr)); gap: 8px; }
.preset {
  display: flex; align-items: center; gap: 8px; padding: 7px 9px;
  border: 1px solid var(--line-soft); border-radius: 10px; background: var(--panel-2);
  cursor: pointer; text-align: left;
}
.preset:hover { border-color: var(--accent); }
.preset .dots { display: flex; gap: 2px; flex: none; }
.preset .dots i { width: 11px; height: 18px; border-radius: 2px; display: block; }
.preset .nm { font-size: .78rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preset .rm { color: var(--muted); font-size: .9rem; padding: 0 2px; }
.preset .rm:hover { color: var(--red); }

/* Univers dans les réglages */
.universe-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 10px; }
.universe-card {
  position: relative; padding: 0; overflow: hidden; cursor: pointer; text-align: left;
  border: 2px solid transparent; border-radius: var(--r); background: var(--panel-2);
  transition: transform .16s var(--ease), border-color .16s;
}
.universe-card:hover { transform: translateY(-2px); }
.universe-card.selected { border-color: var(--accent); }
.universe-card .u-preview { height: 62px; display: block; position: relative; overflow: hidden; }
.universe-card .u-preview .u-sq { position: absolute; right: 8px; bottom: 8px; width: 34px; height: 34px; border-radius: 4px; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; overflow: hidden; }
.universe-card .u-preview .u-sq i { display: block; }
.universe-card .u-body { padding: 8px 10px 10px; }
.universe-card .u-name { font-weight: 620; font-size: .88rem; }
.universe-card .u-tag { font-size: .72rem; color: var(--muted); line-height: 1.35; }

/* Succès */
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 10px; }
.badge {
  display: flex; gap: 10px; align-items: flex-start; padding: 11px 12px;
  border: 1px solid var(--line-soft); border-radius: var(--r); background: var(--panel-2);
}
.badge.locked { opacity: .45; }
.badge .b-ic { font-size: 1.3rem; line-height: 1; flex: none; }
.badge .b-name { font-weight: 580; font-size: .86rem; }
.badge .b-desc { font-size: .74rem; color: var(--muted); }
.badge .b-prog { height: 4px; border-radius: 2px; background: var(--panel-3); margin-top: 5px; overflow: hidden; }
.badge .b-prog i { display: block; height: 100%; background: var(--accent); }

/* Bouton d'installation */
.install-banner {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  border: 1px solid var(--accent); border-radius: var(--r);
  background: var(--accent-soft); margin-bottom: 16px;
}

.board-fx { position: absolute; inset: 0; z-index: 11; pointer-events: none; overflow: hidden; }
