/* =========================================
   READ A STORY – Premium Book-Style Design
   ========================================= */

/* --- VARIABLES --- */
:root {
    --bg: #f5f0e8;
    --sidebar-bg: #2c2c2c;
    --sidebar-text: #e0d8cc;
    --sidebar-active: #e8c36a;
    --reader-bg: #fffef9;
    --text-color: #3a3226;
    --text-muted: #8a7e6e;
    --accent: #c0924c;
    --accent-light: #f3e8d4;
    --border: #e0d8c8;
    --shadow: rgba(60, 50, 30, 0.08);
    --popup-bg: #fffdf5;
    --font-body: 'Libre Baskerville', Georgia, 'Times New Roman', serif;
    --font-ui: 'Inter', 'Segoe UI', Tahoma, sans-serif;
    --sidebar-width: 280px;
    --header-height: 56px;
}

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

/* --- BODY --- */
body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* --- HEADER --- */
#app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 20px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

#app-header h1 {
    font-family: var(--font-ui);
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: var(--sidebar-active);
}

.nav-btn {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    color: var(--sidebar-text);
    font-family: var(--font-ui);
    font-weight: 500;
    font-size: 0.9rem;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.nav-btn:hover {
    opacity: 1;
}

.back-link {
    left: 20px;
}

.home-link {
    right: 20px;
    font-size: 1.1rem;
}

/* --- MOBILE SIDEBAR TOGGLE --- */
#sidebar-toggle {
    display: none;
    position: sticky;
    top: var(--header-height);
    z-index: 50;
    width: 100%;
    background: var(--accent-light);
    border: none;
    border-bottom: 1px solid var(--border);
    padding: 10px 20px;
    font-family: var(--font-ui);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent);
    cursor: pointer;
    text-align: left;
}

#sidebar-toggle i {
    margin-right: 8px;
}

/* --- LAYOUT --- */
#app-layout {
    display: flex;
    flex: 1;
    position: relative;
}

/* --- SIDEBAR --- */
#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    overflow-y: auto;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-header {
    padding: 20px 20px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-header h2 {
    font-family: var(--font-ui);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
}

#sidebar-close {
    display: none;
    position: absolute;
    top: 14px;
    right: 14px;
    background: none;
    border: none;
    color: var(--sidebar-text);
    font-size: 1.3rem;
    cursor: pointer;
}

/* Chapter list */
#chapter-list {
    padding: 10px 0;
    flex: 1;
}

.chapter-item {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 11px 20px;
    font-family: var(--font-ui);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--sidebar-text);
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: all 0.15s ease;
    text-decoration: none;
    line-height: 1.4;
}

.chapter-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
}

.chapter-item.active {
    background: rgba(232, 195, 106, 0.08);
    border-left-color: var(--sidebar-active);
    color: var(--sidebar-active);
    font-weight: 700;
}

.chapter-num {
    font-size: 0.7rem;
    opacity: 0.5;
    min-width: 18px;
}

/* --- MAIN READER --- */
#reader {
    flex: 1;
    max-width: 720px;
    margin: 0 auto;
    padding: 50px 40px 80px;
}

#chapter-content {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chapter-title {
    font-family: var(--font-body);
    font-size: 1.9rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 8px;
    line-height: 1.3;
}

.chapter-number {
    font-family: var(--font-ui);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.chapter-divider {
    width: 60px;
    height: 3px;
    background: var(--accent);
    border: none;
    border-radius: 2px;
    margin: 20px 0 35px;
}

/* Paragraphs & sentences */
.story-paragraph {
    margin-bottom: 22px;
    line-height: 1.95;
    font-size: 1.08rem;
}

.sentence {
    cursor: pointer;
    border-radius: 3px;
    transition: background 0.15s ease, color 0.15s ease;
    padding: 1px 0;
}

.sentence:hover {
    background: var(--accent-light);
}

.sentence.active {
    background: var(--accent);
    color: #fff;
    padding: 1px 4px;
    border-radius: 4px;
}

/* --- CHAPTER NAVIGATION --- */
#chapter-nav {
    display: flex;
    justify-content: space-between;
    margin-top: 50px;
    padding-top: 30px;
    border-top: 1px solid var(--border);
}

.chapter-nav-btn {
    font-family: var(--font-ui);
    font-size: 0.9rem;
    font-weight: 600;
    padding: 10px 22px;
    background: var(--reader-bg);
    color: var(--accent);
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chapter-nav-btn:hover {
    border-color: var(--accent);
    background: var(--accent-light);
}

.chapter-nav-btn:disabled {
    opacity: 0.3;
    cursor: default;
    pointer-events: none;
}

/* --- TRANSLATION POPUP --- */
#translation-popup {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: var(--popup-bg);
    border-top: 3px solid var(--accent);
    box-shadow: 0 -8px 40px rgba(60, 50, 30, 0.15);
    padding: 20px 28px 24px;
    transform: translateY(0);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 50vh;
    overflow-y: auto;
}

#translation-popup.hidden {
    transform: translateY(100%);
    pointer-events: none;
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.popup-label {
    font-family: var(--font-ui);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--accent);
}

.popup-label i {
    margin-right: 6px;
}

#popup-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
}

#popup-close:hover {
    color: var(--text-color);
}

.popup-en {
    font-family: var(--font-body);
    font-size: 1.05rem;
    color: var(--text-color);
    margin-bottom: 6px;
    font-style: italic;
}

.popup-de {
    font-family: var(--font-ui);
    font-size: 0.95rem;
    color: var(--accent);
    font-weight: 600;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

/* Word-by-word */
.popup-words {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.word-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--accent-light);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    min-width: 48px;
    transition: transform 0.15s ease;
}

.word-chip:hover {
    transform: translateY(-2px);
    box-shadow: 0 3px 8px var(--shadow);
}

.word-en {
    font-family: var(--font-body);
    font-size: 0.88rem;
    color: var(--text-color);
    font-weight: 700;
}

.word-de {
    font-family: var(--font-ui);
    font-size: 0.72rem;
    color: var(--accent);
    margin-top: 2px;
}

/* --- SCROLLBAR --- */
#sidebar::-webkit-scrollbar {
    width: 6px;
}

#sidebar::-webkit-scrollbar-track {
    background: transparent;
}

#sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 3px;
}

/* --- RESPONSIVE --- */
@media (max-width: 768px) {
    #sidebar-toggle {
        display: flex;
        align-items: center;
    }

    #sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 85vw;
        max-width: 320px;
        height: 100vh;
        z-index: 300;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    #sidebar.open {
        left: 0;
    }

    #sidebar-close {
        display: block;
    }

    #sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 250;
    }

    #sidebar-overlay.show {
        display: block;
    }

    #reader {
        padding: 30px 20px 80px;
    }

    .chapter-title {
        font-size: 1.5rem;
    }

    .nav-btn span {
        display: none;
    }
}

@media (max-width: 480px) {
    #reader {
        padding: 24px 16px 80px;
    }

    .story-paragraph {
        font-size: 1rem;
    }

    .chapter-title {
        font-size: 1.3rem;
    }

    #translation-popup {
        padding: 16px 18px 20px;
    }
}