/* ========================================
   hangul.dev - Styles
   Zen minimalism + analog nostalgia
   ======================================== */

/* --- CSS Custom Properties --- */
:root {
    --bg-primary: #F5EDE0;        /* Aged Parchment */
    --bg-secondary: #EDE3D0;      /* Foxed Cream */
    --text-primary: #3B2F2F;      /* Dark Cocoa */
    --text-secondary: #5C4A3A;    /* Warm Umber */
    --accent-primary: #A0522D;    /* Burnt Sienna Ink */
    --accent-secondary: #C17252;  /* Faded Vermillion */
    --specimen-bg: #2C1E14;       /* Deep Walnut */
    --specimen-text: #F0E6D4;     /* Warm Ivory */
    --duotone-shadow: #8B7355;    /* Sepia Shadow */
    --duotone-light: #D4C4A8;     /* Sepia Light */
    --code-text: #6B5B4F;
}

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

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

body {
    font-family: 'Quicksand', sans-serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.2vw, 1.15rem);
    line-height: 1.75;
    letter-spacing: 0.005em;
    color: var(--text-secondary);
    background-color: var(--bg-primary);
    overflow-x: hidden;
}

/* --- Noise Overlay --- */
#noise-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

/* --- Grid Paper Background --- */
.grid-paper-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        linear-gradient(var(--duotone-light) 1px, transparent 1px),
        linear-gradient(90deg, var(--duotone-light) 1px, transparent 1px);
    background-size: 24px 24px;
    opacity: 0.15;
    pointer-events: none;
    z-index: 0;
}

.grid-paper-bg.grid-prominent {
    opacity: 0.25;
}

/* --- Typography --- */
h2, .frame-heading, .section-title {
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    font-size: clamp(1.8rem, 4vw, 3.6rem);
    letter-spacing: 0.01em;
    color: var(--text-primary);
}

p {
    margin-bottom: 1em;
}

p:last-child {
    margin-bottom: 0;
}

/* --- Jamo Navigation --- */
#jamo-nav {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 1000;
}

.jamo-indicator {
    font-family: 'Noto Serif KR', serif;
    font-size: 14px;
    font-weight: 500;
    color: var(--duotone-light);
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.25, 0.1, 0.25, 1);
    text-align: center;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.jamo-indicator.active {
    color: var(--accent-primary);
    transform: scale(1.5);
    font-weight: 900;
}

/* --- Stamp Seal --- */
#stamp-seal {
    position: fixed;
    top: 30px;
    right: 60px;
    width: 80px;
    height: 80px;
    z-index: 100;
    opacity: 0.6;
    transition: opacity 0.5s ease;
}

#stamp-seal svg {
    width: 100%;
    height: 100%;
}

/* ========================================
   SECTION: Opening (0-100vh)
   ======================================== */
.section-opening {
    position: relative;
    height: 150vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background-color: var(--bg-primary);
}

.hero-character-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 80vh;
}

.hero-character {
    font-family: 'Noto Serif KR', serif;
    font-weight: 900;
    font-size: clamp(30vw, 50vw, 80vw);
    color: var(--text-primary);
    line-height: 1;
    transition: opacity 0.8s ease;
    position: relative;
    z-index: 2;
    /* Halftone treatment */
    background:
        radial-gradient(circle, var(--duotone-shadow) 1px, transparent 1px),
        linear-gradient(var(--text-primary), var(--text-primary));
    background-size: 4px 4px, 100% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hero-character.fading {
    opacity: 0;
}

.jamo-decomposed {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    gap: clamp(40px, 8vw, 120px);
    opacity: 0;
    transition: opacity 0.6s ease;
    z-index: 3;
}

.jamo-decomposed.visible {
    opacity: 1;
}

.jamo-piece {
    font-family: 'Noto Serif KR', serif;
    font-weight: 900;
    font-size: clamp(4rem, 12vw, 14rem);
    color: var(--text-primary);
    transition: transform 0.6s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.hero-tagline {
    font-family: 'Nunito', sans-serif;
    font-weight: 400;
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-align: center;
    letter-spacing: 0.03em;
    position: relative;
    z-index: 2;
    margin-top: -4vh;
}

/* ========================================
   SECTION 1: The Invention
   ======================================== */
.section-invention {
    position: relative;
    min-height: 100vh;
    padding: 10vh 5vw;
    background-color: var(--bg-secondary);
}

.syllable-frame-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 64px;
    max-width: 1100px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

.syllable-frame {
    padding: 2rem 0;
}

.frame-heading {
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--duotone-light);
}

.frame-body p {
    color: var(--text-secondary);
    margin-bottom: 1.2em;
}

.frame-body p:last-child {
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    color: var(--text-primary);
    font-size: 1.1em;
}

/* Jamo Stroke Diagrams */
.jamo-stroke-diagram {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
}

.stroke-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.stroke-card.visible {
    opacity: 1;
    transform: translateY(0);
}

.stroke-svg {
    width: 100%;
    max-width: 100px;
}

.stroke-path {
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
    transition: stroke-dashoffset 1.2s ease;
}

.stroke-card.visible .stroke-path {
    stroke-dashoffset: 0;
}

.stroke-start {
    opacity: 0;
    transition: opacity 0.3s ease 0.2s;
}

.stroke-card.visible .stroke-start {
    opacity: 1;
}

.stroke-jamo {
    font-family: 'Noto Serif KR', serif;
    font-weight: 900;
    font-size: 2rem;
    color: var(--text-primary);
}

/* ========================================
   SECTION 2: The System (dark panel)
   ======================================== */
.section-system {
    position: relative;
    min-height: 100vh;
    background-color: var(--specimen-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10vh 5vw;
}

.specimen-panel-dark {
    max-width: 1000px;
    width: 100%;
    text-align: center;
}

.morph-sequence {
    display: flex;
    flex-direction: column;
    gap: 60px;
    margin-bottom: 60px;
}

.morph-group {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.7s ease, transform 0.7s ease;
}

.morph-group.visible {
    opacity: 1;
    transform: translateY(0);
}

.morph-chars {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(16px, 3vw, 40px);
    flex-wrap: wrap;
}

.morph-char {
    font-family: 'Noto Serif KR', serif;
    font-weight: 900;
    font-size: clamp(4rem, 10vw, 10rem);
    color: var(--specimen-text);
    line-height: 1;
    transition: color 0.4s ease;
}

.morph-arrow {
    font-size: clamp(1.5rem, 3vw, 3rem);
    color: var(--accent-secondary);
    font-weight: 300;
}

.morph-label {
    font-family: 'Quicksand', sans-serif;
    font-size: 1rem;
    color: var(--duotone-light);
    margin-top: 16px;
    font-weight: 500;
}

.system-explanation {
    max-width: 700px;
    margin: 0 auto;
    padding-top: 40px;
    border-top: 1px solid rgba(240, 230, 212, 0.15);
}

.system-explanation p {
    font-family: 'Quicksand', sans-serif;
    color: var(--specimen-text);
    font-size: clamp(0.95rem, 1.1vw, 1.1rem);
    line-height: 1.8;
    opacity: 0.85;
}

/* ========================================
   Breathing Room
   ======================================== */
.breathing-room {
    position: relative;
    height: 50vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-primary);
}

.breathing-jamo {
    font-family: 'Noto Serif KR', serif;
    font-weight: 300;
    font-size: clamp(6rem, 15vw, 18rem);
    color: var(--duotone-light);
    opacity: 0.4;
    line-height: 1;
}

/* ========================================
   SECTION 3: The Block
   ======================================== */
.section-block {
    position: relative;
    min-height: 100vh;
    padding: 10vh 5vw;
    background-color: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.section-title {
    text-align: center;
    position: relative;
    z-index: 1;
}

.section-subtitle {
    font-family: 'Quicksand', sans-serif;
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 60px;
    position: relative;
    z-index: 1;
    font-size: clamp(0.95rem, 1.2vw, 1.15rem);
}

.block-demo-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 48px;
    max-width: 900px;
    width: 100%;
    position: relative;
    z-index: 1;
}

.block-demo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 32px 24px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--duotone-light);
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s cubic-bezier(0.25, 0.1, 0.25, 1), transform 0.6s cubic-bezier(0.25, 0.1, 0.25, 1);
}

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

.block-exploded {
    display: flex;
    gap: 8px;
}

.block-cell {
    width: 56px;
    height: 56px;
    border: 1.5px dashed var(--duotone-shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

.block-cell span {
    font-family: 'Noto Serif KR', serif;
    font-weight: 500;
    font-size: 1.6rem;
    color: var(--text-primary);
    line-height: 1;
}

.block-cell small {
    font-family: 'Quicksand', sans-serif;
    font-size: 0.55rem;
    color: var(--accent-primary);
    position: absolute;
    bottom: 2px;
    letter-spacing: 0.02em;
}

.block-arrow {
    font-size: 1.5rem;
    color: var(--accent-secondary);
    flex-shrink: 0;
}

.block-composed {
    font-family: 'Noto Serif KR', serif;
    font-weight: 900;
    font-size: clamp(3rem, 6vw, 5rem);
    color: var(--text-primary);
    line-height: 1;
}

.block-romanized {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    color: var(--code-text);
    margin-left: 4px;
}

/* ========================================
   SECTION 4: The Beauty
   ======================================== */
.section-beauty {
    position: relative;
    min-height: 100vh;
    padding: 10vh 5vw;
    background-color: var(--bg-secondary);
}

.specimen-gallery {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    position: relative;
    z-index: 1;
}

.specimen-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.specimen-item.visible {
    opacity: 1;
    transform: translateY(0);
}

.specimen-word {
    font-family: 'Noto Serif KR', serif;
    font-weight: 900;
    font-size: clamp(4rem, 15vw, 20rem);
    color: var(--text-primary);
    line-height: 1.1;
    text-align: center;
}

/* Halftone Treatment */
.halftone-treatment {
    background:
        radial-gradient(circle, var(--duotone-shadow) 1.2px, transparent 1.2px),
        linear-gradient(var(--text-primary), var(--text-primary));
    background-size: 3px 3px, 100% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.specimen-breathing {
    height: 20vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.specimen-meaning {
    font-family: 'Nunito', sans-serif;
    font-weight: 400;
    font-size: 0.9rem;
    color: var(--duotone-light);
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

/* ========================================
   SECTION 5: The Code
   ======================================== */
.section-code {
    position: relative;
    min-height: 100vh;
    padding: 10vh 5vw;
    background-color: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.code-content {
    max-width: 800px;
    width: 100%;
    text-align: center;
    position: relative;
    z-index: 1;
}

.code-content .section-title {
    margin-bottom: 0.5rem;
}

.code-content .section-subtitle {
    margin-bottom: 48px;
}

.code-specimen {
    margin-bottom: 48px;
}

.code-char-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.code-hangul {
    font-family: 'Noto Serif KR', serif;
    font-weight: 900;
    font-size: clamp(6rem, 15vw, 12rem);
    color: var(--text-primary);
    line-height: 1;
}

.code-unicode {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 1rem;
    color: var(--accent-primary);
    letter-spacing: 0.05em;
}

.code-formula-container {
    background-color: var(--bg-primary);
    border: 1px solid var(--duotone-light);
    padding: 40px 32px;
    margin-bottom: 32px;
}

.code-formula {
    margin-bottom: 32px;
}

.code-formula code {
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.85rem, 1.2vw, 1.1rem);
    color: var(--code-text);
    line-height: 1.6;
}

.formula-initial,
.formula-medial,
.formula-final {
    color: var(--accent-primary);
    font-weight: 700;
    transition: color 0.3s ease;
}

.code-breakdown {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-bottom: 32px;
    flex-wrap: wrap;
}

.breakdown-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.breakdown-jamo {
    font-family: 'Noto Serif KR', serif;
    font-weight: 900;
    font-size: 2rem;
    color: var(--text-primary);
    line-height: 1;
}

.breakdown-label {
    font-family: 'Quicksand', sans-serif;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.breakdown-label code {
    font-family: 'IBM Plex Mono', monospace;
    color: var(--accent-primary);
    font-weight: 700;
}

.code-calculation {
    padding-top: 24px;
    border-top: 1px solid var(--duotone-light);
}

.code-calculation code {
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.9rem, 1.3vw, 1.15rem);
    color: var(--code-text);
}

.code-calculation strong {
    color: var(--accent-primary);
    font-size: 1.2em;
}

.code-note {
    font-family: 'Quicksand', sans-serif;
    color: var(--text-secondary);
    font-size: 0.95rem;
    max-width: 600px;
    margin: 0 auto;
    text-align: center;
}

/* ========================================
   SECTION: Closing
   ======================================== */
.section-closing {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-primary);
    overflow: hidden;
}

.syllable-field {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Noto Serif KR', serif;
    font-weight: 300;
    font-size: 8px;
    line-height: 1.4;
    color: var(--text-primary);
    opacity: 0.2;
    text-align: justify;
    word-break: break-all;
    padding: 20px;
    mask-image: radial-gradient(ellipse at center, black 30%, transparent 70%);
    -webkit-mask-image: radial-gradient(ellipse at center, black 30%, transparent 70%);
}

.closing-text {
    position: relative;
    z-index: 2;
    text-align: center;
}

.closing-count {
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: 2rem;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.closing-domain {
    font-family: 'Quicksand', sans-serif;
    font-weight: 400;
    font-size: 1rem;
    color: var(--text-secondary);
    letter-spacing: 0.1em;
}

/* ========================================
   Reduced Motion
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .hero-character.fading {
        opacity: 0;
    }

    .jamo-decomposed.visible {
        opacity: 1;
    }

    .stroke-path {
        stroke-dashoffset: 0 !important;
    }

    .morph-group.visible,
    .stroke-card.visible,
    .block-demo.visible,
    .specimen-item.visible {
        opacity: 1;
        transform: none;
    }
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 768px) {
    .syllable-frame-container {
        grid-template-columns: 1fr;
        gap: 32px;
    }

    .jamo-stroke-diagram {
        grid-template-columns: repeat(5, 1fr);
        gap: 8px;
    }

    .block-demo-container {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    .block-demo {
        flex-wrap: wrap;
        gap: 16px;
    }

    #jamo-nav {
        right: 8px;
        gap: 8px;
    }

    .jamo-indicator {
        font-size: 11px;
        width: 18px;
        height: 18px;
    }

    #stamp-seal {
        width: 50px;
        height: 50px;
        top: 16px;
        right: 40px;
    }

    .morph-chars {
        gap: 10px;
    }

    .code-breakdown {
        flex-direction: column;
        align-items: center;
        gap: 16px;
    }

    .block-cell {
        width: 44px;
        height: 44px;
    }
}

@media (max-width: 480px) {
    .jamo-stroke-diagram {
        grid-template-columns: repeat(3, 1fr);
    }

    .stroke-card:nth-child(4),
    .stroke-card:nth-child(5) {
        grid-column: span 1;
    }

    #stamp-seal {
        display: none;
    }
}
