/* ============================================
   continuum.quest - Surreal Corridor Experience
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --corridor-dark: #1a1714;
    --stone-warm: #c9a96e;
    --parchment: #e8e0d0;
    --fog-gray: #8a8278;
    --violet-deep: #6e5c8e;
    --blush-faded: #b8907a;
    --bone-white: #f2ede5;
    --moss-stain: #5a6b52;
    --surface-dark: #2a2520;
    --surface-mid: #d4cfc4;
    --annotation-color: #a89880;

    --room-progress: 0;
    --scroll-pct: 0;
    --current-room: 1;
}

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

html {
    scroll-behavior: auto;
    overflow-x: hidden;
    background: var(--corridor-dark);
}

body {
    font-family: 'Libre Baskerville', 'Georgia', serif;
    font-size: clamp(1rem, 1.8vw, 1.25rem);
    line-height: 1.75;
    color: var(--surface-mid);
    background: var(--corridor-dark);
    overflow-x: hidden;
    min-height: 900vh;
}

/* --- Corridor Container --- */
.corridor {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    perspective: 1200px;
    perspective-origin: 50% 50%;
    overflow: hidden;
}

/* --- Corridor Layers --- */
.corridor-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
}

/* Layer 0: Vanishing Point */
.layer-vanishing {
    z-index: 0;
    background: radial-gradient(
        ellipse at 50% 50%,
        var(--stone-warm) 0%,
        var(--corridor-dark) 70%
    );
    filter: blur(3px);
    opacity: 0.6;
    transition: background 0.5s ease;
}

.layer-vanishing.cool {
    background: radial-gradient(
        ellipse at 50% 50%,
        var(--violet-deep) 0%,
        var(--corridor-dark) 70%
    );
}

/* Layer 1: Architecture */
.layer-architecture {
    z-index: 1;
    pointer-events: none;
}

.corridor-frames {
    width: 100%;
    height: 100%;
    opacity: 0.4;
}

/* Layer 3: Foreground */
.layer-foreground {
    z-index: 10;
    pointer-events: none;
}

.floating-fragment {
    position: absolute;
    opacity: 0;
    animation: drift 20s ease-in-out infinite;
    will-change: transform;
}

.frag-1 {
    width: 80px;
    height: 80px;
    top: 20%;
    left: 8%;
    animation-delay: 0s;
}

.frag-2 {
    width: 50px;
    height: 85px;
    top: 55%;
    right: 10%;
    animation-delay: -7s;
}

.frag-3 {
    width: 70px;
    height: 48px;
    top: 75%;
    left: 15%;
    animation-delay: -14s;
}

@keyframes drift {
    0% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(3px, -2px) rotate(0.3deg); }
    50% { transform: translate(3px, -2px) rotate(0.5deg); }
    75% { transform: translate(-1px, 1px) rotate(-0.2deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}

/* --- Rooms --- */
.room {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: translateZ(-200px) scale(0.85);
    transition: opacity 0.6s ease, transform 0.6s ease;
    will-change: transform, opacity;
    z-index: 2;
}

.room.active {
    opacity: 1;
    transform: translateZ(0) scale(1);
    z-index: 5;
}

.room.exiting {
    opacity: 0;
    transform: translateZ(200px) scale(1.15);
    z-index: 4;
}

.room.entering {
    opacity: 0;
    transform: translateZ(-200px) scale(0.85);
    z-index: 3;
}

/* --- Room Content --- */
.room-content {
    position: relative;
    max-width: 38ch;
    padding: 2rem;
    z-index: 2;
}

.room-archway {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(70vw, 500px);
    height: min(80vh, 620px);
    z-index: -1;
    opacity: 0.5;
    animation: drift 25s ease-in-out infinite;
}

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

/* --- Room Titles --- */
.room-title {
    font-family: 'Playfair Display', 'Georgia', serif;
    font-size: clamp(3rem, 8vw, 7rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--parchment);
    text-shadow: 0 0 40px rgba(201, 169, 110, 0.15);
    margin-bottom: 2rem;
    line-height: 1.1;
}

/* --- Room Text --- */
.room-text {
    max-width: 38ch;
}

.room-text p {
    margin-bottom: 1.5em;
    color: var(--surface-mid);
}

/* --- Room-specific palette shifts --- */
.room-1 .room-title {
    color: var(--parchment);
    text-shadow: 0 0 40px rgba(201, 169, 110, 0.2);
}

.room-2 .room-title {
    color: var(--parchment);
    text-shadow: 0 0 40px rgba(184, 144, 122, 0.15);
}

.room-2 .room-text p {
    color: var(--surface-mid);
}

.room-3 .room-title {
    color: var(--fog-gray);
    text-shadow: 0 0 40px rgba(138, 130, 120, 0.15);
}

.room-3 .room-text p {
    color: var(--fog-gray);
}

.room-4 .room-title {
    color: var(--violet-deep);
    text-shadow: 0 0 40px rgba(110, 92, 142, 0.2);
}

.room-4 .room-text p {
    color: #b0a8be;
}

.room-5 .room-title {
    color: var(--moss-stain);
    text-shadow: 0 0 40px rgba(90, 107, 82, 0.2);
}

.room-5 .room-text p {
    color: #9a9b90;
}

/* --- Diagonal Cuts --- */
.room-diagonal {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.room-1 .room-diagonal {
    clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
}

/* --- Engraving Fragments --- */
.engraving-fragment {
    position: absolute;
    pointer-events: none;
    opacity: 0;
    transition: opacity 1s ease;
}

.fragment-hand {
    width: 80px;
    height: 110px;
    top: 15%;
    right: -120px;
    transform: rotate(-8deg);
    animation: drift 18s ease-in-out infinite;
    animation-delay: -5s;
}

.fragment-botanical {
    width: 90px;
    height: 130px;
    bottom: 10%;
    left: -130px;
    transform: rotate(5deg);
    animation: drift 22s ease-in-out infinite;
    animation-delay: -10s;
}

.room.active .engraving-fragment {
    opacity: 0.6;
}

/* --- Compass Rose --- */
.compass-rose {
    position: absolute;
    width: 80px;
    height: 80px;
    opacity: 0.3;
    bottom: -100px;
    left: 50%;
    transform: translateX(-50%);
}

.compass-group {
    transform-origin: center;
    animation: compass-spin 90s linear infinite;
}

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

.compass-rose-4 {
    opacity: 0.25;
}

.compass-rose-8 {
    opacity: 0.3;
}

.compass-rose-16 {
    opacity: 0.35;
}

/* --- Marginalia --- */
.marginalia-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 20;
}

.marginalia-note {
    position: absolute;
    font-family: 'Caveat', cursive;
    font-size: clamp(0.85rem, 1.4vw, 1.1rem);
    font-weight: 400;
    color: var(--annotation-color);
    opacity: 0;
    transition: opacity 0.8s ease;
    pointer-events: none;
    white-space: nowrap;
    max-width: 18ch;
    white-space: normal;
    line-height: 1.3;
}

.marginalia-note.visible {
    opacity: 0.6;
}

/* --- Floating Compass Indicator --- */
.compass-indicator {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 48px;
    height: 48px;
    z-index: 100;
    opacity: 0.4;
    cursor: default;
    transition: opacity 0.3s ease;
}

.compass-indicator:hover {
    opacity: 0.9;
}

.compass-indicator svg {
    width: 48px;
    height: 48px;
}

.indicator-compass {
    transform-origin: center;
    animation: compass-spin 90s linear infinite;
}

.compass-info {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 8px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.compass-indicator:hover .compass-info {
    opacity: 1;
}

.compass-room,
.compass-progress {
    font-family: 'Caveat', cursive;
    font-size: 0.9rem;
    color: var(--stone-warm);
    white-space: nowrap;
    line-height: 1.4;
}

/* --- Dissolution Animation --- */
.dissolving .dissolve-char {
    display: inline-block;
    transition: transform 0.6s ease, opacity 0.6s ease;
}

.dissolving.dissolve-active .dissolve-char {
    opacity: 0;
}

/* --- Room Transition Dissolution --- */
.room.dissolving-out .room-text {
    transition: filter 0.8s ease, opacity 0.8s ease;
    filter: blur(4px);
    opacity: 0.3;
}

.room.dissolving-out .room-title {
    transition: letter-spacing 0.8s ease, opacity 0.8s ease;
    letter-spacing: 0.3em;
    opacity: 0.2;
}

/* --- Stroke-draw animation for archways --- */
.archway-svg rect,
.archway-svg line,
.archway-svg path,
.archway-svg circle,
.archway-svg ellipse {
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
    transition: stroke-dashoffset 1.5s ease;
}

.room.active .archway-svg rect,
.room.active .archway-svg line,
.room.active .archway-svg path,
.room.active .archway-svg circle,
.room.active .archway-svg ellipse {
    stroke-dashoffset: 0;
}

/* --- Background gradient transition --- */
.corridor::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    background: var(--corridor-dark);
    pointer-events: none;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .room-content {
        max-width: 90vw;
        padding: 1.5rem;
    }

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

    .room-archway {
        width: 90vw;
        height: 70vh;
    }

    .engraving-fragment {
        display: none;
    }

    .marginalia-note {
        display: none;
    }

    .compass-indicator {
        bottom: 16px;
        right: 16px;
    }
}

@media (max-width: 480px) {
    .room-title {
        font-size: clamp(1.8rem, 12vw, 3rem);
    }

    .compass-rose {
        width: 50px;
        height: 50px;
    }
}
