/* ---------- 文字パズル画面 ---------- */

.puzzle-work {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 40%);
  gap: 14px;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
}

.puzzle-board {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  align-self: center;
  justify-self: center;
  width: min(100%, 560px);
  height: auto;
  aspect-ratio: 1;
  flex: 0 0 auto;
  overflow: hidden;
  min-height: 0;
  border: 6px solid rgba(255, 255, 255, 0.94);
  border-radius: 8px;
  background: #fffdf6;
  box-shadow: var(--shadow);
}

.puzzle-slot {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  border: 0;
  background:
    linear-gradient(90deg, rgba(39, 50, 72, 0.045) 1px, transparent 1px),
    linear-gradient(rgba(39, 50, 72, 0.045) 1px, transparent 1px),
    rgba(255, 255, 255, 0.56);
  background-size: 36px 36px;
}

.puzzle-slot.over {
  background-color: rgba(109, 227, 179, 0.18);
}

.puzzle-tray {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  align-content: stretch;
  gap: 12px;
  min-height: 0;
  padding: 12px;
  border: 6px solid rgba(255, 255, 255, 0.88);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow);
}

.puzzle-home-slot {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  border: 2px dashed rgba(39, 50, 72, 0.12);
  border-radius: 8px;
  background: rgba(255, 248, 231, 0.72);
}

.puzzle-home-slot.over {
  background: rgba(114, 201, 255, 0.18);
}

.puzzle-piece {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  padding: 0;
  margin: 0;
  background: #fffdf6;
  box-shadow: 0 12px 22px rgba(39, 50, 72, 0.14);
  cursor: grab;
  line-height: 0;
  touch-action: none;
}

.puzzle-piece:active,
.puzzle-piece.dragging {
  cursor: grabbing;
  transform: scale(0.98);
}

.puzzle-piece img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.puzzle-slot .puzzle-piece,
.puzzle-home-slot .puzzle-piece {
  width: 100%;
  height: 100%;
  border-radius: 0;
  box-shadow: none;
}

.puzzle-slot .puzzle-piece img {
  object-fit: fill;
}

/* 2x2 の継ぎ目を 1px 重ねて隠す */
.puzzle-slot:nth-child(odd) .puzzle-piece {
  width: calc(100% + 1px);
}

.puzzle-slot:nth-child(even) .puzzle-piece {
  width: calc(100% + 1px);
  transform: translateX(-1px);
}

@media (max-width: 760px) {
  .puzzle-work {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    align-content: start;
  }

  .puzzle-board {
    width: min(calc(100svw - 24px), calc(100svh - 320px));
    max-width: 430px;
  }

  .puzzle-tray {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    padding: 8px;
    align-self: stretch;
  }
}
