/* ==========================================================================
   hangeul.day — evolved-minimal horizontal-scroll codex
   Typography: Noto Serif KR (Hangul) + IBM Plex Mono (Latin)
   Palette: earth tones
   ========================================================================== */

:root {
    --bg-primary:     #f4ede4; /* Warm Parchment */
    --bg-secondary:   #ebe3d7; /* Aged Linen */
    --text-primary:   #3d2b1f; /* Deep Umber */
    --text-secondary: #6b5e52; /* Warm Taupe */
    --accent:         #a0876e; /* Muted Clay */
    --accent-warm:    #c4a882; /* Brushed Sienna */
    --accent-dark:    #2a1f17; /* Inkstone Black */
    --highlight:      #b8c9b1; /* Celadon Mist */

    --font-hangul: "Noto Serif KR", "Nanum Myeongjo", serif;
    --font-latin:  "IBM Plex Mono", "Menlo", monospace;

    --rule: 0.5px solid var(--accent-warm);
}

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

html, body { height: 100%; }

body {
    font-family: var(--font-latin);
    color: var(--text-primary);
    background: var(--bg-primary);
    overflow-x: scroll;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;

    /* Paper-grain fractal noise (data URI SVG) */
    background-image:
        radial-gradient(ellipse at 30% 20%, rgba(235,227,215,0.45), transparent 60%),
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.24  0 0 0 0 0.17  0 0 0 0 0.12  0 0 0 0.07 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
    background-attachment: fixed;
    background-size: auto, 240px 240px;
}

/* Hide scrollbar but keep functionality */
body::-webkit-scrollbar { height: 0; width: 0; }

/* ==========================================================================
   Codex canvas: flex row of 8 full-viewport panels
   ========================================================================== */

.codex {
    display: flex;
    flex-direction: row;
    width: 800vw;
    height: 100vh;
}

.panel {
    position: relative;
    width: 100vw;
    height: 100vh;
    flex-shrink: 0;
    scroll-snap-align: start;
    padding: 10vh 9vw;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.panel::before {
    /* ink-wash halo */
    content: "";
    position: absolute;
    inset: 10% 10%;
    background: radial-gradient(ellipse at center, rgba(235,227,215,0.55), transparent 65%);
    pointer-events: none;
    z-index: 0;
}

.panel > * { position: relative; z-index: 1; }

/* Chapter tag — small uppercase mono label at top-left of each panel */
.panel__chapter-tag {
    font-family: var(--font-latin);
    font-weight: 600;
    font-size: clamp(0.6rem, 0.8vw, 0.75rem);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--accent);
    padding-bottom: 0.7em;
    border-bottom: var(--rule);
    width: fit-content;
    max-width: 70%;
}

/* Marginalia — rotated scholarly annotation */
.panel__marginalia {
    position: absolute;
    top: 50%;
    writing-mode: vertical-rl;
    transform: translateY(-50%) rotate(180deg);
    font-family: var(--font-latin);
    font-size: 0.7rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--accent);
    opacity: 0.75;
}
.panel__marginalia--left { left: 3vw; }
.panel__marginalia--right { right: 3vw; transform: translateY(-50%); }

/* Panel header (h2 + intro) used in middle panels */
.panel__header {
    margin-top: 3vh;
    margin-bottom: 4vh;
}
.panel__header h2 {
    font-family: var(--font-hangul);
    font-weight: 700;
    font-size: clamp(1.8rem, 3vw, 3rem);
    color: var(--text-primary);
    letter-spacing: -0.01em;
}
.panel__header p {
    margin-top: 0.6em;
    font-family: var(--font-latin);
    font-weight: 400;
    font-size: clamp(0.85rem, 1.1vw, 1rem);
    color: var(--text-secondary);
    max-width: 60ch;
    line-height: 1.7;
}

/* Panel footer (panel 1) */
.panel__footer {
    position: absolute;
    bottom: 5vh;
    left: 9vw;
    right: 9vw;
    display: flex;
    justify-content: space-between;
    font-family: var(--font-latin);
    font-size: clamp(0.65rem, 0.8vw, 0.8rem);
    color: var(--accent);
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.mono {
    font-family: var(--font-latin);
    font-weight: 500;
    color: var(--text-primary);
}

/* ==========================================================================
   Fixed UI: progress bar + section-index dots
   ========================================================================== */

.progress-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    height: 3px;
    width: 0%;
    background: var(--accent-warm);
    z-index: 100;
    transition: width 0.08s linear;
}

.section-index {
    position: fixed;
    right: 2vw;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 14px;
    z-index: 100;
    padding: 18px 10px;
    border-left: var(--rule);
}
.section-index .dot {
    display: block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid var(--accent);
    transition: background 0.3s ease, transform 0.3s ease;
    cursor: pointer;
}
.section-index .dot.active {
    background: var(--accent-warm);
    border-color: var(--accent-warm);
    transform: scale(1.3);
}

/* ==========================================================================
   Panel 1 — The Title Scroll
   ========================================================================== */

.panel--title {
    align-items: center;
    justify-content: center;
    text-align: center;
}

.title-wrap {
    margin: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.2em;
}

.title-hangul {
    font-family: var(--font-hangul);
    font-weight: 700;
    font-size: clamp(15rem, 25vw, 30rem);
    color: var(--text-primary);
    line-height: 0.9;
    letter-spacing: -0.04em;
    text-shadow: 2px 2px 0 rgba(42, 31, 23, 0.04);
}

.title-latin {
    font-family: var(--font-latin);
    font-weight: 500;
    font-size: clamp(0.8rem, 1.2vw, 1.1rem);
    color: var(--accent);
    letter-spacing: 0.3em;
    text-transform: uppercase;
}

.title-sub {
    font-family: var(--font-latin);
    font-weight: 400;
    font-size: clamp(0.7rem, 0.9vw, 0.85rem);
    color: var(--text-secondary);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    opacity: 0.8;
}

.arrow-cue {
    font-family: var(--font-latin);
    font-weight: 400;
    font-size: clamp(1.2rem, 1.6vw, 1.8rem);
    color: var(--accent);
    opacity: 0.5;
    margin-top: 2.5em;
    animation: arrow-pulse 2s ease-in-out infinite;
}
@keyframes arrow-pulse {
    0%, 100% { transform: translateX(0); opacity: 0.4; }
    50%      { transform: translateX(8px); opacity: 0.85; }
}

/* ==========================================================================
   Panel 2 — The Origin
   ========================================================================== */

.panel--origin {
    justify-content: center;
    align-items: center;
}

.origin-watermark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: var(--font-latin);
    font-weight: 600;
    font-size: clamp(20rem, 35vw, 40rem);
    color: rgba(164, 136, 104, 0.07);
    letter-spacing: -0.03em;
    line-height: 1;
    user-select: none;
    pointer-events: none;
    z-index: 0;
}

.origin-rule {
    position: absolute;
    top: 8vh;
    bottom: 8vh;
    border-left: var(--rule);
    z-index: 1;
}
.origin-rule--left { left: 15vw; }
.origin-rule--right { right: 15vw; }

.origin-column {
    max-width: 38ch;
    margin: auto;
    text-align: left;
    z-index: 2;
}

.origin-label {
    font-family: var(--font-latin);
    font-weight: 600;
    font-size: 0.7rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 1em;
}

.origin-heading {
    font-family: var(--font-hangul);
    font-weight: 700;
    font-size: clamp(1.4rem, 2.2vw, 2rem);
    color: var(--text-primary);
    margin-bottom: 1.5em;
    line-height: 1.2;
}

.origin-para {
    font-family: var(--font-hangul);
    font-weight: 400;
    font-size: clamp(0.95rem, 1.15vw, 1.05rem);
    color: var(--text-primary);
    line-height: 1.85;
    margin-bottom: 1.3em;
}
.origin-para em {
    font-style: italic;
    color: var(--accent-dark);
    font-weight: 500;
}
.pull {
    display: block;
    padding: 1em 1.2em;
    border-left: 2px solid var(--accent-warm);
    font-style: italic;
    color: var(--text-secondary);
    font-size: 0.98em;
    background: rgba(235, 227, 215, 0.35);
}

.origin-cite {
    font-family: var(--font-latin);
    font-size: 0.75rem;
    color: var(--accent);
    letter-spacing: 0.1em;
    margin-top: 1.8em;
    text-align: right;
}

/* ==========================================================================
   Panel 3 — The Consonant Map
   ========================================================================== */

.consonant-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 2vw;
    width: 82vw;
    height: 62vh;
    margin: auto;
}

.cell {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1vh 0.8vw;
    border: var(--rule);
    background: rgba(244, 237, 228, 0.55);
    box-shadow: 3px 3px 0 rgba(235, 227, 215, 0.6);
    transition: transform 0.4s ease, box-shadow 0.4s ease;
    opacity: 0;
}
.cell.is-in { opacity: 1; animation: brush-set 200ms ease-out forwards; }
.cell:hover {
    transform: translate(-1px, -1px);
    box-shadow: 4px 4px 0 var(--bg-secondary);
}

.cell__char {
    font-family: var(--font-hangul);
    font-weight: 700;
    font-size: clamp(3rem, 5vw, 5rem);
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 0.3em;
}
.cell__rom {
    font-family: var(--font-latin);
    font-weight: 400;
    font-size: 0.75rem;
    color: var(--text-secondary);
    letter-spacing: 0.08em;
    margin-bottom: 0.6em;
}
.cell__diagram {
    width: 40px;
    height: 40px;
    stroke: var(--text-primary);
    stroke-width: 1.5;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0.82;
}

/* Legend cell */
.cell--legend {
    padding: 1.2vh 1vw;
    justify-content: flex-start;
    background: var(--bg-secondary);
}
.cell__legend-title {
    font-family: var(--font-latin);
    font-weight: 600;
    font-size: 0.65rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 1em;
    padding-bottom: 0.6em;
    border-bottom: var(--rule);
    width: 100%;
    text-align: left;
}
.cell__legend-body {
    font-family: var(--font-latin);
    font-size: 0.7rem;
    color: var(--text-secondary);
    line-height: 1.7;
    text-align: left;
}

/* shake-error = brush-set tremor */
@keyframes brush-set {
    0%   { transform: translateX(-2px); }
    25%  { transform: translateX( 2px); }
    50%  { transform: translateX(-1px); }
    75%  { transform: translateX( 1px); }
    100% { transform: translateX(0); opacity: 1; }
}

/* ==========================================================================
   Panel 4 — The Vowel Architecture
   ========================================================================== */

.panel--vowels {
    background: var(--bg-secondary);
}

.mandala {
    position: relative;
    width: min(66vh, 62vw);
    height: min(66vh, 62vw);
    margin: auto;
}

.mandala__lines {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    stroke: var(--accent-warm);
    stroke-width: 0.6;
    fill: none;
    opacity: 0.55;
}

.vowel {
    position: absolute;
    left: var(--x);
    top: var(--y);
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3em;
    background: var(--bg-secondary);
    padding: 0.3em 0.7em;
    transition: transform 0.4s ease;
}
.vowel:hover { transform: translate(-50%, -50%) scale(1.08); }

.vowel__char {
    font-family: var(--font-hangul);
    font-weight: 700;
    font-size: clamp(2rem, 3.6vw, 4rem);
    color: var(--text-primary);
    line-height: 1;
}
.vowel__label {
    font-family: var(--font-latin);
    font-size: 0.65rem;
    color: var(--text-secondary);
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.vowel--center .vowel__char {
    font-size: clamp(3rem, 5vw, 5rem);
    color: var(--accent-dark);
}
.vowel--center .vowel__label {
    color: var(--accent);
}

/* ==========================================================================
   Panel 5 — The Syllable Block
   ========================================================================== */

.syllable-stage {
    margin: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3vw;
    min-height: 40vh;
    padding: 3vh 0;
}

.syllable-piece {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5em;
    transition: transform 0.8s cubic-bezier(0.16, 1, 0.3, 1),
                opacity 0.8s cubic-bezier(0.16, 1, 0.3, 1);
    padding: 1em;
    border: var(--rule);
    background: rgba(244, 237, 228, 0.7);
    box-shadow: 3px 3px 0 var(--bg-secondary);
    min-width: 9vw;
}

.syllable-piece__char {
    font-family: var(--font-hangul);
    font-weight: 700;
    font-size: clamp(5rem, 10vw, 11rem);
    color: var(--text-primary);
    line-height: 0.9;
}
.syllable-piece__role {
    font-family: var(--font-latin);
    font-weight: 600;
    font-size: 0.65rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--accent);
}
.syllable-piece__rom {
    font-family: var(--font-latin);
    font-size: 0.75rem;
    color: var(--text-secondary);
    letter-spacing: 0.08em;
}

.syllable-arrow {
    font-family: var(--font-latin);
    font-weight: 400;
    font-size: clamp(1.2rem, 1.8vw, 2rem);
    color: var(--accent);
    opacity: 0.7;
    transition: opacity 0.8s ease;
}

/* Assembled state: collapse pieces into a single block position */
.syllable-stage.assembled {
    gap: 0;
}
.syllable-stage.assembled .syllable-arrow {
    opacity: 0;
    width: 0;
    overflow: hidden;
    padding: 0;
    margin: 0;
}
.syllable-stage.assembled .syllable-piece {
    border-color: transparent;
    background: transparent;
    box-shadow: none;
    min-width: 0;
    padding: 0;
}
.syllable-stage.assembled .syllable-piece__role,
.syllable-stage.assembled .syllable-piece__rom {
    opacity: 0;
    height: 0;
    overflow: hidden;
}
.syllable-stage.assembled .syllable-piece--initial {
    transform: translate(2vw, 0) scale(0.6);
}
.syllable-stage.assembled .syllable-piece--medial {
    transform: translate(-1vw, 0) scale(0.6);
}
.syllable-stage.assembled .syllable-piece--final {
    transform: translate(-6vw, 3vh) scale(0.6);
}

.syllable-result {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.4em;
    margin: 2vh auto 0;
    padding: 2vh 0;
    border-top: var(--rule);
    max-width: 70%;
}
.syllable-result__arrow {
    font-family: var(--font-latin);
    color: var(--accent);
    font-size: clamp(1rem, 1.5vw, 1.3rem);
}
.syllable-result__char {
    font-family: var(--font-hangul);
    font-weight: 700;
    font-size: clamp(3.5rem, 6vw, 6rem);
    color: var(--accent-dark);
    line-height: 1;
}
.syllable-result__rom {
    font-family: var(--font-latin);
    font-size: clamp(0.8rem, 1vw, 0.95rem);
    color: var(--text-secondary);
    letter-spacing: 0.08em;
}

.syllable-toggle {
    align-self: center;
    margin-top: 2vh;
    font-family: var(--font-latin);
    font-weight: 500;
    font-size: 0.72rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--accent);
    background: transparent;
    border: var(--rule);
    padding: 0.8em 1.4em;
    cursor: pointer;
    transition: background 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}
.syllable-toggle:hover {
    background: var(--highlight);
    color: var(--accent-dark);
    border-color: var(--highlight);
}

/* ==========================================================================
   Panel 6 — The Sound Logic
   ========================================================================== */

.sound-tree {
    width: 100%;
    max-width: 90vw;
    max-height: 60vh;
    margin: auto;
    display: block;
    overflow: visible;
}

.sound-tree .tree-line {
    stroke: var(--accent-warm);
    stroke-width: 1;
    fill: none;
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
    transition: stroke-dashoffset 1.5s cubic-bezier(0.16, 1, 0.3, 1);
}
.panel--sound.is-in .sound-tree .tree-row[data-row="0"] .tree-line { transition-delay: 0ms; stroke-dashoffset: 0; }
.panel--sound.is-in .sound-tree .tree-row[data-row="1"] .tree-line { transition-delay: 300ms; stroke-dashoffset: 0; }
.panel--sound.is-in .sound-tree .tree-row[data-row="2"] .tree-line { transition-delay: 600ms; stroke-dashoffset: 0; }
.panel--sound.is-in .sound-tree .tree-row[data-row="3"] .tree-line { transition-delay: 900ms; stroke-dashoffset: 0; }

.sound-tree .tree-node {
    fill: var(--bg-primary);
    stroke: var(--text-primary);
    stroke-width: 1.5;
}
.sound-tree .tree-char {
    font-family: var(--font-hangul);
    font-weight: 700;
    font-size: 26px;
    fill: var(--text-primary);
    text-anchor: middle;
    dominant-baseline: middle;
}
.sound-tree .tree-label {
    font-family: "IBM Plex Mono", monospace;
    font-size: 11px;
    fill: var(--accent);
    text-anchor: middle;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}
.sound-tree .tree-rom {
    font-family: "IBM Plex Mono", monospace;
    font-size: 12px;
    fill: var(--text-secondary);
    letter-spacing: 0.05em;
}
.sound-tree .tree-col {
    font-family: "IBM Plex Mono", monospace;
    font-size: 11px;
    fill: var(--accent);
    text-anchor: middle;
    letter-spacing: 0.2em;
    text-transform: uppercase;
}

/* ==========================================================================
   Panel 7 — The Living Script
   ========================================================================== */

.pinboard {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 2vw 1.8vw;
    width: 82vw;
    height: 68vh;
    margin: auto;
}

.pinboard__item {
    display: flex;
    flex-direction: column;
    gap: 0.6em;
    transition: transform 0.4s ease;
}
.pinboard__item--1 { grid-column: 1 / span 1; grid-row: 1 / span 1; transform: rotate(-1.2deg); }
.pinboard__item--2 { grid-column: 2 / span 2; grid-row: 1 / span 1; transform: rotate(0.8deg); }
.pinboard__item--3 { grid-column: 4 / span 1; grid-row: 1 / span 1; transform: rotate(1.5deg); }
.pinboard__item--4 { grid-column: 1 / span 2; grid-row: 2 / span 1; transform: rotate(-0.6deg); }
.pinboard__item--5 { grid-column: 3 / span 1; grid-row: 2 / span 1; transform: rotate(1.2deg); }
.pinboard__item--6 { grid-column: 4 / span 1; grid-row: 2 / span 1; transform: rotate(-1.4deg); }
.pinboard__item--7 { display: none; } /* reserve */

.pinboard__item:hover { transform: rotate(0) scale(1.03); z-index: 2; }

.vintage {
    flex: 1;
    min-height: 0;
    border: 1px solid var(--accent-warm);
    box-shadow: 4px 4px 0 var(--bg-secondary);
    overflow: hidden;
    background: var(--bg-secondary);
}
.vintage svg {
    display: block;
    width: 100%;
    height: 100%;
    filter: sepia(0.25) saturate(0.85) contrast(1.08) brightness(0.98);
}

.pinboard__item figcaption {
    font-family: var(--font-latin);
    font-size: 0.65rem;
    color: var(--text-secondary);
    letter-spacing: 0.05em;
    line-height: 1.5;
    padding: 0 0.2em;
}

/* ==========================================================================
   Panel 8 — The Colophon
   ========================================================================== */

.panel--colophon {
    justify-content: center;
    align-items: center;
    text-align: center;
}

.colophon {
    max-width: 40ch;
    margin: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.8em;
}

.colophon__ornament {
    font-family: var(--font-hangul);
    font-size: 1.5rem;
    color: var(--accent);
}
.colophon__ornament--end { margin-top: 1em; }

.colophon__statement {
    font-family: var(--font-hangul);
    font-weight: 700;
    font-size: clamp(1.2rem, 2vw, 2rem);
    line-height: 1.6;
    color: var(--text-primary);
    max-width: 30ch;
}

.colophon__translation {
    font-family: var(--font-latin);
    font-style: italic;
    font-weight: 400;
    font-size: clamp(0.8rem, 1vw, 0.95rem);
    color: var(--text-secondary);
    line-height: 1.7;
    max-width: 38ch;
}

.colophon__meta {
    font-family: var(--font-latin);
    font-weight: 400;
    font-size: clamp(0.75rem, 0.95vw, 0.9rem);
    color: var(--accent);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    display: flex;
    gap: 0.8em;
    align-items: center;
}
.dot-sep { opacity: 0.5; }

.colophon__cite {
    font-family: var(--font-latin);
    font-size: 0.7rem;
    color: var(--text-secondary);
    letter-spacing: 0.1em;
    line-height: 1.9;
    opacity: 0.8;
    margin-top: 0.5em;
}

/* ==========================================================================
   Reduced motion
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    .arrow-cue { animation: none; }
    .cell.is-in { animation: none; opacity: 1; }
    .syllable-piece { transition: none; }
    .sound-tree .tree-line { transition: none; stroke-dashoffset: 0 !important; }
    body { scroll-behavior: auto; }
}
