#chess3-trainer {
  --bg:#faf7f2; --panel:#fff; --ink:#2b2622; --muted:#7a7166;
  --dark-sq:#b98a5e; --light-sq:#f0dcc0; --line:#00000022;
  --sel:#4f8cff; --move:#3fae5c; --capture:#e2543c; --check:#e2543c;
  --white-fill:#ffffff; --white-stroke:#2b2622;
  --black-fill:#2b2622; --black-stroke:#2b2622;
  --red-fill:#c0392b; --red-stroke:#5c1a12;
  margin:0; background:var(--bg); color:var(--ink);
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;
  padding:16px; width:100%; box-sizing:border-box;
}
@media (prefers-color-scheme: dark){
  #chess3-trainer:not([data-theme="light"]){
    --bg:#1c1a17; --panel:#26221e; --ink:#f1ece4; --muted:#a89e90;
    --dark-sq:#7a5636; --light-sq:#c9ab7f; --line:#ffffff22;
  }
}
#chess3-trainer[data-theme="dark"]{
  --bg:#1c1a17; --panel:#26221e; --ink:#f1ece4; --muted:#a89e90;
  --dark-sq:#7a5636; --light-sq:#c9ab7f; --line:#ffffff22;
}
#chess3-trainer, #chess3-trainer *{box-sizing:border-box;}
#chess3-trainer .layout{display:flex;gap:20px;flex-wrap:wrap;justify-content:center;max-width:1100px;width:100%;margin:0 auto;}
#chess3-trainer .board-wrap{position:relative;width:min(560px,92vw);}
#chess3-trainer svg{width:100%;height:auto;overflow:visible;display:block;}
#chess3-trainer .cell{fill:transparent;stroke:none;cursor:pointer;}
#chess3-trainer .cell.selected{fill:var(--sel);opacity:.35;}
#chess3-trainer .dot{fill:var(--move);opacity:.75;pointer-events:none;}
#chess3-trainer .dot.capture{fill:none;stroke:var(--capture);stroke-width:5;opacity:.85;}
#chess3-trainer .cell.checked{fill:var(--check);opacity:.55;}
#chess3-trainer .piece{font-size:44px;pointer-events:none;text-anchor:middle;dominant-baseline:central;}
#chess3-trainer .side{width:280px;background:var(--panel);border-radius:12px;padding:16px;box-shadow:0 1px 4px #0002;}
#chess3-trainer .side h2{font-size:.95rem;margin:0 0 8px;color:var(--ink);}
#chess3-trainer .seat-row{display:flex;align-items:center;gap:8px;padding:6px 0;border-bottom:1px solid var(--line);font-size:.9rem;}
#chess3-trainer .seat-row .swatch{width:14px;height:14px;border-radius:3px;}
#chess3-trainer .seat-row.current{font-weight:700;}
#chess3-trainer .status{margin:10px 0;padding:10px;border-radius:8px;background:var(--bg);font-size:.9rem;line-height:1.4;min-height:2.4em;}
#chess3-trainer button{font:inherit;padding:8px 14px;border-radius:8px;border:1px solid var(--line);background:var(--bg);color:var(--ink);cursor:pointer;}
#chess3-trainer button:hover{filter:brightness(1.05);}
#chess3-trainer .log{max-height:180px;overflow-y:auto;font-size:.8rem;color:var(--muted);}
#chess3-trainer .log div{padding:2px 0;}
#chess3-trainer .promo{position:fixed;inset:0;background:#0006;display:flex;align-items:center;justify-content:center;z-index:99999;}
#chess3-trainer .promo-box{background:var(--panel);border-radius:12px;padding:16px;display:flex;gap:10px;flex-wrap:wrap;}
#chess3-trainer .promo-box button{width:56px;height:56px;display:flex;align-items:center;justify-content:center;padding:6px;}
#chess3-trainer .promo-box button img{display:block;width:40px;height:40px;}
@media (max-width:860px){
  #chess3-trainer{padding:10px;}
  #chess3-trainer .side{width:min(560px,92vw);}
}

#chess3-trainer .seat-row{flex-wrap:wrap;}
#chess3-trainer .seat-name{flex:1 1 auto;min-width:90px;}
#chess3-trainer .player-type,#chess3-trainer .ai-difficulty{font:inherit;font-size:.78rem;padding:4px 6px;border:1px solid var(--line);border-radius:6px;background:var(--bg);color:var(--ink);}
#chess3-trainer .ai-difficulty:disabled{opacity:.45;cursor:not-allowed;}
#chess3-trainer .status.thinking{font-weight:600;}
#chess3-trainer.ai-busy .board-wrap{cursor:wait;}
#chess3-trainer.ai-busy .cell{cursor:wait;}

/* Last-move visualization */
#chess3-trainer{
  --last-from:#f2b84b;
  --last-to:#69a85f;
  --last-arrow:#6b6258;
}
#chess3-trainer .cell.last-from{fill:var(--last-from);opacity:.34;}
#chess3-trainer .cell.last-to{fill:var(--last-to);opacity:.42;}
#chess3-trainer .last-move-arrow{stroke:var(--last-arrow);stroke-width:4;stroke-linecap:round;opacity:.62;}
#chess3-trainer .last-move-arrow-head{fill:var(--last-arrow);opacity:.78;}
#chess3-trainer .cell.last-to.selected,#chess3-trainer .cell.last-from.selected{fill:var(--sel);opacity:.40;}
@media (prefers-reduced-motion:no-preference){
  #chess3-trainer .cell.last-to{animation:chess3-last-move-pulse .65s ease-out 1;}
}
@keyframes chess3-last-move-pulse{
  0%{opacity:.75;}
  100%{opacity:.42;}
}
#chess3-trainer .last-move-arrow.latest{stroke-width:5;opacity:.82;}

/* Final controls */
#chess3-trainer .game-controls{display:flex;flex-direction:column;gap:10px;margin-top:10px;}
#chess3-trainer .speed-control{display:flex;flex-direction:column;gap:5px;font-size:.78rem;color:var(--muted);}
#chess3-trainer .speed-control select,#chess3-trainer .ai-strategy{font:inherit;font-size:.78rem;padding:5px 7px;border:1px solid var(--line);border-radius:6px;background:var(--bg);color:var(--ink);}
#chess3-trainer .ai-strategy:disabled{opacity:.45;cursor:not-allowed;}
#chess3-trainer .log-heading-row{display:flex;align-items:center;justify-content:space-between;gap:8px;flex-wrap:wrap;margin-top:14px;}
#chess3-trainer .log-heading-row h2{margin:0;}
#chess3-trainer .log-actions{display:flex;gap:6px;flex-wrap:wrap;}
#chess3-trainer .log-actions button{font-size:.72rem;padding:5px 8px;}
#chess3-trainer .copy-status{min-height:1.2em;margin-top:5px;font-size:.72rem;color:var(--muted);}
#chess3-trainer .promo-box{max-width:360px;align-items:center;justify-content:center;}
#chess3-trainer .promo-box::before{content:'Выберите фигуру для превращения пешки';flex:1 0 100%;text-align:center;font-size:.88rem;font-weight:600;margin-bottom:4px;}

#chess3-trainer .ai-option{display:flex;align-items:center;gap:5px;font-size:.72rem;color:var(--muted);}
#chess3-trainer .ai-option[hidden]{display:none;}
