/* =========================================
   Shared Header Styles
   Used by index.html and pages/read/index.html
   ========================================= */

/* Background Gradient */
.bg-gradient {
    width: 100%;
    height: 300px;
    background-size: 400% 400%;
    z-index: 0;
    overflow: visible !important;
}

/* Background extension area - pushes content down */
#bg-extension {
    width: 100%;
    height: 0;
    transition: height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: visible;
    position: relative;
    z-index: 999;
    background: #1a1a1a;
    pointer-events: none;
}

#bg-extension::before {
    content: '';
    position: absolute;
    top: -60px;
    left: 0;
    width: 100%;
    height: 60px;
    pointer-events: none;
}

#bg-extension.extended::before {
    pointer-events: none;
}

.read-menu-container,
.study-menu-container,
.titleButton {
    pointer-events: auto !important;
}

#bg-extension.extended {
    height: 280px;
    overflow: visible;
    pointer-events: none;
}

/* Overlay mode - when header is in compact/sticky state */
#bg-extension.overlay-mode {
    position: fixed;
    top: 52px;
    left: 0;
    width: 100%;
    z-index: 999;
    height: 0;
    transition: height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: visible;
    background: #1a1a1a;
    pointer-events: none;
}

#bg-extension.overlay-mode.extended {
    height: 280px;
    overflow: visible;
    pointer-events: none;
}

#bg-extension.overlay-mode.extended .menu-extension-content {
    opacity: 1;
    pointer-events: auto;
}

#bg-extension.overlay-mode::before {
    display: none;
}

/* Menu Extension Content */
.menu-extension-content {
    max-width: 1280px;
    margin: 0 auto;
    padding: 20px 40px;
    height: 100%;
    display: flex;
    gap: 50px;
    opacity: 0;
    transition: opacity 0.3s ease 0.1s;
    width: 100%;
    pointer-events: none;
}

#bg-extension.extended .menu-extension-content {
    opacity: 1;
    pointer-events: auto;
}

/* Menu Section */
.menu-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 12px 16px;
    border-radius: 10px;
    transition: background 0.3s ease;
}

.menu-section:hover {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.07) 0%, rgba(255, 255, 255, 0.015) 100%);
}

.menu-section.section-highlight {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0.01) 100%);
}

.menu-section-header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid rgba(255, 255, 255, 0.15);
    width: 100%;
}

.menu-section-title {
    font-size: 18px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.5);
}

.menu-section-links {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.menu-section-links.multi-column {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px 30px;
}

/* Level Selection Section */
.level-menu-section {
    flex: 0 0 200px;
}

.level-menu-section .menu-section-links {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 9px 20px;
}

.level-option {
    color: rgba(255, 255, 255, 0.8);
    text-decoration-line: underline;
    text-decoration-color: rgba(255, 255, 255, 0);
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
    font-size: 16px;
    font-weight: 400;
    padding: 0;
    border-radius: 0;
    transition: text-decoration-color 0.2s ease;
    display: block;
    background: transparent;
    border: none;
    cursor: pointer;
    text-align: left;
    width: 100%;
    line-height: 1.5;
}

.level-option:hover {
    background: transparent;
    color: rgba(255, 255, 255, 0.8);
    transform: none;
    text-decoration-color: rgba(255, 255, 255, 0.5);
}

.level-option.active {
    background: transparent;
    color: #ffffff;
    font-weight: 600;
}

.level-name {
    display: block;
}

.menu-extension-item {
    color: rgba(255, 255, 255, 0.8);
    text-decoration-line: underline;
    text-decoration-color: rgba(255, 255, 255, 0);
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
    font-size: 16px;
    font-weight: 400;
    padding: 0;
    border-radius: 0;
    transition: text-decoration-color 0.2s ease;
    display: block;
}

.menu-extension-item:hover {
    background: transparent;
    color: rgba(255, 255, 255, 0.8);
    transform: none;
    text-decoration-color: rgba(255, 255, 255, 0.5);
}

.menu-extension-item>span:first-child {
    display: block;
}

.menu-extension-desc {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 4px;
    padding: 0;
    display: block;
}

.menu-extension-icon {
    width: 16px;
    height: 16px;
    object-fit: contain;
    margin-right: 6px;
    display: inline-block;
    vertical-align: middle;
}

/* Hide original mega menus when extension is active */
#bg-extension.extended~.main-content .read-mega-menu,
#bg-extension.extended~.main-content .read-menu-items {
    display: none !important;
}

/* Background Wave */
.bg-wave {
    max-height: 300px;
    height: 300px;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    contain: paint size;
    z-index: 1;
    pointer-events: none;
}

.bg-wave-inner {
    position: absolute;
    inset: 0;
    width: 200%;
    height: 100%;
    background: radial-gradient(circle at center, rgba(255, 255, 255, 0.2) 0%, transparent 60%);
    mix-blend-mode: overlay;
    will-change: transform;
}

/* Header & Nav */
.header {
    position: relative;
    overflow: visible;
    z-index: 1000;
}

#nav1 {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 30px 0;
    margin: 0 auto;
    max-width: 1280px;
    z-index: 1000;
    position: relative;
}

.logo {
    width: 250px;
    display: flex;
    justify-content: center;
    transform: rotate(-4deg);
    cursor: pointer;
}

.logo img {
    width: 100%;
    height: auto;
    filter: drop-shadow(2px 2px 1px rgba(0, 0, 0, 0.2));
}

.slogan {
    margin: 15px;
    font-size: clamp(18px, 6vw, 26px);
    color: white;
    font-weight: 500;
    letter-spacing: 1px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    min-height: 1.5em;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Menu Styles */
.menu {
    width: 100%;
    max-width: 1000px !important;
    display: flex;
    justify-content: space-between !important;
    align-items: baseline;
    gap: 20px;
    filter: drop-shadow(2px 2px 1px rgba(0, 0, 0, 0.2));
    position: relative;
    padding: 0 20px;
    box-sizing: border-box;
    margin: 0 auto;
}

/* Glassmorphism Button Styles - Liquid Wave Effect */
.menu .titleButton {
    display: flex;
    flex-direction: row;
    align-items: center;
    text-decoration: none;
    gap: 10px;
    padding: 10px 20px;
    min-height: 60px;
    background: transparent;
    border: none;
    border-radius: 12px;
    color: white;
    font-size: 16px;
    font-weight: 600;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    z-index: 1;
}

.menu .titleButton::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 85%;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: -1;
    transition: height 0.4s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s;

    --wave: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 60' preserveAspectRatio='none'%3E%3Cpath d='M0,30 Q100,10 200,30 T400,30 V60 H0 Z' fill='black'/%3E%3C/svg%3E");

    -webkit-mask: var(--wave) repeat-x;
    mask: var(--wave) repeat-x;
    -webkit-mask-size: 200% 100%;
    mask-size: 200% 100%;
    -webkit-mask-position: 0 bottom;
    mask-position: 0 bottom;

    animation: waveFlow 4s linear infinite;
}

@keyframes waveFlow {
    0% {
        -webkit-mask-position: 0 bottom;
        mask-position: 0 bottom;
    }
    100% {
        -webkit-mask-position: -200% bottom;
        mask-position: -200% bottom;
    }
}

.menu .titleButton:hover {
    transform: translateY(-5px);
}

.menu .titleButton:hover::before {
    height: 85%;
    background: rgba(255, 255, 255, 0.25);
    animation: waveFlow 4s linear infinite;
}

.menu a img {
    display: block;
    height: 40px;
    width: auto;
    transition: transform 0.3s ease;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.15));
}

.menu-label {
    font-size: 16px;
    font-weight: 600;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
    white-space: nowrap;
    z-index: 2;
}

.menu .menu-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    z-index: 2;
    filter: brightness(0) invert(1) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
}

/* Read Menu Dropdown */
.read-menu-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.read-menu-container::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    height: 15px;
    pointer-events: auto;
}

/* Header Right Top */
.header-right-top {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    z-index: 1003;
}

/* =========================================
   Compact Mode - Sticky Header
   ========================================= */
.header.compact {
    position: fixed;
    top: -248px;
    left: 0;
    width: 100%;
    z-index: 1000;
}

.bg-wave.compact {
    position: fixed;
    top: -248px;
    left: 0;
    width: 100%;
    z-index: 1001;
}

.header.compact #nav1 {
    max-width: 100%;
    padding: 0;
    justify-content: flex-end;
}

.header.compact .menu .titleButton {
    min-height: 50px;
    padding: 8px 20px;
}

.header.compact #dropdown .dropdown-toggle {
    min-height: 50px;
    padding: 8px 20px;
}

.header.compact #slogan {
    position: absolute;
    bottom: 14px;
    left: 16px;
    font-size: 13px;
    margin: 0;
    min-height: auto;
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.header.compact #slogan.slide-in {
    opacity: 1;
    transform: translateY(0);
}

.header.compact .menu .titleButton::before,
.header.compact #dropdown .dropdown-toggle::before {
    animation: none;
}

.header.compact .header-right-top {
    top: auto;
    bottom: 12px;
    right: 20px;
    gap: 10px;
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.header.compact .header-right-top.slide-in {
    opacity: 1;
    transform: translateY(0);
}

/* Placeholder spacer */
#header-spacer {
    display: none;
}

#header-spacer.active {
    display: block;
}

/* =========================================
   Mobile Navigation
   ========================================= */
.mobile-nav-container {
    display: none;
    width: 100%;
    justify-content: flex-start;
    align-items: center;
    padding: 20px 16px;
    margin-top: 10px;
    gap: 12px;
    box-sizing: border-box;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.mobile-nav-container::-webkit-scrollbar {
    display: none;
}

.mobile-sticker-btn {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 10px;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-width: 85px;
    max-width: 100px;
    position: relative;
    scroll-snap-align: start;
    filter: url(#sticker-outline);
    transform-origin: center center;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    -webkit-filter: url(#sticker-outline);
    will-change: transform;
}

.mobile-sticker-btn:hover,
.mobile-sticker-btn:active {
    transform: scale(1.1) rotate(0deg) !important;
    z-index: 10;
}

.sticker-content {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.sticker-content img {
    width: 44px;
    height: 44px;
    object-fit: contain;
    display: block;
}

.sticker-content span {
    font-family: 'Patrick Hand', cursive, sans-serif;
    font-size: 16px;
    color: #2d3748;
    font-weight: 800;
    margin-top: 0;
    white-space: nowrap;
}

.rotate-left {
    transform: rotate(-4deg);
}

.rotate-right {
    transform: rotate(3deg);
}

:root[data-theme="dark"] .sticker-content span {
    color: #2d3748 !important;
}

/* =========================================
   Mobile Responsive
   ========================================= */
@media (max-width: 768px) {
    .menu {
        flex-direction: column;
        height: auto;
        padding: 20px 0;
        align-items: center;
    }

    .menu-left {
        justify-content: center;
        width: 100%;
    }

    #dropdown {
        margin-top: 10px;
        margin-left: 0;
    }

    #dropdown .dropdown-options {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
    }
}

@media (max-width: 1400px) {
    .header.compact #slogan {
        display: none;
    }

    .header.compact #slogan.slide-in {
        display: none;
    }
}

@media (max-width: 1200px) {
    .menu {
        justify-content: flex-start !important;
    }

    .menu-left {
        flex: 0 1 auto;
        justify-content: flex-start;
        gap: 8px;
    }

    #dropdown {
        margin-left: 0;
        transition: none;
    }

    .menu .titleButton {
        padding: 10px 14px;
        transition: none;
    }

    #dropdown .dropdown-toggle {
        padding: 10px 14px;
        transition: none;
    }
}

@media (max-width: 850px) {
    .menu-left {
        display: none;
    }

    .menu {
        display: none !important;
    }

    .mobile-nav-container {
        display: none !important;
    }

    .header-right-top {
        display: none;
    }
}

@media (max-width: 768px) {
    #nav1 {
        padding: 20px 10px 5px 10px;
    }

    .logo {
        transform: rotate(-3deg) scale(0.9);
    }

    .slogan {
        margin-top: 5px;
        margin-bottom: 10px;
    }

    .bg-gradient {
        height: 250px;
    }

    .bg-wave {
        height: 250px;
    }
}

/* =========================================
   Menu-Left Wrapper
   ========================================= */
.menu-left {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

@media (min-width: 1201px) {
    .menu-left {
        flex: 1;
    }
}

/* =========================================
   Dropdown Component (#dropdown)
   ========================================= */
#dropdown {
    position: relative;
    z-index: 1001;
}

@media (min-width: 1201px) {
    #dropdown {
        margin-left: auto;
    }
}

#dropdown .dropdown-toggle {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    min-height: 60px;
    background: transparent;
    border: none;
    border-radius: 12px;
    color: white;
    font-size: 16px;
    font-weight: 600;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    z-index: 1;
}

#dropdown .dropdown-toggle::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 85%;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: -1;
    transition: height 0.4s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s;
    --wave: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 60' preserveAspectRatio='none'%3E%3Cpath d='M0,30 Q100,10 200,30 T400,30 V60 H0 Z' fill='black'/%3E%3C/svg%3E");
    -webkit-mask: var(--wave) repeat-x;
    mask: var(--wave) repeat-x;
    -webkit-mask-size: 200% 100%;
    mask-size: 200% 100%;
    -webkit-mask-position: 0 bottom;
    mask-position: 0 bottom;
    animation: waveFlow 4s linear infinite;
}

#dropdown .dropdown-toggle:hover {
    transform: translateY(-5px);
}

#dropdown .dropdown-toggle:hover::before {
    height: 85%;
    background: rgba(255, 255, 255, 0.25);
    animation: waveFlow 4s linear infinite;
}

#dropdown .dropdown-toggle .arrow {
    border-color: white;
    margin-left: 8px;
    margin-top: -2px;
}

#dropdown .dropdown-options {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    min-width: 180px;
    right: 0;
    left: auto;
    padding: 6px;
    margin-top: 10px;
    overflow: hidden;
    display: none;
    position: absolute;
    z-index: 1002;
    flex-direction: column;
}

#dropdown.open .dropdown-options {
    display: flex;
    animation: fadeIn 0.2s ease;
}

#dropdown .dropdown-group-title {
    color: #64748b;
    font-size: 12px;
    padding: 8px 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    margin-bottom: 4px;
    font-weight: 600;
}

#dropdown .dropdown-option {
    color: #1e293b;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s;
    border-radius: 10px;
    margin-bottom: 2px;
    cursor: pointer;
    text-align: left;
}

#dropdown .dropdown-option:last-child {
    margin-bottom: 0;
}

#dropdown .dropdown-option:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #0f172a;
    transform: translateX(4px);
}

/* Dark Theme Dropdown */
:root[data-theme="dark"] #dropdown .dropdown-options {
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

:root[data-theme="dark"] #dropdown .dropdown-option {
    color: #f8fafc;
}

:root[data-theme="dark"] #dropdown .dropdown-option:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

:root[data-theme="dark"] #dropdown .dropdown-group-title {
    color: #94a3b8;
    border-bottom-color: rgba(255, 255, 255, 0.05);
}

/* =========================================
   Animations
   ========================================= */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInMobile {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Mobile dropdown animation fix */
@media (max-width: 768px) {
    #dropdown.open .dropdown-options {
        animation: fadeInMobile 0.2s ease;
    }
}

/* =========================================
   Mobile Menu Adjustments
   ========================================= */
@media (max-width: 768px) {
    #nav1 {
        padding: 20px 16px;
    }

    .menu {
        gap: 10px;
        flex-wrap: wrap;
    }

    .menu-label {
        font-size: 14px;
    }

    .menu a img {
        height: 36px;
    }

    .slogan {
        font-size: 20px;
    }
}

/* 移动端默认隐藏header组件（bgWave子元素width:200%会撑大viewport） */
@media (max-width: 768px) {
    #bgWave,
    #bgGradient,
    #bg-extension {
        display: none !important;
    }
}
