/* ==========================================================================
   riron.org -- Theory as Dopamine
   Aesthetic: dopamine | Layout: diagonal-sections | Typography: slab-serif
   Palette: midnight-blue | Patterns: parallax | Imagery: glassmorphic-cards
   Motifs: candle-atmospheric | Tone: approachable-casual
   Fonts: Zilla Slab, Nunito, Fira Code (Google Fonts)
   ========================================================================== */

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

html {
    scroll-behavior: smooth;
    background: #050A18;
}

body {
    font-family: "Nunito", system-ui, -apple-system, sans-serif;
    font-weight: 400;
    font-size: clamp(16px, 1.5vw, 18px);
    line-height: 1.8;
    color: #CBD5E1;
    background: #0F172A;
    overflow-x: hidden;
    min-height: 100vh;
    /* Subtle grain to push the late-night-desk feel */
    background-image:
        radial-gradient(1px 1px at 20% 30%, rgba(212, 160, 64, 0.04) 0%, transparent 50%),
        radial-gradient(1px 1px at 80% 70%, rgba(59, 130, 246, 0.04) 0%, transparent 50%);
    background-attachment: fixed;
}

::selection {
    background: rgba(245, 158, 11, 0.35);
    color: #FFFFFF;
}

/* ---------- CSS variables ---------- */
:root {
    --c-midnight-core: #0F172A;
    --c-deep-layer: #050A18;
    --c-shade-mid: #1E293B;
    --c-theory-blue: #3B82F6;
    --c-dopamine-amber: #F59E0B;
    --c-candle-warm: #D4A040;
    --c-star-silver: #CBD5E1;
    --c-glass: rgba(255, 255, 255, 0.08);
    --c-glass-border: rgba(255, 255, 255, 0.12);
    --c-glass-strong: rgba(255, 255, 255, 0.14);

    --diag-cut: 5vw;
    --section-pad-y: clamp(96px, 14vw, 180px);
    --container-max: 1180px;

    --ease-soft: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---------- Headlines ---------- */
h1, h2, h3 {
    font-family: "Zilla Slab", Georgia, serif;
    font-weight: 700;
    line-height: 1.15;
    color: #F1F5F9;
    letter-spacing: -0.01em;
}

h1 { font-size: clamp(40px, 6vw, 72px); }
h2 { font-size: clamp(28px, 4.5vw, 56px); }
h3 { font-size: clamp(22px, 2.4vw, 30px); }

p {
    color: var(--c-star-silver);
}

code, .theory-equation {
    font-family: "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace;
    font-weight: 400;
    font-size: 14px;
}

.amber-highlight {
    color: var(--c-dopamine-amber);
    font-weight: 600;
    /* Subtle reward-glow on the key insight */
    text-shadow:
        0 0 18px rgba(245, 158, 11, 0.35),
        0 0 1px rgba(245, 158, 11, 0.6);
}

/* ==========================================================================
   Diagonal sections
   ========================================================================== */
.diagonal-section {
    position: relative;
    padding: var(--section-pad-y) 6vw;
    overflow: hidden;
    isolation: isolate;
    /* Diagonal cut top + bottom; sections overlap by var(--diag-cut)
       so seams disappear between alternating shades */
    clip-path: polygon(
        0 0,
        100% var(--diag-cut),
        100% 100%,
        0 calc(100% - var(--diag-cut))
    );
    margin-top: calc(-1 * var(--diag-cut));
}

/* First section has a flat top */
.diagonal-section.hero-section {
    clip-path: polygon(
        0 0,
        100% 0,
        100% 100%,
        0 calc(100% - var(--diag-cut))
    );
    margin-top: 0;
}

/* Last section has a flat bottom */
.diagonal-section.footer-section {
    clip-path: polygon(
        0 0,
        100% var(--diag-cut),
        100% 100%,
        0 100%
    );
}

/* Alternating midnight shades per spec */
.shade-deep    { background: var(--c-midnight-core); }   /* #0F172A */
.shade-mid     { background: var(--c-shade-mid); }       /* #1E293B */
.shade-deepest { background: var(--c-deep-layer); }      /* #050A18 */

/* Hero uses midnight core */
.hero-section { background: var(--c-midnight-core); }

.section-inner {
    position: relative;
    max-width: var(--container-max);
    margin: 0 auto;
    z-index: 2;
}

/* ==========================================================================
   Candle-atmospheric glow points
   ========================================================================== */
.parallax-layer {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
}

.candle-glow {
    position: absolute;
    left: var(--gx, 50%);
    top: var(--gy, 50%);
    transform: translate(-50%, -50%);
    width: 360px;
    height: 360px;
    border-radius: 50%;
    background: radial-gradient(
        circle at center,
        rgba(212, 160, 64, 0.22) 0%,
        rgba(212, 160, 64, 0.10) 35%,
        rgba(212, 160, 64, 0.0) 70%
    );
    filter: blur(8px);
    opacity: 0;
    will-change: opacity, transform;
    animation: candle-flicker 5.6s ease-in-out infinite;
}

/* Slight per-glow timing variations so they breathe out of phase */
.glow-h1 { animation-delay: 0s;   }
.glow-h2 { animation-delay: 0.4s; }
.glow-h3 { animation-delay: 0.9s; }
.glow-h4 { animation-delay: 1.4s; }
.glow-h5 { animation-delay: 1.9s; }
.glow-tl, .glow-tr { animation-delay: 0.6s; }
.glow-bl, .glow-br { animation-delay: 1.2s; }
.glow-center      { animation-delay: 0.2s; width: 520px; height: 520px; }
.glow-corner-a    { animation-delay: 1.0s; }
.glow-corner-b    { animation-delay: 1.7s; }
.glow-desk-a, .glow-desk-b, .glow-desk-c { animation-delay: 0.8s; }

@keyframes candle-flicker {
    0%, 100% { opacity: 0.85; transform: translate(-50%, -50%) scale(1); }
    25%      { opacity: 1.00; transform: translate(-50%, -50%) scale(1.04); }
    50%      { opacity: 0.78; transform: translate(-50%, -50%) scale(0.98); }
    75%      { opacity: 0.92; transform: translate(-50%, -50%) scale(1.02); }
}

/* ==========================================================================
   Glassmorphic cards
   ========================================================================== */
.glass-card {
    position: relative;
    background: var(--c-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--c-glass-border);
    border-radius: 20px;
    padding: clamp(28px, 4vw, 56px);
    box-shadow:
        0 30px 60px -20px rgba(5, 10, 24, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.glass-card::before {
    /* Soft top-edge specular -- glass sheen */
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.06) 0%,
        rgba(255, 255, 255, 0.0) 30%
    );
    pointer-events: none;
}

/* Reveal-on-scroll baseline */
.reveal {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s var(--ease-soft), transform 0.5s var(--ease-soft);
}

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

/* Stagger children inside the insight grid */
.insight-grid .reveal { transition-delay: 0s; }
.insight-grid .reveal.is-visible:nth-child(1) { transition-delay: 0ms;   }
.insight-grid .reveal.is-visible:nth-child(2) { transition-delay: 150ms; }
.insight-grid .reveal.is-visible:nth-child(3) { transition-delay: 300ms; }
.insight-grid .reveal.is-visible:nth-child(4) { transition-delay: 450ms; }
.insight-grid .reveal.is-visible:nth-child(5) { transition-delay: 600ms; }
.insight-grid .reveal.is-visible:nth-child(6) { transition-delay: 750ms; }

/* ==========================================================================
   Hero ("Dopamine Hit")
   ========================================================================== */
.hero-section {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: clamp(64px, 10vw, 120px);
    padding-bottom: clamp(120px, 18vw, 220px);
}

.hero-content {
    position: relative;
    z-index: 2;
    width: min(var(--container-max), 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(40px, 6vw, 72px);
}

.hero-card {
    text-align: center;
    padding: clamp(40px, 6vw, 80px) clamp(28px, 6vw, 96px);
    /* Hero card scales in from 0.95 -> 1.0 on load */
    opacity: 0;
    transform: scale(0.95);
    animation: hero-pop 0.6s var(--ease-out) 0.25s forwards;
    max-width: 720px;
}

@keyframes hero-pop {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1); }
}

.kanji-mark {
    display: inline-block;
    font-family: "Zilla Slab", serif;
    font-size: clamp(56px, 8vw, 96px);
    font-weight: 700;
    line-height: 1;
    color: var(--c-theory-blue);
    margin-bottom: 14px;
    text-shadow:
        0 0 24px rgba(59, 130, 246, 0.5),
        0 0 60px rgba(59, 130, 246, 0.2);
    opacity: 0;
    animation: fade-up 0.7s var(--ease-out) 0.55s forwards;
}

.wordmark {
    font-family: "Zilla Slab", Georgia, serif;
    font-weight: 700;
    font-size: clamp(40px, 6.5vw, 80px);
    color: #F8FAFC;
    letter-spacing: -0.02em;
    margin-bottom: 18px;
    opacity: 0;
    animation: fade-up 0.7s var(--ease-out) 0.7s forwards;
}

.hero-tagline {
    font-size: clamp(17px, 1.7vw, 21px);
    color: var(--c-star-silver);
    line-height: 1.65;
    opacity: 0;
    animation: fade-up 0.7s var(--ease-out) 0.9s forwards;
}

@keyframes fade-up {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.scroll-cue {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    opacity: 0;
    animation: fade-up 0.7s var(--ease-out) 1.3s forwards;
}

.cue-line {
    width: 1px;
    height: 56px;
    background: linear-gradient(
        180deg,
        rgba(203, 213, 225, 0) 0%,
        rgba(203, 213, 225, 0.7) 50%,
        rgba(245, 158, 11, 0.8) 100%
    );
    animation: cue-pulse 2.4s ease-in-out infinite;
}

@keyframes cue-pulse {
    0%, 100% { transform: scaleY(1); opacity: 0.6; }
    50%      { transform: scaleY(1.15); opacity: 1; }
}

.cue-label {
    font-family: "Fira Code", monospace;
    font-size: 11px;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    color: rgba(203, 213, 225, 0.65);
}

/* ==========================================================================
   Theory sections
   ========================================================================== */
.theory-section {
    display: flex;
    align-items: center;
    min-height: 90vh;
}

.theory-card {
    max-width: 720px;
    margin: 0 auto 0 0;
}

.theory-card.align-right {
    margin: 0 0 0 auto;
    text-align: left;
}

.theory-index {
    display: inline-block;
    font-family: "Fira Code", monospace;
    font-size: 13px;
    letter-spacing: 0.25em;
    color: var(--c-theory-blue);
    margin-bottom: 14px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(59, 130, 246, 0.10);
    border: 1px solid rgba(59, 130, 246, 0.25);
}

.theory-title {
    margin-bottom: 18px;
}

.theory-body {
    font-size: clamp(17px, 1.6vw, 19px);
    line-height: 1.85;
    margin-bottom: 26px;
}

.theory-equation {
    display: inline-block;
    padding: 10px 14px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(59, 130, 246, 0.25);
    border-radius: 10px;
    color: #DBEAFE;
    letter-spacing: 0.02em;
}

/* ==========================================================================
   Insight wall
   ========================================================================== */
.insight-section {
    padding-top: calc(var(--section-pad-y) + 20px);
    padding-bottom: calc(var(--section-pad-y) + 20px);
}

.wall-heading {
    text-align: center;
    max-width: 720px;
    margin: 0 auto clamp(48px, 6vw, 80px);
}

.wall-eyebrow {
    font-family: "Fira Code", monospace;
    font-size: 12px;
    letter-spacing: 0.32em;
    text-transform: uppercase;
    color: var(--c-theory-blue);
    margin-bottom: 14px;
}

.wall-title {
    margin-bottom: 18px;
}

.wall-sub {
    font-size: clamp(16px, 1.4vw, 18px);
    color: rgba(203, 213, 225, 0.78);
}

.insight-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: clamp(20px, 2.4vw, 32px);
    /* Staggered grid feel: shift even-indexed cards down a touch */
}

.insight-grid > .insight-card:nth-child(even) {
    transform: translateY(28px);
}

.insight-grid > .insight-card:nth-child(even).reveal {
    transform: translateY(48px);
}

.insight-grid > .insight-card:nth-child(even).reveal.is-visible {
    transform: translateY(28px);
}

.insight-card {
    padding: clamp(24px, 2.6vw, 36px);
    transition: transform 0.45s var(--ease-soft), background 0.3s ease, border-color 0.3s ease;
}

.insight-card:hover {
    background: var(--c-glass-strong);
    border-color: rgba(245, 158, 11, 0.35);
}

.insight-title {
    margin-bottom: 12px;
    color: #F8FAFC;
}

.insight-body {
    font-size: 16px;
    line-height: 1.75;
    color: rgba(203, 213, 225, 0.92);
}

/* ==========================================================================
   Night Desk Footer
   ========================================================================== */
.footer-section {
    min-height: 70vh;
    display: flex;
    align-items: center;
    background: var(--c-deep-layer);
}

.footer-card {
    max-width: 720px;
    margin: 0 auto;
    text-align: center;
    padding: clamp(40px, 5vw, 72px);
}

.footer-eyebrow {
    font-family: "Fira Code", monospace;
    font-size: 12px;
    letter-spacing: 0.32em;
    text-transform: uppercase;
    color: var(--c-candle-warm);
    margin-bottom: 22px;
}

.footer-quote {
    font-family: "Zilla Slab", serif;
    font-weight: 700;
    font-size: clamp(22px, 2.6vw, 32px);
    line-height: 1.4;
    color: #F1F5F9;
    margin-bottom: 32px;
}

.footer-meta {
    display: inline-flex;
    align-items: baseline;
    gap: 14px;
    padding-top: 18px;
    border-top: 1px solid rgba(255, 255, 255, 0.10);
}

.footer-mark {
    font-family: "Zilla Slab", serif;
    font-size: 28px;
    color: var(--c-theory-blue);
    text-shadow: 0 0 18px rgba(59, 130, 246, 0.35);
}

.footer-domain {
    font-family: "Fira Code", monospace;
    font-size: 13px;
    color: rgba(203, 213, 225, 0.7);
    letter-spacing: 0.18em;
}

/* ==========================================================================
   Parallax (driven by --scroll set from JS)
   ========================================================================== */
.parallax-slow {
    /* Background candle layers move at 60% speed -> 40% offset of section */
    transform: translate3d(0, calc(var(--scroll, 0px) * -0.4), 0);
    transition: transform 80ms linear;
}

/* ==========================================================================
   Responsive tweaks
   ========================================================================== */
@media (max-width: 720px) {
    :root {
        --diag-cut: 4vw;
        --section-pad-y: clamp(72px, 18vw, 130px);
    }

    .candle-glow {
        width: 240px;
        height: 240px;
    }

    .theory-card,
    .theory-card.align-right {
        margin: 0 auto;
    }

    .insight-grid > .insight-card:nth-child(even),
    .insight-grid > .insight-card:nth-child(even).reveal,
    .insight-grid > .insight-card:nth-child(even).reveal.is-visible {
        transform: translateY(0);
    }
}

/* Reduce-motion fallback (still allow opacity reveals) */
@media (prefers-reduced-motion: reduce) {
    .candle-glow { animation: none; opacity: 0.85; }
    .cue-line    { animation: none; }
    .reveal      { transition-duration: 0.001ms; }
    .parallax-slow { transform: none; }
    .hero-card, .kanji-mark, .wordmark, .hero-tagline, .scroll-cue {
        animation: none;
        opacity: 1;
        transform: none;
    }
}
