.nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    max-width: calc(var(--nav-width) + var(--gap) * 2);
    margin-inline-start: auto;
    margin-inline-end: auto;
    line-height: var(--header-height);
    gap: 12px;
}

.nav a {
    display: block;
}

.logo,
#menu {
    display: flex;
    margin: auto var(--gap);
}

.nav-search-trigger {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    height: 40px;
    margin: auto 0;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--theme);
    color: var(--primary);
    cursor: pointer;
    transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.nav-search-trigger:hover {
    transform: translateY(-1px);
    border-color: var(--secondary);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.08);
}

.nav-search-trigger:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.nav-search-trigger__icon {
    display: inline-flex;
    align-items: center;
}

.nav-search-trigger__label {
    font-size: 14px;
    line-height: 1;
}

.nav-search-trigger__keys {
    display: inline-flex;
    gap: 4px;
}

.nav-search-trigger kbd,
.search-palette kbd {
    min-width: 24px;
    padding: 2px 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--entry);
    color: var(--secondary);
    font-size: 11px;
    line-height: 1.4;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    text-align: center;
}

.logo {
    flex-wrap: inherit;
}

.logo a {
    font-size: 24px;
    font-weight: 700;
}

.logo a img, .logo a svg {
    display: inline;
    vertical-align: middle;
    pointer-events: none;
    transform: translate(0, -10%);
    border-radius: 6px;
    margin-inline-end: 8px;
}

button#theme-toggle {
    font-size: 26px;
    margin: auto 4px;
}

body.dark #moon {
    vertical-align: middle;
    display: none;
}

body:not(.dark) #sun {
    display: none;
}

#menu {
    list-style: none;
    word-break: keep-all;
    overflow-x: auto;
    white-space: nowrap;
}

#menu li + li {
    margin-inline-start: var(--gap);
}

#menu a {
    font-size: 16px;
}

#menu .active {
    font-weight: 500;
    border-bottom: 2px solid currentColor;
}

.lang-switch li,
.lang-switch ul,
.logo-switches {
    display: inline-flex;
    margin: auto 4px;
}

.lang-switch {
    display: flex;
    flex-wrap: inherit;
}

.lang-switch a {
    margin: auto 3px;
    font-size: 16px;
    font-weight: 500;
}

.logo-switches {
    flex-wrap: inherit;
}

.search-palette-open {
    overflow: hidden;
}

/* ── Search Palette: Archival Aesthetic ── */

.search-palette {
    position: fixed;
    inset: 0;
    z-index: 120;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 7vh 16px 24px;
}

.search-palette[hidden] {
    display: none !important;
}

.search-palette {
    animation: palette-in 0.22s cubic-bezier(0.22, 1, 0.36, 1) both;
}

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

.search-palette__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(30, 20, 10, 0.22);
    backdrop-filter: blur(18px) saturate(120%);
    transition: opacity 0.3s ease;
}

.search-palette__panel {
    position: relative;
    width: min(720px, 100%);
    max-height: 82vh;
    overflow: hidden;
    border: 1px solid rgba(180, 160, 130, 0.25);
    border-radius: 6px;
    background: #faf8f4;
    box-shadow:
        0 2px 6px rgba(60, 40, 20, 0.06),
        0 20px 60px rgba(60, 40, 20, 0.14),
        inset 0 1px 0 rgba(255, 255, 255, 0.7);
    display: flex;
    flex-direction: column;
}

.dark .search-palette__panel {
    background: #1c1814;
    border-color: rgba(180, 160, 130, 0.15);
    box-shadow:
        0 2px 6px rgba(0, 0, 0, 0.3),
        0 20px 60px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.search-palette__header,
.search-palette__meta,
.search-palette__input-wrap {
    padding-left: 28px;
    padding-right: 28px;
}

.search-palette__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding-top: 22px;
    padding-bottom: 6px;
}

.search-palette__eyebrow {
    margin: 0 0 6px;
    font-size: 0.68rem;
    font-weight: 500;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #9a8870;
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
}

.dark .search-palette__eyebrow {
    color: #8a7860;
}

.search-palette__header h2 {
    margin: 0;
    color: #2c1f0e;
    font-size: 1.35rem;
    font-weight: 400;
    font-style: italic;
    font-family: Georgia, 'Times New Roman', 'Palatino Linotype', serif;
    letter-spacing: -0.01em;
    line-height: 1.3;
}

.dark .search-palette__header h2 {
    color: #e8dcc8;
}

.search-palette__close {
    padding: 6px 12px;
    border: 1px solid rgba(160, 140, 110, 0.35);
    border-radius: 4px;
    background: transparent;
    color: #9a8870;
    cursor: pointer;
    transition: all 0.18s ease;
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
}

.search-palette__close:hover {
    background: rgba(160, 140, 110, 0.12);
    border-color: rgba(160, 140, 110, 0.6);
    color: #5a4030;
}

.dark .search-palette__close:hover {
    color: #e8dcc8;
    border-color: rgba(180, 160, 130, 0.4);
}

.search-palette__input-wrap {
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 16px;
    padding-top: 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(160, 140, 110, 0.2);
}

.search-palette__input-icon {
    flex: 0 0 auto;
    color: #b0988a;
    transition: color 0.2s ease;
    opacity: 0.7;
}

.search-palette__input:focus ~ .search-palette__input-icon,
.search-palette__input-wrap:focus-within .search-palette__input-icon {
    color: #7a5c40;
    opacity: 1;
}

.dark .search-palette__input-icon {
    color: #8a7860;
}

.dark .search-palette__input-wrap:focus-within .search-palette__input-icon {
    color: #c8a870;
}

.search-palette__input {
    width: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    color: #2c1f0e;
    font-size: 1.05rem;
    padding: 4px 0;
    box-shadow: none;
    font-family: Georgia, 'Times New Roman', serif;
    letter-spacing: 0.01em;
}

.dark .search-palette__input {
    color: #e8dcc8;
}

.search-palette__input::placeholder {
    color: #b0988a;
    font-style: italic;
    opacity: 0.7;
}

.dark .search-palette__input::placeholder {
    color: #6a5848;
}

.search-palette__input-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
}

.search-palette__ai-trigger {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 5px 12px;
    border: 1px solid rgba(160, 140, 110, 0.35);
    border-radius: 4px;
    background: rgba(250, 240, 225, 0.6);
    color: #7a5c40;
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.03em;
    cursor: pointer;
    transition: all 0.18s ease;
    font-family: inherit;
}

.dark .search-palette__ai-trigger {
    background: rgba(50, 38, 25, 0.6);
    border-color: rgba(160, 140, 110, 0.25);
    color: #c8a870;
}

.search-palette__ai-trigger:hover {
    background: rgba(240, 225, 200, 0.9);
    border-color: rgba(140, 110, 75, 0.5);
    color: #5a3a20;
}

.dark .search-palette__ai-trigger:hover {
    background: rgba(70, 52, 32, 0.8);
    border-color: rgba(180, 150, 100, 0.4);
    color: #e8c888;
}

.search-palette__ai-trigger-icon {
    font-size: 0.95rem;
    line-height: 1;
}

/* AI Answer Box */
.search-palette__ai-box {
    margin: 14px 20px 0;
    padding: 16px 20px;
    border-radius: 4px;
    background: rgba(245, 238, 225, 0.5);
    border: 1px solid rgba(160, 140, 110, 0.2);
    border-left: 2px solid rgba(140, 110, 75, 0.4);
    animation: ai-slide-down 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.dark .search-palette__ai-box {
    background: rgba(35, 28, 18, 0.5);
    border-color: rgba(140, 110, 75, 0.2);
    border-left-color: rgba(180, 140, 90, 0.4);
}

@keyframes ai-slide-down {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.search-palette__ai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.search-palette__ai-title {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #9a7858;
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
}

.dark .search-palette__ai-title {
    color: #a08060;
}

.search-palette__ai-close {
    background: transparent;
    border: 0;
    color: #b0988a;
    font-size: 1.2rem;
    cursor: pointer;
    line-height: 1;
    opacity: 0.6;
    transition: opacity 0.15s;
}

.search-palette__ai-close:hover {
    opacity: 1;
}

.search-palette__ai-content {
    font-size: 0.92rem;
    line-height: 1.65;
    color: #3c2c18;
    font-family: Georgia, 'Times New Roman', serif;
}

.dark .search-palette__ai-content {
    color: #d8c8b0;
}

.search-palette__ai-content p { margin: 0 0 10px; }
.search-palette__ai-content p:last-child { margin-bottom: 0; }

.search-palette__ai-loading {
    display: flex;
    gap: 5px;
    padding: 8px 0;
    align-items: center;
}

.search-palette__ai-loading .dot {
    width: 5px;
    height: 5px;
    background: #9a7858;
    border-radius: 50%;
    animation: pulse 1.4s infinite;
}

.search-palette__ai-loading .dot:nth-child(2) { animation-delay: 0.2s; }
.search-palette__ai-loading .dot:nth-child(3) { animation-delay: 0.4s; }

.search-palette__ai-footer {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid rgba(160, 140, 110, 0.15);
    font-size: 0.72rem;
    color: #9a8870;
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    letter-spacing: 0.04em;
}

/* Conversation History */
.search-palette__conversation-message {
    margin-bottom: 14px;
    padding: 10px 14px;
    border-radius: 3px;
    animation: message-fade-in 0.25s ease;
}

@keyframes message-fade-in {
    from { opacity: 0; transform: translateY(3px); }
    to { opacity: 1; transform: translateY(0); }
}

.search-palette__conversation-message.user {
    background: rgba(245, 235, 215, 0.5);
    border-left: 2px solid rgba(140, 100, 60, 0.35);
    margin-left: 15%;
}

.search-palette__conversation-message.assistant {
    background: rgba(240, 235, 225, 0.3);
    border-left: 2px solid rgba(180, 165, 140, 0.3);
    margin-right: 15%;
}

.dark .search-palette__conversation-message.user {
    background: rgba(55, 40, 22, 0.5);
    border-left-color: rgba(180, 130, 80, 0.4);
}

.dark .search-palette__conversation-message.assistant {
    background: rgba(40, 34, 24, 0.4);
    border-left-color: rgba(140, 120, 90, 0.3);
}

.search-palette__conversation-sender {
    font-size: 0.68rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 5px;
    color: #9a8870;
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
}

.search-palette__conversation-content {
    font-size: 0.88rem;
    line-height: 1.65;
    color: #3c2c18;
    font-family: Georgia, 'Times New Roman', serif;
}

.dark .search-palette__conversation-content {
    color: #d8c8b0;
}

.search-palette__conversation-content h2,
.search-palette__conversation-content h3 {
    font-size: 0.92rem;
    margin: 10px 0 5px;
    color: #2c1f0e;
    font-style: italic;
}

.search-palette__conversation-content strong {
    font-weight: 600;
    color: #2c1f0e;
}

.dark .search-palette__conversation-content h2,
.dark .search-palette__conversation-content h3,
.dark .search-palette__conversation-content strong {
    color: #e8dcc8;
}

.search-palette__conversation-content code {
    padding: 1px 5px;
    border-radius: 2px;
    background: rgba(160, 140, 110, 0.12);
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    font-size: 0.83em;
    color: #6a4c2a;
}

.dark .search-palette__conversation-content code {
    background: rgba(100, 80, 50, 0.2);
    color: #c8a870;
}

.search-palette__conversation-content a {
    color: #7a5c40;
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-color: rgba(120, 90, 60, 0.4);
}

.dark .search-palette__conversation-content a {
    color: #c8a870;
    text-decoration-color: rgba(200, 168, 112, 0.4);
}

/* Follow-up Input */
.search-palette__followup {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(160, 140, 110, 0.15);
    animation: slide-up 0.25s ease;
}

@keyframes slide-up {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.search-palette__followup-input {
    flex: 1;
    padding: 8px 12px;
    border: 0;
    border-bottom: 1px solid rgba(160, 140, 110, 0.35);
    border-radius: 0;
    background: transparent;
    color: #2c1f0e;
    font-size: 0.88rem;
    outline: none;
    transition: border-color 0.18s ease;
    font-family: Georgia, 'Times New Roman', serif;
    font-style: italic;
}

.dark .search-palette__followup-input {
    color: #e8dcc8;
    border-bottom-color: rgba(140, 110, 75, 0.3);
}

.search-palette__followup-input:focus {
    border-bottom-color: rgba(120, 90, 55, 0.7);
}

.dark .search-palette__followup-input:focus {
    border-bottom-color: rgba(180, 140, 90, 0.6);
}

.search-palette__followup-input::placeholder {
    color: #b0988a;
    opacity: 0.7;
}

.search-palette__followup-send {
    padding: 8px 16px;
    border: 1px solid rgba(140, 110, 75, 0.4);
    border-radius: 3px;
    background: rgba(120, 90, 55, 0.08);
    color: #7a5c40;
    font-weight: 500;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.18s ease;
    white-space: nowrap;
    letter-spacing: 0.04em;
}

.dark .search-palette__followup-send {
    border-color: rgba(160, 130, 90, 0.35);
    background: rgba(80, 60, 35, 0.3);
    color: #c8a870;
}

.search-palette__followup-send:hover {
    background: rgba(120, 90, 55, 0.16);
    border-color: rgba(120, 90, 55, 0.6);
    color: #5a3a20;
}

.dark .search-palette__followup-send:hover {
    background: rgba(100, 75, 45, 0.5);
    color: #e8c888;
}

.search-palette__followup-send:active {
    transform: none;
}

.search-palette__meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-top: 14px;
    padding-bottom: 10px;
    color: #9a8870;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
}

.dark .search-palette__meta {
    color: #7a6858;
}

.search-palette__full-link {
    color: #7a5c40;
    font-weight: 500;
    text-decoration: none;
    transition: color 0.15s;
    letter-spacing: 0.02em;
}

.dark .search-palette__full-link {
    color: #a08060;
}

.search-palette__full-link:hover {
    color: #3c2010;
}

.dark .search-palette__full-link:hover {
    color: #c8a870;
}

.search-palette__results {
    margin: 0;
    padding: 4px 8px 16px;
    list-style: none;
    max-height: 46vh;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(160, 140, 110, 0.2) transparent;
}

.search-palette__result {
    margin: 0;
}

.search-palette__result + .search-palette__result {
    border-top: 1px solid rgba(160, 140, 110, 0.1);
}

.search-palette__result-link {
    display: grid;
    gap: 5px;
    padding: 14px 20px;
    border-radius: 0;
    text-decoration: none;
    background: transparent;
    transition: background 0.15s ease;
}

.search-palette__result-link:hover {
    background: rgba(160, 140, 110, 0.07);
}

.dark .search-palette__result-link:hover {
    background: rgba(180, 150, 110, 0.07);
}

.search-palette__result-title {
    color: #2c1f0e;
    font-weight: 400;
    font-size: 1rem;
    font-family: Georgia, 'Times New Roman', serif;
    letter-spacing: 0.005em;
}

.dark .search-palette__result-title {
    color: #e8dcc8;
}

.search-palette__result-preview {
    color: #9a8870;
    font-size: 0.84rem;
    line-height: 1.55;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-family: Georgia, 'Times New Roman', serif;
    font-style: italic;
}

.dark .search-palette__result-preview {
    color: #7a6858;
}

.search-palette__result-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 2px;
}

.search-palette__result-meta {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
}

.search-palette__result-tag {
    font-size: 0.68rem;
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #9a7858;
    opacity: 0.75;
    padding: 1px 0;
}

.search-palette__result-tag + .search-palette__result-tag::before {
    content: '·';
    margin-right: 5px;
    opacity: 0.5;
}

.dark .search-palette__result-tag {
    color: #8a6848;
}

.search-palette__result-date {
    font-size: 0.68rem;
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    letter-spacing: 0.05em;
    color: #b8a898;
    margin-left: auto;
    white-space: nowrap;
}

.dark .search-palette__result-date {
    color: #5a4838;
}

.search-palette__empty {
    padding: 48px 20px;
    color: #9a8870;
    text-align: center;
    font-size: 0.92rem;
    font-style: italic;
    font-family: Georgia, 'Times New Roman', serif;
}

@media (max-width: 960px) {
    .nav-search-trigger {
        order: 3;
        margin-inline: var(--gap);
    }
}

@media (max-width: 767px) {
    .search-palette {
        padding-top: 3vh;
    }

    .search-palette__panel {
        border-radius: 4px;
    }

    .search-palette__header,
    .search-palette__meta,
    .search-palette__input-wrap {
        padding-left: 18px;
        padding-right: 18px;
    }

    .search-palette__shortcut,
    .search-palette__ai-trigger-text {
        display: none;
    }

    .search-palette__ai-trigger {
        padding: 6px 8px;
    }

    .search-palette__header h2 {
        font-size: 1.1rem;
    }
}
