/* ===================================
   Navigation — Notion-inspired minimal
   Soft grey hovers, no pills, subtle hairline.
   =================================== */

/* Sticky header with frosted glass */
.header-wrapper {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(251, 249, 244, 0.72);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    border-bottom: 1px solid rgba(30, 35, 30, 0.06);
    /* Animate the auto-hide slide AND the theme-toggle colour fade /
       scroll-elevation. This rule loads after custom.css, so listing
       background/border/box-shadow here keeps those transitions from being
       dropped when the transform transition is declared. */
    transition:
        transform 0.25s ease,
        background-color 0.2s ease,
        border-color 0.2s ease,
        box-shadow 0.25s ease;
    will-change: transform;
}

/* Auto-hide on scroll-down */
.header-wrapper.nav-scroll-hidden {
    transform: translateY(-100%);
}

/* Scroll elevation: at the very top the header sits flush; once the page
   scrolls it lifts with a soft shadow and a firmer hairline, so the bar
   reads as floating above the content. Subtle depth cue on phone + desktop. */
.header-wrapper.nav-scrolled {
    border-bottom-color: rgba(30, 35, 30, 0.1);
    box-shadow: 0 4px 20px rgba(30, 35, 30, 0.06);
}

body.dark .header-wrapper.nav-scrolled {
    border-bottom-color: rgba(226, 227, 225, 0.1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.32);
}

/* Language-specific background tint (light mode only) */
html:lang(en) body:not(.dark) .header-wrapper {
    background: rgba(249, 249, 247, 0.72);
}

/* Dark mode frosted header — declared after the lang tints so it always
   wins the cascade (the lang tints otherwise tie on specificity and would
   leak the light background into dark mode on English pages). */
body.dark .header-wrapper,
html:lang(en) body.dark .header-wrapper,
html:lang(zh) body.dark .header-wrapper {
    background: rgba(20, 22, 24, 0.72);
    border-bottom-color: rgba(226, 227, 225, 0.06);
}

/* Main Navigation Container — tighter Notion rhythm */
.nav {
    gap: 8px;
    padding: 0 4px;
    line-height: 44px;
}

/* Override PaperMod default that pushes logo/menu apart by 24px */
.logo,
#menu {
    margin: auto 0;
}

/* Logo refinement — compact, left-anchored */
.logo {
    margin: auto 0 auto 0;
    gap: 8px;
}

.logo a {
    font-family: var(--font-body, system-ui, sans-serif);
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--color-ink, var(--primary));
}

/* Menu List — centered, tight gap */
#menu {
    display: flex;
    align-items: center;
    gap: 0;
    margin: auto auto;
    flex: 0 1 auto;
    justify-content: center;
}

#menu li {
    margin-inline-start: 0;
}

/* Navigation Links - flat text, no pill */
#menu > li > a {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: 6px;
    background: transparent;
    color: var(--color-ink-muted, var(--secondary));
    font-family: var(--font-body, system-ui, sans-serif);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.01em;
    text-decoration: none;
    border: none;
    line-height: 1.4;
    transition: background-color 0.15s ease, color 0.15s ease;
}

/* Hover State - soft gray fill */
#menu > li > a:hover {
    background: rgba(30, 35, 30, 0.05);
    color: var(--color-ink, var(--primary));
}

body.dark #menu > li > a:hover {
    background: rgba(226, 227, 225, 0.06);
}

/* Active State - solid text color only, no border, no gradient */
#menu > li > a:has(.active),
#menu > li > a .active {
    color: var(--color-ink, var(--primary));
    font-weight: 600;
}

#menu > li > a:has(.active) {
    background: rgba(30, 35, 30, 0.04);
}

body.dark #menu > li > a:has(.active) {
    background: rgba(226, 227, 225, 0.05);
}

/* External link arrow subtle */
#menu > li > a svg {
    opacity: 0.5;
    transition: opacity 0.15s ease;
}

#menu > li > a:hover svg {
    opacity: 0.85;
}

/* Search Button - minimal chip */
.nav-search-trigger {
    height: 30px;
    padding: 0 9px;
    gap: 7px;
    border-radius: 6px;
    border: 1px solid rgba(30, 35, 30, 0.1);
    background: rgba(30, 35, 30, 0.02);
    color: var(--color-ink-muted, var(--secondary));
    font-size: 12.5px;
    flex-shrink: 0;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.nav-search-trigger:hover {
    background: rgba(30, 35, 30, 0.05);
    border-color: rgba(30, 35, 30, 0.15);
    transform: none;
    box-shadow: none;
    color: var(--color-ink, var(--primary));
}

body.dark .nav-search-trigger {
    border-color: rgba(226, 227, 225, 0.1);
    background: rgba(226, 227, 225, 0.03);
}

body.dark .nav-search-trigger:hover {
    background: rgba(226, 227, 225, 0.07);
    border-color: rgba(226, 227, 225, 0.18);
}

.nav-search-trigger__label {
    font-size: 13px;
    white-space: nowrap;
}

.nav-search-trigger__keys {
    flex-shrink: 0;
    white-space: nowrap;
}

.nav-search-trigger kbd {
    min-width: 18px;
    padding: 1px 5px;
    font-size: 10px;
    border-radius: 3px;
    background: rgba(30, 35, 30, 0.05);
    border-color: rgba(30, 35, 30, 0.08);
    color: var(--color-ink-muted, var(--secondary));
}

body.dark .nav-search-trigger kbd {
    background: rgba(226, 227, 225, 0.06);
    border-color: rgba(226, 227, 225, 0.1);
}

/* Theme toggle & lang switcher - understated */
.logo-switches {
    flex-shrink: 0;
    flex-wrap: nowrap;
    gap: 6px;
    align-items: center;
}

#theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--color-ink-muted, var(--secondary));
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

#theme-toggle:hover {
    background: rgba(30, 35, 30, 0.05);
    color: var(--color-ink, var(--primary));
}

body.dark #theme-toggle:hover {
    background: rgba(226, 227, 225, 0.06);
}

#theme-toggle svg {
    width: 16px;
    height: 16px;
}

/* Language Switcher — bilingual pill, current language sealed in cinnabar (朱砂印).
   Both glyphs are always visible so users see the choice, not just the destination.
   Active glyph fills with the cinnabar token (#862122 — the seal red used on
   Chinese 印章); the muted glyph lifts into the same wash on hover. */
:root {
    --color-cinnabar: #862122;
    --color-cinnabar-soft: #a64041;
}
.lang-switch {
    flex-shrink: 0;
    display: inline-flex;
    align-items: stretch;
    gap: 0;
    margin: 0;
    padding: 2px;
    list-style: none;
    border-radius: 999px;
    background: rgba(30, 35, 30, 0.04);
    box-shadow: inset 0 0 0 1px rgba(30, 35, 30, 0.08);
    line-height: 1;
}

.lang-switch__item {
    display: inline-flex;
    margin: 0;
    padding: 0;
    opacity: 1;
    color: inherit;
}

.lang-switch__item > a,
.lang-switch__item > span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 22px;
    padding: 0 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0.4px;
    color: var(--color-ink-muted, var(--secondary));
    text-decoration: none;
    transition: background-color 180ms ease, color 180ms ease, box-shadow 180ms ease;
}

/* Chinese glyph (中) gets a serif face for character feel */
.lang-switch__item--zh > a,
.lang-switch__item--zh > span {
    font-family: "Noto Serif SC", "Source Han Serif SC", var(--font-serif, serif);
    font-size: 13px;
    letter-spacing: 0;
}

/* English glyph picks up the site's display serif */
.lang-switch__item--en > a,
.lang-switch__item--en > span {
    font-family: var(--font-display, "Fraunces", serif);
    font-feature-settings: "ss01" on, "kern" on;
}

/* Inactive hover: cinnabar wash — signals "click to switch here" */
.lang-switch__item > a:hover,
.lang-switch__item > a:focus-visible {
    color: var(--color-cinnabar, #862122);
    background: rgba(134, 33, 34, 0.08);
    box-shadow: inset 0 0 0 1px rgba(134, 33, 34, 0.18);
}

.lang-switch__item > a:focus-visible {
    outline: none;
    box-shadow: inset 0 0 0 1px rgba(134, 33, 34, 0.45);
}

/* Active: cinnabar seal — solid #862122 with white ink, like a stamped 印 */
.lang-switch__item--active > span {
    color: #fff;
    background: var(--color-cinnabar, #862122);
    box-shadow: 0 1px 2px rgba(134, 33, 34, 0.28), inset 0 -1px 0 rgba(0, 0, 0, 0.18);
}

/* Dark mode: lift the rail off the ink background, soften the cinnabar */
body.dark .lang-switch {
    background: rgba(226, 227, 225, 0.05);
    box-shadow: inset 0 0 0 1px rgba(226, 227, 225, 0.08);
}

body.dark .lang-switch__item > a,
body.dark .lang-switch__item > span {
    color: var(--color-ink-muted, var(--secondary));
}

body.dark .lang-switch__item > a:hover,
body.dark .lang-switch__item > a:focus-visible {
    color: #f3c9c9;
    background: rgba(214, 88, 88, 0.14);
    box-shadow: inset 0 0 0 1px rgba(214, 88, 88, 0.30);
}

body.dark .lang-switch__item--active > span {
    color: #fff;
    background: var(--color-cinnabar-soft, #a64041); /* slightly lifted cinnabar for dark surfaces */
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35), inset 0 -1px 0 rgba(0, 0, 0, 0.25);
}

@media (prefers-reduced-motion: reduce) {
    .lang-switch__item > a,
    .lang-switch__item > span {
        transition: none;
    }
}

/* Responsive - Mobile */
@media (max-width: 768px) {
    .nav {
        position: relative;
        line-height: 52px;
    }

    /* Search button: icon-only on mobile, no label or keyboard shortcut */
    .nav-search-trigger__label,
    .nav-search-trigger__keys {
        display: none;
    }

    .nav-search-trigger {
        /* Touch target raised to 44px minimum (was 34px) */
        width: 44px;
        height: 44px;
        min-height: 44px;
        padding: 0;
        border: none;
        background: transparent;
        justify-content: center;
    }

    /* Touch target for theme toggle button */
    #theme-toggle {
        min-width: 44px;
        min-height: 44px;
    }

    .nav-search-trigger:hover {
        background: rgba(30, 35, 30, 0.05);
    }

    body.dark .nav-search-trigger:hover {
        background: rgba(226, 227, 225, 0.06);
    }

    .hamburger-menu {
        display: flex;
        align-items: center;
        justify-content: center;
        /* Touch target raised to 44px minimum (was 34px) */
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        padding: 0;
        background: transparent;
        border: none;
        border-radius: 6px;
        cursor: pointer;
        color: var(--color-ink, var(--primary));
        transition: background-color 0.15s ease;
    }

    .hamburger-menu:hover {
        background: rgba(30, 35, 30, 0.05);
    }

    .hamburger-menu svg {
        width: 20px;
        height: 20px;
    }

    #menu {
        position: absolute;
        top: 100%;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 2px;
        padding: 6px;
        margin-top: 4px;
        background: var(--color-paper, var(--theme));
        border: 1px solid rgba(30, 35, 30, 0.08);
        border-radius: 10px;
        box-shadow: 0 8px 24px rgba(30, 35, 30, 0.08);
        min-width: 200px;
        opacity: 0;
        visibility: hidden;
        transform: translateY(-4px);
        transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s ease;
        z-index: 1000;
    }

    body.dark #menu {
        border-color: rgba(226, 227, 225, 0.08);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    }

    #menu.is-open,
    #menu.mobile-open {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }

    #menu > li {
        width: 100%;
    }

    #menu > li > a {
        display: flex;
        width: 100%;
        padding: 8px 10px;
        font-size: 14px;
        gap: 8px;
        justify-content: flex-start;
        border-radius: 4px;
    }
}

/* Desktop - hide hamburger */
@media (min-width: 769px) {
    .hamburger-menu {
        display: none;
    }
}

/* Scroll anchor padding */
html {
    scroll-padding-top: 72px;
}
