.pa-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(6, 10, 20, 0.75);
    backdrop-filter: blur(3px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 16px;
}

.pa-modal-overlay.open {
    display: flex;
    animation: pa-fade-in 0.15s ease;
}

@keyframes pa-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes pa-pop-in {
    from { opacity: 0; transform: translateY(8px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.pa-modal {
    position: relative;
    width: 100%;
    max-width: 400px;
    background: linear-gradient(180deg, #121b30 0%, #0c1425 100%);
    border: 1px solid rgba(56, 189, 248, 0.18);
    border-radius: 16px;
    padding: 28px 26px;
    color: #e2e8f0;
    font-family: inherit;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.02);
    animation: pa-pop-in 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

.pa-modal-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(34, 211, 238, 0.18), rgba(37, 99, 235, 0.18));
    color: #38bdf8;
    font-size: 1.1rem;
    margin-bottom: 14px;
}

.pa-modal h3 {
    margin: 0 0 6px;
    font-size: 1.2rem;
    font-weight: 700;
    color: #f8fafc;
    letter-spacing: -0.01em;
}

.pa-modal p.pa-sub {
    margin: 0 0 22px;
    font-size: 0.85rem;
    line-height: 1.5;
    color: #8b98ac;
}

.pa-modal-choices {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.pa-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    width: 100%;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.18);
    background: rgba(148, 163, 184, 0.06);
    color: #e2e8f0;
    font-size: 0.88rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-align: center;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.pa-btn i { font-size: 0.85rem; }

.pa-btn:hover { background: rgba(148, 163, 184, 0.13); border-color: rgba(148, 163, 184, 0.3); }
.pa-btn:active { transform: scale(0.98); }

.pa-btn-primary {
    background: linear-gradient(135deg, #22d3ee, #2563eb);
    border: none;
    color: #04101f;
    box-shadow: 0 6px 18px rgba(37, 99, 235, 0.35);
}

.pa-btn-primary:hover { opacity: 0.94; background: linear-gradient(135deg, #22d3ee, #2563eb); }

.pa-btn-ghost {
    background: transparent;
    border: 1px dashed rgba(148, 163, 184, 0.28);
    color: #94a3b8;
}

.pa-btn-ghost:hover { color: #cbd5e1; border-color: rgba(148, 163, 184, 0.45); }

.pa-btn[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

.pa-form { display: none; flex-direction: column; gap: 12px; }
.pa-form.open { display: flex; animation: pa-pop-in 0.16s ease; }

.pa-field { display: flex; flex-direction: column; gap: 6px; }

.pa-form label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #94a3b8;
}

.pa-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.pa-input-wrap i.pa-input-icon {
    position: absolute;
    left: 12px;
    color: #64748b;
    font-size: 0.8rem;
}

.pa-form input[type="text"],
.pa-form input[type="password"] {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px 10px 34px;
    border-radius: 9px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    background: rgba(8, 14, 28, 0.7);
    color: #f1f5f9;
    font-size: 0.87rem;
    font-family: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.pa-form input[type="text"]:focus,
.pa-form input[type="password"]:focus {
    outline: none;
    border-color: #38bdf8;
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.pa-avatar-picker {
    display: flex;
    align-items: center;
    gap: 12px;
}

.pa-avatar-preview {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(148, 163, 184, 0.1);
    border: 1px dashed rgba(148, 163, 184, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
    font-size: 1.1rem;
    overflow: hidden;
    flex-shrink: 0;
}

.pa-avatar-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.pa-avatar-picker input[type="file"] {
    display: none;
}

.pa-avatar-picker-btn {
    font-size: 0.78rem;
    font-weight: 600;
    color: #38bdf8;
    cursor: pointer;
    padding: 7px 12px;
    border-radius: 8px;
    border: 1px solid rgba(56, 189, 248, 0.3);
    background: rgba(56, 189, 248, 0.08);
    transition: background 0.15s ease;
}

.pa-avatar-picker-btn:hover { background: rgba(56, 189, 248, 0.16); }

.pa-checkbox-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 0.76rem;
    line-height: 1.45;
    color: #94a3b8;
    cursor: pointer;
}

.pa-checkbox-row input[type="checkbox"] {
    margin-top: 2px;
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    accent-color: #38bdf8;
    cursor: pointer;
}

.pa-checkbox-row a {
    color: #38bdf8;
    text-decoration: underline;
}

.pa-checkbox-row a:hover { color: #7dd3fc; }


.pa-error {
    font-size: 0.78rem;
    color: #f87171;
    min-height: 0;
    display: none;
}

.pa-error.show {
    display: block;
    padding: 8px 10px;
    background: rgba(248, 113, 113, 0.08);
    border: 1px solid rgba(248, 113, 113, 0.2);
    border-radius: 8px;
}

.pa-back-link {
    font-size: 0.78rem;
    font-weight: 600;
    color: #64748b;
    cursor: pointer;
    text-align: center;
    margin-top: 4px;
    transition: color 0.15s ease;
}

.pa-back-link:hover { color: #94a3b8; }

.pa-modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: rgba(148, 163, 184, 0.08);
    border: none;
    color: #94a3b8;
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.pa-modal-close:hover { background: rgba(148, 163, 184, 0.16); color: #e2e8f0; }

.pa-account-widget {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-muted, #94a3b8);
}

.pa-account-widget img {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid rgba(148, 163, 184, 0.3);
}

.pa-account-widget i.fa-circle-user {
    font-size: 1.4rem;
    color: #64748b;
}

.pa-account-widget span {
    font-weight: 600;
    color: #cbd5e1;
}

.pa-account-widget .pa-logout {
    cursor: pointer;
    color: #38bdf8;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s ease;
}

.pa-account-widget .pa-logout:hover { background: rgba(56, 189, 248, 0.1); }

.pa-home-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted, #94a3b8);
    text-decoration: none;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    transition: all 0.15s ease;
}

.pa-home-btn:hover {
    color: var(--accent, #38bdf8);
    border-color: rgba(56, 189, 248, 0.4);
}

/* ---------- Mobile ---------- */

/* Tall forms (sign-up with avatar picker) must stay reachable on short screens. */
.pa-modal {
    max-height: calc(100vh - 32px);
    overflow-y: auto;
}

@supports (height: 100dvh) {
    .pa-modal {
        max-height: calc(100dvh - 32px);
    }
}

/* Thumb-sized target in the course drawer. */
@media (max-width: 1024px) {
    .pa-home-btn {
        padding: 10px 13px;
    }
}

@media (max-width: 640px) {
    .pa-modal-overlay {
        padding: 12px;
        padding-top: max(12px, env(safe-area-inset-top));
    }

    .pa-modal {
        max-width: 100%;
        padding: 24px 18px;
        border-radius: 14px;
    }

    /* Below 16px iOS Safari zooms the viewport when a field gets focus. */
    .pa-form input[type="text"],
    .pa-form input[type="password"] {
        font-size: 16px;
        padding: 12px 12px 12px 34px;
    }

    .pa-btn {
        padding: 13px 14px;
        font-size: 0.9rem;
    }

    .pa-modal-close {
        width: 34px;
        height: 34px;
    }

    /* Keep long usernames from stretching the navbar. */
    .pa-account-widget {
        font-size: 0.75rem;
        gap: 6px;
    }

    .pa-account-widget > span:not(.pa-logout):not(.pa-back-link) {
        max-width: 90px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .pa-account-widget img,
    .pa-account-widget i.fa-circle-user {
        width: 24px;
        height: 24px;
        font-size: 1.25rem;
    }
}
