/* ============================================
   layer2.quest — Dark-Academia Quest Journal
   Design Implementation
   ============================================ */

/* --- CSS Custom Properties (Design Palette) --- */
:root {
    --library-dark: #0A0808;
    --mahogany: #2A1810;
    --burnished-gold: #D4A853;
    --ivory: #E8DCC8;
    --aged-leather: #A89070;
    --marble-white: #E8E4E0;
    --marble-vein: #C4C0B8;
    --crimson-seal: #8A2A2A;
}

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

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

body {
    background: var(--library-dark);
    color: var(--ivory);
    font-family: 'Lora', serif;
    font-size: clamp(1rem, 1.3vw, 1.15rem);
    line-height: 1.85;
    overflow-x: hidden;
}

/* --- Floating Golden Orbs --- */
#orbs-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
    overflow: hidden;
}

.golden-orb {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle at 40% 40%, rgba(212, 168, 83, 0.35), rgba(212, 168, 83, 0.08) 60%, transparent 80%);
    pointer-events: none;
    animation: floatOrb linear infinite;
}

@keyframes floatOrb {
    0% {
        transform: translateY(0) translateX(0) scale(1);
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    90% {
        opacity: 1;
    }
    100% {
        transform: translateY(-110vh) translateX(40px) scale(0.6);
        opacity: 0;
    }
}

/* --- Candlelight Vignette Overlay --- */
#vignette-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 4;
    background: radial-gradient(ellipse 60% 55% at 50% 50%, transparent 0%, rgba(10, 8, 8, 0.3) 50%, rgba(10, 8, 8, 0.85) 100%);
    opacity: 0;
    transition: opacity 1.5s ease;
}

#vignette-overlay.visible {
    opacity: 1;
}

/* --- Book Spine Navigation --- */
#spine-nav {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 0;
    opacity: 0;
    transition: opacity 0.8s ease 2s;
}

#spine-nav.visible {
    opacity: 1;
}

.spine {
    width: 32px;
    height: 48px;
    background: var(--mahogany);
    border: 1px solid var(--aged-leather);
    border-right: none;
    border-radius: 3px 0 0 3px;
    cursor: pointer;
    position: relative;
    transition: width 0.3s ease, background 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    overflow: hidden;
}

.spine:hover {
    width: 130px;
    background: var(--mahogany);
}

.spine.active {
    background: var(--mahogany);
    box-shadow: 0 0 12px rgba(212, 168, 83, 0.5), inset 0 0 8px rgba(212, 168, 83, 0.15);
    border-color: var(--burnished-gold);
}

.spine-label {
    font-family: 'IM Fell English', serif;
    font-size: 0.7rem;
    color: var(--aged-leather);
    white-space: nowrap;
    padding: 0 8px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.spine:hover .spine-label {
    opacity: 1;
}

.spine.active .spine-label {
    color: var(--burnished-gold);
}

/* --- Quest Sections --- */
.quest-section {
    min-height: 100vh;
    width: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    will-change: transform, opacity;
    transition: transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94), opacity 0.6s ease;
}

.section-inner {
    max-width: 960px;
    width: 100%;
    padding: 80px 40px;
    position: relative;
    z-index: 2;
}

/* --- Dark Sections --- */
.section-dark {
    background: var(--library-dark);
}

/* --- Marble Sections --- */
.section-marble {
    background: var(--marble-white);
    color: var(--library-dark);
    position: relative;
}

.marble-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    background:
        radial-gradient(ellipse 80% 60% at 20% 30%, rgba(200, 192, 184, 0.4) 0%, transparent 60%),
        radial-gradient(ellipse 60% 80% at 70% 60%, rgba(200, 192, 184, 0.3) 0%, transparent 55%),
        radial-gradient(ellipse 40% 30% at 50% 80%, rgba(168, 144, 112, 0.12) 0%, transparent 50%),
        radial-gradient(ellipse 100% 100% at 40% 50%, rgba(232, 228, 224, 0.6) 0%, transparent 70%),
        linear-gradient(135deg, rgba(196, 192, 184, 0.15) 0%, transparent 40%, rgba(196, 192, 184, 0.1) 60%, transparent 100%),
        linear-gradient(45deg, transparent 30%, rgba(196, 192, 184, 0.08) 45%, transparent 55%);
    background-color: var(--marble-white);
}

/* --- Candle Flame --- */
.candle-flame {
    position: relative;
    width: 30px;
    height: 50px;
    margin: 0 auto 30px;
}

.candle-flame-small {
    width: 20px;
    height: 35px;
    margin-bottom: 20px;
}

.flame-body {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 14px;
    height: 28px;
    background: radial-gradient(ellipse at 50% 90%, var(--burnished-gold) 0%, var(--burnished-gold) 20%, rgba(212, 168, 83, 0.6) 50%, transparent 70%);
    border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
    animation: flicker 0.15s infinite alternate;
    filter: blur(0.5px);
}

.candle-flame-small .flame-body {
    width: 10px;
    height: 20px;
}

.flame-glow {
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 60px;
    background: radial-gradient(circle, rgba(212, 168, 83, 0.25) 0%, transparent 70%);
    border-radius: 50%;
    animation: glowPulse 2s infinite alternate;
}

.candle-flame-small .flame-glow {
    width: 40px;
    height: 40px;
}

@keyframes flicker {
    0% { transform: translateX(-50%) scaleY(1) scaleX(1); opacity: 1; }
    25% { transform: translateX(-50%) scaleY(1.04) scaleX(0.96); opacity: 0.95; }
    50% { transform: translateX(-50%) scaleY(0.96) scaleX(1.02); opacity: 1; }
    75% { transform: translateX(-50%) scaleY(1.02) scaleX(0.98); opacity: 0.97; }
    100% { transform: translateX(-50%) scaleY(0.98) scaleX(1.01); opacity: 1; }
}

@keyframes glowPulse {
    0% { opacity: 0.6; transform: translateX(-50%) scale(1); }
    100% { opacity: 1; transform: translateX(-50%) scale(1.15); }
}

/* --- Hero Section (Section 0) --- */
#section-0 .section-inner {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding-top: 0;
    padding-bottom: 0;
}

.hero-title {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: clamp(2.8rem, 8vw, 6rem);
    letter-spacing: 0.06em;
    color: var(--burnished-gold);
    opacity: 0;
    transform: translateY(20px);
    animation: fadeInUp 1.5s ease 0.5s forwards;
    text-shadow: 0 0 40px rgba(212, 168, 83, 0.2);
}

.hero-subtitle {
    font-family: 'Lora', serif;
    font-size: clamp(1rem, 2vw, 1.4rem);
    font-weight: 400;
    color: var(--ivory);
    margin-top: 20px;
    opacity: 0;
    animation: fadeInUp 1.2s ease 1.8s forwards;
    letter-spacing: 0.04em;
}

.scroll-indicator {
    margin-top: 60px;
    opacity: 0;
    animation: fadeInUp 1s ease 2.8s forwards;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.scroll-text {
    font-family: 'IM Fell English', serif;
    font-size: 0.85rem;
    color: var(--aged-leather);
    letter-spacing: 0.05em;
}

.scroll-arrow {
    width: 18px;
    height: 18px;
    border-right: 2px solid var(--aged-leather);
    border-bottom: 2px solid var(--aged-leather);
    transform: rotate(45deg);
    animation: bounceArrow 2s ease infinite;
}

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

@keyframes bounceArrow {
    0%, 20%, 50%, 80%, 100% { transform: rotate(45deg) translateY(0); }
    40% { transform: rotate(45deg) translateY(8px); }
    60% { transform: rotate(45deg) translateY(4px); }
}

/* --- Chapter Headings --- */
.chapter-heading {
    font-family: 'IM Fell English', serif;
    font-size: clamp(0.85rem, 1.2vw, 1rem);
    font-weight: 400;
    color: var(--aged-leather);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    margin-bottom: 8px;
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.section-marble .chapter-heading {
    color: var(--aged-leather);
}

.section-title {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: clamp(2.4rem, 5vw, 4.2rem);
    letter-spacing: 0.01em;
    color: var(--burnished-gold);
    margin-bottom: 40px;
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.8s ease 0.15s, transform 0.8s ease 0.15s;
}

.section-title-dark {
    color: var(--mahogany);
}

/* Reveal animations triggered by JS */
.quest-section.in-view .chapter-heading,
.quest-section.in-view .section-title {
    opacity: 1;
    transform: translateY(0);
}

/* --- Quest Cards --- */
.quest-card {
    position: relative;
    background: linear-gradient(145deg, rgba(42, 24, 16, 0.9) 0%, rgba(42, 24, 16, 0.7) 100%);
    border: 1px solid var(--aged-leather);
    padding: 36px 32px;
    margin-bottom: 24px;
    transform: rotate(-0.5deg);
    transition: transform 0.4s ease, box-shadow 0.4s ease, border-color 0.4s ease;
    opacity: 0;
    cursor: pointer;
}

.quest-card:nth-child(even) {
    transform: rotate(0.5deg);
}

.quest-card-dark {
    background: linear-gradient(145deg, rgba(42, 24, 16, 0.95) 0%, rgba(10, 8, 8, 0.9) 100%);
    border-color: var(--aged-leather);
}

.quest-section.in-view .quest-card {
    opacity: 1;
}

.quest-card:hover {
    transform: rotate(0deg) scale(1.01);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 20px rgba(212, 168, 83, 0.08);
    border-color: var(--burnished-gold);
}

/* Card ornament corners */
.card-ornament {
    position: absolute;
    width: 20px;
    height: 20px;
    border-color: var(--burnished-gold);
    opacity: 0;
    transition: opacity 0.5s ease;
}

.quest-section.in-view .card-ornament {
    opacity: 0.6;
}

.quest-card:hover .card-ornament {
    opacity: 1;
}

.corner-tl {
    top: 6px;
    left: 6px;
    border-top: 2px solid;
    border-left: 2px solid;
    border-color: inherit;
    border-color: var(--burnished-gold);
}

.corner-tr {
    top: 6px;
    right: 6px;
    border-top: 2px solid;
    border-right: 2px solid;
    border-color: var(--burnished-gold);
}

.corner-bl {
    bottom: 6px;
    left: 6px;
    border-bottom: 2px solid;
    border-left: 2px solid;
    border-color: var(--burnished-gold);
}

.corner-br {
    bottom: 6px;
    right: 6px;
    border-bottom: 2px solid;
    border-right: 2px solid;
    border-color: var(--burnished-gold);
}

.card-content {
    position: relative;
    z-index: 2;
}

.quest-label {
    font-family: 'IM Fell English', serif;
    font-size: 0.9rem;
    color: var(--burnished-gold);
    margin-bottom: 12px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.card-text {
    font-family: 'Lora', serif;
    font-size: clamp(0.95rem, 1.2vw, 1.1rem);
    line-height: 1.85;
    color: var(--ivory);
}

.section-marble .card-text {
    color: var(--library-dark);
}

.section-marble .quest-label {
    color: var(--mahogany);
}

/* Difficulty markers */
.difficulty-marker {
    display: inline-block;
    margin-top: 16px;
    font-family: 'IM Fell English', serif;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    padding: 4px 14px;
    border-radius: 2px;
    text-transform: uppercase;
}

.difficulty-intermediate {
    color: var(--burnished-gold);
    border: 1px solid rgba(212, 168, 83, 0.4);
}

.difficulty-advanced {
    color: var(--aged-leather);
    border: 1px solid rgba(168, 144, 112, 0.4);
}

.difficulty-expert {
    color: var(--crimson-seal);
    border: 1px solid rgba(138, 42, 42, 0.4);
}

/* --- Cards Grid --- */
.cards-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
}

.cards-grid-2 {
    grid-template-columns: 1fr;
}

@media (min-width: 768px) {
    .cards-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    .cards-grid-2 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* --- Quest Map (Section 3) --- */
.quest-map {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
}

.map-lines {
    width: 100%;
    max-width: 800px;
    height: auto;
    opacity: 0;
    transition: opacity 1s ease 0.3s;
}

.quest-section.in-view .map-lines {
    opacity: 1;
}

.map-path {
    stroke-dashoffset: 1000;
    animation: none;
}

.quest-section.in-view .map-path {
    animation: drawPath 2s ease forwards 0.5s;
}

@keyframes drawPath {
    from { stroke-dashoffset: 1000; }
    to { stroke-dashoffset: 0; }
}

.map-description {
    max-width: 600px;
    text-align: center;
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.8s ease 1s, transform 0.8s ease 1s;
}

.quest-section.in-view .map-description {
    opacity: 1;
    transform: translateY(0);
}

.map-text {
    font-family: 'Lora', serif;
    font-size: clamp(0.95rem, 1.2vw, 1.1rem);
    line-height: 1.85;
    color: var(--library-dark);
}

/* --- Marginalia --- */
.marginalia {
    margin-top: 48px;
    padding: 24px 32px;
    border-left: 2px solid var(--aged-leather);
    opacity: 0;
    transform: translateX(-10px);
    transition: opacity 0.8s ease 0.4s, transform 0.8s ease 0.4s;
}

.quest-section.in-view .marginalia {
    opacity: 1;
    transform: translateX(0);
}

.marginalia-text {
    font-family: 'IM Fell English', serif;
    font-size: clamp(0.9rem, 1.1vw, 1rem);
    font-style: italic;
    color: var(--aged-leather);
    line-height: 1.8;
}

/* --- Epilogue (Section 5) --- */
.section-epilogue .section-inner {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding-top: 0;
    padding-bottom: 0;
}

.epilogue-heading {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: clamp(2rem, 4vw, 3.5rem);
    color: var(--burnished-gold);
    margin-bottom: 24px;
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.quest-section.in-view .epilogue-heading {
    opacity: 1;
    transform: translateY(0);
}

.epilogue-text {
    font-family: 'Lora', serif;
    font-size: clamp(1rem, 1.4vw, 1.2rem);
    line-height: 1.9;
    color: var(--ivory);
    max-width: 600px;
    margin-bottom: 40px;
    opacity: 0;
    transition: opacity 0.8s ease 0.2s;
}

.quest-section.in-view .epilogue-text {
    opacity: 1;
}

.quest-sigil {
    margin-bottom: 40px;
    opacity: 0;
    transition: opacity 1s ease 0.5s;
}

.quest-section.in-view .quest-sigil {
    opacity: 1;
}

.sigil-svg {
    width: 120px;
    height: 120px;
    animation: rotateSigil 30s linear infinite;
}

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

.epilogue-footer {
    font-family: 'IM Fell English', serif;
    font-size: 0.85rem;
    color: var(--aged-leather);
    letter-spacing: 0.1em;
    opacity: 0;
    transition: opacity 0.8s ease 0.8s;
}

.quest-section.in-view .epilogue-footer {
    opacity: 1;
}

/* --- Card Overlay (Expanded Card) --- */
.card-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 200;
    background: rgba(10, 8, 8, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.card-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.card-overlay-content {
    background: linear-gradient(145deg, var(--mahogany) 0%, var(--library-dark) 100%);
    border: 1px solid var(--burnished-gold);
    padding: 48px 40px;
    max-width: 80vw;
    max-height: 80vh;
    overflow-y: auto;
    transform: scale(0.9);
    transition: transform 0.3s ease;
    position: relative;
}

.card-overlay.active .card-overlay-content {
    transform: scale(1);
}

.card-overlay-content .quest-label {
    font-size: 1.1rem;
    margin-bottom: 16px;
}

.card-overlay-content .card-text {
    font-size: 1.1rem;
    line-height: 2;
}

.card-overlay-content .close-overlay {
    position: absolute;
    top: 16px;
    right: 20px;
    font-family: 'IM Fell English', serif;
    font-size: 1.2rem;
    color: var(--aged-leather);
    cursor: pointer;
    background: none;
    border: none;
    transition: color 0.2s ease;
}

.card-overlay-content .close-overlay:hover {
    color: var(--burnished-gold);
}

/* --- Zoom Focus Transition States --- */
.quest-section.zoom-out {
    transform: scale(0.95);
    opacity: 0.5;
}

.quest-section.zoom-in {
    transform: scale(1);
    opacity: 1;
}

/* --- Quest Map Fragment Background --- */
.section-dark::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        radial-gradient(circle at 15% 25%, rgba(168, 144, 112, 0.03) 0%, transparent 40%),
        radial-gradient(circle at 85% 75%, rgba(168, 144, 112, 0.02) 0%, transparent 35%);
    z-index: 1;
    pointer-events: none;
}

/* --- Ornamental Border Animation --- */
@keyframes drawBorderTL {
    from { width: 0; height: 0; }
    to { width: 20px; height: 20px; }
}

.quest-section.in-view .card-ornament.corner-tl {
    animation: drawBorderTL 0.5s ease forwards;
}
.quest-section.in-view .card-ornament.corner-tr {
    animation: drawBorderTL 0.5s ease 0.1s forwards;
}
.quest-section.in-view .card-ornament.corner-bl {
    animation: drawBorderTL 0.5s ease 0.2s forwards;
}
.quest-section.in-view .card-ornament.corner-br {
    animation: drawBorderTL 0.5s ease 0.3s forwards;
}

/* --- Double-line border effect on quest cards --- */
.quest-card::before {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    right: 3px;
    bottom: 3px;
    border: 1px solid rgba(168, 144, 112, 0.2);
    pointer-events: none;
    transition: border-color 0.4s ease;
}

.quest-card:hover::before {
    border-color: rgba(212, 168, 83, 0.3);
}

/* --- Selection styling --- */
::selection {
    background: rgba(212, 168, 83, 0.3);
    color: var(--ivory);
}

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

::-webkit-scrollbar-track {
    background: var(--library-dark);
}

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

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

/* --- Responsive --- */
@media (max-width: 767px) {
    #spine-nav {
        display: none;
    }

    .section-inner {
        padding: 60px 20px;
    }

    .quest-card {
        padding: 24px 20px;
        transform: rotate(0deg);
    }

    .quest-card:nth-child(even) {
        transform: rotate(0deg);
    }

    .hero-title {
        letter-spacing: 0.03em;
    }

    .cards-grid {
        grid-template-columns: 1fr;
    }

    .cards-grid-2 {
        grid-template-columns: 1fr;
    }

    .card-overlay-content {
        max-width: 95vw;
        padding: 32px 24px;
    }
}
