:root {
    --deep-forest: #1e2a1a;
    --sage-mist: #7a8b6f;
    --meadow-parchment: #f0ece3;
    --lichen-gold: #b8a458;
    --bark-umber: #4a3c2e;
    --glitch-magenta: #c44b8b;
    --moss-shadow: #2d3d28;
    --cloud-linen: #faf8f3;
    --parchment-dark: #e8e3d8;
    --parchment-code: #f4f1eb;
    --sage-green-code: #5a6b52;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Source Sans 3', sans-serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.1vw, 1.15rem);
    line-height: 1.72;
    letter-spacing: 0.005em;
    color: var(--deep-forest);
    background: linear-gradient(to bottom, var(--meadow-parchment), var(--parchment-dark));
    background-attachment: fixed;
    overflow-x: hidden;
}

/* === CLEARINGS === */

.clearing {
    min-height: 100vh;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: clamp(2rem, 4vw, 5rem);
    padding: clamp(2rem, 4vw, 5rem);
    align-content: center;
    position: relative;
}

.clearing--hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 2rem;
}

.clearing--left .tavern-card {
    grid-column: 1 / 6;
}

.clearing--left .margin-note {
    grid-column: 6 / 8;
    align-self: center;
}

.clearing--right .tavern-card,
.clearing--right .herbarium-plate {
    grid-column: 3 / 9;
}

.clearing--right .margin-note {
    grid-column: 1 / 3;
    align-self: center;
}

.clearing--farewell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    gap: 3rem;
}

/* === TAVERN SIGN (Hero) === */

.tavern-sign {
    position: relative;
    display: inline-block;
}

.sign-frame {
    width: clamp(320px, 50vw, 520px);
    height: auto;
}

.sign-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    font-size: clamp(2.2rem, 5.5vw, 4.8rem);
    line-height: 1.08;
    letter-spacing: -0.02em;
    color: var(--deep-forest);
    white-space: nowrap;
}

.subtitle {
    font-family: 'Source Sans 3', sans-serif;
    font-weight: 300;
    font-size: clamp(1.1rem, 1.8vw, 1.5rem);
    color: var(--sage-mist);
    letter-spacing: 0.05em;
}

/* === CIRCUIT VINES === */

.circuit-vine {
    max-width: 400px;
    width: 60%;
    height: auto;
    opacity: 0.7;
}

.vine--hero {
    margin-top: 2rem;
}

.vine-path {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 3s ease;
}

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

.vine--transition {
    max-width: 200px;
    width: 30%;
}

.vine--farewell {
    max-width: 400px;
    width: 50%;
}

/* === TRANSITION ZONES === */

.transition-zone {
    min-height: 60vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.transition-zone--tall {
    min-height: 80vh;
}

.flowing-curve {
    width: 100%;
    height: 120px;
    opacity: 0.5;
}

.curve-path {
    stroke-dasharray: 8 4;
    animation: curveBreath 8s ease-in-out infinite;
}

@keyframes curveBreath {
    0%, 100% { stroke-dasharray: 8 4; }
    50% { stroke-dasharray: 12 2; }
}

/* === TAVERN CARDS === */

.tavern-card {
    background: rgba(250, 248, 243, 0.85);
    backdrop-filter: blur(2px);
    border-radius: 1.5rem;
    border: 1px solid var(--sage-mist);
    box-shadow: 0 8px 32px rgba(42, 36, 28, 0.12), 0 2px 8px rgba(42, 36, 28, 0.06);
    padding: clamp(2rem, 3vw, 3.5rem);
    transition: box-shadow 400ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tavern-card:hover {
    box-shadow: 0 12px 40px rgba(42, 36, 28, 0.18), 0 4px 12px rgba(42, 36, 28, 0.1);
}

.card-heading {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    font-size: clamp(1.8rem, 3.5vw, 3rem);
    line-height: 1.08;
    letter-spacing: -0.02em;
    color: var(--deep-forest);
    margin-bottom: 1.5rem;
}

.tavern-card p {
    margin-bottom: 1.2rem;
    color: var(--deep-forest);
}

/* === CODE BLOCKS === */

.code-block {
    background: var(--parchment-code);
    border-left: 0px solid var(--sage-mist);
    border-radius: 0.5rem;
    padding: 1.5rem;
    margin-top: 1rem;
    overflow-x: auto;
    transition: border-left-width 600ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.code-block.entered {
    border-left-width: 3px;
}

.code-block code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85em;
    letter-spacing: 0.03em;
    color: var(--sage-green-code);
    white-space: pre;
    display: block;
    line-height: 1.6;
}

.code-comment { color: var(--sage-mist); }
.code-keyword { color: var(--bark-umber); }
.code-string { color: var(--lichen-gold); }

/* === MARGIN NOTES === */

.margin-note {
    max-width: 280px;
    font-size: 0.9rem;
    color: var(--sage-mist);
    opacity: 0;
    transition: opacity 600ms ease 200ms;
    font-style: italic;
}

.margin-note.visible {
    opacity: 1;
}

.note-bracket {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.4rem;
    color: var(--sage-mist);
    display: block;
    opacity: 0.5;
}

.margin-note p {
    padding: 0.5rem 0;
}

/* === HERBARIUM PLATE === */

.herbarium-plate {
    display: flex;
    align-items: center;
    gap: clamp(2rem, 4vw, 4rem);
    padding: clamp(2rem, 3vw, 3rem);
    position: relative;
    overflow: hidden;
    cursor: pointer;
}

.botanical-circuit {
    width: 300px;
    flex-shrink: 0;
}

.plate-text h2 {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    font-size: clamp(1.8rem, 3.5vw, 3rem);
    line-height: 1.08;
    letter-spacing: -0.02em;
    color: var(--deep-forest);
    margin-bottom: 1.2rem;
}

.plate-text p {
    color: var(--deep-forest);
    line-height: 1.72;
}

.glitch-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0;
}

/* Glitch effect */
.herbarium-plate.glitching .glitch-overlay {
    opacity: 1;
    animation: glitchFlash 800ms steps(4) forwards;
}

.herbarium-plate.glitching .botanical-circuit {
    animation: glitchShake 800ms ease forwards;
}

@keyframes glitchFlash {
    0% { background: transparent; }
    10% { background: linear-gradient(transparent 30%, rgba(196, 75, 139, 0.1) 30%, rgba(196, 75, 139, 0.1) 32%, transparent 32%); }
    30% { background: linear-gradient(transparent 50%, rgba(196, 75, 139, 0.15) 50%, rgba(196, 75, 139, 0.15) 53%, transparent 53%); }
    50% { background: linear-gradient(transparent 20%, rgba(196, 75, 139, 0.12) 20%, rgba(196, 75, 139, 0.12) 21%, transparent 21%, transparent 70%, rgba(196, 75, 139, 0.1) 70%, rgba(196, 75, 139, 0.1) 72%, transparent 72%); }
    70% { background: linear-gradient(transparent 40%, rgba(196, 75, 139, 0.08) 40%, rgba(196, 75, 139, 0.08) 42%, transparent 42%); }
    100% { background: transparent; }
}

@keyframes glitchShake {
    0% { transform: translate(0, 0); filter: none; }
    15% { transform: translate(-3px, 1px); filter: hue-rotate(90deg); }
    30% { transform: translate(2px, -2px); filter: hue-rotate(180deg); }
    45% { transform: translate(-1px, 2px); filter: hue-rotate(270deg); }
    60% { transform: translate(3px, 0); filter: hue-rotate(120deg); }
    80% { transform: translate(-1px, -1px); filter: hue-rotate(30deg); }
    100% { transform: translate(0, 0); filter: none; }
}

/* === WAX SEALS === */

.wax-seals {
    display: flex;
    gap: 2rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.wax-seal {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.wax-seal svg {
    width: 60px;
    height: 60px;
    transform: scale(1);
    transition: transform 600ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.wax-seal.pulse svg {
    animation: sealPulse 600ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes sealPulse {
    0% { transform: scale(0.8); }
    50% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

.seal-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    letter-spacing: 0.03em;
    color: var(--sage-green-code);
}

/* === FAREWELL === */

.farewell-text {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    color: var(--deep-forest);
    text-align: center;
    opacity: 0;
    transition: opacity 1.5s ease;
}

.farewell-text.visible {
    opacity: 1;
}

/* === COMPASS NAVIGATION === */

.compass-nav {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 100;
}

.compass-rose {
    width: 50px;
    height: 50px;
    border: none;
    background: transparent;
    cursor: pointer;
    animation: spin 120s linear infinite;
    position: relative;
    z-index: 2;
}

.compass-rose svg {
    width: 100%;
    height: 100%;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.radial-menu {
    list-style: none;
    position: absolute;
    bottom: 25px;
    right: 25px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 300ms ease;
}

.compass-nav.open .radial-menu {
    pointer-events: auto;
    opacity: 1;
}

.radial-item {
    position: absolute;
    transform: rotate(var(--angle)) translateY(-90px) rotate(calc(-1 * var(--angle)));
    opacity: 0;
    transition: opacity 300ms ease, transform 400ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.compass-nav.open .radial-item {
    opacity: 1;
}

.compass-nav:not(.open) .radial-item {
    transform: rotate(var(--angle)) translateY(0) rotate(calc(-1 * var(--angle)));
}

.radial-item a {
    display: block;
    background: var(--moss-shadow);
    color: var(--cloud-linen);
    text-decoration: none;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    padding: 0.4rem 0.8rem;
    border-radius: 1rem;
    white-space: nowrap;
    border: 1px solid var(--sage-mist);
    transition: background 200ms ease;
}

.radial-item a:hover {
    background: var(--bark-umber);
}

/* === MODULE ENTER ANIMATION === */

.module-enter {
    opacity: 0;
    transform: translateY(40px);
    transition: opacity 800ms ease, transform 800ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.module-enter.entered {
    opacity: 1;
    transform: translateY(0);
}

/* === RESPONSIVE === */

@media (max-width: 768px) {
    .clearing {
        grid-template-columns: repeat(4, 1fr);
        padding: 1.5rem;
    }

    .clearing--left .tavern-card,
    .clearing--right .tavern-card,
    .clearing--right .herbarium-plate {
        grid-column: 1 / 4;
    }

    .clearing--left .margin-note,
    .clearing--right .margin-note {
        grid-column: 1 / 4;
        max-width: none;
    }

    .herbarium-plate {
        flex-direction: column;
    }

    .botanical-circuit {
        width: 200px;
    }

    .transition-zone {
        min-height: 30vh;
    }

    .transition-zone--tall {
        min-height: 40vh;
    }
}
