:root {
    /* Light theme */
    --bg: #ffffff;
    --text: #111111;
    --accent: #ff0000;
    --card-bg: #f7f7f7;
    --card-text: #222;
    --glow: 0 0 12px #ff0000, 0 0 4px #ff0000;
    --border: #ff0000;
    --meta: #888;
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --text-primary: #2d3436;
    --text-secondary: #636e72;
    --accent-primary: #0984e3;
    --accent-secondary: #74b9ff;
    --border-color: #dfe6e9;
    --card-shadow: rgba(0, 0, 0, 0.1);
    --overlay-bg: rgba(255, 255, 255, 0.8);
    --mono-ui: 'Roboto Mono', monospace;
    --serif-story: 'Spectral SC', 'Playfair Display', serif;
}

[data-theme="dark"] {
    --bg: #000000;
    --text: #fff;
    --accent: #ff0000;
    --card-bg: #181818;
    --card-text: #fff;
    --glow: 0 0 12px #ff0000, 0 0 4px #ff0000;
    --border: #ff0000;
    --meta: #bbb;
    --bg-primary: #0a0a0a;
    --bg-secondary: #18181a;
    --text-primary: #f5f5f5;
    --text-secondary: #b2bec3;
    --accent-primary: #d00000;
    --accent-secondary: #a30000;
    --border-color: #2d2d2d;
    --card-shadow: rgba(208, 0, 0, 0.25);
    --overlay-bg: rgba(10, 10, 10, 0.85);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.7;
    transition: background-color 0.3s, color 0.3s;
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

/* Creepy Quote Bar Styles */
.creepy-quote-bar {
    width: 100%;
    text-align: center;
    font-family: 'Spectral SC', 'Playfair Display', serif;
    font-size: 1.18em;
    color: #d00000;
    letter-spacing: 0.04em;
    background: linear-gradient(90deg, rgba(30,0,0,0.85) 0%, rgba(0,0,0,0.7) 100%);
    padding: 0.6em 0.4em 0.4em 0.4em;
    margin: 0 0 0.2em 0;
    border-bottom: 1.5px solid #2d2d2d;
    box-shadow: 0 2px 16px 0 #d0000033;
    min-height: 2.1em;
    user-select: none;
    opacity: 0.93;
    transition: background 0.3s, color 0.3s;
    z-index: 2001;
    position: relative;
}
.creepy-quote-bar.fade-in {
    animation: creepyFadeIn 1.2s cubic-bezier(.4,2,.6,1);
}
@keyframes creepyFadeIn {
    from { opacity: 0; transform: translateY(-12px) scale(0.98); filter: blur(2px); }
    to   { opacity: 0.93; transform: translateY(0) scale(1); filter: blur(0); }
}

/* Prevent overlap of modal with scrollbars */
body.auth-modal-open {
    overflow: hidden;
}

/* --- Auth Modal & User Bar Styles --- */
.user-auth-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    justify-content: flex-start;
    padding: 0.5rem 0 0.2rem 2.5rem;
    background: none;
    min-height: 2.5rem;
    z-index: 1001;
    position: relative;
}

@media (max-width: 700px) {
    .user-auth-bar {
        padding: 0.5rem 0 0.2rem 0.5rem;
    }
}

/* Add a little space below the auth bar and above the logo */
.nav-header {
    display: flex;
    align-items: center;
    gap: 2.5rem;
    margin-top: 0.2rem;
    width: 100%;
    position: relative;
}
.logo {
    font-family: 'Spectral SC', serif;
    font-size: 3.2rem;
    font-weight: 900;
    color: #a10000;
    letter-spacing: 0.04em;
    margin: 0 auto 0em auto;
    white-space: nowrap;
    text-align: center;
    display: block;
    width: 100%;
    position: relative;
    z-index: 3;
    line-height: 1.05;
    text-shadow: 0 2px 18px #3a0000cc, 0 1px 0 #fff2, 0 0.5px 0 #fff2;
}
.logo-blood-drip {
    width: 100%;
    height: 60px;
    margin: 0;
    padding: 0;
    overflow: visible;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 20;
    pointer-events: none;
    display: block;
}
.blood-base {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 52px;
    z-index: 1;
    pointer-events: none;
}
.blood-drip {
    position: absolute;
    top: 0;
    width: var(--drip-width, 18px);
    height: 38px;
    background: linear-gradient(180deg, #d00000 60%, #a10000 100%);
    border-radius: 50% 50% 60% 60% / 60% 60% 100% 100%;
    box-shadow: 0 4px 18px 0 #a1000033, 0 0 8px #fff2 inset;
    animation: bloodDropFall var(--drip-duration, 7s) cubic-bezier(.4,2,.6,1) 1;
    animation-fill-mode: forwards;
    opacity: 0.97;
    z-index: 2;
    clip-path: ellipse(50% 60% at 50% 60%);
}
.blood-drip .blood-trail {
    position: absolute;
    left: 50%;
    top: 0;
    width: 14px;
    height: 0;
    background: linear-gradient(180deg, #a10000 60%, #d00000 100%);
    border-radius: 7px 7px 18px 18px / 7px 7px 24px 24px;
    opacity: 0.45;
    filter: blur(0.5px);
    transform: translateX(-50%);
    z-index: 1;
    animation: bloodTrailGrowLiquid var(--drip-duration, 7s) cubic-bezier(.4,2,.6,1) 1 forwards;
}
@keyframes bloodDropFall {
    0%   { top: 0; }
    100% { top: var(--drip-distance, 80px); }
}
@keyframes bloodTrailGrowLiquid {
    0%   { height: 0; width: 10px; border-radius: 7px 7px 7px 7px / 7px 7px 7px 7px; opacity: 0.45; }
    80%  { height: var(--drip-distance, 80px); width: 14px; border-radius: 7px 7px 18px 18px / 7px 7px 24px 24px; opacity: 0.45; }
    100% { height: var(--drip-distance, 80px); width: 22px; border-radius: 7px 7px 32px 32px / 7px 7px 38px 38px; opacity: 0.45; }
}

.blood-drip:after {
    content: '';
    display: block;
    position: absolute;
    left: 55%;
    top: 18%;
    width: 7px;
    height: 14px;
    background: linear-gradient(180deg, #fff7 60%, transparent 100%);
    border-radius: 50%;
    opacity: 0.18;
    filter: blur(1.2px);
    z-index: 4;
}

.blood-drip:before {
    content: '';
    display: block;
    position: absolute;
    left: 50%;
    top: 60%;
    width: 18px;
    height: 18px;
    background: radial-gradient(circle at 60% 40%, #fff8 0%, #a10000 80%);
    border-radius: 50%;
    transform: translateX(-50%) scaleY(1.2);
    filter: blur(1.2px);
    opacity: 0.22;
    z-index: 3;
}

.blood-drip .blood-splatter {
    position: absolute;
    left: 50%;
    top: 100%;
    width: 0px;
    height: 0px;
    background: radial-gradient(circle, #a10000 60%, #d00000 100%);
    border-radius: 50%;
    opacity: 0;
    pointer-events: none;
    z-index: 1;
    transform: translate(-50%, -50%) scale(0.2);
    animation: bloodSplatter 0.6s cubic-bezier(.4,2,.6,1) 1 forwards;
    animation-delay: var(--drip-duration, 7s);
}
@keyframes bloodSplatter {
    0%   { width: 0px; height: 0px; opacity: 0; transform: translate(-50%, -50%) scale(0.2); }
    40%  { width: 32px; height: 18px; opacity: 0.7; transform: translate(-50%, -50%) scale(1.1); }
    100% { width: 38px; height: 22px; opacity: 0.0; transform: translate(-50%, -50%) scale(1.3); }
}

.blood-drip {
    animation-duration: 4.5s;
}


.hero-section {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    padding: 0 0 0.2em 0;
    position: relative;
    padding-top: 3.2em;
}
.nav-header {
    margin-top: 0;
    padding-top: 0.2em;
}
@media (max-width: 600px) {
    .logo {
        font-size: 2.1rem;
    }
    .logo-blood-drip {
        height: 32px;
    }
    .blood-base {
        height: 28px;
    }
    .blood-drip {
        height: 18px;
    }
    .hero-section {
        padding-top: 1.6em;
    }
}

.hero-section {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
}
.nav-header {
    margin-top: 0.1rem;
}
.creepy-quote-bar {
    flex: 1 1 auto;
    text-align: left;
    font-family: 'Spectral SC', 'Playfair Display', serif;
    font-size: 1.12em;
    color: #d00000;
    letter-spacing: 0.04em;
    background: rgba(24, 0, 0, 0.73);
    padding: 0.2em 0.8em 0.2em 0.8em;
    margin: 0;
    border: none;
    box-shadow: none;
    min-height: unset;
    user-select: none;
    opacity: 0.97;
    transition: color 0.3s;
    z-index: 99;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    animation: none;
    text-shadow: 0 2px 6px #000, 0 0 2px #fff2;
}
.logo-blood-drip {
    z-index: 5;
}

.creepy-quote-bar.fade-in {
    animation: creepyFadeIn 1.2s cubic-bezier(.4,2,.6,1);
}
@media (max-width: 900px) {
    .nav-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    .creepy-quote-bar {
        text-align: left;
        padding: 0.2em 0 0.2em 0.2em;
        font-size: 1em;
    }
}

/* Remove XP/quests bar styles */
.xp-badges-bar, .xp-bar-container, .xp-label, .xp-bar-bg, .xp-bar-fill, .xp-value, .badge-btn, .badge-icon {
    display: none !important;
}


.hero-section {
    position: relative;
    z-index: 1;
    padding-top: 2.8em;
}

/* Push main header content down below auth bar */
.nav-header {
    margin-top: 0.5rem;
}

/* Add spacing below auth bar and header */
.app-container > header {
    margin-bottom: 0.5rem;
}

@media (max-width: 700px) {
    .user-auth-bar {
        padding: 0.5rem 0.7rem 0.5rem 0;
    }
    .nav-header {
        margin-top: 0.2rem;
    }
    .app-container > header {
        margin-bottom: 0.2rem;
    }
}

.user-status {
    font-size: 1em;
    color: var(--accent);
    font-family: var(--mono-ui);
}
.login-btn, .logout-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0.4em 1.2em;
    font-size: 1em;
    cursor: pointer;
    font-family: var(--mono-ui);
    transition: background 0.2s;
}
.login-btn:hover, .logout-btn:hover {
    background: var(--accent-secondary);
}

.auth-modal {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.65);
    z-index: 30000;
    animation: fadeIn 0.2s;
}

.auth-modal-content {
    box-sizing: border-box;
}

.auth-modal-content {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-radius: 16px;
    box-shadow: 0 0 32px #000a;
    max-width: 350px;
    width: 100%;
    padding: 2.2rem 2rem 1.5rem 2rem;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    animation: slideUp 0.25s;
}
.close-auth-modal {
    background: none;
    border: none;
    position: absolute;
    top: 1rem;
    right: 1.2rem;
    font-size: 1.8em;
    color: var(--accent);
    cursor: pointer;
    line-height: 1;
}
#auth-form {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}
#auth-form label {
    font-size: 1em;
    color: var(--text-secondary);
    margin-bottom: 0.2em;
}
#auth-form input[type="email"],
#auth-form input[type="password"] {
    padding: 0.6em 0.9em;
    border: 1.5px solid var(--border-color);
    border-radius: 6px;
    font-size: 1em;
    background: var(--bg-secondary);
    color: var(--text);
    font-family: var(--mono-ui);
}
.auth-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 0.5rem;
}
#login-submit, #signup-submit {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0.4em 1.2em;
    font-size: 1em;
    cursor: pointer;
    font-family: var(--mono-ui);
    transition: background 0.2s;
}
#login-submit:hover, #signup-submit:hover {
    background: var(--accent-secondary);
}
.auth-error {
    color: #fff;
    background: #d00000;
    padding: 0.5em 1em;
    border-radius: 6px;
    font-size: 1em;
    margin-top: 0.5em;
    text-align: center;
    animation: fadeIn 0.2s;
}
@media (max-width: 600px) {
    .auth-modal-content {
        max-width: 96vw;
        padding: 1.2rem 0.7rem 1.2rem 0.7rem;
    }
    .user-auth-bar {
        padding: 0.5rem 0.5rem 0.5rem 0;
    }
}


h1, h2, h3, h4, h5, h6 {
    font-family: 'Spectral', serif;
    font-weight: 600;
    color: var(--text);
}

/* Layout */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    position: relative;
    z-index: 1;
}

/* Header */
.nav-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
    border-bottom: 1px solid var(--border);
}

.logo {
    font-family: var(--serif-story);
    font-size: 2.7em;
    color: var(--accent);
    letter-spacing: 0.04em;
    text-shadow: var(--glow);
    animation: neonFlicker 2.5s infinite alternate;
    text-transform: uppercase;
    margin-left: 2.5rem;
    margin-right: 1.2rem;
    padding-left: 0.5rem;
}

.theme-toggle {
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--mono-ui);
    font-size: 1em;
    border-radius: 0;
    transition: background 0.2s;
}

.theme-toggle:hover {
    background: var(--bg-secondary);
}

.theme-icon {
    width: 24px;
    height: 24px;
    vertical-align: middle;
    transition: opacity 0.3s, filter 0.3s;
}

.theme-label {
    font-size: 0.95em;
    color: var(--text-secondary);
    letter-spacing: 0.04em;
    margin-left: 2px;
}

.star-icon {
    width: 24px;
    height: 24px;
    vertical-align: middle;
    transition: filter 0.2s, opacity 0.2s;
}

.favorite-toggle.active .star-icon,
.favorite-btn.active .star-icon {
    filter: drop-shadow(0 0 6px #d00000);
    opacity: 1;
}

.favorite-toggle .star-icon,
.favorite-btn .star-icon {
    opacity: 0.8;
}

.favorite-toggle:hover .star-icon,
.favorite-btn:hover .star-icon {
    opacity: 1;
    filter: drop-shadow(0 0 8px #d00000);
}

[data-theme="light"] {
    --bg: #ffffff;
    --text: #111;
    --accent: #ff0000;
    --card-bg: #f7f7f7;
    --card-text: #222;
    --glow: 0 0 12px #ff0000, 0 0 4px #ff0000;
    --border: #ff0000;
    --meta: #888;
    --bg-primary: #f8f8f8;
    --bg-secondary: #ffffff;
    --text-primary: #222;
    --text-secondary: #444;
    --accent-primary: #8b0000;
    --accent-secondary: #b22222;
    --border-color: #e0e0e0;
    --card-shadow: rgba(139, 0, 0, 0.08);
    --overlay-bg: rgba(255,255,255,0.92);
}

[data-theme="light"] body {
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: background 0.4s, color 0.4s;
}

[data-theme="light"] .logo {
    color: var(--accent-primary);
    text-shadow: 0 0 4px #fff, 0 0 12px #8b0000;
}

[data-theme="light"] .story-card, [data-theme="light"] .settings-group, [data-theme="light"] .word-popup {
    background: #fff;
    border: 2px solid var(--border-color);
    box-shadow: 0 2px 16px 0 #8b000022, 0 0 0 1.5px var(--accent-primary);
}

[data-theme="light"] .nav-button, [data-theme="light"] .nav-btn, [data-theme="light"] .icon-btn, [data-theme="light"] .filter-select {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

[data-theme="light"] .nav-button:hover, [data-theme="light"] .nav-btn:hover:not(:disabled), [data-theme="light"] .icon-btn:hover, [data-theme="light"] .filter-select:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: var(--bg-primary);
    text-decoration: underline wavy 1.5px #8b0000;
}

[data-theme="light"] .progress-bar {
    background: linear-gradient(90deg, #e0e0e0 0%, #8b0000 100%);
}

[data-theme="light"] .progress-fill {
    background: #8b0000;
    box-shadow: 0 0 8px #8b0000;
}

[data-theme="light"] .interactive-word {
    color: var(--accent-primary);
    border-bottom: 1.5px dashed var(--accent-primary);
    text-shadow: 0 0 4px #8b0000;
}

[data-theme="light"] .story-text {
    color: var(--text-primary);
    background: none;
    text-shadow: none;
}

[data-theme="light"] .ambient-depth-bg {
    background: linear-gradient(120deg, #f8f8f8 60%, #fff 100%);
    opacity: 0.5;
}

[data-theme="light"] .ambient-fog {
    background: radial-gradient(ellipse at 50% 50%, #8882 0%, #fff0 80%);
    opacity: 0.04;
}

[data-theme="light"] .ambient-shadow {
    background: radial-gradient(ellipse at 60% 80%, #888 0%, #fff0 80%);
    opacity: 0.04;
}

[data-theme="light"] .ambient-flicker {
    background: linear-gradient(90deg, #fff2 0%, #fff0 100%);
    opacity: 0.01;
}

@media (max-width: 600px) {
    .theme-toggle { font-size: 0.95em; padding: 6px 6px; }
    .theme-label { font-size: 0.85em; }
    .star-icon, .theme-icon { width: 20px; height: 20px; }
}

/* Navigation */
.main-navigation {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin: 30px 0;
    background: var(--bg);
    box-shadow: var(--glow);
}

.nav-button {
    background: var(--card-bg);
    color: var(--accent);
    border: 1.5px solid var(--accent);
    border-radius: 1.2rem;
    font-size: 1.05rem;
    padding: 0.4rem 1.1rem;
    margin: 0.3rem 0.5rem;
    box-shadow: 0 0 6px var(--accent) inset;
    outline: none;
    transition: border 0.2s, background 0.2s, color 0.2s;
}

.nav-button:focus, .nav-button:hover {
    background: var(--accent);
    color: var(--bg);
    border: 2px solid var(--accent);
}

.nav-button svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

/* Story Grid */
.section-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 1.5rem;
}
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 1.2rem;
    justify-content: center;
    align-items: center;
    background: rgba(0,0,0,0.5);
    border-radius: 2rem;
    box-shadow: 0 0 16px 2px #ff0000;
    padding: 1.2rem 2rem;
    margin: 0 auto 0.5rem auto;
    width: fit-content;
}
@media (max-width: 700px) {
    .filters {
        flex-direction: column;
        gap: 0.7rem;
        width: 100%;
        padding: 1rem 0.5rem;
    }
    .section-header {
        align-items: stretch;
    }
}
/* Remove Library label styling */
.section-header h2 {
    display: none;
}

.filter-select {
    background: var(--card-bg);
    color: var(--accent);
    border: 1.5px solid var(--accent);
    border-radius: 1.2rem;
    font-size: 1.05rem;
    padding: 0.4rem 1.1rem;
    box-shadow: 0 0 6px var(--accent) inset;
    outline: none;
    transition: border 0.2s;
}

.filter-select:focus {
    border-color: var(--accent-secondary);
}

.story-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 30px;
    padding: 20px 0;
}

.story-card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.3s ease;
}

.story-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px var(--card-shadow);
}

.story-card-image {
    width: 100%;
    height: 200px;
    object-fit: cover;
}

.story-card-content {
    padding: 20px;
}

.story-card h3 {
    margin-bottom: 10px;
    font-size: 1.4em;
}

.story-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-secondary);
    font-size: 0.9em;
    margin-top: 15px;
}

/* Story Reader */
.reader-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.reader-controls {
    display: flex;
    gap: 15px;
}

.icon-btn {
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: 1.2rem;
    font-size: 1.05rem;
    padding: 0.4rem 1.1rem;
    margin: 0.3rem 0.5rem;
    box-shadow: var(--glow);
    outline: none;
    transition: background 0.2s, color 0.2s;
}

.icon-btn:hover {
    background: #fff;
    color: var(--accent);
}

.icon-btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.progress-bar {
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 0 6px var(--accent) inset;
    height: 10px;
    margin: 1rem 0;
    overflow: hidden;
}

.progress-fill {
    background: var(--accent);
    height: 100%;
    width: 0%;
    border-radius: 8px;
    box-shadow: var(--glow);
    transition: width 0.5s cubic-bezier(.4,2,.6,1);
}

.page-container {
    margin: 30px 0;
}

.story-image {
    width: 100%;
    height: 400px;
    background-size: cover;
    background-position: center;
    border-radius: 12px;
    margin-bottom: 30px;
}

.story-text {
    font-size: 1.2em;
    line-height: 1.8;
    color: var(--text);
    font-family: 'Spectral', serif;
}

.story-controls {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 32px;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 32px;
    z-index: 2;
}

.story-controls .nav-btn {
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: 1.8rem;
    font-size: 1.25rem;
    padding: 0.7rem 2.2rem;
    margin: 0.3rem 0.7rem;
    box-shadow: var(--glow);
    outline: none;
    transition: background 0.2s, color 0.2s;
}

.story-controls .nav-btn:focus, .story-controls .nav-btn:hover {
    background: #fff;
    color: var(--accent);
}

.nav-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Settings */
.settings-content {
    max-width: 600px;
    margin: 0 auto;
}

.settings-group {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 30px;
}

.settings-group h3 {
    margin-bottom: 20px;
    color: var(--text);
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}

.setting-item:last-child {
    border-bottom: none;
}

/* Word popup */
.popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--overlay-bg);
    backdrop-filter: blur(5px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.word-popup {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 30px;
    max-width: 400px;
    width: 90%;
    position: relative;
    box-shadow: 0 10px 25px var(--card-shadow);
}

.close-popup {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5em;
    cursor: pointer;
    padding: 5px;
    line-height: 1;
}

/* Responsive design */
@media (max-width: 768px) {
    .main-navigation {
        grid-template-columns: 1fr;
    }

    .section-header {
        flex-direction: column;
        gap: 15px;
    }

    .filters {
        width: 100%;
    }

    .filter-select {
        flex: 1;
    }

    .story-controls {
        position: static;
        padding: 0;
        margin-top: 24px;
    }

    .nav-btn {
        width: 100%;
    }
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

.story-card {
    animation: slideUp 0.3s ease-out;
}

.word-popup {
    animation: fadeIn 0.3s ease-out;
}

@keyframes float {
    0% { transform: translateY(0px) rotate(0deg); }
    50% { transform: translateY(-10px) rotate(2deg); }
    100% { transform: translateY(0px) rotate(0deg); }
}

@keyframes sway {
    0% { transform: translateX(0px) rotate(0deg); }
    50% { transform: translateX(10px) rotate(3deg); }
    100% { transform: translateX(0px) rotate(0deg); }
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 0.6; }
    50% { transform: scale(1.05); opacity: 0.8; }
    100% { transform: scale(1); opacity: 0.6; }
}

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

@keyframes scalePress {
    0% { transform: scale(1); }
    50% { transform: scale(0.95); }
    100% { transform: scale(1); }
}

.floating-cloud {
    position: absolute;
    animation: float 6s ease-in-out infinite;
    opacity: 0.6;
    filter: blur(2px);
    transition: all 0.3s ease;
}

.floating-cloud:hover {
    filter: blur(0);
    opacity: 0.8;
}

.cloud-1 { 
    top: 20%; 
    left: 10%; 
    animation: float 7s ease-in-out infinite;
    transform-origin: center center;
}

.cloud-2 { 
    top: 30%; 
    right: 15%; 
    animation: sway 8s ease-in-out infinite;
    transform-origin: top center;
}

.cloud-3 { 
    top: 15%; 
    left: 30%; 
    animation: pulse 9s ease-in-out infinite;
    transform-origin: center center;
}

.cloud-4 { 
    bottom: 25%; 
    right: 25%; 
    animation: float 10s ease-in-out infinite;
    transform-origin: center center;
}

.cloud-5 { 
    bottom: 35%; 
    left: 20%; 
    animation: sway 11s ease-in-out infinite;
    transform-origin: bottom center;
}

.favorite-btn {
    background: none;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.favorite-btn:hover {
    transform: scale(1.2);
}

.favorite-btn.active {
    color: #FF6B6B;
}

/* Parents Section */
.parents-section {
    max-width: 600px;
    margin: 40px auto;
    padding: 30px;
    background-color: white;
    border-radius: 25px;
    box-shadow: 0 4px 20px var(--card-shadow);
}

.pin-entry {
    text-align: center;
    margin-bottom: 30px;
}

.pin-input {
    font-size: 2em;
    width: 200px;
    text-align: center;
    margin: 20px 0;
    padding: 15px;
    border: 2px solid var(--secondary-color);
    border-radius: 15px;
    letter-spacing: 0.2em;
}

.settings-group label {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 10px 0;
    cursor: pointer;
}

/* Animations */
@keyframes pageFlip {
    0% { transform: rotateY(0deg); opacity: 1; }
    50% { transform: rotateY(90deg); opacity: 0.5; }
    100% { transform: rotateY(0deg); opacity: 1; }
}

.page-flip {
    animation: pageFlip 0.6s ease-in-out;
}

/* Add haptic feedback */
.nav-button:active {
    animation: scalePress 0.2s ease-out;
}

.story-card:active {
    animation: scalePress 0.2s ease-out;
}

/* Stagger story card animations */
.story-grid .story-card:nth-child(1) { animation-delay: 0.1s; }
.story-grid .story-card:nth-child(2) { animation-delay: 0.2s; }
.story-grid .story-card:nth-child(3) { animation-delay: 0.3s; }
.story-grid .story-card:nth-child(4) { animation-delay: 0.4s; }
.story-grid .story-card:nth-child(5) { animation-delay: 0.5s; }
.story-grid .story-card:nth-child(6) { animation-delay: 0.6s; }

/* Enhanced word popup animation */
@keyframes popIn {
    0% { 
        opacity: 0;
        transform: scale(0.8) translateY(10px);
    }
    50% { 
        transform: scale(1.05) translateY(-5px);
    }
    100% { 
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Progress bar styles */
.progress-container {
    padding: 10px 20px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background-color: var(--secondary-color);
    border-radius: 4px;
    transition: width 0.3s ease-out;
    width: 0%;
}

.progress-text {
    font-size: 0.9em;
    color: var(--text-color);
    min-width: 80px;
}

/* Narration wave animation */
@keyframes wave {
    0% { height: 5px; }
    50% { height: 15px; }
    100% { height: 5px; }
}

.narration-controls {
    position: relative;
}

.narration-btn {
    background-color: var(--secondary-color);
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.narration-btn img {
    width: 24px;
    height: 24px;
    transition: transform 0.3s ease;
}

.narration-btn:hover img {
    transform: scale(1.1);
}

.narration-wave {
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 3px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.narration-wave::before,
.narration-wave::after {
    content: '';
    width: 3px;
    height: 10px;
    background-color: var(--secondary-color);
    border-radius: 3px;
}

.narration-btn.playing .narration-wave {
    opacity: 1;
}

.narration-btn.playing .narration-wave::before {
    animation: wave 1s ease-in-out infinite;
}

.narration-btn.playing .narration-wave::after {
    animation: wave 1s ease-in-out infinite 0.2s;
}

/* Confetti animation */
@keyframes confettiFall {
    0% {
        transform: translateY(-100vh) rotate(0deg);
    }
    100% {
        transform: translateY(100vh) rotate(360deg);
    }
}

.confetti {
    position: fixed;
    width: 10px;
    height: 10px;
    top: -10px;
    z-index: 1000;
    animation: confettiFall linear forwards;
    pointer-events: none;
}

/* Word highlighting */
.word-highlight {
    background-color: rgba(255, 226, 171, 0.4);
    border-radius: 4px;
    padding: 0 4px;
    transition: background-color 0.2s ease;
}

/* Blood/Ink FX container */
.blood-fx {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    pointer-events: none;
    z-index: 0;
}

.blood-blob {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle at 60% 40%, #d00000 60%, transparent 100%);
    opacity: 0.18;
    filter: blur(18px);
    animation: bloodDrift 24s linear infinite, bloodPulse 7s ease-in-out infinite;
    mix-blend-mode: lighten;
}

@keyframes bloodDrift {
    0% { transform: translateY(0) scale(1) rotate(0deg); }
    100% { transform: translateY(-60vh) scale(1.2) rotate(30deg); }
}
@keyframes bloodPulse {
    0%,100% { filter: blur(18px); opacity: 0.18; }
    50% { filter: blur(28px); opacity: 0.28; }
}

/* Flicker neon header */
@keyframes neonFlicker {
    0%, 100% { opacity: 1; text-shadow: 0 0 8px #d00000, 0 0 24px #a30000, 0 0 2px #fff; }
    10% { opacity: 0.7; text-shadow: 0 0 2px #d00000, 0 0 8px #a30000; }
    20% { opacity: 0.9; }
    22% { opacity: 0.5; }
    24% { opacity: 1; }
    30% { opacity: 0.8; }
    35% { opacity: 1; }
    40% { opacity: 0.6; }
    45% { opacity: 1; }
}

/* UI Buttons */
.nav-button, .nav-btn, .icon-btn, .filter-select {
    font-family: var(--mono-ui);
    text-transform: uppercase;
    font-size: 1em;
    letter-spacing: 0.08em;
    border-radius: 0;
    border: 2px solid var(--border-color);
    box-shadow: 0 2px 12px rgba(208,0,0,0.08);
    background: var(--bg-secondary);
    color: var(--text);
    transition: border-color 0.3s, box-shadow 0.3s, color 0.3s, background 0.3s;
}

.nav-button:hover, .nav-btn:hover:not(:disabled), .icon-btn:hover, .filter-select:hover {
    border-color: var(--accent-primary);
    box-shadow: 0 0 8px 2px #d00000, 0 0 2px #fff;
    color: var(--accent-primary);
    background: var(--bg-primary);
    text-decoration: underline wavy 1.5px #d00000;
    text-underline-offset: 0.2em;
}

.nav-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    border-color: var(--border-color);
    box-shadow: none;
}

/* Cards */
.story-card, .settings-group, .word-popup {
    border-radius: 0;
    box-shadow: 0 4px 32px 0 #1a0000, 0 0 0 1.5px var(--accent-primary);
    border: 2px solid var(--border-color);
    background: rgba(20, 10, 10, 0.92);
    transition: box-shadow 0.3s, border-color 0.3s;
}
.story-card:hover, .settings-group:hover, .word-popup:hover {
    box-shadow: 0 0 24px 2px #d00000, 0 0 2px #fff;
    border-color: var(--accent-primary);
}

/* Story Text */
.story-text {
    font-family: var(--serif-story);
    font-size: 1.25em;
    color: var(--text);
    background: none;
    padding: 0 0 0.5em 0;
    text-shadow: 0 1px 2px #000a;
}

/* Flicker underline for interactive words */
.interactive-word {
    color: var(--accent-primary);
    border-bottom: 1.5px dashed var(--accent-primary);
    cursor: pointer;
    transition: text-shadow 0.2s;
    text-shadow: 0 0 6px #d00000;
    animation: underlineFlicker 1.2s infinite alternate;
}
@keyframes underlineFlicker {
    0%, 100% { text-shadow: 0 0 6px #d00000; }
    20% { text-shadow: 0 0 2px #a30000; }
    40% { text-shadow: 0 0 10px #d00000; }
    60% { text-shadow: 0 0 4px #fff; }
    80% { text-shadow: 0 0 8px #d00000; }
}

/* Progress Bar */
.progress-bar {
    background: linear-gradient(90deg, #2d2d2d 0%, #d00000 100%);
    height: 6px;
    border-radius: 0;
    box-shadow: 0 0 8px #d00000;
}
.progress-fill {
    background: #d00000;
    box-shadow: 0 0 8px #d00000;
    border-radius: 0;
}

/* Hide story images for Kindle-like look */
.story-image { display: none !important; }

/* Responsive adjustments */
@media (max-width: 768px) {
    .logo { font-size: 2em; }
    .story-text { font-size: 1.05em; }
}

/* Kindle-style controls */

/* Mirror crack effect for Final Chapter (main style injected via JS) */
#story-reader.mirror-crack-anim::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: url('assets/mirror-crack.png') center center/cover no-repeat, rgba(0,0,0,0.18);
  animation: mirrorCrackFade 0.9s cubic-bezier(.7,0,.3,1);
  z-index: 99;
  pointer-events: none;
}
@keyframes mirrorCrackFade {
  0% { opacity: 0; }
  40% { opacity: 1; }
  100% { opacity: 0; }
}
.final-chapter-btn {
  background: linear-gradient(90deg,#fff,#d00000 80%);
  color: #2d2d2d;
  border: none;
  border-radius: 2rem;
  font-size: 1.12rem;
  font-weight: 600;
  padding: 0.6rem 2.2rem;
  margin: 0.7rem 0 0.7rem 1.2rem;
  box-shadow: 0 0 12px #d00000, 0 0 2px #fff;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.final-chapter-btn:focus, .final-chapter-btn:hover {
  background: #d00000;
  color: #fff;
}

.zoom-in-btn, .zoom-out-btn {
    font-size: 1.1em;
    font-family: var(--mono-ui);
    background: var(--bg-secondary);
    color: var(--accent-primary);
    border: 2px solid var(--accent-primary);
    border-radius: 0;
    margin-left: 8px;
    margin-right: 0;
    padding: 4px 12px;
    transition: background 0.2s, color 0.2s, border 0.2s;
}
.zoom-in-btn:hover, .zoom-out-btn:hover {
    background: var(--accent-primary);
    color: #fff;
}
.jump-page-select {
    font-family: var(--mono-ui);
    font-size: 1em;
    background: var(--bg-secondary);
    color: var(--text);
    border: 2px solid var(--accent-primary);
    border-radius: 0;
    margin: 0 10px;
    padding: 4px 10px;
    transition: border 0.2s;
}
.page-indicator {
    font-family: var(--mono-ui);
    font-size: 1em;
    color: var(--accent-primary);
    margin: 0 10px;
}
.story-text {
    transition: font-size 0.25s cubic-bezier(.4,2,.6,1), color 0.2s;
}

/* 3D Ambient Depth Mode */
.ambient-depth-bg {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    z-index: -1;
    pointer-events: none;
    overflow: hidden;
    perspective: 1200px;
    background: linear-gradient(120deg, var(--bg-primary) 60%, var(--bg-secondary) 100%);
    opacity: 0.7;
    animation: ambientGradient 18s ease-in-out infinite alternate;
}
@keyframes ambientGradient {
    0% { background-position: 0% 50%; }
    100% { background-position: 100% 50%; }
}
.ambient-fog {
    position: absolute;
    width: 180vw; height: 60vh;
    left: -40vw; top: 10vh;
    background: radial-gradient(ellipse at 50% 50%, #fff2 0%, #fff0 80%);
    opacity: 0.07;
    filter: blur(36px);
    transform: translateZ(-200px) scale(1.2);
    animation: fogMove 32s linear infinite alternate;
}
@keyframes fogMove {
    0% { left: -40vw; }
    100% { left: 0vw; }
}
.ambient-shadow {
    position: absolute;
    width: 100vw; height: 100vh;
    left: 0; top: 0;
    background: radial-gradient(ellipse at 60% 80%, #000 0%, #0000 80%);
    opacity: 0.09;
    filter: blur(32px);
    transform: translateZ(-300px);
    animation: shadowPulse 18s ease-in-out infinite alternate;
}
@keyframes shadowPulse {
    0% { opacity: 0.08; }
    100% { opacity: 0.16; }
}
.ambient-glow {
    position: absolute;
    width: 120vw; height: 40vh;
    left: -10vw; top: 30vh;
    background: radial-gradient(ellipse at 60% 40%, var(--accent-primary) 0%, transparent 80%);
    opacity: 0.04;
    filter: blur(60px);
    transform: translateZ(-100px);
    animation: glowPulse 22s ease-in-out infinite alternate;
}
@keyframes glowPulse {
    0% { opacity: 0.02; }
    100% { opacity: 0.07; }
}
.ambient-particles {
    position: absolute;
    width: 100vw; height: 100vh;
    left: 0; top: 0;
    pointer-events: none;
    z-index: 1;
}
.ambient-particle {
    position: absolute;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--accent-primary);
    opacity: 0.12;
    filter: blur(2px);
    animation: particleDrift 18s linear infinite;
}
@keyframes particleDrift {
    0% { transform: translateY(0) scale(1); opacity: 0.12; }
    50% { opacity: 0.22; }
    100% { transform: translateY(-60vh) scale(1.2); opacity: 0.08; }
}
.cursor-trail-dot {
    position: fixed;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--accent-primary);
    opacity: 0.18;
    pointer-events: none;
    z-index: 10000;
    filter: blur(4px);
    transition: opacity 0.3s;
}
.story-content.ambient-depth {
    position: relative;
    z-index: 1;
    filter: drop-shadow(0 0 16px #d0000033);
    text-shadow: 0 2px 12px #000a, 0 0 8px #d0000033;
    animation: textShadowMove 8s ease-in-out infinite alternate;
}
@keyframes textShadowMove {
    0% { text-shadow: 0 2px 12px #000a, 0 0 8px #d0000033; }
    50% { text-shadow: 0 4px 24px #000c, 0 0 16px #d0000055; }
    100% { text-shadow: 0 2px 12px #000a, 0 0 8px #d0000033; }
}
.app-container, .story-content {
    position: relative;
    z-index: 1;
}

.story-preview-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 32px;
    padding: 20px 0 40px 0;
}
.story-preview-card {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 0;
    box-shadow: 0 2px 16px 0 var(--card-shadow);
    padding: 28px 24px 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: box-shadow 0.3s, border-color 0.3s;
    position: relative;
}
.story-preview-card:hover {
    box-shadow: 0 0 24px 2px var(--accent-primary), 0 0 2px #fff;
    border-color: var(--accent-primary);
}
.story-preview-card h3 {
    font-size: 1.3em;
    font-family: var(--serif-story);
    margin-bottom: 2px;
}
.story-preview-meta {
    font-size: 0.98em;
    color: var(--text-secondary);
    font-family: var(--mono-ui);
    margin-bottom: 4px;
}
.story-preview-synopsis {
    font-size: 1.05em;
    color: var(--text);
    margin-bottom: 10px;
    font-family: var(--serif-story);
}
.start-reading-btn {
    align-self: flex-end;
    font-family: var(--mono-ui);
    font-size: 1em;
    text-transform: uppercase;
    background: var(--accent-primary);
    color: #fff;
    border: none;
    border-radius: 0;
    padding: 8px 22px;
    cursor: pointer;
    letter-spacing: 0.08em;
    box-shadow: 0 2px 8px 0 var(--card-shadow);
    transition: background 0.2s, box-shadow 0.2s;
}
.start-reading-btn:hover {
    background: var(--accent-secondary);
    box-shadow: 0 0 12px 2px var(--accent-primary);
}
@media (max-width: 600px) {
    .story-preview-list {
        grid-template-columns: 1fr;
        gap: 18px;
    }
    .story-preview-card {
        padding: 18px 10px 14px 10px;
    }
    .start-reading-btn {
        font-size: 0.95em;
        padding: 7px 14px;
    }
}

/* --- Cipher of Shadows Puzzle/Choice UI --- */
.puzzle-block, .cipher-choice-block, .cipher-ending-block {
  background: linear-gradient(120deg, #181a1b 60%, #23272e 100%);
  border: 2px solid #d00000;
  border-radius: 10px;
  box-shadow: 0 0 16px #d0000033, 0 0 2px #fff1;
  padding: 2.2em 1.2em 1.5em 1.2em;
  margin: 1.5em 0 2em 0;
  text-align: center;
  position: relative;
  animation: fadeInUp 0.5s;
}
.puzzle-prompt, .cipher-choice-prompt {
  font-family: var(--mono-ui);
  color: #d00000;
  font-size: 1.15em;
  margin-bottom: 1.2em;
  letter-spacing: 0.04em;
  text-shadow: 0 0 8px #d00000, 0 0 2px #fff;
  animation: glitchText 1.2s infinite alternate-reverse;
}
.puzzle-input {
  width: 70%;
  max-width: 260px;
  padding: 0.7em 1em;
  font-size: 1.1em;
  font-family: var(--mono-ui);
  border: 2px solid #d00000;
  border-radius: 6px;
  background: #0a0a0a;
  color: #fff;
  margin-bottom: 0.7em;
  outline: none;
  box-shadow: 0 0 8px #d0000033;
  transition: border 0.2s, box-shadow 0.2s;
}
.puzzle-input:focus {
  border-color: #fff;
  box-shadow: 0 0 12px #d00000;
}
.puzzle-submit {
  background: #d00000;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-family: var(--mono-ui);
  font-size: 1em;
  padding: 0.6em 1.5em;
  margin-left: 0.5em;
  cursor: pointer;
  box-shadow: 0 0 8px #d00000;
  transition: background 0.2s, box-shadow 0.2s;
}
.puzzle-submit:disabled {
  background: #333;
  color: #888;
  cursor: not-allowed;
  box-shadow: none;
}
.puzzle-error {
  color: #ff3b3b;
  font-size: 0.98em;
  margin-top: 0.7em;
  min-height: 1.2em;
  letter-spacing: 0.03em;
  animation: shake 0.3s;
}
.puzzle-error-anim {
  animation: shake 0.3s;
}
@keyframes shake {
  0% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
  100% { transform: translateX(0); }
}
.cipher-choice-btn {
  background: linear-gradient(90deg, #d00000 60%, #23272e 100%);
  color: #fff;
  border: 2px solid #d00000;
  border-radius: 6px;
  font-family: var(--mono-ui);
  font-size: 1.08em;
  padding: 0.7em 2.2em;
  margin: 0.7em 1.2em 0.2em 1.2em;
  cursor: pointer;
  box-shadow: 0 0 8px #d00000;
  letter-spacing: 0.04em;
  transition: background 0.2s, box-shadow 0.2s, color 0.2s;
}
.cipher-choice-btn:hover, .cipher-choice-btn:focus {
  background: #fff;
  color: #d00000;
  box-shadow: 0 0 16px #d00000;
  outline: none;
}
.cipher-ending-block {
  font-family: var(--mono-ui);
  color: #fff;
  font-size: 1.18em;
  letter-spacing: 0.04em;
  text-shadow: 0 0 8px #d00000, 0 0 2px #fff;
  margin-top: 2em;
  animation: fadeIn 0.7s;
}
.cipher-glitch {
  color: #fff;
  text-shadow: 0 0 8px #d00000, 0 0 2px #fff, 2px 0 #0ff, -2px 0 #f0f, 0 2px #0ff, 0 -2px #f0f;
  animation: glitchText 1.2s infinite alternate-reverse;
}
@keyframes glitchText {
  0% { text-shadow: 2px 0 #0ff, -2px 0 #f0f, 0 2px #0ff, 0 -2px #f0f; }
  20% { text-shadow: 0 0 8px #d00000, 0 0 2px #fff; }
  40% { text-shadow: 2px 2px #0ff, -2px -2px #f0f; }
  60% { text-shadow: 0 0 8px #d00000, 0 0 2px #fff; }
  80% { text-shadow: -2px 2px #0ff, 2px -2px #f0f; }
  100% { text-shadow: 2px 0 #0ff, -2px 0 #f0f, 0 2px #0ff, 0 -2px #f0f; }
}
@media (max-width: 700px) {
  .puzzle-block, .cipher-choice-block, .cipher-ending-block {
    padding: 1.2em 0.5em 1em 0.5em;
    font-size: 0.98em;
  }
  .puzzle-input {
    width: 95%;
    font-size: 1em;
  }
  .cipher-choice-btn {
    width: 90%;
    margin: 0.7em 0 0.2em 0;
    font-size: 1em;
  }
}
/* --- End Cipher of Shadows Puzzle/Choice UI --- */

.next-btn {
    width: auto !important;
    min-width: unset !important;
    max-width: unset !important;
    box-sizing: border-box;
}

#story-reader {
    min-height: 600px;
    position: relative;
}

.story-content {
    display: flex;
    flex-direction: column;
    height: 80vh;
    min-height: 500px;
}

.page-container {
    flex: 1 1 auto;
    padding-bottom: 0;
    overflow-y: auto;
}

.story-controls {
    flex-shrink: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 32px 24px 32px;
    margin-top: 12px;
    position: static;
    background: none;
    z-index: 2;
}

@media (max-width: 700px) {
    .story-content {
        height: auto;
        min-height: unset;
    }
    .story-controls {
        padding: 0;
        margin-top: 24px;
    }
    .page-container {
        padding-bottom: 0;
    }
}

/* XP Bar and Badges */
.xp-badges-bar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    position: absolute;
    top: 1.5rem;
    right: 2.5rem;
    z-index: 10;
}
.xp-bar-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--card-bg);
    border-radius: 2rem;
    padding: 0.3rem 1rem;
    box-shadow: var(--glow);
}
.xp-label {
    font-family: 'Roboto Mono', monospace;
    color: var(--accent);
    font-size: 1rem;
    letter-spacing: 1px;
}
.xp-bar-bg {
    width: 120px;
    height: 12px;
    background: var(--bg);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 0 6px var(--accent) inset;
}
.xp-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), #fff 80%);
    box-shadow: var(--glow);
    border-radius: 8px;
    transition: width 0.5s cubic-bezier(.4,2,.6,1);
}
.xp-value {
    color: var(--text);
    font-family: 'Roboto Mono', monospace;
    font-size: 1rem;
    margin-left: 0.5rem;
    text-shadow: var(--glow);
}
.badge-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.2rem 0.5rem;
    border-radius: 50%;
    box-shadow: var(--glow);
    transition: box-shadow 0.2s, transform 0.2s;
}
.badge-btn:hover, .badge-btn:focus {
    box-shadow: 0 0 16px var(--accent), 0 0 8px #fff;
    transform: scale(1.1);
}
.badge-icon {
    width: 28px;
    height: 28px;
    filter: drop-shadow(0 0 6px var(--accent));
}
.badges-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.95);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.badges-content {
    background: var(--card-bg);
    border-radius: 1.5rem;
    padding: 2rem 2.5rem;
    box-shadow: var(--glow);
    color: var(--text);
    min-width: 320px;
    max-width: 90vw;
    text-align: center;
}
.badges-list {
    display: flex;
    flex-wrap: wrap;
    gap: 1.2rem;
    justify-content: center;
    margin: 1.5rem 0;
}
.badge-earned {
    background: linear-gradient(135deg, var(--accent) 60%, #fff 100%);
    color: var(--bg);
    border-radius: 1rem;
    padding: 0.7rem 1.2rem;
    font-weight: 600;
    box-shadow: var(--glow);
    font-size: 1.1rem;
    text-shadow: 0 0 2px #fff;
    transition: transform 0.2s;
}
.badge-locked {
    background: var(--card-bg);
    color: var(--meta);
    border-radius: 1rem;
    padding: 0.7rem 1.2rem;
    font-weight: 400;
    opacity: 0.5;
    font-size: 1.1rem;
    box-shadow: 0 0 4px var(--accent);
}
.close-badges {
    margin-top: 1rem;
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: 1rem;
    padding: 0.5rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--glow);
    transition: background 0.2s;
}
.close-badges:hover {
    background: #fff;
    color: var(--accent);
}

/* Card Hover Effects */
.story-preview-list .story-card, .continue-list .story-card {
    background: var(--card-bg);
    border-radius: 1.2rem;
    box-shadow: var(--glow);
    transition: box-shadow 0.25s, transform 0.25s, background 0.2s;
    cursor: pointer;
    margin-bottom: 1.5rem;
    padding: 1.2rem 1.5rem;
    position: relative;
    color: var(--card-text);
}
.story-preview-list .story-card:hover, .continue-list .story-card:hover {
    box-shadow: 0 0 24px var(--accent), 0 0 12px #fff;
    transform: translateY(-8px) scale(1.03);
    background: #fff0f0;
}

/* Story Card Readability */
.story-card .story-title {
    font-family: 'Spectral SC', serif;
    font-size: 1.3rem;
    color: var(--accent);
    margin-bottom: 0.5rem;
    text-shadow: var(--glow);
}
.story-card .story-desc {
    font-size: 1.05rem;
    color: var(--card-text);
    line-height: 1.6;
    margin-bottom: 0.7rem;
    padding: 0.2rem 0.1rem;
}
.story-card .story-meta {
    font-size: 0.95rem;
    color: var(--accent);
    margin-bottom: 0.2rem;
}

/* Search Bar & Filters */
.search-bar {
    background: var(--card-bg);
    border: 1.5px solid var(--accent);
    border-radius: 1.2rem;
    color: var(--text);
    font-size: 1.1rem;
    padding: 0.5rem 1.2rem;
    box-shadow: 0 0 8px var(--accent) inset;
    outline: none;
    width: 220px;
    transition: box-shadow 0.2s, border 0.2s;
}
.search-bar:focus {
    box-shadow: 0 0 16px var(--accent), 0 0 8px #fff;
    border: 2px solid var(--accent);
}

/* Continue Reading Section */
.continue-reading-section {
    margin-bottom: 2rem;
}
.continue-reading-section h3 {
    color: var(--accent);
    font-size: 1.15rem;
    margin-bottom: 0.7rem;
    letter-spacing: 1px;
}
.continue-list {
    display: flex;
    flex-wrap: wrap;
    gap: 1.2rem;
}

/* About Author Page */
#about-author .about-content {
    background: var(--card-bg);
    border-radius: 1.5rem;
    box-shadow: var(--glow);
    padding: 2.5rem 2rem;
    margin: 2rem auto;
    max-width: 600px;
    color: var(--text);
    text-align: center;
}
.author-lore {
    font-family: 'Spectral', serif;
    font-size: 1.15rem;
    line-height: 1.7;
    color: var(--card-text);
    text-shadow: var(--glow);
}
.lore-verse {
    font-style: italic;
    margin-bottom: 1.5rem;
}
.meta-hint {
    color: var(--accent);
    font-size: 1rem;
    display: block;
    margin-top: 0.5rem;
    text-shadow: var(--glow);
}

/* Disabled Create Story Button */
.create-story-btn[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
    background: var(--card-bg);
    color: var(--meta);
    border: 1.5px dashed var(--accent);
    box-shadow: var(--glow);
    position: relative;
}
.coming-soon {
    color: var(--accent);
    font-size: 0.9rem;
    margin-left: 0.5rem;
    text-shadow: var(--glow);
}

/* Hero Banner Consistency */
.hero-section {
    background: var(--bg);
    box-shadow: var(--glow);
    padding: 2.2rem 0 1.2rem 0;
    position: relative;
    z-index: 20;
}
.logo {
    font-family: 'Spectral SC', serif;
    font-size: 2.2rem;
    color: var(--accent);
    letter-spacing: 2px;
    text-shadow: var(--glow);
    margin: 0;
}

/* Mobile Optimization */
@media (max-width: 700px) {
    .xp-badges-bar {
        top: 0.7rem;
        right: 1rem;
        gap: 0.7rem;
    }
    .xp-bar-bg {
        width: 70px;
    }
    .hero-section {
        padding: 1.2rem 0 0.7rem 0;
    }
    .about-content {
        padding: 1.2rem 0.5rem;
    }
    .filters {
        flex-direction: column;
        gap: 0.7rem;
        align-items: stretch;
    }
    .continue-list, .story-preview-list {
        flex-direction: column;
        gap: 1rem;
    }
    .story-preview-list .story-card, .continue-list .story-card {
        padding: 1rem 0.7rem;
    }
}

/* Collapsible Filters for Mobile */
@media (max-width: 500px) {
    .filters {
        display: block;
        margin-bottom: 0.7rem;
    }
    .filters.collapsed {
        display: none;
    }
    .filters-toggle-btn {
        display: block;
        background: var(--card-bg);
        color: var(--accent);
        border: 1.5px solid var(--accent);
        border-radius: 1.2rem;
        font-size: 1.05rem;
        padding: 0.4rem 1.1rem;
        margin-bottom: 0.5rem;
        box-shadow: 0 0 6px var(--accent) inset;
        outline: none;
        width: 100%;
        text-align: left;
    }
}

/* Immersive Reader Overlay */
#immersive-reader {
  position: fixed;
  z-index: 9999;
  top: 0; left: 0; right: 0; bottom: 0;
  width: 100vw;
  height: 100vh;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s cubic-bezier(.4,2,.6,1);
}
#immersive-reader.active {
  opacity: 1;
  pointer-events: auto;
  animation: immersiveIn 0.5s cubic-bezier(.4,2,.6,1);
}
@keyframes immersiveIn {
  from { opacity: 0; transform: translateY(40px); }
  to { opacity: 1; transform: none; }
}
.immersive-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.2rem 2rem 0.7rem 2rem;
  background: var(--bg);
  box-shadow: 0 2px 24px var(--accent);
  position: relative;
  z-index: 2;
}
.immersive-tabs {
  display: flex;
  gap: 0.7rem;
}
.immersive-tab {
  background: none;
  border: 2px solid var(--accent);
  color: var(--accent);
  border-radius: 2rem;
  padding: 0.4rem 1.3rem;
  font-size: 1.08rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  box-shadow: 0 0 8px var(--accent) inset;
}
.immersive-tab.active, .immersive-tab:focus {
  background: var(--accent);
  color: var(--bg);
}
.immersive-accessibility {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.immersive-btn {
  background: none;
  border: 2px solid var(--accent);
  color: var(--accent);
  border-radius: 50%;
  width: 2.2rem;
  height: 2.2rem;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 0.2rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border 0.2s;
  box-shadow: 0 0 6px var(--accent) inset;
}
.immersive-btn:focus, .immersive-btn:hover {
  background: var(--accent);
  color: var(--bg);
}
.immersive-theme-toggle .theme-icon {
  font-size: 1.2rem;
}
.immersive-exit-btn {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 1.2rem;
  font-size: 1.05rem;
  padding: 0.4rem 1.1rem;
  margin-left: 1.5rem;
  box-shadow: 0 0 8px var(--accent);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  z-index: 3;
}
.immersive-exit-btn:focus, .immersive-exit-btn:hover {
  background: #fff;
  color: var(--accent);
}
.immersive-content {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 2.2rem 2.5rem 2.5rem 2.5rem;
  font-size: 1.18rem;
  line-height: 1.8;
  max-width: 800px;
  margin: 0 auto;
  color: var(--text);
  background: none;
  transition: font-size 0.2s;
}
.immersive-content.large-text { font-size: 1.38rem; }
.immersive-content.small-text { font-size: 1rem; }

/* Hamburger for mobile */
.immersive-hamburger {
  display: none;
  flex-direction: column;
  gap: 0.2rem;
  background: none;
  border: none;
  width: 2.2rem;
  height: 2.2rem;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  margin-left: 1rem;
}
.immersive-hamburger span {
  display: block;
  width: 1.5rem;
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
}
.immersive-mobile-drawer {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--bg);
  box-shadow: 0 -2px 24px var(--accent);
  padding: 0.7rem 1.2rem;
  z-index: 10001;
  flex-direction: row;
  gap: 1.2rem;
  justify-content: center;
  align-items: center;
}
#immersive-reader.show-drawer .immersive-mobile-drawer {
  display: flex;
}

/* Hide site elements when immersive is active */
body.immersive-active .app-container,
body.immersive-active header,
body.immersive-active nav,
body.immersive-active main,
body.immersive-active .popup-overlay {
  filter: blur(12px) grayscale(0.7) brightness(0.7);
  pointer-events: none;
  user-select: none;
  transition: filter 0.4s;
}
body.immersive-active #immersive-reader {
  display: flex;
}

/* Responsive */
@media (max-width: 700px) {
  #immersive-reader {
    padding: 0;
  }
  .immersive-topbar {
    flex-direction: column;
    align-items: stretch;
    padding: 0.7rem 0.7rem 0.5rem 0.7rem;
    gap: 0.7rem;
  }
  .immersive-content {
    padding: 1.1rem 0.5rem 1.5rem 0.5rem;
    font-size: 1.05rem;
  }
  .immersive-accessibility {
    display: none;
  }
  .immersive-hamburger {
    display: flex;
  }
}
@media (max-width: 500px) {
  .immersive-content {
    font-size: 0.98rem;
    padding: 0.5rem 0.2rem 1.2rem 0.2rem;
  }
}

/* Story text font */
.story-content, .immersive-content, .story-card .story-desc, .story-card .story-title, .immersive-paragraph {
    font-family: 'Book Antiqua', Palatino, 'Palatino Linotype', serif;
}

.immersive-progress-bar {
  width: 100%;
  height: 6px;
  background: linear-gradient(90deg, #18181a 0%, #2d2d2d 100%);
  border-radius: 0;
  box-shadow: 0 0 8px #000a;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 10;
}
.immersive-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--immersive-progress-color, #d00000);
  box-shadow: 0 0 8px var(--immersive-progress-color, #d00000);
  border-radius: 0;
  transition: width 0.35s cubic-bezier(.4,2,.6,1);
}
[data-mood="horror"] .immersive-progress-bar, [data-mood="dark"] .immersive-progress-bar {
  background: linear-gradient(90deg, #18181a 0%, #3a0000 100%);
}
[data-mood="horror"] .immersive-progress-fill, [data-mood="dark"] .immersive-progress-fill {
  background: #d00000;
  box-shadow: 0 0 8px #d00000;
}
[data-mood="reflective"] .immersive-progress-bar {
  background: linear-gradient(90deg, #1a233a 0%, #3a5a8a 100%);
}
[data-mood="reflective"] .immersive-progress-fill {
  background: #4a90e2;
  box-shadow: 0 0 8px #4a90e2;
}

.puzzle-success {
  animation: puzzleSuccessFlash 0.7s;
}
@keyframes puzzleSuccessFlash {
  0% { background: #d00000; }
  30% { background: #2ecc40; color: #fff; box-shadow: 0 0 16px #2ecc40; }
  100% { background: inherit; color: inherit; box-shadow: none; }
}
.puzzle-fail {
  animation: puzzleFailShake 0.5s;
}
@keyframes puzzleFailShake {
  0% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
  100% { transform: translateX(0); }
} 