.theme-toggle {
    cursor: pointer;
}

/* ===== Global text selection (light/dark theme) ===== */
[data-theme="light"] ::selection {
    background: rgba(139, 92, 246, 0.25);
    color: var(--text-primary, #1d1d1f);
}

[data-theme="light"] ::-moz-selection {
    background: rgba(139, 92, 246, 0.25);
    color: var(--text-primary, #1d1d1f);
}

[data-theme="dark"] ::selection {
    background: rgba(139, 92, 246, 0.4);
    color: var(--text-primary, #f0f0f5);
}

[data-theme="dark"] ::-moz-selection {
    background: rgba(139, 92, 246, 0.4);
    color: var(--text-primary, #f0f0f5);
}

/* ===== Theme switch loader (dark/light) ===== */
.theme-loader {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    background: var(--bg-primary, #0a0b10);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none;
}

.theme-loader.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.theme-loader-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-light, rgba(255, 255, 255, 0.1));
    border-top-color: var(--accent-primary, #8b5cf6);
    border-radius: 50%;
    animation: theme-loader-spin 0.8s linear infinite;
}

.theme-loader-text {
    font-size: 0.875rem;
    color: var(--text-secondary, rgba(255, 255, 255, 0.7));
}

@keyframes theme-loader-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ===== CTA Button Row (Free Practice Test / Purchase Test, etc.) ===== */
.cta-button-row {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 2rem;
    padding-bottom: 1rem;
}

.cta-button-row.cta-button-row--top-lg {
    margin-top: 2.5rem;
}

.cta-button-row.cta-button-row--no-pad-bottom {
    padding-bottom: 0;
}

.cta-button-row.cta-button-row--inline {
    margin-top: 1.5rem;
    padding-bottom: 0;
}

/* Theme toggle icons - controlled by data-theme attribute to prevent flicker */
[data-theme="light"] #sun-icon {
    display: none !important;
}

[data-theme="light"] #moon-icon {
    display: block !important;
}

/* Light mode: ensure theme toggle icon is visible on light nav */
[data-theme="light"] .theme-toggle {
    color: var(--text-primary, #1a1a2e);
}

[data-theme="dark"] #sun-icon {
    display: block !important;
}

[data-theme="dark"] #moon-icon {
    display: none !important;
}

/* ===== Nav logo ===== */
.logo {
    display: inline-flex;
    align-items: center;
}

.logo .logo-img {
    height: 50px;
    width: auto;
    max-height: 50px;
    display: block;
}

/* ===== Mobile Navigation Styles ===== */

/* Nav Actions Container - holds theme toggle and hamburger */
.nav-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Mobile Menu Toggle Button - Hidden on desktop */
.mobile-menu-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: 40px;
    height: 40px;
    padding: 8px;
    background: transparent;
    border: none;
    cursor: pointer;
    z-index: 101;
    border-radius: 8px;
    transition: background-color 0.2s ease;
}

.mobile-menu-toggle:hover {
    background: rgba(139, 92, 246, 0.1);
}

.hamburger-line {
    width: 24px;
    height: 2px;
    background: var(--text-primary, #1a1a2e);
    border-radius: 2px;
    transition: all 0.3s ease;
}

/* Hamburger to X animation when menu is open */
.mobile-menu-toggle.active .hamburger-line:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.mobile-menu-toggle.active .hamburger-line:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}

.mobile-menu-toggle.active .hamburger-line:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* Mobile Navigation Responsive Styles */
@media (max-width: 768px) {

    /* Show hamburger menu on mobile */
    .mobile-menu-toggle {
        display: flex;
    }

    /* Nav container adjustments */
    .nav-container {
        position: relative;
    }

    /* Mobile nav links - dropdown menu */
    .nav-links {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        gap: 0;
        background: #0a0b10;
        border-radius: 0 0 16px 16px;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
        padding: 1rem 0;
        opacity: 0;
        visibility: hidden;
        transform: translateY(-10px);
        transition: all 0.3s ease;
        max-height: 0;
        overflow: hidden;
    }

    /* Light mode: mobile dropdown uses light background */
    [data-theme="light"] .nav-links {
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(20px);
        border: 1px solid var(--border-light, rgba(0, 0, 0, 0.06));
        border-top: none;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
    }

    /* Show menu when active */
    .nav-links.active {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
        max-height: 400px;
    }

    /* Mobile nav link items */
    .nav-links a {
        display: block;
        padding: 0.875rem 1.5rem;
        text-align: center;
        border-bottom: 1px solid var(--border-light, rgba(0, 0, 0, 0.05));
        transition: background-color 0.2s ease;
    }

    .nav-links a:last-of-type {
        border-bottom: none;
    }

    /* Nav padding adjustment for mobile */
    nav {
        padding: 0.75rem 1rem;
    }

    /* CTA button row - stack on mobile, full-width buttons */
    .cta-button-row {
        flex-direction: column;
        align-items: stretch;
        margin-top: 1.5rem !important;
        padding-bottom: 0.75rem !important;
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .cta-button-row.cta-button-row--top-lg {
        margin-top: 2rem !important;
    }

    .cta-button-row .btn {
        width: 100%;
        justify-content: center;
        text-align: center;
    }

    /* Hero and final CTA button pairs - stack on mobile */
    .hero-ctas,
    .cta-buttons {
        flex-direction: column;
        align-items: stretch;
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .hero-ctas .btn,
    .cta-buttons .btn {
        width: 100%;
        justify-content: center;
        text-align: center;
    }
}

[data-theme="dark"] .hamburger-line {
    background: var(--text-primary, #f0f0f5);
}

/* ===== Book a Demo modal (institutions) – light theme defaults ===== */
.modal-label-required {
    color: #dc2626;
}

.modal-glass-input select,
.modal-glass-input textarea {
    flex: 1;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.95rem;
    color: inherit;
    outline: none;
    padding: 0.6rem 0.5rem;
    min-height: 2.5rem;
    width: 100%;
}

.modal-glass-input textarea {
    min-height: 80px;
    resize: vertical;
}

.modal-glass-input--select select {
    cursor: pointer;
    appearance: auto;
}

/* Demo modal uses same logo as navbar */
#demoModal .modal-logo {
    display: flex;
    justify-content: center;
    align-items: center;
}

#demoModal .modal-logo img {
    display: block;
    max-width: 120px;
    height: auto;
    object-fit: contain;
}

.modal-demo-content {
    position: relative;
    z-index: 1;
}

.modal-demo-title {
    margin-bottom: 1.25rem;
}

.modal-demo-form {
    max-width: 100%;
    margin: 0px 4px;
}

.modal-wrapper--demo {
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-card--demo {
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-card--demo .modal-demo-content {
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    padding-right: 0.25rem;
}

.modal-demo-consent {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

.modal-demo-checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary, #4b5563);
    cursor: pointer;
}

.modal-demo-checkbox-label input[type="checkbox"] {
    margin-top: 0.2rem;
    flex-shrink: 0;
    accent-color: var(--accent-primary, #8b5cf6);
    width: 1.125rem;
    height: 1.125rem;
    cursor: pointer;
}

.modal-demo-privacy-link {
    color: var(--accent-primary, #8b5cf6);
    text-decoration: underline;
}

.modal-demo-privacy-link:hover {
    color: var(--accent-primary-hover, #7c3aed);
}

/* Demo form validation errors */
.modal-input-error {
    display: block;
    font-size: 0.75rem;
    color: #dc2626;
    margin-top: 0.25rem;
    margin-left: 0.25rem;
}

[data-theme="dark"] .modal-input-error {
    color: #f87171;
}

.modal-input-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: 0.25rem;
    min-height: 1.25rem;
}

.modal-input-meta .modal-input-error {
    margin-top: 0;
    flex: 1;
    min-width: 0;
}

.modal-input-char-count {
    font-size: 0.75rem;
    color: var(--text-muted, #6b7280);
    flex-shrink: 0;
    margin-left: 0.25rem;
}

.modal-input-char-count.at-limit {
    color: #dc2626;
    font-weight: 500;
}

[data-theme="dark"] .modal-input-char-count {
    color: var(--text-muted, #9ca3af);
}

[data-theme="dark"] .modal-input-char-count.at-limit {
    color: #f87171;
}

.modal-glass-input.is-invalid {
    border-color: rgba(220, 38, 38, 0.6);
    box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.15);
}

.modal-demo-form-error {
    font-size: 0.875rem;
    color: #dc2626;
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: rgba(220, 38, 38, 0.08);
    border-radius: 8px;
}

.modal-demo-form-error:empty {
    display: none;
}

[data-theme="dark"] .modal-demo-form-error {
    color: #f87171;
    background: rgba(248, 113, 113, 0.12);
}

/* ----- Demo modal: responsive (tablet & mobile) ----- */
@media (max-width: 768px) {
    #demoModal .modal-wrapper {
        max-width: 100%;
        margin: 0 0.75rem;
    }

    #demoModal .modal-card--demo {
        padding: 1.5rem 1.25rem;
        max-height: 85vh;
    }

    #demoModal .modal-demo-content {
        padding-right: 0;
    }

    #demoModal .modal-demo-title {
        font-size: 1.25rem;
        margin-bottom: 1rem;
    }

    #demoModal .modal-demo-form {
        margin: 0;
    }

    #demoModal .modal-demo-form .modal-input-row {
        grid-template-columns: 1fr;
        gap: 0;
    }

    #demoModal .modal-demo-form .modal-input-group {
        margin-bottom: 0.875rem;
    }

    #demoModal .modal-demo-form .modal-hear-about-extra {
        margin-top: 1rem;
    }

    #demoModal .modal-demo-form .modal-input-row .modal-input-group {
        margin-bottom: 0.875rem;
    }
}

@media (max-width: 480px) {
    #demoModal .modal-logo img {
        max-width: 100px;
    }

    #demoModal .modal-overlay {
        padding: 0.75rem 0.5rem;
        align-items: flex-start;
    }

    #demoModal .modal-wrapper {
        margin: 0.5rem 0;
        max-width: 100%;
    }

    #demoModal .modal-card--demo {
        padding: 1.25rem 1rem;
        border-radius: 24px;
        max-height: 90vh;
    }

    #demoModal .modal-demo-title {
        font-size: 1.125rem;
        margin-bottom: 0.875rem;
    }

    #demoModal .modal-demo-form .modal-input-group,
    #demoModal .modal-demo-form .modal-input-row .modal-input-group {
        margin-bottom: 0.75rem;
    }

    #demoModal .modal-demo-form .modal-hear-about-extra {
        margin-top: 0.875rem;
    }

    #demoModal .modal-demo-form .modal-glass-input input,
    #demoModal .modal-demo-form .modal-glass-input select,
    #demoModal .modal-demo-form .modal-glass-input textarea {
        min-height: 44px;
        font-size: 16px;
        /* reduces zoom on iOS */
    }

    #demoModal .modal-demo-form .modal-glass-input--textarea textarea {
        min-height: 100px;
    }

    #demoModal .modal-demo-form .modal-btn-continue {
        min-height: 48px;
        padding: 0.875rem 1rem;
        font-size: 1rem;
    }

    #demoModal .modal-demo-consent .modal-demo-checkbox-label {
        font-size: 0.8125rem;
    }
}

#demoHearAboutSocialWrap,
#demoHearAboutSocialOtherWrap,
#demoHearAboutOtherWrap,
#demoHearAboutReferralWrap,
#demoNeedsOtherWrap {
    margin-top: 1rem;
}