/* =============================================================
   kaigenrei.com — v2
   Ethereal documentary on martial law (戒厳令 / 계엄령)
   Aurora-gradient · split-screen · crystalline · CJK trilingual

   Fonts: Cormorant Garamond, Noto Sans JP, Space Mono" (Google Fonts)
   Interior padding uses clamp() for responsive spacing.
   All timeline entry elements use IntersectionObserver in script.js
   to drive active-marker advancement on scroll.
   ============================================================= */

:root {
    /* Aurora palette (DESIGN.md) */
    --aurora-deep:    #0d1b2a;   /* midnight navy   */
    --aurora-mid:     #1b3a5c;   /* storm blue      */
    --aurora-light:   #3a5c7c;   /* atmospheric teal */
    --aurora-violet:  #7c3aed;   /* electric violet */
    --aurora-green:   #34d399;   /* northern emerald */
    --warm-ground:    #f8f5f0;   /* soft cream      */
    --ink:            #1a1a2e;   /* text on light   */
    --pale:           #e0ddf0;   /* text on dark    */
    --crystal:        #a78bfa;   /* soft violet     */

    /* Fonts (DESIGN.md) */
    --font-display: "Cormorant Garamond", "Times New Roman", serif;
    --font-body:    "Noto Sans JP", system-ui, -apple-system, "Helvetica Neue", sans-serif;
    --font-mono:    "Space Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

    /* Layout tokens */
    --pad-x: clamp(32px, 5vw, 80px);
    --pad-y: clamp(28px, 4vw, 64px);
    --divider: 2px;

    /* Sizing tokens */
    --display-xl: clamp(48px, 8vw, 120px);
    --display-l:  clamp(32px, 6vw, 80px);
    --display-m:  clamp(24px, 3.4vw, 44px);
    --body:       clamp(15px, 1.05vw, 18px);
    --meta:       12px;
}

* { box-sizing: border-box; }
html, body {
    margin: 0;
    padding: 0;
    background: var(--aurora-deep);
    color: var(--pale);
    font-family: var(--font-body);
    font-size: var(--body);
    line-height: 1.8;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body { overflow-x: hidden; }

::selection {
    background: rgba(124, 58, 237, 0.45);
    color: var(--warm-ground);
}

/* =============================================================
   BOOT VEIL — solid #0d1b2a covering the page until the
   divider draws and panels fade in.
   ============================================================= */
.boot-veil {
    position: fixed;
    inset: 0;
    background: var(--aurora-deep);
    z-index: 999;
    pointer-events: none;
    transition: opacity 1100ms ease 900ms, visibility 0s 2000ms;
}
body.is-ready .boot-veil {
    opacity: 0;
    visibility: hidden;
}

/* =============================================================
   STAGE = full-viewport composition unit
   ============================================================= */
.stage {
    position: relative;
    width: 100%;
    isolation: isolate;
}

/* ----- Hero: vertical split-screen ----- */
.stage--hero {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
}

/* ----- Closing: vertical split-screen, inverted (light then dark) ----- */
.stage--closing {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
}

/* ----- Vertical 2px divider (DESIGN.md) ----- */
.stage__divider--vertical {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: var(--divider);
    height: 0;
    background: var(--aurora-violet);
    box-shadow: 0 0 18px rgba(124, 58, 237, 0.55);
    z-index: 5;
    animation:
        divider-draw 800ms cubic-bezier(0.65, 0, 0.35, 1) 400ms forwards,
        divider-pulse 3s ease-in-out 1400ms infinite;
}

@keyframes divider-draw {
    0%   { height: 0; }
    100% { height: 100%; }
}
@keyframes divider-pulse {
    0%, 100% { opacity: 0.6; }
    50%      { opacity: 1; }
}

/* =============================================================
   PANELS
   ============================================================= */
.panel {
    position: relative;
    overflow: hidden;
    padding: var(--pad-y) var(--pad-x);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.panel--aurora {
    background: var(--aurora-deep);
    color: var(--pale);
    opacity: 0;
    transition: opacity 1200ms ease 1200ms;
}
.panel--ground {
    background: var(--warm-ground);
    color: var(--ink);
    opacity: 0;
    transition: opacity 1200ms ease 1200ms;
}
body.is-ready .panel--aurora,
body.is-ready .panel--ground { opacity: 1; }

/* ---- Aurora veils (animated multi-stop gradients) ---- */
.aurora-veil {
    position: absolute;
    inset: -10%;
    pointer-events: none;
    will-change: background-position, transform, opacity;
}
.aurora-veil--alpha {
    background:
        linear-gradient(135deg,
            var(--aurora-deep) 0%,
            var(--aurora-mid) 25%,
            var(--aurora-light) 50%,
            var(--aurora-violet) 75%,
            var(--aurora-deep) 100%);
    background-size: 400% 400%;
    animation: aurora-shift-a 18s ease-in-out infinite;
    opacity: 0.95;
}
.aurora-veil--beta {
    background:
        radial-gradient(ellipse 80% 60% at 30% 30%, rgba(52, 211, 153, 0.35) 0%, transparent 60%),
        radial-gradient(ellipse 70% 80% at 70% 70%, rgba(124, 58, 237, 0.55) 0%, transparent 65%),
        radial-gradient(ellipse 60% 50% at 50% 90%, rgba(58, 92, 124, 0.6) 0%, transparent 70%);
    background-size: 300% 300%;
    animation: aurora-shift-b 22s ease-in-out infinite;
    mix-blend-mode: screen;
}
.aurora-veil--fade {
    /* Closing-side aurora dissolves toward calm deep blue (DESIGN.md) */
    animation-duration: 28s;
    filter: saturate(0.85) brightness(0.9);
}

@keyframes aurora-shift-a {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}
@keyframes aurora-shift-b {
    0%   { background-position: 0% 0%; transform: rotate(0deg); }
    50%  { background-position: 100% 50%; transform: rotate(0.6deg); }
    100% { background-position: 0% 0%; transform: rotate(0deg); }
}

.aurora-grain {
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
        radial-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px);
    background-size: 3px 3px, 7px 7px;
    background-position: 0 0, 1px 2px;
    mix-blend-mode: overlay;
    opacity: 0.55;
    pointer-events: none;
}

/* ---- Panel meta-text (Space Mono) ---- */
.panel__meta {
    font-family: var(--font-mono);
    font-size: var(--meta);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    opacity: 0.72;
    z-index: 3;
}
.panel__meta--top {
    position: absolute;
    top: var(--pad-y);
    left: var(--pad-x);
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--pale);
}
.panel__meta--bottom {
    position: absolute;
    bottom: var(--pad-y);
    left: var(--pad-x);
    color: var(--pale);
}
.panel__meta--corner {
    position: absolute;
    top: var(--pad-y);
    right: var(--pad-x);
    color: var(--ink);
    opacity: 0.65;
}
.meta-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--aurora-violet);
    box-shadow: 0 0 10px rgba(124, 58, 237, 0.7);
    animation: meta-dot-pulse 3.2s ease-in-out infinite;
}
@keyframes meta-dot-pulse {
    0%, 100% { transform: scale(1);   opacity: 0.85; }
    50%      { transform: scale(1.4); opacity: 1;    }
}

/* =============================================================
   HERO STACK (right-side warm panel)
   ============================================================= */
.hero-stack {
    max-width: 36rem;
    margin: auto 0;
    position: relative;
    z-index: 2;
}
.hero-eyebrow {
    font-family: var(--font-mono);
    font-size: var(--meta);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--aurora-violet);
    margin: 0 0 18px 0;
}
.hero-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: var(--display-xl);
    line-height: 0.95;
    letter-spacing: -0.01em;
    margin: 0 0 14px 0;
    color: var(--ink);
}
.hero-title__line {
    display: inline-block;
    white-space: nowrap;
}
.hero-char {
    display: inline-block;
    transform: translate3d(var(--rand-x, 0), var(--rand-y, 0), 0) rotate(var(--rand-r, 0deg));
    opacity: 0;
    transition:
        transform 600ms cubic-bezier(0.2, 0.7, 0.1, 1),
        opacity 600ms ease;
    will-change: transform, opacity;
}
.hero-char--dot { color: var(--aurora-violet); }
body.is-ready .hero-char {
    transform: translate3d(0, 0, 0) rotate(0deg);
    opacity: 1;
}

.hero-cjk {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: var(--display-m);
    margin: 0 0 28px 0;
    color: var(--aurora-mid);
    letter-spacing: 0.04em;
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    align-items: baseline;
}
.hero-cjk__sep {
    color: var(--aurora-violet);
    font-weight: 500;
    opacity: 0.7;
}
.hero-definition {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: var(--body);
    line-height: 1.8;
    color: var(--ink);
    margin: 0 0 38px 0;
    max-width: 32rem;
}

.hero-cue {
    display: flex;
    align-items: center;
    gap: 14px;
    font-family: var(--font-mono);
    font-size: var(--meta);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--aurora-mid);
    opacity: 0.8;
}
.cue-line {
    display: inline-block;
    width: 56px;
    height: 1px;
    background: var(--aurora-violet);
    transform-origin: left center;
    animation: cue-extend 2.4s ease-in-out infinite;
}
@keyframes cue-extend {
    0%, 100% { transform: scaleX(0.4); }
    50%      { transform: scaleX(1);   }
}

/* =============================================================
   TIMELINE — horizontal split (top: ribbon; bottom: feed)
   ============================================================= */
.stage--timeline {
    background: var(--warm-ground);
    color: var(--ink);
    padding: 0 0 var(--pad-y) 0;
}

.timeline-rail {
    position: sticky;
    top: 0;
    z-index: 4;
    background: var(--warm-ground);
    padding: clamp(40px, 6vw, 80px) var(--pad-x) clamp(28px, 3.5vw, 48px);
    border-bottom: 1px solid rgba(26, 26, 46, 0.08);
}
.rail-inner {
    position: relative;
    max-width: 1280px;
    margin: 0 auto;
    padding: 36px 0 24px;
}
.rail-track {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: rgba(124, 58, 237, 0.35);
    transform: translateY(-50%);
}
.rail-progress {
    position: absolute;
    top: 50%;
    left: 0;
    height: 1px;
    width: 0;
    background: linear-gradient(90deg, var(--aurora-violet), var(--aurora-green));
    box-shadow: 0 0 8px rgba(124, 58, 237, 0.5);
    transform: translateY(-50%);
    transition: width 400ms ease-out;
}
.rail-divider {
    /* the timeline "horizontal divider" between top ribbon and bottom feed */
    position: absolute;
    bottom: -1px;
    left: -100vw;
    right: -100vw;
    height: 1px;
    background: rgba(124, 58, 237, 0.18);
    pointer-events: none;
}
.rail-markers {
    list-style: none;
    margin: 0;
    padding: 0;
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 1px;
}
.rail-marker {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}
.rail-marker__dot {
    appearance: none;
    border: 0;
    cursor: pointer;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--aurora-violet);
    padding: 0;
    transition: width 300ms ease, height 300ms ease, box-shadow 300ms ease, background 300ms ease;
}
.rail-marker.is-active .rail-marker__dot {
    width: 12px;
    height: 12px;
    background: linear-gradient(135deg, var(--aurora-violet), var(--aurora-green));
    box-shadow: 0 0 12px rgba(124, 58, 237, 0.4);
}
.rail-marker__year {
    position: absolute;
    top: 16px;
    font-family: var(--font-mono);
    font-size: var(--meta);
    letter-spacing: 0.05em;
    color: rgba(26, 26, 46, 0.55);
    transition: color 300ms ease, transform 300ms ease;
    white-space: nowrap;
}
.rail-marker.is-active .rail-marker__year {
    color: var(--aurora-violet);
    transform: translateY(2px);
}

/* ---- timeline feed ---- */
.timeline-feed {
    max-width: 980px;
    margin: 0 auto;
    padding: clamp(24px, 4vw, 64px) var(--pad-x) clamp(80px, 10vw, 160px);
}
.entry {
    min-height: 70vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 60px 0;
    border-top: 1px dashed rgba(26, 26, 46, 0.12);
    opacity: 0.32;
    transform: translateY(8px);
    transition: opacity 320ms ease, transform 320ms ease;
}
.entry:first-child { border-top: 0; }
.entry.is-active {
    opacity: 1;
    transform: translateY(0);
}
.entry__head {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    margin: 0 0 18px 0;
    font-family: var(--font-mono);
    font-size: var(--meta);
    letter-spacing: 0.05em;
    color: var(--aurora-mid);
    text-transform: uppercase;
}
.entry__year {
    color: var(--aurora-violet);
    font-weight: 700;
}
.entry__loc { opacity: 0.85; }
.entry__code {
    margin-left: auto;
    padding: 4px 10px;
    border: 1px solid rgba(124, 58, 237, 0.35);
    border-radius: 999px;
    color: var(--aurora-violet);
    background: rgba(124, 58, 237, 0.05);
}
.entry__title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: var(--display-l);
    line-height: 1.05;
    margin: 0 0 28px 0;
    color: var(--ink);
    letter-spacing: -0.005em;
}
.entry__title-alt {
    display: inline-block;
    margin-left: 12px;
    font-weight: 600;
    color: var(--aurora-mid);
    font-size: 0.8em;
}
.entry__lede {
    font-size: var(--body);
    line-height: 1.85;
    color: var(--ink);
    margin: 0 0 18px 0;
}
.entry__detail {
    font-family: var(--font-display);
    font-weight: 500;
    font-style: italic;
    font-size: clamp(17px, 1.8vw, 22px);
    line-height: 1.6;
    color: var(--aurora-mid);
    margin: 0;
    padding-left: 18px;
    border-left: 2px solid var(--aurora-violet);
    max-width: 36rem;
}

/* =============================================================
   ATMOSPHERE — full-bleed aurora with crystalline phrases
   ============================================================= */
.stage--atmosphere {
    min-height: 130vh;
    background: var(--aurora-deep);
    color: var(--pale);
    overflow: hidden;
    padding: clamp(80px, 10vw, 160px) var(--pad-x);
    perspective: 1200px;
}
.atmos-aurora {
    position: absolute;
    inset: 0;
    z-index: 0;
}
.atmos-aurora__layer {
    position: absolute;
    inset: -10%;
    will-change: background-position, transform;
}
.atmos-aurora__layer--1 {
    background: linear-gradient(120deg,
        var(--aurora-deep) 0%,
        var(--aurora-mid)  30%,
        var(--aurora-light) 55%,
        var(--aurora-violet) 80%,
        var(--aurora-deep) 100%);
    background-size: 400% 400%;
    animation: aurora-shift-a 17s ease-in-out infinite;
    opacity: 0.95;
}
.atmos-aurora__layer--2 {
    background: radial-gradient(ellipse 70% 60% at 25% 30%, rgba(52, 211, 153, 0.4) 0%, transparent 60%),
                radial-gradient(ellipse 80% 60% at 75% 70%, rgba(167, 139, 250, 0.55) 0%, transparent 65%),
                radial-gradient(ellipse 50% 80% at 50% 100%, rgba(124, 58, 237, 0.5) 0%, transparent 65%);
    mix-blend-mode: screen;
    animation: atmos-drift 26s ease-in-out infinite;
}
.atmos-aurora__layer--3 {
    background: radial-gradient(ellipse 55% 70% at 50% 30%, rgba(13, 27, 42, 0) 30%, rgba(13, 27, 42, 0.5) 100%);
}
.atmos-aurora__grain {
    position: absolute;
    inset: 0;
    background-image: radial-gradient(rgba(255,255,255,0.05) 1px, transparent 1px);
    background-size: 4px 4px;
    mix-blend-mode: overlay;
    opacity: 0.6;
}
@keyframes atmos-drift {
    0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
    50%      { transform: translate3d(2%, -2%, 0) scale(1.04); }
}

.atmos-header {
    position: relative;
    z-index: 2;
    max-width: 720px;
    margin: 0 auto 64px;
    text-align: center;
}
.atmos-eyebrow {
    font-family: var(--font-mono);
    font-size: var(--meta);
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--crystal);
    display: block;
    margin-bottom: 18px;
}
.atmos-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: var(--display-l);
    margin: 0 0 14px 0;
    color: var(--warm-ground);
    letter-spacing: -0.01em;
}
.atmos-sub {
    font-family: var(--font-body);
    font-size: var(--body);
    color: var(--pale);
    opacity: 0.85;
    margin: 0;
}

.crystal-field {
    position: relative;
    z-index: 2;
    max-width: 1280px;
    margin: 0 auto;
    height: 70vh;
    min-height: 520px;
    transform-style: preserve-3d;
}
.crystal {
    position: absolute;
    top: 50%;
    left: 50%;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(18px, 2.4vw, 32px);
    color: var(--crystal);
    letter-spacing: 0.02em;
    white-space: nowrap;
    transform-origin: center center;
    /* base position is computed from data-tx/ty/rot/z via JS into custom props */
    --tx: 0%;
    --ty: 0%;
    --rot: 0deg;
    --z:   -100px;
    --drift: 0px;
    --magnet: 0px;
    transform: translate3d(calc(-50% + var(--tx)), calc(-50% + var(--ty) + var(--drift) + var(--magnet)), var(--z)) rotate(var(--rot));
    text-shadow:
        0 0 18px rgba(167, 139, 250, 0.55),
        0 0 36px rgba(124, 58, 237, 0.3);
    opacity: 0.65;
    will-change: transform, opacity;
    animation: crystal-bob var(--dur, 12s) ease-in-out var(--delay, 0s) infinite alternate;
}
.crystal:nth-of-type(3n)   { opacity: 0.5; }
.crystal:nth-of-type(4n+1) { opacity: 0.75; color: var(--warm-ground); }
.crystal:nth-of-type(5n+2) { opacity: 0.85; color: var(--aurora-green); }

@keyframes crystal-bob {
    0%   { --drift: -6px; }
    100% { --drift:  14px; }
}

@property --drift {
    syntax: "<length>";
    inherits: false;
    initial-value: 0px;
}
@property --magnet {
    syntax: "<length>";
    inherits: false;
    initial-value: 0px;
}

.atmos-foot {
    position: relative;
    z-index: 2;
    max-width: 760px;
    margin: 80px auto 0;
    text-align: center;
    font-family: var(--font-display);
    font-style: italic;
    font-size: clamp(18px, 2vw, 26px);
    color: var(--pale);
    opacity: 0.85;
    line-height: 1.6;
}
.atmos-foot__char {
    display: inline-block;
    margin: 0 2px;
    transition: transform 400ms ease;
}
.atmos-foot__char:hover { transform: translateY(-3px); }
.atmos-foot__sep { opacity: 0.55; }

/* =============================================================
   CLOSING — inverted split (light, then dark fading to deep blue)
   ============================================================= */
.panel--closing-light {
    background: var(--warm-ground);
    color: var(--ink);
}
.panel--closing-dark {
    background: var(--aurora-deep);
    color: var(--pale);
}
.closing-stack {
    max-width: 38rem;
    margin: auto 0;
}
.closing-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: var(--display-l);
    margin: 0 0 12px 0;
    color: var(--ink);
}
.closing-cjk {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: var(--display-m);
    color: var(--aurora-mid);
    margin: 0 0 36px 0;
}
.closing-cjk__sep {
    color: var(--aurora-violet);
    margin: 0 8px;
    opacity: 0.7;
}
.closing-body {
    font-size: var(--body);
    line-height: 1.85;
    color: var(--ink);
    margin: 0 0 22px 0;
}
.closing-body em {
    font-style: italic;
    color: var(--aurora-violet);
    font-weight: 700;
}
.closing-body--quiet {
    color: var(--aurora-mid);
    font-family: var(--font-display);
    font-style: italic;
    font-size: clamp(17px, 1.8vw, 22px);
}
.closing-sign {
    margin-top: 42px;
    display: flex;
    align-items: center;
    gap: 14px;
    font-family: var(--font-mono);
    font-size: var(--meta);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--aurora-mid);
}
.closing-sign__bar {
    display: inline-block;
    width: 36px;
    height: 1px;
    background: var(--aurora-violet);
}

.closing-index {
    list-style: none;
    margin: auto 0;
    padding: 0;
    position: relative;
    z-index: 2;
    color: var(--pale);
    font-family: var(--font-mono);
    font-size: var(--meta);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    display: grid;
    gap: 14px;
}
.closing-index li {
    display: grid;
    grid-template-columns: 36px 1fr;
    align-items: baseline;
    padding: 12px 0;
    border-top: 1px solid rgba(224, 221, 240, 0.18);
}
.closing-index li:last-child {
    border-bottom: 1px solid rgba(224, 221, 240, 0.18);
}
.closing-index span {
    color: var(--crystal);
    font-weight: 700;
}

/* =============================================================
   RESPONSIVE — collapse split-screens on narrow viewports
   ============================================================= */
@media (max-width: 860px) {
    .stage--hero,
    .stage--closing {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr;
        min-height: 100vh;
    }
    .stage__divider--vertical {
        top: 50%;
        left: 0;
        right: 0;
        width: 100%;
        height: var(--divider);
        transform: translateY(-50%);
        animation:
            divider-draw-h 800ms cubic-bezier(0.65, 0, 0.35, 1) 400ms forwards,
            divider-pulse 3s ease-in-out 1400ms infinite;
    }
    @keyframes divider-draw-h {
        0%   { width: 0; }
        100% { width: 100%; }
    }
    .panel--aurora { order: 1; }
    .panel--ground { order: 2; }
    .panel--closing-light { order: 1; }
    .panel--closing-dark  { order: 2; }
    .panel { min-height: 50vh; }

    .rail-marker__year {
        font-size: 10px;
    }

    .crystal-field {
        height: 100vh;
        min-height: 600px;
    }
    .crystal {
        font-size: clamp(14px, 4vw, 22px);
    }
    .closing-index {
        margin: 24px 0;
    }
}

@media (max-width: 520px) {
    .panel__meta--top,
    .panel__meta--bottom {
        font-size: 10px;
    }
    .entry__head { font-size: 10px; }
    .entry__code { display: none; }
}
