/* =========================================================
   mujun.quest -- y2k futurism in earth tones
   stacked-sections / layered-depth / shake-error / noise
   ========================================================= */

:root {
    --kiln-white: #F2EAE0;
    --kiln-warm: #EDE3D6;
    --dark-loam: #3B2F20;
    --burnt-sienna: #C4592A;
    --weathered-wood: #5C4A3A;
    --dry-clay: #8B7355;
    --sandstone: #A0876E;
    --tarnished-chrome: #6B7B8A;
    --oxidized-copper: #2D6B5A;

    --font-display: 'Jost', 'Futura', 'Space Grotesk', system-ui, sans-serif;
    --font-body: 'DM Sans', 'Inter', system-ui, sans-serif;
    --font-cjk: 'Zen Kaku Gothic New', 'Inter', system-ui, sans-serif;
    --font-mono: 'Space Mono', 'Space', ui-monospace, monospace;
}

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

html {
    background: var(--kiln-white);
    color: var(--dark-loam);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background: var(--kiln-white);
    color: var(--dark-loam);
    font-family: var(--font-body);
    font-weight: 400;
    line-height: 1.55;
    overflow-x: hidden;
    position: relative;
    min-height: 100vh;
}

/* ---- page-wide noise grain ---- */
.page-grain {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 100;
    opacity: 0.08;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.23  0 0 0 0 0.18  0 0 0 0 0.12  0 0 0 1 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
    background-size: 220px 220px;
    mix-blend-mode: multiply;
}

.noise-defs {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* ---- main descent container ---- */
.paradox-descent {
    position: relative;
    z-index: 1;
    scroll-snap-type: y proximity;
    perspective: 800px;
    perspective-origin: 50% 30%;
}

/* ---- generic section ---- */
.contradiction-layer {
    position: relative;
    width: 100%;
    min-height: 80vh;
    padding: clamp(48px, 8vh, 120px) clamp(24px, 6vw, 96px);
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    column-gap: clamp(12px, 1.6vw, 28px);
    row-gap: 24px;
    align-content: center;
    align-items: center;
    transform-style: preserve-3d;
    background: var(--kiln-white);
    scroll-snap-align: start;
    isolation: isolate;
    border-bottom: 1px solid rgba(91, 74, 58, 0.12);
}

.contradiction-layer:nth-child(even) {
    background: var(--kiln-warm);
}

.contradiction-layer:first-child,
.contradiction-layer:last-child {
    min-height: 100vh;
}

/* spear plane (foreground) */
.spear-plane {
    position: relative;
    grid-column: 2 / span 7;
    z-index: 3;
    transform: translateZ(0);
    opacity: 1;
    transition: transform 0.9s cubic-bezier(0.22, 0.61, 0.36, 1),
                opacity 0.9s cubic-bezier(0.22, 0.61, 0.36, 1);
    clip-path: polygon(
        0.4% 0%,
        99.5% 0.6%,
        100% 99%,
        0.8% 100%,
        0% 1%
    );
    padding: clamp(20px, 3vw, 44px) clamp(16px, 2vw, 32px);
}

/* shield plane (background) */
.shield-plane {
    position: relative;
    grid-column: 5 / span 7;
    grid-row: 1;
    z-index: 1;
    transform: translateZ(-40px) translateY(0);
    opacity: 0.42;
    color: var(--tarnished-chrome);
    transition: transform 1s cubic-bezier(0.22, 0.61, 0.36, 1),
                opacity 1s cubic-bezier(0.22, 0.61, 0.36, 1);
    padding: clamp(20px, 3vw, 44px) clamp(16px, 2vw, 32px);
    clip-path: polygon(
        1.2% 0.4%,
        99% 0%,
        99.6% 99.4%,
        0.4% 99.8%,
        0% 0.8%
    );
}

.shield-plane::before {
    content: "";
    position: absolute;
    inset: 0;
    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.45' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.42  0 0 0 0 0.48  0 0 0 0 0.54  0 0 0 1 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
    background-size: 240px 240px;
    opacity: 0.18;
    pointer-events: none;
    mix-blend-mode: multiply;
    transition: opacity 0.9s ease-out;
}

/* mid noise panel */
.noise-panel {
    position: relative;
    grid-column: 9 / span 3;
    grid-row: 1;
    z-index: 2;
    min-height: 60vh;
    transform: translateZ(-20px);
    opacity: 0.42;
    transition: opacity 1.2s ease-out, transform 1s ease-out;
    border: 1px solid rgba(91, 74, 58, 0.18);
    background-color: rgba(196, 89, 42, 0.03);
}

.noise-panel--warm {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='260' height='260'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.3' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.77  0 0 0 0 0.45  0 0 0 0 0.16  0 0 0 1 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
    background-size: 260px 260px;
}

.noise-panel--cool {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='260' height='260'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.42  0 0 0 0 0.48  0 0 0 0 0.54  0 0 0 1 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
    background-size: 260px 260px;
}

.noise-panel--mixed {
    background-image:
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='260' height='260'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='1.4' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.18  0 0 0 0 0.14  0 0 0 0 0.09  0 0 0 1 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>"),
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='260' height='260'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.3' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.77  0 0 0 0 0.45  0 0 0 0 0.16  0 0 0 1 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
    background-size: 260px 260px, 260px 260px;
    background-blend-mode: multiply;
}

/* ---- typographic primitives ---- */
.kicker {
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--burnt-sienna);
    margin-bottom: 18px;
}

.kicker--cool {
    color: var(--tarnished-chrome);
}

.spear-headline {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(40px, 6.4vw, 92px);
    line-height: 0.92;
    letter-spacing: 0.04em;
    color: var(--burnt-sienna);
    text-transform: uppercase;
    margin-bottom: 28px;
}

[data-temper="cool"] .spear-headline {
    color: var(--dark-loam);
}

.shield-headline {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(36px, 5.6vw, 80px);
    line-height: 0.94;
    letter-spacing: 0.03em;
    color: var(--tarnished-chrome);
    text-transform: lowercase;
    margin-bottom: 24px;
    mix-blend-mode: multiply;
}

.spear-body {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(15px, 1.05vw, 18px);
    line-height: 1.55;
    color: var(--weathered-wood);
    max-width: 56ch;
    letter-spacing: 0.01em;
    margin-bottom: 16px;
}

.shield-body {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(14px, 1vw, 17px);
    line-height: 1.55;
    color: var(--tarnished-chrome);
    max-width: 56ch;
    letter-spacing: 0.01em;
    margin-bottom: 16px;
}

.spear-tag,
.shield-tag {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--sandstone);
    letter-spacing: 0.06em;
    opacity: 0.75;
}

.shield-tag {
    color: var(--tarnished-chrome);
}

/* meta line per section */
.meta-line {
    grid-column: 2 / span 10;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--sandstone);
    opacity: 0.7;
    letter-spacing: 0.04em;
    margin-top: clamp(20px, 4vh, 64px);
    border-top: 1px dashed rgba(160, 135, 110, 0.4);
    padding-top: 14px;
    z-index: 4;
    position: relative;
}

.section-index {
    position: absolute;
    top: clamp(24px, 4vh, 48px);
    left: clamp(24px, 6vw, 96px);
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    color: var(--dry-clay);
    z-index: 5;
}

/* ---- section 1: paradox gate ---- */
.gate-layer {
    grid-template-columns: 1fr;
    place-items: center;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.gate-noise {
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='320' height='320'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.3' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.77  0 0 0 0 0.45  0 0 0 0 0.16  0 0 0 1 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
    background-size: 320px 320px;
    opacity: 0.22;
    z-index: 0;
    mix-blend-mode: multiply;
}

.gate-frame {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(16px, 3vh, 36px);
    padding: clamp(24px, 6vh, 64px) clamp(16px, 5vw, 80px);
    border: 1px solid rgba(91, 74, 58, 0.18);
    background: rgba(242, 234, 224, 0.55);
    backdrop-filter: blur(0.4px);
    clip-path: polygon(
        0.6% 0%,
        99% 0.4%,
        100% 99.2%,
        0.4% 100%,
        0% 0.8%
    );
    max-width: min(1100px, 92vw);
    width: 100%;
}

.gate-meta {
    display: flex;
    gap: clamp(16px, 3vw, 40px);
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    width: 100%;
}

.gate-meta--top {
    border-bottom: 1px dashed rgba(91, 74, 58, 0.25);
    padding-bottom: 14px;
}

.gate-meta--bottom {
    border-top: 1px dashed rgba(91, 74, 58, 0.25);
    padding-top: 14px;
}

.meta-tag {
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--dry-clay);
    opacity: 0.8;
}

.gate-kanji {
    font-family: var(--font-cjk);
    font-weight: 700;
    font-size: clamp(120px, 28vw, 320px);
    line-height: 0.88;
    letter-spacing: 0.04em;
    color: var(--dark-loam);
    display: inline-flex;
    gap: clamp(8px, 1.5vw, 24px);
    margin: clamp(8px, 2vh, 24px) 0;
}

.kanji-char {
    display: inline-block;
    color: var(--dark-loam);
    animation: micro-shake 0.15s steps(1) infinite;
    text-shadow:
        0.3px 0 0 rgba(196, 89, 42, 0.55),
        -0.3px 0 0 rgba(45, 107, 90, 0.35);
    will-change: transform;
}

.kanji-char[data-char="盾"] {
    animation-duration: 0.17s;
    animation-delay: 0.08s;
    color: var(--burnt-sienna);
    text-shadow:
        0.3px 0 0 rgba(59, 47, 32, 0.6),
        -0.3px 0 0 rgba(107, 123, 138, 0.4);
}

.gate-translit {
    font-family: var(--font-mono);
    font-size: 14px;
    letter-spacing: 0.5em;
    color: var(--burnt-sienna);
    text-transform: lowercase;
}

.gate-subtitle {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: clamp(15px, 1.6vw, 22px);
    color: var(--weathered-wood);
    letter-spacing: 0.04em;
    max-width: 50ch;
    line-height: 1.4;
}

/* corners on gate + unresolved */
.gate-corner {
    position: absolute;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.22em;
    color: var(--dry-clay);
    text-transform: uppercase;
    opacity: 0.85;
    z-index: 4;
    padding: clamp(20px, 3vh, 36px) clamp(20px, 4vw, 56px);
}

.gate-corner--tl { top: 0; left: 0; }
.gate-corner--tr { top: 0; right: 0; text-align: right; }
.gate-corner--bl { bottom: 0; left: 0; }
.gate-corner--br { bottom: 0; right: 0; text-align: right; }

/* ---- section 6: unresolved ---- */
.unresolved-layer {
    grid-template-columns: 1fr;
    place-items: center;
    text-align: center;
    position: relative;
    overflow: hidden;
    background: var(--kiln-white);
}

.unresolved-noise {
    position: absolute;
    inset: 0;
    background-image:
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='420' height='420'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.36  0 0 0 0 0.29  0 0 0 0 0.13  0 0 0 1 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>"),
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='420' height='420'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.3' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.77  0 0 0 0 0.45  0 0 0 0 0.16  0 0 0 1 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
    background-size: 420px 420px, 420px 420px;
    background-blend-mode: multiply;
    opacity: 0.55;
    z-index: 0;
}

.unresolved-frame {
    position: relative;
    z-index: 2;
    max-width: 720px;
    padding: clamp(24px, 5vh, 64px);
}

.unresolved-quiet {
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 1.6s ease-out, transform 1.6s ease-out;
    display: inline-flex;
    flex-direction: column;
    gap: 12px;
}

.unresolved-quiet.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.unresolved-line {
    font-family: var(--font-cjk);
    font-weight: 500;
    font-size: clamp(20px, 2.4vw, 32px);
    color: var(--dark-loam);
    letter-spacing: 0.06em;
    line-height: 1.4;
}

.unresolved-line:nth-child(2) {
    color: var(--burnt-sienna);
}

.unresolved-translation {
    font-family: var(--font-body);
    font-style: italic;
    font-size: clamp(13px, 1vw, 16px);
    color: var(--weathered-wood);
    margin-top: 18px;
    letter-spacing: 0.04em;
}

/* ---- depth indicator ---- */
.descent-indicator {
    position: fixed;
    right: clamp(12px, 2.4vw, 32px);
    top: 50%;
    transform: translateY(-50%);
    z-index: 90;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    pointer-events: none;
    mix-blend-mode: multiply;
}

.descent-bar {
    position: relative;
    width: 2px;
    height: 220px;
    background: rgba(91, 74, 58, 0.18);
    overflow: hidden;
}

.descent-fill {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 0%;
    background: var(--burnt-sienna);
    transition: height 0.5s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.descent-label {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.22em;
    color: var(--dry-clay);
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    text-transform: uppercase;
}

/* ---- in-view & contradiction states (script.js toggles these) ---- */
.contradiction-layer.is-active .spear-plane {
    transform: translateZ(0) translateY(0);
}

.contradiction-layer.is-active .shield-plane {
    transform: translateZ(-40px) translateY(-15px);
    opacity: 0.5;
}

.contradiction-layer.is-active .noise-panel {
    opacity: 0.62;
}

.contradiction-layer.is-active .shield-plane::before {
    opacity: 0.28;
}

.contradiction-layer.is-inverted .spear-plane {
    transform: translateZ(-30px) translateY(8px);
    opacity: 0.55;
}

.contradiction-layer.is-inverted .shield-plane {
    transform: translateZ(0) translateY(-22px);
    opacity: 1;
}

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

.contradiction-layer.is-shaking .spear-plane,
.contradiction-layer.is-shaking .shield-plane {
    animation: shake-error 0.4s ease-out 1;
}

/* ---- micro-shake for hero kanji ---- */
@keyframes micro-shake {
    0%   { transform: translate(0, 0); }
    20%  { transform: translate(0.4px, -0.3px); }
    40%  { transform: translate(-0.3px, 0.4px); }
    60%  { transform: translate(0.3px, 0.2px); }
    80%  { transform: translate(-0.4px, -0.4px); }
    100% { transform: translate(0, 0); }
}

/* ---- responsive: tablet ---- */
@media (max-width: 1024px) {
    .contradiction-layer {
        padding: clamp(40px, 8vh, 96px) clamp(20px, 5vw, 64px);
    }

    .spear-plane {
        grid-column: 2 / span 9;
    }

    .shield-plane {
        grid-column: 4 / span 9;
        transform: translateZ(-20px) translateY(0);
    }

    .contradiction-layer.is-active .shield-plane {
        transform: translateZ(-20px) translateY(-12px);
    }

    .noise-panel {
        grid-column: 10 / span 3;
        min-height: 40vh;
    }
}

/* ---- responsive: mobile ---- */
@media (max-width: 768px) {
    .contradiction-layer {
        grid-template-columns: 1fr;
        padding: clamp(48px, 10vh, 96px) clamp(18px, 5vw, 28px);
        min-height: auto;
    }

    .contradiction-layer:first-child,
    .contradiction-layer:last-child {
        min-height: 100vh;
    }

    .spear-plane,
    .shield-plane {
        position: relative;
        grid-column: 1;
        grid-row: auto;
        transform: none !important;
        opacity: 1;
        max-width: 100%;
        clip-path: none;
        padding: 18px 4px;
    }

    .shield-plane {
        opacity: 0.85;
        margin-top: 24px;
        padding-top: 32px;
        border-top: 1px solid rgba(91, 74, 58, 0.18);
        position: relative;
    }

    .shield-plane::after {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 40px;
        background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='40'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.42  0 0 0 0 0.48  0 0 0 0 0.54  0 0 0 1 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
        background-size: 120px 40px;
        opacity: 0.5;
        transform: translateY(-100%);
    }

    .noise-panel {
        grid-column: 1;
        grid-row: auto;
        min-height: 80px;
        margin: 16px 0;
        transform: none;
        opacity: 0.55;
    }

    .spear-headline,
    .shield-headline {
        font-size: clamp(34px, 9vw, 56px);
    }

    .gate-kanji {
        font-size: clamp(96px, 36vw, 200px);
    }

    .descent-indicator {
        right: 8px;
    }

    .descent-bar {
        height: 140px;
    }

    .meta-line {
        grid-column: 1;
    }
}

/* ---- reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
    .kanji-char {
        animation: none;
    }

    .contradiction-layer.is-shaking .spear-plane,
    .contradiction-layer.is-shaking .shield-plane {
        animation: none;
    }

    .spear-plane,
    .shield-plane,
    .noise-panel {
        transition-duration: 0.001s;
    }
}
