:root {
  --bg: #312e2b; --panel: #262421; --panel-2: #3c3a37; --text: #e8e6e3; --muted: #9a9894;
  --accent: #81b64c; --accent-d: #6a9a3a; --danger: #fa412d;
  --light: #ebecd0; --dark: #739552;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }

.topbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid #000; }
.brand { font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; }
.topbar-right { display: flex; gap: 12px; align-items: center; }
.topbar form { margin: 0; }

.container { max-width: 1100px; margin: 24px auto; padding: 0 16px; }
.card { background: var(--panel); border-radius: 8px; padding: 16px 18px; margin-bottom: 16px; }
.card h1, .card h2 { margin: 0 0 12px; font-size: 18px; }

.btn { background: var(--panel-2); color: var(--text); border: 0; border-radius: 6px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-block; }
.btn:hover { filter: brightness(1.15); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 3px 0 var(--accent-d); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-sm { padding: 4px 10px; font-size: 13px; box-shadow: none; }
.linkbtn { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }
form.inline { display: inline; }

input { display: block; width: 100%; margin-top: 4px; padding: 9px 10px; border-radius: 6px; border: 1px solid #555; background: #1e1c1a; color: var(--text); font: inherit; }
input[type=checkbox] { display: inline; width: auto; margin: 0 6px 0 0; }
label { font-size: 13px; color: var(--muted); }
.stack { display: grid; gap: 14px; }
.login-card { max-width: 360px; margin: 80px auto; }
.alert { background: #5a1f1a; color: #ffd2cc; padding: 8px 12px; border-radius: 6px; }
.info { background: #2f3d22; padding: 8px 12px; border-radius: 6px; }

.import-form { display: grid; grid-template-columns: 2fr 1fr auto; gap: 12px; align-items: end; }
.import-form .check { display: flex; align-items: center; padding-bottom: 10px; color: var(--text); }
@media (max-width: 700px) { .import-form { grid-template-columns: 1fr; } }

.table-wrap { overflow-x: auto; }
table.games { width: 100%; border-collapse: collapse; }
.games th { text-align: left; font-size: 12px; text-transform: uppercase; color: var(--muted); padding: 6px 8px; }
.games td { padding: 8px; border-top: 1px solid #3a3835; }
.games form { margin: 0; }
.pill { background: var(--panel-2); border-radius: 99px; padding: 2px 10px; font-size: 12px; }
.pill.running { background: #4b5d2f; }
.acc-w { color: #fff; font-weight: 700; }
.acc-b { color: #b9b7b3; font-weight: 700; }

/* ---------------------------------------------------------- review */
.review { max-width: 1500px; margin: 16px auto; padding: 0 16px; }
.review-grid { display: grid; grid-template-columns: 300px minmax(0, 1fr) 340px; grid-template-areas: "left board side"; gap: 20px; align-items: start; }
.left-col { grid-area: left; min-width: 0; }
.board-col { grid-area: board; }
.side-col { grid-area: side; min-width: 0; }
.board-col { min-width: 0; }
.board-row { display: flex; gap: 8px; }
.board-wrap { position: relative; flex: 1; max-width: min(720px, calc(100vh - 170px)); aspect-ratio: 1; }
.board { position: relative; touch-action: none; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); width: 100%; height: 100%; border-radius: 4px; overflow: hidden; container-type: size; }
.arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.sq { position: relative; display: flex; align-items: center; justify-content: center; }
.sq.light { background: var(--light); }
.sq.dark { background: var(--dark); }
.sq.hl::before { content: ""; position: absolute; inset: 0; background: var(--hl, #f6f669); opacity: 0.5; }
.pc { position: relative; display: block; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.sq-badge { position: absolute; top: -8%; right: -8%; width: 42%; height: 42%; border-radius: 50%; color: #fff; font-weight: 800; font-size: 2.6cqw; display: flex; align-items: center; justify-content: center; z-index: 3; box-shadow: 0 1px 3px rgba(0,0,0,.5); }
.coord { position: absolute; font-size: 1.6cqw; font-weight: 700; opacity: .8; }
.coord.rank { top: 3%; left: 4%; }
.coord.file { bottom: 2%; right: 5%; }
.sq.light .coord { color: var(--dark); }
.sq.dark .coord { color: var(--light); }

.evalbar { position: relative; width: 26px; background: #403d39; border-radius: 4px; overflow: hidden; }
.evalbar #evalbar-white { position: absolute; bottom: 0; left: 0; right: 0; background: #fff; transition: height .25s; }
.evalbar.flipped #evalbar-white { top: 0; bottom: auto; }
.evalbar span { position: absolute; left: 0; right: 0; text-align: center; font-size: 10px; font-weight: 700; }
.evalbar span.on-white { bottom: 4px; color: #333; }
.evalbar span.on-black { top: 4px; color: #eee; }
.evalbar.flipped span.on-white { top: 4px; bottom: auto; }
.evalbar.flipped span.on-black { bottom: 4px; top: auto; }

.player-tag { padding: 6px 0 6px 34px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 40px; }
.player-tag .who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clock { font-variant-numeric: tabular-nums; font-size: 18px; font-weight: 700; background: #262421; color: var(--muted); border-radius: 4px; padding: 3px 10px; }
.clock.active { background: #e8e6e3; color: #262421; }
.clock.low.active { background: #fa412d; color: #fff; }
.mv small.spent { color: var(--muted); font-weight: 400; font-size: 11px; margin-left: 6px; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 2px; margin-right: 8px; vertical-align: -1px; }
.dot.white { background: #fff; }
.dot.black { background: #000; border: 1px solid #666; }
.controls { display: flex; gap: 6px; padding-left: 34px; flex-wrap: wrap; }
.controls .btn { min-width: 52px; }

.summary .acc-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; text-align: center; margin-bottom: 8px; }
.acc-label { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-big { font-size: 26px; font-weight: 800; background: #1e1c1a; border-radius: 6px; margin: 4px 20px; padding: 2px 0; }
.counts { width: 100%; border-collapse: collapse; font-size: 14px; }
.counts td { padding: 3px 4px; }
.counts .cw, .counts .cb { width: 40px; text-align: center; font-weight: 700; }
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 26px; border-radius: 50%; color: #fff; font-weight: 800; font-size: 13px; padding: 0 4px; }
.badge.sm { min-width: 20px; height: 20px; font-size: 11px; }

.coach { border-left: 4px solid transparent; }
.coach-head { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; font-size: 16px; }
.coach p { margin: 0; color: var(--text); }

.graph { width: 100%; height: 110px; display: block; border-radius: 4px; cursor: pointer; }

.moves-card { max-height: 300px; overflow-y: auto; padding: 8px; }
.mrow { display: grid; grid-template-columns: 38px 1fr 1fr; padding: 1px 0; }
.mrow:nth-child(odd) { background: #2b2926; }
.mnum { color: var(--muted); padding: 3px 6px; }
.mv { padding: 3px 6px; border-radius: 4px; cursor: pointer; font-weight: 600; }
.mv:hover { background: var(--panel-2); }
.mv.current { background: #4b4847; }
.mv i { font-style: normal; font-weight: 800; margin-right: 4px; font-size: 12px; }

.progress { height: 10px; background: #1e1c1a; border-radius: 99px; overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .4s; }

/* ---------------------------------------------------------- variantes */
.board .sq { cursor: pointer; }
.sq.sel::before { content: ""; position: absolute; inset: 0; background: #f6f669; opacity: 0.55; }
.sq .mdot { position: absolute; width: 28%; height: 28%; border-radius: 50%; background: rgba(0,0,0,.3); z-index: 2; pointer-events: none; }
.sq .mcap { position: absolute; inset: 3%; border-radius: 50%; border: 0.9cqw solid rgba(0,0,0,.3); z-index: 2; pointer-events: none; }
.varbar { border-left: 4px solid #4a8fd9; }
.varbar-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.var-line { line-height: 2; }
.var-mv { padding: 3px 6px; border-radius: 4px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.var-mv:hover { background: var(--panel-2); }
.var-mv.current { background: #4b4847; }
.var-mv i { font-style: normal; font-weight: 800; margin-right: 3px; font-size: 12px; }
.legend { margin-top: 8px; font-size: 12px; color: var(--muted); }
.arrow-key { display: inline-block; width: 14px; height: 6px; border-radius: 3px; margin: 0 4px 1px 6px; vertical-align: middle; }
.legend .arrow-key:first-child { margin-left: 0; }
.coach .reply { margin: 8px 0 4px; }
.coach .reply .arrow-key { margin-left: 0; }

/* ---------------------------------------------------------- glisser / promotion */
.pc.ghost { position: absolute; width: 12.5%; height: 12.5%; z-index: 20; pointer-events: none; transform: scale(1.12); }
.pc.drag-src { opacity: .3; }
.promo-overlay { position: absolute; inset: 0; z-index: 30; background: rgba(0,0,0,.35); container-type: size; }
.promo { position: absolute; width: 12.5%; display: flex; flex-direction: column; background: #fff; border-radius: 4px; box-shadow: 0 4px 16px rgba(0,0,0,.5); overflow: hidden; }
.promo button { aspect-ratio: 1; border: 0; background: #f0f0f0; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }
.promo button:hover { background: #ffd970; }

/* ---------------------------------------------------------- tablette / téléphone */
@media (max-width: 1200px) {
  .review-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "board board" "left side"; }
  .board-col { max-width: 760px; width: 100%; margin: 0 auto; }
  .board-wrap { max-width: none; }
}
@media (max-width: 760px) {
  .topbar { padding: 8px 12px; }
  .topbar .muted { display: none; }
  .container { margin: 12px auto; padding: 0 10px; }
  .review { margin: 8px auto; padding: 0 6px; }
  .review-grid { grid-template-columns: minmax(0, 1fr); grid-template-areas: "board" "left" "side"; gap: 10px; }
  .card { padding: 12px; margin-bottom: 10px; }
  .board-row { gap: 4px; }
  .evalbar { width: 14px; }
  .evalbar span { font-size: 0; }
  .player-tag { padding: 4px 0 4px 18px; font-size: 14px; }
  .controls { padding-left: 18px; gap: 4px; flex-wrap: nowrap; margin-top: 4px; }
  .controls .btn { flex: 1; min-width: 0; padding: 10px 0; }
  .acc-big { font-size: 22px; margin: 4px 8px; }
  .moves-card { max-height: 240px; }
  .games th, .games td { padding: 6px 4px; font-size: 13px; }
  .hide-sm { display: none; }
  .games thead { display: none; }
  .games, .games tbody { display: block; }
  .games tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; padding: 10px 0; border-top: 1px solid #3a3835; align-items: center; }
  .games td { border: 0; padding: 0; }
  .games td.pw::before { content: "○ "; }
  .games td.pb::before { content: "● "; }
  .games td.res { grid-column: 2; grid-row: 1; font-weight: 700; }
  .games td.pb { grid-column: 1; grid-row: 2; }
  .games td.acc { grid-column: 2; grid-row: 2; text-align: right; }
  .games td.status { grid-column: 1; }
  .login-card { margin: 40px auto; }
}

/* ---------------------------------------------------------- accueil par joueur */
.player-nav { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip { background: var(--panel); color: var(--text); text-decoration: none; border-radius: 99px; padding: 6px 14px; font-weight: 600; }
.chip:hover { background: var(--panel-2); }
.player-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.player-head h2 { margin: 0; }

.player-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.btn-danger { background: #5a1f1a; color: #ffd2cc; }
.outcome { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; font-weight: 800; font-size: 13px; color: #fff; margin-right: 4px; vertical-align: middle; }
.outcome.win { background: #81b64c; }
.outcome.loss { background: #fa412d; }
.outcome.draw { background: #77736e; }

/* ---------------------------------------------------------- compteurs cliquables */
.count-btn { background: transparent; border: 0; color: var(--text); font: inherit; font-weight: 700; cursor: pointer; border-radius: 6px; padding: 2px 8px; min-width: 32px; }
.count-btn:hover { background: var(--panel-2); }
.count-btn.active { background: #4b4847; outline: 1px solid var(--muted); }
.counts td.zero { color: var(--muted); }
.count-label { background: transparent; border: 0; color: var(--text); font: inherit; cursor: pointer; border-radius: 6px; padding: 2px 6px; text-align: left; display: inline-flex; align-items: center; gap: 6px; width: 100%; }
.count-label:hover { background: var(--panel-2); }
.count-label.active { background: #4b4847; }
.count-label.off { cursor: default; color: var(--muted); }

/* ---------------------------------------------------------- rejouer mes erreurs */
.train-btn { width: 100%; margin-bottom: 16px; padding: 12px; font-size: 15px; }
.train-count { background: rgba(0,0,0,.25); border-radius: 99px; padding: 1px 8px; margin-left: 6px; font-size: 13px; }
.train-progress { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 6px; }
.train-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

/* ---------------------------------------------------------- comptes */
.notif { background: var(--danger); color: #fff; border-radius: 99px; padding: 0 7px; font-size: 12px; margin-left: 4px; }
textarea { display: block; width: 100%; margin-top: 4px; padding: 9px 10px; border-radius: 6px; border: 1px solid #555; background: #1e1c1a; color: var(--text); font: inherit; resize: vertical; }
table.users { width: 100%; border-collapse: collapse; }
.users th { text-align: left; font-size: 12px; text-transform: uppercase; color: var(--muted); padding: 6px 8px; }
.users td { padding: 8px; border-top: 1px solid #3a3835; vertical-align: top; }
.users td.note { max-width: 360px; white-space: pre-wrap; word-break: break-word; }
.users td.actions { white-space: nowrap; text-align: right; }
.users td.actions form { margin-left: 4px; }
.added-by { font-size: 11px; color: var(--muted); }
.quota-full { color: var(--danger); }
.topbar-right a.btn { text-decoration: none; }

/* ---------------------------------------------------------- ouverture */
.opening { cursor: pointer; font-size: 13px; padding: 6px 4px 10px; border-bottom: 1px solid #3a3835; margin-bottom: 6px; }
.opening:empty { display: none; }
.opening:hover { color: #fff; }
.opening .eco { font-weight: 800; color: #c9a77c; margin: 0 4px; }

/* connexion SSO */
.btn-block { display: block; width: 100%; text-align: center; box-sizing: border-box; }
.local-login { margin-top: 1rem; }
.local-login summary { cursor: pointer; margin-bottom: .6rem; }
