:root {
    --bg-canvas: #FAF7F2;
    --bg-card: #FFFFFF;
    --bg-header: rgba(255, 255, 255, 0.96);
    --ink-primary: #1B242B;
    --ink-muted: #5C666E;
    --brand-navy: #102A38;
    --brand-gold: #B88E2E;
    --brand-gold-soft: #F5EBCF;
    --border-subtle: #EAE3D5;
    --border-card: #E2D9C8;
}

[data-theme="dark"] {
    --bg-canvas: #0E171D;
    --bg-card: #15222B;
    --bg-header: rgba(14, 23, 29, 0.96);
    --ink-primary: #E6E0D6;
    --ink-muted: #A4B0B8;
    --brand-navy: #EDE4D5;
    --brand-gold: #D4A85F;
    --brand-gold-soft: rgba(212, 168, 95, 0.16);
    --border-subtle: #1E2E38;
    --border-card: #243642;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    max-width: 100%;
    overflow-x: clip;
}

body {
    background-color: var(--bg-canvas);
    color: var(--ink-primary);
    font-family: 'Lora', Georgia, serif;
    font-size: 1rem;
    line-height: 1.8;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.25s ease, color 0.25s ease;
}

h1, h2, h3, .poetic-display {
    font-family: 'Cormorant Garamond', Georgia, serif;
}

a {
    color: inherit;
    text-decoration: none;
    transition: color 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
}

/* 1. Top Utility Bar */
.top-utility-bar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.82rem;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

.top-utility-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 7px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.top-tagline {
    font-style: italic;
    color: var(--ink-muted);
    font-size: 0.82rem;
    white-space: nowrap;
}

.top-utility-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.top-pill-outline {
    display: inline-flex;
    align-items: center;
    padding: 4px 13px;
    border-radius: 999px;
    border: 1px solid var(--border-card);
    color: var(--brand-navy);
    font-style: italic;
    font-weight: 500;
    white-space: nowrap;
    line-height: 1.4;
}

.top-pill-outline:hover {
    border-color: var(--brand-navy);
    background: var(--brand-navy);
    color: var(--bg-canvas);
}

.top-pill-solid {
    display: inline-flex;
    align-items: center;
    padding: 4px 14px;
    border-radius: 999px;
    background: var(--brand-navy);
    border: 1px solid var(--brand-navy);
    color: var(--bg-canvas);
    font-weight: 600;
    white-space: nowrap;
    line-height: 1.4;
}

.top-pill-solid:hover {
    background: var(--brand-gold);
    border-color: var(--brand-gold);
    color: #FFFFFF;
}

[data-theme="dark"] .top-pill-solid:hover {
    color: #0E171D;
}

.top-profile-link {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 2px 10px 2px 3px;
    border-radius: 999px;
    border: 1px solid var(--border-card);
    background: var(--bg-canvas);
    color: var(--brand-navy);
    font-weight: 600;
    white-space: nowrap;
}

.top-profile-link:hover {
    border-color: var(--brand-gold);
    color: var(--brand-gold);
}

.top-profile-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.top-profile-icon {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--brand-navy);
    color: var(--bg-canvas);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.btn-logout {
    background: none;
    border: none;
    cursor: pointer;
    font: inherit;
    font-style: italic;
    color: var(--ink-muted);
    white-space: nowrap;
    padding: 4px 4px;
    transition: color 0.2s ease;
}

.btn-logout:hover {
    color: var(--brand-gold);
}

/* Theme Toggle Button */
.theme-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border-card);
    background: var(--bg-canvas);
    color: var(--brand-navy);
    cursor: pointer;
    flex-shrink: 0;
    transition: border-color 0.2s ease, color 0.2s ease, background-color 0.2s ease;
}

.theme-toggle-btn:hover {
    border-color: var(--brand-gold);
    color: var(--brand-gold);
}

.theme-toggle-btn .icon-sun {
    display: none;
}

[data-theme="dark"] .theme-toggle-btn .icon-moon {
    display: none;
}

[data-theme="dark"] .theme-toggle-btn .icon-sun {
    display: block;
}

/* 2. Main Sticky Header Bar */
.header-bar {
    background: var(--bg-header);
    border-bottom: 1px solid var(--border-subtle);
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(8px);
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

.header-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 13px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    position: relative;
}

.brand-logo {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 1.85rem;
    font-weight: 700;
    font-style: italic;
    letter-spacing: 0.5px;
    color: var(--brand-navy);
    display: inline-flex;
    align-items: center;
    gap: 2px;
    white-space: nowrap;
    line-height: 1.1;
}

.brand-logo span {
    color: var(--brand-gold);
    font-style: normal;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: 'Lora', Georgia, serif;
    font-size: 0.88rem;
}

.nav-text-link {
    color: var(--ink-muted);
    font-weight: 500;
    padding: 5px 8px;
    border-radius: 6px;
    white-space: nowrap;
}

.nav-text-link:hover {
    color: var(--brand-gold);
}

/* Header Enter Button with Gradient Border */
.btn-header-enter {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 16px;
    border-radius: 999px;
    font-style: italic;
    font-weight: 600;
    color: var(--brand-navy);
    background:
        linear-gradient(var(--bg-card), var(--bg-card)) padding-box,
        linear-gradient(135deg, #D4A85F, #8E641B, #2C5E75) border-box;
    border: 1.5px solid transparent;
    white-space: nowrap;
    transition: transform 0.18s ease, box-shadow 0.2s ease, color 0.2s ease;
}

.btn-header-enter:hover {
    color: var(--brand-gold);
    box-shadow: 0 4px 14px rgba(184, 142, 46, 0.22);
    transform: translateY(-1px);
}

.btn-auth-link {
    padding: 6px 15px;
    border-radius: 999px;
    border: 1px solid var(--brand-navy);
    color: var(--brand-navy);
    font-style: italic;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-auth-link:hover {
    background: var(--brand-navy);
    color: var(--bg-canvas);
}

.btn-register-link {
    padding: 6px 15px;
    border-radius: 999px;
    background: var(--brand-navy);
    border: 1px solid var(--brand-navy);
    color: var(--bg-canvas);
    font-weight: 600;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-register-link:hover {
    background: var(--brand-gold);
    border-color: var(--brand-gold);
    color: #FFFFFF;
}

[data-theme="dark"] .btn-register-link:hover {
    color: #0E171D;
}

.btn-admin-link {
    background: var(--brand-gold);
    color: #FFFFFF;
    padding: 6px 15px;
    border-radius: 999px;
    font-weight: 600;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-admin-link:hover {
    background: var(--brand-navy);
    color: var(--bg-canvas);
}

/* Mobile Hamburger Toggle */
.nav-toggle-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: 1px solid var(--border-card);
    background: var(--bg-card);
    color: var(--brand-navy);
    cursor: pointer;
    flex-shrink: 0;
}

.nav-toggle-btn:hover {
    border-color: var(--brand-gold);
    color: var(--brand-gold);
}

.nav-toggle-btn .icon-close {
    display: none;
}

.nav-toggle-btn[aria-expanded="true"] .icon-menu {
    display: none;
}

.nav-toggle-btn[aria-expanded="true"] .icon-close {
    display: block;
}

/* Responsive Mobile Header & Top Bar */
@media (max-width: 780px) {
    .top-utility-inner {
        padding: 7px 14px;
    }

    .top-tagline {
        display: none;
    }

    .top-utility-actions {
        width: 100%;
        justify-content: flex-end;
        gap: 8px;
    }

    .top-profile-name {
        display: none;
    }

    .top-profile-link {
        padding: 2px;
    }

    .header-inner {
        padding: 11px 14px;
        flex-wrap: wrap;
    }

    .brand-logo {
        font-size: 1.65rem;
    }

    .nav-toggle-btn {
        display: inline-flex;
    }

    .header-nav {
        display: none;
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding-top: 12px;
        margin-top: 4px;
        border-top: 1px solid var(--border-subtle);
    }

    .header-nav.is-open {
        display: flex;
    }

    .header-nav .nav-text-link {
        padding: 9px 12px;
        background: var(--bg-canvas);
        border: 1px solid var(--border-subtle);
        border-radius: 8px;
        color: var(--brand-navy);
    }

    .header-nav .btn-header-enter,
    .header-nav .btn-auth-link,
    .header-nav .btn-register-link,
    .header-nav .btn-admin-link {
        width: 100%;
        padding: 9px 14px;
    }
}

/* Main & Footer */
.main-wrapper {
    max-width: 1180px;
    margin: 0 auto;
    padding: 28px 22px 64px;
    width: 100%;
}

@media (max-width: 640px) {
    .main-wrapper {
        padding: 18px 14px 48px;
    }
}

.footer-bar {
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-card);
    padding: 24px 16px;
    text-align: center;
    font-size: 0.88rem;
    font-style: italic;
    color: var(--ink-muted);
    width: 100%;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

.footer-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 18px;
    margin-bottom: 10px;
    font-style: normal;
    font-size: 0.86rem;
}

.footer-nav a {
    color: var(--brand-navy);
    font-weight: 500;
}

.footer-nav a:hover {
    color: var(--brand-gold);
}

.footer-nav .footer-rss-link {
    color: var(--brand-gold);
    font-weight: 600;
}

/* Dark Mode Component Overrides */
[data-theme="dark"] .btn-admin-link {
    color: #0E171D;
}

[data-theme="dark"] .type-pill,
[data-theme="dark"] .search-input,
[data-theme="dark"] .pagination-wrap a,
[data-theme="dark"] .pagination-wrap span {
    background: var(--bg-card);
    color: var(--ink-primary);
}

[data-theme="dark"] .type-pill.active,
[data-theme="dark"] .type-pill:hover,
[data-theme="dark"] .spotlight-read-btn,
[data-theme="dark"] .search-btn,
[data-theme="dark"] .btn-buy-book,
[data-theme="dark"] .work-cat-pill:hover,
[data-theme="dark"] .share-btn:hover,
[data-theme="dark"] .social-pill:hover,
[data-theme="dark"] .profile-fallback,
[data-theme="dark"] .author-avatar-fallback {
    color: #0E171D;
}