/* Шахматные задачи (chess-puzzles.js): разделы и экран задачи.

   Доска — по образцу владельца (23.10): светлые клетки ≈ #e5e5e5 с лёгким
   переходом, тёмные ≈ #8a8a8a, серая рамка с буквами снизу и цифрами слева,
   тонкая чёрная линия по краю поля; фигуры — классический набор диаграмм
   (cburnett), белые кремовые, чёрные с бликом (web-nardy/img/chess). */

#screen-chess, #screen-puzzle { gap: 12px; }

.cz-head { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.cz-back {
  width: 40px; height: 40px; flex: none; border: 0; border-radius: 50%;
  background: var(--surface-2); color: var(--text); font-size: 26px; line-height: 1;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
/* в Telegram назад ведёт его системная кнопка — своя нужна только в браузере */
body.tg .cz-back { display: none; }
.cz-head-text { flex: 1; min-width: 0; }
.cz-title { font-size: 19px; font-weight: 700; }
.cz-sub { font-size: 13px; color: var(--text-2); padding-top: 2px; }
.cz-chip {
  flex: none; display: flex; flex-direction: column; align-items: center;
  padding: 5px 10px; border-radius: 12px; background: var(--surface-1);
}
.cz-chip b { font-size: 16px; color: var(--accent); font-variant-numeric: tabular-nums; }
.cz-chip span { font-size: 11px; color: var(--text-2); }

/* --- разделы --- */
.cz-card {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 14px; border: 0; border-radius: 18px; background: var(--surface-1);
  color: var(--text); font: inherit; cursor: pointer;
}
.cz-card + .cz-card { margin-top: 10px; }
.cz-tile {
  width: 52px; height: 52px; flex: none; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
}
.cz-tile img { width: 44px; height: 44px; }
.cz-card-body { flex: 1; min-width: 0; }
.cz-card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.cz-card-name { font-size: 17px; font-weight: 600; }
.cz-card-count { font-size: 13px; color: var(--text-2); white-space: nowrap; }
.cz-bar { height: 6px; border-radius: 3px; background: var(--surface-3); margin-top: 8px; overflow: hidden; }
.cz-bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.cz-card-note { font-size: 12px; color: var(--text-3); padding-top: 6px; }
.cz-card.classic { background: linear-gradient(135deg, #2a2216, var(--surface-1) 70%);
  border: 1px solid rgba(var(--accent-rgb), .35); }
.cz-year { width: 52px; flex: none; text-align: center; }
.cz-year b { display: block; font-size: 19px; color: var(--accent); }
.cz-year span { font-size: 11px; color: var(--text-2); }
.cz-done { color: var(--ok); font-size: 18px; flex: none; }
.cz-credit { margin-top: auto; text-align: center; font-size: 11px; color: var(--text-3); }

/* --- экран задачи --- */
#screen-puzzle { padding-left: 6px; padding-right: 6px; }
#screen-puzzle .cz-head, #screen-puzzle .cz-panel { padding: 0 10px; }
.cz-main { display: flex; flex-direction: column; gap: 10px; }
.cz-board-wrap { position: relative; display: flex; justify-content: center; }
.cz-frame {
  --cz: min(calc(100vw - 12px), 60dvh);        /* вся рамка */
  width: var(--cz);
  box-sizing: border-box;
  background: #c3c3c3;
  border: 1px solid #6d6d6d;
  padding: 6px 6px 0 0;
  display: grid;
  grid-template-columns: 20px 1fr;
  grid-template-rows: 1fr 22px;
  font-family: Arial, Helvetica, sans-serif;
}
.cz-ranks { display: grid; grid-template-rows: repeat(8, 1fr); }
.cz-files { display: grid; grid-template-columns: repeat(8, 1fr); }
.cz-ranks div, .cz-files div {
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #111;
}
.cz-board {
  position: relative;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 1px solid #000;
  overflow: hidden;
  touch-action: manipulation;
}
.czs { position: relative; background: linear-gradient(180deg, #ebebeb, #dedede); cursor: pointer; }
.czs.dk { background: linear-gradient(180deg, #8f8f8f, #858585); }
.czs.last { background: #e6d98a; }
.czs.dk.last { background: #c4b459; }
.czs.sel { background: #f0dd6e; }
.czs.dk.sel { background: #d2bc44; }
.czs.check { background: radial-gradient(circle, #ff5a4a 0, #e5484d 45%, rgba(229, 72, 77, .35) 80%); }
.czs.bad { background: #ef9a90; }
.czs.dk.bad { background: #cd6357; }
.czs.hint { box-shadow: inset 0 0 0 4px #3dd68c; animation: cz-hint 1s ease-in-out 3; }
@keyframes cz-hint { 50% { box-shadow: inset 0 0 0 4px rgba(61, 214, 140, .2); } }
/* куда можно пойти: точка на пустой клетке, кольцо на клетке со взятием */
.czs.to::after {
  content: ""; position: absolute; left: 36%; top: 36%; width: 28%; height: 28%;
  border-radius: 50%; background: rgba(30, 30, 30, .35); pointer-events: none;
}
.czs.to.cap::after {
  left: 4%; top: 4%; width: 92%; height: 92%; box-sizing: border-box;
  background: none; border: 4px solid rgba(30, 30, 30, .35);
}
/* фигура: у набора свои поля, поэтому знак крупнее клетки — как на образце */
.czp {
  position: absolute; left: -8%; top: -9%; width: 116%; height: 116%;
  pointer-events: none; z-index: 1;
  transition: transform .18s ease;
}
.czp.moving { z-index: 3; }
@media (prefers-reduced-motion: reduce) { .czp { transition: none; } }

.cz-promo {
  position: absolute; z-index: 5; left: 50%; top: 50%; transform: translate(-50%, -50%);
  display: flex; gap: 6px; padding: 8px; border-radius: 14px;
  background: rgba(23, 26, 33, .96); box-shadow: var(--sh-2);
}
.cz-promo.hidden { display: none; }
.cz-promo button {
  width: 64px; height: 64px; border: 0; border-radius: 10px; background: #e5e5e5;
  padding: 2px; cursor: pointer;
}
.cz-promo img { width: 100%; height: 100%; }

.cz-panel { display: flex; flex-direction: column; gap: 10px; }
.cz-task { text-align: center; font-size: 15px; color: var(--text); }
.cz-task .faint { display: block; font-size: 13px; padding-top: 2px; }
.cz-about {
  padding: 10px 12px; border-radius: 14px; font-size: 13px; line-height: 1.4; color: #d6d9e0;
  background: linear-gradient(135deg, #2a2216, var(--surface-1) 75%);
  border: 1px solid rgba(var(--accent-rgb), .3);
}
.cz-about.hidden { display: none; }
.cz-about b { display: block; color: var(--accent); font-size: 12px; padding-bottom: 3px; }
.cz-result {
  padding: 12px 14px; border-radius: 14px; font-size: 14px; line-height: 1.4;
  display: flex; flex-direction: column; gap: 4px;
}
.cz-result.hidden { display: none; }
.cz-result.ok { background: rgba(61, 214, 140, .12); border: 1px solid rgba(61, 214, 140, .4); }
.cz-result.bad { background: rgba(229, 72, 77, .14); border: 1px solid rgba(229, 72, 77, .4); }
.cz-result.shown { background: var(--surface-1); border: 1px solid var(--line); }
.cz-result strong { font-size: 17px; }
.cz-line { font-weight: 600; }
.cz-hist { font-size: 12px; color: var(--text-2); }
.cz-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cz-actions.hidden { display: none; }
.cz-actions .btn { min-height: 46px; }
#cz-after { grid-template-columns: 1fr 2fr; }
.cz-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; }

@media (orientation: landscape) {
  /* доска слева во всю высоту, справа шапка и панель */
  #screen-puzzle {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    column-gap: 14px;
    row-gap: 8px;
    align-content: start;
    padding-top: calc(8px + var(--sa-top, 0px));
  }
  .cz-main { display: contents; }
  .cz-board-wrap { grid-column: 1; grid-row: 1 / span 2; }
  #screen-puzzle .cz-head { grid-column: 2; grid-row: 1; }
  .cz-panel { grid-column: 2; grid-row: 2; }
  .cz-frame { --cz: min(calc(100dvh - 20px - var(--sa-top, 0px) - var(--sa-bottom, 0px)), 58vw); }
}

/* --- партия на двоих (game-chess.js, board-chess.js) ---
   Доска та же, что у задач; размер — общий для игр (--board-w), а не свой.
   Часы: идущие — латунная рамка, последние 20 секунд — красным. */
#board-wrap-chess {
  display: flex; flex-direction: column; align-items: center; width: 100%; position: relative;
  gap: 6px;
}
#board-wrap-chess .cz-frame { --cz: var(--board-w); width: var(--cz); max-width: 100%; }
.chs-board { width: var(--board-w); max-width: 100%; display: flex; justify-content: center; }
.chs-row {
  width: var(--board-w); max-width: 100%; box-sizing: border-box;
  display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 2px;
}
#side > .chs-row { width: 100%; }
.chs-cap { display: flex; align-items: center; min-width: 0; flex: 1; overflow: hidden; }
.chs-cap img { width: 20px; height: 20px; margin-right: -7px; flex: none; }
.chs-cap span { padding-left: 12px; font-size: 13px; font-weight: 700; color: var(--text-2); }
.chs-note {
  font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; max-width: 45%;
}
.chs-clock {
  flex: none; min-width: 88px; box-sizing: border-box; padding: 4px 10px; border-radius: 10px;
  background: var(--surface-1); color: var(--text-2); text-align: center;
  font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.chs-clock.on { background: #2a2216; color: #fff; box-shadow: inset 0 0 0 2px var(--accent); }
.chs-clock.low.on { background: #3a1715; color: #ff8a80; box-shadow: inset 0 0 0 2px #e5484d; }
.chs-clock.zero { background: #3a1715; color: #ff8a80; }
.chs-clock.corr { font-size: 14px; font-weight: 600; min-width: 0; }
.chs-clock.corr:empty { display: none; }
.chs-promo { flex-direction: column; top: 40%; }

#chs-moves {
  width: 100%; box-sizing: border-box; border-radius: 12px; background: var(--surface-1);
  padding: 6px 10px; display: flex; flex-direction: column; gap: 6px;
}
#chs-moves.hidden { display: none; }
.chs-list {
  display: flex; gap: 12px; overflow-x: auto; white-space: nowrap; font-size: 14px;
  scrollbar-width: none;
}
.chs-list::-webkit-scrollbar { display: none; }
.chs-pair { display: inline-flex; gap: 5px; align-items: baseline; }
.chs-pair i { font-style: normal; color: var(--text-3); }
.chs-pair b { font-weight: 500; cursor: default; padding: 0 2px; border-radius: 4px; }
.chs-pair b.cur { color: var(--accent); font-weight: 700; }
.chs-nav { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.chs-nav button {
  height: 36px; border: 0; border-radius: 10px; background: var(--surface-2); color: var(--text);
  font-size: 17px; cursor: pointer;
}
@media (orientation: landscape) {
  /* в колонке запись — столбиком по парам, листается вниз */
  .chs-list { flex-wrap: wrap; white-space: normal; max-height: 30dvh; overflow-y: auto;
    row-gap: 2px; column-gap: 10px; }
  .chs-pair { min-width: 44%; }
  .chs-clock { font-size: 20px; min-width: 80px; }
}
/* экран видов шахмат: вход в задачи над видами партии (flow.js) */
.vcard-puzzles { background: linear-gradient(135deg, #2a2216, var(--surface-1) 70%);
  border-color: rgba(var(--accent-rgb), .35); }
.vcard-puzzles .vcard-art { display: flex; align-items: center; justify-content: center;
  background: #3b2e18; }
.vcard-puzzles .vcard-art img { width: 40px; height: 40px; }

/* «Классика» по эпохам (chess-puzzles.js): заголовок эпохи, инициалы мастера */
.cz-era {
  margin: 16px 2px 6px; font-size: 12px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text-2);
}
.cz-era:first-child { margin-top: 2px; }
.cz-face {
  background: linear-gradient(160deg, #4a3a22, #2a2216); color: var(--accent);
  font-size: 19px; font-weight: 800; letter-spacing: .02em;
}
.cz-bio { margin-bottom: 10px; }
