/* ==========================================================================
   Modal - Overlay, content, auth views, split layout, close/back buttons
   ========================================================================== */


/* --- Modal Overlay & Content --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 15px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 450px;
    max-height: 90vh;
    overflow-y: auto;
    transform: translateY(20px);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.modal-overlay.active .modal-content {
    transform: translateY(0) scale(1);
    animation: modalEnter 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}


/* --- Modal Header --- */
.modal-header {
    text-align: center;
    margin-bottom: 30px;
}

.modal-logo {
    font-family: "Special Gothic Expanded One", sans-serif;
    font-size: 2rem;
    margin-bottom: 10px;
    color: #333;
}

.modal-subtitle {
    color: #666;
    font-size: 14px;
}


/* --- Modal Close Button --- */
.modal-close {
    position: absolute;
    top: 15px;
    right: 20px;
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    color: #6b7280;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.modal-close:hover {
    background: #f3f4f6;
    color: #111827;
}


/* --- Split Column Auth Layout --- */
.modal-split {
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    position: relative;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Ensure close button in modal-split uses consistent styling */
.modal-split > .modal-close {
    position: absolute !important;
    top: 15px !important;
    right: 20px !important;
    width: 36px !important;
    height: 36px !important;
    background: none !important;
    border: none !important;
    border-radius: 50% !important;
    font-size: 24px !important;
    cursor: pointer !important;
    color: #6b7280 !important;
    transition: all 0.2s ease !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
    line-height: 1 !important;
    -webkit-tap-highlight-color: transparent !important;
    touch-action: manipulation !important;
}

.modal-split > .modal-close:hover {
    background: #f3f4f6 !important;
    color: #111827 !important;
}


/* --- Initial Choice Container --- */
.initial-container {
    display: none;
    flex-direction: column;
    padding: 40px;
    min-height: 400px;
    position: relative;
}

.initial-container.active {
    display: flex;
}

.choice-section {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.choice-divider {
    height: 1px;
    background: #e5e7eb;
    margin: 30px 0;
    width: 100%;
}

.choice-content {
    text-align: center;
    max-width: 320px;
}

.choice-title {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
    color: #111827;
}

.choice-subtitle {
    font-size: 14px;
    color: #6b7280;
    margin-bottom: 24px;
}

.choice-btn {
    background: #000;
    color: white;
    border: none;
    padding: 12px 32px;
    font-size: 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.choice-btn:hover {
    background: #1a1a1a;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}


/* --- Auth Views (Login / Register) --- */
.auth-view {
    display: none;
    padding: 40px;
    opacity: 0;
    transform: translateX(20px);
}

.auth-view.active {
    display: block;
    animation: slideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Auth view header positioning (logo centered, aligned with buttons) */
#loginView .modal-header,
#registerView .modal-header {
    position: absolute;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 0;
    width: auto;
}

#loginView .modal-header .modal-logo,
#registerView .modal-header .modal-logo {
    margin-bottom: 0;
    line-height: 36px;
    height: 36px;
    display: flex;
    align-items: center;
}

#loginView .modal-header .modal-subtitle,
#registerView .modal-header .modal-subtitle {
    display: none;
}

#loginView .auth-form,
#registerView .auth-form {
    margin-top: 70px;
}

/* Close button alignment when auth views are active */
.modal-content:has(.auth-view.active) > .modal-close,
.modal-content.auth-view-active > .modal-close,
.modal-content.modal-split.auth-view-active > .modal-close {
    top: 15px !important;
    right: 40px !important;
}

.auth-form {
    max-width: 380px;
    margin: 0 auto;
}


/* --- Back Button --- */
.back-btn {
    position: absolute;
    top: 15px;
    left: 20px;
    background: none;
    border: none;
    display: flex;
    align-items: center;
    gap: 4px;
    color: #6b7280;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
    padding: 8px;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.back-btn:hover {
    background: #f3f4f6;
    color: #111827;
}

.back-btn svg {
    flex-shrink: 0;
}

.back-arrow-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #374151;
    text-decoration: none;
    font-size: 14px;
    font-weight: 400;
    transition: color 0.2s ease;
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
}

.back-arrow-btn:hover {
    color: #000000;
    text-decoration: underline;
}

.back-arrow-btn svg {
    width: 16px;
    height: 16px;
}


/* --- Auth Toggle --- */
.auth-toggle {
    text-align: center;
    margin-top: 20px;
}

.auth-toggle a {
    color: #667eea;
    text-decoration: none;
    font-size: 14px;
}

.auth-toggle a:hover {
    text-decoration: underline;
}


/* ==========================================================================
   Modal Responsive
   ========================================================================== */

/* --- Mobile (max 768px) --- */
@media (max-width: 768px) {
    .modal-overlay {
        padding: 10px;
        align-items: flex-start;
        padding-top: 20px;
    }

    .modal-content {
        width: calc(100% - 20px);
        max-width: none;
        /* Trim vertical padding on phones so the auth form fits without
           awkward scroll. The desktop 40px top/bottom dwarfs the email +
           password fields on a Samsung S23-sized viewport. */
        padding: 20px 20px 22px;
        margin: 10px auto;
        border-radius: 12px;
        max-height: calc(100vh - 40px);
    }

    .modal-header {
        /* Smaller gap between "pacearena / subtitle" and the form so the
           first form field (email) sits closer to the top of the modal. */
        margin-bottom: 16px;
    }

    .modal-logo {
        font-size: 22px;
    }

    .modal-subtitle {
        font-size: 14px;
    }

    .initial-container {
        padding: 30px 20px;
        min-height: 350px;
    }

    .choice-section {
        flex: none;
        min-height: auto;
    }

    .choice-divider {
        margin: 20px 0;
    }

    .auth-view {
        padding: 30px 20px;
    }

    /* Auth view headers for mobile */
    #loginView .modal-header,
    #registerView .modal-header {
        top: 12px;
    }

    #loginView .modal-header .modal-logo,
    #registerView .modal-header .modal-logo {
        font-size: 20px;
        line-height: 48px;
        height: 48px;
    }

    #loginView .auth-form,
    #registerView .auth-form {
        margin-top: 65px;
    }

    /* Close button alignment for mobile auth views */
    .modal-content:has(.auth-view.active) > .modal-close,
    .modal-content.auth-view-active > .modal-close,
    .modal-content.modal-split.auth-view-active > .modal-close {
        top: 12px !important;
        right: 30px !important;
    }

    .modal-split > .modal-close {
        top: 12px !important;
        right: 16px !important;
        width: 48px !important;
        height: 48px !important;
        background-color: rgba(0,0,0,0.05) !important;
    }

    .modal-split {
        width: calc(100% - 20px);
        margin: 10px;
    }

    .back-btn {
        top: 12px;
        left: 16px;
        width: 48px;
        height: 48px;
        background-color: rgba(0,0,0,0.05);
    }

    .back-btn:hover,
    .back-btn:active {
        background-color: #f3f4f6;
        color: #000;
    }
}

/* --- Small mobile (max 480px) --- */
@media (max-width: 480px) {
    .modal-overlay {
        padding: 5px;
        align-items: flex-start;
        padding-top: 10px;
    }

    .modal-content {
        width: calc(100% - 10px);
        padding: 25px 16px;
        margin: 5px auto;
        border-radius: 10px;
        max-height: calc(100vh - 20px);
    }

    .modal-header {
        margin-bottom: 20px;
    }

    .modal-logo {
        font-size: 22px;
    }

    .modal-subtitle {
        font-size: 13px;
    }

    .auth-toggle {
        margin-top: 15px;
    }

    .auth-toggle a {
        font-size: 13px;
    }
}

/* --- Landscape phone --- */
@media (max-width: 768px) and (max-height: 500px) {
    .modal-content {
        max-height: 95vh;
        padding: 20px 16px;
    }

    .modal-header {
        margin-bottom: 15px;
    }

    .modal-logo {
        font-size: 20px;
    }
}

/* --- Large desktop (min 1200px) --- */
@media (min-width: 1200px) {
    .modal-content {
        max-width: 480px;
        padding: 50px;
    }

    .modal-logo {
        font-size: 32px;
    }

    .modal-subtitle {
        font-size: 18px;
    }
}

/* --- Touch devices --- */
@media (pointer: coarse) {
    .modal-close {
        width: 48px;
        height: 48px;
        top: 12px;
        right: 16px;
        background-color: rgba(0,0,0,0.05);
    }

    .modal-close:hover,
    .modal-close:active {
        background-color: #f3f4f6;
        color: #000;
    }

    .auth-toggle a {
        min-height: 44px;
        padding: 10px 16px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}
