/* hwaklyul.com (v2) — wabi-sabi probability herbarium
   Palette: aged paper, bark, indigo, persimmon, moss, tea-stain
   Fonts: Fraunces (variable serif), Cormorant Garamond, JetBrains Mono
*/

:root {
    --paper: #EFE6D2;
    --paper-cream: #F8F1DD;
    --bark: #6E5A3E;
    --indigo: #2E3A5C;
    --persimmon: #B8443A;
    --moss: #5A6B4A;
    --tea: #C4A77A;
    --sumi: #1F1A14;
    --ink-soft: #3A2E1E;

    --font-display: "Fraunces", "Cormorant Garamond", Georgia, serif;
    --font-body: "Cormorant Garamond", Georgia, serif;
    --font-mono: "JetBrains Mono", "Courier New", monospace;
}

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

html {
    scroll-behavior: smooth;
}

body {
    background: var(--paper);
    color: var(--ink-soft);
    font-family: var(--font-body);
    font-size: clamp(15px, 1.05vw, 17px);
    line-height: 1.78;
    overflow-x: hidden;
    position: relative;
    min-height: 100vh;
}

/* Paper grain overlay — subtle SVG noise */
.paper-grain-overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    opacity: 0.55;
    background-image: 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.85' numOctaves='2' seed='5'/><feColorMatrix values='0 0 0 0 0.43  0 0 0 0 0.35  0 0 0 0 0.24  0 0 0 0.06 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
    mix-blend-mode: multiply;
}

/* ============== HERO ============== */
.hero {
    position: relative;
    min-height: 90vh;
    padding: 8vh 8vw 6vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2;
    overflow: hidden;
}

.botanical {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    animation: botanical-fade-in 1.4s ease-out forwards;
}

.botanical-ginkgo {
    width: clamp(180px, 18vw, 280px);
    height: auto;
    bottom: 4vh;
    left: 4vw;
    animation-delay: 0.4s;
    transform: rotate(-6deg);
}

.botanical-fern {
    width: clamp(160px, 14vw, 240px);
    height: auto;
    top: 6vh;
    right: 6vw;
    animation-delay: 0.8s;
    transform: rotate(8deg);
}

.botanical-bamboo {
    width: clamp(140px, 12vw, 220px);
    height: auto;
    top: 35%;
    left: 2vw;
    animation-delay: 1.2s;
    transform: rotate(-3deg);
}

@keyframes botanical-fade-in {
    from { opacity: 0; }
    to { opacity: 0.78; }
}

/* SVG path-draw animation */
.draw-path {
    stroke-dasharray: 800;
    stroke-dashoffset: 800;
    animation: draw-stroke 2.4s ease-out forwards;
    animation-delay: 0.2s;
}

.botanical-ginkgo .draw-path { animation-delay: 0.6s; }
.botanical-fern .draw-path { animation-delay: 1.0s; }
.botanical-bamboo .draw-path { animation-delay: 1.4s; }

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

.hero-content {
    text-align: center;
    z-index: 3;
    max-width: 60ch;
    position: relative;
}

.logotype {
    font-family: var(--font-display);
    font-size: clamp(96px, 18vw, 240px);
    font-weight: 600;
    color: var(--indigo);
    line-height: 1.0;
    letter-spacing: -0.02em;
    margin-bottom: 0.35em;
    font-variation-settings: "opsz" 144, "SOFT" 80, "slnt" 0;
    opacity: 0;
    filter: blur(8px);
    animation: logotype-reveal 1.1s ease-out 0.4s forwards, logotype-breath 14s ease-in-out 1.6s infinite alternate;
}

@keyframes logotype-reveal {
    from {
        opacity: 0;
        filter: blur(8px);
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        filter: blur(0);
        transform: translateY(0);
    }
}

@keyframes logotype-breath {
    0% {
        font-variation-settings: "opsz" 144, "SOFT" 50, "slnt" 0;
    }
    100% {
        font-variation-settings: "opsz" 144, "SOFT" 100, "slnt" -4;
    }
}

.domain-mark {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 400;
    letter-spacing: 0.32em;
    text-transform: uppercase;
    color: var(--bark);
    opacity: 0;
    animation: fade-in 0.8s ease-out 1.6s forwards;
}

.tagline {
    margin-top: 1.6em;
    font-family: var(--font-display);
    font-style: italic;
    font-size: clamp(15px, 1.2vw, 19px);
    color: var(--ink-soft);
    opacity: 0;
    animation: fade-in 0.8s ease-out 2.0s forwards;
}

@keyframes fade-in {
    to { opacity: 1; }
}

.hero-footer-mark {
    position: absolute;
    bottom: 3vh;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.18em;
    color: var(--bark);
    opacity: 0;
    animation: fade-in 1.2s ease-out 2.4s forwards;
    display: flex;
    gap: 12px;
    align-items: center;
}

.hero-footer-mark .mark-num { color: var(--persimmon); }
.hero-footer-mark .mark-sep { opacity: 0.5; }

/* ============== SECTION HEADINGS ============== */
.section-heading {
    text-align: center;
    margin: 0 auto 4rem;
    max-width: 60ch;
    padding: 0 6vw;
}

.section-title {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: clamp(36px, 4.6vw, 64px);
    color: var(--indigo);
    letter-spacing: -0.01em;
    line-height: 1.1;
    font-variation-settings: "opsz" 144, "SOFT" 70;
}

.section-sub {
    margin-top: 0.6em;
    font-family: var(--font-display);
    font-style: italic;
    font-size: clamp(15px, 1.2vw, 19px);
    color: var(--bark);
}

/* ============== BENTO SECTION ============== */
.bento-section {
    position: relative;
    padding: 12vh 6vw;
    z-index: 2;
}

.bento-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: minmax(110px, auto);
    gap: 18px;
    max-width: 1280px;
    margin: 0 auto;
}

.bento-cell {
    position: relative;
    background: var(--paper-cream);
    padding: 28px 28px 36px;
    border-radius: 2px;
    overflow: hidden;
    cursor: pointer;
    /* Hand-trembled "ink wall" border via SVG mask */
    background-image:
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 300' preserveAspectRatio='none'><path d='M2 4 Q 100 6 200 3 T 398 4 Q 396 100 397 150 T 396 296 Q 300 297 200 296 T 4 297 Q 5 200 3 100 T 2 4 Z' fill='none' stroke='%236E5A3E' stroke-width='1.2' opacity='0.55'/></svg>");
    background-size: 100% 100%;
    background-repeat: no-repeat;
    background-position: center;
    transition: transform 600ms cubic-bezier(0.22, 0.61, 0.36, 1), box-shadow 600ms ease;
}

.bento-cell::before {
    /* Tiny brushwork tick at top-left corner */
    content: "";
    position: absolute;
    top: 8px;
    left: 8px;
    width: 12px;
    height: 12px;
    background:
        linear-gradient(135deg, var(--bark) 0 1.5px, transparent 1.5px) 0 0/12px 12px no-repeat,
        linear-gradient(45deg, var(--bark) 0 1px, transparent 1px) 0 0/12px 12px no-repeat;
    opacity: 0.55;
    pointer-events: none;
}

.bento-cell::after {
    /* Tick at bottom-right */
    content: "";
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 14px;
    height: 14px;
    background: linear-gradient(-45deg, var(--bark) 0 1.5px, transparent 1.5px) 0 0/14px 14px no-repeat;
    opacity: 0.5;
    pointer-events: none;
}

.bento-cell.alt {
    background: var(--paper);
}

/* Cell sizing for irregular bento layout */
.cell-a { grid-column: span 5; grid-row: span 3; }
.cell-b { grid-column: span 4; grid-row: span 2; background: var(--paper); }
.cell-c { grid-column: span 3; grid-row: span 3; }
.cell-d { grid-column: span 4; grid-row: span 3; background: var(--paper); }
.cell-e { grid-column: span 5; grid-row: span 2; }
.cell-f { grid-column: span 12; grid-row: span 2; background: var(--paper); }

.cell-illustration {
    width: 100%;
    height: 130px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.cell-illustration svg {
    width: 100%;
    max-width: 220px;
    height: 100%;
    overflow: visible;
}

.morph-path {
    transition: d 1.6s ease-in-out;
}

.morph-aux {
    transition: opacity 1.6s ease-in-out;
}

.cell-body {
    position: relative;
    z-index: 2;
}

.cell-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(24px, 2.4vw, 34px);
    color: var(--indigo);
    line-height: 1.1;
    margin-bottom: 0.4em;
    font-variation-settings: "opsz" 144, "SOFT" 60;
}

.cell-en {
    font-family: var(--font-display);
    font-style: italic;
    font-size: 15px;
    color: var(--bark);
    margin-bottom: 0.9em;
    line-height: 1.4;
}

.cell-formula {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--ink-soft);
    background: rgba(196, 167, 122, 0.18);
    padding: 6px 10px;
    border-radius: 1px;
    display: inline-block;
    border-left: 2px solid var(--moss);
}

.cell-formula sup, .cell-formula sub {
    font-size: 0.8em;
}

.cell-formula .binom {
    display: inline-block;
    border-left: 1px solid var(--ink-soft);
    border-right: 1px solid var(--ink-soft);
    padding: 0 4px;
}

/* Seal stamps */
.cell-seal {
    position: absolute;
    bottom: 16px;
    right: 16px;
    width: 38px;
    height: 38px;
    background: var(--persimmon);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--paper-cream);
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 22px;
    transform: rotate(-2deg);
    transition: transform 500ms cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: inset 0 0 0 1px rgba(255, 235, 220, 0.4);
}

.cell-seal::before {
    content: "";
    position: absolute;
    inset: 3px;
    border: 1px solid rgba(255, 235, 220, 0.45);
    pointer-events: none;
}

.bento-cell:hover .cell-seal {
    transform: rotate(4deg) scale(1.06);
}

.bento-cell:hover {
    transform: translateY(-4px);
    box-shadow: 0 18px 40px -16px rgba(46, 58, 92, 0.18);
}

/* Reveal animation when in viewport */
.bento-cell {
    opacity: 0;
    transform: rotateX(-12deg) translateY(20px);
    transform-origin: top center;
    transition:
        opacity 800ms ease-out,
        transform 800ms cubic-bezier(0.22, 0.61, 0.36, 1),
        box-shadow 600ms ease;
}

.bento-cell.in-view {
    opacity: 1;
    transform: rotateX(0deg) translateY(0);
}

/* ============== BRANCHING SECTION ============== */
.branching-section {
    position: relative;
    padding: 10vh 6vw 14vh;
    z-index: 2;
    background: linear-gradient(180deg, transparent 0%, rgba(196, 167, 122, 0.10) 50%, transparent 100%);
}

.branching-frame {
    max-width: 1280px;
    margin: 0 auto;
    background: var(--paper-cream);
    padding: 4vh 4vw;
    position: relative;
    background-image:
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 300' preserveAspectRatio='none'><path d='M3 5 Q 100 7 200 4 T 397 5 Q 395 100 396 150 T 395 295 Q 300 296 200 295 T 5 296 Q 6 200 4 100 T 3 5 Z' fill='none' stroke='%232E3A5C' stroke-width='1.2' opacity='0.4'/></svg>");
    background-size: 100% 100%;
    background-repeat: no-repeat;
}

.branch-tree {
    width: 100%;
    height: auto;
    display: block;
    overflow: visible;
}

.branch {
    stroke-dasharray: 1200;
    stroke-dashoffset: 1200;
    transition: stroke-dashoffset 1.4s ease-out;
}

.branching-section.in-view .branch {
    stroke-dashoffset: 0;
}

.branching-section .branch-1 { transition-delay: 0s; }
.branching-section .branch-2 { transition-delay: 0.7s; }
.branching-section .branch-3 { transition-delay: 0.7s; }
.branching-section .branch-4 { transition-delay: 1.4s; }
.branching-section .branch-5 { transition-delay: 1.4s; }
.branching-section .branch-6 { transition-delay: 1.4s; }
.branching-section .branch-7 { transition-delay: 1.4s; }

.tip {
    opacity: 0;
    transition: opacity 600ms ease-out;
}

.branching-section.in-view .tip-1 { opacity: 1; transition-delay: 2.6s; }
.branching-section.in-view .tip-2 { opacity: 1; transition-delay: 2.7s; }
.branching-section.in-view .tip-3 { opacity: 1; transition-delay: 2.8s; }
.branching-section.in-view .tip-4 { opacity: 1; transition-delay: 2.9s; }

.branch-labels text {
    opacity: 0;
    transition: opacity 600ms ease-out;
}

.branching-section.in-view .lbl-trunk { opacity: 1; transition-delay: 0.4s; }
.branching-section.in-view .lbl-2 { opacity: 1; transition-delay: 1.6s; }
.branching-section.in-view .lbl-3 { opacity: 1; transition-delay: 1.6s; }
.branching-section.in-view .lbl-4 { opacity: 1; transition-delay: 2.4s; }
.branching-section.in-view .lbl-5 { opacity: 1; transition-delay: 2.4s; }
.branching-section.in-view .lbl-6 { opacity: 1; transition-delay: 2.4s; }
.branching-section.in-view .lbl-7 { opacity: 1; transition-delay: 2.4s; }
.branching-section.in-view .lbl-tip { opacity: 1; transition-delay: 3.0s; }
.branching-section.in-view .lbl-tip-1 { transition-delay: 3.0s; }
.branching-section.in-view .lbl-tip-2 { transition-delay: 3.1s; }
.branching-section.in-view .lbl-tip-3 { transition-delay: 3.2s; }
.branching-section.in-view .lbl-tip-4 { transition-delay: 3.3s; }

.branch-caption {
    margin-top: 2.4em;
    text-align: center;
    font-family: var(--font-display);
    font-style: italic;
    color: var(--bark);
    max-width: 60ch;
    margin-left: auto;
    margin-right: auto;
}

/* ============== LEDGER SECTION ============== */
.ledger-section {
    position: relative;
    padding: 12vh 6vw;
    z-index: 2;
    overflow: hidden;
}

.tea-stain {
    position: absolute;
    border-radius: 50%;
    filter: blur(2px);
    pointer-events: none;
    z-index: 1;
    mix-blend-mode: multiply;
    animation: stain-drift 14s ease-in-out infinite alternate;
}

.stain-1 {
    width: 320px;
    height: 320px;
    top: 8%;
    left: -4%;
    background: radial-gradient(circle, rgba(196, 167, 122, 0.55) 0%, rgba(196, 167, 122, 0.18) 40%, transparent 70%);
    animation-delay: 0s;
}

.stain-2 {
    width: 260px;
    height: 260px;
    top: 30%;
    right: -2%;
    background: radial-gradient(circle, rgba(110, 90, 62, 0.42) 0%, rgba(110, 90, 62, 0.12) 45%, transparent 70%);
    animation-delay: 3s;
    animation-duration: 16s;
}

.stain-3 {
    width: 220px;
    height: 220px;
    bottom: 12%;
    left: 18%;
    background: radial-gradient(circle, rgba(184, 68, 58, 0.22) 0%, rgba(184, 68, 58, 0.06) 50%, transparent 75%);
    animation-delay: 6s;
    animation-duration: 18s;
}

.stain-4 {
    width: 180px;
    height: 180px;
    bottom: 4%;
    right: 22%;
    background: radial-gradient(circle, rgba(196, 167, 122, 0.46) 0%, rgba(196, 167, 122, 0.10) 45%, transparent 70%);
    animation-delay: 9s;
    animation-duration: 13s;
}

@keyframes stain-drift {
    0% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(3px, -2px) scale(1.02); }
    100% { transform: translate(-2px, 3px) scale(0.98); }
}

.ledger-table {
    position: relative;
    z-index: 2;
    max-width: 1080px;
    margin: 0 auto;
}

.ledger-row {
    display: grid;
    grid-template-columns: 2.4fr 1.6fr 1.2fr 1.2fr;
    gap: 1.5rem;
    padding: 1.4rem 1.2rem;
    border-bottom: 1px dashed rgba(110, 90, 62, 0.35);
    align-items: baseline;
    transition: background 400ms ease;
}

.ledger-row:last-child {
    border-bottom: none;
}

.ledger-row:not(.ledger-head):hover {
    background: rgba(196, 167, 122, 0.18);
}

.ledger-head {
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.22em;
    color: var(--bark);
    border-bottom: 2px solid var(--bark);
    padding-bottom: 1.6rem;
    margin-bottom: 0.5rem;
}

.ledger-col strong {
    font-family: var(--font-display);
    font-weight: 600;
    color: var(--indigo);
    font-size: clamp(18px, 1.6vw, 22px);
    font-variation-settings: "opsz" 144, "SOFT" 60;
}

.ledger-col code {
    font-family: var(--font-mono);
    font-size: 14px;
    color: var(--ink-soft);
}

.ledger-col.col-name code,
.ledger-row:not(.ledger-head) .ledger-col.col-mean code,
.ledger-row:not(.ledger-head) .ledger-col.col-var code {
    color: var(--persimmon);
}

.ledger-margin {
    margin-top: 3rem;
    text-align: center;
    font-family: var(--font-display);
    font-style: italic;
    color: var(--bark);
    opacity: 0.78;
    font-size: 16px;
    position: relative;
    z-index: 2;
}

/* ============== FOOTER ============== */
.footer {
    position: relative;
    padding: 6vh 6vw 8vh;
    text-align: center;
    z-index: 2;
}

.horizon-line {
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, var(--moss) 20%, var(--moss) 80%, transparent 100%);
    max-width: 600px;
    margin: 0 auto 3vh;
}

.dragonfly {
    width: 140px;
    height: auto;
    margin: 0 auto 2vh;
    display: block;
    opacity: 0.78;
    animation: dragonfly-hover 6s ease-in-out infinite alternate;
}

@keyframes dragonfly-hover {
    0% { transform: translateX(-8px) translateY(0); }
    100% { transform: translateX(8px) translateY(-3px); }
}

.footer-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.8rem;
}

.seal-stamp {
    width: 42px;
    height: 42px;
    background: var(--persimmon);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--paper-cream);
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 24px;
    transform: rotate(-3deg);
    box-shadow: inset 0 0 0 1px rgba(255, 235, 220, 0.45);
    position: relative;
}

.seal-stamp::before {
    content: "";
    position: absolute;
    inset: 3px;
    border: 1px solid rgba(255, 235, 220, 0.45);
}

.footer-line {
    font-family: var(--font-display);
    font-style: italic;
    color: var(--ink-soft);
    font-size: 16px;
}

.footer-line-small {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--bark);
    opacity: 0.78;
}

/* ============== INK TRAIL ============== */
.ink-trail {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
}

.ink-dot {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--persimmon);
    transform: translate(-50%, -50%);
    filter: blur(1.5px);
    opacity: 0.7;
    animation: ink-fade 1200ms ease-out forwards;
}

@keyframes ink-fade {
    from {
        opacity: 0.7;
        transform: translate(-50%, -50%) scale(1);
    }
    to {
        opacity: 0;
        transform: translate(-50%, -50%) scale(2.4);
    }
}

/* ============== RESPONSIVE ============== */
@media (max-width: 880px) {
    .botanical-bamboo { display: none; }

    .bento-grid {
        grid-template-columns: repeat(6, 1fr);
        gap: 14px;
    }

    .cell-a { grid-column: span 6; grid-row: span 3; }
    .cell-b { grid-column: span 6; grid-row: span 2; }
    .cell-c { grid-column: span 3; grid-row: span 2; }
    .cell-d { grid-column: span 3; grid-row: span 2; }
    .cell-e { grid-column: span 6; grid-row: span 2; }
    .cell-f { grid-column: span 6; grid-row: span 2; }

    .ledger-row {
        grid-template-columns: 1fr 1fr;
        gap: 0.6rem 1rem;
    }
    .ledger-head .col-support,
    .ledger-head .col-mean,
    .ledger-head .col-var,
    .ledger-row .col-support,
    .ledger-row .col-mean,
    .ledger-row .col-var {
        font-size: 12px;
    }
}

@media (max-width: 540px) {
    .botanical-fern { opacity: 0.4; }
    .logotype { font-size: clamp(72px, 22vw, 130px); }
    .ledger-row {
        grid-template-columns: 1fr;
        gap: 0.3rem;
    }
}
