/* =========================================
   Jigsaw Puzzle Styles
   ========================================= */

.jigsaw-hint {
    font-size: 0.85rem;
    color: var(--depths);
    opacity: 0.8;
}

#jigsaw-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

/* ---- Board ---- */
#jigsaw-board {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: repeat(5, 1fr);
    gap: 1px;
    width: 100%;
    max-width: 270px;
    /* 6 cols × 5 rows, image is 2:3 → board ratio = 6/5 × (1440/2160) = 4/5 */
    aspect-ratio: 4 / 5;
    background: var(--drift);
    border: 3px solid var(--depths);
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}

.board-cell {
    position: relative;
    background: rgba(200, 218, 245, 0.3);
    border: none;
    transition: background 0.2s ease;
}

/* Highlight cell when a piece hovers over it */
.board-cell.hover-target {
    background: rgba(163, 183, 216, 0.5);
    border-color: var(--horizon);
}

/* Cell has a placed piece */
.board-cell.filled {
    border-color: transparent;
}

.board-cell.filled::before {
    opacity: 0;
}

/* ---- Placed piece inside a cell ---- */
.placed-piece {
    position: absolute;
    inset: 0;
    background-image: var(--jigsaw-img);
    background-size: 600% 500%;
    animation: pieceSnap 0.3s ease;
}

@keyframes pieceSnap {
    0%   { transform: scale(1.1); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

/* ---- Counter ---- */
#jigsaw-counter {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--depths);
    text-align: center;
}

/* ---- Piece tray ---- */
#jigsaw-tray {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    width: 100%;
    max-width: 340px;
    min-height: 80px;
    padding: 10px 6px;
    background: var(--white);
    border: 2px solid var(--drift);
    border-radius: 12px;
}

/* ---- Tray piece (thumbnail) ---- */
.tray-piece {
    width: 40px;
    height: 48px;
    background-image: var(--jigsaw-img);
    background-size: 600% 500%;
    border: 2px solid var(--drift);
    border-radius: 6px;
    cursor: grab;
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    user-select: none;
}

.tray-piece:active {
    cursor: grabbing;
}

.tray-piece.selected {
    border-color: var(--horizon);
    box-shadow: 0 0 0 3px rgba(107, 126, 178, 0.4);
    transform: scale(1.05);
}

/* ---- Dragging ghost ---- */
.drag-ghost {
    position: fixed;
    z-index: 2000;
    pointer-events: none;
    opacity: 0.9;
    border: 2px solid var(--horizon);
    border-radius: 6px;
    box-shadow: 0 6px 20px rgba(27, 42, 74, 0.35);
    transition: none;
}

/* ---- Shake for wrong placement ---- */
@keyframes wrongShake {
    0%, 100% { transform: translateX(0); }
    25%      { transform: translateX(-6px); }
    50%      { transform: translateX(6px); }
    75%      { transform: translateX(-4px); }
}

.tray-piece.wrong {
    animation: wrongShake 0.3s ease;
    border-color: #d9534f;
}

/* ---- Win state ---- */
#jigsaw-board.complete {
    border-color: var(--gold);
    box-shadow: 0 0 16px var(--gold), 0 0 32px rgba(245, 214, 128, 0.4);
    animation: boardGlow 2s ease-in-out infinite alternate;
}

@keyframes boardGlow {
    0%   { box-shadow: 0 0 8px var(--gold), 0 0 16px rgba(245, 214, 128, 0.3); }
    100% { box-shadow: 0 0 20px var(--gold-bright), 0 0 40px rgba(245, 214, 128, 0.6); }
}

/* Empty tray after completion */
#jigsaw-tray:empty {
    display: none;
}
