/* ===========================================
   mosun.xyz — Light-Academia Design
   A study in scholarly contradictions
   =========================================== */

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

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    background-color: #F5F0E6;
    color: #3A352E;
    font-family: 'EB Garamond', Georgia, serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.5vw, 1.12rem);
    line-height: 1.82;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* --- Opening Section --- */
.opening-section {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 0 24px;
}

.opening-content {
    width: 100%;
    max-width: 720px;
    margin-top: 33.333vh;
}

.site-title {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 600;
    font-size: clamp(1.8rem, 3.5vw, 2.8rem);
    color: #3A352E;
    letter-spacing: 0.02em;
    margin-bottom: 0.5em;
}

.site-subtitle {
    font-family: 'EB Garamond', Georgia, serif;
    font-style: italic;
    font-weight: 400;
    font-size: clamp(1rem, 1.5vw, 1.12rem);
    color: #8A8070;
    max-width: 540px;
}

/* Candle animation in upper-right */
.candle-animation {
    position: absolute;
    top: 40px;
    right: 40px;
    opacity: 0;
    animation: candleFadeIn 1.5s ease-out 0.5s forwards;
}

.candle-animation .flame {
    animation: flameFlicker 2s ease-in-out infinite;
    transform-origin: center bottom;
}

.candle-animation .flame-inner {
    animation: flameInnerFlicker 1.8s ease-in-out infinite 0.1s;
    transform-origin: center bottom;
}

@keyframes candleFadeIn {
    0% { opacity: 0; transform: translateY(8px); }
    100% { opacity: 1; transform: translateY(0); }
}

@keyframes flameFlicker {
    0%, 100% { transform: scaleX(1) scaleY(1); opacity: 1; }
    25% { transform: scaleX(0.9) scaleY(1.05); opacity: 0.9; }
    50% { transform: scaleX(1.05) scaleY(0.95); opacity: 1; }
    75% { transform: scaleX(0.95) scaleY(1.02); opacity: 0.85; }
}

@keyframes flameInnerFlicker {
    0%, 100% { transform: scaleX(1) scaleY(1); }
    30% { transform: scaleX(1.1) scaleY(0.9); }
    60% { transform: scaleX(0.85) scaleY(1.1); }
}

/* --- Chapter Sections --- */
.chapter {
    position: relative;
    min-height: 60vh;
    max-width: 720px;
    margin: 0 auto;
    padding: 80px 24px 100px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 400ms ease-out, transform 400ms ease-out;
}

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

/* Duotone left borders */
.chapter-odd {
    border-left: 3px solid #C4A868;
}

.chapter-even {
    border-left: 3px solid #8AAA90;
}

/* Chapter Numbers */
.chapter-number {
    position: absolute;
    top: 40px;
    left: 24px;
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 300;
    font-size: 6rem;
    color: #C8B8A0;
    opacity: 0.2;
    line-height: 1;
    pointer-events: none;
    user-select: none;
}

/* Chapter Titles */
.chapter-title {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 600;
    font-size: clamp(1.8rem, 3.5vw, 2.8rem);
    color: #3A352E;
    margin-bottom: 0.25em;
    position: relative;
    z-index: 1;
}

.chapter-subtitle {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1rem, 1.8vw, 1.25rem);
    color: #8A8070;
    margin-bottom: 2em;
}

/* --- Text Blocks --- */
.text-block {
    position: relative;
    margin-bottom: 2.5em;
    background-color: #FFFCF5;
    padding: 2em 2em;
    border-radius: 2px;
    box-shadow: 0 2px 12px rgba(58, 53, 46, 0.05);
}

.text-block p {
    margin-bottom: 1.2em;
}

.text-block p:last-child {
    margin-bottom: 0;
}

.text-block em {
    font-style: italic;
    color: #B08850;
}

/* --- Margin Notes --- */
.margin-note {
    font-family: 'EB Garamond', Georgia, serif;
    font-style: italic;
    font-weight: 400;
    font-size: 0.85rem;
    color: #8A8070;
    line-height: 1.6;
    opacity: 0;
    transition: opacity 200ms ease-out;
}

.margin-note.visible {
    opacity: 1;
}

/* Desktop: positioned in left margin */
@media (min-width: 1200px) {
    .chapter {
        padding-left: 40px;
    }

    .margin-note {
        position: absolute;
        left: -200px;
        width: 170px;
        text-align: right;
    }
}

/* Mobile/Tablet: inline indented */
@media (max-width: 1199px) {
    .margin-note {
        display: block;
        padding: 0.75em 1em;
        margin-bottom: 1em;
        border-left: 2px solid #D8D0C0;
        background-color: transparent;
    }
}

/* --- Euler Diagrams --- */
.euler-diagram {
    position: relative;
    width: 120px;
    height: 80px;
    margin-bottom: 1.5em;
}

.euler-circle {
    position: absolute;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: transparent;
    border-width: 2px;
    border-style: solid;
    top: 10px;
}

.euler-circle-a {
    left: 0;
}

.euler-circle-b {
    left: 40px;
}

.euler-diagram-gold .euler-circle-a {
    border-color: #C4A868;
}

.euler-diagram-gold .euler-circle-b {
    border-color: #8AAA90;
}

.euler-diagram-sage .euler-circle-a {
    border-color: #8AAA90;
}

.euler-diagram-sage .euler-circle-b {
    border-color: #C4A868;
}

/* --- Golden Rectangles --- */
.golden-rectangle-container {
    position: relative;
    width: 200px;
    height: 130px;
    margin: 2em auto;
}

.golden-rect {
    position: absolute;
    border: 1.5px solid #D8D0C0;
    border-radius: 1px;
}

.golden-rect-1 {
    width: 200px;
    height: 123.6px;
    top: 0;
    left: 0;
    background-color: rgba(216, 208, 192, 0.08);
}

.golden-rect-2 {
    width: 123.6px;
    height: 76.4px;
    top: 12px;
    left: 12px;
    background-color: rgba(216, 208, 192, 0.12);
}

.golden-rect-3 {
    width: 76.4px;
    height: 47.2px;
    top: 24px;
    left: 24px;
    background-color: rgba(216, 208, 192, 0.18);
}

/* --- Paradox Arrows --- */
.paradox-arrows {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
    margin: 2em auto;
    height: 40px;
}

.arrow {
    width: 0;
    height: 0;
}

.arrow-left {
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-right: 18px solid #C4A868;
}

.arrow-right {
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-left: 18px solid #8AAA90;
}

.arrow-up {
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-bottom: 18px solid #C4A868;
}

.arrow-down {
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 18px solid #8AAA90;
}

/* --- Chapter Breaks (Lottie-style SVG animations) --- */
.chapter-break {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px 0;
    opacity: 0;
    transition: opacity 600ms ease-out;
}

.chapter-break.visible {
    opacity: 1;
}

.chapter-break-svg {
    display: block;
}

/* Page turning animation */
.chapter-break.visible .page-left {
    animation: pageLeftTurn 1.2s ease-in-out forwards;
}

.chapter-break.visible .page-right {
    animation: pageRightTurn 1.2s ease-in-out 0.2s forwards;
}

.chapter-break.visible .page-turn {
    animation: pageCurlDraw 1s ease-out 0.4s forwards;
    stroke-dasharray: 50;
    stroke-dashoffset: 50;
}

@keyframes pageLeftTurn {
    0% { transform: rotate(0deg); }
    50% { transform: rotate(-3deg); }
    100% { transform: rotate(0deg); }
}

@keyframes pageRightTurn {
    0% { transform: rotate(0deg); }
    50% { transform: rotate(3deg); }
    100% { transform: rotate(0deg); }
}

@keyframes pageCurlDraw {
    0% { stroke-dashoffset: 50; }
    100% { stroke-dashoffset: 0; }
}

/* Pen nib animation */
.chapter-break.visible .pen-line {
    stroke-dasharray: 40;
    stroke-dashoffset: 40;
    animation: penDraw 1.2s ease-out forwards;
}

.chapter-break.visible .pen-nib {
    animation: penNibPulse 0.8s ease-in-out 1s forwards;
    opacity: 0;
}

.chapter-break.visible .pen-tip {
    animation: penTipAppear 0.6s ease-out 0.8s forwards;
    opacity: 0;
}

@keyframes penDraw {
    0% { stroke-dashoffset: 40; }
    100% { stroke-dashoffset: 0; }
}

@keyframes penNibPulse {
    0% { opacity: 0; transform: scale(0.5); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes penTipAppear {
    0% { opacity: 0; }
    100% { opacity: 0.5; }
}

/* Candle break animation */
.chapter-break.visible .flame {
    animation: flameFlicker 2s ease-in-out infinite;
    transform-origin: center bottom;
}

.chapter-break.visible .flame-inner {
    animation: flameInnerFlicker 1.8s ease-in-out infinite 0.1s;
    transform-origin: center bottom;
}

/* --- Colophon --- */
.colophon-text {
    text-align: left;
}

.colophon-text p {
    font-family: 'EB Garamond', Georgia, serif;
    font-style: italic;
    color: #8A8070;
}

.colophon-date {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 300;
    font-size: 0.85rem;
    color: #C8B8A0;
    margin-top: 2em;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.colophon-note {
    font-family: 'EB Garamond', Georgia, serif;
    font-style: italic;
    font-size: 0.95rem;
    color: #8A8070;
    margin-top: 0.5em;
}

/* --- Links (if any) --- */
a {
    color: #B08850;
    text-decoration: none;
    transition: color 200ms ease;
}

a:hover {
    color: #8A6A3A;
}

/* --- Selection --- */
::selection {
    background-color: rgba(196, 168, 104, 0.25);
    color: #3A352E;
}

/* --- Responsive Adjustments --- */
@media (max-width: 768px) {
    .opening-content {
        margin-top: 25vh;
    }

    .chapter {
        padding: 60px 20px 80px;
    }

    .chapter-number {
        font-size: 4rem;
        top: 20px;
        left: 20px;
    }

    .candle-animation {
        top: 20px;
        right: 20px;
    }

    .text-block {
        padding: 1.5em 1.25em;
    }

    .golden-rectangle-container {
        width: 150px;
        height: 100px;
    }

    .golden-rect-1 {
        width: 150px;
        height: 92.7px;
    }

    .golden-rect-2 {
        width: 92.7px;
        height: 57.3px;
    }

    .golden-rect-3 {
        width: 57.3px;
        height: 35.4px;
    }
}

@media (max-width: 480px) {
    .chapter-number {
        font-size: 3rem;
    }

    .euler-diagram {
        width: 90px;
        height: 60px;
    }

    .euler-circle {
        width: 45px;
        height: 45px;
    }

    .euler-circle-b {
        left: 30px;
    }
}
