:root {
    --nine-ink: #29251f;
    --nine-muted: #665e52;
    --nine-accent: #a3472d;
    --nine-board: #d6c6aa;
    --nine-slot: #f5efe4;
}

.nine-square-main {
    width: min(1220px, calc(100% - 24px));
    margin-inline: auto;
    padding-bottom: 48px;
}

.puzzle-heading {
    text-align: center;
    max-width: 760px;
    margin: 8px auto 18px;
}

.puzzle-heading h1 {
    margin: 2px 0 8px;
    color: var(--nine-ink);
}

.puzzle-heading p:last-child,
.panel-heading p {
    color: var(--nine-muted);
}

.eyebrow {
    margin: 0;
    color: var(--nine-accent);
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
    font-size: .78rem;
}

.game-summary {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 18px;
    margin: 0 auto 18px;
    padding: 10px 16px;
    width: fit-content;
    max-width: 100%;
    border: 1px solid #d7cec0;
    border-radius: 999px;
    background: #fffdf9;
    color: var(--nine-muted);
}

#game-status {
    min-width: 190px;
    text-align: center;
}

.game-feedback {
    color: var(--nine-muted);
    text-align: center;
}

.game-feedback[hidden] { display: none; }

.play-area { display: block; }

.play-panel {
    min-width: 0;
}

.panel-heading {
    min-height: 58px;
    text-align: center;
}

.panel-heading h2,
.panel-heading p {
    margin: 0 0 4px;
}

.panel-heading strong { color: var(--nine-ink); }
.mobile-gesture-label { display: none; }

.puzzle-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    aspect-ratio: 1;
    width: 100%;
    max-width: 620px;
    margin-inline: auto;
}

.puzzle-board {
    gap: 0;
    padding: 4px;
    border: 3px solid #6d5a42;
    border-radius: 8px;
    background: var(--nine-board);
    box-shadow: 0 8px 24px #392d1d22;
}

.board-slot {
    position: relative;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    border: 1px dashed #9d8d76;
    background: var(--nine-slot);
}

.puzzle-board.is-swapping .board-slot {
    overflow: visible;
}

.puzzle-board.is-swapping {
    isolation: isolate;
}

.board-slot:focus-visible {
    outline: 3px solid #1261a0;
    outline-offset: 2px;
}

.pm-piece {
    position: relative;
    aspect-ratio: 1;
    min-width: 0;
    overflow: hidden;
    border: 2px solid #fff;
    border-radius: 5px;
    background: #dceef4;
    box-shadow: 0 2px 8px #30281d38;
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.board-slot > .pm-piece {
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

.pm-piece:focus-visible,
.pm-piece.is-selected {
    outline: none;
    z-index: 5;
}

.pm-piece:focus-visible::after,
.pm-piece.is-selected::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 6;
    border: 4px solid #1261a0;
    pointer-events: none;
}

.pm-piece.drag-ghost {
    position: fixed;
    z-index: 10000;
    margin: 0;
    cursor: grabbing;
    pointer-events: none;
    box-shadow: 0 14px 34px #21190f66;
}

.pm-piece.is-drag-source { opacity: .35; }

.piece-face {
    position: absolute;
    inset: 0;
    transform: rotate(var(--piece-rotation, 0deg));
    transition: transform 160ms ease;
}

.piece-face canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.game-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin: 22px 0;
}

.game-controls button,
.result-actions button {
    min-height: 44px;
    padding: 9px 18px;
}

.print-card {
    width: min(560px, 100%);
}

.print-choices {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin: 22px 0 16px;
}

.print-choice {
    display: grid;
    gap: 6px;
    min-height: 108px;
    padding: 16px;
    text-align: left;
}

.print-choice strong {
    font-size: 1.05rem;
}

.print-choice span {
    font-weight: 400;
}

.instructions-card {
    max-width: 780px;
    margin: 0 auto;
    border: 1px solid #d7cec0;
    border-radius: 10px;
    background: #fffdf9;
    padding: 12px 16px;
}

.instructions-card summary {
    cursor: pointer;
    font-weight: 800;
}

.instructions-card li + li {
    margin-top: 6px;
}

.result-overlay {
    position: fixed;
    inset: 0;
    z-index: 20000;
    display: grid;
    place-items: center;
    padding: 20px;
    background: #1b1711aa;
}

.result-overlay[hidden] {
    display: none;
}

.result-card {
    position: relative;
    z-index: 1;
    overflow: hidden;
    width: min(480px, 100%);
    padding: 28px;
    border-radius: 16px;
    background: #fffdf9;
    text-align: center;
    box-shadow: 0 20px 70px #0007;
}

.result-kicker {
    color: #9c3e27;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.victory-stats {
    font-weight: 700;
}

.result-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.primary-action {
    background: #9c3e27;
    color: #fff;
}

.confetti {
    position: absolute;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.confetti-piece {
    position: absolute;
    top: -16px;
    width: 9px;
    height: 16px;
    animation: nine-confetti 2.8s ease-in forwards;
}

@keyframes nine-confetti {
    to { transform: translate(var(--drift), calc(100vh + 32px)) rotate(720deg); opacity: .15; }
}

.celebration-balloon {
    position: absolute;
    bottom: -90px;
    width: 44px;
    height: 56px;
    border-radius: 52% 52% 48% 48%;
    background: var(--balloon-color);
    box-shadow: inset -8px -10px 0 #0002, inset 7px 5px 0 #fff4;
    animation: nine-balloon-rise var(--balloon-duration, 4s) ease-out forwards;
}

.celebration-balloon::before {
    content: "";
    position: absolute;
    left: 18px;
    bottom: -6px;
    width: 9px;
    height: 9px;
    background: var(--balloon-color);
    transform: rotate(45deg);
}

.celebration-balloon::after {
    content: "";
    position: absolute;
    left: 22px;
    bottom: -58px;
    width: 1px;
    height: 54px;
    background: #fff9;
}

@keyframes nine-balloon-rise {
    to { transform: translateY(calc(-100vh - 150px)) rotate(var(--balloon-sway)); }
}

@media (max-width: 760px) {
    .site-frame[data-page="nine-squares"] .site-nav {
        display: none;
    }

    .site-frame[data-page="nine-squares"] .header-inner {
        min-height: 54px;
        padding: 6px 10px;
        grid-template-columns: auto minmax(0, 1fr);
    }

    .site-frame[data-page="nine-squares"] .brand-mark {
        width: 30px;
        height: 30px;
    }

    .nine-square-main {
        width: min(100% - 12px, 620px);
        padding-bottom: 18px;
    }

    .nine-square-main > .back-link {
        display: inline-flex;
        align-items: center;
        min-height: 44px;
        margin: 4px 0 0;
        font-weight: 800;
    }

    .puzzle-heading .eyebrow,
    .puzzle-heading p:last-child {
        display: none;
    }

    .puzzle-heading {
        margin: 4px auto;
    }

    .puzzle-heading h1 {
        margin: 0;
        font-size: 1.3rem;
    }

    .game-summary {
        gap: 4px 10px;
        margin-bottom: 4px;
        padding: 4px 10px;
        font-size: .82rem;
    }

    .panel-heading {
        min-height: auto;
        margin-bottom: 4px;
    }

    .panel-heading h2 {
        display: none;
    }

    .panel-heading p {
        margin: 0;
        font-size: .86rem;
        line-height: 1.25;
    }

    .puzzle-board {
        width: min(96vw, 560px);
    }

    .game-summary { border-radius: 12px; }
    #game-status { min-width: 0; }
    .desktop-gesture-label { display: none; }
    .mobile-gesture-label { display: inline; }
}

@media (max-width: 520px) {
    .print-choices {
        grid-template-columns: 1fr;
    }

    .print-choice {
        min-height: 84px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .piece-face { transition: none; }
    .confetti-piece,
    .celebration-balloon { animation: none; display: none; }
}
