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

:root {
    --paper: #f5efe3;
    --ink: #2a2520;
    --seal: #c44536;
    --tea: #c4a882;
    --pencil: #8a7b6b;
    --shadow: #d8ceb8;
    --sakura: #e8c4b8;
    --deep: #3d352c;
    --muted: #a09585;
}

html {
    scroll-behavior: smooth;
}

body.paper-ground {
    background-color: var(--paper);
    color: var(--ink);
    font-family: 'Libre Baskerville', serif;
    overflow-x: hidden;
}

/* === Paper Texture (set via JS canvas) === */
.paper-ground {
    background-repeat: repeat;
    background-size: 4px 4px;
}

/* === Diplomatic Tremor === */
@keyframes diplomatic-tremor {
    0% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    50% { transform: translateX(2px); }
    75% { transform: translateX(-1px); }
    100% { transform: translateX(0); }
}

body.rushing {
    animation: diplomatic-tremor 300ms ease-out;
}

/* === Section Base === */
.section {
    min-height: 100vh;
    display: flex;
    position: relative;
}

/* === Tea Stain Blotches (per section) === */
.section::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(ellipse at 30% 70%, rgba(196,168,130,0.15) 0%, transparent 60%),
        radial-gradient(ellipse at 75% 20%, rgba(196,168,130,0.1) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 90%, rgba(196,168,130,0.08) 0%, transparent 55%);
    z-index: 0;
}

/* === Fold Lines === */
.section-chapter::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 33%;
    height: 0;
    border-top: 1px solid rgba(196,168,130,0.12);
    pointer-events: none;
    z-index: 0;
}

/* === Foxing Spots === */
.section-chapter .panel-left::after,
.section-chapter .panel-right::before {
    content: '';
    position: absolute;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: rgba(180,155,120,0.2);
    pointer-events: none;
    z-index: 1;
}
.section-chapter .panel-left::after {
    top: 22%;
    left: 15%;
}
.section-chapter .panel-right::before {
    bottom: 18%;
    right: 12%;
}
.section-chapter:nth-child(odd) .panel-left::after {
    top: 65%;
    left: 60%;
}
.section-chapter:nth-child(odd) .panel-right::before {
    top: 40%;
    right: 25%;
}

/* === Panel Layout === */
.panel-left {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-right: 1px solid rgba(196,168,130,0.4);
    cursor: vertical-text;
    z-index: 1;
    flex-shrink: 0;
}

.panel-right {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    cursor: default;
    z-index: 1;
    overflow: hidden;
}

/* === Dynamic split widths (set via JS based on data-split) === */
.section[data-split="38"] .panel-left { flex-basis: 38%; max-width: 38%; }
.section[data-split="40"] .panel-left { flex-basis: 40%; max-width: 40%; }
.section[data-split="36"] .panel-left { flex-basis: 36%; max-width: 36%; }
.section[data-split="42"] .panel-left { flex-basis: 42%; max-width: 42%; }

/* === Komon Dot Pattern === */
.komon-bg {
    background-image: radial-gradient(circle, rgba(196,168,130,0.05) 0.5px, transparent 0.5px);
    background-size: 12px 12px;
}

/* === Opening Section === */
.opening-kanji {
    font-family: 'Shippori Mincho', serif;
    font-weight: 600;
    font-size: clamp(8rem, 20vw, 16rem);
    line-height: 1.1;
    color: var(--ink);
    opacity: 0;
    transform: translateX(-20px);
    transition: opacity 1.2s cubic-bezier(0.25, 0.1, 0.25, 1), transform 1.2s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.center-line {
    text-align: center;
    font-style: italic;
}

/* === Hanko Mini (opening) === */
.hanko-mini {
    position: absolute;
    bottom: 12%;
    font-family: 'Shippori Mincho', serif;
    font-size: 10px;
    color: var(--seal);
    width: 20px;
    height: 20px;
    border: 1.5px solid var(--seal);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: rotate(-3deg);
    line-height: 1;
}

/* === Reference Codes === */
.ref-code {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 300;
    font-size: 11px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--muted);
}

/* === Vertical Kanji === */
.kanji-vertical {
    font-family: 'Shippori Mincho', serif;
    font-weight: 600;
    font-size: clamp(4rem, 12vw, 12rem);
    line-height: 1.1;
    writing-mode: vertical-rl;
    letter-spacing: 0.3em;
    color: var(--ink);
    opacity: 0;
    transform: translateX(-20px);
    transition: opacity 1.2s cubic-bezier(0.25, 0.1, 0.25, 1), transform 1.2s cubic-bezier(0.25, 0.1, 0.25, 1);
}

/* === Right Panel Content === */
.right-content {
    max-width: 38ch;
    padding: 2rem;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 1.2s cubic-bezier(0.25, 0.1, 0.25, 1) 0.4s, transform 1.2s cubic-bezier(0.25, 0.1, 0.25, 1) 0.4s;
}

.body-prose {
    font-family: 'Libre Baskerville', serif;
    font-size: clamp(1rem, 1.2vw, 1.25rem);
    font-weight: 400;
    line-height: 1.85;
    letter-spacing: 0.01em;
    color: var(--ink);
}

.annotation {
    display: block;
    margin-top: 1.5rem;
    font-family: 'Caveat', cursive;
    font-size: clamp(0.85rem, 1vw, 1.1rem);
    font-weight: 400;
    color: var(--pencil);
}

/* === Hanko Watermark === */
.hanko-watermark {
    position: absolute;
    bottom: 5%;
    right: 5%;
    font-family: 'Shippori Mincho', serif;
    font-size: 8rem;
    color: var(--seal);
    opacity: 0.04;
    pointer-events: none;
    transform: rotate(-3deg);
    line-height: 1;
}

/* === Divider Line Animation === */
.panel-left {
    border-right-color: rgba(196,168,130,0);
    transition: border-right-color 0.8s ease;
}

.section.revealed .panel-left {
    border-right-color: rgba(196,168,130,0.4);
}

/* === Section Reveal === */
.section.revealed .kanji-vertical,
.section.revealed .opening-kanji {
    opacity: 1;
    transform: translateX(0);
}

.section.revealed .right-content {
    opacity: 1;
    transform: translateY(0);
}

/* === Seal Section === */
.section-seal {
    justify-content: center;
    align-items: center;
    background-color: var(--paper);
}

.seal-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 100vh;
}

.asanoha-bg {
    position: absolute;
    inset: 0;
    opacity: 0.08;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Cpath d='M20 0L40 20L20 40L0 20Z' fill='none' stroke='%23d8ceb8' stroke-width='0.5'/%3E%3Cpath d='M20 0L20 40M0 20L40 20' fill='none' stroke='%23d8ceb8' stroke-width='0.3'/%3E%3C/svg%3E");
    background-size: 40px 40px;
    pointer-events: none;
}

.hanko-seal {
    width: 80px;
    height: 80px;
    border: 3px solid var(--seal);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: rotate(-3deg);
    opacity: 0;
    transition: opacity 1.2s ease 0.3s;
    z-index: 2;
}

.section-seal.revealed .hanko-seal {
    opacity: 1;
}

.hanko-text {
    font-family: 'Shippori Mincho', serif;
    font-size: 28px;
    font-weight: 600;
    color: var(--seal);
    line-height: 1;
}

.domain-name {
    margin-top: 2rem;
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 300;
    font-size: 12px;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    color: var(--pencil);
    opacity: 0;
    transition: opacity 1.2s ease 0.6s;
    z-index: 2;
}

.section-seal.revealed .domain-name {
    opacity: 1;
}

/* === Seal section: dissolve the split line === */
.section-seal .panel-left {
    border-right: none;
}

/* === Seigaiha Wave Divider between sections === */
.section-chapter + .section-chapter::before {
    content: '';
    position: absolute;
    top: -20px;
    left: 0;
    right: 0;
    height: 40px;
    background-image:
        radial-gradient(circle at 10px 20px, transparent 9px, rgba(196,168,130,0.2) 9px, rgba(196,168,130,0.2) 10px, transparent 10px),
        radial-gradient(circle at 30px 20px, transparent 9px, rgba(196,168,130,0.2) 9px, rgba(196,168,130,0.2) 10px, transparent 10px);
    background-size: 40px 40px;
    pointer-events: none;
    z-index: 2;
}

/* === Responsive: <768px === */
@media (max-width: 768px) {
    .section {
        flex-direction: column;
    }

    .panel-left {
        flex-basis: 15vh !important;
        max-width: 100% !important;
        min-height: 15vh;
        border-right: none;
        border-bottom: 1px solid rgba(196,168,130,0.4);
    }

    .panel-right {
        flex: 1;
    }

    .kanji-vertical {
        writing-mode: horizontal-tb;
        letter-spacing: 0.1em;
        font-size: clamp(2.5rem, 8vw, 5rem);
    }

    .opening-kanji {
        font-size: clamp(5rem, 15vw, 10rem);
    }

    .hanko-watermark {
        font-size: 5rem;
    }

    .right-content {
        padding: 1.5rem;
        max-width: 100%;
    }
}

/* === Dark Mode === */
@media (prefers-color-scheme: dark) {
    :root {
        --paper: #3d352c;
        --ink: #e8dcc8;
        --seal: #c44536;
        --tea: #8a7b6b;
        --pencil: #a09585;
        --shadow: #2a2520;
        --muted: #8a7b6b;
    }

    body.paper-ground {
        background-color: var(--paper);
        color: var(--ink);
    }

    .hanko-seal {
        opacity: 0.8;
    }

    .section-seal.revealed .hanko-seal {
        opacity: 0.8;
    }

    .section::before {
        background:
            radial-gradient(ellipse at 30% 70%, rgba(100,85,65,0.15) 0%, transparent 60%),
            radial-gradient(ellipse at 75% 20%, rgba(100,85,65,0.1) 0%, transparent 50%),
            radial-gradient(ellipse at 50% 90%, rgba(100,85,65,0.08) 0%, transparent 55%);
    }
}
