/* =====================================================================
   MMIDDL.com — A Scholar's Folio
   Palette: #E6D5B8 #F2E8D5 #E87C3E #2B2520 #D4A04A #C45A1A #1C1A17 #A0522D
   Fonts:   Playfair Display, Lora, Space Grotesk, Cormorant Garamond
   ===================================================================== */

:root {
    --color-burnt-sienna: #C45A1A;
    --color-aged-ivory: #F2E8D5;
    --color-deep-charcoal: #1C1A17;
    --color-candle-gold: #D4A04A;
    --color-foxed-parchment: #E6D5B8;
    --color-ink-well: #2B2520;
    --color-ember-glow: #E87C3E;
    --color-burnt-sienna-soft: #A0522D;

    --font-display: "Playfair Display", "Lora", Georgia, serif;
    --font-body: "Lora", Georgia, "Times New Roman", serif;
    --font-sans: "Space Grotesk", "Inter", system-ui, sans-serif;
    --font-numeral: "Cormorant Garamond", "Playfair Display", serif;

    --sidebar-width: 280px;
    --sidebar-width-mobile: 48px;
    --reading-measure: 64ch;

    --ease-candle: cubic-bezier(0.25, 0.1, 0.25, 1.0);
    --ease-spring: cubic-bezier(0.34, 1.2, 0.64, 1);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--color-aged-ivory);
    color: var(--color-deep-charcoal);
    font-family: var(--font-body);
    font-size: 18px;
    line-height: 1.75;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

body {
    min-height: 100vh;
    position: relative;
}

/* Generative noise canvas — sits behind everything */
#noiseCanvas {
    position: fixed;
    top: 0; left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
    pointer-events: none;
    opacity: 0.85;
    mix-blend-mode: multiply;
}

/* Paper texture: SVG-filter generated, layered at low opacity */
.paper-texture {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    opacity: 0.5;
    background-color: transparent;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='400' height='400'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' seed='3'/><feColorMatrix values='0 0 0 0 0.17  0 0 0 0 0.10  0 0 0 0 0.09  0 0 0 0.32 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='0.6'/></svg>");
    background-repeat: repeat;
    mix-blend-mode: multiply;
}

/* Candle vignette in upper-right of main area */
.candle-vignette {
    position: fixed;
    top: -10vh;
    right: -10vw;
    width: 60vw;
    height: 60vh;
    z-index: 2;
    pointer-events: none;
    background: radial-gradient(circle at 70% 30%,
        rgba(212, 160, 74, 0.18) 0%,
        rgba(232, 124, 62, 0.08) 25%,
        rgba(232, 124, 62, 0.0) 60%);
    /* Note: this gradient is for the candle radial glow effect specified in design,
       not a decorative palette gradient. It uses layered transparent ember glow. */
    animation: candleFlicker 7s var(--ease-candle) infinite;
}

@keyframes candleFlicker {
    0%, 100% { opacity: 0.95; transform: translate(0, 0) scale(1); }
    20%      { opacity: 1.0;  transform: translate(-4px, 2px) scale(1.02); }
    40%      { opacity: 0.88; transform: translate(2px, -3px) scale(0.99); }
    60%      { opacity: 0.97; transform: translate(-2px, 1px) scale(1.01); }
    80%      { opacity: 0.92; transform: translate(3px, 2px) scale(1.00); }
}

/* =====================================================================
   Sidebar — the book spine
   ===================================================================== */
.sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--color-deep-charcoal);
    color: var(--color-aged-ivory);
    z-index: 50;
    overflow-y: auto;
    border-right: 1px solid var(--color-ink-well);
    box-shadow: 2px 0 0 0 var(--color-burnt-sienna), 6px 0 24px rgba(0,0,0,0.25);
}

.sidebar-inner {
    position: relative;
    padding: 2.25rem 1.75rem 2rem 1.75rem;
    min-height: 100%;
}

.sidebar-inner::before {
    /* warm pulse behind active nav item */
    content: "";
    position: absolute;
    left: 0;
    width: 100%;
    height: 80px;
    top: 220px;
    background: radial-gradient(ellipse at 40% 50%,
        rgba(212, 160, 74, 0.22) 0%,
        rgba(232, 124, 62, 0.06) 40%,
        rgba(0,0,0,0) 70%);
    /* radial glow effect, not a palette gradient */
    z-index: 0;
    pointer-events: none;
    transition: top 600ms var(--ease-candle), opacity 400ms var(--ease-candle);
    animation: candleFlicker 5s var(--ease-candle) infinite;
}

.candle {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 1.5rem;
    height: 100px;
}

.candle-icon {
    width: 48px;
    height: 96px;
    position: relative;
    z-index: 2;
}

.candle-icon .flame {
    transform-origin: 20px 28px;
    animation: flameWobble 1.8s var(--ease-candle) infinite;
}

.candle-icon .flame-core {
    animation: flameCore 1.8s var(--ease-candle) infinite;
}

@keyframes flameWobble {
    0%, 100% { transform: scale(1, 1) rotate(-1deg); opacity: 1; }
    25%      { transform: scale(0.95, 1.05) rotate(2deg); opacity: 0.85; }
    50%      { transform: scale(1.05, 0.95) rotate(-2deg); opacity: 1; }
    75%      { transform: scale(0.98, 1.02) rotate(1deg); opacity: 0.92; }
}

@keyframes flameCore {
    0%, 100% { opacity: 0.8; r: 3; }
    50%      { opacity: 1.0; r: 3.5; }
}

.candle-glow {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 160px;
    height: 160px;
    background: radial-gradient(circle,
        rgba(212, 160, 74, 0.35) 0%,
        rgba(232, 124, 62, 0.15) 30%,
        rgba(0,0,0,0) 70%);
    /* radial candle glow */
    z-index: 1;
    pointer-events: none;
    animation: candleFlicker 6s var(--ease-candle) infinite;
}

.brand {
    text-align: center;
    margin: 0 0 2rem 0;
    line-height: 1.2;
    position: relative;
    z-index: 2;
}

.brand-mark {
    display: block;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.65rem;
    letter-spacing: 0.18em;
    color: var(--color-aged-ivory);
}

.brand-sub {
    display: block;
    margin-top: 0.5rem;
    font-family: var(--font-body);
    font-style: italic;
    font-size: 0.78rem;
    letter-spacing: 0.05em;
    color: var(--color-candle-gold);
    opacity: 0.85;
}

.chapter-nav {
    position: relative;
    z-index: 2;
}

.chapter-nav ol {
    list-style: none;
    margin: 0;
    padding: 0;
}

.chapter-nav li {
    margin: 0;
    padding: 0;
}

.chapter-link {
    display: flex;
    align-items: baseline;
    gap: 1rem;
    padding: 0.85rem 0.9rem;
    color: rgba(242, 232, 213, 0.7);
    text-decoration: none;
    font-family: var(--font-sans);
    font-weight: 500;
    font-size: 14px;
    letter-spacing: 0.02em;
    border-left: 3px solid transparent;
    transition: color 320ms var(--ease-candle),
                border-left-color 420ms var(--ease-candle),
                background-color 320ms var(--ease-candle),
                padding-left 320ms var(--ease-candle);
    position: relative;
}

.chapter-link::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    width: 0;
    height: 1px;
    background: var(--color-burnt-sienna);
    transform: translateY(-50%);
    transition: width 380ms var(--ease-candle);
}

.chapter-link .numeral {
    font-family: var(--font-numeral);
    font-weight: 600;
    font-size: 1.25rem;
    color: var(--color-burnt-sienna);
    min-width: 2ch;
    letter-spacing: 0.02em;
    transition: color 320ms var(--ease-candle), text-shadow 320ms var(--ease-candle);
}

.chapter-link .chapter-title {
    font-variant: small-caps;
    letter-spacing: 0.12em;
    text-transform: lowercase;
}

.chapter-link:hover {
    color: var(--color-aged-ivory);
    background: rgba(196, 90, 26, 0.08);
}

.chapter-link:hover .numeral {
    color: var(--color-candle-gold);
    text-shadow: 0 0 10px rgba(212, 160, 74, 0.5);
}

.chapter-link.active {
    color: var(--color-aged-ivory);
    border-left-color: var(--color-burnt-sienna);
    background: rgba(196, 90, 26, 0.12);
    padding-left: 1.1rem;
}

.chapter-link.active::before {
    width: 14px;
}

.chapter-link.active .numeral {
    color: var(--color-candle-gold);
    text-shadow: 0 0 12px rgba(212, 160, 74, 0.6);
}

.sidebar-rule {
    height: 1px;
    background: linear-gradient(to right,
        rgba(196, 90, 26, 0) 0%,
        rgba(196, 90, 26, 0.6) 50%,
        rgba(196, 90, 26, 0) 100%);
    /* this is a structural rule, used as accent line not as palette gradient */
    margin: 2rem 0 1rem 0;
}

.sidebar-foot {
    text-align: center;
    font-family: var(--font-sans);
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: rgba(242, 232, 213, 0.55);
    margin: 0;
}

#sessionSigil {
    color: var(--color-candle-gold);
    font-weight: 600;
}

/* mobile sidebar toggle */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 1rem;
    left: calc(var(--sidebar-width-mobile) + 0.5rem);
    z-index: 80;
    width: 44px;
    height: 44px;
    border: 1px solid var(--color-burnt-sienna);
    background: var(--color-ink-well);
    color: var(--color-aged-ivory);
    cursor: pointer;
    padding: 0;
    border-radius: 2px;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
}

.sidebar-toggle span {
    display: block;
    width: 18px;
    height: 1.5px;
    background: var(--color-candle-gold);
}

/* =====================================================================
   Main reading area
   ===================================================================== */
.main {
    margin-left: var(--sidebar-width);
    position: relative;
    z-index: 5;
    min-height: 100vh;
    scroll-snap-type: y proximity;
    overflow-x: hidden;
}

.folios {
    display: block;
}

.folio {
    position: relative;
    min-height: 100vh;
    padding: clamp(3rem, 8vh, 6rem) clamp(2rem, 5vw, 6rem);
    padding-left: clamp(4rem, 8vw, 9rem);  /* leave room for margin annotations */
    scroll-snap-align: start;
    scroll-snap-stop: normal;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 600ms var(--ease-candle),
                transform 600ms var(--ease-candle);
    overflow: hidden;
}

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

.folio--ivory {
    background: var(--color-aged-ivory);
}

.folio--parchment {
    background: var(--color-foxed-parchment);
}

.folio--parchment::after {
    /* overlay extra paper grain seed */
    content: "";
    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.78' numOctaves='3' seed='11'/><feColorMatrix values='0 0 0 0 0.17  0 0 0 0 0.10  0 0 0 0 0.09  0 0 0 0.18 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
    opacity: 0.5;
    mix-blend-mode: multiply;
    pointer-events: none;
}

.folio--charcoal {
    background: var(--color-ink-well);
    color: var(--color-aged-ivory);
}

.folio-header {
    max-width: var(--reading-measure);
    margin-bottom: 2.25rem;
    position: relative;
    z-index: 2;
}

.folio-eyebrow {
    font-family: var(--font-sans);
    font-size: 12px;
    letter-spacing: 0.24em;
    text-transform: uppercase;
    color: var(--color-burnt-sienna);
    margin: 0 0 0.75rem 0;
    font-weight: 500;
}

.folio--charcoal .folio-eyebrow {
    color: var(--color-candle-gold);
}

.folio-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-style: italic;
    font-size: clamp(2rem, 4vw, 3.5rem);
    line-height: 1.15;
    margin: 0;
    color: var(--color-deep-charcoal);
    font-variant: normal;
    letter-spacing: -0.005em;
}

.folio--charcoal .folio-title {
    color: var(--color-aged-ivory);
}

.folio-body {
    max-width: var(--reading-measure);
    position: relative;
    z-index: 2;
}

.folio-body p {
    margin: 0 0 1.4em 0;
    color: var(--color-deep-charcoal);
}

.folio--charcoal .folio-body p {
    color: rgba(242, 232, 213, 0.9);
}

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

.folio-body strong, .folio-body b {
    font-weight: 700;
    color: var(--color-burnt-sienna);
}

.lede {
    position: relative;
}

/* Drop cap with candle glow */
.dropcap {
    float: left;
    font-family: var(--font-numeral);
    font-weight: 700;
    font-size: 6rem;
    line-height: 0.9;
    margin: 0.15em 0.12em -0.05em 0;
    color: var(--color-burnt-sienna);
    text-shadow:
        0 0 18px rgba(232, 124, 62, 0.35),
        0 0 36px rgba(212, 160, 74, 0.25);
    position: relative;
    z-index: 1;
}

.lede::before {
    content: "";
    position: absolute;
    top: -10px;
    left: -20px;
    width: 200px;
    height: 200px;
    background: radial-gradient(circle,
        rgba(212, 160, 74, 0.20) 0%,
        rgba(232, 124, 62, 0.08) 30%,
        rgba(0,0,0,0) 65%);
    /* candle glow behind dropcap */
    z-index: 0;
    pointer-events: none;
    animation: candleFlicker 6s var(--ease-candle) infinite;
}

.epigraph {
    margin: 2em 0 2em 1.5em;
    padding-left: 1.5em;
    border-left: 2px solid var(--color-burnt-sienna);
    font-style: italic;
    font-family: var(--font-display);
    font-size: 1.15em;
    color: var(--color-burnt-sienna-soft);
    line-height: 1.55;
}

.bookish-list {
    margin: 1.5em 0;
    padding-left: 0;
    list-style: none;
}

.bookish-list li {
    position: relative;
    padding-left: 2em;
    margin: 0.4em 0;
}

.bookish-list li::before {
    content: "❦";
    position: absolute;
    left: 0;
    color: var(--color-burnt-sienna);
    font-size: 0.95em;
}

/* =====================================================================
   Folio separator — generative calligraphic flourish
   ===================================================================== */
.folio-separator {
    display: block;
    width: 100%;
    padding: 1.5rem clamp(2rem, 5vw, 6rem);
    padding-left: clamp(4rem, 8vw, 9rem);
    background: var(--color-aged-ivory);
    position: relative;
    z-index: 4;
}

.separator-svg {
    width: 100%;
    height: 40px;
    display: block;
    opacity: 0.6;
}

.separator-path {
    animation: separatorBreathe 4s var(--ease-candle) infinite;
}

@keyframes separatorBreathe {
    0%, 100% { stroke-width: 1.0; opacity: 0.55; }
    50%      { stroke-width: 1.4; opacity: 0.75; }
}

/* =====================================================================
   Marginal annotations
   ===================================================================== */
.margin-annotations {
    position: absolute;
    top: 0;
    left: 0;
    width: clamp(3.5rem, 7vw, 7rem);
    height: 100%;
    pointer-events: none;
    z-index: 3;
}

.annotation {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 28px;
    height: 28px;
    background: transparent;
    border: 0;
    padding: 0;
    cursor: pointer;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.annotation .dot {
    display: block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-burnt-sienna);
    box-shadow: 0 0 0 0 rgba(232, 124, 62, 0.6);
    transition: transform 300ms var(--ease-spring),
                background 300ms var(--ease-candle),
                box-shadow 600ms var(--ease-candle);
}

.annotation:hover .dot,
.annotation.is-active .dot {
    transform: scale(1.6);
    background: var(--color-ember-glow);
    box-shadow: 0 0 0 6px rgba(232, 124, 62, 0.18),
                0 0 18px rgba(232, 124, 62, 0.45);
}

/* Singleton annotation panel */
.annotation-panel {
    position: absolute;
    z-index: 70;
    width: 240px;
    background: var(--color-foxed-parchment);
    border: 1px solid var(--color-burnt-sienna-soft);
    box-shadow: 0 6px 28px rgba(28, 26, 23, 0.25),
                0 0 0 4px rgba(232, 124, 62, 0.06);
    padding: 1rem 1.1rem;
    font-family: var(--font-sans);
    font-size: 13px;
    line-height: 1.55;
    color: var(--color-deep-charcoal);
    opacity: 0;
    pointer-events: none;
    transform: translateY(6px) scale(0.96);
    transform-origin: top left;
    transition: opacity 300ms var(--ease-candle),
                transform 360ms var(--ease-spring);
}

.annotation-panel.is-visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.annotation-panel-inner {
    position: relative;
}

.annotation-panel em {
    color: var(--color-burnt-sienna);
    font-style: italic;
}

.annotation-panel::before {
    content: "";
    position: absolute;
    left: -7px;
    top: 12px;
    width: 12px;
    height: 12px;
    background: var(--color-foxed-parchment);
    border-left: 1px solid var(--color-burnt-sienna-soft);
    border-bottom: 1px solid var(--color-burnt-sienna-soft);
    transform: rotate(45deg);
}

/* =====================================================================
   Colophon
   ===================================================================== */
.colophon {
    max-width: 36rem;
    margin: 1.5rem auto 0;
    text-align: center;
    color: var(--color-aged-ivory);
    position: relative;
    z-index: 2;
}

.sigil {
    width: 96px;
    height: 96px;
    margin: 0 auto 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
}

#sigilSvg {
    width: 96px;
    height: 96px;
    filter: drop-shadow(0 0 12px rgba(212, 160, 74, 0.45));
}

.colophon-line {
    font-family: var(--font-sans);
    font-size: 13px;
    letter-spacing: 0.06em;
    line-height: 1.7;
    margin: 0.25em 0;
    color: rgba(242, 232, 213, 0.75);
}

.colophon-line em {
    font-style: italic;
    color: var(--color-candle-gold);
}

.colophon-sigil {
    margin-top: 1.5rem;
    font-family: var(--font-numeral);
    font-size: 1rem;
    letter-spacing: 0.18em;
    color: var(--color-burnt-sienna);
}

#sigilNumber {
    color: var(--color-candle-gold);
}

.colophon-explicit {
    margin-top: 2rem;
    font-family: var(--font-display);
    font-style: italic;
    font-size: 1rem;
    color: rgba(242, 232, 213, 0.6);
    line-height: 1.6;
}

/* =====================================================================
   Responsive
   ===================================================================== */
@media (max-width: 900px) {
    :root { --reading-measure: 60ch; }
    .folio {
        padding-left: clamp(3rem, 7vw, 6rem);
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: var(--sidebar-width-mobile);
        transition: width 380ms var(--ease-candle);
    }

    .sidebar.is-open {
        width: 260px;
        box-shadow: 4px 0 0 0 var(--color-burnt-sienna),
                    24px 0 60px rgba(0,0,0,0.55);
    }

    .sidebar-inner {
        padding: 1.25rem 0.5rem;
    }

    .sidebar.is-open .sidebar-inner {
        padding: 2rem 1.5rem;
    }

    .candle-icon { width: 28px; height: 56px; }
    .candle { height: 60px; margin-bottom: 0.75rem; }
    .candle-glow { width: 80px; height: 80px; }

    .brand-mark { font-size: 0; letter-spacing: 0; }
    .brand-mark::after {
        content: "M";
        font-size: 1rem;
        letter-spacing: 0;
    }
    .sidebar.is-open .brand-mark { font-size: 1.4rem; letter-spacing: 0.18em; }
    .sidebar.is-open .brand-mark::after { content: ""; }
    .brand-sub { display: none; }
    .sidebar.is-open .brand-sub { display: block; }

    .chapter-link {
        padding: 0.75rem 0.4rem;
        justify-content: center;
        gap: 0;
    }
    .chapter-link .chapter-title { display: none; }
    .sidebar.is-open .chapter-link {
        padding: 0.85rem 0.9rem;
        justify-content: flex-start;
        gap: 1rem;
    }
    .sidebar.is-open .chapter-link .chapter-title { display: inline; }

    .sidebar-rule, .sidebar-foot { display: none; }
    .sidebar.is-open .sidebar-rule,
    .sidebar.is-open .sidebar-foot { display: block; }

    .main { margin-left: var(--sidebar-width-mobile); }

    .folio { padding-left: clamp(3rem, 7vw, 4.5rem); }

    .sidebar-toggle { display: flex; }

    /* mobile overlay backdrop */
    .sidebar.is-open::after {
        content: "";
        position: fixed;
        top: 0; left: 260px;
        width: 100vw; height: 100vh;
        background: rgba(43, 37, 32, 0.55);
        pointer-events: none;
    }

    .annotation-panel {
        width: min(240px, calc(100vw - 4rem));
    }
}

@media (max-width: 540px) {
    html, body { font-size: 17px; }
    .folio { padding: 3rem 1.25rem 3rem 3.5rem; }
    .folio-separator { padding: 1rem 1.25rem 1rem 3.5rem; }
    .dropcap { font-size: 5rem; }
    .lede::before { width: 160px; height: 160px; }
}
