/* mujun.study — Ambient Scholarship
   Pastoral-romantic, candle-atmospheric, HUD-overlay
   Palette: bone cream, charcoal-sage, dim amber, burnt sienna, muted sage, taupe, pale ochre
*/

:root {
    --ground: #F9F5F0;          /* bone cream */
    --ink: #3D3A36;             /* charcoal-sage */
    --amber: #C4A470;           /* dim amber */
    --sienna: #8B7355;          /* burnt sienna */
    --sage: #8B9B7A;            /* muted sage */
    --taupe: #D4C9BB;           /* divider whisper */
    --ochre: #E8DCC9;           /* hover warmth */

    --measure: 70ch;
    --hud-inset: 32px;
    --hud-stroke: 2px;

    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-block: cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    background: var(--ground);
    color: var(--ink);
    font-family: 'Lora', Georgia, serif;
    font-size: 17px;
    line-height: 1.8;
    letter-spacing: -0.3px;
    text-rendering: geometricPrecision;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    position: relative;
}

/* Subtle linen paper texture overlay */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    background-image:
        repeating-linear-gradient(0deg, rgba(61,58,54,0.012) 0 1px, transparent 1px 3px),
        repeating-linear-gradient(90deg, rgba(61,58,54,0.010) 0 1px, transparent 1px 3px);
    mix-blend-mode: multiply;
    opacity: 0.75;
}

/* ============================================================
   HUD — Fixed frame, off-center, breathing
   ============================================================ */
.hud {
    position: fixed;
    inset: var(--hud-inset);
    pointer-events: none;
    z-index: 50;
    transform-origin: center;
    will-change: transform;
    animation: hud-breathe 4s ease-in-out infinite;
}

@keyframes hud-breathe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

.hud__corner {
    position: absolute;
    color: var(--sage);
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.hud__corner--tl {
    top: 0;
    left: 0;
    padding: 12px 16px 12px 14px;
    border-top: var(--hud-stroke) solid var(--sage);
    border-left: var(--hud-stroke) solid var(--sage);
    min-width: 220px;
}

.hud__corner--bl {
    bottom: 0;
    left: 0;
    padding: 12px 16px 12px 14px;
    border-bottom: var(--hud-stroke) solid var(--sage);
    border-left: var(--hud-stroke) solid var(--sage);
    min-width: 160px;
}

.hud__corner--br {
    bottom: 0;
    right: 0;
    padding: 12px 14px 12px 16px;
    border-bottom: var(--hud-stroke) solid var(--sage);
    border-right: var(--hud-stroke) solid var(--sage);
    min-width: 200px;
}

.hud__label {
    font-size: 9px;
    color: var(--taupe);
    letter-spacing: 0.18em;
    margin-bottom: 4px;
}

.hud__section-title {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 11px;
    color: var(--ink);
    letter-spacing: 0.16em;
    text-transform: lowercase;
    transition: color 1.2s var(--ease-out);
}

.hud__time-elapsed {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 11px;
    color: var(--ink);
    letter-spacing: 0.16em;
}

.hud__progress-candle {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 3px;
    height: 22px;
    width: 100%;
    max-width: 180px;
}

.hud__progress-segment {
    flex: 1 1 auto;
    height: 100%;
    background: var(--taupe);
    opacity: 0.35;
    border-radius: 1px;
    transition: background 0.6s var(--ease-out), opacity 0.6s var(--ease-out);
}

.hud__progress-segment.is-lit {
    background: var(--amber);
    opacity: 0.9;
    animation: candle-flicker 3.5s ease-in-out infinite;
}

.hud__progress-segment.is-lit:nth-child(2n) { animation-duration: 4.2s; animation-delay: -0.6s; }
.hud__progress-segment.is-lit:nth-child(3n) { animation-duration: 3.1s; animation-delay: -1.4s; }
.hud__progress-segment.is-lit:nth-child(5n) { animation-duration: 4.7s; animation-delay: -2.0s; }

@keyframes candle-flicker {
    0%, 100% { opacity: 0.86; }
    35% { opacity: 0.74; }
    65% { opacity: 0.94; }
}

/* ============================================================
   Chamber — main scroll container
   ============================================================ */
.chamber {
    position: relative;
    z-index: 2;
    width: 100%;
    padding: 0;
    margin: 0;
}

/* ============================================================
   Sections — full-bleed, asymmetric gutters
   ============================================================ */
.section {
    position: relative;
    width: 100%;
    padding: 14vh 24px 14vh 24px;
    border-bottom: 1px solid var(--taupe);
    opacity: 0;
    transform: translateY(20px) scale(0.97);
    transition: opacity 600ms var(--ease-block), transform 600ms var(--ease-block);
}

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

.section:last-of-type {
    border-bottom: none;
}

.section__inner {
    max-width: 1240px;
    margin: 0 auto;
    padding: 0 24px 0 48px;
    position: relative;
}

.section--alternate .section__inner,
.section--alternate-rev .section__inner {
    padding: 0 48px 0 24px;
}

.section__inner--split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 80px;
    align-items: center;
}

.section__inner--reversed {
    /* visual reversal — illustration on left, text on right */
}

.section__inner--narrow {
    max-width: 780px;
    text-align: left;
}

/* Section variants */
.section--open {
    padding-top: calc(var(--hud-inset) + 80px + 14vh);
    padding-bottom: 16vh;
}

.section--alternate {
    background: linear-gradient(
        180deg,
        var(--ground) 0%,
        rgba(232, 220, 201, 0.32) 50%,
        var(--ground) 100%
    );
    padding: 18vh 24px;
}

.section--learning {
    padding: 16vh 24px;
}

.section--breathe {
    padding: 22vh 24px;
    background: linear-gradient(
        180deg,
        var(--ground) 0%,
        rgba(212, 201, 187, 0.18) 100%
    );
}

.section--breathe-close {
    padding-bottom: calc(var(--hud-inset) + 14vh);
}

/* ============================================================
   Typography
   ============================================================ */
.section__metadata {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 11px;
    color: var(--sienna);
    letter-spacing: 0.18em;
    text-transform: lowercase;
    margin: 0 0 28px 0;
    text-shadow: 0 2px 4px rgba(61, 58, 54, 0.06);
}

.section__eyebrow {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 11px;
    color: var(--sage);
    letter-spacing: 0.22em;
    text-transform: uppercase;
    margin: 0 0 18px 0;
}

.section__eyebrow--centered {
    text-align: center;
}

.section__title {
    font-family: 'Crimson Text', 'Cormorant Garamond', Georgia, serif;
    font-size: clamp(28px, 3.4vw, 44px);
    font-weight: 700;
    line-height: 1.3;
    color: var(--ink);
    letter-spacing: -0.005em;
    margin: 0 0 32px 0;
    max-width: 22ch;
    text-shadow: 0 2px 4px rgba(61, 58, 54, 0.08);
    position: relative;
}

.section__title--display {
    font-size: clamp(38px, 5.2vw, 72px);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.1;
    max-width: 16ch;
    font-weight: 700;
}

.section__title--centered {
    text-align: center;
    margin-left: auto;
    margin-right: auto;
}

/* Underline draw — animated on enter-viewport */
.section__title::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: -14px;
    width: 0;
    height: 2px;
    background: var(--amber);
    border-radius: 1px;
    transition: width 1.2s var(--ease-out) 200ms;
}

.section.is-visible .section__title::after {
    width: 84px;
}

.section__title--display::after {
    bottom: -18px;
    height: 3px;
}

.section__title--centered::after {
    left: 50%;
    transform: translateX(-50%);
}

.section__lead {
    font-family: 'Lora', Georgia, serif;
    font-size: clamp(18px, 1.4vw, 22px);
    line-height: 1.75;
    color: var(--ink);
    max-width: var(--measure);
    margin: 0 0 32px 0;
    text-shadow: 0 2px 4px rgba(61, 58, 54, 0.06);
}

.section__lead em {
    color: var(--sienna);
    font-style: italic;
}

.section__body {
    font-family: 'Lora', Georgia, serif;
    font-size: 17px;
    line-height: 1.85;
    color: var(--ink);
    max-width: var(--measure);
    margin: 0 0 24px 0;
    text-shadow: 0 2px 4px rgba(61, 58, 54, 0.06);
}

.section__body--centered {
    margin-left: auto;
    margin-right: auto;
    text-align: center;
}

.section__caveat {
    font-family: 'Caveat', cursive;
    font-size: 18px;
    line-height: 1.5;
    color: var(--sienna);
    margin: 16px 0 0 0;
    transform: translate(2px, 0) rotate(-0.5deg);
    text-shadow: 0 2px 4px rgba(61, 58, 54, 0.06);
}

.section__caveat--margin {
    margin-top: 36px;
    color: var(--sage);
    transform: translate(0, 0) rotate(-0.8deg);
}

.section__caveat--centered {
    text-align: center;
    transform: rotate(-0.5deg);
}

/* ============================================================
   Candle Markers — line + flicker cap
   ============================================================ */
.marker {
    display: block;
    position: relative;
}

.marker--light,
.marker--pulse {
    width: 1px;
    height: 60px;
    background: var(--sage);
    margin: 0 0 28px 0;
    transform-origin: bottom center;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 800ms var(--ease-out), transform 800ms var(--ease-out);
}

.marker--light::before,
.marker--pulse::before {
    content: "";
    position: absolute;
    top: -4px;
    left: 50%;
    transform: translateX(-50%);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--amber);
    box-shadow: 0 0 12px rgba(196, 164, 112, 0.55), 0 0 4px rgba(196, 164, 112, 0.85);
}

.section.is-visible .marker--light,
.section.is-visible .marker--pulse {
    opacity: 1;
    transform: scale(1);
}

.marker--pulse::before {
    animation: candle-pulse 3.6s ease-in-out infinite;
}

.marker--light::before {
    animation: candle-pulse 4.0s ease-in-out infinite;
    animation-delay: -1.2s;
}

@keyframes candle-pulse {
    0%, 100% {
        opacity: 0.88;
        transform: translateX(-50%) scale(1);
    }
    35% {
        opacity: 0.74;
        transform: translateX(-50%) scale(0.96) rotate(-0.5deg);
    }
    62% {
        opacity: 0.96;
        transform: translateX(-50%) scale(1.04) rotate(0.4deg);
    }
}

/* Gutter marker — sticky in margins */
.marker--gutter {
    position: absolute;
    left: -32px;
    top: 18px;
    width: 1px;
    height: 48px;
    background: var(--sage);
    opacity: 0;
    transition: opacity 400ms var(--ease-out);
}

.marker--gutter::before {
    content: "";
    position: absolute;
    top: -3px;
    left: 50%;
    transform: translateX(-50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--amber);
    box-shadow: 0 0 8px rgba(196, 164, 112, 0.5);
    animation: candle-pulse 3.8s ease-in-out infinite;
}

.section.is-visible .marker--gutter {
    opacity: 0.85;
}

.marker--gutter-left {
    left: 24px;
    top: 24px;
}

.marker--closing {
    position: relative;
    margin: 24px auto 0 auto;
    left: 50%;
    transform: translateX(-50%);
    width: 1px;
    height: 56px;
    background: var(--sage);
    opacity: 1;
}

/* ============================================================
   Learning units — concept triplet
   ============================================================ */
.learning-triplet {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 56px;
    margin-top: 48px;
}

.learning-unit {
    position: relative;
    padding: 8px 0 8px 28px;
}

.learning-unit__index {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 11px;
    color: var(--sienna);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    margin: 0 0 12px 0;
}

.learning-unit__title {
    font-family: 'Crimson Text', Georgia, serif;
    font-size: 24px;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.3;
    margin: 0 0 16px 0;
    letter-spacing: -0.01em;
    position: relative;
    display: inline-block;
}

.learning-unit__body {
    font-family: 'Lora', Georgia, serif;
    font-size: 16px;
    line-height: 1.8;
    color: var(--ink);
    margin: 0 0 18px 0;
}

.learning-unit__outcome {
    font-family: 'Caveat', cursive;
    font-size: 17px;
    color: var(--sage);
    margin: 0;
    transform: rotate(-0.6deg);
}

/* underline-draw on learning-unit titles */
.underline-draw {
    position: absolute;
    left: 0;
    bottom: -4px;
    width: 0;
    height: 2px;
    background: var(--amber);
    border-radius: 1px;
    transition: width 1.2s var(--ease-out) 350ms;
    pointer-events: none;
}

.section.is-visible .underline-draw {
    width: 100%;
}

/* ============================================================
   Illustration block
   ============================================================ */
.illustration {
    position: relative;
    width: 100%;
    aspect-ratio: 6 / 7;
    overflow: hidden;
    border-radius: 2px;
}

.illustration::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        repeating-linear-gradient(0deg, rgba(61,58,54,0.025) 0 1px, transparent 1px 3px),
        repeating-linear-gradient(90deg, rgba(61,58,54,0.020) 0 1px, transparent 1px 3px);
    mix-blend-mode: multiply;
    opacity: 0.4;
}

.illustration__svg {
    display: block;
    width: 100%;
    height: 100%;
}

/* ============================================================
   Passage / quote
   ============================================================ */
.passage {
    margin: 36px 0;
    padding: 24px 0;
    border: none;
}

.passage__text {
    font-family: 'Crimson Text', Georgia, serif;
    font-style: italic;
    font-size: clamp(22px, 2.4vw, 32px);
    line-height: 1.5;
    color: var(--ink);
    margin: 0 0 24px 0;
    letter-spacing: -0.005em;
    text-shadow: 0 2px 4px rgba(61, 58, 54, 0.08);
}

.passage__cite {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 11px;
    color: var(--sienna);
    letter-spacing: 0.16em;
    text-transform: lowercase;
    margin: 0;
}

/* ============================================================
   Closing flourish
   ============================================================ */
.closing-mark {
    margin-top: 48px;
    text-align: center;
    height: 80px;
    position: relative;
}

/* ============================================================
   Color modulation on scroll — focused candle warms
   ============================================================ */
.section.is-focused .marker--light::before,
.section.is-focused .marker--pulse::before,
.section.is-focused .marker--gutter::before {
    background: var(--sienna);
    box-shadow: 0 0 14px rgba(139, 115, 85, 0.55), 0 0 5px rgba(139, 115, 85, 0.85);
    transition: background 2s var(--ease-out), box-shadow 2s var(--ease-out);
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1024px) {
    .section__inner--split {
        grid-template-columns: 1fr;
        gap: 56px;
    }
    .section__column--illustration {
        order: 2;
    }
    .section__inner--reversed .section__column--illustration {
        order: 2;
    }
    .learning-triplet {
        grid-template-columns: 1fr 1fr;
        gap: 48px;
    }
}

@media (max-width: 640px) {
    :root {
        --hud-inset: 18px;
    }
    body { font-size: 16px; }
    .section { padding: 10vh 18px; }
    .section__inner { padding: 0 12px 0 28px; }
    .section--alternate .section__inner,
    .section--alternate-rev .section__inner { padding: 0 28px 0 12px; }
    .section--open { padding-top: calc(var(--hud-inset) + 60px + 12vh); }
    .hud__corner--tl { min-width: 160px; padding: 8px 10px; }
    .hud__corner--bl { min-width: 110px; padding: 8px 10px; display: none; }
    .hud__corner--br { min-width: 130px; padding: 8px 10px; }
    .hud__progress-candle { max-width: 110px; height: 16px; }
    .learning-triplet {
        grid-template-columns: 1fr;
        gap: 36px;
    }
    .section__title--display {
        font-size: clamp(30px, 8vw, 44px);
    }
    .marker--light, .marker--pulse { height: 42px; margin-bottom: 22px; }
    .marker--gutter { left: -22px; height: 36px; }
}

/* Reduced motion: disable animations except candle (becomes static) */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
    .hud { animation: none; }
    .marker--light::before,
    .marker--pulse::before,
    .marker--gutter::before {
        animation: none;
        opacity: 0.9;
    }
    .hud__progress-segment.is-lit { animation: none; opacity: 0.9; }
    .section { opacity: 1; transform: none; }
    .section.is-visible .section__title::after,
    .section.is-visible .underline-draw { transition: none; }
}
