/* =========================================================
   PUZZLES — сетка карточек
   ========================================================= */

.puzzle-card {
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform .25s ease, border-color .25s ease;
}
.puzzle-card:hover { transform: translateY(-3px); }

.puzzle-card-check {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(106, 168, 79, .9);
  color: #fff;
  font-size: 14px;
  opacity: 0;
  transform: scale(.6);
  transition: all .25s ease;
  z-index: 3;
}
.puzzle-card.solved .puzzle-card-check {
  opacity: 1;
  transform: scale(1);
}

.puzzle-mini-board {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: var(--r-sm, 10px);
  overflow: hidden;
  margin-bottom: 14px;
  background: var(--c-board-light, #ead6b4);
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}

.puzzle-mini-sq {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(11px, 2.6vw, 18px);
  line-height: 1;
  position: relative;
}
.puzzle-mini-sq.light { background: var(--c-board-light, #ead6b4); }
.puzzle-mini-sq.dark  { background: var(--c-board-dark,  #8a6c4a); }

.puzzle-mini-sq .piece {
  font-size: inherit;
  line-height: 1;
  filter: var(--sh-piece, drop-shadow(0 1px 1px rgba(0,0,0,.5)));
}
.puzzle-mini-sq .piece.white { color: #fff; }
.puzzle-mini-sq .piece.black { color: #1a1a1a; }

.puzzle-card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  font-size: 12px;
}

.puzzle-card-theme {
  color: #e0b070;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  font-weight: 500;
  font-size: 11px;
}

.puzzle-card-rating {
  color: #b39a80;
  background: rgba(0,0,0,.2);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
}

/* =========================================================
   SOLVER — оверлей
   ========================================================= */

.puzzle-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 6, 3, .82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: pzOverlayIn .25s ease;
}
.puzzle-overlay[hidden] { display: none; }

@keyframes pzOverlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.puzzle-modal {
  position: relative;
  width: 100%;
  max-width: 1080px;
  max-height: 94vh;
  background: linear-gradient(160deg, #2c1810 0%, #1f130c 100%);
  border: 1px solid rgba(224, 176, 112, .18);
  border-radius: 24px;
  padding: 32px;
  box-shadow:
    0 24px 80px rgba(0,0,0,.7),
    0 2px 0 rgba(255,255,255,.04) inset;
  overflow-y: auto;
  animation: pzModalIn .3s cubic-bezier(.2, .9, .3, 1.2);
}

@keyframes pzModalIn {
  from { opacity: 0; transform: scale(.94) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.puzzle-close {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
  color: #b39a80;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: all .2s ease;
  z-index: 5;
}
.puzzle-close:hover {
  background: rgba(224,176,112,.15);
  border-color: rgba(224,176,112,.4);
  color: #e0b070;
  transform: rotate(90deg);
}

/* =========================================================
   SOLVER — сетка
   ========================================================= */

.puzzle-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, .9fr);
  gap: 36px;
  align-items: start;
}

@media (max-width: 860px) {
  .puzzle-modal { padding: 22px; border-radius: 18px; }
  .puzzle-layout { grid-template-columns: 1fr; gap: 24px; }
  .puzzle-close { top: 14px; right: 14px; }
}

/* ЛЕВАЯ КОЛОНКА */
.puzzle-board-col { min-width: 0; }

.puzzle-board-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 12px;
}

.puzzle-theme {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  color: #e0b070;
  text-transform: uppercase;
  letter-spacing: 1.6px;
  background: rgba(224,176,112,.1);
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid rgba(224,176,112,.2);
}

.puzzle-board-meta {
  display: flex;
  gap: 10px;
  font-size: 12px;
  color: #b39a80;
}
.puzzle-rating,
.puzzle-level {
  background: rgba(0,0,0,.25);
  padding: 4px 10px;
  border-radius: 8px;
}
.puzzle-rating::before { content: '★ '; color: #e0b070; }
.puzzle-level::before  { content: '◆ '; color: #e0b070; }

/* ===== Доска — как в board.css ===== */
#puzzleBoardFrame {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--c-board-frame, #3a2318);
  border-radius: var(--r-sm, 10px);
  padding: 8px;
  box-shadow: var(--sh-board, 0 12px 40px rgba(0,0,0,.55));
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  touch-action: none;
  transition: box-shadow var(--t-med, .3s);
}
#puzzleBoardFrame::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: var(--r-sm, 10px);
  padding: 2px;
  background: linear-gradient(135deg, #6b4c3a, var(--c-board-frame, #3a2318), #6b4c3a);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

#puzzleBoard {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border-radius: var(--r-sm, 10px);
  overflow: hidden;
  background: var(--c-board-light, #ead6b4);
  box-shadow: inset 0 0 20px rgba(0,0,0,0.2);
  position: relative;
  touch-action: none;
}

/* ===== Клетки — как .square в board.css ===== */
#puzzleBoard .square {
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  aspect-ratio: 1 / 1;
  position: relative;
  font-size: clamp(24px, 5.5vw, 48px);
  transition: background var(--t-fast, .15s);
}
#puzzleBoard .square.light { background: var(--c-board-light, #ead6b4); }
#puzzleBoard .square.dark  { background: var(--c-board-dark,  #8a6c4a); }

#puzzleBoard .square .coord {
  position: absolute;
  font-size: clamp(9px, 1.1vw, 12px);
  font-weight: 500;
  pointer-events: none;
  opacity: 0.6;
}
#puzzleBoard .square .coord-file { bottom: 2px; right: 4px; }
#puzzleBoard .square .coord-rank { top: 2px; left: 4px; }
#puzzleBoard .square.light .coord { color: #5a4a3a; }
#puzzleBoard .square.dark  .coord { color: var(--c-board-light, #ead6b4); opacity: 0.5; }

/* курсоры */
#puzzleBoard .square.has-piece { cursor: grab; }
#puzzleBoard .square.has-piece:active { cursor: grabbing; }
#puzzleBoardFrame.dragging,
#puzzleBoardFrame.dragging .square.has-piece { cursor: grabbing; }

/* подсветки */
#puzzleBoard .square.selected {
  background: var(--c-selected, #d4a862) !important;
}
#puzzleBoard .square.last-move {
  background: var(--c-last-move, rgba(212,168,98,.55)) !important;
}

#puzzleBoard .square.valid-move::before {
  content: '';
  position: absolute;
  width: 24%;
  height: 24%;
  background: var(--c-valid, rgba(224,176,112,.85));
  border-radius: 50%;
  pointer-events: none;
  z-index: 2;
  animation: dotIn var(--t-med, .3s);
}
#puzzleBoard .square.dark.valid-move::before {
  background: var(--c-valid-dark, rgba(224,176,112,.6));
}
@keyframes dotIn {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

#puzzleBoard .square.valid-capture {
  background: var(--c-capture, rgba(200,50,50,.25)) !important;
  box-shadow: inset 0 0 0 3px rgba(200, 50, 50, 0.5);
}

/* correct / wrong — оставляем свои, чтобы отличать от игровых */
#puzzleBoard .square.correct {
  background: #6aa84f !important;
  animation: pzCorrect .5s ease;
}
#puzzleBoard .square.wrong {
  background: #c25a4a !important;
  animation: pzWrong .4s ease;
}
@keyframes pzCorrect {
  0%   { box-shadow: inset 0 0 0 0 #fff; }
  50%  { box-shadow: inset 0 0 0 6px rgba(255,255,255,.4); }
  100% { box-shadow: inset 0 0 0 0 transparent; }
}
@keyframes pzWrong {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-3px); }
  75%      { transform: translateX(3px); }
}

/* ===== Фигуры — как в board.css ===== */
#puzzleBoard .square .piece {
  pointer-events: none;
  line-height: 1;
  filter: var(--sh-piece, drop-shadow(0 2px 2px rgba(0,0,0,.45)));
  position: relative;
  z-index: 1;
  font-size: inherit;
  transition: transform var(--t-fast, .15s);
  animation: pieceIn var(--t-med, .3s);
}
@keyframes pieceIn {
  from { transform: scale(0.6); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
#puzzleBoard .square .piece.white { color: #ffffff; text-shadow: 0 2px 6px rgba(0,0,0,0.5); }
#puzzleBoard .square .piece.black { color: #1a1a1a; text-shadow: 0 2px 6px rgba(255,255,255,0.15); }

/* Прогресс */
.puzzle-progress {
  height: 5px;
  background: rgba(0,0,0,.35);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 16px;
}
.puzzle-progress > div {
  height: 100%;
  background: linear-gradient(90deg, #e0b070, #c98a3c);
  width: 0%;
  transition: width .35s cubic-bezier(.2, .9, .3, 1);
  border-radius: 999px;
}

/* ПРАВАЯ КОЛОНКА */
.puzzle-side {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.puzzle-name {
  font-family: 'Fira Sans', system-ui, sans-serif;
  font-size: 26px;
  font-weight: 600;
  color: #efe3d3;
  line-height: 1.2;
  margin: 0;
  padding-right: 40px;
}

.puzzle-turn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0,0,0,.25);
  border: 1px solid rgba(224,176,112,.12);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 13px;
}
.puzzle-turn-label {
  color: #b39a80;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  font-size: 11px;
}
.puzzle-turn strong {
  color: #e0b070;
  font-weight: 600;
  font-size: 14px;
}

.puzzle-moves-head {
  font-size: 11px;
  color: #b39a80;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  margin-bottom: -8px;
}

.puzzle-moves {
  background: rgba(0,0,0,.25);
  border: 1px solid rgba(224,176,112,.12);
  border-radius: 12px;
  padding: 12px 14px;
  font-family: 'Fira Code', monospace;
  font-size: 13px;
  color: #b39a80;
  min-height: 52px;
  max-height: 140px;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: flex-start;
  align-content: flex-start;
}
.puzzle-moves-empty { color: #7a6650; }

.puzzle-moves .mv {
  padding: 3px 9px;
  border-radius: 6px;
  background: rgba(255,255,255,.05);
  font-size: 12px;
}
.puzzle-moves .mv.user { background: #e0b070; color: #1a1008; font-weight: 600; }
.puzzle-moves .mv.bot  { background: rgba(224,176,112,.15); color: #e0b070; }

.puzzle-feedback {
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 13.5px;
  line-height: 1.55;
  display: none;
  animation: pzFadeIn .25s ease;
}
@keyframes pzFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.puzzle-feedback.show { display: block; }
.puzzle-feedback.ok   { background: rgba(106,168,79,.12); border: 1px solid rgba(106,168,79,.5); color: #d5e8c8; }
.puzzle-feedback.bad  { background: rgba(194,90,74,.12); border: 1px solid rgba(194,90,74,.5); color: #f0c8c0; }
.puzzle-feedback.hint { background: rgba(224,176,112,.1); border: 1px solid rgba(224,176,112,.4); color: #f0dfc0; }

.puzzle-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: auto;
}

.pz-btn {
  flex: 1 1 auto;
  min-width: 110px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  color: #efe3d3;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(224,176,112,.2);
  border-radius: 10px;
  cursor: pointer;
  transition: all .2s ease;
}
.pz-btn:hover {
  background: rgba(224,176,112,.12);
  border-color: rgba(224,176,112,.5);
  color: #e0b070;
  transform: translateY(-1px);
}
.pz-btn i { font-size: 13px; }

.pz-btn-primary {
  background: linear-gradient(160deg, #e0b070, #c98a3c);
  border-color: #e0b070;
  color: #1a1008;
  font-weight: 600;
}
.pz-btn-primary:hover {
  background: linear-gradient(160deg, #e8bc80, #d49548);
  color: #1a1008;
}

/* ===== Drag ghost — как в board.css ===== */
#puzzleGhost {
  position: fixed;
  pointer-events: none;
  z-index: 10000;
  font-size: clamp(28px, 6vw, 50px);
  line-height: 1;
  filter: var(--sh-ghost, drop-shadow(0 8px 16px rgba(0,0,0,.5)));
  transform: translate(-50%, -50%) scale(1.1);
  transition: none;
  opacity: 0;
  will-change: transform, left, top;
  display: block;
}
#puzzleGhost.visible { opacity: 1; }
#puzzleGhost .piece.white { color: #ffffff; text-shadow: 0 2px 12px rgba(0,0,0,0.7); }
#puzzleGhost .piece.black { color: #1a1a1a; text-shadow: 0 2px 12px rgba(255,255,255,0.2); }
