.puzzle-panel {
    max-width: 620px;
    margin: 22px auto 0;
}

.puzzle-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    width: min(100%, 560px);
    aspect-ratio: 1 / 1;
    margin: 0 auto;
    padding: 4px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.85);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
}

.puzzle-piece {
    min-width: 0;
    border: 0;
    border-radius: 6px;
    background-image: url("../img/joc-de-pistes/portal-pedro-ager.jpg");
    background-repeat: no-repeat;
    background-size: 300% 400%;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.75);
    cursor: pointer;
    touch-action: manipulation;
    transition: transform 160ms ease, box-shadow 160ms ease;
}

.puzzle-piece:hover,
.puzzle-piece:focus-visible {
    transform: scale(0.985);
    outline: none;
    box-shadow: inset 0 0 0 2px #111, 0 0 0 3px rgba(255, 255, 255, 0.9);
}

.puzzle-piece.is-selected {
    transform: scale(0.96);
    box-shadow: inset 0 0 0 3px #111, 0 0 0 4px #ffc107;
}

.puzzle-board.is-solved .puzzle-piece {
    cursor: default;
    transform: none;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.45);
}

.puzzle-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 12px;
}

.puzzle-clue {
    display: none;
    max-width: 620px;
    margin: 18px auto 0;
    padding: 0 12px;
    text-align: center;
}

.puzzle-clue.is-visible {
    display: block;
}

.puzzle-status {
    min-height: 24px;
    margin: 10px 0 0;
    font-weight: 700;
}

.puzzle-help {
    border: 0;
    padding: 4px 6px;
    color: rgba(0, 0, 0, 0.68);
    background: transparent;
    font-size: 0.95rem;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.puzzle-help:focus-visible {
    outline: 2px solid #111;
    outline-offset: 3px;
}

.story-panel {
    max-width: 620px;
    margin: 0 auto 24px;
    text-align: center;
}

.story-panel img {
    margin-bottom: 14px;
}

.story-panel h3 {
    margin-bottom: 12px;
    font-size: 1.5rem;
}

.story-panel p {
    margin-bottom: 8px;
    font-size: 1.05rem;
}

.arrival-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.arrival-image {
    width: min(100%, 620px);
    max-height: 58vh;
    margin: 18px auto 18px;
    object-fit: contain;
}

.choice-form {
    max-width: 620px;
    margin: 0 auto;
}

.choice-question {
    margin-bottom: 18px;
    text-align: left;
}

.choice-question p {
    margin-bottom: 8px;
    font-size: 1.08rem;
    font-weight: 800;
}

.choice-list {
    display: grid;
    gap: 8px;
}

.choice-list label {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 10px 12px;
    border: 2px solid rgba(0, 0, 0, 0.18);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.76);
    font-weight: 700;
}

.choice-list input {
    width: 1.1rem;
    height: 1.1rem;
    flex: 0 0 auto;
}

.choice-list label:has(input:checked) {
    border-color: #111;
    background: #fff8da;
}

.block-heading {
    position: relative;
}

.clue-progress {
    display: flex;
    align-items: center;
    width: max-content;
    min-height: 34px;
    margin: 0 0 14px auto;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(255, 248, 218, 0.92);
    color: #1f2328;
    font-size: 0.95rem;
    font-weight: 800;
}

.puzzle-win {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(0, 0, 0, 0.42);
}

.puzzle-win[hidden] {
    display: none;
}

.puzzle-win-box {
    width: min(100%, 420px);
    padding: 30px 22px 22px;
    border-radius: 14px;
    color: #111;
    background: #fff8da;
    text-align: center;
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.3);
    animation: puzzleWinPop 240ms ease-out;
}

.puzzle-win-kicker {
    margin: 0 0 6px;
    font-size: clamp(2.4rem, 12vw, 4.6rem);
    line-height: 1;
    font-weight: 800;
}

.puzzle-win-box h2 {
    margin: 0 0 10px;
    font-size: clamp(1.45rem, 7vw, 2.2rem);
}

.puzzle-win-box p {
    margin-bottom: 10px;
    font-size: 1.25rem;
}

.puzzle-win-alert {
    padding: 10px 12px;
    border-radius: 8px;
    background: #ffc107;
    font-weight: 900;
}

.puzzle-score-message {
    display: inline-block;
    margin: 6px auto 16px;
    padding: 10px 16px;
    border: 2px solid #ffc107;
    border-radius: 8px;
    background: #fff;
    color: #111;
    font-size: clamp(1.1rem, 4vw, 1.45rem);
    font-weight: 900;
}

.final-stats {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: 18px auto 26px;
    max-width: 620px;
}

.final-stats p {
    margin: 0;
    padding: 18px 14px;
    border: 3px solid #111;
    border-radius: 12px;
    background: #fff8da;
    box-shadow: 0 8px 0 rgba(0, 0, 0, 0.16);
}

.final-stats span {
    display: block;
    margin-bottom: 4px;
    color: rgba(0, 0, 0, 0.66);
    font-size: clamp(1rem, 4vw, 1.25rem);
    font-weight: 800;
}

.final-stats strong {
    display: block;
    color: #111;
    font-size: clamp(2.2rem, 10vw, 4rem);
    font-weight: 900;
    line-height: 1;
}

.rating-choice {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.rating-choice label {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 54px;
    border: 2px solid rgba(0, 0, 0, 0.16);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.76);
    color: #111;
    font-size: 1.35rem;
    font-weight: 900;
}

.rating-choice .rating-low {
    background: #f8d7da;
}

.rating-choice .rating-mid {
    background: #fff3cd;
}

.rating-choice .rating-high {
    background: #d1e7dd;
}

.rating-choice input {
    margin-right: 6px;
}

.rating-choice label:has(input:checked) {
    border-color: #111;
    box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.12);
}

.local-server-warning {
    margin: 0 auto 18px;
    max-width: 760px;
    padding: 12px 14px;
    border: 2px solid #dc3545;
    border-radius: 8px;
    background: #f8d7da;
    color: #58151c;
    font-weight: 800;
    text-align: center;
}

.final-celebration {
    position: relative;
    width: min(70vw, 360px);
    height: 94px;
    margin: 0 auto 10px;
}

.final-celebration::before {
    content: "";
    position: absolute;
    inset: 18px 50% auto auto;
    width: 88px;
    height: 88px;
    border-radius: 50%;
    background:
        radial-gradient(circle at center, #fff8da 0 30%, transparent 31%),
        conic-gradient(#dc3545, #ffc107, #198754, #0d6efd, #fd7e14, #dc3545);
    transform: translateX(50%);
    animation: finalSpin 4s linear infinite;
}

.final-celebration::after {
    content: "!";
    position: absolute;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    color: #111;
    font-size: 3.3rem;
    font-weight: 900;
    line-height: 1;
}

.final-celebration span {
    position: absolute;
    top: 52px;
    left: 50%;
    width: 14px;
    height: 14px;
    border-radius: 4px;
    background: #ffc107;
    animation: finalConfetti 1.8s ease-in-out infinite;
}

.final-celebration span:nth-child(1) {
    --x: -135px;
    --y: -44px;
    background: #dc3545;
}

.final-celebration span:nth-child(2) {
    --x: -82px;
    --y: -72px;
    background: #0d6efd;
    animation-delay: 120ms;
}

.final-celebration span:nth-child(3) {
    --x: -35px;
    --y: -36px;
    background: #198754;
    animation-delay: 240ms;
}

.final-celebration span:nth-child(4) {
    --x: 45px;
    --y: -68px;
    background: #ffc107;
    animation-delay: 360ms;
}

.final-celebration span:nth-child(5) {
    --x: 92px;
    --y: -34px;
    background: #fd7e14;
    animation-delay: 480ms;
}

.final-celebration span:nth-child(6) {
    --x: 136px;
    --y: -76px;
    background: #6f42c1;
    animation-delay: 600ms;
}

.celebration-burst {
    position: relative;
    width: 132px;
    height: 42px;
    margin: -8px auto 8px;
}

.celebration-burst span {
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    background: #ffc107;
    opacity: 0;
    animation: celebrationPop 900ms ease-out both;
}

.celebration-burst span:nth-child(1) {
    background: #dc3545;
    transform: translateX(-50%) rotate(12deg);
}

.celebration-burst span:nth-child(2) {
    background: #0d6efd;
    animation-delay: 80ms;
}

.celebration-burst span:nth-child(3) {
    background: #198754;
    animation-delay: 150ms;
}

.celebration-burst span:nth-child(4) {
    background: #ffc107;
    animation-delay: 210ms;
}

.celebration-burst span:nth-child(5) {
    background: #fd7e14;
    animation-delay: 270ms;
}

.puzzle-win-image {
    display: block;
    width: min(100%, 260px);
    aspect-ratio: 1 / 1;
    margin: 0 auto 12px;
    border-radius: 8px;
    object-fit: cover;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
}

.puzzle-win-close {
    border: 0;
    margin-top: 14px;
    padding: 4px 6px;
    color: rgba(0, 0, 0, 0.65);
    background: transparent;
    text-decoration: underline;
    text-underline-offset: 3px;
}

@keyframes puzzleWinPop {
    from {
        opacity: 0;
        transform: translateY(14px) scale(0.94);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes celebrationPop {
    0% {
        opacity: 0;
        transform: translate(-50%, 18px) scale(0.6) rotate(0deg);
    }

    24% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        transform: translate(calc(-50% + var(--x, 0px)), var(--y, -34px)) scale(1) rotate(120deg);
    }
}

@keyframes finalSpin {
    to {
        transform: translateX(50%) rotate(360deg);
    }
}

@keyframes finalConfetti {
    0%, 100% {
        opacity: 0.2;
        transform: translate(-50%, 0) scale(0.7) rotate(0deg);
    }

    45% {
        opacity: 1;
        transform: translate(calc(-50% + var(--x)), var(--y)) scale(1.1) rotate(160deg);
    }
}

@media (max-width: 575px) {
    .final-stats {
        grid-template-columns: 1fr;
    }
}

.celebration-burst span:nth-child(1) {
    --x: -52px;
    --y: -24px;
}

.celebration-burst span:nth-child(2) {
    --x: -24px;
    --y: -42px;
}

.celebration-burst span:nth-child(3) {
    --x: 0px;
    --y: -30px;
}

.celebration-burst span:nth-child(4) {
    --x: 28px;
    --y: -44px;
}

.celebration-burst span:nth-child(5) {
    --x: 54px;
    --y: -26px;
}

@media (max-width: 420px) {
    .puzzle-board {
        gap: 3px;
        padding: 3px;
        border-radius: 8px;
    }

    .puzzle-piece {
        border-radius: 4px;
    }
}
