/* ========================================
   ronri.day - Gilded Botanical Theorem
   ======================================== */

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

:root {
    /* Palette */
    --vellum-white: #FAF5EB;
    --library-umber: #2C2618;
    --theorem-gold: #C5A55A;
    --aged-walnut: #5C5040;
    --parchment-cream: #E8DCC8;
    --faded-bronze: #8A7A5A;
    --verdigris-mint: #7ABFA0;
    --twilight-lavender: #A78BBF;
    --paradox-orange: #FF6B35;
    --pressed-fern: #6B8F5E;
    --dark-chamber: #3A3228;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Commissioner', sans-serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.15vw, 1.15rem);
    line-height: 1.78;
    color: var(--aged-walnut);
    background: var(--vellum-white);
    overflow-x: hidden;
}

/* --- Scroll Container --- */
#theorem-scroll {
    scroll-snap-type: y proximity;
}

/* --- Chambers --- */
.chamber {
    min-height: 100vh;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    scroll-snap-align: start;
}

/* --- Phi Return Button (top-right) --- */
#phi-return {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100;
    background: none;
    border: none;
    font-family: 'Commissioner', serif;
    font-size: 1.5rem;
    color: var(--theorem-gold);
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.3s ease, transform 0.3s ease;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#phi-return:hover {
    opacity: 1;
    transform: rotate(360deg);
}

/* --- Vine Progress Indicator --- */
#vine-progress {
    position: fixed;
    right: 10px;
    top: 10%;
    height: 80%;
    width: 20px;
    z-index: 90;
    opacity: 0.5;
}

#vine-path {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 0.1s ease-out;
}

/* --- Fibonacci Watermark --- */
.fibonacci-watermark {
    position: absolute;
    width: 80%;
    height: 80%;
    top: 10%;
    left: 10%;
    opacity: 0.03;
    pointer-events: none;
}

.fibonacci-watermark.rotated-15 {
    transform: rotate(15deg);
}
.fibonacci-watermark.rotated-30 {
    transform: rotate(30deg);
}
.fibonacci-watermark.rotated-45 {
    transform: rotate(45deg);
}
.fibonacci-watermark.rotated-60 {
    transform: rotate(60deg);
}

/* --- Theorem Spine --- */
.theorem-spine {
    max-width: 680px;
    width: 90%;
    margin: 0 auto;
    position: relative;
    padding: 2rem 1.5rem;
    text-align: center;
    z-index: 2;
}

.theorem-spine::before,
.theorem-spine::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--theorem-gold);
    opacity: 0.2;
}

.theorem-spine::before {
    left: 0;
}

.theorem-spine::after {
    right: 0;
}

/* --- Chamber Labels --- */
.chamber-label {
    font-family: 'Commissioner', sans-serif;
    font-weight: 300;
    font-size: clamp(1rem, 1.5vw, 1.3rem);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--theorem-gold);
    margin-bottom: clamp(2rem, 4vh, 4rem);
}

/* --- Logic Notation --- */
.logic-notation {
    font-family: 'Fira Code', monospace;
    font-weight: 400;
    font-size: clamp(0.85rem, 1vw, 1rem);
    color: var(--faded-bronze);
    background: rgba(197, 165, 90, 0.08);
    padding: 0.15em 0.4em;
    border-radius: 2px;
}

/* --- SVG Logic Text --- */
.svg-logic-text {
    font-family: 'Fira Code', monospace;
}

/* ========================================
   CHAMBER 1: AXIOM
   ======================================== */
#axiom {
    background: var(--vellum-white);
}

.axiom-content {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

/* Gold horizontal line */
.gold-line {
    width: 0;
    height: 1px;
    background: var(--theorem-gold);
    opacity: 0.4;
    transition: width 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    margin: 1rem 0;
}

.gold-line.active {
    width: 60vw;
}

/* Title: RONRI */
.axiom-title {
    font-family: 'Commissioner', sans-serif;
    font-weight: 300;
    font-size: clamp(4rem, 8vw, 7rem);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--theorem-gold);
    line-height: 1.1;
    display: flex;
    gap: 0.05em;
}

.axiom-title .char {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.axiom-title .char.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Subtitle: .DAY */
.axiom-subtitle {
    font-family: 'Fira Code', monospace;
    font-weight: 400;
    font-size: clamp(1.2rem, 2vw, 1.8rem);
    color: var(--faded-bronze);
    letter-spacing: 0.15em;
    opacity: 0;
    transform: translateY(5px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.axiom-subtitle.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Tendrils SVG */
.tendrils-svg {
    width: 60vw;
    max-width: 800px;
    height: 60px;
    opacity: 0;
    transition: opacity 1s ease 0.5s;
}

.tendrils-svg.visible {
    opacity: 0.7;
}

.tendrils-svg path {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 1.5s ease;
}

.tendrils-svg.visible path {
    stroke-dashoffset: 0;
}

/* ========================================
   CHAMBER DIVIDERS
   ======================================== */
.chamber-divider {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40px;
    z-index: 5;
}

.divider-vine {
    width: 100%;
    height: 40px;
}

.divider-line {
    transition: x1 0.6s ease, x2 0.6s ease;
}

.chamber-divider.active .divider-line {
    x: 0;
}

.chamber-divider.active .divider-branches-left path,
.chamber-divider.active .divider-branches-right path {
    opacity: 0.6;
    stroke-dasharray: 600;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 1.2s ease 0.3s, opacity 0.3s ease 0.3s;
}

.divider-branches-left path,
.divider-branches-right path {
    stroke-dasharray: 600;
    stroke-dashoffset: 600;
}

/* ========================================
   CHAMBER 2: HYPOTHESIS
   ======================================== */
#hypothesis {
    background: var(--library-umber);
    color: var(--parchment-cream);
    transition: background 0.6s ease;
}

.body-text {
    font-family: 'Commissioner', sans-serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.15vw, 1.15rem);
    line-height: 1.78;
    margin-bottom: clamp(1.5rem, 3vh, 3rem);
}

#hypothesis .body-text {
    color: var(--parchment-cream);
}

#hypothesis .chamber-label {
    color: var(--theorem-gold);
}

.hypothesis-text {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.hypothesis-text.visible {
    opacity: 1;
    transform: translateY(0);
}

/* --- Lens Flares --- */
.lens-flare {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    z-index: 1;
    opacity: 0;
    transition: opacity 1s ease;
}

.lens-flare.active {
    opacity: 1;
}

.flare-1 {
    width: 200px;
    height: 200px;
    top: 8%;
    left: 15%;
    background: radial-gradient(ellipse at center, rgba(197, 165, 90, 0.08) 0%, transparent 70%);
    animation: flare-drift-1 8s ease-in-out infinite;
}

.flare-2 {
    width: 150px;
    height: 150px;
    top: 12%;
    right: 20%;
    background: radial-gradient(ellipse at center, rgba(197, 165, 90, 0.06) 0%, transparent 70%);
    animation: flare-drift-2 10s ease-in-out infinite;
    /* Hexagonal shape via clip-path */
    clip-path: polygon(50% 0%, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%);
}

.flare-3 {
    width: 120px;
    height: 120px;
    top: 5%;
    left: 50%;
    background: radial-gradient(ellipse at center, rgba(197, 165, 90, 0.1) 0%, transparent 70%);
    animation: flare-drift-3 12s ease-in-out infinite;
    clip-path: polygon(50% 0%, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%);
}

/* Intensified lens flares for Chamber 4 */
.flare-4 {
    width: 250px;
    height: 250px;
    top: 15%;
    left: 10%;
    background: radial-gradient(ellipse at center, rgba(197, 165, 90, 0.1) 0%, transparent 70%);
    animation: flare-drift-1 9s ease-in-out infinite;
    clip-path: polygon(50% 0%, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%);
}

.flare-5 {
    width: 180px;
    height: 180px;
    top: 20%;
    right: 15%;
    background: radial-gradient(ellipse at center, rgba(197, 165, 90, 0.1) 0%, transparent 70%);
    animation: flare-drift-2 11s ease-in-out infinite;
}

@keyframes flare-drift-1 {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(30px, 15px); }
}

@keyframes flare-drift-2 {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(-20px, 25px); }
}

@keyframes flare-drift-3 {
    0%, 100% { transform: translate(0, 0); }
    33% { transform: translate(15px, -10px); }
    66% { transform: translate(-10px, 20px); }
}

/* --- Branching Asides --- */
.branching-aside {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 3;
    opacity: 0;
    width: 200px;
}

.aside-left {
    left: 2%;
    transform: translateY(-50%) translateX(-30px);
    transition: opacity 0.4s ease 0.2s, transform 0.4s ease 0.2s;
}

.aside-right {
    right: 2%;
    transform: translateY(-50%) translateX(30px);
    transition: opacity 0.4s ease 0.4s, transform 0.4s ease 0.4s;
}

.branching-aside.visible {
    opacity: 1;
}

.aside-left.visible {
    transform: translateY(-50%) translateX(0);
}

.aside-right.visible {
    transform: translateY(-50%) translateX(0);
}

/* Glitch entry for asides */
.branching-aside.glitch-enter {
    animation: glitch-aside 0.26s ease-out;
}

@keyframes glitch-aside {
    0% { transform: translateY(-50%) translateX(-20px); opacity: 0; }
    23% { transform: translateY(-50%) translateX(5px); opacity: 0.7; }
    46% { transform: translateY(-50%) translateX(-3px); opacity: 0.9; }
    100% { transform: translateY(-50%) translateX(0); opacity: 1; }
}

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

/* ========================================
   CHAMBER 3: DEMONSTRATION
   ======================================== */
#demonstration {
    background: var(--vellum-white);
}

.specimen {
    margin-bottom: clamp(3rem, 5vh, 6rem);
    opacity: 0;
    transform: translateX(-5px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.specimen.visible {
    opacity: 1;
    transform: translateX(0);
}

.specimen.glitch-enter {
    animation: glitch-specimen 0.26s ease-out forwards;
}

@keyframes glitch-specimen {
    0% { transform: translateX(-5px); opacity: 0.5; }
    23% { transform: translateX(4px); opacity: 0.8; }
    46% { transform: translateX(-2px); opacity: 0.9; }
    100% { transform: translateX(0); opacity: 1; }
}

.specimen-svg {
    max-width: 400px;
    width: 100%;
    margin: 0 auto;
    display: block;
}

/* Gold highlights on hover */
.specimen-svg:hover circle[fill="#C5A55A"],
.specimen-svg:hover path[stroke="#C5A55A"],
.specimen-svg:hover text[fill="#C5A55A"] {
    filter: brightness(1.3);
    transition: filter 0.3s ease;
}

.specimen-caption {
    text-align: center;
    margin-top: 1rem;
    font-style: italic;
    font-size: clamp(0.85rem, 1vw, 1rem);
}

/* ========================================
   CHAMBER 4: LEMMA
   ======================================== */
#lemma {
    background: var(--dark-chamber);
    color: var(--parchment-cream);
}

#lemma .theorem-spine::before,
#lemma .theorem-spine::after {
    background: var(--theorem-gold);
    opacity: 0.12;
}

.lemma-text {
    font-family: 'Commissioner', sans-serif;
    font-weight: 300;
    font-size: clamp(1.2rem, 2vw, 1.6rem);
    line-height: 1.8;
    color: var(--parchment-cream);
    margin-bottom: clamp(2rem, 4vh, 4rem);
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.lemma-text.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Aurora highlights */
.aurora-highlight.mint {
    color: var(--verdigris-mint);
    font-weight: 500;
}

.aurora-highlight.lavender {
    color: var(--twilight-lavender);
    font-weight: 500;
}

/* --- Aurora Ribbons --- */
.aurora-ribbon {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0;
    transition: opacity 1s ease;
}

.aurora-ribbon.active {
    opacity: 1;
}

.aurora-1 {
    background: linear-gradient(
        135deg,
        transparent 20%,
        rgba(122, 191, 160, 0.15) 35%,
        transparent 50%,
        rgba(167, 139, 191, 0.12) 65%,
        transparent 80%
    );
    background-size: 200% 200%;
    animation: aurora-shift-1 12s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.aurora-2 {
    background: linear-gradient(
        225deg,
        transparent 15%,
        rgba(167, 139, 191, 0.18) 30%,
        transparent 45%,
        rgba(122, 191, 160, 0.1) 60%,
        transparent 75%
    );
    background-size: 200% 200%;
    animation: aurora-shift-2 15s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.aurora-3 {
    background: linear-gradient(
        180deg,
        transparent 25%,
        rgba(122, 191, 160, 0.08) 40%,
        rgba(167, 139, 191, 0.1) 55%,
        transparent 70%
    );
    background-size: 200% 200%;
    animation: aurora-shift-3 18s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes aurora-shift-1 {
    0% { background-position: 0% 0%; }
    50% { background-position: 100% 100%; }
    100% { background-position: 0% 0%; }
}

@keyframes aurora-shift-2 {
    0% { background-position: 100% 0%; }
    50% { background-position: 0% 100%; }
    100% { background-position: 100% 0%; }
}

@keyframes aurora-shift-3 {
    0% { background-position: 50% 0%; }
    33% { background-position: 0% 50%; }
    66% { background-position: 100% 50%; }
    100% { background-position: 50% 0%; }
}

/* ========================================
   CHAMBER 5: Q.E.D.
   ======================================== */
#qed {
    background: var(--library-umber);
}

.qed-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2;
    position: relative;
}

.qed-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
}

.qed-letter {
    width: clamp(3rem, 8vw, 7rem);
    height: auto;
}

.qed-letter[data-letter="dot"] {
    width: clamp(1.5rem, 3vw, 3rem);
}

.qed-path {
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    transition: stroke-dashoffset 1.5s ease;
}

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

/* Final tree */
.final-tree-svg {
    width: 80%;
    max-width: 600px;
    margin-top: 3rem;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 1.2s ease, transform 1.2s ease;
}

.final-tree-svg.visible {
    opacity: 1;
    transform: translateY(0);
}

.tree-path {
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
    transition: stroke-dashoffset 2s ease;
}

.final-tree-svg.visible .tree-path {
    stroke-dashoffset: 0;
}

/* Return to Axiom button */
.return-axiom {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    background: none;
    border: none;
    font-family: 'Commissioner', sans-serif;
    font-weight: 300;
    font-size: 0.9rem;
    color: var(--theorem-gold);
    cursor: pointer;
    opacity: 0;
    letter-spacing: 0.1em;
    transition: opacity 0.5s ease;
    animation: pulse-gentle 3s ease-in-out infinite;
}

.return-axiom.visible {
    opacity: 0.7;
}

.return-axiom:hover {
    opacity: 1;
}

@keyframes pulse-gentle {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 0.8; }
}

/* ========================================
   GLITCH EFFECTS
   ======================================== */
.glitch-active {
    animation: glitch-viewport 0.08s ease-out;
}

@keyframes glitch-viewport {
    0% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(3px);
        filter: hue-rotate(15deg);
    }
    50% {
        transform: translateX(-2px);
    }
    75% {
        transform: translateX(4px);
    }
    100% {
        transform: translateX(0);
        filter: none;
    }
}

/* Glitch text double effect */
.glitch-text-active {
    text-shadow: 2px 0 var(--paradox-orange), -2px 0 var(--verdigris-mint);
}

/* Glitch border flash */
.glitch-border-active {
    box-shadow: inset 0 0 0 2px var(--paradox-orange) !important;
}

/* ========================================
   PRESSED SPECIMEN SHADOWS
   ======================================== */
.specimen-shadow {
    box-shadow:
        4px 6px 12px rgba(44, 38, 24, 0.08),
        -1px -1px 0 rgba(250, 245, 235, 0.5);
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 900px) {
    .branching-aside {
        position: relative;
        top: auto;
        left: auto;
        right: auto;
        transform: none;
        width: 80%;
        max-width: 300px;
        margin: 2rem auto;
    }

    .aside-left,
    .aside-right {
        transform: translateY(20px);
    }

    .aside-left.visible,
    .aside-right.visible {
        transform: translateY(0);
    }

    #vine-progress {
        display: none;
    }
}

@media (max-width: 600px) {
    .axiom-title {
        letter-spacing: 0.1em;
    }

    .qed-letter {
        width: clamp(2rem, 12vw, 5rem);
    }

    .qed-letter[data-letter="dot"] {
        width: clamp(1rem, 4vw, 2rem);
    }
}

/* ========================================
   DIVIDER LINE ANIMATION
   ======================================== */
.chamber-divider.active .divider-line {
    animation: divider-expand 0.6s ease forwards;
}

@keyframes divider-expand {
    0% {
        x1: 500;
        x2: 500;
    }
    100% {
        x1: 40;
        x2: 960;
    }
}
