:root {
  --board: min(calc(92vw - 26px), 82vh, 640px);
  --sq: calc(var(--board) / 8);
  --light: #f0d9b5;
  --dark: #b58863;
  --bg: #262421;
  --panel: #312e2b;
  --text: #e8e6e3;
  --muted: #9e9a95;
  --accent: #81b64c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.app {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  justify-content: center;
  align-items: flex-start;
  padding: 24px 16px;
}

/* ---------- Режимы ---------- */

body[data-mode="play"] .analysis-only,
body[data-mode="online"] .analysis-only,
body[data-mode="online"] .play-only,
body[data-mode="analysis"] .play-only,
body[data-mode="analysis"] .game-only { display: none !important; }

/* ---------- Доска ---------- */

.board-area { display: flex; gap: 8px; }
.board-wrap { position: relative; }
.board-col { display: flex; flex-direction: column; gap: 8px; }
.main-line { width: var(--board); box-sizing: border-box; padding: 8px 10px; background: #2a2724; border-radius: 4px; font-size: 13px; line-height: 1.6; color: var(--muted); }
.main-line[hidden], body:not([data-mode="learn"]) .main-line, body:not([data-view="learn"]) .main-line { display: none; }
.main-line .ml-title { font-weight: 600; color: var(--text); margin-right: 6px; }
.main-line .ml-move { white-space: nowrap; }
.main-line .ml-move.played { color: #8bc34a; }
.main-line .ml-move.next { color: #fff; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.main-line .ml-off { display: block; margin-top: 2px; color: #e6c07b; }

.arrows {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
  pointer-events: none;
}
.arrows line { stroke-width: .17; }
.arrows .best line { stroke: #15781b; }
.arrows .best polygon { fill: #15781b; }
.arrows .best { opacity: .8; }
.arrows .alt line { stroke: #003088; }
.arrows .alt polygon { fill: #003088; }
.arrows .alt { opacity: .4; }
.arrows .bad line { stroke: #b3261e; }
.arrows .bad polygon { fill: #b3261e; }
.arrows .bad { opacity: .55; }
.arrows .focus line { stroke: #e69f00; }
.arrows .focus polygon { fill: #e69f00; }
.arrows .focus { opacity: .9; }

/* Полоска перевеса — в анализе и в «Обучении» (тренировка гамбитов). */
body:not([data-mode="analysis"]):not([data-mode="learn"]) .eval-bar,
body[data-mode="learn"]:not([data-view="learn"]) .eval-bar { display: none; }
.eval-bar {
  position: relative;
  width: 18px;
  height: var(--board);
  border-radius: 3px;
  overflow: hidden;
  background: #403d39;
}
.eval-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--white, 50%);
  background: #f2f2f2;
  transition: height .4s ease;
}
.eval-bar.flipped .eval-fill { top: 0; bottom: auto; }
.eval-bar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  border-top: 1px solid rgba(220, 60, 60, .7);
}

.board {
  display: grid;
  grid-template-columns: repeat(8, var(--sq));
  grid-template-rows: repeat(8, var(--sq));
  width: var(--board);
  height: var(--board);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .45);
  touch-action: none;
  user-select: none;
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sq.light { background: var(--light); }
.sq.dark { background: var(--dark); }

.sq.last::before,
.sq.selected::before,
.sq.check::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.sq.last::before { background: rgba(255, 235, 59, .38); }
.sq.selected::before { background: rgba(20, 110, 40, .45); }
.sq.check::before { background: radial-gradient(circle, rgba(255, 0, 0, .9) 0%, rgba(230, 0, 0, .5) 45%, transparent 75%); }

.sq.target::after {
  content: "";
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(20, 85, 30, .45);
  pointer-events: none;
}
.sq.target.capture::after {
  width: 100%;
  height: 100%;
  background: radial-gradient(circle, transparent 62%, rgba(20, 85, 30, .45) 64%);
}
.sq.target:hover { outline: 3px solid rgba(20, 85, 30, .6); outline-offset: -3px; }

.piece {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;
}
.sq.movable { cursor: grab; }
.sq.dragging .piece { opacity: .25; }

.ghost {
  position: fixed;
  z-index: 100;
  width: var(--sq);
  height: var(--sq);
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1.1);
  cursor: grabbing;
}

.coord {
  position: absolute;
  z-index: 2;
  font-size: calc(var(--sq) * .18);
  font-weight: 700;
  pointer-events: none;
}
.coord.rank { top: 3px; left: 4px; }
.coord.file { bottom: 2px; right: 4px; }
.sq.light .coord { color: var(--dark); }
.sq.dark .coord { color: var(--light); }

/* ---------- Превращение пешки ---------- */

.promo {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .55);
  border-radius: 4px;
}
.promo[hidden] { display: none; }
.promo-box {
  background: var(--panel);
  padding: 16px 20px;
  border-radius: 8px;
  text-align: center;
}
.promo-box p { margin: 0 0 10px; }
.promo-choices { display: flex; gap: 8px; }
.promo-choices button {
  width: var(--sq);
  height: var(--sq);
  padding: 0;
  background: var(--light);
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}
.promo-choices button:hover { background: #fff3c4; }

/* ---------- Панель ---------- */

.panel {
  width: min(92vw, 320px);
  background: var(--panel);
  border-radius: 8px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
h1 { margin: 0; font-size: 22px; }

.controls { display: flex; flex-direction: column; gap: 10px; }
.controls label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
select, button {
  font: inherit;
  color: var(--text);
  background: #45423e;
  border: 1px solid #55524d;
  border-radius: 6px;
  padding: 6px 10px;
}
select { min-width: 150px; }
button { cursor: pointer; }
button:hover:not(:disabled) { background: #55524d; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: #95c95e; }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.buttons button { flex: 1 1 auto; }

.status {
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  padding: 8px 10px;
  border-bottom: 1px solid #3d3a36;
}
.status.over { background: #4a3a22; }
.status.thinking::after {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-left: 8px;
  border: 2px solid var(--muted);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.info { color: var(--muted); font-size: 13px; min-height: 1.4em; }

/* ---------- Колонка с часами и записью (как на lichess) ---------- */

.table {
  display: flex;
  flex-direction: column;
  width: 270px;
  height: var(--board);
  margin-left: -16px; /* вплотную к доске, как на lichess */
}

.rclock { display: flex; flex-direction: column; align-items: flex-start; }
.rclock[hidden] { display: none; }
.rclock .time {
  padding: 0 14px;
  font: 400 44px/1.25 Roboto, "Noto Sans", system-ui, sans-serif;
  letter-spacing: 4px;
  font-variant-numeric: tabular-nums;
  color: #bababa;
  background: var(--panel);
}
.rclock-top .time { border-radius: 4px 4px 0 0; }
.rclock-bottom .time { border-radius: 0 0 4px 4px; }
.rclock .sep { opacity: .5; padding: 0 1px; }
.rclock .tenths { font-size: 70%; }
.rclock .bar {
  width: 100%;
  height: 4px;
  background: #629924;
  transform-origin: left;
  transform: scaleX(var(--left, 1));
}
.rclock.running .time { background: #3d5a1c; color: #fff; }
.rclock.low .time { color: #ff9b8f; }
.rclock.running.low .time { background: #7a2a24; color: #fff; }
.rclock.flagged .time { background: #7a2a24; color: #fff; }
.rclock.low .bar { background: #c33; }

.table-mid {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
}
.rclock-top + .table-mid { border-top-right-radius: 4px; }
.table-mid:last-child, .table-mid:first-child { border-radius: 4px; }

.ruser {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  font-size: 16px;
}
.ruser .dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.5px solid #bababa;
  flex: none;
}
.ruser .dot.w { background: #fff; }
.ruser .dot.b { background: #111; }
.ruser .note { color: var(--muted); font-size: 13px; }
.ruser .material { margin-left: auto; display: flex; align-items: center; color: var(--muted); font-size: 13px; }
.ruser .material img { width: 22px; height: 22px; margin-right: -8px; }
.ruser .material .group { display: flex; margin-right: 10px; }
.ruser .material b { font-weight: 400; margin-left: 4px; }

@media (max-width: 1100px) {
  .table { width: var(--board); height: auto; margin-left: 0; }
  .table .moves { max-height: 200px; }
}

/* ---------- Вкладки и анализ ---------- */

.tabs { display: flex; background: #2a2724; border-radius: 6px; padding: 3px; }
.tabs button { flex: 1; background: none; border: 0; color: var(--muted); }
.tabs button.active { background: #45423e; color: var(--text); font-weight: 600; }

.analysis { display: flex; flex-direction: column; gap: 10px; }
.engine-head { display: flex; align-items: baseline; gap: 12px; }
.switch { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.switch input { accent-color: var(--accent); width: 16px; height: 16px; }
.eval-text { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.depth { color: var(--muted); font-size: 13px; margin-left: auto; }

.pv {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
  background: #2a2724;
  border-radius: 6px;
}
.pv:empty { display: none; }
.pv li {
  display: flex;
  gap: 8px;
  padding: 4px 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pv li + li { border-top: 1px solid #36332f; }
.pv b { min-width: 42px; font-variant-numeric: tabular-nums; }
.pv span { overflow: hidden; text-overflow: ellipsis; color: #cfcbc6; }
.error { color: #e6a23c; }

.ideas-head { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.ideas { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 3px; }
.ideas li {
  padding: 5px 8px;
  font-size: 13px;
  line-height: 1.35;
  background: #2a2724;
  border-left: 3px solid #6b6762;
  border-radius: 0 4px 4px 0;
  cursor: default;
}
.ideas li.good { border-left-color: #629924; }
.ideas li.bad { border-left-color: #c9483f; }
.ideas li:hover { background: #36332f; }
.ideas:empty::after { content: "Нет заметных идей"; color: var(--muted); font-size: 13px; }
.sq.idea { box-shadow: inset 0 0 0 4px rgba(255, 170, 0, .9); }

.review-summary p { margin: 2px 0; font-size: 13px; }
.review-summary:empty { display: none; }

.graph {
  width: 100%;
  height: 90px;
  background: #3a3733;
  border-radius: 6px;
  cursor: pointer;
}
.graph.empty { display: none; }
.graph .area { fill: #f2f2f2; opacity: .9; }
.graph line { vector-effect: non-scaling-stroke; stroke-width: 1px; }
.graph .mid { stroke: rgba(220, 60, 60, .6); }
.graph .cursor { stroke: var(--accent); stroke-width: 2px; }
.graph .inaccuracy { stroke: #56b4e9; }
.graph .mistake { stroke: #e69f00; }
.graph .blunder { stroke: #df5353; }

.inaccuracy { --mark: #56b4e9; }
.mistake { --mark: #e69f00; }
.blunder { --mark: #df5353; }
.review-summary span { color: var(--mark); }

.nav {
  display: flex;
  gap: 4px;
  align-items: center;
  border-top: 1px solid #3d3a36;
  border-bottom: 1px solid #3d3a36;
}
.nav-btn {
  flex: 1 1 0;
  height: 34px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 0;
  color: #f2f2f2;
}
.nav-btn:hover:not(:disabled) { background: rgba(255, 255, 255, .08); }
.nav-btn:disabled { opacity: .3; }
.nav-btn svg { width: 20px; height: 20px; fill: currentColor; }
.nav-btn .chevron {
  fill: none;
  stroke: currentColor;
  stroke-width: 3.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
body[data-mode="play"] .nav #flip { flex: 0 0 44px; margin-left: auto; }
body[data-mode="play"] .nav #resign,
body[data-mode="online"] .nav #resign,
body[data-mode="play"] .nav #offerDraw,
body[data-mode="online"] .nav #offerDraw { flex: 0 0 44px; }
body[data-mode="online"] .nav #flip { flex: 0 0 44px; margin-left: auto; }
.resign-confirm { display: flex; align-items: center; gap: 6px; padding-left: 10px; font-size: 14px; }
.resign-confirm[hidden],
.nav-btn[hidden] { display: none; }
/* Перемотка ходов нужна и в «Обучении». */
body[data-mode="learn"][data-view="learn"] .nav-btn.learn-nav { display: flex !important; }
.resign-confirm button { padding: 3px 10px; }
.resign-confirm .yes { background: #a33a32; border-color: #a33a32; color: #fff; }
.resign-confirm .yes:hover { background: #c0443a; }

.moves {
  margin: 0;
  padding: 0;
  list-style: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  font-variant-numeric: tabular-nums;
}
.moves li {
  display: grid;
  grid-template-columns: 36px 1fr 1fr;
  padding: 3px 8px;
}
.moves li:nth-child(odd) { background: #2f2c29; }
.moves .num { color: var(--muted); }
.moves .move { padding: 0 4px; border-radius: 3px; }
body[data-mode="analysis"] .moves .move { cursor: pointer; }
body[data-mode="analysis"] .moves .move:hover { background: #45423e; }
.moves .current { color: var(--accent); font-weight: 700; }
body[data-mode="analysis"] .moves .current { background: #2f5d8a; color: #fff; }
.moves .mark { color: var(--mark); font-weight: 700; margin-left: 1px; }
.moves small { float: right; color: var(--muted); font-size: 11px; font-weight: 400; margin-top: 2px; }

/* ---------- Вкладка «Партии», аккаунт ---------- */

body[data-view="games"] .panel .play-only,
body[data-view="games"] .panel .analysis-only,
body[data-view="online"] .panel .play-only,
body[data-view="online"] .panel .analysis-only,
body:not([data-view="online"]) .online-only,
body:not([data-view="admin"]) .admin-only,
body:not([data-view="learn"]) .learn-only,
body[data-view="learn"] .panel .play-only,
body[data-view="learn"] .panel .analysis-only,
body[data-mode="learn"] .play-only,
body[data-mode="learn"] .analysis-only,
body[data-mode="learn"] .game-only,
body[data-mode="puzzle"] .play-only,
body[data-mode="puzzle"] .analysis-only,
body[data-mode="puzzle"] .game-only,
body[data-view="admin"] .panel .play-only,
body[data-view="admin"] .panel .analysis-only,
body:not([data-view="games"]) .games-only { display: none !important; }
body[data-view="games"] .panel .info { display: none; }

.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.account { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.account .login { font-weight: 600; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); }

button.link {
  padding: 0;
  background: none;
  border: 0;
  color: #8fc3ff;
  text-decoration: underline;
  text-underline-offset: 2px;
}
button.link:hover:not(:disabled) { background: none; color: #b5d8ff; }
button.danger { background: #a33a32; border-color: #a33a32; color: #fff; }
button.danger:hover:not(:disabled) { background: #c0443a; }

input {
  font: inherit;
  color: var(--text);
  background: #2a2724;
  border: 1px solid #55524d;
  border-radius: 6px;
  padding: 7px 10px;
  min-width: 0;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid #8fc3ff; outline-offset: 1px; }

.stack { display: flex; flex-direction: column; gap: 8px; }
.stack input[hidden] { display: none; }

.games { display: flex; flex-direction: column; gap: 10px; }
.games-guest p { margin: 0 0 10px; color: var(--muted); font-size: 14px; }
.games-msg { margin: 0; font-size: 13px; color: #e6c07b; }
.filter { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; }

.stats p { margin: 0 0 4px; font-size: 13px; }
.stats table { width: 100%; font-size: 12px; color: var(--muted); border-collapse: collapse; }
.stats td { padding: 1px 0; }
.stats td + td { text-align: right; white-space: nowrap; }
.stats .win, .game-item.win .gi-badge { color: #8bc34a; }
.stats .loss, .game-item.loss .gi-badge { color: #ef7b70; }
.stats .draw, .game-item.draw .gi-badge { color: #c8c3bd; }

.games-list {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 46vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.games-list .empty { color: var(--muted); font-size: 13px; padding: 6px 0; }
.game-item {
  padding: 7px 9px;
  background: #2a2724;
  border-left: 3px solid #6b6762;
  border-radius: 0 4px 4px 0;
}
.game-item.win { border-left-color: #629924; }
.game-item.loss { border-left-color: #c9483f; }
.gi-main { display: flex; gap: 8px; align-items: baseline; font-size: 14px; }
.gi-main .gi-badge { font-weight: 700; flex: none; }
.gi-main .opp { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gi-meta { font-size: 12px; color: var(--muted); margin: 2px 0 6px; }
.gi-actions { display: flex; gap: 6px; }
.gi-actions button { padding: 2px 9px; font-size: 13px; }
.gi-actions .del { margin-left: auto; }
.gi-actions .del.confirm { background: #a33a32; border-color: #a33a32; color: #fff; }

.account-settings summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.account-settings form { margin-top: 8px; }

.auth-dialog {
  width: min(92vw, 340px);
  padding: 20px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid #45423e;
  border-radius: 10px;
}
.auth-dialog::backdrop { background: rgba(0, 0, 0, .6); }
.auth-dialog h2 { margin: 0 0 4px; font-size: 20px; }
.auth-dialog .error { margin: 0; font-size: 13px; }

.invites { display: flex; flex-direction: column; gap: 8px; padding-top: 6px; border-top: 1px solid #3d3a36; }
.invites h3 { margin: 0; font-size: 15px; }
.hint { margin: 0; font-size: 12px; color: var(--muted); }
.invite-fresh[hidden] { display: none; }
.invite-fresh { display: flex; flex-direction: column; gap: 6px; padding: 8px; background: #2a2724; border-radius: 6px; }
.invite-fresh code { font-size: 18px; letter-spacing: 2px; color: #fff; text-align: center; }
.invite-fresh input { font-size: 12px; }
.invites-list { margin: 0; padding: 0; list-style: none; font-size: 12px; display: flex; flex-direction: column; gap: 2px; }
.invites-list li { display: flex; gap: 8px; align-items: center; color: var(--muted); }
.invites-list .hint-code { font-family: ui-monospace, monospace; color: var(--text); }
.invites-list button { margin-left: auto; font-size: 12px; }

/* ---------- Онлайн: лобби, партия с человеком, настройки ---------- */

.head-tools { display: flex; align-items: center; gap: 8px; }
.icon-btn { padding: 4px; background: none; border: 0; color: var(--muted); display: flex; }
.icon-btn:hover:not(:disabled) { background: none; color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }

.tabs button { position: relative; }
.badge-dot { position: absolute; top: 4px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: #e0533f; }
.badge-dot[hidden] { display: none; }

.online-panel { display: flex; flex-direction: column; gap: 10px; }
.lobby { display: flex; flex-direction: column; gap: 8px; }
.lobby h3 { margin: 6px 0 0; font-size: 14px; color: var(--muted); }
.lobby label { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 14px; }
.lobby label.check, .stack label.check { justify-content: flex-start; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.challenge-to { display: flex; gap: 6px; }
.challenge-to input { flex: 1; }
.my-ratings { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; text-align: center; font-size: 12px; }
.my-ratings div { background: #2a2724; border-radius: 4px; padding: 4px 2px; }
.my-ratings b { display: block; font-size: 15px; color: var(--text); }
.my-ratings span { color: var(--muted); }

.lobby-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.lobby-list:empty::after { content: "—"; color: var(--muted); }
.lobby-list li { display: flex; align-items: center; gap: 6px; padding: 4px 8px; background: #2a2724; border-radius: 4px; }
.lobby-list .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lobby-list .meta { color: var(--muted); white-space: nowrap; }
.lobby-list button { padding: 2px 8px; font-size: 12px; }
.lobby-list .online-dot { width: 8px; height: 8px; border-radius: 50%; background: #629924; flex: none; }
.lobby-list .offline-dot { width: 8px; height: 8px; border-radius: 50%; background: #6b6762; flex: none; }

.online-game { display: flex; flex-direction: column; gap: 8px; padding: 10px; background: #2a2724; border-radius: 6px; }
.online-game-info { margin: 0; font-size: 14px; }
.draw-offer { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 14px; color: #e6c07b; }
.draw-offer[hidden], .online-game[hidden], .lobby[hidden] { display: none; }

.sq.premove::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(20, 30, 85, .45);
  pointer-events: none;
}

.email-box p { margin: 0; font-size: 13px; }
.email-box details { font-size: 13px; }
.email-box summary { cursor: pointer; color: var(--muted); }
.email-box .stack { margin-top: 6px; }
.ok { color: #8bc34a; }
.warn { color: #e6a23c; }

.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(92vw, 520px);
  padding: 10px 14px;
  background: #3d5a1c;
  color: #fff;
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .5);
  font-size: 14px;
}
.toast[hidden] { display: none; }
.toast button { padding: 3px 10px; }
.buttons[hidden] { display: none; }
.import-url { display: flex; gap: 8px; margin-top: 8px; }
.import-url input { flex: 1 1 auto; min-width: 0; }

/* ---------- Кнопка «Сдаться» и админка ---------- */

.tabs button[hidden] { display: none; }
.resign-btn { border-color: #7a3b35; }
.resign-btn:hover:not(:disabled) { background: #5a2f2a; }
.resign-btn.confirm { background: #a33a32; border-color: #a33a32; color: #fff; }

.admin-panel { display: flex; flex-direction: column; gap: 8px; }
.admin-panel h3 { margin: 4px 0 0; font-size: 14px; color: var(--muted); }
.admin-panel select { min-width: 0; flex: 1; }
.admin-users { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; max-height: 55vh; overflow-y: auto; }
.admin-users li { padding: 7px 9px; background: #2a2724; border-radius: 4px; font-size: 13px; }
.admin-users li.blocked { opacity: .6; }
.au-main { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.au-main b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.au-tag { font-size: 11px; padding: 1px 5px; border-radius: 3px; background: #45423e; color: var(--muted); }
.au-tag.admin { background: #3d5a1c; color: #fff; }
.au-tag.blocked { background: #7a2a24; color: #fff; }
.au-meta { color: var(--muted); font-size: 12px; margin: 3px 0 6px; line-height: 1.4; }
.au-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.au-actions button { padding: 2px 9px; font-size: 12px; }

/* Пять вкладок помещаются в ширину панели. */
.tabs { gap: 2px; }
.tabs button { flex: 1 1 0; min-width: 0; padding: 6px 2px; font-size: 14px; }

/* Без контроля времени: секундомер затраченного времени, без полоски остатка. */
.rclock.untimed .bar { visibility: hidden; }

/* Дебют над записью ходов и книжные ходы в разборе. */
.opening-name {
  padding: 4px 10px;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid #3d3a36;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.opening-name[hidden] { display: none; }
.moves .move.book { color: #9db7d6; }

/* Статистика ходов (Opening Explorer). */
.explorer-box[hidden] { display: none; }
.explorer-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.explorer-head select { min-width: 0; padding: 2px 6px; font-size: 12px; }
.explorer { margin: 4px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.explorer li { display: grid; grid-template-columns: 52px 64px 1fr; align-items: center; gap: 6px; padding: 3px 6px; background: #2a2724; border-radius: 3px; cursor: pointer; }
.explorer li:hover { background: #36332f; }
.explorer .games { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; }
.explorer .wdl { display: flex; height: 16px; border-radius: 3px; overflow: hidden; font-size: 10px; line-height: 16px; font-style: normal; }
.explorer .wdl i { font-style: normal; text-align: center; overflow: hidden; white-space: nowrap; }
.explorer .wdl .w { background: #f2f2f2; color: #333; }
.explorer .wdl .d { background: #8a8580; color: #fff; }
.explorer .wdl .b { background: #1f1f1f; color: #ddd; }

/* ---------- Обучение ---------- */

.learn-panel, .learn-pick, .learn-session { display: flex; flex-direction: column; gap: 8px; }
.learn-pick[hidden], .learn-session[hidden] { display: none; }
.learn-panel h3 { margin: 4px 0 0; font-size: 15px; }
.learn-panel label { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 13px; }
.learn-panel select { min-width: 0; }
.gambit-list, .opening-results { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
.gambit-list { max-height: 42vh; overflow-y: auto; }
.gambit-list li, .opening-results li { padding: 7px 9px; background: #2a2724; border-radius: 4px; cursor: pointer; }
.gambit-list li:hover, .opening-results li:hover { background: #36332f; }
.gl-head { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.gl-side { color: var(--muted); font-size: 12px; white-space: nowrap; }
.gl-head b { flex: 1; }
.fav-btn { flex: none; padding: 0 4px; border: 0; background: none; color: var(--muted); font-size: 16px; line-height: 1; cursor: pointer; }
.fav-btn:hover { color: #e6c07b; }
.fav-btn.on { color: #f0b429; }
.opening-results li { display: flex; align-items: center; gap: 6px; }
.opening-results li .or-name { flex: 1; }
.gl-line { font-size: 12px; color: #9db7d6; margin: 2px 0; }
.gl-idea { font-size: 12px; color: var(--muted); line-height: 1.35; }
.opening-results { max-height: 30vh; overflow-y: auto; font-size: 13px; }
.opening-results .empty { cursor: default; color: var(--muted); }
.learn-status { margin: 0; font-weight: 600; min-height: 1.3em; }
.learn-feed { display: flex; flex-direction: column; gap: 5px; max-height: 48vh; overflow-y: auto; }
.lf-item { padding: 7px 9px; background: #2a2724; border-left: 3px solid #6b6762; border-radius: 0 4px 4px 0; font-size: 13px; line-height: 1.4; }
.lf-item ul { margin: 4px 0 0; padding-left: 16px; }
.lf-head { display: flex; align-items: baseline; gap: 8px; }
.lf-verdict { font-weight: 700; }
.lf-eval { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.lf-name { color: #9db7d6; font-size: 12px; }
.lf-rec { margin: 5px 0 0; color: #cfe3b8; }
.lf-actions { margin-top: 5px; }
.lf-actions button { padding: 2px 9px; font-size: 12px; }
.lf-item.theory, .lf-item.best { border-left-color: #629924; }
.lf-item.theory .lf-verdict, .lf-item.best .lf-verdict { color: #8bc34a; }
.lf-item.good { border-left-color: #8bc34a; }
.lf-item.inaccuracy { border-left-color: #56b4e9; }
.lf-item.inaccuracy .lf-verdict { color: #56b4e9; }
.lf-item.mistake { border-left-color: #e69f00; }
.lf-item.mistake .lf-verdict { color: #e69f00; }
.lf-item.blunder { border-left-color: #df5353; }
.lf-item.blunder .lf-verdict { color: #df5353; }
.lf-opp { color: var(--muted); }
.lf-note { border-left-color: #2f5d8a; color: #cfd8e3; }
.learn-lines { display: flex; flex-direction: column; gap: 4px; }
.learn-lines[hidden] { display: none; }
.ll-head { font-size: 13px; font-weight: 600; color: var(--muted); }
.ll-head .hint { font-weight: 400; }
.ll-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 3px; max-height: 32vh; overflow-y: auto; font-size: 13px; }
.ll-list li { display: flex; flex-direction: column; gap: 3px; padding: 5px 8px; background: #2a2724; border-left: 3px solid #6b6762; border-radius: 0 4px 4px 0; cursor: pointer; }
.ll-list li:hover { background: #36332f; }
.ll-list li.top { border-left-color: #629924; }
.ll-list li:hover { border-left-color: #e69f00; }
.ll-row { display: flex; align-items: baseline; gap: 8px; }
.ll-best { color: #8bc34a; }
.ll-bad { padding: 0 5px; border-radius: 3px; background: #b3261e; color: #fff; font-size: 11px; }
.ll-list li.bad { border-left-color: #b3261e; }
.ll-share { color: var(--muted); font-size: 12px; }
.ll-eval { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.ll-name { color: #9db7d6; font-size: 12px; }
.ll-list .wdl { display: flex; height: 14px; border-radius: 3px; overflow: hidden; font-size: 10px; line-height: 14px; }
.ll-list .wdl i { font-style: normal; text-align: center; overflow: hidden; white-space: nowrap; }
.ll-list .wdl .w { background: #f2f2f2; color: #333; }
.ll-list .wdl .d { background: #8a8580; color: #fff; }
.ll-list .wdl .b { background: #1f1f1f; color: #ddd; }

/* Шесть вкладок: переносятся на вторую строку, а не наезжают друг на друга. */
.tabs { flex-wrap: wrap; }
.tabs button { flex: 1 1 auto; padding: 6px 8px; font-size: 13px; white-space: nowrap; }

/* ---------- Задачи и «Мои ошибки» ---------- */

.seg { display: flex; background: #2a2724; border-radius: 6px; padding: 3px; gap: 2px; }
.seg button { flex: 1; background: none; border: 0; color: var(--muted); padding: 5px 4px; font-size: 13px; }
.seg button.active { background: #45423e; color: var(--text); font-weight: 600; }
.puzzle-panel { display: flex; flex-direction: column; gap: 8px; }
.puzzle-panel[hidden] { display: none; }
.puzzle-panel label { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 13px; }
.puzzle-panel select { min-width: 0; flex: 1; }
.pz-rating { margin: 0; font-size: 14px; font-weight: 600; }
.pz-recent { display: flex; flex-wrap: wrap; gap: 3px; margin: 0; padding: 0; list-style: none; }
.pz-recent:empty { display: none; }
.pz-recent li { width: 18px; height: 18px; border-radius: 3px; font-size: 11px; line-height: 18px; text-align: center; color: #fff; }
.pz-recent .ok { background: #3d5a1c; }
.pz-recent .bad { background: #7a2a24; }
.mistakes-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 3px; max-height: 40vh; overflow-y: auto; font-size: 13px; }
.mistakes-list li { display: flex; flex-wrap: wrap; gap: 4px 8px; padding: 5px 8px; background: #2a2724; border-left: 3px solid #e69f00; border-radius: 0 4px 4px 0; cursor: pointer; }
.mistakes-list li.blunder { border-left-color: #df5353; }
.mistakes-list li.done { border-left-color: #629924; opacity: .6; }
.mistakes-list li:hover { background: #36332f; }
.mistakes-list .meta { color: var(--muted); font-size: 12px; width: 100%; }
#puzzleLink[hidden] { display: none; }

/* Итог партии под записью ходов, как на lichess. */
.game-over { display: flex; flex-direction: column; align-items: stretch; border-top: 1px solid #3d3a36; }
.game-over[hidden] { display: none; }
.go-score { padding: 8px 10px 0; text-align: center; font-size: 20px; font-weight: 700; }
.go-reason { padding: 2px 10px 10px; text-align: center; font-size: 14px; font-style: italic; color: #cfcbc6; }
.go-main {
  margin: 0 8px 6px;
  padding: 14px 10px;
  font-size: 15px;
  letter-spacing: .5px;
  text-transform: uppercase;
  background: #3a3733;
  border: 1px solid #4a4743;
}
.go-main:hover:not(:disabled) { background: #46433f; }
.go-link {
  padding: 10px;
  font-size: 13px;
  letter-spacing: .5px;
  text-transform: uppercase;
  background: none;
  border: 0;
  border-radius: 0;
  color: #cfcbc6;
}
.go-link:hover:not(:disabled) { background: #36332f; color: #fff; }
.game-over button[hidden], .status[hidden] { display: none; }

/* Счётчик до автоматической ничьей. */
.draw-counter { padding: 3px 10px; font-size: 12px; color: var(--muted); border-bottom: 1px solid #3d3a36; }
.draw-counter[hidden] { display: none; }
.draw-counter.warn { color: #e6c07b; }

.rules-form { display: flex; flex-direction: column; gap: 6px; }
.rules-form label { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; }
.rules-form input { width: 72px; }

/* Книжка у теоретических ходов. */
.moves .book-icon { width: 11px; height: 11px; margin-left: 4px; vertical-align: -1px; fill: #9db7d6; }

/* Значки ходов как на chess.com: книжка (теория) в записи и на доске у последнего хода. */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  margin-right: 4px;
  border-radius: 50%;
  vertical-align: -3px;
  background: #a88865;
}
.badge svg { width: 11px; height: 11px; fill: #fff; }
.moves .move.book { color: inherit; }
.sq-badge {
  position: absolute;
  z-index: 4;
  top: -6%;
  right: -6%;
  width: 36%;
  height: 36%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .9);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
  color: #fff;
  font-weight: 800;
  font-size: calc(var(--sq) * .16);
  pointer-events: none;
}
.sq-badge.book { background: #a88865; }
.sq-badge.book svg { width: 70%; height: 70%; fill: #fff; }
.sq-badge.inaccuracy { background: #56b4e9; }
.sq-badge.mistake { background: #e69f00; }
.sq-badge.blunder { background: #df5353; }
.sq-badge.end svg { width: 68%; height: 68%; fill: #fff; }
.sq-badge.won { background: #e2a72e; }
.sq-badge.lost { background: #d64545; }
.sq-badge.draw { background: #8a8580; }

/* Вариант в анализе. */
.variation { padding: 6px 10px; border-top: 1px solid #3d3a36; background: #2a2724; font-size: 13px; }
.variation[hidden] { display: none; }
.variation-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.variation-moves { line-height: 1.8; }
.variation-moves .num { color: var(--muted); margin-right: 2px; }
.vmove { padding: 1px 4px; border-radius: 3px; cursor: pointer; }
.vmove:hover { background: #45423e; }
.vmove.current { background: #2f5d8a; color: #fff; }

/* Значки плохих ходов в записи. */
.badge.inaccuracy, .badge.mistake, .badge.blunder { color: #fff; font-size: 9px; font-weight: 800; letter-spacing: -.5px; }
.badge.inaccuracy { background: #56b4e9; }
.badge.mistake { background: #e69f00; }
.badge.blunder { background: #df5353; }

/* «½» — предложить ничью. */
.draw-btn { font-size: 18px; font-weight: 700; }
.draw-btn.offered { color: #8bc34a; }
