/* =====================================================================
   lovebot.quest -- surreal dreamscape, hand-drawn storybook
   Palette
     Cream     #faf6ef   (storybook background)
     Pencil    #2a2420   (text, line art)
     Ink       #5a5048   (warm gray body / pencil-weight)
     Heart     #e87080   (love accents)
     Highlight #f0d8a8   (golden chapter numbers)
     Wash Pink rgba(255,182,193,0.15)  base #ffb6c1
     Wash Blue rgba(173,216,230,0.12)  base #add8e6
   Type
     Display  : Caveat 700
     Body     : Libre Baskerville 400
     Dialogue : Caveat 400 italic
   ===================================================================== */

* { box-sizing: border-box; }

:root {
    --cream: #faf6ef;
    --pencil: #2a2420;
    --ink: #5a5048;
    --heart: #e87080;
    --highlight: #f0d8a8;
    --wash-pink-solid: #ffb6c1;
    --wash-blue-solid: #add8e6;
    --wash-pink: rgba(255, 182, 193, 0.15);
    --wash-blue: rgba(173, 216, 230, 0.12);

    --font-display: "Caveat", "Comic Sans MS", cursive;
    --font-body: "Libre Baskerville", Georgia, "Times New Roman", serif;
    --font-dialogue: "Caveat", cursive;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--cream);
    color: var(--pencil);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.9;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    overflow: hidden;          /* the .storybook is the scroller */
    height: 100vh;
}

/* hidden defs container */
.svg-defs {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
    pointer-events: none;
}

/* ----------------- scroll container ---------------- */
.storybook {
    scroll-snap-type: y mandatory;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    background: var(--cream);
    /* subtle paper texture via repeating tiny radial dots */
    background-image:
        radial-gradient(circle at 18% 22%, rgba(90,80,72,0.025) 0 1px, transparent 2px),
        radial-gradient(circle at 78% 64%, rgba(90,80,72,0.02) 0 1px, transparent 2px),
        radial-gradient(circle at 42% 88%, rgba(90,80,72,0.025) 0 1px, transparent 2px);
    background-size: 220px 220px, 320px 320px, 280px 280px;
}

/* paper-edge vignette */
.storybook::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    box-shadow: inset 0 0 80px rgba(90, 80, 72, 0.08);
    z-index: 50;
}

/* ----------------- chapter base -------------------- */
.chapter {
    scroll-snap-align: start;
    min-height: 100vh;
    width: 100%;
    padding: clamp(2rem, 5vw, 4rem);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background: var(--cream);
    overflow: hidden;
}

/* ----------------- watercolor washes --------------- */
.wash {
    position: absolute;
    pointer-events: none;
    z-index: 0;
    filter: blur(2px);
}
.wash-pink {
    background: radial-gradient(circle, var(--wash-pink) 0%, rgba(255,182,193,0.05) 40%, transparent 70%);
}
.wash-blue {
    background: radial-gradient(circle, var(--wash-blue) 0%, rgba(173,216,230,0.04) 40%, transparent 70%);
}
.wash-tl { top: -12%; left: -12%; width: 60%; height: 60%; }
.wash-tr { top: -10%; right: -14%; width: 55%; height: 55%; }
.wash-br { bottom: -14%; right: -12%; width: 60%; height: 60%; }
.wash-bl { bottom: -12%; left: -14%; width: 55%; height: 55%; }

/* ----------------- typography ---------------------- */
.chapter-label {
    font-family: var(--font-body);
    font-size: 0.78rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ink);
    margin: 0 0 0.6rem 0;
    font-weight: 400;
}
.chapter-num {
    font-family: var(--font-display);
    font-size: 1.4em;
    color: var(--highlight);
    -webkit-text-stroke: 0.6px var(--pencil);
    margin-left: 0.1em;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: none;
}

.chapter-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(2rem, 5vw, 3.4rem);
    line-height: 1.1;
    color: var(--pencil);
    margin: 0 0 1.2rem 0;
    letter-spacing: 0.5px;
}

.narrative-body {
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.9;
    color: var(--ink);
    margin: 0 0 1.2rem 0;
    max-width: 38ch;
}
.narrative-body.centered {
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    max-width: 48ch;
}

.dialogue {
    font-family: var(--font-dialogue);
    font-style: italic;
    font-size: 1.25rem;
    line-height: 1.55;
    color: var(--pencil);
    margin: 1rem 0 1.2rem 0;
    padding: 0.3rem 0 0.3rem 1rem;
    border-left: 1.5px solid var(--heart);
    max-width: 38ch;
}
.dialogue .speaker {
    display: block;
    font-family: var(--font-body);
    font-style: normal;
    font-size: 0.7rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--heart);
    margin-bottom: 0.1rem;
}

/* ----------------- HERO chapter -------------------- */
.chapter-hero {
    flex-direction: column;
    text-align: center;
}

.hero-frame {
    position: relative;
    z-index: 2;
    width: min(640px, 92vw);
    aspect-ratio: 600 / 380;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
}
.frame-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
.frame-inner {
    position: relative;
    padding: 2.4rem clamp(1.5rem, 4vw, 3rem);
    text-align: center;
    z-index: 2;
    max-width: 100%;
}

.domain-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(2.6rem, 7vw, 4.6rem);
    color: var(--pencil);
    margin: 0.2rem 0 0.4rem 0;
    line-height: 1;
    letter-spacing: 0.5px;
}
.domain-title .dot {
    color: var(--heart);
    font-weight: 700;
}

.hero-tagline {
    font-family: var(--font-body);
    font-size: 0.95rem;
    color: var(--ink);
    margin: 0 auto 1.2rem auto;
    max-width: 30ch;
    line-height: 1.7;
}

.hero-heart {
    width: 46px;
    height: 46px;
    margin: 0.2rem auto 0.6rem auto;
    display: block;
    animation: heart-breathe 4.6s ease-in-out infinite;
}
.hero-heart svg { width: 100%; height: 100%; display: block; }

.hero-subline {
    font-family: var(--font-dialogue);
    font-size: 1.15rem;
    color: var(--ink);
    margin: 0;
    font-style: italic;
}

.scroll-hint {
    position: absolute;
    bottom: 2.2rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    z-index: 3;
    color: var(--ink);
    animation: hint-bob 2.6s ease-in-out infinite;
}
.hint-text {
    font-family: var(--font-dialogue);
    font-size: 1.05rem;
    color: var(--ink);
}

/* ----------------- content chapter grid ------------ */
.chapter-content { }

.chapter-grid {
    position: relative;
    z-index: 2;
    width: min(1100px, 100%);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: clamp(2rem, 5vw, 4rem);
    align-items: center;
}
.grid-reverse { grid-template-columns: 1fr 1fr; }
.grid-reverse .narrative { order: 2; }
.grid-reverse .illustration-wrap { order: 1; }

.narrative {
    position: relative;
    z-index: 2;
}
.narrative .narrative-body,
.narrative .dialogue {
    max-width: 42ch;
}

.illustration-wrap {
    position: relative;
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
    aspect-ratio: 320 / 360;
}
.illo-frame {
    width: 100%;
    height: 100%;
    display: block;
}

/* page divider (small wobble line) */
.page-divider {
    position: absolute;
    bottom: 1.4rem;
    left: 50%;
    transform: translateX(-50%);
    width: 240px;
    height: 20px;
    opacity: 0.55;
    pointer-events: none;
    z-index: 1;
}
.page-divider svg { width: 100%; height: 100%; }

/* ----------------- choice (fork) chapter ----------- */
.chapter-choice { }
.choice-wrap {
    position: relative;
    z-index: 2;
    width: min(900px, 100%);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.choice-wrap .chapter-title { text-align: center; }

.fork {
    position: relative;
    width: 100%;
    max-width: 760px;
    margin: 1.2rem auto 0 auto;
    aspect-ratio: 720 / 220;
}
.fork-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.fork-branch {
    transition: stroke 600ms ease, stroke-width 600ms ease, opacity 600ms ease;
}
.fork.selected-left  .fork-branch-left  { stroke: var(--heart); stroke-width: 2.2; }
.fork.selected-left  .fork-branch-right { opacity: 0.25; }
.fork.selected-right .fork-branch-right { stroke: var(--heart); stroke-width: 2.2; }
.fork.selected-right .fork-branch-left  { opacity: 0.25; }

.choice {
    position: absolute;
    background: transparent;
    border: 0;
    padding: 0.6rem 0.9rem;
    text-align: center;
    cursor: pointer;
    font-family: var(--font-body);
    color: var(--pencil);
    transition: transform 320ms ease, color 320ms ease;
    z-index: 3;
    max-width: 220px;
}
.choice .choice-label {
    display: block;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.6rem;
    color: var(--pencil);
    line-height: 1.1;
    margin-bottom: 0.2rem;
    transition: color 320ms ease;
}
.choice .choice-detail {
    display: block;
    font-family: var(--font-body);
    font-size: 0.78rem;
    color: var(--ink);
    line-height: 1.5;
    font-style: italic;
}
.choice-left  { top: 8%; left: 4%; }
.choice-right { top: 8%; right: 4%; }

.choice:hover .choice-label,
.choice:active .choice-label {
    color: var(--heart);
    transform: translateY(-1px);
}
.choice.is-chosen .choice-label { color: var(--heart); }
.choice.is-faded { opacity: 0.4; }

.choice-aftermath {
    margin-top: 1.4rem;
    font-family: var(--font-dialogue);
    font-size: 1.25rem;
    color: var(--pencil);
    font-style: italic;
    min-height: 1.5em;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 700ms ease, transform 700ms ease;
    max-width: 46ch;
}
.choice-aftermath.is-visible {
    opacity: 1;
    transform: translateY(0);
}

/* ----------------- epilogue ------------------------ */
.chapter-epilogue {
    flex-direction: column;
    text-align: center;
}
.epilogue-inner {
    position: relative;
    z-index: 2;
    max-width: 640px;
    text-align: center;
    padding: 2rem;
}

.big-heart {
    width: clamp(140px, 26vw, 220px);
    height: clamp(140px, 26vw, 220px);
    margin: 1rem auto 1.4rem auto;
}
.big-heart svg { width: 100%; height: 100%; }

#big-heart-path {
    stroke-dasharray: 320;
    stroke-dashoffset: 320;
    transition: stroke-dashoffset 2400ms ease-in-out;
}
.chapter-epilogue.is-visible #big-heart-path {
    stroke-dashoffset: 0;
}

.epilogue-line {
    font-family: var(--font-dialogue);
    font-size: clamp(1.1rem, 2.2vw, 1.5rem);
    color: var(--pencil);
    margin: 0 auto 1rem auto;
    max-width: 36ch;
}
.epilogue-signature {
    font-family: var(--font-body);
    font-size: 0.85rem;
    color: var(--ink);
    letter-spacing: 0.1em;
    margin: 0 0 1.8rem 0;
}
.signature-domain {
    font-family: var(--font-display);
    color: var(--heart);
    font-size: 1.4em;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.restart {
    background: transparent;
    border: 1.4px solid var(--pencil);
    border-radius: 999px;
    color: var(--pencil);
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.35rem;
    padding: 0.45rem 1.6rem;
    cursor: pointer;
    transition: background 240ms ease, color 240ms ease, transform 240ms ease;
    letter-spacing: 0.5px;
}
.restart:hover {
    background: var(--heart);
    color: var(--cream);
    border-color: var(--heart);
    transform: translateY(-2px);
}

/* ----------------- chapter dots nav ---------------- */
.chapter-dots {
    position: fixed;
    right: clamp(0.8rem, 2vw, 1.6rem);
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    z-index: 100;
}
.chapter-dots .dot {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1.2px solid var(--ink);
    background: rgba(250, 246, 239, 0.7);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ink);
    font-family: var(--font-display);
    font-size: 0.85rem;
    line-height: 1;
    padding: 0;
    transition: background 260ms ease, color 260ms ease,
                border-color 260ms ease, transform 260ms ease;
}
.chapter-dots .dot span {
    display: block;
    transform: translateY(1px);
}
.chapter-dots .dot:hover {
    transform: scale(1.12);
    border-color: var(--heart);
    color: var(--heart);
}
.chapter-dots .dot.is-active {
    background: var(--heart);
    color: var(--cream);
    border-color: var(--heart);
}

/* ----------------- entry animations ---------------- */
.chapter .narrative,
.chapter .illustration-wrap,
.chapter .choice-wrap,
.chapter .hero-frame,
.chapter .epilogue-inner {
    opacity: 0;
    transform: translateY(18px);
    transition: opacity 900ms ease, transform 900ms ease;
}
.chapter.is-visible .narrative,
.chapter.is-visible .illustration-wrap,
.chapter.is-visible .choice-wrap,
.chapter.is-visible .hero-frame,
.chapter.is-visible .epilogue-inner {
    opacity: 1;
    transform: translateY(0);
}
.chapter.is-visible .illustration-wrap { transition-delay: 180ms; }

/* ----------------- keyframes ----------------------- */
@keyframes heart-breathe {
    0%, 100% { transform: scale(1); opacity: 0.95; }
    50%      { transform: scale(1.07); opacity: 1; }
}
@keyframes hint-bob {
    0%, 100% { transform: translate(-50%, 0); opacity: 0.85; }
    50%      { transform: translate(-50%, 6px); opacity: 1; }
}

/* ----------------- responsive ---------------------- */
@media (max-width: 820px) {
    .chapter { padding: 2rem 1.4rem 3.4rem 1.4rem; }
    .chapter-grid,
    .grid-reverse {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
    .grid-reverse .narrative { order: 2; }
    .grid-reverse .illustration-wrap { order: 1; }

    .narrative .narrative-body,
    .narrative .dialogue { max-width: 100%; }

    .illustration-wrap { max-width: 320px; }

    .fork { aspect-ratio: 720 / 280; max-width: 100%; }
    .choice { max-width: 46%; }
    .choice-left  { left: 2%; }
    .choice-right { right: 2%; }
    .choice .choice-label { font-size: 1.3rem; }
    .choice .choice-detail { font-size: 0.72rem; }

    .chapter-dots {
        right: 0.6rem;
        gap: 0.4rem;
    }
    .chapter-dots .dot {
        width: 22px; height: 22px; font-size: 0.7rem;
    }
}

@media (max-width: 480px) {
    .domain-title { font-size: clamp(2rem, 9vw, 3rem); }
    .hero-frame { aspect-ratio: 600 / 460; }
    .scroll-hint { bottom: 1rem; }
}
