/* ================================================
   hangul.name - Styles
   A scholarly editorial experience celebrating
   the architecture of the Hangul writing system
   ================================================ */

/* ---- CSS Custom Properties ---- */
:root {
    --bg-primary: #0A0A0A;
    --bg-secondary: #1A1A1A;
    --gold-primary: #C9A84C;
    --gold-secondary: #8B7332;
    --gold-tertiary: #3D3422;
    --text-primary: #E8E0D0;
    --text-secondary: #9E9688;
    --accent-vermillion: #B5453A;

    --font-display: 'Cormorant Garamond', serif;
    --font-body: 'Source Serif 4', serif;
    --font-korean: 'Noto Sans KR', sans-serif;
    --font-accent: 'Cormorant', serif;

    --margin-frame: 120px;
    --gutter: 32px;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-weight: 400;
    line-height: 1.75;
    overflow: hidden;
}

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

/* ---- Hanji Paper Texture Overlay ---- */
.folio::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0.04;
    filter: url(#hanji-texture);
    background: var(--text-primary);
}

/* ---- Hunminjeongeum Grid Pattern ---- */
.folio::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0.15;
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 59px,
            var(--gold-tertiary) 59px,
            var(--gold-tertiary) 60px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 59px,
            var(--gold-tertiary) 59px,
            var(--gold-tertiary) 60px
        );
}

/* ---- Navigation Dots ---- */
#folio-nav {
    position: fixed;
    right: 40px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.nav-dot {
    width: 12px;
    height: 12px;
    border: 1.5px solid var(--gold-primary);
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    position: relative;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.nav-dot.active {
    background-color: var(--gold-primary);
}

.nav-dot:hover {
    border-color: var(--gold-primary);
    background-color: var(--gold-secondary);
}

.nav-tooltip {
    position: absolute;
    right: 24px;
    top: 50%;
    transform: translateY(-50%);
    white-space: nowrap;
    font-family: var(--font-accent);
    font-style: italic;
    font-weight: 300;
    font-size: 0.85rem;
    color: var(--gold-primary);
    letter-spacing: 0.04em;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.nav-dot:hover .nav-tooltip {
    opacity: 1;
}

/* ---- Main Scroll Container ---- */
#scroll-container {
    width: 100vw;
    height: 100vh;
    overflow-y: scroll;
    scroll-snap-type: y mandatory;
    -webkit-overflow-scrolling: touch;
}

/* Hide scrollbar */
#scroll-container::-webkit-scrollbar {
    display: none;
}

#scroll-container {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* ---- Folio Base ---- */
.folio {
    width: 100vw;
    height: 100vh;
    scroll-snap-align: start;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.folio-content {
    position: relative;
    z-index: 1;
    width: calc(100% - var(--margin-frame) * 2);
    height: calc(100% - var(--margin-frame) * 2);
    max-width: calc(100% - var(--margin-frame) * 2);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* ---- Fade Reveal Animations ---- */
.fade-reveal {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.fade-reveal.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ---- Typography ---- */
.folio-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(2.5rem, 6vw, 5rem);
    letter-spacing: 0.06em;
    color: var(--gold-primary);
    margin-bottom: 2rem;
}

.folio-title-centered {
    text-align: center;
}

.folio-text {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1rem, 1.1vw, 1.15rem);
    line-height: 1.75;
    color: var(--text-primary);
}

.folio-text p {
    margin-bottom: 1.25em;
}

.folio-text p:last-child {
    margin-bottom: 0;
}

.annotation {
    display: block;
    margin-top: 2rem;
    font-family: var(--font-korean);
    font-weight: 300;
    font-size: clamp(0.75rem, 0.9vw, 0.875rem);
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    border-top: 1px solid var(--gold-tertiary);
    padding-top: 1rem;
}

/* ================================================
   FOLIO I: The Name (Hero)
   ================================================ */
.folio-hero {
    background-color: var(--bg-primary);
}

.folio-hero .folio-content {
    justify-content: center;
    align-items: center;
}

.hero-hangul-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4vw;
    margin-bottom: 3rem;
}

.hero-syllable {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hero-syllable .construction-svg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 110%;
    height: 110%;
    pointer-events: none;
}

.construction-lines {
    transition: opacity 2s ease-in-out;
}

.construction-lines.visible {
    opacity: 0.35 !important;
}

.hangul-char {
    font-family: var(--font-korean);
    font-weight: 400;
    font-size: clamp(15rem, 25vw, 30rem);
    color: var(--text-primary);
    line-height: 1;
    display: block;
    position: relative;
    z-index: 1;
}

.hero-tagline {
    font-family: var(--font-display);
    font-weight: 300;
    font-size: clamp(1.2rem, 2vw, 1.8rem);
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    text-align: center;
    opacity: 0;
    animation: fadeInUp 1s 1s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ---- Nakgwan Seal ---- */
.nakgwan-seal {
    position: absolute;
    bottom: calc(var(--margin-frame) * 0.5);
    right: calc(var(--margin-frame) * 0.5);
    width: 60px;
    height: 60px;
    z-index: 10;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.nakgwan-seal.visible {
    opacity: 1;
    transform: scale(1);
}

#seal-folio1 {
    animation: sealAppear 0.6s 3s ease forwards;
}

@keyframes sealAppear {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ================================================
   FOLIO II: The Logic (Specimen 60/40)
   ================================================ */
.folio-specimen {
    background-color: var(--bg-primary);
}

.folio-split {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    width: 100%;
    height: 100%;
    gap: 0;
}

.folio-left {
    flex: 0 0 60%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--gutter);
}

.folio-right {
    flex: 0 0 calc(40% - 1px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: var(--gutter);
    padding-left: calc(var(--gutter) * 1.5);
    position: relative;
}

.folio-divider {
    width: 1px;
    background: linear-gradient(
        to bottom,
        transparent 10%,
        var(--gold-primary) 10%,
        var(--gold-primary) 90%,
        transparent 90%
    );
    flex-shrink: 0;
}

/* Consonant display */
.consonant-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    width: 100%;
    max-height: 100%;
}

.consonant-item {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 200px;
}

.jamo-svg {
    width: 100%;
    height: auto;
    max-height: 14vh;
}

/* ================================================
   FOLIO III: The Cosmos (Manuscript Folio)
   ================================================ */
.folio-manuscript {
    background-color: var(--bg-primary);
}

.folio-manuscript .folio-content {
    justify-content: center;
    align-items: center;
}

.cosmos-container {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 4vw;
    width: 100%;
    max-width: 1200px;
    margin-bottom: 2rem;
}

.cosmos-element {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cosmos-svg {
    width: 100%;
    max-width: 300px;
    height: auto;
}

/* SVG path draw animation for lines */
.cosmos-line {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 1.5s ease-in-out;
}

.cosmos-element.visible .cosmos-line {
    stroke-dashoffset: 0;
}

/* For the circle (heaven dot), we animate opacity instead */
.cosmos-dot {
    opacity: 0;
    transition: opacity 1.5s ease-in-out;
}

.cosmos-element.visible .cosmos-dot {
    opacity: 1;
}

/* Derived vowels fade in after main element */
.derived-vowels {
    opacity: 0;
    transition: opacity 1.2s ease-in-out 0.8s;
}

.cosmos-element.visible .derived-vowels {
    opacity: 1;
}

.derivation-lines {
    opacity: 0;
    transition: opacity 1.5s ease-in-out 1.2s;
}

.cosmos-element.visible .derivation-lines {
    opacity: 0.15;
}

.cosmos-caption {
    font-family: var(--font-accent);
    font-style: italic;
    font-weight: 300;
    font-size: clamp(0.9rem, 1.1vw, 1.1rem);
    color: var(--text-secondary);
    text-align: center;
    max-width: 700px;
    line-height: 1.5;
}

/* Constellation background */
.constellation-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

.constellation-bg svg {
    width: 100%;
    height: 100%;
}

/* ================================================
   FOLIO IV: The Assembly (Reversed 40/60)
   ================================================ */
.folio-specimen-reversed {
    background-color: var(--bg-primary);
}

.folio-specimen-reversed .folio-split {
    flex-direction: row;
}

.folio-left-text {
    flex: 0 0 40%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: var(--gutter);
    padding-right: calc(var(--gutter) * 1.5);
    position: relative;
}

.folio-right-visual {
    flex: 0 0 calc(60% - 1px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--gutter);
    position: relative;
}

/* Assembly Grid */
.assembly-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3vw;
    position: relative;
    z-index: 2;
}

.assembly-grid-lines {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    height: 80%;
    z-index: 1;
    pointer-events: none;
    opacity: 0.4;
}

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

/* Syllable Block */
.syllable-block {
    width: clamp(120px, 15vw, 180px);
    height: clamp(120px, 15vw, 180px);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    border: 1px solid var(--gold-tertiary);
    background: var(--bg-secondary);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.syllable-block:hover {
    border-color: var(--gold-secondary);
    box-shadow: 0 0 20px rgba(201, 168, 76, 0.08);
}

.block-whole {
    font-family: var(--font-korean);
    font-weight: 400;
    font-size: clamp(4rem, 8vw, 7rem);
    color: var(--text-primary);
    line-height: 1;
    transition: opacity 0.4s ease-out;
}

.block-parts {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease-out;
}

.jamo-part {
    font-family: var(--font-korean);
    font-weight: 300;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    color: var(--gold-primary);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    line-height: 1;
    padding: 0.2em;
}

/* Hover: decompose syllable block */
.syllable-block:hover .block-whole,
.syllable-block.touch-active .block-whole {
    opacity: 0;
}

.syllable-block:hover .block-parts,
.syllable-block.touch-active .block-parts {
    opacity: 1;
    pointer-events: auto;
}

.syllable-block:hover .jamo-initial,
.syllable-block.touch-active .jamo-initial {
    transform: translate(-15px, -15px);
}

.syllable-block:hover .jamo-medial,
.syllable-block.touch-active .jamo-medial {
    transform: translate(15px, -5px);
}

.syllable-block:hover .jamo-final,
.syllable-block.touch-active .jamo-final {
    transform: translate(0, 15px);
}

/* ================================================
   FOLIO V: The Endurance (Closing)
   ================================================ */
.folio-closing {
    background-color: var(--bg-primary);
}

.folio-closing .folio-content {
    justify-content: center;
    align-items: center;
}

/* Timeline */
.timeline-container {
    width: 100%;
    max-width: 900px;
    margin: 2rem 0 4rem;
    overflow: hidden;
}

.timeline-track {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 40px 0;
    width: 100%;
}

.timeline-line {
    position: absolute;
    top: 50%;
    left: 0;
    width: 0%;
    height: 1px;
    background: var(--gold-primary);
    transform: translateY(-50%);
    transition: width 2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.timeline-track.animate .timeline-line {
    width: 100%;
}

.timeline-marker {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 2;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.timeline-track.animate .timeline-marker {
    opacity: 1;
    transform: translateY(0);
}

.timeline-track.animate .timeline-marker:nth-child(2) {
    transition-delay: 0.3s;
}

.timeline-track.animate .timeline-marker:nth-child(3) {
    transition-delay: 0.6s;
}

.timeline-track.animate .timeline-marker:nth-child(4) {
    transition-delay: 0.9s;
}

.timeline-track.animate .timeline-marker:nth-child(5) {
    transition-delay: 1.2s;
}

.timeline-track.animate .timeline-marker:nth-child(6) {
    transition-delay: 1.5s;
}

.timeline-track.animate .timeline-marker:nth-child(7) {
    transition-delay: 1.8s;
}

.timeline-track.animate .timeline-marker:nth-child(8) {
    transition-delay: 2.1s;
}

.timeline-marker::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--gold-primary);
    margin-bottom: 12px;
    box-shadow: 0 0 12px rgba(201, 168, 76, 0.3);
}

.timeline-year {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(0.85rem, 1vw, 1rem);
    color: var(--gold-primary);
    letter-spacing: 0.06em;
    margin-bottom: 4px;
}

.timeline-label {
    font-family: var(--font-korean);
    font-weight: 300;
    font-size: clamp(0.65rem, 0.75vw, 0.8rem);
    color: var(--text-secondary);
    letter-spacing: 0.04em;
    white-space: nowrap;
}

/* Closing statement */
.closing-statement {
    text-align: center;
}

.closing-text {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(2rem, 4vw, 3.5rem);
    letter-spacing: 0.06em;
    color: var(--gold-primary);
}

/* ================================================
   Gold Filament Decorations
   ================================================ */
.folio-right::before,
.folio-left-text::before {
    content: '';
    position: absolute;
    top: 15%;
    left: 0;
    width: 60px;
    height: 1px;
    background: var(--gold-primary);
    opacity: 0.3;
    transform: scaleX(0);
    transform-origin: left center;
    transition: transform 1.2s ease-in-out 0.5s;
}

.folio-right::after,
.folio-left-text::after {
    content: '';
    position: absolute;
    bottom: 15%;
    right: 0;
    width: 60px;
    height: 1px;
    background: var(--gold-primary);
    opacity: 0.3;
    transform: scaleX(0);
    transform-origin: right center;
    transition: transform 1.2s ease-in-out 0.8s;
}

.folio.in-view .folio-right::before,
.folio.in-view .folio-left-text::before,
.folio.in-view .folio-right::after,
.folio.in-view .folio-left-text::after {
    transform: scaleX(1);
}

/* ================================================
   Responsive Adjustments
   ================================================ */
@media (max-width: 1024px) {
    :root {
        --margin-frame: 60px;
    }

    #folio-nav {
        right: 20px;
    }

    .folio-split {
        flex-direction: column;
    }

    .folio-left,
    .folio-right,
    .folio-left-text,
    .folio-right-visual {
        flex: unset;
        width: 100%;
        padding: var(--gutter);
    }

    .folio-left {
        height: 50%;
    }

    .folio-right {
        height: 50%;
    }

    .folio-left-text {
        height: 45%;
    }

    .folio-right-visual {
        height: 55%;
    }

    .folio-divider {
        width: 80%;
        height: 1px;
        background: linear-gradient(
            to right,
            transparent 10%,
            var(--gold-primary) 10%,
            var(--gold-primary) 90%,
            transparent 90%
        );
        margin: 0 auto;
    }

    .consonant-display {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }

    .consonant-item {
        max-width: 120px;
    }

    .jamo-svg {
        max-height: 10vh;
    }

    .cosmos-container {
        flex-direction: column;
        align-items: center;
        gap: 2rem;
    }

    .cosmos-svg {
        max-width: 200px;
    }

    .hangul-char {
        font-size: clamp(8rem, 18vw, 15rem);
    }
}

@media (max-width: 640px) {
    :root {
        --margin-frame: 24px;
    }

    #folio-nav {
        right: 12px;
        gap: 12px;
    }

    .nav-dot {
        width: 8px;
        height: 8px;
    }

    .nav-tooltip {
        display: none;
    }

    .assembly-grid {
        gap: 2vw;
    }

    .syllable-block {
        width: clamp(80px, 20vw, 120px);
        height: clamp(80px, 20vw, 120px);
    }

    .block-whole {
        font-size: clamp(2.5rem, 10vw, 4rem);
    }

    .timeline-track {
        flex-wrap: wrap;
        gap: 20px;
        justify-content: center;
    }

    .timeline-line {
        display: none;
    }

    .timeline-marker {
        width: auto;
    }

    .cosmos-caption {
        font-size: clamp(0.8rem, 1vw, 0.95rem);
        max-width: 90%;
    }
}
