/* ===========================================
   hangeul.day — Styles
   The Ink and Paper System
   =========================================== */

/* --- CSS Custom Properties --- */
:root {
    /* Colors — The Ink and Paper System */
    --hanji-paper: #F2EDE4;
    --pine-soot-ink: #2D2923;
    --midnight-ink: #1E1B16;
    --bamboo-green: #6B7F5E;
    --persimmon-wash: #B87A4A;
    --guideline-gray: #D4C9B8;
    --scholars-brown: #8B6F52;
    --silk-thread: #E8DCC4;
    --hanji-grain: #EDE6DA;
    --muted-annotation: #9B8E7E;
    --warm-gray: #7A7062;

    /* Typography */
    --font-korean: 'Noto Serif KR', serif;
    --font-latin: 'Cormorant Garamond', serif;
    --font-mono: 'IBM Plex Mono', monospace;

    /* Timing */
    --stroke-draw-duration: 3s;
    --fade-duration: 1.2s;
    --assembly-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --brush-ease: cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

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

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    font-family: var(--font-korean);
    background-color: var(--hanji-paper);
    color: var(--pine-soot-ink);
    overflow-x: hidden;
    position: relative;
    /* Hanji paper texture - horizontal fiber grain */
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 1px,
            rgba(237, 230, 218, 0.3) 1px,
            rgba(237, 230, 218, 0.3) 1.5px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 3px,
            rgba(237, 230, 218, 0.15) 3px,
            rgba(237, 230, 218, 0.15) 3.5px
        );
}

/* Hanji noise texture overlay */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0.04;
    filter: url(#hanji-noise);
    background: var(--hanji-paper);
}

/* SVG filters container - hidden */
.svg-filters {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* --- Scroll Progress Line --- */
.scroll-progress {
    position: fixed;
    top: 0;
    right: 3vw;
    width: 10px;
    height: 100vh;
    z-index: 100;
    pointer-events: none;
}

.scroll-progress svg {
    width: 100%;
    height: 100%;
}

.scroll-progress .tick {
    opacity: 0;
    transition: opacity 0.6s ease;
}

.scroll-progress .tick.visible {
    opacity: 1;
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
    .brush-stroke,
    .brush-stroke-overlay,
    .jamo-path,
    .jamo-path-overlay,
    .closing-path {
        stroke-dasharray: none !important;
        stroke-dashoffset: 0 !important;
        transition: opacity 0.3s ease !important;
    }

    .syllable-block [data-role] {
        transition: none !important;
        transform: none !important;
    }

    .assembly-jamo {
        transition: opacity 0.3s ease !important;
        transform: none !important;
    }
}

/* ===========================================
   Section 1: The Void
   =========================================== */
.section-void {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;
}

.void-content {
    text-align: center;
    position: relative;
}

.opening-stroke {
    width: clamp(250px, 40vw, 600px);
    height: auto;
    display: block;
    margin: 0 auto;
}

.brush-stroke,
.brush-stroke-overlay {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
}

.brush-stroke.animate {
    animation: drawStroke var(--stroke-draw-duration) var(--brush-ease) forwards;
    animation-delay: 0.8s;
}

.brush-stroke-overlay.animate {
    animation: drawStroke var(--stroke-draw-duration) var(--brush-ease) forwards;
    animation-delay: 1.0s;
}

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

.romanization {
    font-family: var(--font-latin);
    font-size: 14px;
    font-weight: 300;
    letter-spacing: 0.08em;
    color: var(--muted-annotation);
    margin-top: 2rem;
    opacity: 0;
    transition: opacity var(--fade-duration) ease;
}

.romanization.visible {
    opacity: 1;
}

/* ===========================================
   Section 2: Jamo Assembly
   =========================================== */
.section-jamo {
    padding: 10vh 0;
    position: relative;
    z-index: 1;
}

.jamo-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    padding: 10vh 2rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.jamo-block.visible {
    opacity: 1;
    transform: translateY(0);
}

.jamo-display {
    display: flex;
    align-items: center;
    justify-content: center;
}

.jamo-svg {
    width: clamp(8rem, 20vw, 16rem);
    height: clamp(8rem, 20vw, 16rem);
}

.jamo-path {
    stroke-dasharray: 800;
    stroke-dashoffset: 800;
    transition: stroke-dashoffset 1.5s var(--brush-ease);
}

.jamo-path-overlay {
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
    transition: stroke-dashoffset 1.5s var(--brush-ease);
}

.jamo-block.drawn .jamo-path {
    stroke-dashoffset: 0;
}

.jamo-block.drawn .jamo-path-overlay {
    stroke-dashoffset: 0;
}

.jamo-annotation {
    margin-top: 2rem;
    text-align: center;
    opacity: 0;
    transition: opacity 0.6s ease;
    transition-delay: 0.6s;
}

.jamo-block.drawn .jamo-annotation {
    opacity: 1;
}

.annotation-text {
    font-family: var(--font-latin);
    font-size: clamp(0.85rem, 1.2vw, 1.1rem);
    font-weight: 400;
    letter-spacing: 0.08em;
    color: var(--warm-gray);
    margin-bottom: 0.4rem;
}

.annotation-desc {
    font-family: var(--font-latin);
    font-size: clamp(0.75rem, 1vw, 0.9rem);
    font-weight: 300;
    letter-spacing: 0.06em;
    color: var(--muted-annotation);
    margin-bottom: 0.8rem;
}

.articulation-diagram {
    width: 40px;
    height: 40px;
    display: block;
    margin: 0 auto;
}

/* ===========================================
   Section 3: Combination Engine
   =========================================== */
.section-combination {
    padding: 15vh 0;
    position: relative;
    z-index: 1;
}

.combination-intro {
    text-align: center;
    padding: 10vh 2rem;
}

.section-label {
    font-family: var(--font-latin);
    font-size: clamp(0.85rem, 1.2vw, 1.1rem);
    font-weight: 300;
    letter-spacing: 0.15em;
    color: var(--guideline-gray);
    text-transform: lowercase;
}

.syllable-assembly {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    padding: 10vh 2rem;
    opacity: 0;
    transition: opacity 0.8s ease;
}

.syllable-assembly.visible {
    opacity: 1;
}

.assembly-grid {
    position: relative;
    width: clamp(160px, 25vw, 280px);
    height: clamp(160px, 25vw, 280px);
}

.grid-guides {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.syllable-assembly.assembling .grid-guides {
    opacity: 0.3;
}

.syllable-assembly.assembled .grid-guides {
    opacity: 0;
    transition: opacity 0.8s ease 1s;
}

.assembly-jamo {
    position: absolute;
    transition: all 0.8s var(--assembly-spring);
}

.assembly-jamo[data-part="initial"] {
    top: 0;
    left: 0;
    width: 55%;
    height: 55%;
}

.assembly-jamo[data-part="medial"] {
    top: 0;
    right: 0;
    width: 40%;
    height: 60%;
}

.assembly-jamo[data-part="final"] {
    bottom: 0;
    left: 0;
    width: 100%;
    height: 40%;
}

.assembly-jamo svg {
    width: 100%;
    height: 100%;
}

.assembly-jamo .part-label {
    display: block;
    text-align: center;
    font-family: var(--font-korean);
    font-size: 0.7rem;
    font-weight: 200;
    color: var(--muted-annotation);
    margin-top: 0.2rem;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.syllable-assembly.visible .assembly-jamo .part-label {
    opacity: 1;
}

.syllable-assembly.assembled .assembly-jamo .part-label {
    opacity: 0;
}

/* Pre-assembly scattered positions */
.syllable-assembly:not(.assembling):not(.assembled) .assembly-jamo[data-part="initial"] {
    transform: translate(-30px, -20px);
}

.syllable-assembly:not(.assembling):not(.assembled) .assembly-jamo[data-part="medial"] {
    transform: translate(30px, -10px);
}

.syllable-assembly:not(.assembling):not(.assembled) .assembly-jamo[data-part="final"] {
    transform: translate(0, 30px);
}

/* Assembled positions */
.syllable-assembly.assembling .assembly-jamo,
.syllable-assembly.assembled .assembly-jamo {
    transform: translate(0, 0);
}

.syllable-result {
    font-family: var(--font-korean);
    font-size: clamp(2.4rem, 6vw, 5rem);
    font-weight: 200;
    letter-spacing: 0.12em;
    color: var(--pine-soot-ink);
    margin-top: 3rem;
    opacity: 0;
    transition: opacity 0.8s ease;
}

.syllable-assembly.assembled .syllable-result {
    opacity: 1;
}

.syllable-romanization {
    font-family: var(--font-latin);
    font-size: 14px;
    font-weight: 300;
    letter-spacing: 0.08em;
    color: var(--muted-annotation);
    margin-top: 0.5rem;
    opacity: 0;
    transition: opacity 0.8s ease 0.3s;
}

.syllable-assembly.assembled .syllable-romanization {
    opacity: 1;
}

/* ===========================================
   Section 4: Living Text
   =========================================== */
.section-living-text {
    padding: 15vh 0;
    position: relative;
    z-index: 1;
}

.living-sentence {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 15vh 2rem;
    opacity: 0;
    transition: opacity 0.8s ease;
}

.living-sentence.visible {
    opacity: 1;
}

.korean-text {
    font-family: var(--font-korean);
    font-size: clamp(2.4rem, 6vw, 5rem);
    font-weight: 200;
    letter-spacing: 0.12em;
    line-height: 1.9;
    color: var(--pine-soot-ink);
    text-align: center;
    max-width: 80vw;
}

.syllable-block {
    display: inline-block;
    position: relative;
    cursor: default;
}

/* Hidden jamo roles (shown during breathing) */
.syllable-block [data-role] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    text-align: center;
    opacity: 0;
    font-size: 0.5em;
    transition:
        opacity 0.4s ease calc(var(--char-index) * 0.04s),
        transform 0.3s ease calc(var(--char-index) * 0.04s),
        color 0.4s ease;
    pointer-events: none;
}

.syllable-block [data-role="initial"] {
    color: var(--pine-soot-ink);
}

.syllable-block [data-role="medial"] {
    color: var(--bamboo-green);
}

.syllable-block [data-role="final"] {
    color: var(--scholars-brown);
}

/* Breathing effect active */
.syllable-block.breathing [data-role] {
    opacity: 1;
}

.syllable-block.breathing [data-role="initial"] {
    transform: translate(-4px, -4px);
}

.syllable-block.breathing [data-role="medial"] {
    transform: translate(4px, 0);
}

.syllable-block.breathing [data-role="final"] {
    transform: translate(0, 4px);
}

.syllable-block.breathing .syllable-display {
    opacity: 0.15;
    transition: opacity 0.3s ease;
}

.syllable-display {
    position: relative;
    z-index: 1;
    transition: opacity 0.5s ease;
}

.sentence-translation {
    font-family: var(--font-latin);
    font-size: clamp(0.85rem, 1.2vw, 1.1rem);
    font-weight: 300;
    font-style: italic;
    letter-spacing: 0.08em;
    color: var(--warm-gray);
    margin-top: 3rem;
    opacity: 0;
    transition: opacity 0.8s ease 0.4s;
}

.living-sentence.visible .sentence-translation {
    opacity: 1;
}

.sentence-source {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-weight: 300;
    letter-spacing: 0.04em;
    color: var(--muted-annotation);
    margin-top: 0.8rem;
    opacity: 0;
    transition: opacity 0.8s ease 0.6s;
}

.living-sentence.visible .sentence-source {
    opacity: 1;
}

/* ===========================================
   Section 5: Scholar's Closing
   =========================================== */
.section-closing {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;
    padding: 10vh 2rem;
    transition: background-color 3s ease, color 3s ease;
}

.section-closing.dark {
    background-color: var(--midnight-ink);
}

.closing-content {
    text-align: center;
    max-width: 90vw;
}

.closing-character {
    width: clamp(250px, 60vw, 500px);
    height: auto;
    display: block;
    margin: 0 auto;
}

.closing-path {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke 3s ease;
}

.section-closing.dark .closing-path {
    stroke: var(--silk-thread);
}

/* Sequential drawing of closing jamo */
#closingH .closing-path {
    transition: stroke-dashoffset 2.5s var(--brush-ease), stroke 3s ease;
}

#closingA .closing-path {
    transition: stroke-dashoffset 1.8s var(--brush-ease), stroke 3s ease;
    transition-delay: 2.9s;
}

#closingN .closing-path {
    transition: stroke-dashoffset 1.5s var(--brush-ease), stroke 3s ease;
    transition-delay: 5.1s;
}

.section-closing.drawing #closingH .closing-path,
.section-closing.drawing #closingA .closing-path,
.section-closing.drawing #closingN .closing-path {
    stroke-dashoffset: 0;
}

/* Grid flash */
.section-closing.drawing #closingGrid {
    animation: gridFlash 2s ease 6.6s forwards;
}

@keyframes gridFlash {
    0% { opacity: 0; }
    30% { opacity: 0.3; }
    100% { opacity: 0; }
}

.closing-passage {
    font-family: var(--font-korean);
    font-size: clamp(1.1rem, 2.5vw, 1.8rem);
    font-weight: 200;
    letter-spacing: 0.12em;
    line-height: 2;
    color: var(--pine-soot-ink);
    margin-top: 5rem;
    opacity: 0;
    transition: opacity 1.5s ease, color 3s ease;
}

.section-closing.dark .closing-passage {
    color: var(--silk-thread);
}

.section-closing.text-reveal .closing-passage {
    opacity: 1;
}

.closing-translation {
    font-family: var(--font-latin);
    font-size: clamp(0.85rem, 1.2vw, 1.1rem);
    font-weight: 300;
    font-style: italic;
    letter-spacing: 0.08em;
    line-height: 1.8;
    color: var(--warm-gray);
    margin-top: 2rem;
    opacity: 0;
    transition: opacity 1.5s ease 0.5s, color 3s ease;
}

.section-closing.dark .closing-translation {
    color: var(--muted-annotation);
}

.section-closing.text-reveal .closing-translation {
    opacity: 1;
}

.closing-year {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 300;
    letter-spacing: 0.04em;
    color: var(--warm-gray);
    margin-top: 4rem;
    opacity: 0;
    transition: opacity 1.5s ease 1.5s, color 3s ease;
}

.section-closing.dark .closing-year {
    color: var(--muted-annotation);
}

.section-closing.text-reveal .closing-year {
    opacity: 1;
}

/* ===========================================
   Responsive
   =========================================== */
@media (max-width: 768px) {
    .jamo-block {
        min-height: 50vh;
        padding: 8vh 1.5rem;
    }

    .syllable-assembly {
        min-height: 50vh;
    }

    .living-sentence {
        min-height: 80vh;
        padding: 10vh 1.5rem;
    }

    .korean-text {
        max-width: 95vw;
    }

    .assembly-grid {
        width: 180px;
        height: 180px;
    }
}
