/* ==========================================================================
   Chess Trainer — feuille de style commune
   ========================================================================== */

:root {
  --bg: #f5f4f1;
  --bg-elevated: #ffffff;
  --bg-inset: #ececea;
  --text: #1c1b1a;
  --text-muted: #6b6862;
  --border: #ddd9d2;
  --accent: #2f6f4f;
  --accent-hover: #245c40;
  --accent-contrast: #ffffff;
  --danger: #b1433a;
  --warning: #b3831b;
  --info: #2f6f9e;
  --board-light: #eef0e2;
  --board-dark: #6f8f5b;
  --board-highlight: #f6f27a;
  --board-lastmove: #f4e07a;
  --board-check: #d95d4a;
  --board-move-dot: rgba(30, 30, 30, 0.28);
  --shadow: 0 1px 2px rgba(20, 20, 15, 0.06), 0 6px 20px rgba(20, 20, 15, 0.06);
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181b;
    --bg-elevated: #1e2125;
    --bg-inset: #24272c;
    --text: #eceae5;
    --text-muted: #9a978f;
    --border: #33363b;
    --accent: #4caf7d;
    --accent-hover: #62c091;
    --accent-contrast: #0c1210;
    --danger: #e0685a;
    --warning: #e0b04a;
    --info: #6bb0e6;
    --board-light: #d9d5c9;
    --board-dark: #4a6741;
    --board-highlight: #d7cf5a;
    --board-lastmove: #b7a53f;
    --board-check: #d95d4a;
    --board-move-dot: rgba(255, 255, 255, 0.35);
  }
}

:root[data-theme="dark"] {
  --bg: #16181b;
  --bg-elevated: #1e2125;
  --bg-inset: #24272c;
  --text: #eceae5;
  --text-muted: #9a978f;
  --border: #33363b;
  --accent: #4caf7d;
  --accent-hover: #62c091;
  --accent-contrast: #0c1210;
  --danger: #e0685a;
  --warning: #e0b04a;
  --info: #6bb0e6;
  --board-light: #d9d5c9;
  --board-dark: #4a6741;
  --board-highlight: #d7cf5a;
  --board-lastmove: #b7a53f;
  --board-check: #d95d4a;
  --board-move-dot: rgba(255, 255, 255, 0.35);
}

* { box-sizing: border-box; }

html {
  scroll-padding-top: 4.5rem; /* évite que l'en-tête collant ne recouvre un élément amené en vue */
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--accent); }

.app-header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.25rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.app-header .brand {
  font-weight: 700;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}

.app-nav {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  flex: 1;
}

.app-nav a {
  text-decoration: none;
  color: var(--text-muted);
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.92rem;
}

.app-nav a:hover { background: var(--bg-inset); color: var(--text); }
.app-nav a.active { background: var(--accent); color: var(--accent-contrast); }

.theme-toggle {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  width: 2.1rem;
  height: 2.1rem;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

main.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

h1, h2, h3 { line-height: 1.25; }
h1 { font-size: 1.6rem; margin: 0 0 0.35rem; }
h2 { font-size: 1.2rem; margin: 0 0 0.5rem; }
.page-lede { color: var(--text-muted); margin: 0 0 1.5rem; max-width: 62ch; }

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.2rem;
}

.grid {
  display: grid;
  gap: 1.25rem;
}

.layout-board {
  display: grid;
  grid-template-columns: minmax(280px, 560px) 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 860px) {
  .layout-board { grid-template-columns: 1fr; }
}

/* Boutons ------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid var(--border);
  background: var(--bg-inset);
  color: var(--text);
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.2;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.82rem; }
.btn-group { display: flex; gap: 0.4rem; flex-wrap: wrap; }

select, input[type="text"], input[type="search"], textarea {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.6rem;
  font-size: 0.9rem;
  font-family: var(--font);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  background: var(--bg-inset);
  color: var(--text-muted);
}
.badge-accent { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.badge-danger { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.badge-info { background: color-mix(in srgb, var(--info) 18%, transparent); color: var(--info); }

.status-line {
  min-height: 1.4rem;
  font-weight: 600;
}
.status-ok { color: var(--accent); }
.status-error { color: var(--danger); }
.status-info { color: var(--info); }

/* Échiquier ------------------------------------------------------------ */

.board-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: 100%;
}

.board-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 560px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  user-select: none;
  touch-action: none;
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: min(6.4vw, 42px);
}

.sq-light { background: var(--board-light); }
.sq-dark { background: var(--board-dark); }
.sq.is-selected::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--board-highlight);
  opacity: 0.65;
}
.sq.is-lastmove::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--board-lastmove);
  opacity: 0.55;
}
.sq.is-check::after {
  content: "";
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  background: radial-gradient(circle, var(--board-check) 0%, rgba(217, 93, 74, 0) 72%);
}
.sq .move-dot {
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: var(--board-move-dot);
  pointer-events: none;
}
.sq .capture-ring {
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  border: 5px solid var(--board-move-dot);
  pointer-events: none;
}
.sq .piece {
  position: relative;
  z-index: 3;
  cursor: grab;
  line-height: 1;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.35));
}
.sq .piece.piece-white { color: #f7f5ef; -webkit-text-stroke: 1px #2a2a26; }
.sq .piece.piece-black { color: #17181a; -webkit-text-stroke: 1px #17181a; }
.sq .piece.dragging { opacity: 0.35; }
.board-frame.not-interactive .piece { cursor: default; }

.coord-file, .coord-rank {
  position: absolute;
  font-size: 0.62rem;
  font-weight: 700;
  opacity: 0.55;
  pointer-events: none;
  z-index: 4;
}
.coord-rank { top: 2px; left: 3px; }
.coord-file { bottom: 2px; right: 4px; }

.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 50;
  font-size: 42px;
  transform: translate(-50%, -50%);
}

.board-arrows {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.promo-picker {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 10, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
}
.promo-choices {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 0.6rem;
  display: flex;
  gap: 0.4rem;
  box-shadow: var(--shadow);
}
.promo-choices button {
  font-size: 2rem;
  width: 3.2rem;
  height: 3.2rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-inset);
  cursor: pointer;
}
.promo-choices button:hover { border-color: var(--accent); }

.board-controls {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
}

/* Barre d'évaluation ----------------------------------------------------- */

.eval-bar-wrap {
  display: flex;
  align-items: stretch;
  gap: 0.6rem;
}
.eval-bar {
  width: 26px;
  border-radius: 6px;
  overflow: hidden;
  background: #1a1a1a;
  position: relative;
  border: 1px solid var(--border);
}
.eval-bar .eval-white {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: #f2f0ea;
  transition: height 0.25s ease;
}
.eval-bar .eval-label {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 0;
}

.move-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.4rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.86rem;
  max-height: 180px;
  overflow-y: auto;
  padding: 0.4rem;
  background: var(--bg-inset);
  border-radius: var(--radius-sm);
}
.move-list .mv {
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
  cursor: pointer;
}
.move-list .mv:hover { background: var(--border); }
.move-list .mv.current { background: var(--accent); color: var(--accent-contrast); }
.move-list .mvnum { color: var(--text-muted); margin-left: 0.4rem; }

.move-list .mv.cls-exc::after,
.move-list .mv.cls-good::after,
.move-list .mv.cls-inacc::after,
.move-list .mv.cls-mistake::after,
.move-list .mv.cls-blunder::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-left: 0.3rem;
  vertical-align: middle;
}
.move-list .mv.cls-exc::after { background: var(--accent); }
.move-list .mv.cls-good::after { background: var(--info); }
.move-list .mv.cls-inacc::after { background: var(--warning); }
.move-list .mv.cls-mistake::after { background: var(--warning); box-shadow: 0 0 0 2px color-mix(in srgb, var(--warning) 30%, transparent); }
.move-list .mv.cls-blunder::after { background: var(--danger); }

.report-stat-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; padding: 0.15rem 0; }
.report-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.report-dot.exc { background: var(--accent); }
.report-dot.good { background: var(--info); }
.report-dot.inacc, .report-dot.mistake { background: var(--warning); }
.report-dot.blunder { background: var(--danger); }

.pill-group { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.pill {
  border: 1px solid var(--border);
  background: var(--bg-inset);
  color: var(--text);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.pill.active { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }

.explain-box {
  border-left: 3px solid var(--info);
  background: color-mix(in srgb, var(--info) 8%, var(--bg-elevated));
  padding: 0.7rem 0.9rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.92rem;
}
.explain-box.bad { border-left-color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--bg-elevated)); }
.explain-box.good { border-left-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--bg-elevated)); }

table.simple { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.simple th, table.simple td { text-align: left; padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--border); }
table.simple th { color: var(--text-muted); font-weight: 700; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
table.simple tr:hover td { background: var(--bg-inset); cursor: pointer; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0.75rem; }
.stat-tile { background: var(--bg-inset); border-radius: var(--radius-sm); padding: 0.7rem 0.85rem; }
.stat-tile .num { font-size: 1.5rem; font-weight: 800; }
.stat-tile .lbl { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; }

.spinner { display: inline-block; width: 1em; height: 1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.footer-note { margin-top: 2.5rem; color: var(--text-muted); font-size: 0.8rem; text-align: center; }

.hidden { display: none !important; }
