/* nonri.xyz — Goblincore Scholar's Study */
/* Fonts: Space Grotesk, Lora, Caveat, IBM Plex Mono */

:root {
    --parchment: #f4ece1;
    --parchment-warm: #f0e5d6;
    --parchment-edge: #ede2d4;
    --leather: #3d2b1f;
    --deep-ink: #2a1810;
    --moss: #5a6b4e;
    --tallow: #c98a4b;
    --foxing: #b89a78;
    --olive: #6b7c5e;
    --wax: #f0d9b5;
    --mushroom-tan: #9a7b5e;
    --mushroom-cap: #d4c4a8;
    --charcoal: #4a4a4a;
}

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

html {
    scroll-behavior: smooth;
}

body {
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
    background: var(--parchment);
    cursor: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path d="M3,14 L5,4 Q6,2 8,1 L7,3 L8,5 L6,6 L4,13 Z" fill="%232a1810" opacity="0.8"/></svg>') 3 14, auto;
}

/* ================================
   LEFT PANEL — THE MARGIN
   ================================ */

#margin-panel {
    position: fixed;
    left: 0;
    top: 0;
    width: 35vw;
    height: 100vh;
    background: var(--leather);
    z-index: 10;
    overflow: hidden;
    transition: transform 0.3s ease;
}

/* Leather texture via CSS noise */
#margin-panel::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        repeating-linear-gradient(
            45deg,
            rgba(0,0,0,0.02) 0px,
            transparent 1px,
            transparent 3px
        ),
        repeating-linear-gradient(
            -45deg,
            rgba(0,0,0,0.015) 0px,
            transparent 1px,
            transparent 4px
        ),
        radial-gradient(ellipse at 20% 50%, rgba(90,70,50,0.15) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 30%, rgba(60,40,25,0.1) 0%, transparent 50%);
    pointer-events: none;
}

.margin-content {
    position: relative;
    padding: 3vh 2vw;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Site Identity */
.site-logotype {
    font-family: 'Caveat', cursive;
    font-weight: 500;
    font-size: clamp(2.5rem, 4vw, 4rem);
    color: var(--parchment);
    letter-spacing: 0.02em;
    line-height: 1;
    opacity: 0.9;
}

.site-subtitle {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    color: var(--foxing);
    letter-spacing: 0.1em;
    margin-top: 0.3rem;
    margin-bottom: 2rem;
    opacity: 0.7;
}

/* Table of Contents */
#toc {
    position: relative;
    margin: 1rem 0 2rem;
}

.toc-line {
    position: absolute;
    left: 0.6rem;
    top: 0;
    bottom: 0;
    width: 1px;
    background: linear-gradient(
        to bottom,
        rgba(244,236,225,0.1) 0%,
        rgba(244,236,225,0.3) 20%,
        rgba(244,236,225,0.25) 50%,
        rgba(244,236,225,0.35) 80%,
        rgba(244,236,225,0.1) 100%
    );
    animation: inkPulse 4s ease-in-out infinite;
}

@keyframes inkPulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

#toc ul {
    list-style: none;
    padding-left: 0;
}

#toc li {
    margin-bottom: 0.6rem;
}

.toc-link {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    text-decoration: none;
    padding: 0.3rem 0.5rem;
    border-radius: 2px;
    transition: all 0.4s ease;
}

.toc-link .numeral {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    color: var(--foxing);
    min-width: 1.2rem;
    opacity: 0.6;
    transition: all 0.4s ease;
}

.toc-link .toc-label {
    font-family: 'Lora', serif;
    font-size: 0.8rem;
    color: var(--mushroom-cap);
    opacity: 0.5;
    transition: all 0.4s ease;
}

.toc-link.active .numeral {
    color: var(--tallow);
    opacity: 1;
}

.toc-link.active .toc-label {
    color: var(--parchment);
    opacity: 0.85;
}

.toc-link:hover .toc-label {
    color: var(--parchment);
    opacity: 0.7;
}

/* Ink Blots */
.ink-blot {
    position: absolute;
    border-radius: 50%;
    background: var(--deep-ink);
    opacity: 0.08;
}

.ink-blot-1 {
    width: 60px;
    height: 55px;
    top: 55%;
    left: 15%;
    border-radius: 42% 58% 70% 30% / 45% 45% 55% 55%;
    animation: blobMorph1 25s ease-in-out infinite;
}

.ink-blot-2 {
    width: 40px;
    height: 38px;
    top: 62%;
    left: 60%;
    border-radius: 58% 42% 35% 65% / 50% 60% 40% 50%;
    animation: blobMorph2 30s ease-in-out infinite;
}

.ink-blot-3 {
    width: 50px;
    height: 45px;
    top: 72%;
    left: 35%;
    border-radius: 45% 55% 60% 40% / 55% 40% 60% 45%;
    animation: blobMorph3 28s ease-in-out infinite;
}

@keyframes blobMorph1 {
    0%   { border-radius: 42% 58% 70% 30% / 45% 45% 55% 55%; }
    20%  { border-radius: 55% 45% 50% 50% / 60% 35% 65% 40%; }
    40%  { border-radius: 38% 62% 45% 55% / 50% 55% 45% 50%; }
    60%  { border-radius: 60% 40% 55% 45% / 40% 60% 40% 60%; }
    80%  { border-radius: 48% 52% 65% 35% / 55% 42% 58% 45%; }
    100% { border-radius: 42% 58% 70% 30% / 45% 45% 55% 55%; }
}

@keyframes blobMorph2 {
    0%   { border-radius: 58% 42% 35% 65% / 50% 60% 40% 50%; }
    25%  { border-radius: 45% 55% 55% 45% / 40% 50% 60% 50%; }
    50%  { border-radius: 52% 48% 42% 58% / 55% 45% 55% 45%; }
    75%  { border-radius: 40% 60% 60% 40% / 48% 55% 45% 52%; }
    100% { border-radius: 58% 42% 35% 65% / 50% 60% 40% 50%; }
}

@keyframes blobMorph3 {
    0%   { border-radius: 45% 55% 60% 40% / 55% 40% 60% 45%; }
    33%  { border-radius: 55% 45% 45% 55% / 42% 58% 42% 58%; }
    66%  { border-radius: 50% 50% 55% 45% / 60% 45% 55% 40%; }
    100% { border-radius: 45% 55% 60% 40% / 55% 40% 60% 45%; }
}

/* Marginalia Notes */
#marginalia-container {
    margin-top: auto;
    padding: 1rem 0;
    min-height: 80px;
}

.marginal-note {
    font-family: 'Caveat', cursive;
    font-size: clamp(0.85rem, 1.1vw, 1rem);
    color: var(--moss);
    line-height: 1.5;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.8s ease, transform 0.8s ease;
    position: absolute;
    bottom: 18%;
    left: 2vw;
    right: 2vw;
    pointer-events: none;
}

.marginal-note.visible {
    opacity: 0.85;
    transform: translateY(0);
}

/* Proofreading Marks */
.proof-marks {
    position: absolute;
    right: 1.5vw;
    top: 45%;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.proof-mark {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 1.2rem;
    color: var(--foxing);
    opacity: 0;
    animation-duration: 12s;
    animation-iteration-count: infinite;
    animation-timing-function: ease-in-out;
}

.mark-caret {
    animation-name: proofFade1;
}

.mark-pilcrow {
    animation-name: proofFade2;
}

.mark-dagger {
    animation-name: proofFade3;
}

@keyframes proofFade1 {
    0%, 25%, 100% { opacity: 0; }
    30%, 40% { opacity: 0.4; }
}

@keyframes proofFade2 {
    0%, 50%, 100% { opacity: 0; }
    55%, 65% { opacity: 0.35; }
}

@keyframes proofFade3 {
    0%, 75%, 100% { opacity: 0; }
    80%, 90% { opacity: 0.45; }
}

/* Mushroom Cluster */
.mushroom-cluster {
    position: absolute;
    bottom: 5%;
    left: 1.5vw;
    display: flex;
    gap: 3px;
    align-items: flex-end;
}

.mushroom {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.mushroom .cap {
    border-radius: 50% 50% 10% 10%;
    background: var(--mushroom-tan);
}

.mushroom .stem {
    background: var(--mushroom-tan);
    opacity: 0.7;
    border-radius: 2px;
}

.mushroom.m1 .cap { width: 16px; height: 10px; }
.mushroom.m1 .stem { width: 4px; height: 12px; }

.mushroom.m2 .cap { width: 22px; height: 14px; }
.mushroom.m2 .stem { width: 5px; height: 16px; }

.mushroom.m3 .cap { width: 12px; height: 8px; }
.mushroom.m3 .stem { width: 3px; height: 10px; }

.mushroom.m4 .cap {
    width: 18px;
    height: 11px;
    background: var(--mushroom-cap);
}
.mushroom.m4 .stem { width: 4px; height: 14px; }

/* ================================
   THE GUTTER (binding seam)
   ================================ */

#gutter-line {
    position: fixed;
    left: 35vw;
    top: 0;
    width: 3px;
    height: 100vh;
    z-index: 20;
    background: linear-gradient(
        to bottom,
        rgba(42,24,16,0.3) 0%,
        rgba(42,24,16,0.6) 15%,
        rgba(42,24,16,0.5) 30%,
        rgba(42,24,16,0.7) 50%,
        rgba(42,24,16,0.4) 70%,
        rgba(42,24,16,0.65) 85%,
        rgba(42,24,16,0.3) 100%
    );
}

#gutter-creature {
    position: absolute;
    width: 24px;
    height: 24px;
    left: -10px;
    opacity: 0;
    transition: opacity 0.5s ease, transform 1.5s ease-out;
    pointer-events: none;
}

/* ================================
   RIGHT PANEL — THE TEXT
   ================================ */

#text-panel {
    margin-left: 35vw;
    width: 65vw;
    min-height: 100vh;
    position: relative;
    transition: transform 0.3s ease;
    /* Aged paper texture */
    background:
        /* Fiber layer */
        repeating-linear-gradient(
            87deg,
            rgba(180,160,140,0.03) 0px,
            rgba(180,160,140,0.03) 1px,
            transparent 1px,
            transparent 3px
        ),
        /* Foxing spots */
        radial-gradient(circle at 15% 8%, rgba(184,154,120,0.05) 0%, transparent 60px),
        radial-gradient(circle at 72% 15%, rgba(184,154,120,0.04) 0%, transparent 45px),
        radial-gradient(circle at 45% 25%, rgba(184,154,120,0.06) 0%, transparent 70px),
        radial-gradient(circle at 88% 35%, rgba(184,154,120,0.03) 0%, transparent 40px),
        radial-gradient(circle at 25% 50%, rgba(184,154,120,0.05) 0%, transparent 55px),
        radial-gradient(circle at 65% 55%, rgba(184,154,120,0.04) 0%, transparent 65px),
        radial-gradient(circle at 80% 70%, rgba(184,154,120,0.06) 0%, transparent 50px),
        radial-gradient(circle at 35% 80%, rgba(184,154,120,0.04) 0%, transparent 45px),
        radial-gradient(circle at 55% 90%, rgba(184,154,120,0.05) 0%, transparent 60px),
        radial-gradient(circle at 10% 95%, rgba(184,154,120,0.03) 0%, transparent 35px),
        /* Base layer */
        linear-gradient(175deg, #f4ece1 0%, #ede2d4 100%);
}

/* ================================
   TEXT SECTIONS
   ================================ */

.text-section {
    padding: 0 4vw 0 8vw;
}

/* Opening Section */
#opening {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    text-align: center;
    padding: 0 4vw;
}

.opening-content {
    text-align: center;
}

.headline {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: clamp(1.8rem, 3.5vw, 3rem);
    color: var(--deep-ink);
    letter-spacing: 0.06em;
    font-variant: small-caps;
    font-feature-settings: 'smcp';
    margin-bottom: 1rem;
}

.subtitle {
    font-family: 'Lora', serif;
    font-style: italic;
    font-size: clamp(1rem, 1.5vw, 1.3rem);
    color: var(--leather);
    letter-spacing: 0.02em;
    opacity: 0.8;
}

/* Section Titles */
.section-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: clamp(1.4rem, 2.5vw, 2rem);
    color: var(--deep-ink);
    letter-spacing: 0.06em;
    font-variant: small-caps;
    font-feature-settings: 'smcp';
    margin-bottom: 2rem;
    padding-top: 2rem;
}

/* Body Text */
.body-text {
    font-family: 'Lora', serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.3vw, 1.15rem);
    line-height: 1.75;
    letter-spacing: 0.01em;
    color: var(--leather);
    margin-bottom: 1.5rem;
    max-width: 42em;
}

.body-text strong {
    font-weight: 600;
    color: var(--deep-ink);
}

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

/* Monospace Accents */
.mono-accent {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85em;
    color: var(--charcoal);
    background: rgba(240,217,181,0.3);
    padding: 0.1em 0.3em;
    border-radius: 2px;
}

/* Interlude Section */
.interlude-section {
    padding-top: 4rem;
    padding-bottom: 4rem;
    background:
        repeating-linear-gradient(
            87deg,
            rgba(180,160,140,0.03) 0px,
            rgba(180,160,140,0.03) 1px,
            transparent 1px,
            transparent 3px
        ),
        linear-gradient(175deg, var(--parchment-warm) 0%, var(--parchment-edge) 100%);
}

.interlude-text {
    font-size: clamp(1.05rem, 1.4vw, 1.2rem);
    text-align: center;
    max-width: 36em;
    margin-left: auto;
    margin-right: auto;
    color: var(--moss);
}

/* Closing Section */
.closing-content {
    padding-bottom: 6rem;
    padding-top: 2rem;
}

.closing-voice {
    font-family: 'Caveat', cursive;
    font-size: clamp(1.1rem, 1.5vw, 1.3rem);
    line-height: 1.8;
    color: var(--leather);
}

.closing-signature {
    margin-top: 3rem;
    text-align: right;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.9rem;
    color: var(--moss);
    opacity: 0.7;
}

/* Bottom Space */
.bottom-space {
    height: 15vh;
}

/* ================================
   BOTANICAL DIVIDERS
   ================================ */

.botanical-divider {
    display: flex;
    justify-content: center;
    padding: 3rem 0;
    opacity: 0.7;
}

.divider-svg {
    width: 40%;
    max-width: 250px;
    height: auto;
}

.divider-elaborate .divider-svg {
    width: 55%;
    max-width: 350px;
}

/* ================================
   SLIDE-REVEAL ANIMATION
   ================================ */

.reveal {
    opacity: 0;
    transform: translateY(24px);
}

.reveal.visible {
    opacity: 1;
    transform: translateY(0);
    transition: transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                opacity 0.5s ease;
}

/* Text selection */
::selection {
    background: var(--wax);
    color: var(--deep-ink);
}

/* ================================
   GUTTER HOVER EFFECT
   ================================ */

body.gutter-hover #margin-panel {
    transform: translateX(-2px);
}

body.gutter-hover #text-panel {
    transform: translateX(2px);
}

/* ================================
   MOBILE RESPONSIVE (< 768px)
   ================================ */

@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    #margin-panel {
        position: sticky;
        top: 0;
        width: 100vw;
        height: auto;
        min-height: unset;
        z-index: 100;
    }

    .margin-content {
        padding: 1.5rem 1rem 1rem;
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.5rem;
    }

    .site-logotype {
        font-size: 1.8rem;
        margin-right: 0.5rem;
    }

    .site-subtitle {
        margin: 0;
        font-size: 0.75rem;
    }

    #toc {
        width: 100%;
        margin: 0.5rem 0 0;
        overflow-x: auto;
    }

    .toc-line { display: none; }

    #toc ul {
        display: flex;
        gap: 0.3rem;
        white-space: nowrap;
        padding-bottom: 0.3rem;
    }

    #toc li { margin: 0; }

    .toc-link {
        padding: 0.2rem 0.5rem;
        gap: 0.3rem;
    }

    .ink-blot,
    .proof-marks,
    .mushroom-cluster {
        display: none;
    }

    #marginalia-container {
        display: none;
    }

    #gutter-line {
        display: none;
    }

    #text-panel {
        margin-left: 0;
        width: 100vw;
    }

    .text-section {
        padding: 0 1.5rem;
    }

    #opening {
        padding: 0 1.5rem;
    }

    .body-text {
        max-width: 100%;
    }
}

/* Scrollbar styling */
#text-panel::-webkit-scrollbar {
    width: 6px;
}

#text-panel::-webkit-scrollbar-track {
    background: var(--parchment-edge);
}

#text-panel::-webkit-scrollbar-thumb {
    background: var(--foxing);
    border-radius: 3px;
}

/* TOC glow for closing state */
.toc-link.final-glow .numeral {
    color: var(--tallow);
    opacity: 1;
    text-shadow: 0 0 8px rgba(201,138,75,0.4);
    transition: all 1.5s ease;
}
