/* ============================================
   kaigenrei.com - Styles
   Grainy-textured pastoral glitch aesthetic
   ============================================ */

/* ---- CSS Custom Properties ---- */
:root {
    --aged-linen: #e8ddd0;
    --dark-loam: #2c2418;
    --ochre-gold: #b8860b;
    --moss-sage: #7a8b6f;
    --faded-terracotta: #b07558;
    --glitch-cyan: #00d4aa;
    --glitch-magenta: #d4007a;
    --raw-canvas: #d4c4a0;

    --font-display: 'Caveat', cursive;
    --font-body: 'Lora', serif;
    --font-scrawl: 'Homemade Apple', cursive;

    --content-max: 680px;
    --content-padding: clamp(1.5rem, 5vw, 3rem);
}

/* ---- Reset ---- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--aged-linen);
    color: var(--dark-loam);
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1rem, 2.2vw, 1.15rem);
    line-height: 1.75;
    letter-spacing: 0.01em;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ---- Grain Overlay ---- */
#grain-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.06;
    filter: url(#grain-filter);
    background: var(--aged-linen);
}

/* ---- Glitch Body Effect ---- */
body.glitch-event {
    animation: bodyGlitch 150ms steps(3) forwards;
}

@keyframes bodyGlitch {
    0% {
        transform: translateX(-4px);
        box-shadow: 4px 0 0 var(--glitch-cyan);
    }
    40% {
        transform: translateX(4px);
        box-shadow: -4px 0 0 var(--glitch-magenta);
    }
    100% {
        transform: translateX(0);
        box-shadow: none;
    }
}

/* ============================================
   HERO: THE GRAIN FIELD
   ============================================ */
#hero {
    position: relative;
    width: 100%;
    height: 100vh;
    display: grid;
    place-items: center;
    background-color: var(--aged-linen);
    overflow: hidden;
}

.hero-content {
    text-align: center;
    z-index: 1;
}

/* Hero Title - Letter by Letter */
#hero-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(3rem, 8vw, 6rem);
    letter-spacing: 0.02em;
    line-height: 1.3;
    color: var(--dark-loam);
    margin-bottom: 1.5rem;
}

#hero-title .letter {
    display: inline-block;
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 120ms ease-out, transform 120ms ease-out;
}

#hero-title .letter.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Hero Subtitle */
#hero-subtitle {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(0.9rem, 2vw, 1.1rem);
    line-height: 1.75;
    color: var(--dark-loam);
    opacity: 0;
    transition: opacity 600ms ease-out;
    margin-bottom: 2.5rem;
}

#hero-subtitle.visible {
    opacity: 1;
}

/* Hero Arrow */
#hero-arrow {
    opacity: 0;
    transition: opacity 400ms ease-out;
    animation: arrowBounce 2s ease-in-out infinite;
    animation-play-state: paused;
}

#hero-arrow.visible {
    opacity: 1;
    animation-play-state: running;
}

@keyframes arrowBounce {
    0%, 100% { transform: translateY(3px); }
    50% { transform: translateY(-3px); }
}

/* Hero Sentinel */
#hero-sentinel {
    position: absolute;
    bottom: 15vh;
    left: 0;
    width: 100%;
    height: 1px;
    pointer-events: none;
}

/* ============================================
   MARGINALIA ANCHORS
   ============================================ */
#marginalia {
    position: fixed;
    left: 30px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    opacity: 0;
    transition: opacity 600ms ease;
    pointer-events: none;
}

#marginalia.visible {
    opacity: 1;
    pointer-events: auto;
}

.marginalia-anchor {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-decoration: none;
    transform: rotate(var(--rot, -5deg));
    transition: transform 300ms cubic-bezier(0.34, 1.56, 0.64, 1), color 250ms ease;
    cursor: pointer;
}

.marginalia-text {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.75rem;
    color: var(--moss-sage);
    letter-spacing: 0.02em;
    line-height: 1.3;
    transition: color 250ms ease;
}

.marginalia-underline {
    opacity: 0;
    transition: opacity 400ms ease-out;
    margin-top: 2px;
}

.marginalia-underline path {
    stroke-dasharray: 80;
    stroke-dashoffset: 80;
    transition: stroke-dashoffset 400ms ease-out;
}

.marginalia-anchor:hover {
    transform: rotate(0deg);
}

.marginalia-anchor:hover .marginalia-text {
    color: var(--ochre-gold);
}

.marginalia-anchor:hover .marginalia-underline {
    opacity: 1;
}

.marginalia-anchor:hover .marginalia-underline path {
    stroke-dashoffset: 0;
}

/* Hide marginalia on narrow viewports */
@media (max-width: 900px) {
    #marginalia {
        display: none;
    }
}

/* ============================================
   PARCHMENT SPINE (Content Zone)
   ============================================ */
#parchment-spine {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 4rem var(--content-padding) 2rem;
    position: relative;
}

/* ---- Content Sections ---- */
.content-section {
    position: relative;
    margin-bottom: 3rem;
}

.section-inner {
    position: relative;
}

.section-heading {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.8rem, 4vw, 2.8rem);
    letter-spacing: 0.02em;
    line-height: 1.3;
    color: var(--dark-loam);
    margin-bottom: 1.2rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 500ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 500ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.section-heading.revealed {
    opacity: 1;
    transform: translateY(0);
}

/* Flash gold on scroll-to */
.section-heading.flash-gold {
    color: var(--ochre-gold);
    transition: color 0ms;
}

.section-heading.flash-gold-settle {
    color: var(--dark-loam);
    transition: color 600ms ease;
}

.body-text {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1rem, 2.2vw, 1.15rem);
    line-height: 1.75;
    letter-spacing: 0.01em;
    color: var(--dark-loam);
    margin-bottom: 1.2rem;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 400ms ease, transform 400ms ease;
}

.body-text.revealed {
    opacity: 1;
    transform: translateY(0);
}

.body-text em {
    font-style: italic;
}

/* ---- Pencil Scrawl Annotations ---- */
.pencil-scrawl {
    font-family: var(--font-scrawl);
    font-weight: 400;
    font-size: 0.75rem;
    color: var(--faded-terracotta);
    display: block;
    margin-top: 1rem;
    opacity: 0;
    transition: opacity 400ms ease;
}

.pencil-scrawl.revealed {
    opacity: 1;
}

.annotation {
    text-align: right;
    padding-right: 1rem;
}

/* ---- Pressed Flowers ---- */
.pressed-flower {
    position: absolute;
    top: var(--pf-top, 20px);
    right: var(--pf-right, -30px);
    transform: rotate(var(--pf-rot, 5deg));
    opacity: 0.6;
    pointer-events: none;
}

@media (max-width: 800px) {
    .pressed-flower {
        display: none;
    }
}

/* ============================================
   BOTANICAL DIVIDERS
   ============================================ */
.botanical-divider {
    text-align: center;
    margin: 2.5rem auto;
    max-width: 300px;
}

.botanical-svg {
    width: 100%;
    height: auto;
    overflow: visible;
}

.draw-path {
    stroke-dasharray: var(--path-length, 300);
    stroke-dashoffset: var(--path-length, 300);
    transition: stroke-dashoffset 1200ms ease-in-out;
}

.draw-path.drawn {
    stroke-dashoffset: 0;
}

/* ---- Pressed Flower Dividers ---- */
.pressed-flower-divider {
    text-align: center;
    margin: 2rem auto;
}

/* ============================================
   GLITCH BANDS
   ============================================ */
.glitch-band {
    position: relative;
    width: 100vw;
    margin-left: calc(-50vw + 50%);
    height: 8px;
    margin-top: 2rem;
    margin-bottom: 2rem;
    overflow: hidden;
}

.glitch-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    mix-blend-mode: screen;
}

.glitch-cyan {
    background-color: var(--glitch-cyan);
    opacity: 0.6;
    transform: translateX(-3px);
}

.glitch-center {
    background-color: var(--dark-loam);
    opacity: 1;
    mix-blend-mode: normal;
}

.glitch-magenta {
    background-color: var(--glitch-magenta);
    opacity: 0.6;
    transform: translateX(3px);
}

/* Active glitch tear animation */
.glitch-band[data-active="true"] .glitch-cyan.tearing {
    animation: glitchTearCyan 200ms steps(2) forwards;
}

.glitch-band[data-active="true"] .glitch-magenta.tearing {
    animation: glitchTearMagenta 200ms steps(2) forwards;
}

.glitch-band[data-active="true"] .glitch-center.tearing {
    animation: glitchTearCenter 200ms steps(2) forwards;
}

@keyframes glitchTearCyan {
    0% { transform: translateX(-3px); }
    50% { transform: translateX(var(--tear-x-cyan, -6px)); }
    100% { transform: translateX(-3px); }
}

@keyframes glitchTearMagenta {
    0% { transform: translateX(3px); }
    50% { transform: translateX(var(--tear-x-magenta, 6px)); }
    100% { transform: translateX(3px); }
}

@keyframes glitchTearCenter {
    0% { transform: translateX(0); }
    50% { transform: translateX(var(--tear-x-center, 2px)); }
    100% { transform: translateX(0); }
}

/* Varying glitch band heights */
.glitch-band:nth-child(odd) {
    height: 6px;
}

.glitch-band:nth-child(3n) {
    height: 10px;
}

.glitch-band:nth-child(5n) {
    height: 4px;
}

/* ============================================
   TORN EDGE FOOTER
   ============================================ */
#torn-edge-sentinel {
    height: 1px;
    pointer-events: none;
}

#torn-footer {
    position: relative;
    width: 100%;
    overflow: hidden;
}

.torn-edge-top {
    position: relative;
    width: 100%;
    height: 30px;
    background-color: var(--aged-linen);
    clip-path: polygon(
        0% 0%,
        100% 0%,
        100% 40%,
        98% 52%,
        96% 45%,
        94% 58%,
        92% 48%,
        90% 62%,
        88% 50%,
        86% 55%,
        84% 42%,
        82% 60%,
        80% 48%,
        78% 65%,
        76% 52%,
        74% 45%,
        72% 58%,
        70% 50%,
        68% 42%,
        66% 55%,
        64% 48%,
        62% 62%,
        60% 50%,
        58% 58%,
        56% 44%,
        54% 55%,
        52% 48%,
        50% 60%,
        48% 45%,
        46% 55%,
        44% 50%,
        42% 62%,
        40% 48%,
        38% 56%,
        36% 42%,
        34% 58%,
        32% 50%,
        30% 45%,
        28% 60%,
        26% 48%,
        24% 55%,
        22% 42%,
        20% 58%,
        18% 50%,
        16% 62%,
        14% 45%,
        12% 55%,
        10% 48%,
        8% 60%,
        6% 50%,
        4% 42%,
        2% 55%,
        0% 48%
    );
    z-index: 2;
}

.footer-canvas {
    position: relative;
    background-color: var(--raw-canvas);
    min-height: 200px;
    padding: 3rem var(--content-padding);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Glitch Confetti */
.confetti-piece {
    position: absolute;
    width: 5px;
    height: 20px;
    background-color: var(--cc, var(--glitch-cyan));
    opacity: 0;
    left: var(--cx, 50%);
    top: var(--cy, 50%);
    transform: translateY(-30px) rotate(var(--cr, 0deg));
    transition: opacity 600ms ease, transform 600ms ease;
}

.confetti-piece.fallen {
    opacity: 0.4;
    transform: translateY(0) rotate(var(--cr, 0deg));
}

/* Farewell Scrawl */
#farewell-scrawl {
    font-family: var(--font-scrawl);
    font-weight: 400;
    font-size: 0.85rem;
    color: var(--dark-loam);
    opacity: 0;
    transition: opacity 800ms ease;
    text-align: center;
    position: relative;
    z-index: 3;
}

#farewell-scrawl.visible {
    opacity: 1;
}

/* ============================================
   SELECTION STYLES
   ============================================ */
::selection {
    background-color: var(--ochre-gold);
    color: var(--aged-linen);
}

/* ============================================
   LINKS
   ============================================ */
a {
    color: var(--ochre-gold);
    text-decoration: none;
    transition: color 250ms ease;
}

a:hover {
    color: var(--faded-terracotta);
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */
@media (max-width: 600px) {
    #parchment-spine {
        padding: 3rem 1.2rem 2rem;
    }

    .botanical-divider {
        max-width: 220px;
    }

    .glitch-band {
        height: 6px;
    }

    .footer-canvas {
        min-height: 160px;
    }
}
