/* =========================================================
   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);
  container-type: inline-size;
}

.puzzle-mini-sq {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 7cqw;
  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(211, 209, 209, 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, 1fr) 340px;
  gap: 28px;
  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;
  flex-wrap: wrap;
}

.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; }

/* Доска-слот */
.puzzle-board-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 560px;
  margin: 0 auto;
  background: #1a1008;
  border: 8px solid var(--c-board-frame, #2c1810);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0,0,0,0.4);
  container-type: inline-size;
}

/* Подсказка — яркая, показывается поверх слотов на 3 секунды */
.puzzle-hint-layer {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  pointer-events: none;
  z-index: 10;
  background: #1a1008;
  animation: hintAppear .2s ease;
}
.puzzle-hint-layer[hidden] { display: none; }

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

.puzzle-hint-layer .hint-sq {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 6cqw;
  line-height: 1;
}
.puzzle-hint-layer .hint-sq.light { background: var(--c-board-light, #e8d5b0); }
.puzzle-hint-layer .hint-sq.dark  { background: var(--c-board-dark, #5a4a42); }
.puzzle-hint-layer .hint-sq .piece { font-size: inherit; }
.puzzle-hint-layer .hint-sq .piece.white { color: #fff; }
.puzzle-hint-layer .hint-sq .piece.black { color: #1a1a1a; }

/* Слоты */
.puzzle-slot-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
}
.puzzle-slot-grid .slot {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed rgba(255,255,255,0.10);
  transition: all 0.15s ease;
}
.puzzle-slot-grid .slot.drag-over {
  background: rgba(34,197,94,0.2);
  box-shadow: inset 0 0 0 2px #22c55e;
}
.puzzle-slot-grid .slot.filled {
  border: 1px solid rgba(34,197,94,0.25);
}
.puzzle-slot-grid .slot.wrong {
  background: rgba(239,68,68,0.25);
  box-shadow: inset 0 0 0 2px #ef4444;
  animation: puzzleShake 0.4s ease;
}

@keyframes puzzleShake {
  0%,100% { transform: translateX(0); }
  25%     { transform: translateX(-4px); }
  75%     { transform: translateX(4px); }
}

/* Координаты на пустых слотах */
.slot-coords {
  width: 100%;
  height: 100%;
  display: grid;
  pointer-events: none;
  container-type: inline-size;
}
.slot-coord {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Fira Code', monospace;
  font-size: 22cqw;
  font-weight: 500;
  color: rgba(224, 176, 112, 0.35);
  letter-spacing: 0.02em;
  line-height: 1;
  user-select: none;
}

/* Кусочек 2×2 */
.puzzle-block {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  container-type: inline-size;
}
.puzzle-block .blk-sq {
  position: relative;   
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48cqw;
  line-height: 1;
  user-select: none;
}
.puzzle-block .blk-sq.light { background: var(--c-board-light, #e8d5b0); }
.puzzle-block .blk-sq.dark  { background: var(--c-board-dark, #5a4a42); }
.puzzle-block .blk-sq .piece { font-size: inherit; }
.puzzle-block .blk-sq .piece.white { color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.5); }
.puzzle-block .blk-sq .piece.black { color: #1a1a1a; text-shadow: 0 1px 1px rgba(255,255,255,0.2); }

/* Прогресс */
.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: 24px;
  font-weight: 600;
  color: #efe3d3;
  line-height: 1.2;
  margin: 0;
  padding-right: 40px;
}

.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-tray-label {
  display: flex;
  justify-content: space-between;
  font-family: 'Fira Code', monospace;
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #b39a80;
  margin: 4px 0 8px;
}
.puzzle-tray {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.puzzle-tray-piece {
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.10);
  background: #000;
  cursor: grab;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  box-shadow: 0 4px 10px rgba(0,0,0,0.35);
  user-select: none;
  -webkit-user-select: none;
  
}
.puzzle-tray-piece:hover {
  transform: translateY(-2px) scale(1.03);
  border-color: #b5722c;
  box-shadow: 0 8px 20px rgba(0,0,0,0.45);
  z-index: 5;
}
.puzzle-tray-piece:active { cursor: grabbing; }
.puzzle-tray-piece.dragging { opacity: 0.4; }
.puzzle-tray-piece.selected {
  border-color: #22c55e;
  box-shadow: 0 0 0 3px rgba(34,197,94,0.25);
  transform: translateY(-2px) scale(1.03);
}
.puzzle-tray-piece.used {
  opacity: 0.12;
  pointer-events: none;
  transform: scale(0.9);
}

/* Кнопки */
.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;
}

/* Мобильные */
@media (max-width: 900px) {
  .puzzle-board-wrap { max-width: 100%; }
}


.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.85;
  transform: scale(1.05);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 20px rgba(0,0,0,.45);
}

/* базовый размер — для лотка */
.blk-coord {
  position: absolute;
  bottom: 7cqw;
  right: 7cqw;
  font-size: 28cqw;
  line-height: 1;
  font-weight: 700;
  pointer-events: none;
  user-select: none;
  /* text-shadow: 0 0 2px rgba(0, 0, 0, 0.35); */
}
.blk-sq.light .blk-coord { color: rgba(90, 74, 58, 0.9); }
.blk-sq.dark  .blk-coord { color: rgba(236, 218, 185, 0.95); }
/* .blk-sq.dark .blk-coord {
  color: rgba(255, 255, 255, 0.55);
} */

/* на доске — меньше */
.slot .blk-coord {
  font-size: 9px;
  bottom: 1px;
  right: 2px;
}

/* other */
.puzzle-tray-piece,
.slot,
.puzzle-block,
.blk-sq {
  touch-action: none;
}