/* ============================================================================
 *  game.css — layout & components for the puzzle screen (index.html).
 * ========================================================================== */

html, body {
    height: 100%;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg);
    background-image: radial-gradient(var(--muted) 2px, transparent 2px);
    background-size: 26px 26px;
    color: var(--fg);
    height: 100vh;
    /* Use dynamic viewport height where supported so the board fits under mobile
     * browser chrome (address bar) without being clipped. */
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
}

.game-wrapper {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Top bar: brand + player info + navigation */
.topbar {
    width: 100%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 24px;
    background: rgba(255, 255, 255, 0.8);
    border-bottom: 1px solid rgba(46, 42, 38, 0.1);
    flex-wrap: wrap;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.chip {
    padding: 9px 18px;
    border-radius: var(--radius-pill);
    background: var(--card);
    box-shadow: var(--shadow-sm);
    font-size: 0.85em;
    font-weight: 500;
}

.chip b {
    font-weight: 700;
    color: var(--red);
}

.game-area {
    position: relative;
    width: 100%;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.puzzle-board-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

#puzzleCanvas {
    display: block;
    background: #ffffff;
    box-shadow: var(--shadow);
    cursor: crosshair;
    z-index: 5;
    position: relative;
}

.pieces-scattered {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.puzzle-piece {
    position: absolute;
    cursor: grab;
    background: transparent;
    /* Shadow follows the jigsaw shape (the canvas is transparent around it). */
    filter: drop-shadow(0 3px 4px rgba(46, 42, 38, 0.28));
    transition: transform 0.2s ease-out;
    pointer-events: auto;
    z-index: 20;
    /* Touch: the piece handles its own drag, so suppress the browser's
     * scroll/zoom/selection gestures and the blue tap highlight. */
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

.puzzle-piece:hover {
    transform: translateY(-4px);
    z-index: 30;
}

.puzzle-piece.grabbed {
    cursor: grabbing;
    z-index: 1000;
    transform: translateY(-6px) scale(1.05);
}

/* Once a piece sits in the grid, drop the shadow so the assembled image is
 * seamless. The piece seams still show from the outline stroked onto each
 * piece's canvas. */
.puzzle-piece.in-cell {
    filter: none;
}

.puzzle-piece.returning {
    transition: left 0.25s ease-out, top 0.25s ease-out;
    z-index: 900;
}

.puzzle-piece.snapping {
    animation: snapIn 0.18s ease-out;
}

@keyframes snapIn {
    0% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

.controls {
    display: flex;
    gap: 16px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    flex-shrink: 0;
    padding: 20px 0 30px;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(46, 42, 38, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

.modal.hidden {
    display: none;
}

/* Full-screen confetti, in front of the celebration card but click-through. */
.confetti-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 3002;
}

.modal-content {
    position: relative;
    background: var(--card);
    padding: 40px 46px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    text-align: center;
    animation: popIn 0.25s ease-out;
    max-width: min(92vw, 820px);
    max-height: 92vh;
    overflow-y: auto;
    z-index: 3001;
}

@keyframes popIn {
    0% { transform: scale(0.9); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes revealUp {
    0% { opacity: 0; transform: translateY(14px); }
    100% { opacity: 1; transform: translateY(0); }
}

.modal-content h2 {
    font-size: 2.6em;
    font-weight: 700;
    color: var(--red);
    margin-bottom: 10px;
    animation: popIn 0.4s ease-out;
}

.victory-points {
    font-family: var(--font-display);
    font-size: 1.6em;
    font-weight: 700;
    color: var(--orange);
    margin-bottom: 8px;
}

/* Showcase (annotated image) — revealed after the celebration beat. */
.showcase {
    display: none;
    margin: 18px 0 26px;
}

.modal-content.show-marked .showcase {
    display: block;
    animation: revealUp 0.5s ease-out;
}

.showcase-img {
    display: block;
    width: 100%;
    max-width: 720px;
    max-height: 52vh;
    margin: 0 auto;
    object-fit: contain;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.showcase-caption {
    margin-top: 14px;
    font-size: 1.05em;
    font-weight: 600;
    color: var(--fg);
}

/* The Next button only appears once the child has seen the features. */
#playAgainBtn {
    display: none;
}

.modal-content.show-next #playAgainBtn {
    display: inline-block;
    animation: revealUp 0.4s ease-out;
}

@media (max-width: 768px) {
    /* NOTE: do NOT set a CSS width/height on #puzzleCanvas here — the canvas is
     * sized in JS to exact buffer pixels, and CSS scaling would break the
     * piece-drop coordinate math. renderPuzzleBoard() handles mobile sizing. */

    .topbar {
        padding: 8px 10px;
        gap: 6px;
    }

    /* The logo takes space we'd rather give to the board on a phone. */
    .topbar-brand {
        display: none;
    }

    .topbar-right {
        width: 100%;
        gap: 6px;
        justify-content: center;
    }

    .chip {
        padding: 6px 11px;
        font-size: 0.72em;
    }

    .btn-sm {
        padding: 7px 14px;
        font-size: 0.75em;
    }

    .controls {
        padding: 10px 0 16px;
    }

    .modal-content {
        padding: 26px 20px;
    }

    .modal-content h2 {
        font-size: 1.9em;
    }

    .victory-points {
        font-size: 1.3em;
    }

    .showcase {
        margin: 12px 0 20px;
    }

    .showcase-caption {
        font-size: 0.95em;
    }
}

/* Very small phones: tighten the info chips further so they fit one row. */
@media (max-width: 400px) {
    .chip {
        padding: 5px 9px;
        font-size: 0.66em;
    }

    .topbar-right {
        gap: 4px;
    }
}
