:root {
    color-scheme: dark;
}

body {
    font-family: 'Orbitron', system-ui, sans-serif;
}

.stats-grid {
    width: 100%;
}

.stat-label {
    display: block;
    letter-spacing: 0.32em;
}

.stat-value {
    display: block;
}

.puzzle-shell {
    position: relative;
    width: min(100%, 520px);
    margin: 0 auto;
    padding: 18px;
    border-radius: 28px;
    background: linear-gradient(145deg, rgba(30, 41, 59, 0.8), rgba(15, 23, 42, 0.8));
    border: 1px solid rgba(148, 163, 184, 0.15);
    box-shadow: 0 20px 60px -35px rgba(14, 165, 233, 0.45);
}

.puzzle-board {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 24px;
    background: radial-gradient(circle at 25% 25%, rgba(148, 163, 184, 0.18), rgba(30, 41, 59, 0.45));
    overflow: hidden;
}

.puzzle-board::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    border-radius: 24px;
    border: 1px solid rgba(148, 163, 184, 0.2);
}

[data-info-panels] {
    width: 100%;
}

.info-panel {
    border-radius: 24px;
    border: 1px solid rgba(148, 163, 184, 0.15);
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(12px);
    box-shadow: 0 20px 60px -30px rgba(56, 189, 248, 0.25);
    overflow: hidden;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.info-panel summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    list-style: none;
    cursor: pointer;
    padding: 20px 24px;
    font-size: 0.7rem;
    letter-spacing: 0.35em;
    text-transform: uppercase;
    font-weight: 600;
    color: rgba(125, 211, 252, 0.85);
    background: rgba(15, 23, 42, 0.35);
}

.info-panel summary::-webkit-details-marker {
    display: none;
}

.info-panel[data-info-panel="scores"] summary {
    color: rgba(253, 224, 71, 0.85);
}

.info-panel[data-info-panel="tips"] summary {
    color: rgba(16, 185, 129, 0.85);
}

.info-panel-title {
    flex: 1;
}

.info-panel-chevron {
    font-size: 0.9rem;
    transition: transform 0.2s ease;
}

.info-panel[open] .info-panel-chevron {
    transform: rotate(180deg);
}

.info-panel-body {
    padding: 20px 24px 24px;
}

.info-panel-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 12px;
}

.info-panel-clear {
    font-size: 0.65rem;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    color: rgba(248, 250, 252, 0.75);
    border: 1px solid rgba(244, 114, 182, 0.4);
    background: rgba(236, 72, 153, 0.18);
    border-radius: 999px;
    padding: 8px 16px;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.info-panel-clear:hover {
    color: rgba(248, 250, 252, 0.95);
    background: rgba(244, 63, 94, 0.25);
    border-color: rgba(244, 63, 94, 0.55);
}

.puzzle-tile {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 18px;
    background: linear-gradient(160deg, rgba(56, 189, 248, 0.92), rgba(129, 140, 248, 0.92));
    color: #0f172a;
    font-weight: 700;
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    text-shadow: 0 8px 25px rgba(14, 165, 233, 0.4);
    box-shadow: 0 18px 35px rgba(14, 165, 233, 0.25);
    cursor: pointer;
    user-select: none;
    transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.22s ease, background 0.22s ease;
}

.puzzle-tile:focus-visible {
    outline: 3px solid rgba(251, 191, 36, 0.85);
    outline-offset: 3px;
}

.puzzle-tile:hover {
    background: linear-gradient(160deg, rgba(125, 211, 252, 0.96), rgba(165, 180, 252, 0.96));
    box-shadow: 0 22px 45px rgba(59, 130, 246, 0.45);
}

.puzzle-tile.movable::after {
    content: '';
    position: absolute;
    inset: 6px;
    border-radius: 14px;
    border: 1px dashed rgba(248, 250, 252, 0.5);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.puzzle-tile.movable:hover::after,
.puzzle-tile.movable:focus-visible::after {
    opacity: 1;
}

.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 40;
}

.modal.hidden {
    pointer-events: none;
    opacity: 0;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 23, 0.75);
    backdrop-filter: blur(12px);
}

.modal-content {
    position: relative;
    width: min(92vw, 420px);
    border-radius: 28px;
    overflow: hidden;
    border: 1px solid rgba(148, 163, 184, 0.25);
    background: rgba(15, 23, 42, 0.9);
    box-shadow: 0 25px 80px rgba(14, 165, 233, 0.25);
    transform: translateY(40px);
    opacity: 0;
    transition: opacity 0.24s ease, transform 0.24s ease;
}

.modal:not(.hidden) .modal-content {
    transform: translateY(0);
    opacity: 1;
}

@media (max-width: 640px) {
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .stat-label {
        font-size: 0.6rem;
        letter-spacing: 0.24em;
    }

    .stat-value {
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    .puzzle-shell {
        padding: 14px;
        border-radius: 22px;
    }

    .puzzle-board {
        border-radius: 20px;
    }

    .info-panel summary {
        padding: 16px 18px;
        font-size: 0.58rem;
        letter-spacing: 0.18em;
        flex-wrap: wrap;
        row-gap: 6px;
    }

    .info-panel-body {
        padding: 16px 18px 18px;
    }

    .modal-content {
        width: min(95vw, 380px);
    }

    .stat-label {
        font-size: 0.52rem;
        letter-spacing: 0.16em;
    }

    .stat-value {
        font-size: 0.95rem;
    }
}

@media (max-width: 640px) {
    .puzzle-shell {
        padding: 14px;
    }

    .info-panel summary {
        padding: 16px 20px;
    }

    .info-panel-body {
        padding: 16px 20px 20px;
    }
}

.modal-inner {
    padding: 32px;
}

.modal-eyebrow {
    font-size: 11px;
    letter-spacing: 0.4em;
    text-transform: uppercase;
    color: rgba(56, 189, 248, 0.76);
}

.modal-title {
    margin-top: 12px;
    font-size: clamp(1.5rem, 5vw, 2.2rem);
    font-weight: 600;
    color: #ffffff;
}

.modal-body {
    margin-top: 14px;
    font-size: 0.95rem;
    line-height: 1.6;
    color: rgba(226, 232, 240, 0.9);
}

.modal-actions {
    margin-top: 28px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.modal-button {
    flex: 1 1 auto;
    min-width: 120px;
    border-radius: 999px;
    padding: 12px 18px;
    font-size: 0.75rem;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    font-weight: 600;
    border: 1px solid rgba(148, 163, 184, 0.35);
    background: rgba(30, 64, 175, 0.85);
    color: #ffffff;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.modal-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 25px rgba(59, 130, 246, 0.4);
}

.modal-button.secondary {
    background: rgba(15, 23, 42, 0.87);
    color: rgba(226, 232, 240, 0.9);
}

.modal-button.danger {
    background: rgba(190, 24, 93, 0.88);
    border-color: rgba(244, 63, 94, 0.6);
}

@media (max-width: 768px) {
    .puzzle-shell {
        padding: 12px;
        border-radius: 20px;
        max-width: 100%;
    }

    .puzzle-board {
        border-radius: 16px;
    }

    .puzzle-tile {
        border-radius: 12px;
        font-size: 1.25rem;
    }

    .info-panel {
        border-radius: 16px;
    }

    .info-panel summary {
        padding: 12px 16px;
        font-size: 0.65rem;
        letter-spacing: 0.25em;
        min-height: 44px;
    }

    .info-panel-body {
        padding: 12px 16px 16px;
    }

    .info-panel-clear {
        width: 100%;
        text-align: center;
    }

    /* Mobile button tap targets */
    button,
    #restartStage,
    #shuffleBoard,
    #resetRun,
    #clearScores {
        min-height: 44px;
        touch-action: manipulation;
    }
    
    /* Compact summary sections */
    details summary {
        min-height: 44px;
        display: flex;
        align-items: center;
        position: relative;
    }
    
    details summary::after {
        content: '▼';
        position: absolute;
        right: 16px;
        font-size: 10px;
        transition: transform 0.3s ease;
    }
    
    details[open] summary::after {
        transform: rotate(180deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .puzzle-tile,
    .modal-content,
    .modal-button,
    .modal-button:hover {
        transition: none !important;
    }
}
