/* =====================================================
   20241203.com — a notebook for one long night
   sepia-nostalgic / minimalist / handwritten / layered-depth
   -----------------------------------------------------
   Implementation notes (per DESIGN.md):
   Uses IntersectionObserver to trigger per-page animations.
   Primary fonts: Caveat, Gaegu, Cormorant Garamond
   System-fallback families used: Inter, Space Grotesk
   ===================================================== */

:root {
    --paper-cream:        #f5ebd9;
    --paper-endpaper:     #ebdcc0;
    --sepia-light:        #c9a875;
    --sepia-mid:          #8b6f47;
    --sepia-deep:         #5a4226;
    --walnut-ink:         #2e1f12;
    --rust-accent:        #a83828;
    --ruling-line:        #d8c9a8;

    --hand-primary:   "Caveat", "Bradley Hand", "Inter", cursive;
    --hand-korean:    "Gaegu", "Caveat", "Inter", cursive;
    --serif-quote:    "Cormorant Garamond", "Times New Roman", serif;
    --sys-sans:       "Inter", "Space Grotesk", system-ui, sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    background: var(--paper-cream);
    color: var(--sepia-deep);
    font-family: var(--hand-korean);
    overflow-x: hidden;
    min-height: 100vh;
    line-height: 1.7;
    position: relative;
    animation: bodyFade 1.4s ease-out;
}

@keyframes bodyFade {
    0%   { background: #fbf6ec; }
    100% { background: var(--paper-cream); }
}

/* Hide-from-flow defs container */
.svg-defs {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* =============== PAPER GRAIN (fixed overlay) =============== */
.paper-grain {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.06;
    mix-blend-mode: multiply;
}
.paper-grain svg { width: 100%; height: 100%; display: block; }

/* =============== MARGIN COLUMN (timestamps) =============== */
.margin-column {
    position: fixed;
    top: 0;
    left: 0;
    width: 12%;
    height: 100vh;
    padding-top: 22vh;
    padding-left: 3.5vw;
    z-index: 50;
    pointer-events: auto;
    opacity: 0;
    transition: opacity 1s ease;
}
.margin-column.visible {
    opacity: 1;
}

.timestamps {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 1.6rem;
}
.timestamps .ts {
    font-family: var(--hand-primary);
    font-size: 1.5rem;
    color: var(--sepia-light);
    font-weight: 400;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: color 0.9s ease, font-weight 0.9s ease, transform 0.6s ease;
    line-height: 1;
}
.timestamps .ts.active {
    color: var(--walnut-ink);
    font-weight: 600;
    transform: translateX(4px);
}

/* =============== NOTEBOOK =============== */
.notebook {
    position: relative;
    width: 100%;
    margin: 0 auto;
    max-width: 100%;
}

/* =============== COVER =============== */
.cover {
    position: relative;
    width: 100%;
    height: 100vh;
    min-height: 600px;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse at 30% 25%, #efe2c8 0%, transparent 60%),
        radial-gradient(ellipse at 70% 80%, #e3d2b0 0%, transparent 65%),
        linear-gradient(180deg, #ede0c4 0%, #e1d1ad 100%);
    overflow: hidden;
}
.cover-inner {
    position: relative;
    width: 86%;
    max-width: 980px;
    height: 80%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.cover-frame {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
.cover-frame-rect {
    stroke-dasharray: 3050;
    stroke-dashoffset: 3050;
    animation: drawBorder 2.6s 1.4s ease-in-out forwards;
}
@keyframes drawBorder {
    to { stroke-dashoffset: 0; }
}

.cover-mark {
    position: relative;
    text-align: center;
    z-index: 2;
}
.cover-1203 {
    width: clamp(200px, 28vw, 360px);
    height: auto;
    display: block;
    margin: 0 auto;
}
.ink-stroke {
    stroke-dasharray: 360;
    stroke-dashoffset: 360;
    animation: writeStroke 0.6s ease-out forwards;
    animation-delay: 0.2s;
}
.cover-1203 .ink-stroke:nth-child(2) { animation-delay: 0.34s; }
.cover-1203 .ink-stroke:nth-child(3) { animation-delay: 0.48s; }
.cover-1203 .ink-stroke:nth-child(4) { animation-delay: 0.56s; }
.cover-1203 .ink-stroke:nth-child(5) { animation-delay: 0.7s; }
.cover-1203 .ink-stroke.ink-dot {
    stroke-dasharray: none;
    stroke-dashoffset: 0;
    opacity: 0;
    animation: dotFade 0.4s 0.55s ease-out forwards;
}
@keyframes writeStroke {
    0%   { stroke-dashoffset: 360; }
    100% { stroke-dashoffset: 0; }
}
@keyframes dotFade {
    to { opacity: 1; }
}

.cover-subtitle {
    margin-top: 1.4rem;
    font-family: var(--hand-primary);
    font-size: clamp(1.1rem, 1.8vw, 1.7rem);
    color: var(--sepia-deep);
    letter-spacing: 0.01em;
    opacity: 0;
    transform: rotate(-1deg);
    animation: typeIn 0.8s 0.9s ease-out forwards;
}
@keyframes typeIn {
    0%   { opacity: 0; clip-path: inset(0 100% 0 0); }
    100% { opacity: 1; clip-path: inset(0 0 0 0); }
}
.cursor {
    display: inline-block;
    width: 2px;
    height: 1.1em;
    background: var(--sepia-deep);
    margin-left: 4px;
    vertical-align: text-bottom;
    animation: blink 1s 1.7s steps(1) 6;
    opacity: 0;
}
@keyframes blink {
    0%, 49%   { opacity: 1; }
    50%, 100% { opacity: 0; }
}

.scroll-hint {
    position: absolute;
    bottom: 4vh;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    animation: scrollHintIn 0.8s 4.2s ease-out forwards, bob 2s 5s ease-in-out infinite;
}
@keyframes scrollHintIn {
    0%   { opacity: 0; transform: translate(-50%, 10px); }
    100% { opacity: 0.75; transform: translate(-50%, 0); }
}
@keyframes bob {
    0%, 100% { transform: translate(-50%, 0); }
    50%      { transform: translate(-50%, 8px); }
}

/* =============== ENDPAPER =============== */
.endpaper {
    position: relative;
    width: 100%;
    height: 50vh;
    min-height: 360px;
    background: var(--paper-endpaper);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    overflow: hidden;
}
.endpaper-leaf {
    transform: rotate(-8deg) translateX(-12vw);
    filter: drop-shadow(0 2px 4px rgba(90,66,38,0.15));
}
.endpaper-date {
    font-family: var(--hand-korean);
    font-size: clamp(1.1rem, 1.6vw, 1.5rem);
    color: var(--sepia-deep);
    transform: rotate(-1deg);
    letter-spacing: 0.02em;
}
.endpaper-frame {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
.border-stroke {
    stroke-dasharray: 2620;
    stroke-dashoffset: 2620;
    transition: stroke-dashoffset 2.4s ease-in-out;
}
.border-stroke.in-view {
    stroke-dashoffset: 0;
}

/* =============== PAGE (parallax) =============== */
.page {
    position: relative;
    width: 100%;
    min-height: 120vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 8vh 14% 8vh 16%;
    background:
        repeating-linear-gradient(
            180deg,
            transparent 0,
            transparent 38px,
            rgba(216, 201, 168, 0.16) 38px,
            rgba(216, 201, 168, 0.16) 39px
        ),
        var(--paper-cream);
}

.layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    will-change: transform;
}
.layer.layer-back {
    z-index: 1;
    transform: translate3d(0, 0, -200px);
}
.layer.layer-mid {
    z-index: 2;
    position: relative;
    pointer-events: auto;
    width: 100%;
}
.layer.layer-front {
    z-index: 3;
    transform: translate3d(0, 0, 120px);
}

.mountains {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 50%;
    opacity: 0;
    transition: opacity 1.2s ease;
}
.page.in-view .mountains {
    opacity: 1;
}

/* mid layer page paper */
.page-paper {
    position: relative;
    z-index: 2;
    max-width: 620px;
    margin-left: 0;
    padding: 1.6rem 0;
}
.page-paper-wide { max-width: 700px; }

.page-time {
    font-family: var(--hand-primary);
    font-size: clamp(2.5rem, 6vw, 6rem);
    color: var(--sepia-deep);
    line-height: 1;
    margin-bottom: 1.4rem;
    letter-spacing: 0.01em;
    font-feature-settings: "tnum" 0;
    transform: rotate(-1.5deg);
    font-weight: 500;
}

.page-body {
    font-family: var(--hand-korean);
    font-size: clamp(1.05rem, 1.35vw, 1.32rem);
    line-height: 1.95;
    color: var(--ruling-line);
    margin-bottom: 1.4rem;
    transition: color 1.6s ease;
    letter-spacing: 0.01em;
    max-width: 32em;
}
.page.in-view .page-body {
    color: var(--sepia-deep);
}
.page-body.en {
    font-family: var(--hand-primary);
    font-size: clamp(1.1rem, 1.5vw, 1.5rem);
    line-height: 1.55;
    color: var(--sepia-mid);
    transform: rotate(-0.5deg);
    transform-origin: top left;
}
.page.in-view .page-body.en {
    color: var(--sepia-mid);
}

.official-fragment {
    font-family: var(--serif-quote);
    font-style: italic;
    font-weight: 400;
    font-size: 0.95rem;
    color: var(--sepia-light);
    border-left: 1px solid var(--ruling-line);
    padding: 0.4rem 0 0.4rem 1rem;
    margin: 1.4rem 0 0;
    max-width: 28em;
    transform: rotate(-0.4deg);
    line-height: 1.6;
}

/* circled word */
.circled {
    position: relative;
    display: inline-block;
    padding: 0 0.3em;
}
.circled::before {
    content: "";
    position: absolute;
    inset: -0.2em -0.4em;
    border: 1.5px solid var(--sepia-deep);
    border-radius: 50%;
    transform: rotate(-3deg) scale(1.05);
    pointer-events: none;
}

/* coffee ring on page 4 */
.coffee-ring {
    position: absolute;
    width: 240px;
    height: 240px;
    top: 55%;
    right: 16%;
    border-radius: 50%;
    background:
        radial-gradient(
            circle,
            transparent 38%,
            rgba(139, 111, 71, 0.22) 40%,
            rgba(139, 111, 71, 0.08) 46%,
            transparent 50%
        );
    opacity: 0.7;
    transform: rotate(15deg);
    pointer-events: none;
    z-index: 1;
}

/* ============== MARGINALIA (front layer) ============== */
.marginalia {
    position: absolute;
    pointer-events: auto;
    opacity: 0;
    transform: translateY(20px) rotate(var(--rot, -1deg));
    transition: opacity 0.9s cubic-bezier(0.25,0.46,0.45,0.94),
                transform 0.9s cubic-bezier(0.25,0.46,0.45,0.94);
}
.page.in-view .marginalia {
    opacity: 1;
    transform: translateY(0) rotate(var(--rot, -1deg));
}

.handnote {
    font-family: var(--hand-primary);
    font-size: clamp(1rem, 1.4vw, 1.4rem);
    color: var(--sepia-deep);
    line-height: 1.4;
    max-width: 14em;
    letter-spacing: 0.01em;
}
.handnote.rust {
    color: var(--rust-accent);
    font-size: clamp(2rem, 4vw, 3.4rem);
    line-height: 1;
    font-weight: 600;
}
.handnote.strike {
    text-decoration: line-through;
    text-decoration-thickness: 1.2px;
    text-decoration-color: var(--sepia-deep);
    opacity: 0.7;
}

.leaf-press {
    filter: drop-shadow(0 2px 4px rgba(90, 66, 38, 0.15));
    cursor: pointer;
    transition: transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                filter 0.6s ease;
}
.leaf-press:hover {
    transform: translateY(-3px) rotate(2deg);
    filter: drop-shadow(0 5px 9px rgba(90, 66, 38, 0.28));
    transition: transform 0.6s ease, filter 0.6s ease;
}
.leaf-press:not(:hover) {
    transition: transform 0.8s ease, filter 0.8s ease;
}

.doodle-arrow svg { display: block; }
.stamp-mark svg   { display: block; }

/* =============== CLOSING =============== */
.closing {
    position: relative;
    width: 100%;
    height: 60vh;
    min-height: 480px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.4rem;
    background: var(--paper-cream);
    overflow: hidden;
    padding: 6vh 8vw;
}
.closing-leaf {
    filter: drop-shadow(0 3px 8px rgba(168, 56, 40, 0.18));
}
.closing-line {
    font-family: var(--hand-korean);
    font-size: clamp(1.15rem, 1.6vw, 1.5rem);
    color: var(--sepia-deep);
    text-align: center;
    line-height: 1.6;
    transform: rotate(-0.8deg);
    letter-spacing: 0.02em;
}
.closing-line.en {
    font-family: var(--hand-primary);
    font-size: clamp(1.15rem, 1.7vw, 1.6rem);
    color: var(--sepia-mid);
    transform: rotate(0.6deg);
}
.closing-frame {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
.closing-border {
    stroke-dasharray: 2530;
    stroke-dashoffset: 2530;
    transition: stroke-dashoffset 2.4s ease-in-out;
}
.closing-border.in-view {
    stroke-dashoffset: 0;
}

/* =============== RESPONSIVE =============== */
@media (max-width: 900px) {
    .page {
        padding: 6vh 8vw 6vh 18vw;
    }
    .margin-column {
        width: 16vw;
        padding-left: 4vw;
    }
    .marginalia {
        font-size: 0.95rem;
    }
}
@media (max-width: 640px) {
    .page {
        padding: 5vh 6vw 5vh 22vw;
        min-height: 110vh;
    }
    .margin-column {
        width: 18vw;
        padding-left: 3vw;
    }
    .page-paper { max-width: 90%; }
    .marginalia.leaf-press {
        transform: scale(0.7) translateY(20px) rotate(var(--rot, -1deg));
    }
    .page.in-view .marginalia.leaf-press {
        transform: scale(0.7) translateY(0) rotate(var(--rot, -1deg));
    }
    .coffee-ring { width: 160px; height: 160px; right: 8%; }
}
