@import url('https://fonts.googleapis.com/css2?family=Crimson+Text:ital,wght@0,400;0,600;1,400&family=Cinzel:wght@400;600;700&display=swap');

:root {
    --parchment-light: #f4f1e8;
    --parchment-dark: #2a2419;
    --ink-color: #3d3024;
    --gold-accent: #d4a574;
    --gold-hover: #f0c989;
    --shadow-soft: rgba(0, 0, 0, 0.1);
    --shadow-medium: rgba(0, 0, 0, 0.2);
}

body {
    font-family: 'Crimson Text', serif;
    font-weight: 400;
    background: linear-gradient(135deg, #f4f1e8 0%, #e8dcc8 100%);
    background-attachment: fixed;
    overflow: hidden;
    color: var(--ink-color);
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(139, 115, 85, 0.03) 2px,
            rgba(139, 115, 85, 0.03) 4px
        );
    pointer-events: none;
    z-index: 1;
}

@media screen and (prefers-reduced-motion: no-preference) {
    body.switched {
        transition: color 0.8s ease, background 0.8s ease;
    }
}

h1,
h2 {
    text-align: center;
    font-family: 'Cinzel', serif;
    margin: 0;
    padding: 0;
}

h1 {
    font-size: 42pt;
    margin-bottom: 15px;
    color: var(--ink-color);
    text-shadow: 2px 2px 4px var(--shadow-soft);
    letter-spacing: 2px;
    font-weight: 700;
}

h2 {
    font-size: 16pt;
    font-style: italic;
    font-weight: 400;
    color: #8b7355;
    letter-spacing: 1px;
}

.header {
    padding-top: 4em;
    padding-bottom: 3em;
    position: relative;
}

.header::after {
    content: '✦';
    display: block;
    text-align: center;
    font-size: 20pt;
    color: var(--gold-accent);
    margin-top: 20px;
}

.byline {
    font-style: italic;
    color: #8b7355;
    font-size: 14pt;
}

.written-in-ink {
    z-index: 5;
    font-size: 9pt;
    font-family: 'Crimson Text', serif;
    text-align: center;
    font-weight: 600;
    position: fixed;
    display: block;
    width: 100%;
    background: linear-gradient(180deg, var(--parchment-light) 0%, rgba(244, 241, 232, 0.95) 100%);
    backdrop-filter: blur(5px);
    margin: 0;
    padding-top: 8px;
    padding-bottom: 8px;
    height: 16px;
    top: 0;
    border-bottom: 1px solid rgba(139, 115, 85, 0.2);
    box-shadow: 0 2px 10px var(--shadow-soft);
}

@media screen and (prefers-reduced-motion: no-preference) {
    .written-in-ink {
        transition: color 0.6s, background 0.6s;
    }
}

.outerContainer {
    position: absolute;
    display: block;
    margin: 0;
    padding: 0;
    -webkit-overflow-scrolling: touch;
    overflow: scroll;
    overflow-x: hidden;
    height: 100%;
    width: 100%;
    top: 0;
    left: 0;
    margin-top: 24px;
    background-size: cover;
    background-repeat: no-repeat;
    z-index: 2;
}

@media screen and (max-width: 980px) {
    .outerContainer {
        margin-top: 44px;
    }
}

.container {
    display: block;
    max-width: 700px;
    margin: 0 auto;
    padding: 40px;
    padding-top: 4em;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 50px var(--shadow-medium);
    border-radius: 8px;
    border: 1px solid rgba(212, 165, 116, 0.3);
    position: relative;
}

.container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><rect width="100" height="100" fill="none"/><path d="M0 0 L100 100 M100 0 L0 100" stroke="rgba(139,115,85,0.02)" stroke-width="0.5"/></svg>');
    background-size: 50px 50px;
    opacity: 0.3;
    pointer-events: none;
    border-radius: 8px;
}

@media screen and (max-width: 768px) {
    .container {
        padding: 30px 25px;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
}

@media screen and (prefers-reduced-motion: no-preference) {
    .switched .container {
        transition: background-color 0.8s ease;
    }
}

p {
    font-size: 16pt;
    color: var(--ink-color);
    line-height: 1.8em;
    font-weight: 400;
    text-indent: 2em;
    margin-bottom: 1.2em;
    position: relative;
    z-index: 1;
    padding-top: 0.8em;
    border-top: 1px solid transparent;
}

/* Add decorative divider between story sections */
p:not(:first-of-type):not(.choice)::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 1px;
    background: linear-gradient(
        90deg, 
        transparent, 
        rgba(212, 165, 116, 0.4) 20%, 
        rgba(212, 165, 116, 0.6) 50%, 
        rgba(212, 165, 116, 0.4) 80%, 
        transparent
    );
}

p:first-of-type::first-letter {
    font-size: 3.5em;
    line-height: 0.85em;
    float: left;
    margin-right: 12px;
    margin-top: 5px;
    margin-left: -3px;
    font-family: 'Cinzel', serif;
    color: var(--gold-accent);
    text-shadow: 1px 1px 2px var(--shadow-soft);
}

a {
    font-weight: 600;
    color: var(--gold-accent);
    font-family: 'Crimson Text', serif;
    text-decoration: none;
    border-bottom: 2px solid transparent;
    padding-bottom: 2px;
    display: inline-block;
}

.unclickable {
    font-weight: 600;
    color: #9d8569;
    font-family: 'Crimson Text', serif;
    text-decoration: none;
    cursor: not-allowed;
    opacity: 0.5;
}

a:hover {
    color: var(--gold-hover);
    border-bottom: 2px solid var(--gold-hover);
    transform: translateY(-2px);
}

@media screen and (prefers-reduced-motion: no-preference) {
    a {
        transition: all 0.3s ease;
    }

    a:hover {
        transition: all 0.15s ease;
    }
}

strong {
    color: var(--ink-color);
    font-weight: 600;
}

img {
    display: block;
    margin: 2em auto;
    max-width: 100%;
    border-radius: 6px;
    box-shadow: 0 8px 30px var(--shadow-medium);
    border: 3px solid var(--gold-accent);
}

.container .hide {
    opacity: 0.0;
}

.container .invisible {
    display: none;
}

.container>* {
    opacity: 1.0;
}

@media screen and (prefers-reduced-motion: no-preference) {
    .container>* {
        transition: opacity 1.2s ease;
    }
}

.choice {
    text-align: center;
    line-height: 2em;
    padding: 8px 0;
    text-indent: 0 !important; /* Override paragraph text-indent */
}

/* Prevent drop cap on choice paragraphs */
.choice::first-letter {
    font-size: inherit;
    line-height: inherit;
    float: none;
    margin: 0;
    font-family: inherit;
    color: inherit;
    text-shadow: none;
}

:not(.choice)+.choice {
    padding-top: 1.5em;
}

.choice a, .choice span {
    font-size: 17pt;
    padding: 12px 24px;
    border: 2px solid var(--gold-accent);
    border-radius: 6px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9) 0%, rgba(244, 241, 232, 0.9) 100%);
    box-shadow: 0 4px 15px var(--shadow-soft);
    display: inline-block;
    min-width: 200px;
}

@media screen and (prefers-reduced-motion: no-preference) {
    .choice a {
        transition: all 0.3s ease;
    }
}

.choice a:hover {
    background: linear-gradient(135deg, var(--gold-accent) 0%, var(--gold-hover) 100%);
    color: white;
    transform: translateY(-3px);
    box-shadow: 0 6px 20px var(--shadow-medium);
    border-color: var(--gold-hover);
}

.end {
    text-align: center;
    font-weight: 600;
    font-size: 18pt;
    color: var(--ink-color);
    padding-top: 30px;
    padding-bottom: 30px;
    font-family: 'Cinzel', serif;
    letter-spacing: 2px;
}

.end::before,
.end::after {
    content: '✦';
    display: inline-block;
    margin: 0 15px;
    color: var(--gold-accent);
}

#controls {
    z-index: 6;
    font-size: 10pt;
    text-align: center;
    padding: 8px 14px;
    position: fixed;
    right: 14px;
    top: 4px;
    user-select: none;
    background: rgba(244, 241, 232, 0.95);
    backdrop-filter: blur(5px);
    border-radius: 6px;
    border: 1px solid rgba(139, 115, 85, 0.2);
    box-shadow: 0 2px 10px var(--shadow-soft);
}

#controls a {
    border: none;
    padding: 0;
}

@media screen and (prefers-reduced-motion: no-preference) {
    #controls {
        transition: all 0.3s ease;
    }
}

#controls [disabled] {
    color: #ccc;
}

#controls>*:not(:last-child):after {
    content: " | ";
    color: var(--gold-accent);
}

@media screen and (max-width: 980px) {
    #controls {
        z-index: 2;
        padding-top: 24px;
        top: 0;
        left: 0;
        right: 0;
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-top: none;
    }
    
    h1 {
        font-size: 32pt;
    }
}

/* Dark Theme Enhanced */
body.dark {
    background: linear-gradient(135deg, #1a1410 0%, #0f0c08 100%);
    color: #d4c5b0;
}

body.dark::before {
    background-image: 
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(212, 165, 116, 0.03) 2px,
            rgba(212, 165, 116, 0.03) 4px
        );
}

.dark h1 {
    color: var(--gold-accent);
    text-shadow: 2px 2px 8px rgba(212, 165, 116, 0.3);
}

.dark h2 {
    color: #8b7355;
}

.dark .container {
    background: rgba(42, 36, 25, 0.9);
    border-color: rgba(212, 165, 116, 0.4);
}

.dark .written-in-ink {
    background: linear-gradient(180deg, var(--parchment-dark) 0%, rgba(42, 36, 25, 0.95) 100%);
    border-bottom-color: rgba(212, 165, 116, 0.3);
}

.dark p {
    color: #d4c5b0;
}

.dark a {
    color: var(--gold-hover);
}

.dark .unclickable {
    color: #6b5d4f;
}

.dark a:hover {
    color: #ffe4b5;
    border-bottom-color: #ffe4b5;
}

.dark strong {
    color: #f4f1e8;
}

.dark #controls [disabled] {
    color: #444;
}

.dark .end {
    color: var(--gold-accent);
}

.dark #controls {
    background: rgba(42, 36, 25, 0.95);
    border-color: rgba(212, 165, 116, 0.3);
}

.dark .choice a, .dark .choice span {
    background: linear-gradient(135deg, rgba(42, 36, 25, 0.9) 0%, rgba(31, 27, 19, 0.9) 100%);
    border-color: var(--gold-accent);
    color: var(--gold-hover);
}

.dark .choice a:hover {
    background: linear-gradient(135deg, var(--gold-accent) 0%, var(--gold-hover) 100%);
    color: var(--parchment-dark);
}

/* Audio Controls - Dual Track System */
#audio-controls {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 6;
    background: rgba(244, 241, 232, 0.95);
    backdrop-filter: blur(5px);
    padding: 14px 18px;
    border-radius: 12px;
    border: 1px solid rgba(139, 115, 85, 0.2);
    box-shadow: 0 4px 15px var(--shadow-soft);
}

.dark #audio-controls {
    background: rgba(42, 36, 25, 0.95);
    border-color: rgba(212, 165, 116, 0.3);
}

#audio-controls button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18pt;
    color: var(--gold-accent);
    padding: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

#audio-controls button:hover {
    color: var(--gold-hover);
    transform: scale(1.15);
}

#music-slider,
#ambience-slider {
    width: 100px;
    height: 4px;
    background: rgba(139, 115, 85, 0.3);
    border-radius: 2px;
    outline: none;
    -webkit-appearance: none;
}

#music-slider::-webkit-slider-thumb,
#ambience-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: var(--gold-accent);
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.3s ease;
}

#music-slider::-webkit-slider-thumb:hover,
#ambience-slider::-webkit-slider-thumb:hover {
    background: var(--gold-hover);
    transform: scale(1.2);
}

#music-slider::-moz-range-thumb,
#ambience-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--gold-accent);
    cursor: pointer;
    border-radius: 50%;
    border: none;
    transition: all 0.3s ease;
}

#music-slider::-moz-range-thumb:hover,
#ambience-slider::-moz-range-thumb:hover {
    background: var(--gold-hover);
    transform: scale(1.2);
}

@media screen and (max-width: 768px) {
    #audio-controls {
        bottom: 10px;
        right: 10px;
        padding: 12px 14px;
    }
    
    #music-slider,
    #ambience-slider {
        width: 70px;
    }
    
    #audio-controls button {
        font-size: 16pt;
        width: 24px;
        height: 24px;
    }
}

/* Page turn animation hint */
@keyframes pageGlow {
    0%, 100% { 
        opacity: 0.3;
        box-shadow: 0 0 20px rgba(212, 165, 116, 0.4);
    }
    50% { 
        opacity: 0.7;
        box-shadow: 0 0 30px rgba(212, 165, 116, 0.7);
    }
}

.choice a::after {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 6px;
    background: linear-gradient(135deg, 
        rgba(255, 255, 255, 0.4), 
        rgba(255, 235, 205, 0.6), 
        rgba(255, 255, 255, 0.4)
    );
    opacity: 0;
    pointer-events: none;
    z-index: -1;
}

@media screen and (prefers-reduced-motion: no-preference) {
    .choice a:hover::after {
        animation: pageGlow 1.5s ease infinite;
    }
}