:root {
    --bg-color: #f8f5f0;
    --text-color: #333;
    --accent-color: #e63946;
    --secondary-color: #457b9d;
    --font-main: 'Inter', sans-serif;
    --glass-bg: rgba(255, 255, 255, 0.2);
    --glass-border: rgba(255, 255, 255, 0.4);
    --shadow-color: rgba(0, 0, 0, 0.1);
}

.dark-theme {
    --bg-color: #0f172a;
    --text-color: #f1f5f9;
    --glass-bg: rgba(30, 41, 59, 0.6);
    --glass-border: rgba(255, 255, 255, 0.1);
    --shadow-color: rgba(0, 0, 0, 0.4);
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-main);
    overflow-x: hidden;
    line-height: 1.6;
}

body.auth-locked {
    overflow: hidden;
}

body.auth-locked #library,
body.auth-locked #presentation,
body.auth-locked .nav-dots,
body.auth-locked #thumb-rail,
body.auth-locked #home-btn,
body.auth-locked #caption-toggle,
body.auth-locked #reader-controls {
    visibility: hidden;
    pointer-events: none;
}

/* Background Texture */
body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background:
        linear-gradient(rgba(255, 255, 255, 0.32), rgba(255, 255, 255, 0.32)),
        repeating-linear-gradient(0deg, rgba(0,0,0,0.025) 0, rgba(0,0,0,0.025) 1px, transparent 1px, transparent 6px);
    opacity: 0.35;
    z-index: -1;
    pointer-events: none;
}

.auth-gate {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background:
        linear-gradient(rgba(248, 245, 240, 0.92), rgba(248, 245, 240, 0.92)),
        repeating-linear-gradient(0deg, rgba(0,0,0,0.025) 0, rgba(0,0,0,0.025) 1px, transparent 1px, transparent 6px);
    z-index: 5000;
}

.auth-gate.hidden {
    display: none;
}

.auth-card {
    width: min(100%, 360px);
    padding: 2rem;
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.82);
    box-shadow: 0 20px 70px rgba(0,0,0,0.14);
    backdrop-filter: blur(18px);
}

.auth-kicker {
    color: var(--accent-color);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.auth-card h1 {
    margin: 0.35rem 0 1.5rem;
    color: var(--text-color);
    font-size: 2rem;
    line-height: 1.1;
    letter-spacing: 0;
}

.auth-field {
    display: grid;
    gap: 0.45rem;
    color: #555;
    font-size: 0.9rem;
    font-weight: 800;
}

.auth-field input {
    width: 100%;
    min-height: 46px;
    border: 1px solid rgba(0,0,0,0.16);
    border-radius: 8px;
    padding: 0.75rem 0.9rem;
    color: var(--text-color);
    background: #fff;
    font: inherit;
    outline: none;
}

.auth-field input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(230, 57, 70, 0.16);
}

.auth-error {
    min-height: 1.4rem;
    margin-top: 0.65rem;
    color: #c1121f;
    font-size: 0.9rem;
    font-weight: 700;
}

.auth-submit {
    width: 100%;
    min-height: 46px;
    margin-top: 0.75rem;
    border: 0;
    border-radius: 8px;
    background: var(--accent-color);
    color: #fff;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.auth-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 28px rgba(230, 57, 70, 0.26);
}

/* Scroll Container */
#presentation {
    height: 100vh;
    overflow-y: scroll;
    scroll-snap-type: y mandatory;
    scrollbar-width: none;
}

#presentation::-webkit-scrollbar {
    display: none;
}

/* Sections */
section {
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    scroll-snap-align: start;
    position: relative;
    padding: 5.5rem 4rem 6.5rem;
    overflow: hidden;
}

/* Content Layout */
.content-wrapper {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1.25rem;
    max-width: 1100px;
    width: min(92vw, 1200px);
    height: calc(100vh - 12rem);
    margin: auto;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease, transform 0.8s ease;
    z-index: 10;
}

section.active .content-wrapper {
    opacity: 1;
    transform: translateY(0);
}

.illustration-container {
    flex: 1 1 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-height: 0; /* Allow shrinking */
    transition: transform 0.1s ease-out; /* Smooth JS parallax */
    will-change: transform;
}

.illustration {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 15px 50px rgba(0,0,0,0.12);
    background: transparent;
    padding: 0;
    border: 0;
}

#presentation:not(.captions-on) .illustration-container {
    flex: 1 1 100%;
}

#presentation:not(.captions-on) .illustration {
    max-height: calc(100vh - 10rem);
}

.title-cover {
    max-width: min(92vw, 1100px);
    max-height: calc(100vh - 10rem);
    box-shadow: none;
}

.title-wrapper {
    gap: 1rem;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.portrait-image {
    max-height: calc(100vh - 10rem);
}

.wide-strip-image {
    width: min(92vw, 1120px);
    max-height: 42vh;
    background: #fff;
    box-shadow: 0 10px 30px rgba(0,0,0,0.08);
}

#presentation.mode-deck .illustration {
    border-radius: 4px;
}

#presentation.mode-photo-page .illustration {
    background: #fff;
    padding: 8px;
    box-shadow: 0 16px 42px rgba(0,0,0,0.14);
}

#presentation.mode-photo-page .portrait-image {
    max-height: calc(100vh - 13rem);
}

#presentation.mode-mixed .illustration {
    background: #fff;
    padding: 6px;
}

.story-text-container {
    display: none;
    flex: 0 0 auto;
    width: 100%;
    max-width: 900px;
    padding: 1.5rem 2rem;
    background: var(--glass-bg);
    backdrop-filter: blur(25px) saturate(200%);
    -webkit-backdrop-filter: blur(25px) saturate(200%);
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 20px 60px var(--shadow-color);
    margin-top: 0;
    z-index: 20;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

#presentation.captions-on .story-text-container {
    display: block;
}

.story-text-container:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-5px);
    box-shadow: 0 15px 50px rgba(0,0,0,0.15);
}

.story-text {
    font-size: 1.35rem;
    font-weight: 500;
    text-align: center;
    max-width: 100%;
    color: var(--text-color);
    line-height: 1.8;
    word-break: keep-all;
    text-shadow: 0 2px 4px var(--shadow-color);
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    section { padding: 4.5rem 1rem 2rem; }
    .content-wrapper { height: calc(100vh - 5rem); width: 94vw; }
    body.reader-panel-open section { padding-bottom: 8.5rem; }
    body.reader-panel-open .content-wrapper { height: calc(100vh - 11.5rem); }
    .story-text { font-size: 1.05rem; line-height: 1.7; }
    h1.title { font-size: 3.4rem; }
    .thumb-rail { display: none; }
    .nav-dots { right: 1rem; }
}

/* Specific Styles */
h1.title {
    font-size: 8rem;
    font-weight: 900;
    margin-bottom: 0;
    color: var(--text-color);
    letter-spacing: 0;
    line-height: 1;
    text-shadow: 0 10px 30px rgba(0,0,0,0.1);
}

.author {
    font-size: 1.2rem;
    color: #888;
    margin-top: 1rem;
}

/* Dot Decorations */
.deco-dot {
    position: absolute;
    border-radius: 50%;
    z-index: -1;
    filter: blur(5px);
    opacity: 0.2;
    transition: all 2s ease;
}

section.active .deco-dot {
    transform: scale(1.5);
    opacity: 0.4;
}

/* Navigation */
.nav-dots {
    position: fixed;
    right: 2rem;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    z-index: 100;
}

.thumb-rail {
    position: fixed;
    left: 50%;
    bottom: 1rem;
    transform: translateX(-50%);
    display: flex;
    gap: 0.5rem;
    width: min(78vw, 920px);
    max-width: calc(100vw - 12rem);
    overflow-x: auto;
    padding: 0.5rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.74);
    backdrop-filter: blur(14px);
    border: 1px solid rgba(0,0,0,0.08);
    box-shadow: 0 10px 30px rgba(0,0,0,0.12);
    z-index: 1200;
    scrollbar-width: thin;
}

.thumb-rail.hidden {
    display: none;
}

.thumb {
    flex: 0 0 auto;
    width: 62px;
    height: 44px;
    border: 2px solid transparent;
    border-radius: 6px;
    background: #f8f9fa;
    color: #333;
    cursor: pointer;
    overflow: hidden;
    padding: 0;
    font-weight: 800;
}

.thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.thumb.active {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(255,255,255,0.85);
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ccc;
    cursor: pointer;
    transition: all 0.3s ease;
}

.dot.active {
    background: var(--accent-color);
    transform: scale(1.4);
}

/* Floating Dots Animation */
@keyframes floatDot {
    0% { transform: translate(0, 0); }
    100% { transform: translate(20px, -20px); }
}

.floating-dot {
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    opacity: 0.3;
    animation: floatDot 5s infinite alternate ease-in-out;
}

/* Library View */
#library {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(248, 245, 240, 0.95);
    backdrop-filter: blur(20px);
    z-index: 2000;
    padding: 4rem 2rem;
    overflow-y: auto;
    transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

#library.hidden {
    transform: translateY(-100%);
}

.library-header {
    text-align: center;
    margin-bottom: 4rem;
}

.library-header h1 {
    font-size: 3.5rem;
    font-weight: 800;
    color: var(--text-color);
    letter-spacing: 0;
}

.library-header p {
    font-size: 1.2rem;
    color: #666;
    margin-top: 1rem;
}

.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 3rem;
    max-width: 1400px;
    margin: 0 auto;
}

.book-card {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.05);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    cursor: pointer;
    position: relative;
    border: 1px solid rgba(0,0,0,0.03);
}

.book-card:hover {
    transform: translateY(-15px) scale(1.02);
    box-shadow: 0 20px 60px rgba(0,0,0,0.12);
}

.book-cover-wrapper {
    width: 100%;
    height: 380px;
    overflow: hidden;
    background: #f1f3f5;
    display: flex;
    align-items: center;
    justify-content: center;
}

.book-cover {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform 0.6s ease;
}

.book-card:hover .book-cover {
    transform: scale(1.1);
}

.book-info {
    padding: 1.5rem;
    background: white;
}

.book-title {
    font-size: 1.4rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.book-author {
    font-size: 1rem;
    color: #888;
}

/* Home/Library Button */
.home-btn {
    position: fixed;
    top: 2rem;
    left: 2rem;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0,0,0,0.1);
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    z-index: 1500;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.home-btn:hover {
    background: white;
    transform: translateX(5px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.home-btn.hidden {
    display: none;
}

.caption-toggle {
    position: fixed;
    top: 2rem;
    left: 11.25rem;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    border: 1px solid rgba(0,0,0,0.1);
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    color: var(--text-color);
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    z-index: 1500;
    transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.caption-toggle:hover {
    background: white;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.caption-toggle[aria-pressed="true"] {
    background: var(--accent-color);
    color: white;
    border-color: transparent;
}

.caption-toggle.hidden {
    display: none;
}

.reader-controls {
    position: fixed;
    top: 2rem;
    left: 14.75rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.45rem;
    max-width: calc(100vw - 17rem);
    border-radius: 8px;
    z-index: 1500;
}

.reader-controls.hidden {
    display: none;
}

.reader-compact,
.reader-panel {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem;
    border-radius: 8px;
    border: 1px solid rgba(0,0,0,0.1);
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: blur(12px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.08);
}

.reader-panel {
    align-self: flex-start;
    max-width: min(760px, calc(100vw - 17rem));
}

.reader-panel.hidden {
    display: none;
}

.reader-icon-btn {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid rgba(0,0,0,0.1);
    background: #fff;
    color: var(--text-color);
    font-weight: 800;
    cursor: pointer;
    line-height: 1;
    transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.reader-play-btn {
    width: 42px;
}

.reader-menu-btn {
    min-width: 54px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid rgba(0,0,0,0.1);
    background: #fff;
    color: var(--text-color);
    font-size: 0.88rem;
    font-weight: 800;
    cursor: pointer;
    padding: 0 0.7rem;
    transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.reader-icon-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 5px 14px rgba(0,0,0,0.12);
}

.reader-menu-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 5px 14px rgba(0,0,0,0.12);
}

.reader-menu-btn[aria-expanded="true"] {
    background: var(--accent-color);
    border-color: transparent;
    color: #fff;
}

.reader-icon-btn[aria-pressed="true"] {
    background: var(--accent-color);
    border-color: transparent;
    color: #fff;
}

.reader-field {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 92px;
    color: var(--text-color);
    font-size: 0.72rem;
    font-weight: 800;
    line-height: 1.15;
}

.reader-field span {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    white-space: nowrap;
    color: rgba(51, 51, 51, 0.74);
}

.dark-theme .reader-field span {
    color: rgba(241, 245, 249, 0.78);
}

.reader-field select,
.reader-field input {
    width: 100%;
}

.reader-field select {
    height: 32px;
    border: 1px solid rgba(0,0,0,0.12);
    border-radius: 6px;
    background: #fff;
    color: #222;
    font: inherit;
    font-size: 0.82rem;
    padding: 0 0.45rem;
}

.reader-voice-field {
    min-width: 180px;
}

.reader-rate-field {
    min-width: 130px;
}

.reader-rate-field input {
    accent-color: var(--accent-color);
}

.reader-disclosure {
    flex: 0 0 auto;
    padding: 0.3rem 0.45rem;
    border-radius: 6px;
    background: rgba(0,0,0,0.06);
    color: rgba(51, 51, 51, 0.72);
    font-size: 0.72rem;
    font-weight: 800;
    white-space: nowrap;
}

.dark-theme .reader-disclosure {
    background: rgba(255,255,255,0.12);
    color: rgba(241, 245, 249, 0.78);
}

/* Mobile Adjustments for Library */
@media (max-width: 768px) {
    #library { padding: 2rem 1rem; }
    .library-header h1 { font-size: 2.5rem; }
    .book-grid { grid-template-columns: 1fr; gap: 2rem; }
    .book-cover-wrapper { height: 300px; }
    .home-btn { top: 1rem; left: 1rem; padding: 0.6rem 1rem; font-size: 0.9rem; }
    .caption-toggle { top: 1rem; left: auto; right: 1rem; }
    .reader-controls {
        top: auto;
        left: 50%;
        right: auto;
        bottom: 0.75rem;
        width: min(94vw, 440px);
        max-width: none;
        transform: translateX(-50%);
        align-items: stretch;
        gap: 0.4rem;
    }
    .reader-compact {
        align-self: center;
        width: max-content;
        margin: 0 auto;
        background: rgba(255, 255, 255, 0.88);
    }
    .reader-panel {
        display: grid;
        grid-template-columns: 40px minmax(0, 1fr) minmax(0, 1fr);
        align-items: end;
        width: 100%;
        max-width: none;
        overflow: hidden;
        background: rgba(255, 255, 255, 0.92);
    }
    .reader-field {
        min-width: 0;
    }
    .reader-voice-field {
        grid-column: 1 / -1;
        min-width: 0;
    }
    .reader-rate-field {
        min-width: 0;
    }
    .reader-disclosure {
        align-self: center;
        justify-self: end;
    }
    .thumb-rail { display: none; }
}
