/* استایل هدر — ارتفاع مشترک برای فاصله محتوا از هدر ثابت */
:root {
    --site-header-height: 60px;
    /* Logo hangs below the bar (~16px) + decorative notch — keep content clear */
    --site-header-logo-overhang: 20px;
    --site-header-offset: calc(var(--site-header-height) + var(--site-header-logo-overhang) + env(safe-area-inset-top, 0px));
    /* Sticky in-page subnav (about resume rail). JS overwrites with measured height. */
    --about-subnav-offset: 0px;
}

.main-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(var(--site-header-height) + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    background: var(--glass-bg);
    backdrop-filter: blur(14px) saturate(1.1);
    -webkit-backdrop-filter: blur(14px) saturate(1.1);
    border-bottom: 1px solid var(--glass-border);
    z-index: 1100;
    box-shadow: 0 2px 14px rgba(0, 0, 0, 0.12);
    overflow: visible;
}

.main-header::after {
    content: '';
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 20px;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 0 0 50px 50px;
    border: 1px solid var(--glass-border);
    border-top: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: -1;
    pointer-events: none;
}

.header-container {
    max-width: 1200px;
    margin: 0 auto;
    height: var(--site-header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: relative;
    box-sizing: border-box;
}

.header-container .hamburger-btn {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
}

.header-left-buttons {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: calc(50% - 56px);
    flex-wrap: nowrap;
    min-width: 0;
    overflow: visible;
}

.header-icon-btn {
    position: relative;
    width: 38px;
    height: 38px;
    min-width: 38px;
    border-radius: 12px;
    border: 1px solid rgba(218, 178, 93, 0.22);
    background: linear-gradient(160deg, rgba(255,255,255,0.08), rgba(255,255,255,0.02));
    color: var(--text-primary, #f5e6c8);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    text-decoration: none;
    flex-shrink: 0;
    transition: transform 0.22s ease, border-color 0.22s ease, background 0.22s ease, box-shadow 0.22s ease, color 0.22s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
    -webkit-tap-highlight-color: transparent;
}

.header-icon-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(218, 178, 93, 0.55);
    color: #dab25d;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(218, 178, 93, 0.08);
}

/* Guest login = person; auth logout = exit — keep shapes distinct at small size */
.header-icon-btn--login {
    color: #dab25d;
}
.header-icon-btn--logout {
    color: var(--text-primary, #f5e6c8);
}
.header-icon-btn--logout:hover {
    color: #f87171;
    border-color: rgba(248, 113, 113, 0.45);
}

.header-icon-btn:active {
    transform: translateY(0) scale(0.96);
}

.header-icon-btn:focus-visible {
    outline: 2px solid rgba(218, 178, 93, 0.75);
    outline-offset: 2px;
}

.header-bell-badge {
    position: absolute;
    top: -4px;
    left: -4px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: #dab25d;
    color: #1a1208;
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    box-shadow: 0 2px 6px rgba(0,0,0,.25);
}

.header-icon-svg {
    display: block;
}

.header-notif-dot {
    position: absolute;
    top: 8px;
    left: 9px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #e85d5d;
    box-shadow: 0 0 0 2px rgba(12, 16, 24, 0.85);
    animation: headerNotifPulse 1.8s ease-in-out infinite;
}

.header-notif-dot[hidden] {
    display: none !important;
}

@keyframes headerNotifPulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.15); opacity: 0.75; }
}

.header-notification-btn:hover .header-icon-svg {
    animation: headerBellRing 0.55s ease;
}

@keyframes headerBellRing {
    0%, 100% { transform: rotate(0deg); }
    20% { transform: rotate(-12deg); }
    40% { transform: rotate(10deg); }
    60% { transform: rotate(-6deg); }
    80% { transform: rotate(4deg); }
}

.header-container .theme-toggle-header {
    position: relative;
    margin: 0;
}

.hamburger-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    color: var(--text-primary, #f5e6c8);
    transition: background 0.3s ease, color 0.3s ease;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    visibility: visible;
    -webkit-tap-highlight-color: transparent;
}
.hamburger-btn svg {
    display: block;
    stroke: currentColor;
    color: inherit;
}

.hamburger-btn:hover {
    background: rgba(218, 178, 93, 0.1);
    color: var(--primary-color, #dab25d);
}

.header-container .hamburger-btn:hover {
    transform: translateY(-50%) scale(1.06);
}

.hamburger-btn:focus-visible {
    outline: 2px solid rgba(218, 178, 93, 0.75);
    outline-offset: 2px;
}

.header-logo {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    height: 100%;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 10;
    text-decoration: none;
    transition: transform 0.3s ease;
    pointer-events: auto;
}

.header-logo:hover {
    transform: translateX(-50%) scale(1.05);
}

.header-logo-img {
    height: 72px;
    width: auto;
    max-width: min(168px, 40vw);
    object-fit: contain;
    transition: opacity 0.3s ease;
    position: relative;
    z-index: 3;
    margin-top: 4px;
    display: block;
    opacity: 1;
    visibility: visible;
}

.theme-toggle-header .theme-icon-wrap {
    position: relative;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}

.theme-toggle-header .theme-icon {
    position: absolute;
    inset: 0;
    margin: auto;
    display: block;
    width: 18px;
    height: 18px;
    pointer-events: none;
    transition: none;
    transform: none !important;
}

/* در تم تاریک: آیکن خورشید (برای رفتن به روشن) */
.theme-toggle-header .theme-icon-sun {
    opacity: 1;
    visibility: visible;
    color: #f0d48a;
}
.theme-toggle-header .theme-icon-moon {
    opacity: 0;
    visibility: hidden;
    color: #c9a24a;
}

[data-theme="light"] .theme-toggle-header .theme-icon-sun {
    opacity: 0;
    visibility: hidden;
}
[data-theme="light"] .theme-toggle-header .theme-icon-moon {
    opacity: 1;
    visibility: visible;
    color: #7a5618;
}

[data-theme="light"] .main-header {
    background: rgba(250, 244, 232, 0.92);
    border-bottom-color: rgba(160, 120, 42, 0.36);
    box-shadow: 0 2px 18px rgba(55, 38, 12, 0.08);
    backdrop-filter: blur(14px) saturate(1.08);
    -webkit-backdrop-filter: blur(14px) saturate(1.08);
}

[data-theme="light"] .main-header::after {
    background: rgba(250, 244, 232, 0.92);
    border-color: rgba(160, 120, 42, 0.34);
    box-shadow: 0 4px 14px rgba(55, 38, 12, 0.08);
}

[data-theme="light"] .header-icon-btn {
    border-color: rgba(160, 120, 42, 0.40);
    background: linear-gradient(160deg, rgba(250, 244, 232, 0.98), rgba(238, 229, 212, 0.88));
    color: #1a1510;
    box-shadow: 0 2px 10px rgba(55, 38, 12, 0.08);
}
[data-theme="light"] .header-icon-btn:hover {
    color: #7a5618;
    border-color: rgba(160, 120, 42, 0.62);
    box-shadow: 0 4px 14px rgba(201, 162, 55, 0.22), 0 0 0 1px rgba(218, 178, 93, 0.14);
}
[data-theme="light"] .header-icon-btn--logout:hover {
    color: #c24141;
    border-color: rgba(194, 65, 65, 0.4);
}
[data-theme="light"] .header-notif-dot {
    box-shadow: 0 0 0 2px rgba(250, 244, 232, 0.96);
}

body {
    padding-top: var(--site-header-offset);
}

/* Quiz / welcome cards clear hanging logo */
.quiz-welcome,
.eq-container,
.quiz-container,
.quiz-instructions {
    position: relative;
    z-index: 1;
}

@media (max-width: 768px) {
    :root {
        --site-header-height: 56px;
        --site-header-logo-overhang: 18px;
    }

    .header-container {
        padding: 0 10px;
    }

    .header-container .hamburger-btn {
        right: 8px;
        min-width: 42px;
        min-height: 42px;
        padding: 7px;
    }

    .header-left-buttons {
        left: 6px;
        gap: 4px;
        max-width: calc(50% - 48px);
    }

    .header-left-buttons .lang-switcher {
        transform: scale(0.9);
        transform-origin: left center;
        flex-shrink: 0;
    }

    html[dir="rtl"] .header-left-buttons .lang-switcher {
        transform-origin: right center;
    }

    /* Events + dashboard live in bottom nav — keep header chrome lean */
    .header-left-buttons .header-icon-btn--events,
    .header-left-buttons .header-icon-btn--dashboard {
        display: none;
    }

    .header-icon-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
        border-radius: 10px;
    }

    .header-logo-img {
        height: 64px;
        margin-top: 2px;
        max-width: min(148px, 38vw);
    }

    .main-header::after {
        width: 72px;
        height: 12px;
        bottom: -12px;
        border-radius: 0 0 40px 40px;
    }

    .logo-container-wrapper {
        margin-top: -15px;
    }
}

/* Phones under ~480: logout is in the sidebar — keep bell + theme + lang */
@media (max-width: 480px) {
    .header-left-buttons form:has(.header-icon-btn--logout),
    .header-left-buttons .header-icon-btn--logout {
        display: none;
    }
}

/* Narrow phones — keep brand centered, reduce chrome density */
@media (max-width: 375px) {
    :root {
        --site-header-height: 52px;
        --site-header-logo-overhang: 16px;
    }

    .header-container {
        padding: 0 6px;
    }

    .header-left-buttons {
        left: 4px;
        gap: 3px;
        max-width: calc(50% - 36px);
    }

    /* Keep FA/EN switcher on ~375 — compact, do not hide behind the logo */
    .header-left-buttons .lang-switcher {
        display: inline-flex;
        transform: scale(0.86);
        padding: 1px;
        gap: 0;
    }

    .header-left-buttons .lang-switcher__item {
        min-width: 28px;
        height: 24px;
        padding: 0 5px;
        font-size: 10px;
    }

    .header-icon-btn {
        width: 32px;
        height: 32px;
        min-width: 32px;
        border-radius: 9px;
    }

    .header-logo-img {
        height: 58px;
        margin-top: 2px;
        max-width: min(132px, 36vw);
    }

    .header-container .hamburger-btn {
        right: 4px;
        min-width: 40px;
        min-height: 40px;
        padding: 6px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .main-header,
    .header-notif-dot,
    .header-notification-btn:hover .header-icon-svg {
        animation: none !important;
    }
    .header-icon-btn:hover,
    .hamburger-btn:hover,
    .header-logo:hover {
        transform: none !important;
    }
    .header-container .hamburger-btn:hover {
        transform: translateY(-50%) !important;
    }
    .header-logo:hover {
        transform: translateX(-50%) !important;
    }
}
