/* ============================================
   scientific.quest - Styles
   Victorian Naturalist's Greenhouse at Midnight
   ============================================ */

/* ---- CSS Custom Properties ---- */
:root {
    --bg-deep: #0a0812;
    --bg-panel: #141019;
    --bg-gradient-end: #0f0e1a;
    --jewel-sapphire: #1b4d89;
    --jewel-emerald: #1a6b52;
    --jewel-amethyst: #6b3fa0;
    --accent-amber: #b87333;
    --text-primary: #e8dfd0;
    --text-secondary: #8a8494;
    --highlight-ruby: #9b2d5e;
    --botanical-jade: #2d8a6e;
    --spring-overshoot: cubic-bezier(0.34, 1.56, 0.64, 1);
    --spring-settle: cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

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

html {
    scroll-behavior: smooth;
}

body {
    background: var(--bg-deep);
    color: var(--text-primary);
    font-family: 'Source Sans 3', 'Source Sans Pro', sans-serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.72;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ---- Global Ambient Warmth Overlay ---- */
#ambient-warmth {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    background: radial-gradient(ellipse at 50% 0%, rgba(184, 115, 51, 0.03), transparent 70%);
    z-index: 1000;
}

/* ---- HUD Measurement Grid ---- */
#hud-grid {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 1;
    background:
        repeating-linear-gradient(0deg, rgba(138, 132, 148, 0.06) 0px, rgba(138, 132, 148, 0.06) 1px, transparent 1px, transparent 40px),
        repeating-linear-gradient(90deg, rgba(138, 132, 148, 0.06) 0px, rgba(138, 132, 148, 0.06) 1px, transparent 1px, transparent 40px);
    opacity: 0;
    animation: gridFadeIn 2s ease-in-out 0.5s forwards;
}

@keyframes gridFadeIn {
    to { opacity: 0.05; }
}

/* ---- Chamber Base Styles ---- */
.chamber {
    position: relative;
    min-height: 100vh;
    overflow: hidden;
}

.chamber-bg {
    position: absolute;
    inset: 0;
    z-index: 0;
}

#chamber-0 .chamber-bg {
    background: var(--bg-deep);
}

#chamber-1 .chamber-bg {
    background: linear-gradient(145deg, #0a0812 0%, #141019 40%, #0f0e1a 100%);
}

#chamber-2 .chamber-bg {
    background: linear-gradient(145deg, #0a0812 0%, #12101b 50%, #0f0e1a 100%);
}

#chamber-3 .chamber-bg {
    background: linear-gradient(145deg, #0a0812 0%, #141019 40%, #0f0e1a 100%);
}

#chamber-4 .chamber-bg {
    background: linear-gradient(180deg, #0a0812 0%, #080610 60%, #060509 100%);
}

#chamber-5 .chamber-bg {
    background: linear-gradient(145deg, #0a0812 0%, #141019 40%, #0f0e1a 100%);
}

/* ---- Candle Glow Effects ---- */
.candle-glow {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 1;
}

.candle-glow-0 {
    background: radial-gradient(ellipse at 30% 20%, rgba(184, 115, 51, 0.06), transparent 60%);
    animation: candleBreath 4s ease-in-out infinite;
}

.candle-glow-1 {
    background: radial-gradient(ellipse at 20% 40%, rgba(184, 115, 51, 0.05), transparent 55%);
    animation: candleBreath 4.3s ease-in-out infinite;
}

.candle-glow-2 {
    background: radial-gradient(ellipse at 80% 30%, rgba(184, 115, 51, 0.05), transparent 55%);
    animation: candleBreath 3.8s ease-in-out infinite;
}

.candle-glow-3 {
    background: radial-gradient(ellipse at 50% 20%, rgba(184, 115, 51, 0.04), transparent 60%);
    animation: candleBreath 4.1s ease-in-out infinite;
}

.candle-glow-4 {
    background: radial-gradient(ellipse at 25% 50%, rgba(184, 115, 51, 0.06), transparent 50%);
    animation: candleBreath 4.5s ease-in-out infinite;
}

.candle-glow-5 {
    background: radial-gradient(ellipse at 50% 40%, rgba(184, 115, 51, 0.08), transparent 55%);
    animation: candleBreath 4s ease-in-out infinite;
}

@keyframes candleBreath {
    0%, 100% {
        opacity: 0.7;
        transform: scale(1);
    }
    50% {
        opacity: 1;
        transform: scale(1.02);
    }
}

/* ---- Chamber 0 — The Dark Glass ---- */
#chamber-0 {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
}

.chamber-0-content {
    position: relative;
    z-index: 10;
    text-align: center;
    opacity: 0;
    animation: titleReveal 1.2s var(--spring-settle) 1.6s forwards;
}

.site-title {
    font-family: 'Nunito Sans', sans-serif;
    font-weight: 300;
    font-size: clamp(2rem, 4vw, 3rem);
    color: var(--text-primary);
    letter-spacing: -0.02em;
    margin-bottom: 1rem;
}

.hud-protocol {
    color: var(--text-secondary);
    animation-delay: 2.2s;
}

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

/* ---- Bubble Clusters ---- */
.bubble-cluster {
    position: absolute;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.bubble-cluster-0 {
    bottom: 15%;
    left: 50%;
    transform: translateX(-50%);
}

.bubble-cluster-1 {
    right: 8%;
    top: 30%;
    align-items: flex-end;
}

.bubble-cluster-final {
    bottom: 20%;
    left: 50%;
    transform: translateX(-50%);
    flex-direction: row;
    gap: 16px;
}

.bubble {
    opacity: 0;
    animation: bubbleRise 8s ease-in-out infinite;
}

.bubble-cluster-0 .bubble:nth-child(2) { animation-delay: 0.12s; }
.bubble-cluster-0 .bubble:nth-child(3) { animation-delay: 0.24s; }
.bubble-cluster-0 .bubble:nth-child(4) { animation-delay: 0.36s; }
.bubble-cluster-0 .bubble:nth-child(5) { animation-delay: 0.48s; }
.bubble-cluster-0 .bubble:nth-child(6) { animation-delay: 0.60s; }

@keyframes bubbleRise {
    0% {
        opacity: 0;
        transform: translateY(30px) translateX(0);
    }
    10% {
        opacity: 0.8;
    }
    25% {
        transform: translateY(-10px) translateX(5px);
    }
    50% {
        transform: translateY(-30px) translateX(-3px);
    }
    75% {
        transform: translateY(-50px) translateX(4px);
    }
    90% {
        opacity: 0.6;
    }
    100% {
        opacity: 0;
        transform: translateY(-70px) translateX(0);
    }
}

.bubble-tiny {
    animation-duration: 10s;
}

.bubble-field-left .bubble-tiny:nth-child(2) { animation-delay: 1.5s; animation-duration: 12s; }
.bubble-field-left .bubble-tiny:nth-child(3) { animation-delay: 3s; animation-duration: 9s; }
.bubble-field-left .bubble-tiny:nth-child(4) { animation-delay: 4.5s; animation-duration: 11s; }
.bubble-field-left .bubble-tiny:nth-child(5) { animation-delay: 6s; animation-duration: 8s; }

.bubble-field-right .bubble-tiny:nth-child(2) { animation-delay: 2s; animation-duration: 11s; }
.bubble-field-right .bubble-tiny:nth-child(3) { animation-delay: 3.5s; animation-duration: 9s; }
.bubble-field-right .bubble-tiny:nth-child(4) { animation-delay: 5s; animation-duration: 10s; }
.bubble-field-right .bubble-tiny:nth-child(5) { animation-delay: 7s; animation-duration: 12s; }

.bubble-field {
    position: absolute;
    z-index: 5;
    display: flex;
    flex-direction: column;
    gap: 20px;
    top: 20%;
}

.bubble-field-left {
    left: 3%;
}

.bubble-field-right {
    right: 3%;
}

/* ---- HUD Labels ---- */
.hud-label {
    font-family: 'Inconsolata', monospace;
    font-weight: 400;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

/* ---- Reading Panels ---- */
.reading-panel {
    position: relative;
    z-index: 10;
    max-width: 680px;
    padding: 3rem 2.5rem;
    background: rgba(20, 16, 25, 0.72);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border: 1px solid rgba(138, 132, 148, 0.08);
    border-radius: 3px;
    margin: 8vh 0;
    opacity: 0;
    transform: translateX(-60px);
    transition: opacity 0.8s var(--spring-settle), transform 0.8s var(--spring-overshoot);
    animation: panelCandleGlow 4s ease-in-out infinite;
}

.reading-panel.visible {
    opacity: 1;
    transform: translateX(0);
}

.reading-panel[data-direction='right'] {
    transform: translateX(60px);
}

.reading-panel[data-direction='right'].visible {
    transform: translateX(0);
}

.panel-left {
    margin-left: 8%;
}

.panel-right {
    margin-left: auto;
    margin-right: 8%;
}

.panel-wide {
    max-width: 780px;
}

@keyframes panelCandleGlow {
    0%, 100% {
        box-shadow: 0 0 80px rgba(184, 115, 51, 0.04);
    }
    50% {
        box-shadow: 0 0 120px rgba(184, 115, 51, 0.07);
    }
}

.panel-glow-edge {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, rgba(184, 115, 51, 0.08), transparent);
    pointer-events: none;
    border-radius: 3px;
}

.panel-glow-right {
    background: linear-gradient(270deg, rgba(184, 115, 51, 0.08), transparent);
}

/* ---- Typography ---- */
.chamber-title {
    font-family: 'Nunito Sans', sans-serif;
    font-weight: 700;
    font-size: clamp(2.4rem, 5.5vw, 4.2rem);
    letter-spacing: -0.02em;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
}

.body-text {
    font-family: 'Source Sans 3', 'Source Sans Pro', sans-serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.72;
    color: var(--text-primary);
    margin-bottom: 1.4em;
}

.body-text:last-child {
    margin-bottom: 0;
}

/* ---- HUD Overlay Panel ---- */
.hud-overlay-panel {
    position: absolute;
    top: 8%;
    left: 5%;
    z-index: 15;
    opacity: 0;
    transition: opacity 1s var(--spring-settle);
}

.hud-overlay-panel.visible {
    opacity: 1;
}

.hud-panel-border {
    background: rgba(10, 8, 18, 0.72);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border: 1px solid rgba(27, 77, 137, 0.2);
    border-radius: 3px;
    padding: 1.2rem 1.5rem;
    min-width: 200px;
}

.hud-panel-title {
    color: var(--jewel-sapphire);
    margin-bottom: 0.8rem;
    font-size: 0.7rem;
    letter-spacing: 0.12em;
}

.hud-data-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.3rem 0;
    border-bottom: 1px solid rgba(138, 132, 148, 0.06);
}

.hud-data-row:last-child {
    border-bottom: none;
}

.hud-value {
    font-family: 'Inconsolata', monospace;
    font-size: 0.8rem;
    color: var(--accent-amber);
    letter-spacing: 0.05em;
}

/* ---- Candle Flame Motifs ---- */
.candle-flame {
    position: absolute;
    z-index: 5;
    opacity: 0;
    transition: opacity 1s ease;
}

.candle-flame.visible {
    opacity: 1;
}

.flame-left {
    left: 3%;
    top: 50%;
}

.flame-right {
    right: 3%;
    bottom: 30%;
}

.flame-outer {
    width: 12px;
    height: 28px;
    background: linear-gradient(to top, rgba(184, 115, 51, 0.6), rgba(184, 115, 51, 0.1));
    border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
    animation: flameFlicker 3s ease-in-out infinite;
    position: relative;
}

.flame-inner {
    width: 6px;
    height: 16px;
    background: linear-gradient(to top, rgba(232, 223, 208, 0.5), rgba(184, 115, 51, 0.2));
    border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
    position: absolute;
    top: 4px;
    left: 3px;
    animation: flameFlickerInner 2.5s ease-in-out infinite;
}

@keyframes flameFlicker {
    0% { transform: scaleY(1) scaleX(1); }
    33% { transform: scaleY(1.1) scaleX(0.95); }
    67% { transform: scaleY(0.92) scaleX(1.05); }
    100% { transform: scaleY(1) scaleX(1); }
}

@keyframes flameFlickerInner {
    0% { transform: scaleY(1); opacity: 0.6; }
    50% { transform: scaleY(1.15); opacity: 0.8; }
    100% { transform: scaleY(1); opacity: 0.6; }
}

/* ---- Specimen Gallery ---- */
#chamber-3 {
    min-height: 140vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8vh 5%;
}

.gallery-title {
    margin-bottom: 4rem;
    text-align: center;
    opacity: 0;
    transition: opacity 0.8s var(--spring-settle);
}

.gallery-title.visible {
    opacity: 1;
}

.specimen-grid {
    display: grid;
    grid-template-columns: repeat(3, 240px);
    grid-template-rows: repeat(2, 320px);
    gap: 2rem;
    z-index: 10;
    position: relative;
}

.specimen-card {
    opacity: 0;
    transform: translateY(40px) scale(0.95);
    transition: opacity 0.6s var(--spring-settle), transform 0.6s var(--spring-overshoot);
}

.specimen-card.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.card-hud-border {
    width: 240px;
    height: 320px;
    background: rgba(10, 8, 18, 0.85);
    border: 1px solid rgba(138, 132, 148, 0.12);
    border-radius: 3px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1.5rem;
    transition: border-color 0.4s ease, box-shadow 0.4s ease;
}

.card-hud-border:hover {
    border-color: rgba(138, 132, 148, 0.25);
    box-shadow: 0 0 30px rgba(184, 115, 51, 0.05);
}

.card-hud-border:hover .specimen-bubble circle {
    animation: bubblePulse 1.5s ease-in-out infinite;
}

@keyframes bubblePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.specimen-bubble {
    margin-bottom: 0.5rem;
}

.specimen-id {
    font-size: 0.65rem;
    letter-spacing: 0.1em;
    color: var(--text-secondary);
}

.specimen-name {
    font-family: 'Source Sans 3', 'Source Sans Pro', sans-serif;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
}

/* ---- Botanical Line Art ---- */
.botanical-vine {
    position: absolute;
    z-index: 3;
    pointer-events: none;
}

.vine-right {
    right: 2%;
    top: 0;
    height: 100%;
    width: 60px;
}

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

.reveal-draw.visible .vine-path {
    stroke-dashoffset: 0;
}

.botanical-flower {
    position: absolute;
    right: 5%;
    top: 50%;
    transform: translateY(-50%);
    width: 250px;
    height: 340px;
    z-index: 3;
    pointer-events: none;
}

/* ---- Chamber Dividers ---- */
.chamber-divider {
    position: relative;
    height: 40px;
    width: 100%;
    z-index: 10;
}

.chamber-divider svg {
    width: 100%;
    height: 100%;
}

/* ---- Chamber 5 — Closing ---- */
#chamber-5 {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.chamber-5-content {
    position: relative;
    z-index: 10;
    text-align: center;
    opacity: 0;
    transition: opacity 1.2s var(--spring-settle);
}

.chamber-5-content.visible {
    opacity: 1;
}

.closing-title {
    font-family: 'Nunito Sans', sans-serif;
    font-weight: 700;
    font-size: clamp(2.4rem, 5.5vw, 4.2rem);
    letter-spacing: -0.02em;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.closing-subtitle {
    font-family: 'Source Sans 3', 'Source Sans Pro', sans-serif;
    font-weight: 400;
    font-size: clamp(1.1rem, 2vw, 1.3rem);
    color: var(--text-secondary);
    line-height: 1.6;
}

.hud-complete {
    position: absolute;
    bottom: 8%;
    right: 5%;
    z-index: 10;
    color: var(--accent-amber);
    opacity: 0;
    transition: opacity 1s ease;
}

.hud-complete.visible {
    opacity: 1;
}

/* ---- Reveal Animations (JS-driven) ---- */
.reveal-fade {
    opacity: 0;
    transition: opacity 0.8s var(--spring-settle);
}

.reveal-fade.visible {
    opacity: 1;
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
    .specimen-grid {
        grid-template-columns: repeat(2, 220px);
        grid-template-rows: repeat(3, 300px);
    }

    .panel-left {
        margin-left: 5%;
    }

    .panel-right {
        margin-right: 5%;
    }

    .hud-overlay-panel {
        position: relative;
        top: auto;
        left: auto;
        margin: 3vh 5%;
    }

    .botanical-flower {
        display: none;
    }
}

@media (max-width: 600px) {
    .specimen-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
        gap: 1.5rem;
        width: 90%;
    }

    .specimen-card,
    .card-hud-border {
        width: 100%;
    }

    .reading-panel {
        margin-left: 4% !important;
        margin-right: 4% !important;
        max-width: none;
        padding: 2rem 1.5rem;
    }

    .botanical-vine {
        display: none;
    }

    .bubble-field {
        display: none;
    }

    .bubble-cluster-1 {
        display: none;
    }
}
