/* ========================================
   ronri.xyz — Arcane Logic Zine
   ======================================== */

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

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

body {
    background-color: #1C1A17;
    color: #C4B5A0;
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 400;
    font-size: clamp(0.95rem, 1.8vw, 1.15rem);
    line-height: 1.72;
    letter-spacing: 0.005em;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

.svg-filters {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* --- Palette Reference ---
   Background Primary:  #1C1A17 (Lampblack)
   Background Secondary: #2A2520 (Charred Oak)
   Surface:             #3D3630 (Tobacco Leaf)
   Text Primary:        #C4B5A0 (Aged Parchment)
   Text Secondary:      #8B7355 (Smoked Umber)
   Accent Warm:         #D4A574 (Tallow Gold)
   Accent Cool:         #7A8B6E (Verdigris Ink)
   Accent Alert:        #A0522D (Sienna Wax)
   Glitch Artifact:     #4A6B8A (Cyanotype Blue)
   Candle Glow:         #E8C87A (Beeswax)
   Goldenrod:           #B8860B (Dark Goldenrod)
--- */

/* --- Candle Cursor Light (Desktop) --- */
#candle-light {
    position: fixed;
    width: 160px;
    height: 160px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(232, 200, 122, 0.06) 0%, transparent 70%);
    pointer-events: none;
    z-index: 9999;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.5s ease;
}

body.candle-active #candle-light {
    opacity: 1;
}

/* --- Table of Contents --- */
#toc-toggle {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 1000;
    cursor: pointer;
    padding: 8px;
    opacity: 0;
    transition: opacity 0.6s ease 2.5s;
}

body.intro-done #toc-toggle {
    opacity: 1;
    transition: opacity 0.6s ease;
}

#toc-toggle:hover .toc-icon path {
    stroke: #E8C87A;
}

.toc-overlay {
    position: fixed;
    inset: 0;
    background: rgba(28, 26, 23, 0.92);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.4s ease;
}

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

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

.toc-title {
    font-family: 'Caveat', cursive;
    font-size: 2rem;
    color: #D4A574;
    margin-bottom: 2rem;
    font-weight: 400;
}

.toc-list {
    list-style: none;
}

.toc-list li {
    margin-bottom: 1rem;
}

.toc-list a {
    font-family: 'Caveat', cursive;
    font-size: 1.4rem;
    color: #C4B5A0;
    text-decoration: none;
    transition: color 0.3s ease;
    position: relative;
}

.toc-list a::before {
    content: attr(data-num);
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.7rem;
    color: #7A8B6E;
    margin-right: 12px;
    letter-spacing: 0.05em;
}

.toc-list a:hover {
    color: #E8C87A;
}

/* Surface / hover state color */
.spread-col:hover .spread-heading {
    text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.3), 0 0 30px rgba(232, 200, 122, 0.05);
}

/* Wax seal hover */
.wax-seal:hover .seal-svg circle:first-child {
    fill: #A0522D;
    filter: brightness(1.1);
}

/* Surface elements */
.fragment-item:hover {
    background-color: #3D3630;
    transition: background-color 0.3s ease;
}

/* --- Typography --- */
.spread-heading {
    font-family: 'Space Grotesk', sans-serif;
    font-size: clamp(2.2rem, 5vw, 4rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    text-transform: uppercase;
    color: #D4A574;
    text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.3);
    margin-bottom: 1.5rem;
    line-height: 1.1;
}

.spread-body {
    color: #C4B5A0;
    margin-bottom: 1.2rem;
}

.spread-annotation {
    font-family: 'Caveat', cursive;
    font-size: clamp(0.8rem, 1.4vw, 1rem);
    color: #7A8B6E;
    transform: rotate(-1deg);
    margin-top: 1rem;
    margin-bottom: 1rem;
    padding-left: 1rem;
    border-left: 2px solid rgba(122, 139, 110, 0.3);
}

.annotation-inline {
    font-family: 'Caveat', cursive;
    color: #B8860B;
    font-size: 1.1em;
}

.keyword-circle {
    font-family: 'Space Grotesk', sans-serif;
    color: #D4A574;
    font-weight: 500;
    border: 1px solid rgba(212, 165, 116, 0.4);
    border-radius: 50%;
    padding: 2px 8px;
    font-size: 0.85em;
    letter-spacing: 0.02em;
}

/* --- Spread Layout --- */
.spread {
    min-height: 100vh;
    display: flex;
    align-items: center;
    padding: 4rem 3rem;
    position: relative;
    background-color: #1C1A17;
}

.spread-col {
    flex: 1;
}

.spread-col-left {
    flex: 0 0 55%;
    padding-right: 1rem;
}

.spread-col-right {
    flex: 0 0 40%;
    padding-left: 1rem;
}

.spread-gutter {
    flex: 0 0 60px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gutter-annotations {
    width: 60px;
    height: 100%;
    max-height: 600px;
}

/* --- Opening Sequence --- */
.spread-opening {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    position: relative;
    overflow: hidden;
}

.opening-candle {
    opacity: 0;
    animation: fadeInCandle 0.5s ease 0.3s forwards;
    z-index: 2;
}

.opening-glow {
    position: absolute;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(232, 200, 122, 0.12) 0%, rgba(232, 200, 122, 0.04) 40%, transparent 70%);
    animation: expandGlow 1.2s ease 0.8s forwards;
    z-index: 1;
}

.opening-title {
    font-family: 'Space Grotesk', sans-serif;
    font-size: clamp(5rem, 12vw, 10rem);
    font-weight: 700;
    color: #D4A574;
    letter-spacing: -0.03em;
    text-transform: uppercase;
    text-shadow: 0 0 60px rgba(232, 200, 122, 0.2), 1px 1px 0 rgba(0, 0, 0, 0.3);
    opacity: 0;
    animation: fadeInTitle 0.8s ease 1.2s forwards;
    z-index: 2;
}

.opening-subtitle {
    font-family: 'Caveat', cursive;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    color: #7A8B6E;
    transform: rotate(-3deg);
    opacity: 0;
    animation: fadeInTitle 0.6s ease 1.6s forwards;
    z-index: 2;
    margin-top: -0.5rem;
}

.opening-tagline {
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 300;
    font-size: clamp(0.85rem, 1.5vw, 1.1rem);
    color: #8B7355;
    letter-spacing: 0.1em;
    opacity: 0;
    animation: fadeInTitle 0.8s ease 2s forwards;
    z-index: 2;
    margin-top: 1.5rem;
}

/* Candle Flame Flicker */
.candle-flame .flame-outer {
    animation: flameFlicker 0.8s ease-in-out infinite alternate;
    transform-origin: 20px 50px;
}

.candle-flame .flame-inner {
    animation: flameFlickerInner 0.6s ease-in-out infinite alternate;
    transform-origin: 20px 45px;
}

@keyframes flameFlicker {
    0% { transform: scaleX(1) scaleY(1) rotate(0deg); }
    50% { transform: scaleX(0.92) scaleY(1.04) rotate(-2deg); }
    100% { transform: scaleX(1.05) scaleY(0.97) rotate(1deg); }
}

@keyframes flameFlickerInner {
    0% { transform: scaleX(1) scaleY(1) rotate(0deg); }
    100% { transform: scaleX(0.88) scaleY(1.06) rotate(2deg); }
}

@keyframes fadeInCandle {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes expandGlow {
    from { width: 0; height: 0; opacity: 0; }
    to { width: 120vmax; height: 120vmax; opacity: 1; }
}

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

.opening-subtitle {
    animation-name: fadeInSubtitle;
}

@keyframes fadeInSubtitle {
    from { opacity: 0; transform: rotate(-3deg) translateY(10px); }
    to { opacity: 1; transform: rotate(-3deg) translateY(0); }
}

/* --- Fixed Title --- */
.fixed-title {
    position: fixed;
    top: 20px;
    left: 24px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: opacity 0.4s ease;
}

.fixed-title.hidden {
    opacity: 0;
    pointer-events: none;
}

.fixed-title-text {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    color: #D4A574;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.mini-flame {
    animation: flameFlicker 0.8s ease-in-out infinite alternate;
    transform-origin: 8px 17px;
}

/* --- Spread Dividers --- */
.spread-divider {
    position: relative;
    width: 100%;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
}

.divider-line {
    position: absolute;
    width: 100%;
    height: 20px;
}

.divider-candle {
    position: relative;
    z-index: 1;
}

.divider-flame {
    animation: flameFlicker 0.8s ease-in-out infinite alternate;
    transform-origin: 10px 15px;
}

/* --- Evidence Spread --- */
.spread-evidence {
    background-color: #1C1A17;
}

.spread-evidence .spread-col-left {
    flex: 0 0 50%;
}

.spread-evidence .spread-col-right {
    flex: 0 0 42%;
}

.evidence-sketch {
    width: 100%;
    height: auto;
    max-height: 70vh;
}

/* --- Glitch Image Treatment --- */
.glitch-image {
    position: relative;
    overflow: hidden;
}

.glitch-layer {
    position: relative;
}

.glitch-layer.glitch-base {
    position: relative;
    z-index: 1;
}

.glitch-layer.glitch-cyan {
    position: absolute;
    inset: 0;
    z-index: 2;
    background: #4A6B8A;
    opacity: 0.15;
    mix-blend-mode: multiply;
    transform: translate(2px, -1px);
    transition: transform 0.3s ease-out, opacity 0.3s ease-out;
    pointer-events: none;
}

.glitch-layer.glitch-warm {
    position: absolute;
    inset: 0;
    z-index: 3;
    background: rgba(212, 165, 116, 0.08);
    mix-blend-mode: multiply;
    transform: translate(-2px, 1px);
    transition: transform 0.3s ease-out;
    pointer-events: none;
}

.glitch-image:hover .glitch-cyan {
    transform: translate(6px, -3px);
}

.glitch-image:hover .glitch-warm {
    transform: translate(-6px, 3px);
}

.glitch-image:hover::after {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent 0px,
        transparent 2px,
        rgba(0, 0, 0, 0.05) 2px,
        rgba(0, 0, 0, 0.05) 3px
    );
    z-index: 4;
    pointer-events: none;
}

/* Mobile: glitch on scroll-into-view */
.glitch-image.glitch-active .glitch-cyan {
    transform: translate(6px, -3px);
}

.glitch-image.glitch-active .glitch-warm {
    transform: translate(-6px, 3px);
}

/* --- Index Spread --- */
.spread-index {
    background-color: #2A2520;
}

.spread-index .spread-col-left {
    flex: 0 0 48%;
}

.spread-index .spread-col-right {
    flex: 0 0 44%;
}

.index-column {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.index-group {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}

.index-bracket {
    width: 20px;
    flex-shrink: 0;
    height: auto;
}

.index-list {
    list-style: none;
    flex: 1;
}

.index-list li {
    display: flex;
    justify-content: space-between;
    padding: 0.35rem 0;
    border-bottom: 1px solid rgba(61, 54, 48, 0.5);
    font-size: clamp(0.85rem, 1.4vw, 1rem);
}

.index-term {
    color: #C4B5A0;
    font-family: 'Source Serif 4', Georgia, serif;
}

.index-ref {
    color: #8B7355;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.85em;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

/* --- Diagram Spread --- */
.spread-diagram {
    flex-direction: column;
    background-color: #1C1A17;
    padding: 4rem 2rem;
}

.diagram-heading {
    text-align: center;
    margin-bottom: 2rem;
}

.diagram-container {
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
}

.logic-diagram-svg {
    width: 100%;
    height: auto;
}

.diagram-caption {
    font-family: 'Caveat', cursive;
    font-size: clamp(0.8rem, 1.4vw, 1rem);
    color: #8B7355;
    text-align: center;
    transform: rotate(-0.5deg);
    margin-top: 2rem;
    max-width: 700px;
    margin-left: auto;
    margin-right: auto;
}

/* Diagram path animation */
.diagram-path {
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    transition: stroke-dashoffset 2s ease;
}

.diagram-path.drawn {
    stroke-dashoffset: 0;
}

.diagram-node {
    opacity: 0;
    transition: opacity 0.5s ease;
}

.diagram-node.visible {
    opacity: 1;
}

/* --- Fragment Spread --- */
.spread-fragment {
    background-color: #2A2520;
    padding: 4rem 3rem;
    display: block;
}

.fragment-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
    max-width: 1100px;
    margin: 0 auto;
}

.fragment-item {
    padding: 1.5rem;
    position: relative;
}

.fragment-quote {
    grid-column: 1 / 3;
    background: rgba(28, 26, 23, 0.6);
    border-left: 3px solid #D4A574;
    padding: 2rem;
}

.fragment-quote blockquote {
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: clamp(1.2rem, 2.5vw, 1.8rem);
    font-weight: 300;
    font-style: italic;
    color: #D4A574;
    line-height: 1.5;
}

.fragment-cite {
    display: block;
    font-family: 'Caveat', cursive;
    color: #8B7355;
    margin-top: 0.75rem;
    font-style: normal;
}

.fragment-image {
    display: flex;
    align-items: center;
    justify-content: center;
}

.fragment-sketch {
    max-width: 240px;
}

.small-sketch {
    width: 100%;
    height: auto;
}

.fragment-note {
    grid-column: 1 / 2;
    background: rgba(28, 26, 23, 0.4);
    padding: 1.5rem;
}

.margin-note {
    font-family: 'Caveat', cursive;
    font-size: clamp(0.9rem, 1.5vw, 1.1rem);
    color: #7A8B6E;
    line-height: 1.6;
    transform: rotate(-0.5deg);
}

.margin-note em {
    color: #B8860B;
    font-style: italic;
}

.fragment-list {
    grid-column: 2 / 4;
    background: rgba(28, 26, 23, 0.5);
    padding: 1.5rem 2rem;
}

.fragment-heading {
    font-family: 'Space Grotesk', sans-serif;
    font-size: clamp(1rem, 2vw, 1.3rem);
    font-weight: 500;
    color: #8B7355;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
    text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.3);
}

.fragment-ul {
    list-style: none;
}

.fragment-ul li {
    padding: 0.3rem 0;
    color: #C4B5A0;
    position: relative;
    padding-left: 1.2rem;
}

.fragment-ul li::before {
    content: '—';
    position: absolute;
    left: 0;
    color: #7A8B6E;
}

.strikethrough {
    text-decoration: line-through;
    color: #8B7355;
    margin-right: 0.5rem;
    opacity: 0.7;
}

.fragment-annotation {
    display: flex;
    align-items: center;
    justify-content: center;
}

.annotation-svg {
    width: 100%;
    max-width: 200px;
    height: auto;
}

.fragment-quote-small {
    display: flex;
    align-items: center;
    grid-column: 2 / 4;
}

.small-quote {
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 300;
    font-style: italic;
    color: #8B7355;
    font-size: clamp(0.95rem, 1.6vw, 1.15rem);
    padding-left: 1rem;
    border-left: 2px solid rgba(139, 115, 85, 0.3);
}

/* --- Seal Spread --- */
.spread-seal {
    background-color: #1C1A17;
}

.seal-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
}

.wax-seal {
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.4)) drop-shadow(0 2px 3px rgba(160, 82, 45, 0.2));
}

.seal-svg {
    width: 120px;
    height: 120px;
}

.seal-text {
    font-family: 'Caveat', cursive;
    color: #8B7355;
    font-size: 1rem;
    text-align: center;
}

/* --- Footer --- */
.site-footer {
    padding: 3rem 2rem 2rem;
    text-align: center;
    background-color: #1C1A17;
    border-top: 1px solid rgba(61, 54, 48, 0.3);
}

.footer-candles {
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: center;
}

.footer-candles-svg {
    width: 300px;
    height: 30px;
}

.footer-flame {
    animation: flameFlicker 0.8s ease-in-out infinite alternate;
}

.footer-candle.lit .footer-flame {
    opacity: 0.9;
}

.footer-candle:nth-child(2) .footer-flame { animation-delay: 0.15s; }
.footer-candle:nth-child(3) .footer-flame { animation-delay: 0.3s; }
.footer-candle:nth-child(5) .footer-flame { animation-delay: 0.1s; }
.footer-candle:nth-child(7) .footer-flame { animation-delay: 0.25s; }

.footer-text {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.75rem;
    color: #8B7355;
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

/* --- Scroll Animation --- */
.anim-target {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.anim-target.anim-visible {
    opacity: 1;
    transform: translateY(0);
}

/* Stagger delay classes applied via JS */
.anim-delay-1 { transition-delay: 0.08s; }
.anim-delay-2 { transition-delay: 0.16s; }
.anim-delay-3 { transition-delay: 0.24s; }
.anim-delay-4 { transition-delay: 0.32s; }
.anim-delay-5 { transition-delay: 0.40s; }
.anim-delay-6 { transition-delay: 0.48s; }
.anim-delay-7 { transition-delay: 0.56s; }

/* --- Torn Edge Decorations --- */
.spread-evidence::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 12px;
    background: linear-gradient(to right,
        #1C1A17 0%, transparent 2%,
        #1C1A17 4%, transparent 8%,
        #1C1A17 12%, transparent 15%,
        #1C1A17 20%, transparent 22%,
        #1C1A17 28%, transparent 30%,
        #1C1A17 35%, transparent 38%,
        #1C1A17 42%, transparent 45%,
        #1C1A17 50%, transparent 52%,
        #1C1A17 55%, transparent 58%,
        #1C1A17 62%, transparent 65%,
        #1C1A17 70%, transparent 72%,
        #1C1A17 78%, transparent 80%,
        #1C1A17 85%, transparent 88%,
        #1C1A17 92%, transparent 95%,
        #1C1A17 100%
    );
    z-index: 5;
    opacity: 0.4;
}

/* --- Responsive / Mobile --- */
@media (max-width: 768px) {
    .spread {
        flex-direction: column;
        padding: 3rem 1.5rem;
    }

    .spread-col-left,
    .spread-col-right {
        flex: 1 1 100%;
        padding: 0;
    }

    .spread-gutter {
        width: 100%;
        flex: 0 0 40px;
        transform: rotate(90deg);
        margin: 1rem 0;
    }

    .gutter-annotations {
        width: 40px;
        max-height: 300px;
    }

    .fragment-grid {
        grid-template-columns: 1fr;
    }

    .fragment-quote,
    .fragment-list,
    .fragment-quote-small {
        grid-column: 1 / -1;
    }

    .spread-heading {
        font-size: clamp(1.8rem, 8vw, 3rem);
    }

    .opening-title {
        font-size: clamp(3rem, 15vw, 6rem);
    }

    .diagram-container {
        overflow-x: auto;
    }

    .logic-diagram-svg {
        min-width: 700px;
    }

    #toc-toggle {
        top: 16px;
        right: 16px;
    }

    .fixed-title {
        top: 14px;
        left: 16px;
    }
}

@media (max-width: 480px) {
    .spread {
        padding: 2rem 1rem;
    }

    .index-list li {
        flex-direction: column;
    }

    .index-ref {
        font-size: 0.75em;
    }
}
