:root {
    --primary-color: #d4af37;
    /* Gold */
    --accent-color: #b8860b;
    /* Dark Goldenrod */
    --bg-color: #0f1115;
    /* Very Dark Blue/Grey */
    --panel-bg: rgba(20, 24, 32, 0.7);
    /* Glassmorphism background */
    --text-main: #e0e0e0;
    --text-title: #f5f5dc;
    /* Beige */
    --border-glow: rgba(212, 175, 55, 0.3);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: 'Lora', serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    position: relative;
    background-image: radial-gradient(circle at center, #1a1f2b 0%, #050608 100%);
}

.page-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" opacity="0.03"><pattern id="pattern" width="20" height="20" patternUnits="userSpaceOnUse"><path d="M0,10 L20,10 M10,0 L10,20" stroke="%23d4af37" stroke-width="0.5"/></pattern><rect width="100" height="100" fill="url(%23pattern)"/></svg>');
    z-index: -1;
    pointer-events: none;
}

.container {
    width: 90%;
    max-width: 1100px;
    height: 95vh;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    position: relative;
    z-index: 1;
}

/* Glassmorphism utility */
.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(212, 175, 55, 0.15);
    border-radius: 8px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
}

/* Typography */
h1,
h2,
.scene-indicator {
    font-family: 'Cinzel', serif;
    text-align: center;
}

h1 {
    font-size: 2.5rem;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 4px;
    text-shadow: 0 0 15px var(--border-glow);
    margin-bottom: 0.2rem;
}

h2 {
    font-size: 1.2rem;
    color: var(--text-title);
    font-weight: 400;
    letter-spacing: 2px;
    opacity: 0.8;
}

/* Header styling */
header {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 1.5rem;
}

.divider {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin: 8px 0;
}

.divider-line {
    height: 1px;
    width: 100px;
    background: linear-gradient(90deg, transparent, var(--primary-color), transparent);
}

.divider-icon {
    color: var(--primary-color);
    font-size: 1.2rem;
}

.title-container {
    text-align: center;
}

/* Main Layout */
main {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-height: 0;
}

/* Image Container */
.scene-wrapper {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

.scene-container {
    height: 100%;
    width: 100%;
    max-width: 900px;
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8), 0 0 20px rgba(212, 175, 55, 0.2);
    border: 2px solid rgba(212, 175, 55, 0.3);
    background-color: #000;
    display: flex;
    justify-content: center;
    align-items: center;
}

#scene-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    transition: opacity 1s cubic-bezier(0.4, 0, 0.2, 1), transform 1.5s ease;
}

.scene-container:hover #scene-image {
    transform: scale(1.02);
}

.image-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.5) 0%, transparent 40%);
    pointer-events: none;
}

/* Text Container */
.text-wrapper {
    flex: 0 0 25%;
    min-height: 120px;
    display: flex;
    justify-content: center;
}

.text-container {
    width: 100%;
    max-width: 900px;
    padding: 1.5rem 2rem;
    position: relative;
    overflow-y: auto;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

#scene-text {
    font-size: 1.2rem;
    line-height: 1.7;
    text-align: justify;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
    transition: opacity 0.8s ease;
}


/* Footer & Controls */
footer {
    flex: 0 0 auto;
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
}

.chapter-nav {
    display: flex;
    width: 100%;
    max-width: 900px;
    padding: 0.45rem;
    gap: 0.35rem;
    align-items: center;
    justify-content: center;
}

.chapter-tab {
    min-height: 36px;
    padding: 0 0.8rem;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text-main);
    font-family: 'Cinzel', serif;
    font-size: 0.78rem;
    letter-spacing: 1px;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.chapter-tab:hover {
    border-color: rgba(212, 175, 55, 0.45);
    background: rgba(212, 175, 55, 0.08);
}

.chapter-tab.active {
    border-color: var(--accent-color);
    background: rgba(212, 175, 55, 0.16);
    color: var(--primary-color);
}

.chapter-tab.unavailable {
    color: rgba(224, 224, 224, 0.42);
    border-color: rgba(255, 255, 255, 0.08);
    cursor: not-allowed;
    opacity: 0.58;
}

.chapter-tab.unavailable:hover {
    background: transparent;
    border-color: rgba(255, 255, 255, 0.08);
}

.controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 900px;
    padding: 0.8rem 1.5rem;
    gap: 1.5rem;
}

.audio-wrapper {
    flex-grow: 1;
}

audio {
    width: 100%;
    height: 40px;
    border-radius: 20px;
    outline: none;
}

/* Audio styling across browsers */
audio::-webkit-media-controls-panel {
    background-color: #2a2d35;
}

audio::-webkit-media-controls-current-time-display,
audio::-webkit-media-controls-time-remaining-display {
    color: var(--text-main);
}

audio::-webkit-media-controls-play-button {
    filter: invert(70%) sepia(30%) saturate(1000%) hue-rotate(5deg);
}

.fantasy-btn {
    background: transparent;
    color: var(--primary-color);
    border: 1px solid var(--accent-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

.fantasy-btn:hover {
    background: rgba(212, 175, 55, 0.1);
    box-shadow: 0 0 15px var(--border-glow);
    transform: translateY(-2px);
}

.fantasy-btn:active {
    transform: translateY(1px);
}

.fantasy-btn:disabled {
    color: rgba(212, 175, 55, 0.38);
    border-color: rgba(212, 175, 55, 0.24);
    cursor: not-allowed;
    opacity: 0.55;
    box-shadow: none;
}

.fantasy-btn:disabled:hover,
.fantasy-btn:disabled:active {
    background: transparent;
    box-shadow: none;
    transform: none;
}

/* Progress indicator */
.progress-container {
    width: 100%;
    max-width: 900px;
    text-align: center;
}

.progress-bar-bg {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    margin-bottom: 8px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #b8860b, #d4af37);
    width: 0%;
    transition: width 0.3s ease;
    box-shadow: 0 0 10px var(--primary-color);
}

.scene-indicator-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-family: 'Cinzel', serif;
    font-size: 0.9rem;
    color: var(--text-main);
    letter-spacing: 1px;
}

.ornament-small {
    color: var(--primary-color);
    font-size: 0.8rem;
}

/* Fade Classes */
.fade-out {
    opacity: 0 !important;
}

/* Cinematic Panning Animations */
@keyframes pan-top-to-bottom {
    0% {
        object-position: center top;
    }

    100% {
        object-position: center bottom;
    }
}

.pan-top-to-bottom {
    animation: pan-top-to-bottom 15s linear alternate forwards;
}

@keyframes pan-bottom-to-top {
    0% {
        object-position: center bottom;
    }

    100% {
        object-position: center top;
    }
}

.pan-bottom-to-top {
    animation: pan-bottom-to-top 15s linear alternate forwards;
}

@keyframes pan-left-to-right {
    0% {
        object-position: left center;
    }

    100% {
        object-position: right center;
    }
}

.pan-left-to-right {
    animation: pan-left-to-right 15s linear alternate forwards;
}

@keyframes pan-right-to-left {
    0% {
        object-position: right center;
    }

    100% {
        object-position: left center;
    }
}

.pan-right-to-left {
    animation: pan-right-to-left 15s linear alternate forwards;
}

.hidden {
    display: none !important;
}

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

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}

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

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

/* Responsive constraints */
@media (max-width: 768px) {
    h1 {
        font-size: 1.8rem;
    }

    h2 {
        font-size: 1rem;
    }

    .text-wrapper {
        flex: 0 0 35%;
    }

    #scene-text {
        font-size: 1rem;
    }

    .controls {
        padding: 0.8rem;
    }

    .chapter-nav {
        justify-content: flex-start;
        overflow-x: auto;
    }

    .chapter-tab {
        flex: 0 0 auto;
    }
}
