/* ============================================
   ronri.org — Goblincore meets Formal Logic
   A naturalist's journal of logic
   ============================================ */

/* CSS Custom Properties */
:root {
    --bg-parchment: #F5ECD7;
    --text-walnut: #4A3728;
    --text-umber: #5D4E3C;
    --accent-amber: #D4883A;
    --accent-rust: #A0522D;
    --faded-ink: #8B7355;
    --parchment-shadow: #D4C5A9;
    --moss-gold: #B8960C;
    --mushroom-cap: #3D2B1F;
    --baseline: 28px;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    background-color: var(--bg-parchment);
    color: var(--text-umber);
    font-family: 'Source Serif 4', Georgia, 'Times New Roman', serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.72;
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* Paper Grain Overlay */
#paper-grain {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.04;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='1'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px 256px;
}

/* Foxing Stain Effects */
#foxing-stains {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.foxing-stain {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(ellipse at center, var(--parchment-shadow) 0%, transparent 70%);
    opacity: 0.15;
}

/* Background Logic Diagrams */
#background-diagrams {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
    opacity: 0.03;
    transition: opacity 0.8s ease;
}

.bg-diagram {
    position: absolute;
}

/* Drift animations for background diagrams */
@keyframes drift1 {
    0%, 100% { transform: translate(0, 0); }
    25% { transform: translate(8px, -5px); }
    50% { transform: translate(-3px, 8px); }
    75% { transform: translate(5px, 3px); }
}

@keyframes drift2 {
    0%, 100% { transform: translate(0, 0); }
    25% { transform: translate(-6px, 4px); }
    50% { transform: translate(5px, -7px); }
    75% { transform: translate(-3px, -2px); }
}

@keyframes drift3 {
    0%, 100% { transform: translate(0, 0); }
    25% { transform: translate(4px, 6px); }
    50% { transform: translate(-7px, -3px); }
    75% { transform: translate(2px, -5px); }
}

@keyframes drift4 {
    0%, 100% { transform: translate(0, 0); }
    25% { transform: translate(-5px, -4px); }
    50% { transform: translate(6px, 5px); }
    75% { transform: translate(-2px, 7px); }
}

@keyframes drift5 {
    0%, 100% { transform: translate(0, 0); }
    25% { transform: translate(7px, 3px); }
    50% { transform: translate(-4px, -6px); }
    75% { transform: translate(3px, -3px); }
}

.drift-1 { animation: drift1 22s ease-in-out infinite; }
.drift-2 { animation: drift2 26s ease-in-out infinite; }
.drift-3 { animation: drift3 20s ease-in-out infinite; }
.drift-4 { animation: drift4 24s ease-in-out infinite; }
.drift-5 { animation: drift5 28s ease-in-out infinite; }

/* Typography */
h1, h2, h3 {
    font-family: 'Playfair Display', 'Georgia', serif;
    font-weight: 700;
    color: var(--text-walnut);
    letter-spacing: -0.01em;
}

.annotation-text {
    font-family: 'Caveat', cursive;
    color: var(--faded-ink);
    font-size: 0.85rem;
}

.mono-text {
    font-family: 'IBM Plex Mono', 'Courier New', monospace;
    font-weight: 400;
    font-size: 0.9rem;
    color: #6B5B4A;
    font-feature-settings: "ss01";
}

.mono-text-back {
    font-family: 'IBM Plex Mono', 'Courier New', monospace;
    font-weight: 400;
    font-size: 0.9rem;
    color: var(--bg-parchment);
    font-feature-settings: "ss01";
}

.svg-annotation {
    font-family: 'Caveat', cursive;
}

/* Navigation Sigil */
#nav-sigil {
    position: fixed;
    top: 24px;
    left: 24px;
    z-index: 500;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    transition: transform 0.2s ease, opacity 0.2s ease;
    opacity: 0.7;
}

#nav-sigil:hover {
    transform: translateY(-2px);
    opacity: 1;
}

/* Table of Contents Overlay */
#toc-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 400;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(61, 43, 31, 0.4);
    backdrop-filter: blur(4px);
    opacity: 1;
    transition: opacity 0.4s ease;
}

#toc-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

#toc-card {
    background: var(--bg-parchment);
    border: 1px solid var(--faded-ink);
    border-radius: 2px;
    padding: 48px 56px;
    max-width: 460px;
    width: 90%;
    position: relative;
    box-shadow: 0 8px 40px rgba(61, 43, 31, 0.2);
}

.toc-title {
    font-size: clamp(1.6rem, 3vw, 2.2rem);
    margin-bottom: 8px;
}

.toc-subtitle {
    font-family: 'Caveat', cursive;
    color: var(--faded-ink);
    font-size: 1rem;
    margin-bottom: 32px;
}

#toc-nav {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toc-link {
    display: flex;
    align-items: baseline;
    gap: 16px;
    text-decoration: none;
    color: var(--text-umber);
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: 1rem;
    padding: 6px 0;
    border-bottom: 1px solid transparent;
    transition: color 0.2s ease, border-color 0.2s ease;
}

.toc-link::before {
    content: attr(data-num);
    font-family: 'Caveat', cursive;
    color: var(--faded-ink);
    font-size: 0.9rem;
    min-width: 28px;
}

.toc-link:hover {
    color: var(--accent-rust);
    border-bottom-color: var(--parchment-shadow);
}

#toc-close {
    position: absolute;
    top: 16px;
    right: 20px;
    background: none;
    border: none;
    cursor: pointer;
    font-family: 'Caveat', cursive;
    font-size: 1rem;
    color: var(--faded-ink);
    padding: 4px 8px;
    transition: color 0.2s ease;
}

#toc-close:hover {
    color: var(--accent-rust);
}

/* Sections */
.section-opening {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    position: relative;
    z-index: 10;
}

.section-chapter {
    min-height: 100vh;
    display: flex;
    align-items: center;
    padding: 80px 20px;
    position: relative;
    z-index: 10;
}

/* Specimen Cards */
.specimen-card {
    background: var(--bg-parchment);
    border: 1px solid var(--faded-ink);
    border-radius: 2px;
    position: relative;
    perspective: 1200px;
    cursor: default;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.specimen-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(61, 43, 31, 0.1);
}

/* Card flip mechanics */
.specimen-card .card-front,
.specimen-card .card-back {
    backface-visibility: hidden;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.specimen-card .card-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: rotateY(180deg);
    background: var(--mushroom-cap);
    border-radius: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.specimen-card.flipped .card-front {
    transform: rotateY(180deg);
}

.specimen-card.flipped .card-back {
    transform: rotateY(0deg);
}

.card-inner {
    padding: 40px 48px;
}

/* Hero card */
.specimen-card--hero {
    max-width: 600px;
    width: 90%;
    text-align: center;
}

.site-title {
    font-size: clamp(2.8rem, 6vw, 5rem);
    color: var(--text-walnut);
    margin-bottom: 16px;
    line-height: 1.1;
}

.site-subtitle {
    font-family: 'Caveat', cursive;
    font-size: clamp(1.1rem, 2.5vw, 1.4rem);
    color: var(--faded-ink);
    line-height: 1.6;
    margin-bottom: 24px;
}

.title-ornament {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

.title-date {
    font-size: 0.9rem;
}

/* Chapter cards: alternating left-right alignment */
.card-left {
    max-width: 560px;
    width: 85%;
    margin-left: 10%;
    margin-right: auto;
}

.card-right {
    max-width: 560px;
    width: 85%;
    margin-right: 10%;
    margin-left: auto;
}

/* Card content styles */
.card-number {
    display: block;
    margin-bottom: 12px;
    font-size: 0.8rem;
}

.card-title {
    font-size: clamp(1.8rem, 4vw, 2.6rem);
    margin-bottom: 16px;
}

.card-title-small {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: clamp(1.2rem, 2.5vw, 1.6rem);
    color: var(--text-walnut);
    letter-spacing: -0.01em;
    margin-bottom: 12px;
}

.card-rule {
    width: 60px;
    height: 1px;
    background: var(--faded-ink);
    margin-bottom: 20px;
}

.card-body {
    margin-bottom: 20px;
    color: var(--text-umber);
}

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

.logic-notation {
    background: rgba(212, 197, 169, 0.2);
    padding: 16px 24px;
    margin-bottom: 20px;
    border-left: 2px solid var(--parchment-shadow);
    border-radius: 0 2px 2px 0;
}

.card-annotation {
    font-size: 0.85rem;
    margin-top: 8px;
    line-height: 1.5;
}

/* Card back styles */
.card-title-back {
    font-size: clamp(1.4rem, 3vw, 2rem);
    color: var(--bg-parchment);
    margin-bottom: 20px;
}

.card-title-back-small {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: clamp(1rem, 2vw, 1.3rem);
    color: var(--bg-parchment);
    letter-spacing: -0.01em;
    margin-bottom: 16px;
}

.logic-notation-back {
    background: rgba(184, 150, 12, 0.1);
    padding: 16px 24px;
    margin-bottom: 20px;
    border-left: 2px solid var(--moss-gold);
    border-radius: 0 2px 2px 0;
}

.card-annotation-back {
    font-family: 'Caveat', cursive;
    font-size: 0.85rem;
    color: var(--parchment-shadow);
    line-height: 1.5;
}

/* Truth Table */
.truth-table {
    width: 100%;
    max-width: 280px;
    border-collapse: collapse;
    margin: 20px 0;
}

.truth-table th {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: 0.85rem;
    color: var(--text-walnut);
    padding: 8px 12px;
    border-bottom: 1px solid var(--faded-ink);
    text-align: center;
}

.truth-table td {
    padding: 10px 12px;
    text-align: center;
    border-bottom: 1px solid var(--parchment-shadow);
}

/* Spore prints (truth values) */
.spore-print {
    display: inline-block;
    width: 18px;
    height: 18px;
    border-radius: 50%;
}

.spore-true {
    background: radial-gradient(circle, var(--mushroom-cap) 0%, var(--text-walnut) 40%, transparent 70%);
}

.spore-false {
    background: radial-gradient(circle, var(--parchment-shadow) 0%, rgba(212, 197, 169, 0.3) 40%, transparent 70%);
}

/* Venn Diagram */
.venn-diagram {
    display: flex;
    justify-content: center;
    margin: 20px 0;
}

/* Specimen Wall Section */
.section-specimen-wall {
    padding: 80px 20px 120px;
    position: relative;
    z-index: 10;
}

.wall-title {
    text-align: center;
    font-size: clamp(2rem, 4vw, 3rem);
    margin-bottom: 8px;
}

.wall-subtitle {
    text-align: center;
    font-size: 1rem;
    margin-bottom: 56px;
}

.specimen-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 28px;
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 20px;
}

.specimen-card--small {
    min-height: 220px;
    cursor: pointer;
}

.specimen-card--small .card-inner {
    padding: 28px 32px;
}

.specimen-card--small .card-back .card-inner {
    padding: 28px 32px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Colophon Section */
.section-colophon {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    position: relative;
    z-index: 10;
}

.specimen-card--colophon {
    max-width: 480px;
    width: 90%;
    text-align: center;
}

#colophon-sigil {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
}

/* Sigil path-draw animation */
.sigil-path {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 2s ease-in-out;
}

.sigil-dot {
    opacity: 0;
    transition: opacity 0.6s ease-in-out 1.8s;
}

.sigil-animated .sigil-path {
    stroke-dashoffset: 0;
}

.sigil-animated .sigil-dot {
    opacity: 1;
}

.colophon-text {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: clamp(1.6rem, 3vw, 2.4rem);
    color: var(--text-walnut);
    margin-bottom: 16px;
}

.colophon-annotation {
    font-size: 0.95rem;
    line-height: 1.7;
    margin-bottom: 24px;
}

.colophon-year {
    font-size: 0.85rem;
    letter-spacing: 0.05em;
}

/* Scroll-triggered reveal animation */
.reveal-on-scroll {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.8s ease-out, transform 0.8s ease-out;
}

.reveal-on-scroll.revealed {
    opacity: 1;
    transform: translateY(0);
}

/* Background diagram pulse on scroll */
.bg-pulse {
    opacity: 0.08 !important;
}

/* Responsive */
@media (max-width: 768px) {
    .card-left,
    .card-right {
        margin-left: auto;
        margin-right: auto;
        width: 92%;
    }

    .card-inner {
        padding: 28px 24px;
    }

    .specimen-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    #toc-card {
        padding: 36px 28px;
    }

    #nav-sigil {
        top: 16px;
        left: 16px;
    }
}

@media (max-width: 480px) {
    .site-title {
        font-size: 2.4rem;
    }

    .card-title {
        font-size: 1.6rem;
    }

    .specimen-card--hero .card-inner {
        padding: 32px 20px;
    }

    .card-inner {
        padding: 24px 20px;
    }
}

/* Mycelium root-trace growth animation from card corners */
@keyframes rootGrow {
    0% {
        stroke-dashoffset: 100;
        opacity: 0;
    }
    20% {
        opacity: 0.06;
    }
    100% {
        stroke-dashoffset: 0;
        opacity: 0.06;
    }
}

.specimen-card::before {
    content: '';
    position: absolute;
    top: -1px;
    left: -1px;
    right: -1px;
    bottom: -1px;
    border-radius: 2px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.specimen-card:hover::before {
    opacity: 1;
}

/* Pressed-leaf section divider */
.section-chapter + .section-chapter::before {
    content: '';
    display: block;
    width: 40px;
    height: 1px;
    background: var(--parchment-shadow);
    margin: 0 auto;
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
}
