/* ==========================================================================
   xanadu.science — Styles
   The Pleasure Dome of Inquiry
   ========================================================================== */

/* --- CSS Custom Properties --- */
:root {
    --ground-top: #F5E6C8;
    --ground-bottom: #3D2B1F;
    --text-primary: #2C1A0E;
    --text-secondary: #6B4E37;
    --accent-gold: #B8923F;
    --accent-copper: #7A8B6A;
    --highlight: #D4A84B;
    --artifact-shadow: #1A1209;
    --text-light: #D4C4A8;
    --surface-mid: #C4A882;
    --surface-dark: #8B6E4E;

    --font-display: 'Cormorant Garamond', 'Georgia', serif;
    --font-body: 'Source Serif 4', 'Georgia', serif;
    --font-accent: 'Recursive', 'Courier New', monospace;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    background: linear-gradient(to bottom, #F5E6C8 0%, #C4A882 40%, #8B6E4E 70%, #3D2B1F 100%);
    background-attachment: fixed;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-weight: 380;
    line-height: 1.72;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Typography --- */
.site-title {
    font-family: var(--font-display);
    font-size: clamp(2.6rem, 6vw, 4.8rem);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-primary);
    animation: titleBreathe 10s ease-in-out infinite;
}

@keyframes titleBreathe {
    0%, 100% { font-weight: 500; }
    50% { font-weight: 600; }
}

.site-subtitle {
    font-family: var(--font-accent);
    font-size: 0.8rem;
    font-weight: 400;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-top: 1rem;
    font-variation-settings: 'MONO' 1, 'CASL' 0;
}

.section-heading {
    font-family: var(--font-display);
    font-size: clamp(1.8rem, 4vw, 3rem);
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-primary);
    margin-bottom: 2rem;
}

.section-heading-light {
    color: var(--text-light);
}

.body-text {
    font-family: var(--font-body);
    font-size: clamp(1.05rem, 1.8vw, 1.2rem);
    font-weight: 380;
    line-height: 1.72;
    color: var(--text-primary);
    max-width: 62ch;
    margin-bottom: 1.8rem;
}

.body-text-light {
    color: var(--text-light);
}

.annotation {
    font-family: var(--font-accent);
    font-size: clamp(0.72rem, 1.1vw, 0.85rem);
    font-weight: 400;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent-gold);
    margin-top: 2rem;
    font-variation-settings: 'MONO' 1, 'CASL' 0;
}

.annotation-light {
    color: var(--highlight);
    opacity: 0.8;
}

.vault-text {
    font-family: var(--font-display);
    font-size: clamp(1.4rem, 3vw, 2.2rem);
    font-weight: 300;
    font-style: italic;
    line-height: 1.6;
    color: var(--text-light);
    max-width: 62ch;
    margin-bottom: 2.5rem;
}

/* --- Chamber Layout --- */
.chamber {
    position: relative;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10vh 2rem;
}

/* Chamber One: The Threshold */
#chamber-threshold {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.threshold-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.threshold-content .site-title,
.threshold-content .site-subtitle {
    opacity: 0;
    transform: translateY(-12px);
}

.threshold-content .site-title.visible {
    animation: titleBreathe 10s ease-in-out infinite, thresholdFadeIn 2.4s cubic-bezier(0.25, 0.1, 0.25, 1.0) forwards;
}

.threshold-content .site-subtitle.visible {
    animation: thresholdFadeIn 2.4s cubic-bezier(0.25, 0.1, 0.25, 1.0) 0.3s forwards;
}

@keyframes thresholdFadeIn {
    from {
        opacity: 0;
        transform: translateY(-12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.threshold-line {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 3rem;
    position: relative;
    height: 20px;
    width: 180px;
    opacity: 0;
}

.threshold-line.visible {
    animation: thresholdFadeIn 1.2s cubic-bezier(0.25, 0.1, 0.25, 1.0) forwards;
}

.threshold-line::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--accent-gold);
    transform: scaleX(0);
    transform-origin: center;
    transition: transform 1.2s cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

.threshold-line.visible::before {
    transform: scaleX(1);
}

.threshold-glyph {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 1s ease 0.8s;
}

.threshold-line.visible .threshold-glyph {
    opacity: 1;
}

/* --- Inscribed Threshold Dividers --- */
.inscribed-threshold {
    padding: 8vh 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.threshold-rule {
    position: relative;
    width: 100%;
    max-width: 720px;
    height: 1px;
    background: var(--accent-gold);
    opacity: 0.5;
    display: flex;
    align-items: center;
    justify-content: center;
}

.threshold-rule-dark {
    opacity: 0.35;
}

.threshold-ornament {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    padding: 0 12px;
}

.inscribed-threshold-dark .threshold-ornament {
    background: transparent;
}

/* --- Text Column --- */
.text-column {
    max-width: 720px;
    width: 100%;
    padding: 4vh 0;
}

/* --- Artifact Container --- */
.artifact-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 6vh 0;
}

.artifact-image {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.artifact-svg {
    width: 100%;
    height: auto;
    filter: sepia(0.2) saturate(0.85);
}

/* Astrolabe */
.astrolabe-artifact {
    width: clamp(280px, 65vw, 500px);
    cursor: default;
}

.astrolabe-artifact .artifact-svg {
    animation: gentleSpin 240s linear infinite;
}

/* Armillary */
.armillary-artifact {
    width: clamp(280px, 65vw, 500px);
    cursor: default;
}

.armillary-artifact .artifact-svg {
    animation: gentleSpin 120s linear infinite;
}

/* Counter-rotating rings */
.armillary-ring-outer {
    animation: ringSpinSlow 180s linear infinite;
    transform-origin: 250px 250px;
}

.armillary-ring-mid {
    animation: ringSpinReverse 90s linear infinite;
    transform-origin: 250px 250px;
}

.armillary-ring-inner {
    animation: ringSpinSlow 60s linear infinite;
    transform-origin: 250px 250px;
}

.armillary-ring-meridian {
    animation: ringSpinReverse 200s linear infinite;
    transform-origin: 250px 250px;
}

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

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

/* Flask */
.flask-artifact {
    width: clamp(260px, 55vw, 420px);
    cursor: pointer;
    position: relative;
}

.flask-glow {
    position: absolute;
    width: 300px;
    height: 300px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(212, 168, 75, 0.2) 0%, rgba(184, 146, 63, 0.08) 50%, transparent 70%);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -40%);
    animation: flaskPulse 6s ease-in-out infinite;
    pointer-events: none;
}

@keyframes flaskPulse {
    0%, 100% {
        opacity: 0.6;
        transform: translate(-50%, -40%) scale(1);
    }
    50% {
        opacity: 1;
        transform: translate(-50%, -40%) scale(1.08);
    }
}

/* Flask golden halo on click */
.flask-artifact .flask-halo {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    border-radius: 50%;
    box-shadow: 0 0 60px 30px rgba(212, 168, 75, 0.4);
    opacity: 0;
    pointer-events: none;
    animation: flaskHaloBurst 0.8s ease-out forwards;
}

@keyframes flaskHaloBurst {
    0% { opacity: 0.8; transform: scale(0.8); }
    100% { opacity: 0; transform: scale(1.5); }
}

/* Caustic animations */
.caustic-1 {
    animation: causticDrift1 5s ease-in-out infinite;
}

.caustic-2 {
    animation: causticDrift2 7s ease-in-out infinite;
}

.caustic-3 {
    animation: causticDrift3 6s ease-in-out infinite;
}

@keyframes causticDrift1 {
    0%, 100% { transform: translate(0, 0); opacity: 0.2; }
    50% { transform: translate(8px, -4px); opacity: 0.35; }
}

@keyframes causticDrift2 {
    0%, 100% { transform: translate(0, 0); opacity: 0.15; }
    50% { transform: translate(-6px, 3px); opacity: 0.28; }
}

@keyframes causticDrift3 {
    0%, 100% { transform: translate(0, 0); opacity: 0.15; }
    50% { transform: translate(5px, -6px); opacity: 0.25; }
}

/* Orrery */
.orrery-artifact {
    width: clamp(260px, 55vw, 420px);
    cursor: default;
}

.orrery-spin {
    animation: gentleSpin 180s linear infinite;
}

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

/* --- Instrument Tremor (Shake-Error Recontextualized) --- */
@keyframes instrumentTremor {
    0%, 100% { transform: translateX(0) rotate(0); }
    15% { transform: translateX(-3px) rotate(-0.5deg); }
    30% { transform: translateX(2px) rotate(0.3deg); }
    45% { transform: translateX(-2px) rotate(-0.2deg); }
    60% { transform: translateX(1.5px) rotate(0.15deg); }
    80% { transform: translateX(-1px) rotate(0); }
}

@keyframes instrumentTremorStrong {
    0%, 100% { transform: translateX(0) rotate(0); }
    15% { transform: translateX(-6px) rotate(-1deg); }
    30% { transform: translateX(4px) rotate(0.6deg); }
    45% { transform: translateX(-4px) rotate(-0.4deg); }
    60% { transform: translateX(3px) rotate(0.3deg); }
    80% { transform: translateX(-2px) rotate(0); }
}

.armillary-artifact:hover .artifact-svg {
    animation: instrumentTremor 0.4s ease-in-out, gentleSpin 120s linear infinite;
}

.flask-artifact.tremor .artifact-svg {
    animation: instrumentTremorStrong 0.5s ease-in-out;
}

.astrolabe-artifact:hover .artifact-svg {
    animation: instrumentTremor 0.4s ease-in-out, gentleSpin 240s linear infinite;
}

/* --- Celestial Grid Overlay --- */
.celestial-grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: 0;
}

.celestial-grid-overlay svg {
    width: 100%;
    height: 100%;
}

#chamber-methods {
    position: relative;
}

#chamber-methods .artifact-container,
#chamber-methods .text-column {
    position: relative;
    z-index: 1;
}

/* --- Waveform Overlay --- */
.waveform-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: 0;
}

.waveform-svg {
    position: absolute;
    width: 100%;
    height: 200px;
}

.waveform-1 {
    top: 15%;
    animation: waveformDrift1 8s ease-in-out infinite;
}

.waveform-2 {
    top: 50%;
    animation: waveformDrift2 8s ease-in-out infinite;
}

.waveform-3 {
    top: 80%;
    animation: waveformDrift3 8s ease-in-out infinite;
}

@keyframes waveformDrift1 {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(20px); }
}

@keyframes waveformDrift2 {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(-15px); }
}

@keyframes waveformDrift3 {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(12px); }
}

/* --- Chamber Dark Variants --- */
.chamber-dark .section-heading {
    color: var(--text-light);
}

.chamber-dark .body-text {
    color: var(--text-light);
}

.chamber-dark .annotation {
    color: var(--highlight);
}

.chamber-deepest {
    position: relative;
}

.chamber-deepest .artifact-container,
.chamber-deepest .text-column,
.chamber-deepest .vault-footer {
    position: relative;
    z-index: 1;
}

/* --- Vault Footer --- */
.vault-footer {
    text-align: center;
    padding: 10vh 0 6vh;
}

.vault-domain {
    font-family: var(--font-accent);
    font-size: clamp(0.72rem, 1.1vw, 0.85rem);
    font-weight: 400;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent-gold);
    opacity: 0.6;
    margin-bottom: 1.5rem;
    font-variation-settings: 'MONO' 1, 'CASL' 0;
}

.vault-glyph {
    display: flex;
    justify-content: center;
    margin-bottom: 2rem;
    opacity: 0.5;
}

/* --- Reveal Animation (Scroll-triggered) --- */
.reveal-element {
    opacity: 0;
    transform: translateY(24px);
    transition: opacity 0.8s cubic-bezier(0.25, 0.1, 0.25, 1.0),
                transform 0.8s cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

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

/* --- Artifact Floating Shadow --- */
.artifact-image {
    filter: drop-shadow(0 40px 80px rgba(26, 18, 9, 0.35));
}

/* --- Scroll-triggered Artifact Scaling --- */
.artifact-container .artifact-image {
    transform: scale(0.92);
    opacity: 0.6;
    transition: transform 1s cubic-bezier(0.25, 0.1, 0.25, 1.0),
                opacity 1s cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

.artifact-container.revealed .artifact-image {
    transform: scale(1);
    opacity: 1;
}

/* --- Selection Colors --- */
::selection {
    background: rgba(184, 146, 63, 0.3);
    color: var(--text-primary);
}

/* --- Scrollbar Styling --- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--ground-bottom);
}

::-webkit-scrollbar-thumb {
    background: var(--accent-gold);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--highlight);
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .chamber {
        padding: 6vh 1.2rem;
    }

    .text-column {
        max-width: 100%;
        padding: 3vh 0;
    }

    .inscribed-threshold {
        padding: 5vh 1.2rem;
    }

    .threshold-rule {
        max-width: 100%;
    }

    .astrolabe-artifact,
    .armillary-artifact {
        width: clamp(240px, 80vw, 400px);
    }

    .flask-artifact,
    .orrery-artifact {
        width: clamp(220px, 70vw, 360px);
    }

    .flask-glow {
        width: 200px;
        height: 200px;
    }

    .vault-text {
        font-size: clamp(1.2rem, 4vw, 1.8rem);
    }

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

@media (max-width: 480px) {
    .site-title {
        font-size: clamp(2rem, 8vw, 3rem);
        letter-spacing: 0.1em;
    }

    .chamber {
        padding: 4vh 1rem;
    }
}
