:root {
  --bg: #16191f;
  --panel: #21252e;
  --panel-2: #1b1e25;
  --line: #3a404e;
  --text: #eef0f4;
  --muted: #969eae;
  --dim: #78808e;
  --accent: #3ca046;
  --spot: #ffd60a;
  --light: #f0d9b5;
  --dark: #b58863;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  display: flex;
  flex-direction: column;
}
button, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* --- Barre du haut -------------------------------------------------------------------- */
.topbar {
  height: 48px; flex: none;
  display: flex; align-items: center; gap: 18px;
  padding: 0 20px;
  border-bottom: 1px solid #262a33;
}
.brand { color: var(--text); text-decoration: none; font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.topbar-title { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- Bibliothèque --------------------------------------------------------------------- */
.library { max-width: 1100px; width: 100%; margin: 0 auto; padding: 32px 16px 64px; overflow: auto; }
.library h1 { margin: 0 0 6px; font-size: 30px; }
.lib-sub { color: var(--muted); margin: 0 0 26px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card {
  display: flex; flex-direction: column; gap: 8px;
  background: var(--panel); border: 1px solid #2c313c; border-radius: 14px;
  padding: 18px; color: var(--text); text-decoration: none;
  transition: transform .15s ease, border-color .15s ease;
}
.card:hover { transform: translateY(-2px); border-color: #4a5262; }
.card .c-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card .c-date { color: var(--muted); font-size: 14px; }
.card .c-out { font-size: 13px; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.c-out.win { background: rgba(60,160,70,.18); color: #7fd38a; }
.c-out.loss { background: rgba(205,55,50,.18); color: #f08a85; }
.c-out.draw { background: rgba(150,158,174,.18); color: var(--muted); }
.card h2 { margin: 2px 0 0; font-size: 21px; }
.card .c-sub { color: var(--muted); font-size: 14px; }
.card .c-theme { align-self: flex-start; background: var(--accent); color: #fff; font-weight: 700; font-size: 13px; padding: 4px 12px; border-radius: 999px; }
.card .c-meta { color: var(--dim); font-size: 13px; margin-top: auto; }

/* --- Lecteur -------------------------------------------------------------------------- */
.player { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.stage-wrap { flex: 1; min-height: 0; padding: 16px 20px 10px; }
.stage { position: relative; height: 100%; max-width: 1700px; margin: 0 auto; }
.stage.fade { animation: fade .35s ease; }
@keyframes fade { from { opacity: .15; } to { opacity: 1; } }
.scene { height: 100%; }

/* Échiquier + panneau */
.scene-board { display: flex; gap: 24px; }
.board-area { height: 100%; display: flex; gap: 10px; flex: none; }
.evalbar { position: relative; width: 22px; height: 100%; background: #403d3a; border-radius: 4px; overflow: hidden; flex: none; }
.evalfill { position: absolute; left: 0; right: 0; background: #f2f2f2; transition: height .35s ease, top .35s ease, bottom .35s ease; }
.evalbar::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 2px; background: #c83c3c; }
.evallabel { position: absolute; left: 0; right: 0; text-align: center; font-size: 10px; font-weight: 700; }
.board { height: 100%; aspect-ratio: 1; display: block; border-radius: 4px; }

.panel {
  flex: 1; min-width: 300px; min-height: 0;
  background: var(--panel); border-radius: 18px;
  padding: clamp(18px, 2.4vw, 36px);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.p-head { display: flex; align-items: center; gap: 12px; color: var(--muted); font-weight: 600; font-size: 14px; text-transform: uppercase; letter-spacing: .3px; }
.chip { background: var(--accent); color: #fff; border-radius: 999px; padding: 2px 12px; font-weight: 700; text-transform: none; }
.chip:empty { display: none; }
.p-title { margin: 10px 0 8px; font-size: clamp(22px, 2.3vw, 38px); line-height: 1.2; }
.p-move { display: flex; align-items: center; gap: 2px; font-size: clamp(26px, 2.8vw, 46px); font-weight: 700; min-height: 1.3em; }
.nag { margin-right: 14px; }
.badge { font-size: 14px; font-weight: 700; color: #fff; padding: 4px 14px; border-radius: 999px; letter-spacing: .4px; }
.badge:empty { display: none; }
.p-eval { color: var(--muted); font-weight: 600; font-size: clamp(14px, 1.3vw, 20px); padding-bottom: 14px; border-bottom: 2px solid var(--line); margin-bottom: 18px; min-height: 1.4em; }
.bullets { list-style: none; margin: 0; padding: 0; flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-start; gap: 12px; }
.bullets li { position: relative; padding-left: 26px; font-size: clamp(15px, 1.45vw, 24px); line-height: 1.35; color: #7c8493; transition: color .3s; }
.bullets li::before { content: ""; position: absolute; left: 0; top: .5em; width: 11px; height: 11px; border-radius: 3px; background: var(--line); }
.bullets li.cur { color: var(--text); }
.bullets li.cur::before { background: var(--accent); }
.bullets li.new { animation: pop-in .45s ease; }
@keyframes pop-in { from { opacity: 0; transform: translateX(18px); } to { opacity: 1; transform: none; } }
.p-bottom { border-top: 2px solid var(--line); padding-top: 14px; margin-top: 12px; }
.moves { display: flex; flex-wrap: wrap; gap: 6px 12px; font-weight: 600; color: var(--muted); font-size: clamp(14px, 1.3vw, 20px); }
.moves .hl { color: #fff; border-radius: 7px; padding: 0 8px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 22px; margin-top: 12px; color: var(--muted); font-size: 14px; font-weight: 600; }
.legend:empty { display: none; }
.legend span::before { content: ""; display: inline-block; width: 14px; height: 14px; border-radius: 4px; margin-right: 8px; vertical-align: -2px; background: var(--c); }

/* Courbe */
.scene-graph { display: flex; flex-direction: column; }
.g-title { margin: 0 0 4px; font-size: clamp(22px, 2.6vw, 40px); }
.graph { flex: 1; min-height: 0; width: 100%; }
.g-caption { text-align: center; margin: 6px 0 0; font-size: clamp(15px, 1.6vw, 26px); }
.mk { opacity: 0; transform: scale(.4); transform-box: fill-box; transform-origin: center; transition: opacity .25s ease, transform .4s cubic-bezier(.3, 1.7, .5, 1); }
.mk.on { opacity: 1; transform: none; }

/* Titre */
.scene-title { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 18px; }
.t-tag { color: var(--muted); font-weight: 600; letter-spacing: 1px; text-transform: uppercase; font-size: 15px; }
.t-title { margin: 0; font-size: clamp(36px, 6vw, 92px); line-height: 1.1; }
.t-line { width: 120px; height: 8px; border-radius: 4px; background: var(--accent); }
.t-sub { color: var(--muted); font-size: clamp(16px, 2.2vw, 34px); display: flex; flex-direction: column; gap: 6px; }
.scene-title.enter .t-tag { animation: rise .5s ease both; }
.scene-title.enter .t-title { animation: rise .7s .12s ease both; }
.scene-title.enter .t-line { animation: grow .6s .4s ease both; }
.scene-title.enter .t-sub { animation: rise .7s .5s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(28px); } to { opacity: 1; transform: none; } }
@keyframes grow { from { transform: scaleX(0); } to { transform: none; } }

/* Leçons */
.scene-lessons { display: flex; flex-direction: column; justify-content: center; max-width: 1300px; margin: 0 auto; }
.l-title { font-size: clamp(26px, 3.4vw, 56px); margin: 0 0 26px; }
.l-items { list-style: none; counter-reset: l; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 18px; }
.l-items li { counter-increment: l; display: flex; gap: 22px; align-items: center; background: var(--panel-2); color: var(--muted); border-radius: 18px; padding: 22px 28px; font-size: clamp(16px, 2vw, 32px); transition: background .35s, color .35s; }
.l-items li::before { content: counter(l); flex: none; display: grid; place-items: center; width: 1.9em; height: 1.9em; border-radius: 50%; background: var(--line); color: #fff; font-weight: 700; transition: background .35s; }
.l-items li.on { background: var(--panel); color: var(--text); }
.l-items li.on::before { background: var(--accent); }

/* Sous-titres, bouton central */
.caption { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); max-width: 90%; background: rgba(0,0,0,.78); padding: 8px 16px; border-radius: 8px; font-size: clamp(15px, 1.5vw, 22px); text-align: center; pointer-events: none; }
.bigplay {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 108px; height: 108px; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(60,160,70,.94); color: #fff; font-size: 44px; padding-left: 8px;
  box-shadow: 0 10px 40px rgba(0,0,0,.45);
}
.bigplay:hover { background: #48b453; }

/* --- Contrôles ------------------------------------------------------------------------ */
.controls { flex: none; display: flex; align-items: center; gap: 10px; padding: 10px 20px 14px; border-top: 1px solid #262a33; }
.controls button, .controls select {
  background: var(--panel); border: 1px solid #2f3440; border-radius: 10px; height: 40px; min-width: 44px; padding: 0 12px; cursor: pointer;
}
.controls button:hover { border-color: #4a5262; }
.controls button.on { background: var(--accent); border-color: var(--accent); }
.controls .play { min-width: 56px; font-size: 18px; }
.timeline { position: relative; flex: 1; height: 10px; background: #2a2f39; border-radius: 6px; cursor: pointer; }
.tl-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 6px; width: 0; }
.tl-tick { position: absolute; top: -3px; width: 2px; height: 16px; background: #5a6272; }
.time { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 96px; text-align: right; }

/* Chapitres */
.chapters { position: fixed; right: 16px; bottom: 72px; width: min(380px, calc(100vw - 32px)); max-height: 60vh; overflow: auto; background: var(--panel); border: 1px solid #343a46; border-radius: 14px; padding: 14px 16px; box-shadow: 0 16px 50px rgba(0,0,0,.5); z-index: 5; }
.chapters h3 { margin: 0 0 8px; font-size: 16px; }
.chapters ol { list-style: none; margin: 0; padding: 0; }
.chapters li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.chapters li:hover { background: #2a2f39; }
.chapters li.on { color: var(--text); background: #2c3a2e; }
.chapters li span:last-child { font-variant-numeric: tabular-nums; }

/* --- Téléphone / écran étroit : échiquier au-dessus du panneau ------------------------ */
@media (max-width: 900px), (max-aspect-ratio: 1/1) {
  .topbar { gap: 12px; padding: 0 16px; }
  .topbar-title { font-size: 13px; }
  .stage-wrap { overflow: auto; padding: 12px 16px 8px; }
  .stage { height: auto; min-height: 100%; }
  .scene-board { flex-direction: column; gap: 14px; }
  .board-area { height: auto; width: 100%; }
  .evalbar { height: auto; }
  .board { height: auto; width: calc(100% - 32px); }
  .panel { min-width: 0; }
  .bullets { overflow: visible; }
  .scene-graph, .scene-title, .scene-lessons { min-height: 60vh; }
  .controls { flex-wrap: wrap; padding: 8px 12px 12px; }
  .timeline { order: -1; flex-basis: 100%; }
  .time { min-width: 0; }
}
