/* ═══════════════════════════════════════════════════════
   MODALS — Premium glassmorphism overlays
   Fixed for mobile: buttons always visible, content scrollable
   ═══════════════════════════════════════════════════════ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(20, 12, 4, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    padding: var(--space-md);
}

.modal-overlay.visible {
    display: flex;
}

.modal-box {
    background: linear-gradient(180deg, rgba(60, 42, 22, 0.97), rgba(44, 30, 16, 0.98));
    border: 2px solid rgba(200, 170, 100, 0.2);
    border-image: none;
    border-radius: var(--radius-xl);
    padding: var(--space-lg) var(--space-md);
    max-width: 480px;
    width: 100%;
    max-height: 90vh;
    max-height: 90dvh;
    overflow-y: auto;
    position: relative;
    box-shadow:
        0 25px 80px rgba(0, 0, 0, 0.6),
        0 0 60px rgba(255, 215, 0, 0.05),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
}

.modal-box h2 {
    font-family: var(--font-display);
    font-size: 1.4rem;
    text-align: center;
    margin-bottom: var(--space-xs);
    background: linear-gradient(135deg, #ffe066, #ffd700, #e8a020);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 2px 4px rgba(255, 215, 0, 0.2));
    flex-shrink: 0;
}

.modal-desc {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-bottom: var(--space-md);
    flex-shrink: 0;
}

/* ═══ Intro Screen ═══ */
.intro-box {
    text-align: center;
    max-width: 520px;
}

.intro-logo-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto var(--space-sm);
    position: relative;
    animation: introFloat 3s ease-in-out infinite;
}

/* CSS Crossed Swords */
.intro-logo-icon::before,
.intro-logo-icon::after {
    content: '';
    position: absolute;
    width: 4px;
    height: 40px;
    background: linear-gradient(180deg, #ffd700, #b8860b);
    border-radius: 2px;
    top: 4px;
    left: 50%;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
}

.intro-logo-icon::before {
    transform: translateX(-12px) rotate(-25deg);
}

.intro-logo-icon::after {
    transform: translateX(8px) rotate(25deg);
}

/* Step icons — CSS only */
.step-icon {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.step-icon--merge {
    background: linear-gradient(135deg, #5cc472, #3a9e50);
    box-shadow: 0 2px 8px rgba(58, 158, 80, 0.3);
}

.step-icon--merge::after {
    content: '';
    width: 14px;
    height: 14px;
    background: white;
    clip-path: polygon(30% 0%, 70% 0%, 70% 30%, 100% 30%, 100% 70%, 70% 70%, 70% 100%, 30% 100%, 30% 70%, 0% 70%, 0% 30%, 30% 30%);
    opacity: 0.9;
}

.step-icon--gold {
    background: linear-gradient(135deg, #ffd700, #b8860b);
    box-shadow: 0 2px 8px rgba(255, 215, 0, 0.3);
}

.step-icon--gold::after {
    content: 'G';
    font-size: 0.7rem;
    font-weight: 900;
    color: #6b4c00;
    font-family: var(--font-display);
}

.step-icon--goal {
    background: linear-gradient(135deg, #c084fc, #7c3aed);
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.3);
}

.step-icon--goal::after {
    content: '';
    width: 14px;
    height: 14px;
    background: white;
    clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
    opacity: 0.9;
}

@keyframes introFloat {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-6px);
    }
}

.intro-title {
    font-family: var(--font-display);
    font-size: 2rem;
    line-height: 1.1;
    background: linear-gradient(135deg, #ffe066, #ffd700, #ffaa00, #ffd700);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: goldShift 4s ease-in-out infinite;
    margin-bottom: var(--space-xs);
    letter-spacing: 2px;
}

@keyframes goldShift {

    0%,
    100% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }
}

.intro-subtitle {
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-style: italic;
    margin-bottom: var(--space-md);
}

/* Tier timeline */
.tier-timeline {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
    margin-bottom: var(--space-md);
}

.timeline-icon {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.5rem;
    font-weight: 800;
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
    transition: transform var(--transition-fast);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.timeline-icon:hover {
    transform: scale(1.15) translateY(-2px);
}

/* How to play steps */
.how-to-play {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.how-step {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    text-align: left;
    background: rgba(245, 234, 208, 0.05);
    border: 1px solid rgba(200, 170, 100, 0.1);
    border-radius: var(--radius-sm);
    padding: var(--space-sm);
    transition: all var(--transition-fast);
}

.how-step:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--gold-400);
    transform: translateX(4px);
}

.how-step .step-icon {
    font-size: 1.3rem;
    flex-shrink: 0;
    width: 36px;
    text-align: center;
}

.how-step .step-content {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    flex: 1;
}

.how-step .step-num {
    width: 22px;
    height: 22px;
    border-radius: var(--radius-round);
    background: linear-gradient(135deg, var(--gold-400), var(--gold-600));
    color: var(--bg-primary);
    font-size: 0.6rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.how-step .step-text {
    font-size: 0.72rem;
    color: var(--text-secondary);
    line-height: 1.3;
}

/* ═══ Buttons ═══ */
.modal-buttons {
    display: flex;
    gap: var(--space-sm);
    justify-content: center;
    flex-wrap: wrap;
    flex-shrink: 0;
    padding-top: var(--space-sm);
}

.modal-btn {
    padding: 10px 24px;
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 2px solid transparent;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: relative;
    overflow: hidden;
}

.modal-btn::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.15), transparent);
    pointer-events: none;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.modal-btn-primary {
    background: linear-gradient(180deg, #ffd700, #e6c200, #cc9900);
    color: #1a0a00;
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: 0 4px 16px rgba(255, 215, 0, 0.3);
}

.modal-btn-primary:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 8px 28px rgba(255, 215, 0, 0.4);
}

.modal-btn-primary:active {
    transform: translateY(1px) scale(0.98);
}

.start-btn {
    padding: 14px 40px;
    font-size: 0.95rem;
    border-radius: var(--radius-lg);
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    animation: startPulse 2.5s ease-in-out infinite;
}

@keyframes startPulse {

    0%,
    100% {
        box-shadow: 0 4px 16px rgba(255, 215, 0, 0.3);
    }

    50% {
        box-shadow: 0 4px 16px rgba(255, 215, 0, 0.3), 0 0 30px rgba(255, 215, 0, 0.2);
    }
}

.modal-btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.1);
}

.modal-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
    transform: translateY(-1px);
}

.modal-btn-danger {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.2);
}

.modal-btn-danger:hover {
    background: rgba(239, 68, 68, 0.25);
}

/* ═══ Resume Modal ═══ */
.resume-info {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.resume-stat {
    text-align: center;
    background: rgba(245, 234, 208, 0.05);
    border: 1px solid rgba(200, 170, 100, 0.1);
    border-radius: var(--radius-sm);
    padding: var(--space-sm);
}

.resume-stat .label {
    font-size: 0.6rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 2px;
}

.resume-stat .value {
    font-family: var(--font-display);
    font-size: 0.95rem;
    color: var(--gold-400);
}

/* ═══ Win Screen ═══ */
.win-title {
    font-size: 1.5rem !important;
    animation: winPulse 1.5s ease-in-out infinite;
}

@keyframes winPulse {

    0%,
    100% {
        filter: drop-shadow(0 2px 4px rgba(255, 215, 0, 0.2));
    }

    50% {
        filter: drop-shadow(0 2px 16px rgba(255, 215, 0, 0.5));
    }
}

.win-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.win-stat {
    text-align: center;
    background: rgba(245, 234, 208, 0.05);
    border: 1px solid rgba(200, 170, 100, 0.12);
    border-radius: var(--radius-sm);
    padding: var(--space-sm);
}

.win-stat .stat-label {
    font-size: 0.6rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 2px;
}

.win-stat .stat-value {
    font-family: var(--font-display);
    font-size: 1.1rem;
    color: var(--gold-400);
}

/* ═══ Settings Modal ═══ */
.settings-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-primary);
    background: rgba(245, 234, 208, 0.05);
    border: 1px solid rgba(200, 170, 100, 0.1);
    border-radius: var(--radius-sm);
    padding: var(--space-sm);
}

.setting-row input[type="range"] {
    width: 80px;
    accent-color: var(--gold-400);
    cursor: pointer;
}

.settings-heading {
    font-family: var(--font-display);
    font-size: 0.85rem;
    color: var(--gold-400);
    margin-bottom: var(--space-sm);
    text-align: center;
    letter-spacing: 1px;
}

.toggle-switch {
    width: 44px;
    height: 24px;
    border-radius: 12px;
    background: rgba(200, 170, 100, 0.15);
    border: 2px solid rgba(200, 170, 100, 0.2);
    position: relative;
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.toggle-switch::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: white;
    transition: transform var(--transition-fast);
}

.toggle-switch.active {
    background: var(--gold-400);
    border-color: var(--gold-500);
}

.toggle-switch.active::before {
    transform: translateX(20px);
}

.theme-selector {
    display: flex;
    gap: var(--space-xs);
    justify-content: center;
    flex-wrap: wrap;
}

.theme-btn {
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    background: rgba(245, 234, 208, 0.06);
    color: var(--text-secondary);
    border: 2px solid rgba(200, 170, 100, 0.1);
    transition: all var(--transition-fast);
}

.theme-btn:hover {
    border-color: var(--gold-400);
    color: var(--text-primary);
}

.theme-btn.active-theme {
    background: rgba(255, 215, 0, 0.1);
    border-color: var(--gold-400);
    color: var(--gold-400);
}

.theme-btn.locked {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ═══ Confetti ═══ */
.confetti {
    position: fixed;
    z-index: calc(var(--z-modal) + 1);
    pointer-events: none;
    animation: confettiFall var(--fall-dur, 3s) ease-in var(--delay, 0s) forwards;
}

@keyframes confettiFall {
    0% {
        opacity: 1;
        transform: translateY(-20px) rotate(0deg) scale(1);
    }

    100% {
        opacity: 0;
        transform: translateY(100vh) rotate(var(--rot, 720deg)) scale(0.5);
    }
}

/* ═══ Responsive Modals ═══ */
@media (max-width: 600px) {
    .modal-overlay {
        padding: var(--space-sm);
        align-items: stretch;
    }

    .modal-box {
        padding: var(--space-md) var(--space-sm);
        margin: auto 0;
        max-height: 85vh;
        max-height: 85dvh;
    }

    .intro-title {
        font-size: 1.5rem;
        letter-spacing: 1px;
    }

    .intro-logo-icon {
        width: 40px;
        height: 40px;
        margin-bottom: var(--space-xs);
    }

    .intro-logo-icon::before,
    .intro-logo-icon::after {
        height: 32px;
    }

    .timeline-icon {
        width: 24px;
        height: 24px;
        font-size: 0.4rem;
        border-radius: 4px;
    }

    .tier-timeline {
        gap: 3px;
        margin-bottom: var(--space-sm);
    }

    .how-step {
        padding: 6px;
    }

    .how-step .step-text {
        font-size: 0.65rem;
    }

    .step-icon {
        width: 30px;
        height: 30px;
    }

    .how-step .step-num {
        width: 18px;
        height: 18px;
        font-size: 0.55rem;
    }

    .start-btn {
        padding: 12px 32px;
        font-size: 0.85rem;
    }

    .modal-btn {
        padding: 10px 20px;
        font-size: 0.8rem;
    }

    .win-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .resume-info {
        grid-template-columns: repeat(3, 1fr);
        gap: var(--space-xs);
    }

    .resume-stat {
        padding: var(--space-xs);
    }

    .resume-stat .value {
        font-size: 0.85rem;
    }

    .intro-subtitle {
        font-size: 0.7rem;
        margin-bottom: var(--space-sm);
    }

    .settings-group {
        gap: var(--space-xs);
    }

    .setting-row {
        padding: var(--space-xs) var(--space-sm);
        font-size: 0.75rem;
    }

    .setting-row input[type="range"] {
        width: 60px;
    }
}

/* Very small screens */
@media (max-height: 650px) {
    .modal-box {
        padding: var(--space-sm);
        max-height: 92vh;
        max-height: 92dvh;
    }

    .intro-logo-icon {
        width: 32px;
        height: 32px;
    }

    .intro-logo-icon::before,
    .intro-logo-icon::after {
        height: 26px;
    }

    .intro-title {
        font-size: 1.3rem;
    }

    .intro-subtitle {
        font-size: 0.65rem;
        margin-bottom: var(--space-xs);
    }

    .timeline-icon {
        width: 20px;
        height: 20px;
        font-size: 0.35rem;
    }

    .tier-timeline {
        gap: 2px;
    }

    .how-step {
        padding: 4px 6px;
    }

    .how-step .step-text {
        font-size: 0.6rem;
    }

    .step-icon {
        width: 26px;
        height: 26px;
    }

    .start-btn {
        padding: 10px 28px;
        font-size: 0.8rem;
    }
}