/* ==========================================================================
   GAME 05: MEMORY SHUFFLE STYLESHEET
   ========================================================================== */

.memory-shuffle-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 14px;
}

/* -------------------------------------------------------------
   HUD Header Styling
   ------------------------------------------------------------- */
.ms-hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 18px;
    background: var(--bg-surface, #10131B);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-subtle);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    gap: 12px;
    flex-wrap: wrap;
}

.ms-hud-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 150px;
}

.ms-challenge-meta {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ms-badge-category {
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--green, #47D18C);
    letter-spacing: 0.8px;
}

.ms-badge-diff {
    font-size: 0.68rem;
    font-weight: 800;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ms-badge-diff.diff-easy {
    background: rgba(71, 209, 140, 0.15);
    color: #47D18C;
    border: 1px solid rgba(71, 209, 140, 0.3);
}

.ms-badge-diff.diff-medium {
    background: rgba(245, 158, 11, 0.12);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.ms-badge-diff.diff-hard {
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.ms-puzzle-name {
    font-size: 0.95rem;
    color: var(--text-primary);
    font-weight: 700;
}

.ms-hud-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.ms-swaps-box {
    background: rgba(71, 209, 140, 0.12);
    padding: 6px 16px;
    border-radius: 20px;
    border: 1.5px solid var(--green, #47D18C);
    box-shadow: 0 4px 12px rgba(71, 209, 140, 0.15);
    display: flex;
    align-items: center;
    gap: 8px;
}

.ms-swaps-label {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--text-muted);
    letter-spacing: 1px;
}

.ms-swaps-badge {
    font-size: 1.2rem;
    font-weight: 900;
    color: var(--green, #47D18C);
    font-family: var(--font-display);
}

.ms-hud-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ms-hud-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.ms-stat-label {
    font-size: 0.65rem;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.8px;
}

.ms-stat-val {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* -------------------------------------------------------------
   Timer Pill & Pulse Warning
   ------------------------------------------------------------- */
.ms-timer-pill {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: rgba(71, 209, 140, 0.12);
    border: 1.5px solid var(--green, #47D18C);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--green, #47D18C);
    min-width: 95px;
    box-sizing: border-box;
    font-variant-numeric: tabular-nums;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

#ms-timer-val {
    font-variant-numeric: tabular-nums;
    display: inline-block;
    min-width: 1.8ch;
    text-align: center;
}

.ms-timer-unit {
    font-size: 0.8rem;
    font-weight: 600;
}

.ms-timer-pill.timer-warning {
    background: rgba(239, 68, 68, 0.15);
    border-color: #ef4444;
    color: #ef4444;
    animation: msPulse 1s infinite alternate;
}

.ms-timer-pill.timer-expired {
    background: rgba(239, 68, 68, 0.2);
    border-color: #ef4444;
    color: #ef4444;
}

@keyframes msPulse {
    from {
        transform: scale(1);
        box-shadow: 0 0 4px rgba(239, 68, 68, 0.3);
    }
    to {
        transform: scale(1.06);
        box-shadow: 0 0 14px rgba(239, 68, 68, 0.6);
    }
}

/* -------------------------------------------------------------
   Puzzle Arena
   ------------------------------------------------------------- */
.ms-arena {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    width: 100%;
    position: relative;
}

.ms-phase-title {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: 1.5px;
    color: var(--green, #47D18C);
    text-transform: uppercase;
    margin-bottom: 12px;
    text-align: center;
}

/* 1. Preview Box */
.ms-preview-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.ms-preview-countdown {
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--green, #47D18C);
    margin-bottom: 8px;
    animation: msPulse 1s infinite alternate;
}

.ms-preview-image-container {
    width: 100%;
    max-width: 500px;
    padding: 10px;
    background: var(--bg-surface, #10131B);
    border: 2px solid var(--border-subtle);
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    box-sizing: border-box;
}

.ms-preview-canvas, .ms-preview-img {
    border-radius: 10px;
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    object-fit: cover;
}

/* 2. Interactive Scrambled Grid */
.ms-puzzle-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    position: relative;
}

.ms-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 4px;
    width: 100%;
    max-width: 500px;
    aspect-ratio: 1 / 1;
    margin: 0 auto;
    background: var(--bg-surface, #10131B);
    border: 3px solid var(--border-subtle);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    touch-action: none;
    user-select: none;
}

.ms-grid-piece {
    width: 100%;
    height: 100%;
    cursor: pointer;
    box-sizing: border-box;
    border: 1px solid rgba(255, 79, 112, 0.15);
    transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.ms-grid-piece:hover:not(.selected) {
    transform: scale(1.03);
    border-color: var(--primary);
    z-index: 5;
}

.ms-grid-piece.selected {
    border: 3.5px solid var(--primary) !important;
    box-shadow: inset 0 0 15px rgba(255, 79, 112, 0.3), 0 0 15px rgba(255, 79, 112, 0.3);
    transform: scale(1.05);
    z-index: 10;
}

.ms-grid.locked {
    pointer-events: none;
    opacity: 0.85;
}

/* Solved & Timeout Overlays */
.ms-solved-overlay, .ms-timeout-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.92);
    font-size: 1.8rem;
    font-weight: 900;
    border-radius: 16px;
    z-index: 50;
    pointer-events: none;
    animation: msFadeIn 0.25s ease-out;
}

.ms-solved-overlay {
    color: var(--success);
    border: 2.5px solid var(--success);
    text-shadow: 0 0 15px rgba(16, 185, 129, 0.2);
}

.ms-timeout-overlay {
    color: var(--danger);
    border: 2.5px solid var(--danger);
    text-shadow: 0 0 15px rgba(239, 68, 68, 0.2);
}

@keyframes msFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* -------------------------------------------------------------
   Scoreboard Panel
   ------------------------------------------------------------- */
.ms-scores-panel {
    background: var(--bg-surface, #10131B);
    border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.08));
    border-radius: var(--border-radius);
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

.ms-scores-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    font-weight: 800;
}

.ms-player-scores {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.ms-score-card {
    background: var(--bg-card, #181C27);
    border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.08));
    border-radius: 8px;
    padding: 8px 14px;
    display: flex;
    flex-direction: column;
    min-width: 140px;
    gap: 4px;
}

.ms-score-card.self {
    border-color: var(--gold-primary, #F4B860);
    background: var(--bg-card, #181C27);
    box-shadow: 0 2px 8px rgba(244, 184, 96, 0.2);
}

.ms-score-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
}

.ms-score-name {
    font-weight: 700;
}

.ms-player-status-badge {
    font-size: 0.75rem;
    font-weight: 800;
}

.ms-player-status-badge.done {
    color: #10b981;
}

.ms-player-status-badge.solving {
    color: var(--text-muted);
}

.ms-score-val {
    color: var(--primary);
    font-weight: 800;
    font-size: 1rem;
}

/* -------------------------------------------------------------
   Round Results & Final Podium
   ------------------------------------------------------------- */
.ms-results-wrapper {
    background: var(--bg-surface, #10131B);
    border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.08));
    border-radius: 16px;
    padding: 25px 20px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
}

.ms-results-card, .ms-final-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.ms-results-top-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.ms-results-card-title {
    font-size: 1.5rem;
    letter-spacing: 2px;
    color: var(--text-color);
    text-transform: uppercase;
    font-weight: 800;
    margin-bottom: 12px;
}

.ms-results-row-image {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 20px;
}

.ms-results-canvas {
    border-radius: 10px;
    border: 2px solid var(--card-border);
    box-shadow: 0 4px 15px rgba(255, 79, 112, 0.08);
}

.ms-results-name-pill {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--primary);
    margin-top: 6px;
}

.ms-results-list {
    width: 100%;
    max-width: 580px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ms-results-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.02);
    border-left: 4px solid var(--card-border);
    font-size: 1rem;
}

.ms-results-row.completed {
    border-left-color: #10b981;
    background: rgba(16, 185, 129, 0.06);
}

.ms-results-row.failed {
    border-left-color: #ef4444;
    background: rgba(239, 68, 68, 0.04);
}

.ms-row-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ms-row-name {
    font-weight: 700;
}

.ms-row-moves {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
}

.ms-row-time {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.ms-row-points {
    font-weight: 800;
    color: var(--primary);
}

/* -------------------------------------------------------------
   Final Results Podium
   ------------------------------------------------------------- */
.ms-results-header {
    font-size: 1.1rem;
    letter-spacing: 2px;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.ms-results-complete-title {
    font-size: 2rem;
    font-weight: 900;
    color: var(--text-color);
    margin-bottom: 20px;
}

.ms-podium-container {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 12px;
    width: 100%;
    max-width: 580px;
    margin-bottom: 25px;
    min-height: 180px;
}

.ms-podium-slot {
    flex: 1;
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid var(--card-border);
    border-radius: 12px 12px 8px 8px;
    padding: 12px 8px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.ms-podium-slot.rank-1 {
    height: 190px;
    background: rgba(255, 215, 0, 0.08);
    border-color: #ffd700;
}

.ms-podium-slot.rank-2 {
    height: 155px;
    border-color: #c0c0c0;
}

.ms-podium-slot.rank-3 {
    height: 130px;
    border-color: #cd7f32;
}

.ms-podium-trophy {
    font-size: 1.4rem;
}

.ms-podium-trophy.rank-1 { color: #ffd700; }
.ms-podium-trophy.rank-2 { color: #a0a0a0; }
.ms-podium-trophy.rank-3 { color: #cd7f32; }

.ms-podium-rank {
    font-size: 1.6rem;
    font-weight: 900;
    color: var(--text-color);
}

.ms-podium-name {
    font-weight: 700;
    font-size: 0.95rem;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ms-podium-score {
    color: var(--primary);
    font-weight: 800;
    font-size: 0.85rem;
}

.ms-leaderboard-list {
    width: 100%;
    max-width: 580px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 20px;
}

.ms-leaderboard-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid var(--card-border);
    font-size: 0.95rem;
}

.ms-row-player {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ms-rank-badge {
    background: rgba(0, 0, 0, 0.06);
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
}

.ms-final-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    width: 100%;
    margin-top: 10px;
}

/* -------------------------------------------------------------
   Responsive Breakpoints (Tablet & 390px Mobile)
   ------------------------------------------------------------- */
@media (max-width: 768px) {
    .memory-shuffle-container,
    .ms-hud,
    .ms-grid,
    .ms-podium-container,
    .ms-leaderboard-list,
    .ms-timeout-card-content {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }

    .ms-hud-left,
    .ms-puzzle-name {
        min-width: 0;
        max-width: 100%;
        overflow-wrap: break-word;
        word-break: break-word;
    }

    .ms-hud {
        padding: 10px 14px;
        gap: 8px;
    }

    .ms-grid {
        max-width: 300px;
    }
}

@media (max-width: 480px) {
    .ms-hud {
        padding: 8px 10px;
        gap: 6px;
    }

    .ms-hud-left {
        min-width: 0;
    }

    .ms-badge-category {
        font-size: 0.68rem;
    }

    .ms-badge-diff {
        font-size: 0.6rem;
        padding: 1px 6px;
    }

    .ms-puzzle-name {
        font-size: 0.82rem;
    }

    .ms-swaps-box {
        padding: 4px 10px;
    }

    .ms-swaps-badge {
        font-size: 1.05rem;
    }

    .ms-timer-pill {
        padding: 4px 10px;
        font-size: 0.95rem;
    }

    .ms-grid {
        max-width: 280px;
    }

    .ms-preview-countdown {
        font-size: 2rem;
    }

    .ms-podium-container {
        gap: 6px;
        min-height: 150px;
    }

    .ms-podium-slot.rank-1 { height: 160px; }
}

/* -------------------------------------------------------------
   Round Results Image & In-Game Timeout / Loss Card
   ------------------------------------------------------------- */
.ms-results-img {
    width: 180px;
    height: 180px;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 14px;
    display: block;
    margin: 0 auto 10px auto;
    border: 3px solid var(--card-border);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.ms-timeout-card-content {
    background: var(--bg-surface, #10131B);
    border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.08));
    border-radius: 20px;
    padding: 24px 20px;
    text-align: center;
    max-width: 340px;
    width: 90%;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
    margin: 0 auto;
}

.ms-timeout-card-icon {
    font-size: 2.5rem;
    margin-bottom: 6px;
}

.ms-timeout-card-title {
    font-size: 1.6rem;
    font-weight: 900;
    color: #ef4444;
    margin: 0 0 4px 0;
    letter-spacing: 1px;
}

.ms-timeout-card-subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin: 0 0 14px 0;
}

.ms-timeout-card-badge {
    display: inline-block;
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
    font-weight: 800;
    font-size: 0.8rem;
    letter-spacing: 1.5px;
    padding: 4px 14px;
    border-radius: 12px;
    margin-bottom: 14px;
}

.ms-timeout-card-stats {
    display: flex;
    justify-content: space-around;
    background: var(--bg-card, #181C27);
    padding: 8px 14px;
    border-radius: 12px;
    font-weight: 700;
    color: var(--text-color);
    font-size: 0.85rem;
    margin-bottom: 10px;
    border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.08));
}

.ms-timeout-card-footer {
    font-size: 0.8rem;
    color: var(--text-muted, #9B9EAA);
    font-style: italic;
    margin: 0;
}

@media (max-width: 350px) {
    .ms-grid {
        max-width: 250px;
    }
}

