/* ------------------------------------------------------------------ base */
:root {
  --bg: #0f1115;
  --bg-2: #161920;
  --bg-3: #1d2129;
  --line: #2a2f3a;
  --txt: #e7e9ee;
  --txt-dim: #97a0b0;
  --accent: #6ea8fe;
  --accent-2: #8b5cf6;
  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --light-sq: #ebecd0;
  --dark-sq: #6f8f5a;
  --sel: rgba(255, 214, 0, .45);
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: dark;
}
body.theme-light {
  --bg: #f5f6f8;
  --bg-2: #ffffff;
  --bg-3: #eef0f4;
  --line: #d9dee6;
  --txt: #171a20;
  --txt-dim: #5d6675;
  --shadow: 0 6px 24px rgba(20,25,40,.10);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--txt);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: .95rem; }
.boot { padding: 3rem; text-align: center; color: var(--txt-dim); }

/* ------------------------------------------------------------------ layout */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem 1rem; background: var(--bg-2);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30;
  padding-top: max(.6rem, env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; letter-spacing: .2px; }
.brand svg { width: 26px; height: 26px; }
.nav { display: flex; gap: .25rem; margin-left: auto; align-items: center; }
.nav a {
  padding: .45rem .7rem; border-radius: 10px; color: var(--txt-dim);
  font-size: .9rem; font-weight: 600;
}
.nav a.active, .nav a:hover { background: var(--bg-3); color: var(--txt); }
.main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 1rem; padding-bottom: 4rem; }
.mobile-nav { display: none; }

@media (max-width: 780px) {
  .nav .label { display: none; }
  .main { padding: .75rem; padding-bottom: 5.5rem; }
  .mobile-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
    background: var(--bg-2); border-top: 1px solid var(--line);
    padding: .35rem .35rem calc(.35rem + env(safe-area-inset-bottom));
  }
  .mobile-nav a {
    flex: 1; text-align: center; padding: .45rem 0; border-radius: 10px;
    color: var(--txt-dim); font-size: .68rem; font-weight: 600;
  }
  .mobile-nav a.active { color: var(--accent); background: var(--bg-3); }
  .mobile-nav .ico { display: block; font-size: 1.15rem; line-height: 1.3; }
}

/* ------------------------------------------------------------------ cartes */
.card {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem;
}
.card + .card { margin-top: .75rem; }
.grid { display: grid; gap: .75rem; }
.grid.cols { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.muted { color: var(--txt-dim); }
.small { font-size: .82rem; }
.tiny { font-size: .74rem; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.stack > * + * { margin-top: .6rem; }

/* ------------------------------------------------------------------ boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .55rem .9rem; border-radius: 11px; border: 1px solid var(--line);
  background: var(--bg-3); cursor: pointer; font-weight: 600; font-size: .9rem;
  transition: filter .15s, transform .05s; white-space: nowrap; text-decoration: none;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: transparent; color: #0b1020; }
.btn.ok { background: var(--ok); border-color: transparent; color: #06210f; }
.btn.bad { background: var(--bad); border-color: transparent; color: #2a0a0a; }
.btn.ghost { background: transparent; }
.btn.sm { padding: .32rem .6rem; font-size: .8rem; border-radius: 9px; }
.btn.block { width: 100%; }
.btn-group { display: flex; gap: .4rem; flex-wrap: wrap; }

input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: .6rem .7rem; border-radius: 11px;
  border: 1px solid var(--line); background: var(--bg-3); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 130px; resize: vertical; font-family: ui-monospace, Menlo, monospace; font-size: .82rem; }
label.field { display: block; }
label.field span { display: block; font-size: .8rem; color: var(--txt-dim); margin-bottom: .25rem; }

.badge {
  display: inline-flex; align-items: center; gap: .3rem; padding: .12rem .5rem;
  border-radius: 999px; font-size: .72rem; font-weight: 700;
  background: var(--bg-3); border: 1px solid var(--line);
}
.badge.white { background: #f2f3f5; color: #14161a; border-color: #f2f3f5; }
.badge.black { background: #262a33; color: #d7dbe4; }
.badge.due { background: rgba(251,191,36,.16); color: var(--warn); border-color: transparent; }
.badge.new { background: rgba(110,168,254,.16); color: var(--accent); border-color: transparent; }
.badge.ok { background: rgba(74,222,128,.16); color: var(--ok); border-color: transparent; }

.pill-row { display: flex; gap: .35rem; flex-wrap: wrap; }
.pill {
  padding: .35rem .7rem; border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg-3); cursor: pointer; font-size: .82rem; font-weight: 600;
}
.pill.active { background: var(--accent); color: #0b1020; border-color: transparent; }

.progress { height: 8px; border-radius: 99px; background: var(--bg-3); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); transition: width .3s; }

/* ------------------------------------------------------------------ échiquier */
.board-wrap { width: 100%; max-width: min(560px, 92vw); margin: 0 auto; }
.board {
  position: relative; width: 100%; aspect-ratio: 1/1; border-radius: 10px;
  overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
  box-shadow: var(--shadow);
}
.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(--light-sq); }
.sq.dark { background: var(--dark-sq); }
.sq .coord { position: absolute; font-size: .58rem; font-weight: 700; opacity: .55; }
.sq .coord.file { right: 2px; bottom: 0px; }
.sq .coord.rank { left: 2px; top: 0px; }
.sq.light .coord { color: var(--dark-sq); }
.sq.dark .coord { color: var(--light-sq); }
.sq.last { box-shadow: inset 0 0 0 100px rgba(255, 214, 0, .22); }
.sq.sel  { box-shadow: inset 0 0 0 100px var(--sel); }
.sq.check { background: radial-gradient(circle, #ff5252 12%, transparent 70%), var(--dark-sq); }
.sq.hint::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 26%; height: 26%; border-radius: 50%; background: rgba(20,20,20,.32);
}
.sq.hint.capture::after {
  width: 92%; height: 92%; background: transparent; border-radius: 50%;
  border: 6px solid rgba(20,20,20,.28);
}
.board .pieces { position: absolute; inset: 0; }
.piece {
  position: absolute; width: 12.5%; height: 12.5%; will-change: transform;
  transition: transform .16s ease-out; cursor: grab; z-index: 2;
}
.piece.dragging { transition: none; z-index: 10; cursor: grabbing; filter: drop-shadow(0 6px 8px rgba(0,0,0,.4)); }
.piece svg { width: 100%; height: 100%; display: block; pointer-events: none; }
.board.shake { animation: shake .34s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-7px); } 40% { transform: translateX(7px); }
  60% { transform: translateX(-4px); } 80% { transform: translateX(4px); }
}
.promo {
  position: absolute; inset: 0; background: rgba(8,10,14,.72); z-index: 20;
  display: flex; align-items: center; justify-content: center; gap: .35rem;
}
.promo button {
  width: 15%; aspect-ratio: 1; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 12px; cursor: pointer; padding: 4px;
}
.promo button:hover { border-color: var(--accent); }

/* ------------------------------------------------------------------ arbre */
.tree { max-height: 62vh; overflow: auto; font-size: .88rem; }
.tree-line { display: flex; align-items: center; gap: .3rem; padding: .1rem 0; }
.tree-move {
  padding: .13rem .42rem; border-radius: 7px; cursor: pointer; font-weight: 600;
  border: 1px solid transparent; white-space: nowrap;
}
.tree-move:hover { background: var(--bg-3); }
.tree-move.current { background: var(--accent); color: #0b1020; }
.tree-move.own { border-color: rgba(110,168,254,.35); }
.tree-move.disabled { opacity: .4; text-decoration: line-through; }
.tree-branch { border-left: 1px solid var(--line); margin-left: .55rem; padding-left: .55rem; }
.tree-comment { color: var(--txt-dim); font-size: .78rem; font-style: italic; }
.sec-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.moves-strip { display: flex; flex-wrap: wrap; gap: .25rem; font-size: .85rem; }
.moves-strip b { font-weight: 700; color: var(--txt-dim); }

/* ------------------------------------------------------------------ entraînement */
.train-layout { display: grid; gap: 1rem; grid-template-columns: minmax(0,1fr) 320px; align-items: start; }
@media (max-width: 900px) { .train-layout { grid-template-columns: 1fr; } }
.editor-layout { display: grid; gap: 1rem; grid-template-columns: minmax(0,1fr) 380px; align-items: start; }
@media (max-width: 980px) { .editor-layout { grid-template-columns: 1fr; } }

.feedback { min-height: 2.2rem; font-weight: 700; display: flex; align-items: center; gap: .4rem; }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }
.kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px,1fr)); gap: .5rem; }
.kpi > div {
  background: var(--bg-3); border-radius: 12px; padding: .55rem; text-align: center;
}
.kpi b { display: block; font-size: 1.25rem; line-height: 1.3; }
.kpi span { font-size: .7rem; color: var(--txt-dim); }

/* ------------------------------------------------------------------ modales */
.overlay {
  position: fixed; inset: 0; background: rgba(6,8,12,.6); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
  backdrop-filter: blur(3px);
}
.modal {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem; width: min(560px, 100%); max-height: 88vh; overflow: auto;
  box-shadow: var(--shadow);
}

.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 5rem; z-index: 90;
  display: flex; flex-direction: column; gap: .4rem; align-items: center; pointer-events: none; }
.toast {
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 10px;
  padding: .5rem .85rem; font-size: .86rem; box-shadow: var(--shadow); max-width: 92vw;
}
.toast.bad { border-color: var(--bad); color: var(--bad); }
.toast.ok { border-color: var(--ok); color: var(--ok); }

/* ------------------------------------------------------------------ auth */
.auth-wrap { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.auth-card { width: min(420px, 100%); }

/* ------------------------------------------------------------------ graphiques */
.chart { width: 100%; height: 150px; display: block; }
.chart .bar { fill: var(--accent); }
.chart .bar.ok { fill: var(--ok); }
.legend { display: flex; gap: .8rem; font-size: .74rem; color: var(--txt-dim); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .25rem; }

table.tbl { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.tbl th { text-align: left; color: var(--txt-dim); font-weight: 600; font-size: .76rem; padding: .35rem .4rem; }
table.tbl td { padding: .4rem; border-top: 1px solid var(--line); }
