/* ==========================================================================
   hangul.name — nostalgic-botanical codex of the Korean alphabet
   palette: cool-grays + aurora accents (green/violet/cyan)
   fonts:   Gaegu (display), Nanum Myeongjo (body), Caveat (annotation)
   layout:  horizontal scroll-snap codex, F-pattern spreads
   ========================================================================== */

:root {
    /* cool-grays */
    --fog-white: #eaecf0;
    --temple-stone: #d4d6dc;
    --slate-ink: #2c2e33;
    --pencil-gray: #8b8d94;
    --silver-thread: #c8cad0;
    /* botanical + aurora */
    --pressed-leaf: #b5c4a8;
    --northern-moss: #7eb8a2;
    --twilight-haze: #9b8ec4;
    --frozen-stream: #6baed6;

    --page-w: 100vw;
    --page-h: 100vh;

    --ease-page: cubic-bezier(0.22, 1, 0.36, 1);
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--fog-white);
    color: var(--slate-ink);
    font-family: 'Nanum Myeongjo', 'Noto Serif KR', Georgia, serif;
    font-weight: 400;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    position: relative;
    letter-spacing: 0.01em;
}

/* ==========================================================================
   GLOBAL LAYERS: paper grain + aurora atmosphere
   ========================================================================== */

.paper-grain {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 50;
    opacity: 0.35;
    mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.55  0 0 0 0 0.55  0 0 0 0 0.58  0 0 0 0.08 0'/></filter><rect width='180' height='180' filter='url(%23n)'/></svg>");
    background-size: 180px 180px;
}

.aurora-layer {
    position: fixed;
    inset: -10vh -10vw;
    pointer-events: none;
    z-index: 1;
    filter: blur(90px);
    opacity: 0;
    transition: opacity 1.6s ease;
    will-change: transform, opacity;
}

.aurora-green {
    background:
        radial-gradient(40vw 40vh at 75% 25%, rgba(126, 184, 162, 0.35), transparent 70%),
        radial-gradient(30vw 30vh at 20% 80%, rgba(181, 196, 168, 0.25), transparent 70%);
    animation: drift-a 32s ease-in-out infinite alternate;
}

.aurora-violet {
    background:
        radial-gradient(45vw 45vh at 30% 30%, rgba(155, 142, 196, 0.35), transparent 70%),
        radial-gradient(30vw 30vh at 80% 75%, rgba(155, 142, 196, 0.2), transparent 70%);
    animation: drift-b 28s ease-in-out infinite alternate;
}

.aurora-cyan {
    background:
        radial-gradient(50vw 50vh at 50% 50%, rgba(107, 174, 214, 0.32), transparent 70%),
        radial-gradient(25vw 25vh at 85% 20%, rgba(126, 184, 162, 0.18), transparent 70%);
    animation: drift-c 34s ease-in-out infinite alternate;
}

.aurora-layer.is-active {
    opacity: 1;
}

@keyframes drift-a {
    0%   { transform: translate(0, 0) scale(1); }
    50%  { transform: translate(4vw, -3vh) scale(1.06); }
    100% { transform: translate(-3vw, 4vh) scale(1.04); }
}

@keyframes drift-b {
    0%   { transform: translate(0, 0) scale(1); }
    50%  { transform: translate(-4vw, 4vh) scale(1.07); }
    100% { transform: translate(5vw, -2vh) scale(1.03); }
}

@keyframes drift-c {
    0%   { transform: translate(0, 0) scale(1); }
    50%  { transform: translate(3vw, 3vh) scale(1.05); }
    100% { transform: translate(-4vw, -3vh) scale(1.08); }
}

/* ==========================================================================
   CHAPTER RAIL (left edge navigation)
   ========================================================================== */

.chapter-rail {
    position: fixed;
    top: 0;
    left: 0;
    width: 72px;
    height: 100vh;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.rail-line {
    position: absolute;
    top: 10vh;
    bottom: 10vh;
    left: 36px;
    width: 1px;
    background: linear-gradient(to bottom,
        transparent 0%,
        var(--silver-thread) 10%,
        var(--silver-thread) 90%,
        transparent 100%);
}

.rail-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: 80vh;
    justify-content: center;
    align-items: center;
    position: relative;
    pointer-events: auto;
}

.rail-item {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 50%;
    transition: transform 400ms var(--ease-page), background 400ms ease;
    position: relative;
}

.rail-glyph {
    font-family: 'Gaegu', 'Nanum Myeongjo', serif;
    font-size: 11px;
    font-weight: 400;
    color: var(--silver-thread);
    transition: color 500ms ease, text-shadow 500ms ease, font-size 500ms ease;
    line-height: 1;
}

.rail-item:hover .rail-glyph {
    color: var(--pencil-gray);
}

.rail-item.is-active .rail-glyph {
    color: var(--slate-ink);
    font-size: 15px;
    font-weight: 700;
    text-shadow:
        0 0 8px rgba(126, 184, 162, 0.6),
        0 0 16px rgba(126, 184, 162, 0.3);
    animation: pulse-glow 3s ease-in-out infinite;
}

.rail-item.is-active[data-aurora-active="violet"] .rail-glyph {
    text-shadow:
        0 0 8px rgba(155, 142, 196, 0.6),
        0 0 16px rgba(155, 142, 196, 0.3);
}

.rail-item.is-active[data-aurora-active="cyan"] .rail-glyph {
    text-shadow:
        0 0 8px rgba(107, 174, 214, 0.6),
        0 0 16px rgba(107, 174, 214, 0.3);
}

@keyframes pulse-glow {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.25); }
}

/* ==========================================================================
   FOLIO counter + SCROLL HINT
   ========================================================================== */

.folio {
    position: fixed;
    top: 32px;
    right: 40px;
    z-index: 40;
    font-family: 'Caveat', cursive;
    font-size: 18px;
    color: var(--pencil-gray);
    letter-spacing: 0.05em;
    display: flex;
    align-items: baseline;
    gap: 6px;
    pointer-events: none;
}

.folio-label {
    font-size: 13px;
    text-transform: lowercase;
    opacity: 0.75;
    margin-right: 4px;
}

.folio-current {
    color: var(--slate-ink);
    font-size: 24px;
    font-weight: 500;
    transition: opacity 300ms ease;
}

.folio-sep {
    color: var(--silver-thread);
    font-size: 20px;
}

.folio-total {
    color: var(--pencil-gray);
    font-size: 16px;
}

.scroll-hint {
    position: fixed;
    bottom: 40px;
    right: 50px;
    z-index: 40;
    font-family: 'Caveat', cursive;
    font-size: 16px;
    color: var(--pencil-gray);
    display: flex;
    align-items: center;
    gap: 14px;
    pointer-events: none;
    opacity: 1;
    transition: opacity 800ms ease;
}

.scroll-hint.is-hidden {
    opacity: 0;
}

.hint-line {
    display: inline-block;
    width: 60px;
    height: 1px;
    background: var(--silver-thread);
    animation: hint-slide 2.8s ease-in-out infinite;
}

.hint-text {
    letter-spacing: 0.04em;
}

@keyframes hint-slide {
    0%   { transform: translateX(0);    opacity: 0.4; }
    50%  { transform: translateX(10px); opacity: 1;   }
    100% { transform: translateX(20px); opacity: 0.4; }
}

/* ==========================================================================
   CODEX: horizontal scroll-snap container
   ========================================================================== */

.codex {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -ms-overflow-style: none;
    z-index: 5;
}

.codex::-webkit-scrollbar {
    display: none;
}

.page {
    flex: 0 0 100vw;
    width: 100vw;
    height: 100vh;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    position: relative;
    overflow: hidden;
    background: var(--fog-white);
    transition: background-color 1.2s ease;
}

.page:nth-child(even) {
    background: var(--temple-stone);
}

.page-inner {
    position: relative;
    width: 100%;
    height: 100%;
    padding: 10vh 8vw 10vh 120px;
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    column-gap: 24px;
}

/* CSS calligraphy grid behind specimen area */
.page-grid {
    position: absolute;
    top: 8vh;
    bottom: 8vh;
    left: 120px;
    width: 55%;
    background-image:
        repeating-linear-gradient(
            to right,
            rgba(200, 202, 208, 0.55) 0 1px,
            transparent 1px 40px),
        repeating-linear-gradient(
            to bottom,
            rgba(200, 202, 208, 0.55) 0 1px,
            transparent 1px 40px);
    opacity: 0.25;
    pointer-events: none;
    z-index: 1;
}

.page-grid-wide {
    width: calc(100% - 200px);
    left: 120px;
    right: 80px;
}

/* Page number in the bottom-right corner */
.page-number {
    position: absolute;
    bottom: 32px;
    right: 40px;
    font-family: 'Caveat', cursive;
    font-size: 14px;
    color: var(--pencil-gray);
    letter-spacing: 0.08em;
    font-style: italic;
    opacity: 0.8;
}

.caveat {
    font-family: 'Caveat', cursive;
    color: var(--pencil-gray);
    letter-spacing: 0.04em;
}

/* ==========================================================================
   PAGE 1 — TITLE SPREAD
   ========================================================================== */

.page-title .page-inner {
    grid-template-columns: repeat(12, 1fr);
    align-items: center;
}

.title-stack {
    grid-column: 1 / span 7;
    position: relative;
    z-index: 3;
    padding: 0 0 0 4vw;
}

.title-strokes {
    width: 100%;
    max-width: 520px;
    height: auto;
    margin-bottom: 1.5rem;
}

.stroke-path {
    stroke-dasharray: 800;
    stroke-dashoffset: 800;
    animation: draw-stroke 2.5s cubic-bezier(0.55, 0.05, 0.45, 1) forwards;
}

.stroke-path:nth-child(1) { animation-delay: 0.2s; }
.stroke-path:nth-child(2) { animation-delay: 0.55s; }
.stroke-path:nth-child(3) { animation-delay: 0.9s; }
.stroke-path:nth-child(4) { animation-delay: 1.25s; }
.stroke-path:nth-child(5) { animation-delay: 1.6s; }
.stroke-path:nth-child(6) { animation-delay: 1.9s; }
.stroke-path:nth-child(7) { animation-delay: 2.15s; }
.stroke-path:nth-child(8) { animation-delay: 2.35s; }

@keyframes draw-stroke {
    to { stroke-dashoffset: 0; }
}

.title-hangul-text {
    font-family: 'Gaegu', 'Nanum Myeongjo', serif;
    font-weight: 700;
    font-size: clamp(6rem, 14vw, 12rem);
    line-height: 0.95;
    color: var(--slate-ink);
    letter-spacing: 0.02em;
    margin-bottom: 0.5rem;
    opacity: 0;
    animation: fade-in 1.4s ease 2.6s forwards;
}

.title-romanized {
    font-family: 'Caveat', cursive;
    font-weight: 500;
    font-size: 1.15rem;
    color: var(--pencil-gray);
    letter-spacing: 0.22em;
    margin-left: 0.25rem;
    opacity: 0;
    animation: fade-in 1s ease 3.1s forwards;
}

.title-annotation {
    margin-top: 0.75rem;
    margin-left: 0.25rem;
    font-family: 'Caveat', cursive;
    font-size: 1rem;
    color: var(--pencil-gray);
    font-style: italic;
    opacity: 0;
    animation: fade-in 1s ease 3.5s forwards;
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.title-ornament {
    grid-column: 9 / span 4;
    justify-self: end;
    align-self: end;
    opacity: 0;
    animation: fade-in 2.2s ease 2.8s forwards;
}

.pressed-fern {
    width: clamp(180px, 22vw, 300px);
    height: auto;
    opacity: 0.55;
}

/* ==========================================================================
   CONSONANT + VOWEL PAGES (specimen spreads)
   ========================================================================== */

.page-consonant .page-inner,
.page-vowel .page-inner {
    align-items: center;
}

.specimen-stage {
    grid-column: 1 / span 7;
    position: relative;
    z-index: 2;
    height: 70vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.specimen-character {
    font-family: 'Gaegu', 'Nanum Myeongjo', serif;
    font-weight: 700;
    font-size: clamp(8rem, 20vw, 16rem);
    line-height: 1;
    color: var(--slate-ink);
    letter-spacing: 0.02em;
    z-index: 3;
    position: relative;
    user-select: none;
    transform: translateZ(0);
    text-shadow:
        0 2px 16px rgba(44, 46, 51, 0.06),
        1px 1px 0 rgba(44, 46, 51, 0.04);
}

/* very subtle watercolor smudge behind the character */
.specimen-character::after {
    content: '';
    position: absolute;
    inset: -15% -20%;
    background: radial-gradient(
        closest-side,
        rgba(181, 196, 168, 0.22),
        transparent 75%);
    z-index: -1;
    filter: blur(14px);
}

.page-vowel .specimen-character::after {
    background: radial-gradient(
        closest-side,
        rgba(155, 142, 196, 0.2),
        transparent 75%);
}

.specimen-botanical {
    position: absolute;
    left: 52%;
    top: 50%;
    width: 45%;
    max-width: 380px;
    height: auto;
    transform: translateY(-50%);
    opacity: 0.68;
    z-index: 2;
    pointer-events: none;
}

.page-vowel .specimen-botanical {
    left: auto;
    right: 8%;
    opacity: 0.55;
}

/* Prose panel (F-pattern secondary zone) */
.prose-panel {
    grid-column: 8 / span 5;
    position: relative;
    z-index: 3;
    padding: 0 0 0 1vw;
    max-width: 420px;
}

.specimen-label {
    display: inline-block;
    font-family: 'Caveat', cursive;
    font-size: 0.95rem;
    color: var(--pencil-gray);
    letter-spacing: 0.06em;
    margin-bottom: 1.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--silver-thread);
    text-transform: lowercase;
}

.prose-heading {
    font-family: 'Nanum Myeongjo', serif;
    font-weight: 800;
    font-size: clamp(1.75rem, 2.5vw, 2.5rem);
    color: var(--slate-ink);
    margin-bottom: 1.5rem;
    letter-spacing: -0.01em;
    line-height: 1.1;
}

.prose-subheading {
    font-family: 'Gaegu', 'Nanum Myeongjo', serif;
    font-weight: 400;
    font-size: 0.7em;
    color: var(--pencil-gray);
    margin-left: 0.5em;
    letter-spacing: 0;
}

.prose-body {
    font-family: 'Nanum Myeongjo', serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.15vw, 1.1rem);
    line-height: 1.85;
    color: var(--slate-ink);
    margin-bottom: 1.1rem;
}

.prose-body em {
    font-family: 'Gaegu', 'Nanum Myeongjo', serif;
    font-weight: 700;
    font-style: normal;
    color: var(--slate-ink);
    background: linear-gradient(
        to top,
        rgba(126, 184, 162, 0.18) 0%,
        rgba(126, 184, 162, 0.18) 35%,
        transparent 35%);
    padding: 0 0.15em;
}

.page-vowel .prose-body em {
    background: linear-gradient(
        to top,
        rgba(155, 142, 196, 0.22) 0%,
        rgba(155, 142, 196, 0.22) 35%,
        transparent 35%);
}

.prose-footnote {
    font-family: 'Caveat', cursive;
    font-size: 0.95rem;
    color: var(--pencil-gray);
    margin-top: 1.5rem;
    padding-top: 0.75rem;
    border-top: 1px dashed var(--silver-thread);
    letter-spacing: 0.04em;
    font-style: italic;
    opacity: 0.85;
}

/* ==========================================================================
   CLOSING PAGE — syllable chart
   ========================================================================== */

.page-closing {
    background: linear-gradient(135deg, var(--fog-white) 0%, var(--temple-stone) 100%);
}

.page-closing .page-inner {
    grid-template-columns: 1fr;
    align-items: center;
    justify-items: start;
    padding: 8vh 6vw 8vh 130px;
}

.closing-stack {
    grid-column: 1;
    width: 100%;
    max-width: 1100px;
    z-index: 3;
    position: relative;
}

.closing-preamble {
    font-family: 'Caveat', cursive;
    font-size: 1.2rem;
    color: var(--pencil-gray);
    margin-bottom: 0.8rem;
    letter-spacing: 0.04em;
    font-style: italic;
}

.closing-heading {
    font-family: 'Nanum Myeongjo', serif;
    font-weight: 700;
    font-size: clamp(2rem, 3vw, 3rem);
    color: var(--slate-ink);
    margin-bottom: 3rem;
    letter-spacing: -0.01em;
}

.syllable-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0;
    margin-bottom: 3rem;
    border-top: 1px solid var(--silver-thread);
    border-left: 1px solid var(--silver-thread);
    max-width: 900px;
}

.syllable {
    font-family: 'Gaegu', 'Nanum Myeongjo', serif;
    font-weight: 400;
    font-size: clamp(2rem, 3.5vw, 3.5rem);
    color: var(--slate-ink);
    padding: 1.2rem 1rem;
    text-align: center;
    border-right: 1px solid var(--silver-thread);
    border-bottom: 1px solid var(--silver-thread);
    background: rgba(234, 236, 240, 0.3);
    transition: background 600ms ease, color 600ms ease, transform 600ms var(--ease-page);
    position: relative;
}

.syllable::before {
    content: '';
    position: absolute;
    inset: 6px;
    background-image:
        repeating-linear-gradient(to right,
            rgba(200, 202, 208, 0.35) 0 1px,
            transparent 1px 14px),
        repeating-linear-gradient(to bottom,
            rgba(200, 202, 208, 0.35) 0 1px,
            transparent 1px 14px);
    pointer-events: none;
    opacity: 0.5;
}

.closing-annotation {
    font-family: 'Caveat', cursive;
    font-size: 1.35rem;
    color: var(--pencil-gray);
    letter-spacing: 0.05em;
    font-style: italic;
    margin-top: 1.5rem;
    margin-bottom: 1rem;
}

.closing-rule {
    width: 100%;
    max-width: 480px;
    height: 20px;
    display: block;
    margin-top: 0.5rem;
    opacity: 0.7;
}

/* ==========================================================================
   REVEAL ANIMATIONS — page content slides in when section becomes active
   ========================================================================== */

.page .specimen-character,
.page .specimen-botanical,
.page .prose-panel,
.page .title-stack,
.page .title-ornament,
.page .closing-stack {
    opacity: 0;
    transform: translateX(30px);
    transition:
        opacity 1000ms var(--ease-page),
        transform 1000ms var(--ease-page);
}

.page.is-active .specimen-character,
.page.is-active .title-stack,
.page.is-active .closing-stack {
    opacity: 1;
    transform: translateX(0);
    transition-delay: 200ms;
}

.page.is-active .specimen-botanical,
.page.is-active .title-ornament {
    opacity: 0.68;
    transform: translateX(0) translateY(-50%);
    transition-delay: 500ms;
}

.page.is-active .title-ornament {
    opacity: 1;
    transform: translateX(0);
}

.page.is-active .prose-panel {
    opacity: 1;
    transform: translateX(0);
    transition-delay: 700ms;
}

/* Title page strokes run via their own animation */
.page-title .title-stack { opacity: 1; transform: none; }

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

@media (max-width: 960px) {
    .chapter-rail { width: 48px; }
    .rail-line { left: 24px; }
    .page-inner {
        padding: 6vh 6vw 6vh 60px;
        grid-template-columns: 1fr;
        column-gap: 0;
    }
    .page-grid {
        left: 60px;
        right: 6vw;
        width: auto;
    }
    .specimen-stage {
        grid-column: 1;
        height: 45vh;
    }
    .prose-panel {
        grid-column: 1;
        max-width: 90%;
        margin-top: 2rem;
    }
    .specimen-botanical {
        width: 60%;
    }
    .page-vowel .specimen-botanical {
        right: 2%;
    }
    .folio {
        top: 18px;
        right: 18px;
    }
    .scroll-hint {
        bottom: 20px;
        right: 20px;
    }
    .syllable-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    .page-title .title-ornament {
        display: none;
    }
}

@media (max-width: 560px) {
    .page-inner {
        padding: 8vh 5vw 8vh 52px;
    }
    .chapter-rail .rail-glyph {
        font-size: 9px;
    }
    .rail-item.is-active .rail-glyph { font-size: 13px; }
}
