/* ============================================================
   yesang.xyz — Cartography of Probable Futures
   Aesthetic: futuristic-cutting-edge + dreamy-ethereal
   Palette: Prediction Cone
   ============================================================ */

:root {
    /* Prediction Cone Palette */
    --origin-point: #0A0A1A;
    --near-certainty: #1A2030;
    --mid-horizon: #3A4A5A;
    --fog-limit: #7A8A9A;
    --thread-red: #C44536;
    --branch-gold: #D4A017;
    --bg-top: #FAFBFC;
    --bg-bottom: #E8ECF0;
    --confidence-glow: #3B82F6;

    /* Typography stack
       Note: Victor Mono is not on Google Fonts; substitute JetBrains Mono italic. */
    --font-display: "Sora", "Inter", system-ui, sans-serif;
    --font-body: "Source Sans 3", "Inter", system-ui, sans-serif;
    --font-mono: "JetBrains Mono", "Space Mono", ui-monospace, monospace;
    --font-frag: "Space Grotesk", "Inter", system-ui, sans-serif;

    /* Per-horizon opacity decay */
    --text-opacity: 1.0;

    /* Layout */
    --page-max: 1600px;
    --gutter: clamp(20px, 4vw, 56px);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    overflow-x: hidden;
}

body {
    font-family: var(--font-body);
    color: var(--origin-point);
    background: transparent;
    line-height: 1.7;
    position: relative;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ---------------- Background Gradient ---------------- */
.bg-gradient {
    position: fixed;
    inset: 0;
    z-index: -2;
    background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
    pointer-events: none;
}

/* ---------------- Thread SVG (full page nervous system) ---------------- */
.thread-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
    overflow: visible;
}

.thread-svg .threads path {
    fill: none;
    stroke: var(--thread-red);
    stroke-width: 1;
    stroke-linecap: round;
    /* Drawn-by-scroll effect */
    stroke-dasharray: var(--len, 4000);
    stroke-dashoffset: var(--len, 4000);
    transition: stroke-dashoffset 1s linear;
}

.thread-svg .fans path {
    fill: var(--branch-gold);
    fill-opacity: 0.08;
    stroke: none;
}

.thread-svg .nodes circle {
    fill: transparent;
    stroke: var(--thread-red);
    stroke-width: 2;
    pointer-events: auto;
    cursor: crosshair;
    transition: fill 200ms ease, transform 200ms ease;
    transform-box: fill-box;
    transform-origin: center;
}

.thread-svg .nodes circle:hover {
    fill: var(--thread-red);
    transform: scale(1.4);
}

.node-tooltip {
    position: fixed;
    z-index: 50;
    pointer-events: none;
    font-family: var(--font-mono);
    font-style: italic;
    font-size: 13px;
    color: var(--thread-red);
    background: rgba(250, 251, 252, 0.94);
    border: 1px solid var(--thread-red);
    padding: 6px 10px;
    border-radius: 2px;
    opacity: 0;
    transform: translate(-50%, -120%);
    transition: opacity 200ms ease;
    white-space: nowrap;
}

.node-tooltip.visible { opacity: 1; }

/* ---------------- Page container ---------------- */
.page {
    position: relative;
    width: 100%;
    max-width: var(--page-max);
    margin: 0 auto;
    padding: 0 var(--gutter);
    z-index: 1;
}

/* ---------------- Horizon shared styles ---------------- */
.horizon {
    position: relative;
    padding: clamp(80px, 14vh, 180px) 0;
    transition: max-width 700ms cubic-bezier(.2, .7, .1, 1);
}

.horizon-marker {
    font-family: var(--font-mono);
    font-style: italic;
    font-size: 12px;
    color: var(--thread-red);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    display: flex;
    gap: 24px;
    margin-bottom: 32px;
    opacity: 0.85;
}

.marker-label::before { content: "◇ "; }
.marker-prob { color: var(--mid-horizon); }

.horizon-title {
    font-family: var(--font-display);
    font-weight: 700;
    letter-spacing: -0.015em;
    margin: 0 0 28px 0;
}

.prose p {
    margin: 0 0 1.1em 0;
    opacity: var(--text-opacity);
    font-size: 17px;
}

.prose .lede {
    font-size: 19px;
    line-height: 1.65;
}

.prose em {
    font-style: italic;
    color: var(--thread-red);
    font-weight: 600;
}

.branch-label {
    font-family: var(--font-mono);
    font-style: italic;
    color: var(--thread-red);
    font-size: 14px;
    letter-spacing: 0.01em;
}

.branch-head {
    font-family: var(--font-display);
    font-weight: 400;
    color: var(--mid-horizon);
    font-size: 18px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin: 0 0 12px 0;
    border-top: 1px solid var(--thread-red);
    padding-top: 10px;
    opacity: 0.85;
}

/* ---------------- HORIZON 1 — single column, narrow, certain ---------------- */
.horizon-1 {
    --text-opacity: 1.0;
    max-width: 600px;
    margin: 0 auto;
    padding-top: clamp(120px, 20vh, 220px);
}

.horizon-1 .horizon-title {
    font-size: clamp(40px, 5vw, 60px);
    color: var(--origin-point);
    line-height: 1.05;
}

.masthead { margin-bottom: 56px; }

.hangul {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(64px, 9vw, 120px);
    color: var(--origin-point);
    letter-spacing: -0.02em;
    line-height: 0.9;
    margin-bottom: 28px;
}

.horizon-meta {
    font-family: var(--font-mono);
    font-style: italic;
    font-size: 14px;
    color: var(--mid-horizon);
    margin-top: 14px;
    letter-spacing: 0.02em;
}

.probability-tag {
    display: inline-flex;
    align-items: center;
    gap: 14px;
    margin-top: 36px;
    font-family: var(--font-mono);
    font-style: italic;
    font-size: 13px;
    color: var(--thread-red);
    border-top: 1px solid var(--thread-red);
    padding-top: 12px;
}

.tag-bar {
    display: inline-block;
    width: 160px;
    height: 4px;
    background: rgba(196, 69, 54, 0.14);
    position: relative;
}

.tag-fill {
    position: absolute;
    inset: 0 auto 0 0;
    width: var(--fill, 0%);
    background: var(--thread-red);
}

.tag-value { color: var(--mid-horizon); }
.tag-label { letter-spacing: 0.18em; text-transform: uppercase; font-size: 11px; }

/* ---------------- HORIZON 2 — two columns, slight asymmetry ---------------- */
.horizon-2 {
    --text-opacity: 0.85;
    max-width: 800px;
    margin: 0 auto;
}

.horizon-2 .horizon-title {
    font-size: clamp(34px, 4.4vw, 52px);
    color: var(--near-certainty);
    line-height: 1.08;
}

.grid-2 {
    display: grid;
    grid-template-columns: 55fr 45fr;
    gap: 56px;
    align-items: start;
}

.prose-major p { font-size: 17px; }

.prose-minor .annotation {
    font-family: var(--font-mono);
    font-style: italic;
    color: var(--thread-red);
    font-size: 12px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    margin-bottom: 8px;
    opacity: 1;
}

.thread-list {
    list-style: none;
    padding: 0;
    margin: 18px 0 0 0;
    border-top: 1px dashed rgba(196, 69, 54, 0.4);
}

.thread-list li {
    padding: 10px 0;
    border-bottom: 1px dashed rgba(196, 69, 54, 0.25);
    font-size: 15px;
    color: var(--mid-horizon);
    opacity: var(--text-opacity);
}

.thread-list .prob {
    font-family: var(--font-mono);
    font-style: italic;
    color: var(--thread-red);
    margin-right: 10px;
}

/* ---------------- HORIZON 3 — three columns, full width ---------------- */
.horizon-3 {
    --text-opacity: 0.7;
    max-width: 100%;
}

.horizon-3 .horizon-title {
    font-size: clamp(30px, 4vw, 48px);
    color: var(--mid-horizon);
    text-align: center;
    line-height: 1.1;
    margin-bottom: 56px;
}

.horizon-3 .horizon-marker { justify-content: center; }

.grid-3 {
    display: grid;
    grid-template-columns: 30fr 40fr 30fr;
    gap: 48px;
    align-items: start;
}

/* ---------------- HORIZON 4 — four columns of varying widths ---------------- */
.horizon-4 {
    --text-opacity: 0.55;
    max-width: 100%;
}

.horizon-4 .horizon-title {
    font-size: clamp(28px, 3.6vw, 44px);
    color: var(--mid-horizon);
    text-align: right;
    margin-bottom: 56px;
    opacity: 0.85;
}

.horizon-4 .horizon-marker { justify-content: flex-end; }

.grid-4 {
    display: grid;
    grid-template-columns: 20fr 30fr 25fr 25fr;
    gap: 36px;
    align-items: start;
}

.horizon-4 .prose p { font-size: 15px; line-height: 1.6; }

/* ---------------- HORIZON 5 — fragment field, scattered text ---------------- */
.horizon-5 {
    --text-opacity: 0.4;
    max-width: 100%;
    min-height: 100vh;
}

.horizon-5 .horizon-title {
    font-size: clamp(24px, 3vw, 36px);
    color: var(--fog-limit);
    text-align: center;
    margin-bottom: 80px;
    font-weight: 400;
    letter-spacing: 0.04em;
    opacity: 0.7;
}

.horizon-5 .horizon-marker { justify-content: center; opacity: 0.55; }

.fragment-field {
    position: relative;
    width: 100%;
    height: clamp(700px, 80vh, 1100px);
}

.frag {
    position: absolute;
    font-family: var(--font-frag);
    font-weight: 300;
    color: var(--origin-point);
    white-space: nowrap;
    user-select: none;
    transform-origin: center;
    /* Fall-in transition driven by JS */
    opacity: 0;
    transform: translate(-50%, -50%) rotate(0deg) translateY(8px);
    transition: opacity 1.2s ease, transform 1.2s ease;
}

.frag.lit {
    opacity: var(--frag-opacity, 0.5);
    transform: translate(-50%, -50%) rotate(var(--frag-rot, 0deg)) translateY(0);
}

/* ---------------- Page footer ---------------- */
.page-footer {
    position: absolute;
    bottom: 28px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    padding: 0 var(--gutter);
    font-family: var(--font-mono);
    font-style: italic;
    font-size: 11px;
    color: var(--fog-limit);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    opacity: 0.6;
}

.foot-prob { color: var(--thread-red); }

/* ---------------- Scroll-aware reveal ---------------- */
.horizon {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 900ms ease, transform 900ms ease;
}

.horizon.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Horizon 1 starts visible (top of page) */
.horizon-1 { opacity: 1; transform: none; }

/* ---------------- Responsive collapse for narrow viewports ---------------- */
@media (max-width: 880px) {
    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
        gap: 32px;
    }

    .horizon-3 .horizon-title,
    .horizon-4 .horizon-title { text-align: left; }

    .horizon-3 .horizon-marker,
    .horizon-4 .horizon-marker,
    .horizon-5 .horizon-marker { justify-content: flex-start; }

    .fragment-field { height: clamp(600px, 90vh, 900px); }

    .page-footer {
        flex-direction: column;
        gap: 6px;
        text-align: left;
    }
}

@media (max-width: 540px) {
    .hangul { font-size: 80px; }
    .horizon-1 .horizon-title { font-size: 36px; }
    .tag-bar { width: 100px; }
}

/* ---------------- Reduced motion ---------------- */
@media (prefers-reduced-motion: reduce) {
    .thread-svg .threads path { transition: none; stroke-dashoffset: 0; }
    .horizon { transition: none; transform: none; opacity: 1; }
    .frag { transition: none; opacity: var(--frag-opacity, 0.5); transform: translate(-50%, -50%) rotate(var(--frag-rot, 0deg)); }
}
