/* === Base Reset & Variables === */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --deep-ink: #2d1f0e;
    --parchment: #f5ede0;
    --warm-brass: #b8956a;
    --sea-blue: #4a7c8a;
    --cottage-cream: #faf6ee;
    --deep-ocean: #1a3a4a;
    --rosehip: #c4897a;
    --sage: #6b7f5e;
    --walnut: #3d2e1c;
    --faded-graphite: #7a6248;
    --base-unit: 1.618rem;
}

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--parchment);
    color: var(--walnut);
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: clamp(1.05rem, 1.8vw, 1.2rem);
    line-height: 1.75;
    overflow-x: hidden;
}

/* === Floating Background Layer === */
#floating-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
    overflow: hidden;
}

.float-el {
    position: absolute;
    opacity: 0.15;
    animation: float-drift 30s ease-in-out infinite;
}

.compass-rose {
    top: 10%;
    left: 8%;
    animation-duration: 35s;
}

.compass-2 {
    top: 60%;
    right: 12%;
    left: auto;
    animation-duration: 28s;
    animation-delay: -10s;
}

.lavender {
    top: 25%;
    right: 10%;
    left: auto;
    opacity: 0.12;
    animation-duration: 25s;
    animation-delay: -5s;
}

.wild-rose {
    top: 50%;
    left: 5%;
    opacity: 0.12;
    animation-duration: 32s;
    animation-delay: -15s;
}

.coord-mark {
    font-family: 'Caveat', cursive;
    font-size: 1rem;
    color: var(--sea-blue);
    opacity: 0.1;
    top: 35%;
    right: 6%;
    left: auto;
    animation-duration: 40s;
    animation-delay: -8s;
}

.coord-2 {
    top: 70%;
    left: 7%;
    right: auto;
    animation-delay: -20s;
}

.star-cluster {
    top: 80%;
    left: 15%;
    opacity: 0.2;
    animation-duration: 22s;
    animation-delay: -3s;
}

.meadow-grass {
    top: 45%;
    right: 5%;
    left: auto;
    opacity: 0.12;
    animation-duration: 38s;
    animation-delay: -12s;
}

@keyframes float-drift {
    0%, 100% { transform: translateY(0) translateX(0); }
    25% { transform: translateY(-15px) translateX(5px); }
    50% { transform: translateY(5px) translateX(-8px); }
    75% { transform: translateY(-10px) translateX(3px); }
}

/* === Main Content === */
#content {
    max-width: 680px;
    margin: 0 auto;
    padding: 0 clamp(1.5rem, 5vw, 6rem);
    position: relative;
}

/* === Chapters === */
.chapter {
    min-height: 100vh;
    padding: 12vh 0;
    position: relative;
}

.chapter-header {
    margin-bottom: calc(var(--base-unit) * 2);
}

.chapter-subtitle {
    font-family: 'Caveat', cursive;
    font-size: clamp(1.1rem, 2vw, 1.4rem);
    color: var(--faded-graphite);
    font-weight: 400;
}

/* === Typography === */
.drop-cap {
    float: left;
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: 5em;
    line-height: 0.8;
    margin-right: 0.08em;
    margin-top: 0.05em;
    color: var(--warm-brass);
}

.opening-line {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: clamp(1.8rem, 4vw, 2.8rem);
    line-height: 1.3;
    letter-spacing: -0.02em;
    color: var(--deep-ink);
    text-align: center;
    padding: 20vh 0 8vh;
}

.chapter-body p {
    margin-bottom: var(--base-unit);
}

.chapter-body p em {
    font-weight: 600;
    font-style: italic;
}

.larger-text p {
    font-size: 1.15em;
}

/* === Reveal Animation === */
.reveal {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.reveal.visible {
    opacity: 1;
    transform: translateY(0);
}

/* === Dividers === */
.divider {
    display: block;
    width: 60%;
    max-width: 300px;
    height: 20px;
    margin: 8vh auto;
}

/* === Organic Blobs === */
.blob {
    position: absolute;
    width: 120px;
    height: 120px;
    border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%;
    animation: blob-breathe 8s ease-in-out infinite;
    pointer-events: none;
}

.sun-blob {
    background: radial-gradient(circle at 40% 40%, var(--warm-brass), var(--rosehip));
    right: -8vw;
    top: 20vh;
    opacity: 0.6;
    box-shadow: 0 0 40px rgba(184, 149, 106, 0.3);
}

.moon-blob {
    background: radial-gradient(circle at 40% 40%, var(--sea-blue), var(--deep-ocean));
    left: -8vw;
    top: 15vh;
    opacity: 0.7;
    animation-delay: -4s;
    box-shadow: 0 0 60px rgba(74, 124, 138, 0.5), 0 0 100px rgba(74, 124, 138, 0.2);
}

.moon-blob-light {
    background: radial-gradient(circle at 40% 40%, var(--sea-blue), var(--deep-ocean));
    left: -6vw;
    top: 25vh;
    opacity: 0.4;
    width: 90px;
    height: 90px;
    animation-delay: -4s;
}

.converging-sun {
    right: -4vw;
    top: 30vh;
    width: 100px;
    height: 100px;
    opacity: 0.5;
}

.converging-moon {
    left: -4vw;
    top: 32vh;
}

@keyframes blob-breathe {
    0%, 100% { border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%; }
    50% { border-radius: 60% 40% 50% 50% / 50% 60% 40% 50%; }
}

/* === Clock Blob === */
.clock-blob {
    position: absolute;
    right: -6vw;
    top: 10vh;
    width: 160px;
    height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.clock-ring {
    position: absolute;
    border-radius: 50%;
    border: 2px solid var(--warm-brass);
    animation: clock-pulse 4s ease-in-out infinite;
}

.ring-1 {
    width: 60px;
    height: 60px;
    opacity: 0.3;
    animation-delay: 0s;
}

.ring-2 {
    width: 100px;
    height: 100px;
    opacity: 0.2;
    animation-delay: 1.3s;
}

.ring-3 {
    width: 140px;
    height: 140px;
    opacity: 0.1;
    animation-delay: 2.6s;
}

@keyframes clock-pulse {
    0%, 100% { transform: scale(1); opacity: 0.3; }
    50% { transform: scale(1.1); opacity: 0.1; }
}

/* === Clock Face === */
.clock-face-container {
    position: absolute;
    left: -8vw;
    top: 15vh;
}

.clock-hand {
    transform-origin: 30px 30px;
    animation: clock-hour 720s linear infinite;
}

.clock-minute {
    transform-origin: 30px 30px;
    animation: clock-min 60s linear infinite;
}

@keyframes clock-hour {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes clock-min {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* === Marginalia === */
.marginalia {
    position: absolute;
    font-family: 'Caveat', cursive;
    font-size: clamp(0.85rem, 1.3vw, 1rem);
    color: var(--faded-graphite);
}

.left-margin {
    left: -8vw;
    top: 8vh;
}

.right-margin {
    right: -8vw;
}

.margin-note {
    display: block;
    max-width: 120px;
    line-height: 1.4;
}

/* === Dark Chapter === */
.dark-transition-in {
    height: 200px;
    background: linear-gradient(to bottom, var(--parchment) 0%, var(--deep-ocean) 100%);
    margin: 0 calc(-50vw + 50%);
    width: 100vw;
    position: relative;
    left: 50%;
    transform: translateX(-50%);
}

.dark-chapter {
    background-color: var(--deep-ocean);
    margin: 0 calc(-50vw + 50%);
    width: 100vw;
    padding-left: calc(50vw - 340px);
    padding-right: calc(50vw - 340px);
    position: relative;
}

.dark-chapter::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-conic-gradient(rgba(255,255,255,0.02) 0% 25%, transparent 0% 50%) 0 0 / 4px 4px;
    pointer-events: none;
}

.dark-transition-out {
    height: 200px;
    background: linear-gradient(to bottom, var(--deep-ocean) 0%, var(--parchment) 100%);
    margin: 0 calc(-50vw + 50%);
    width: 100vw;
    position: relative;
    left: 50%;
    transform: translateX(-50%);
}

.light-text {
    color: var(--parchment);
}

.light-drop {
    color: var(--sea-blue);
}

.dark-chapter .chapter-subtitle {
    color: var(--rosehip);
}

.dark-chapter .moon-blob {
    box-shadow: 0 0 80px rgba(74, 124, 138, 0.6), 0 0 120px rgba(74, 124, 138, 0.3);
}

/* === Final Section === */
.final-space {
    height: 30vh;
}

.final-coordinate {
    text-align: center;
    font-family: 'Caveat', cursive;
    font-size: clamp(1.2rem, 3vw, 1.8rem);
    color: var(--faded-graphite);
    padding-bottom: 10vh;
}

/* === Compass Navigation === */
#compass-nav {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 100;
}

.compass-icon {
    cursor: pointer;
    opacity: 0.4;
    transition: opacity 0.3s ease;
}

.compass-icon:hover {
    opacity: 1;
}

.chapter-list {
    position: absolute;
    bottom: 60px;
    right: 0;
    background: var(--parchment);
    border: 1px solid var(--warm-brass);
    border-radius: 4px;
    padding: 1rem;
    display: none;
    flex-direction: column;
    gap: 0.5rem;
    box-shadow: 0 4px 20px rgba(45, 31, 14, 0.15);
    min-width: 200px;
}

.chapter-list.open {
    display: flex;
}

.chapter-list a {
    font-family: 'Caveat', cursive;
    font-size: 1.1rem;
    color: var(--deep-ink);
    text-decoration: none;
    padding: 0.25rem 0.5rem;
    border-radius: 3px;
    transition: background 0.2s;
}

.chapter-list a:hover {
    background: rgba(184, 149, 106, 0.2);
}

/* === Responsive === */
@media (max-width: 900px) {
    .marginalia {
        position: relative;
        left: auto !important;
        right: auto !important;
        margin: 1rem 0;
    }

    .blob {
        display: none;
    }

    .clock-blob {
        display: none;
    }

    .clock-face-container {
        display: none;
    }

    .sun-blob, .moon-blob, .moon-blob-light, .converging-sun, .converging-moon {
        display: none;
    }

    .dark-chapter {
        padding-left: clamp(1.5rem, 5vw, 3rem);
        padding-right: clamp(1.5rem, 5vw, 3rem);
    }

    .float-el:nth-child(n+5) {
        display: none;
    }
}

@media (max-width: 600px) {
    .opening-line {
        padding: 10vh 0 5vh;
    }

    #compass-nav {
        bottom: 1rem;
        right: 1rem;
    }
}
