/* ============================================
   bada.casa — Skeuomorphic Alpine Dollhouse
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    /* Ocean Deep Palette */
    --abyssal-ink: #0A1628;
    --bathyal-blue: #0F2A4A;
    --photic-teal: #1B5E7A;
    --lantern-gold: #F0C96A;
    --frost-breath: #E8F0F4;
    --coral-blush: #E88B6A;
    --sea-glass: #A7C7D6;
    --alpine-mist: #B8D8E8;
    --deep-hull: #1A3448;
    --pale-tide: #C8DDE8;

    /* Dynamic scroll-driven properties */
    --room-bg: #0A1628;
    --text-color: #E8F0F4;
    --accent-color: #F0C96A;
    --scroll-pct: 0;
}

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

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    font-family: 'Karla', sans-serif;
    font-weight: 400;
    line-height: 1.72;
    letter-spacing: 0.01em;
    color: var(--pale-tide);
    background: var(--abyssal-ink);
    overflow-x: hidden;
    position: relative;
}

/* --- Background Gradient --- */
#bg-gradient {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        to top,
        #0A1628 0%,
        #0F2A4A 20%,
        #1B5E7A 40%,
        #A7C7D6 65%,
        #B8D8E8 80%,
        #E8F0F4 100%
    );
    z-index: -2;
    pointer-events: none;
}

/* --- Cross-Section Frame (left wall) --- */
#cross-section-frame {
    position: fixed;
    top: 0;
    left: 0;
    width: 60px;
    height: 100vh;
    z-index: 100;
    pointer-events: none;
    overflow: hidden;
}

.frame-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transition: opacity 0.6s ease;
    opacity: 0;
}

.frame-volcanic {
    background:
        repeating-linear-gradient(
            180deg,
            #0A1628 0px,
            #0F2A4A 8px,
            #1A3448 12px,
            #0A1628 16px
        );
    border-right: 2px solid #1B5E7A;
}

.frame-volcanic.active { opacity: 1; }

.frame-coral {
    background:
        repeating-linear-gradient(
            175deg,
            #0F2A4A 0px,
            #1B5E7A 6px,
            #E88B6A 8px,
            #0F2A4A 14px
        );
    border-right: 2px solid #A7C7D6;
}

.frame-coral.active { opacity: 1; }

.frame-timber {
    background:
        repeating-linear-gradient(
            182deg,
            #1A3448 0px,
            #0F2A4A 4px,
            #1B5E7A 6px,
            #1A3448 10px
        );
    border-right: 2px solid #F0C96A;
}

/* Wood grain overlay */
.frame-timber::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        0deg,
        transparent 0px,
        rgba(240,201,106,0.06) 2px,
        transparent 4px
    );
}

.frame-timber.active { opacity: 1; }

.frame-stone {
    background:
        repeating-linear-gradient(
            178deg,
            #A7C7D6 0px,
            #B8D8E8 5px,
            #A7C7D6 8px,
            #1B5E7A 10px,
            #A7C7D6 14px
        );
    border-right: 2px solid #1B5E7A;
}

.frame-stone.active { opacity: 1; }

.frame-alpine {
    background:
        repeating-linear-gradient(
            181deg,
            #B8D8E8 0px,
            #E8F0F4 3px,
            #B8D8E8 5px,
            #A7C7D6 7px,
            #E8F0F4 10px
        );
    border-right: 2px solid #A7C7D6;
}

.frame-alpine.active { opacity: 1; }

/* --- Altitude Thermometer --- */
#altitude-thermometer {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    height: 60vh;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.thermometer-track {
    width: 8px;
    height: 100%;
    background: rgba(167,199,214,0.2);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(167,199,214,0.3);
}

.thermometer-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 0%;
    background: linear-gradient(to top, #E88B6A, #F0C96A);
    border-radius: 4px;
    transition: height 0.15s ease-out;
}

.altitude-labels {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
    padding: 2px 0;
}

.altitude-label {
    font-family: 'Caveat', cursive;
    font-size: 0.85rem;
    color: var(--sea-glass);
    opacity: 0.6;
    transition: opacity 0.4s ease, color 0.4s ease;
    white-space: nowrap;
}

.altitude-label.active {
    opacity: 1;
    color: var(--lantern-gold);
}

/* --- Staircase Thread --- */
#staircase-thread {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99;
    pointer-events: none;
}

/* --- Room Sections --- */
.room {
    position: relative;
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 5vh 0;
    z-index: 1;
}

.room-panel {
    position: relative;
    width: 85vw;
    min-height: 90vh;
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 12px 48px rgba(0,30,60,0.35);
    /* Wood grain texture overlay */
    background-image: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 8px,
        rgba(255,255,255,0.015) 8px,
        rgba(255,255,255,0.015) 10px
    );
    opacity: 0;
    transform: translateX(-30px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

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

/* Asymmetric zigzag positioning */
.room-left .room-panel {
    margin-left: 4vw;
    margin-right: auto;
    transform: translateX(-30px);
}

.room-left .room-panel.visible {
    transform: translateX(0);
}

.room-right .room-panel {
    margin-left: 11vw;
    margin-right: auto;
    transform: translateX(30px);
}

.room-right .room-panel.visible {
    transform: translateX(0);
}

.room-center .room-panel {
    margin-left: auto;
    margin-right: auto;
    transform: translateY(30px);
}

.room-center .room-panel.visible {
    transform: translateY(0);
}

/* --- Door Arch Transitions --- */
.door-arch {
    position: relative;
    width: 200px;
    height: 100px;
    margin: -20px auto 0;
    z-index: 2;
}

.door-frame {
    width: 100%;
    height: 100%;
    clip-path: ellipse(45% 48% at 50% 100%);
    background: repeating-linear-gradient(
        0deg,
        #1A3448 0px,
        #0F2A4A 3px,
        #1A3448 6px
    );
    border: 2px solid #A7C7D6;
    border-radius: 50% 50% 0 0;
    position: relative;
}

.door-frame::before,
.door-frame::after {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #F0C96A;
    opacity: 0.6;
    top: 60%;
}

.door-frame::before { left: 15px; }
.door-frame::after { right: 15px; }

/* --- Room Content Base --- */
.room-content {
    position: relative;
    z-index: 2;
    padding: clamp(2rem, 5vw, 4rem);
}

.room-heading {
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    font-size: clamp(1.8rem, 4.5vw, 3.6rem);
    color: var(--frost-breath);
    text-shadow: 0 2px 4px rgba(10,22,40,0.4);
    letter-spacing: 0.02em;
    margin-bottom: 1.2rem;
}

.room-body {
    font-family: 'Karla', sans-serif;
    font-weight: 400;
    font-size: clamp(0.95rem, 1.8vw, 1.15rem);
    color: #C8DDE8;
    line-height: 1.72;
    letter-spacing: 0.01em;
    margin-bottom: 1rem;
    max-width: 55ch;
}

.room-annotation {
    font-family: 'Caveat', cursive;
    font-weight: 400;
    font-size: clamp(1rem, 2vw, 1.4rem);
    color: var(--lantern-gold);
    margin-top: 1.5rem;
}

/* --- Skeuomorphic Button --- */
.skeu-button {
    font-family: 'Karla', sans-serif;
    font-weight: 500;
    font-size: clamp(0.9rem, 1.5vw, 1.05rem);
    color: var(--frost-breath);
    background: linear-gradient(135deg, #1B5E7A 0%, #0F2A4A 100%);
    border: none;
    padding: 12px 28px;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 3px 3px 8px rgba(0,0,0,0.4), inset 1px 1px 2px rgba(255,255,255,0.15);
    transition: box-shadow 0.2s ease, transform 0.1s ease;
    margin-top: 1.5rem;
    display: inline-block;
}

.skeu-button:hover {
    box-shadow: 4px 4px 12px rgba(0,0,0,0.5), inset 1px 1px 2px rgba(255,255,255,0.2);
    transform: scale(1.02);
}

.skeu-button:active {
    box-shadow: inset 2px 2px 6px rgba(0,0,0,0.5);
    transform: translateY(1px);
}

/* ===== ROOM 1: Ocean Floor ===== */
#room-ocean {
    background: transparent;
}

#room-ocean .room-panel {
    background-color: var(--abyssal-ink);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Bioluminescent dots */
.bioluminescent-field {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

.bio-dot {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--lantern-gold);
    opacity: 0;
    animation: bioPulse 3s ease-in-out infinite;
    box-shadow: 0 0 12px 4px rgba(240,201,106,0.3);
}

@keyframes bioPulse {
    0%, 100% { opacity: 0.15; transform: scale(0.8); }
    50% { opacity: 0.6; transform: scale(1.3); }
}

/* Water caustics */
.caustics-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
    background:
        radial-gradient(ellipse 80px 60px at 20% 30%, rgba(167,199,214,0.08) 0%, transparent 70%),
        radial-gradient(ellipse 100px 50px at 60% 50%, rgba(167,199,214,0.06) 0%, transparent 70%),
        radial-gradient(ellipse 70px 80px at 80% 20%, rgba(167,199,214,0.07) 0%, transparent 70%),
        radial-gradient(ellipse 90px 70px at 40% 70%, rgba(167,199,214,0.05) 0%, transparent 70%);
    animation: causticsShift 8s ease-in-out infinite alternate;
    opacity: 0.15;
}

@keyframes causticsShift {
    0% {
        background-position: 0 0, 10px 5px, -5px 10px, 8px -3px;
        transform: scale(1);
    }
    100% {
        background-position: 15px 10px, -8px -5px, 12px -8px, -10px 12px;
        transform: scale(1.05);
    }
}

/* Anglerfish */
.anglerfish {
    position: absolute;
    z-index: 1;
    opacity: 0.7;
}

.anglerfish-tl {
    top: 8%;
    left: 5%;
    width: 100px;
    animation: anglerDrift 6s ease-in-out infinite alternate;
}

.anglerfish-br {
    bottom: 12%;
    right: 5%;
    width: 90px;
    animation: anglerDrift 7s ease-in-out infinite alternate-reverse;
}

@keyframes anglerDrift {
    0% { transform: translate(0, 0) rotate(-2deg); }
    100% { transform: translate(10px, -8px) rotate(2deg); }
}

.angler-light {
    animation: anglerGlow 2s ease-in-out infinite;
}

@keyframes anglerGlow {
    0%, 100% { opacity: 0.5; r: 3; }
    50% { opacity: 1; r: 5; }
}

/* Ocean content */
.ocean-content {
    text-align: center;
    z-index: 3;
}

.ocean-title {
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    font-size: clamp(3rem, 8vw, 6rem);
    color: var(--frost-breath);
    text-shadow: 0 2px 8px rgba(10,22,40,0.5);
    letter-spacing: 0.02em;
    margin-bottom: 0.5rem;
    display: inline-flex;
}

.float-letter {
    display: inline-block;
    transform: translateY(var(--offset, 0));
    animation: letterFloat 3s ease-in-out infinite;
    animation-delay: calc(var(--offset, 0) * 0.1s);
}

@keyframes letterFloat {
    0%, 100% { transform: translateY(var(--offset, 0)); }
    50% { transform: translateY(calc(var(--offset, 0) * -1)); }
}

.ocean-subtitle {
    font-family: 'Caveat', cursive;
    font-weight: 400;
    font-size: clamp(1.2rem, 2.5vw, 1.8rem);
    color: var(--lantern-gold);
    margin-bottom: 2rem;
}

/* House silhouette */
.house-silhouette {
    width: 80px;
    height: 70px;
    margin: 0 auto;
    display: block;
    animation: houseWobble 3s ease-in-out infinite;
}

@keyframes houseWobble {
    0%, 100% { transform: rotate(-1deg); }
    50% { transform: rotate(1deg); }
}

.house-window {
    animation: windowGlow 2.5s ease-in-out infinite;
}

@keyframes windowGlow {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* ===== ROOM 2: Coral Shelf ===== */
#room-coral .room-panel {
    background-color: var(--bathyal-blue);
}

.coral-split {
    display: flex;
    min-height: 90vh;
}

.coral-text-panel {
    flex: 0 0 60%;
    padding: clamp(2rem, 5vw, 4rem);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.coral-porthole-panel {
    flex: 0 0 40%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.porthole {
    position: relative;
    width: min(280px, 100%);
    height: min(280px, 35vw);
    border-radius: 50%;
    overflow: hidden;
}

.porthole-frame {
    position: absolute;
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
    border-radius: 50%;
    border: 8px solid #1A3448;
    box-shadow:
        inset 0 0 20px rgba(0,0,0,0.3),
        0 4px 12px rgba(0,0,0,0.3);
    z-index: 2;
    pointer-events: none;
    background: transparent;
}

.porthole-frame::before {
    content: '';
    position: absolute;
    top: -12px;
    left: -12px;
    right: -12px;
    bottom: -12px;
    border-radius: 50%;
    border: 3px solid #A7C7D6;
    opacity: 0.4;
}

.porthole-glass {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: linear-gradient(180deg, #0F2A4A 0%, #1B5E7A 60%, #0A1628 100%);
    position: relative;
    overflow: hidden;
}

/* Waves */
.seascape-waves {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 70%;
}

.wave {
    animation: waveMotion 8s ease-in-out infinite;
}

.wave-1 { animation-delay: 0s; }
.wave-2 { animation-delay: -2s; }
.wave-3 { animation-delay: -4s; }

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

.coral-drawing {
    position: absolute;
    bottom: 10%;
    left: 10%;
    width: 80%;
    height: 60%;
    opacity: 0.8;
}

/* ===== ROOM 3: Timber Hall ===== */
#room-timber .room-panel {
    background-color: var(--photic-teal);
}

.pine-trunk {
    position: absolute;
    top: 0;
    height: 100%;
    z-index: 1;
    opacity: 0.5;
}

.pine-trunk-left {
    left: 3%;
    width: 50px;
}

.pine-trunk-right {
    right: 8%;
    width: 45px;
}

.timber-content {
    margin-left: 10%;
    margin-right: 15%;
}

/* Fireplace */
.fireplace-container {
    position: absolute;
    bottom: 5%;
    right: 5%;
    width: 200px;
    height: 150px;
    z-index: 2;
}

.fireplace-svg {
    width: 100%;
    height: 100%;
}

.flame {
    transform-origin: bottom center;
}

.flame-1 {
    animation: flameFlicker1 1.5s ease-in-out infinite alternate;
}

.flame-2 {
    animation: flameFlicker2 1.2s ease-in-out infinite alternate;
}

.flame-3 {
    animation: flameFlicker3 0.8s ease-in-out infinite alternate;
}

@keyframes flameFlicker1 {
    0% { transform: scaleY(1) scaleX(1); opacity: 0.9; }
    100% { transform: scaleY(1.08) scaleX(0.95); opacity: 0.7; }
}

@keyframes flameFlicker2 {
    0% { transform: scaleY(1) scaleX(1); opacity: 0.8; }
    100% { transform: scaleY(0.92) scaleX(1.05); opacity: 0.9; }
}

@keyframes flameFlicker3 {
    0% { transform: scaleY(1); opacity: 0.4; }
    100% { transform: scaleY(1.15); opacity: 0.6; }
}

/* Fireplace glow */
.fireplace-glow {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 50%;
    height: 50%;
    background: radial-gradient(ellipse at 80% 90%, rgba(240,201,106,0.08) 0%, transparent 60%);
    animation: glowPulse 4s ease-in-out infinite;
    z-index: 0;
    pointer-events: none;
}

@keyframes glowPulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* ===== ROOM 4: Alpine Meadow ===== */
#room-meadow .room-panel {
    background-color: var(--sea-glass);
}

#room-meadow .room-heading,
.meadow-heading {
    color: var(--deep-hull);
    text-shadow: 0 1px 3px rgba(167,199,214,0.3);
}

#room-meadow .room-body {
    color: var(--deep-hull);
}

#room-meadow .room-annotation {
    color: var(--photic-teal);
}

.meadow-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.meadow-scatter {
    transition: transform 0.3s ease;
}

.scatter-1 { margin-left: 5%; }
.scatter-2 { margin-left: 12%; max-width: 50ch; }
.scatter-3 { margin-left: 2%; max-width: 48ch; }
.scatter-4 { margin-left: 18%; }

/* Meadow flowers */
.meadow-flower {
    position: absolute;
    z-index: 1;
    opacity: 0.6;
}

.flower-1 {
    bottom: 10%;
    left: 8%;
    width: 40px;
    animation: flowerSway 4s ease-in-out infinite;
}

.flower-2 {
    top: 15%;
    right: 12%;
    width: 35px;
    animation: flowerSway 5s ease-in-out infinite reverse;
}

.flower-3 {
    bottom: 25%;
    right: 25%;
    width: 38px;
    animation: flowerSway 4.5s ease-in-out infinite;
    animation-delay: -1s;
}

@keyframes flowerSway {
    0%, 100% { transform: rotate(-3deg); }
    50% { transform: rotate(3deg); }
}

/* Butterfly */
.butterfly {
    position: absolute;
    top: 20%;
    left: 40%;
    width: 50px;
    z-index: 3;
    animation: butterflyFly 12s ease-in-out infinite;
}

@keyframes butterflyFly {
    0% { transform: translate(0, 0) rotate(-5deg); }
    25% { transform: translate(60px, -30px) rotate(5deg); }
    50% { transform: translate(20px, -50px) rotate(-3deg); }
    75% { transform: translate(-40px, -20px) rotate(8deg); }
    100% { transform: translate(0, 0) rotate(-5deg); }
}

.wing-left,
.wing-right {
    transform-origin: center right;
    animation: wingFlutter 0.3s ease-in-out infinite alternate;
}

.wing-right {
    transform-origin: center left;
    animation-delay: 0.15s;
}

@keyframes wingFlutter {
    0% { transform: scaleX(1); }
    100% { transform: scaleX(0.6); }
}

/* ===== ROOM 5: Summit ===== */
#room-summit .room-panel {
    background: linear-gradient(to top, #B8D8E8, #E8F0F4);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
}

.summit-content {
    text-align: center;
    z-index: 2;
}

.summit-heading {
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    font-size: clamp(2.5rem, 7vw, 5rem);
    color: var(--deep-hull);
    text-shadow: 0 2px 6px rgba(184,216,232,0.4);
    letter-spacing: 0.02em;
    margin-bottom: 2rem;
}

/* Flag */
.summit-flag {
    width: 100px;
    height: 140px;
    margin: 0 auto;
    display: block;
}

.flag-fabric {
    animation: flagWave 2s ease-in-out infinite;
    transform-origin: left center;
}

@keyframes flagWave {
    0%, 100% {
        d: path("M30,15 Q55,20 65,30 Q75,40 55,50 Q45,55 30,50 Z");
    }
    50% {
        d: path("M30,15 Q60,25 70,32 Q78,38 58,48 Q42,53 30,50 Z");
    }
}

/* Mountain panorama */
.mountain-panorama {
    position: absolute;
    bottom: 10%;
    left: -50%;
    width: 200%;
    height: 200px;
    z-index: 1;
    animation: panMountains 120s linear infinite;
}

@keyframes panMountains {
    0% { transform: translateX(0); }
    100% { transform: translateX(-50%); }
}

/* ===== Footer ===== */
#site-footer {
    position: relative;
    z-index: 1;
    padding: 2rem 0 1.5rem;
    text-align: center;
}

.footer-mountains {
    width: 100%;
    height: 60px;
    display: block;
    margin-bottom: 1rem;
}

.footer-text {
    font-family: 'Caveat', cursive;
    font-size: 1.1rem;
    color: var(--sea-glass);
    opacity: 0.7;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    #cross-section-frame {
        width: 30px;
    }

    #altitude-thermometer {
        right: 10px;
        height: 40vh;
    }

    .altitude-label {
        font-size: 0.7rem;
    }

    .room-panel {
        width: 92vw;
        min-height: 85vh;
        border-radius: 16px;
    }

    .room-left .room-panel,
    .room-right .room-panel {
        margin-left: 2vw;
    }

    .coral-split {
        flex-direction: column;
    }

    .coral-text-panel {
        flex: 1;
    }

    .coral-porthole-panel {
        flex: 0 0 auto;
        padding: 1rem;
    }

    .porthole {
        width: 200px;
        height: 200px;
    }

    .timber-content {
        margin-left: 5%;
        margin-right: 5%;
    }

    .fireplace-container {
        width: 140px;
        height: 105px;
    }

    .scatter-1,
    .scatter-2,
    .scatter-3,
    .scatter-4 {
        margin-left: 2%;
    }

    .anglerfish-tl { width: 70px; }
    .anglerfish-br { width: 60px; }
}

@media (max-width: 480px) {
    #cross-section-frame {
        display: none;
    }

    #altitude-thermometer {
        height: 30vh;
        right: 6px;
    }

    .altitude-labels {
        display: none;
    }

    .room-panel {
        width: 96vw;
        border-radius: 12px;
    }

    .ocean-title {
        font-size: clamp(2rem, 10vw, 3.5rem);
    }

    .pine-trunk { display: none; }

    .fireplace-container {
        width: 100px;
        height: 75px;
        bottom: 2%;
        right: 2%;
    }
}
