@import url('https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@400;500;600;700&display=swap');

:root {
    --gold: #D4956A;
    --gold-soft: #E8B892;
    --gold-deep: #B8764E;
    --gold-pale: #F5DCC8;
    --gold-muted: #A08060;
    --gold-glow: rgba(212, 149, 106, 0.10);
    --gold-glow-strong: rgba(212, 149, 106, 0.20);

    --bg-primary: #0C0907;
    --bg-elevated: #111010;
    --bg-card: rgba(255, 255, 255, 0.02);
    --bg-card-hover: rgba(255, 255, 255, 0.04);
    --bg-glass: rgba(12, 9, 7, 0.80);

    --border-subtle: rgba(212, 149, 106, 0.10);
    --border-active: rgba(212, 149, 106, 0.22);
    --border-glow: rgba(212, 149, 106, 0.35);

    --text-primary: #fff;
    --text-high: rgba(255, 255, 255, 0.92);
    --text-secondary: rgba(255, 255, 255, 0.72);
    --text-tertiary: rgba(255, 255, 255, 0.42);

    --font-display: 'Crimson Pro', 'Georgia', serif;
    --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;

    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);

    --header-h: 64px;
}

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    color: var(--text-high);
    line-height: 1.75;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.page-ambient {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.page-ambient::before {
    content: '';
    position: absolute;
    top: -30%;
    left: 50%;
    transform: translateX(-50%);
    width: 140%;
    height: 55%;
    background: radial-gradient(ellipse, rgba(212, 149, 106, 0.07) 0%, transparent 70%);
    opacity: 0.6;
    animation: ambientPulse 14s ease-in-out infinite alternate;
}

.page-ambient::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 40%;
    background: linear-gradient(to top, var(--bg-primary) 0%, transparent 100%);
}

@keyframes ambientPulse {
    0% {
        opacity: 0.4;
        transform: translateX(-50%) scale(1);
    }

    100% {
        opacity: 0.65;
        transform: translateX(-50%) scale(1.04);
    }
}

.page-grain {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    opacity: 0.025;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px 256px;
}

/* Header */
header {
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 clamp(1.25rem, 4vw, 3rem);
    background: rgba(12, 9, 7, 0.80);
    backdrop-filter: blur(20px) saturate(1.1);
    -webkit-backdrop-filter: blur(20px) saturate(1.1);
    border-bottom: 1px solid var(--border-subtle);
    transition: border-color 0.4s ease, box-shadow 0.4s ease;
}

header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 1px;
    background: linear-gradient(90deg,
            transparent 0%,
            rgba(212, 149, 106, 0.15) 30%,
            rgba(212, 149, 106, 0.15) 70%,
            transparent 100%);
}

header.scrolled {
    border-bottom-color: var(--border-active);
    box-shadow: 0 1px 30px rgba(0, 0, 0, 0.35);
}

.brand-link {
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    position: relative;
}

.brand-logo {
    width: 24px;
    height: 24px;
    color: var(--gold);
    transition: transform 0.5s var(--ease-out-expo);
    will-change: transform;
}

.brand-link:hover .brand-logo {
    transform: scale(1.08);
}

.brand-title {
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.2em;
    text-transform: uppercase;
}

.nav-link {
    color: var(--text-tertiary);
    text-decoration: none;
    font-family: var(--font-body);
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.9rem;
    border: 1px solid transparent;
    transition: all 0.4s var(--ease-out-quart);
}

.nav-link:hover {
    color: var(--gold);
    border-color: var(--border-active);
    background: var(--gold-glow);
}

.nav-link svg {
    width: 14px;
    height: 14px;
    transition: transform 0.35s var(--ease-out-expo);
}

.nav-link:hover svg {
    transform: translateX(-3px);
}

/* Main Content */
.main-container {
    flex: 1;
    width: 100%;
    max-width: 920px;
    margin: 0 auto;
    padding: clamp(2rem, 5vw, 3.5rem) clamp(1.25rem, 4vw, 2rem);
    position: relative;
    z-index: 2;
}

h1 {
    font-family: var(--font-display);
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: -0.01em;
    text-align: center;
    color: var(--text-primary);
    margin-bottom: 0.6rem;
    opacity: 0;
    transform: translateY(20px);
    animation: fadeUp 0.8s var(--ease-out-expo) 0.1s forwards;
}

.title-ornament {
    display: block;
    width: 40px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
    margin: 0 auto 2.5rem;
    opacity: 0;
    animation: fadeUp 0.8s var(--ease-out-expo) 0.25s forwards;
}

@keyframes fadeUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.content-wrapper {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 0;
    padding: clamp(1.75rem, 4vw, 3rem);
    position: relative;
    overflow: hidden;
    opacity: 0;
    transform: translateY(24px);
    animation: fadeUp 0.9s var(--ease-out-expo) 0.35s forwards;
}

.content-wrapper::before {
    content: '';
    position: absolute;
    top: 0;
    left: 15%;
    right: 15%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold-glow-strong), transparent);
}

/* Sections */
.section {
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 2rem;
    margin-bottom: 2rem;
}

.section:last-child {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

h2 {
    font-family: var(--font-display);
    font-size: clamp(1.25rem, 3vw, 1.6rem);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1.25rem;
    position: relative;
    line-height: 1.3;
}

h2 .section-number {
    display: inline-block;
    color: var(--gold);
    font-family: var(--font-body);
    font-size: 0.72em;
    font-weight: 600;
    letter-spacing: 0.05em;
    margin-right: 0.4em;
    opacity: 0.85;
}

h3 {
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--gold-soft);
    margin-top: 1.75rem;
    margin-bottom: 0.75rem;
    letter-spacing: 0.01em;
}

p {
    margin-bottom: 1.3rem;
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.8;
    text-align: justify;
    hyphens: auto;
    -webkit-hyphens: auto;
}

strong {
    color: var(--text-primary);
    font-weight: 600;
}

ul {
    margin-bottom: 1.3rem;
    padding-left: 0;
    list-style: none;
    color: var(--text-secondary);
}

li {
    position: relative;
    padding-left: 1.4rem;
    margin-bottom: 0.6rem;
    font-size: 0.95rem;
    line-height: 1.75;
    text-align: justify;
    hyphens: auto;
    -webkit-hyphens: auto;
}

li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.7em;
    width: 4px;
    height: 4px;
    border-radius: 0;
    background: var(--gold);
    opacity: 0.5;
    transform: rotate(45deg);
}

/* Sidebar */
.page-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
    max-width: 1080px;
    margin: 0 auto;
    padding: clamp(2rem, 5vw, 3.5rem) clamp(1.25rem, 4vw, 2rem);
    position: relative;
    z-index: 2;
}

@media (min-width: 1024px) {
    .page-layout {
        grid-template-columns: 200px 1fr;
        gap: 2.5rem;
    }
}

.toc-sidebar {
    display: none;
}

@media (min-width: 1024px) {
    .toc-sidebar {
        display: block;
        position: sticky;
        top: calc(var(--header-h) + 2rem);
        align-self: start;
        max-height: calc(100vh - var(--header-h) - 4rem);
        overflow-y: auto;
        scrollbar-width: none;
    }

    .toc-sidebar::-webkit-scrollbar {
        display: none;
    }
}

.toc-sidebar nav {
    opacity: 0;
    animation: fadeUp 0.8s var(--ease-out-expo) 0.5s forwards;
}

.toc-label {
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    margin-bottom: 1rem;
}

.toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.toc-list li {
    padding-left: 0;
    margin-bottom: 0;
}

.toc-list li::before {
    display: none;
}

.toc-link {
    display: block;
    padding: 0.35rem 0 0.35rem 0.9rem;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    text-decoration: none;
    border-left: 1px solid var(--border-subtle);
    transition: all 0.3s var(--ease-out-quart);
    line-height: 1.4;
    text-align: left;
}

.toc-link:hover {
    color: var(--text-secondary);
    border-left-color: var(--border-active);
}

.toc-link.active {
    color: var(--gold);
    border-left-color: var(--gold);
}

/* Scroll Reveal */
.reveal {
    opacity: 0;
    transform: translateY(14px);
    transition: opacity 0.7s var(--ease-out-expo),
        transform 0.7s var(--ease-out-expo);
}

.reveal.visible {
    opacity: 1;
    transform: translateY(0);
}

.reading-progress {
    position: fixed;
    top: var(--header-h);
    left: 0;
    width: 0%;
    height: 1px;
    background: linear-gradient(90deg, var(--gold-deep), var(--gold), var(--gold-soft));
    z-index: 101;
    transition: width 0.15s linear;
    will-change: width;
}

.accordion-section {
    border: 1px solid var(--border-subtle);
    border-radius: 0;
    margin-bottom: 0.5rem;
    overflow: hidden;
    transition: border-color 0.35s ease, box-shadow 0.35s ease;
    background: var(--bg-elevated);
}

.accordion-section:hover {
    border-color: var(--border-active);
}

.accordion-section.open {
    border-color: var(--border-active);
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.2);
}

.accordion-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: none;
    border: none;
    cursor: pointer;
    font-family: var(--font-display);
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-high);
    text-align: left;
    line-height: 1.3;
    gap: 1rem;
    transition: color 0.3s ease;
}

.accordion-trigger:hover {
    color: var(--gold-soft);
}

.accordion-icon {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    color: var(--gold);
    transition: transform 0.4s var(--ease-out-expo);
}

.accordion-section.open .accordion-icon {
    transform: rotate(45deg);
}

.accordion-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.5s var(--ease-out-expo);
}

.accordion-body-inner {
    padding: 0 1.25rem 1.25rem;
}

/* Back to Top */
.back-to-top {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 90;
    width: 40px;
    height: 40px;
    border-radius: 0;
    border: 1px solid var(--border-active);
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    color: var(--gold);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.4s var(--ease-out-expo);
    pointer-events: none;
}

.back-to-top.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.back-to-top:hover {
    background: var(--gold-glow);
    border-color: var(--gold);
    transform: translateY(-2px);
}

footer {
    margin-top: auto;
    padding: 1.5rem clamp(1.25rem, 4vw, 3rem);
    text-align: center;
    border-top: 1px solid var(--border-subtle);
    position: relative;
    z-index: 2;
}

footer p {
    font-family: var(--font-body);
    font-size: 0.7rem;
    color: var(--text-tertiary);
    text-align: center;
    margin-bottom: 0;
    letter-spacing: 0.5px;
}

@media (max-width: 768px) {
    :root {
        --header-h: 56px;
    }

    .accordion-trigger {
        padding: 0.9rem 1rem;
        font-size: 0.95rem;
    }

    .accordion-body-inner {
        padding: 0 1rem 1rem;
    }

    .back-to-top {
        bottom: 1.25rem;
        right: 1.25rem;
        width: 36px;
        height: 36px;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.65rem;
    }

    p,
    li {
        font-size: 0.9rem;
    }
}

@media print {

    .page-ambient,
    .page-grain,
    .reading-progress,
    .back-to-top,
    .toc-sidebar,
    header {
        display: none !important;
    }

    body {
        background: #fff;
        color: #111;
    }

    .content-wrapper {
        background: none;
        border: none;
        box-shadow: none;
        padding: 0;
    }

    h1,
    h2 {
        color: #111;
    }

    p,
    li {
        color: #333;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .reveal {
        opacity: 1;
        transform: none;
    }

    html {
        scroll-behavior: auto;
    }
}

:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 3px;
}
