:root {
    --bg-dark: #0f172a;
    --bg-darker: #080e1e;
    --bg-card: #1e293b;
    --bg-card-hover: #263349;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --accent: #3b82f6;
    --accent-glow: rgba(59, 130, 246, 0.15);
    --accent-soft: #2563eb;
    --border: rgba(51, 65, 85, 0.6);
    --border-light: rgba(51, 65, 85, 0.3);
    --sidebar-width: 340px;
    --mobile-header-h: 56px;
    --transition-speed: 0.3s;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Outfit', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-darker);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* ========== Mobile Header ========== */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--mobile-header-h);
    background-color: var(--bg-dark);
    border-bottom: 1px solid var(--border);
    align-items: center;
    padding: 0 16px;
    z-index: 100;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.mobile-header-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-left: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Hamburger Button */
.hamburger {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    transition: background var(--transition-speed);
    flex-shrink: 0;
}

.hamburger:hover {
    background-color: rgba(255,255,255,0.08);
}

.hamburger span {
    display: block;
    width: 100%;
    height: 2px;
    background-color: var(--text-primary);
    border-radius: 2px;
    transition: all var(--transition-speed) ease;
    transform-origin: center;
}

.hamburger.open span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}
.hamburger.open span:nth-child(2) {
    opacity: 0;
}
.hamburger.open span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* ========== Sidebar Overlay (mobile) ========== */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 49;
    opacity: 0;
    transition: opacity var(--transition-speed) ease;
}

.sidebar-overlay.visible {
    display: block;
    opacity: 1;
}

/* ========== App Container ========== */
.app-container {
    display: flex;
    width: 100%;
    height: 100vh;
    height: 100dvh;
}

/* ========== Sidebar ========== */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background-color: var(--bg-dark);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 50;
}

.sidebar-header {
    padding: 24px 20px 20px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(30,41,59,0.9) 0%, var(--bg-dark) 100%);
}

.sidebar-header-top {
    display: flex;
    align-items: center;
    gap: 16px;
}

.book-icon {
    width: 64px;
    height: 64px;
    border-radius: 14px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.35);
    object-fit: cover;
    flex-shrink: 0;
    transition: transform var(--transition-speed) ease;
}

.book-icon:hover {
    transform: scale(1.05);
}

.sidebar-header-info {
    flex: 1;
    min-width: 0;
}

.book-selector {
    margin-bottom: 6px;
}

.book-selector select {
    width: 100%;
    padding: 8px 12px;
    font-size: 1rem;
    font-family: inherit;
    font-weight: 700;
    color: var(--text-primary);
    background-color: var(--bg-darker);
    border: 1px solid var(--border);
    border-radius: 10px;
    outline: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
    transition: border-color var(--transition-speed);
}

.book-selector select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.author {
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 400;
    letter-spacing: 0.3px;
}

/* ========== Search ========== */
.search-box {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    position: relative;
}

.search-icon {
    position: absolute;
    left: 32px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
    pointer-events: none;
}

.search-box input {
    width: 100%;
    padding: 10px 14px 10px 38px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background-color: var(--bg-darker);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    transition: all var(--transition-speed) ease;
}

.search-box input::placeholder {
    color: var(--text-secondary);
}

.search-box input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

/* ========== Chapter List ========== */
.chapter-list {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.chapter-list::-webkit-scrollbar {
    width: 5px;
}

.chapter-list::-webkit-scrollbar-track {
    background: transparent;
}

.chapter-list::-webkit-scrollbar-thumb {
    background-color: rgba(148,163,184,0.25);
    border-radius: 10px;
}

.chapter-item {
    padding: 14px 20px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-light);
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
}

.chapter-item:hover {
    background-color: rgba(59, 130, 246, 0.08);
    border-left-color: rgba(59, 130, 246, 0.4);
}

.chapter-item.active {
    background-color: var(--accent);
    border-left-color: #fff;
}

.chapter-number {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1.2px;
    margin-bottom: 3px;
    font-weight: 500;
}

.chapter-item.active .chapter-number {
    color: rgba(255, 255, 255, 0.75);
}

.chapter-title {
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.3;
}

/* ========== Main Content ========== */
.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background:
        radial-gradient(ellipse at 80% 10%, rgba(59,130,246,0.06), transparent 60%),
        radial-gradient(ellipse at 20% 90%, rgba(139,92,246,0.04), transparent 50%),
        var(--bg-darker);
    position: relative;
}

.content-wrapper {
    max-width: 780px;
    margin: 0 auto;
    padding: 60px 48px;
    width: 100%;
}

/* ========== Welcome Screen ========== */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 55vh;
    text-align: center;
    color: var(--text-secondary);
    animation: fadeIn 0.5s ease;
}

.welcome-icon {
    font-size: 3.5rem;
    margin-bottom: 18px;
    opacity: 0.45;
}

.welcome-screen h2 {
    font-size: 1.6rem;
    color: var(--text-primary);
    margin-bottom: 10px;
    font-weight: 600;
}

.welcome-screen p {
    font-size: 1rem;
    line-height: 1.7;
    max-width: 420px;
}

/* ========== Summary Card ========== */
.summary-card {
    background-color: rgba(30, 41, 59, 0.6);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 44px;
    box-shadow:
        0 4px 6px rgba(0,0,0,0.1),
        0 20px 40px rgba(0,0,0,0.2);
    animation: slideUp 0.35s ease-out;
}

.summary-header {
    margin-bottom: 28px;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(59, 130, 246, 0.2);
}

.summary-chapter-num {
    color: var(--accent);
    font-weight: 600;
    font-size: 0.9rem;
    letter-spacing: 2.5px;
    text-transform: uppercase;
    margin-bottom: 8px;
    display: block;
}

.summary-title {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.3;
    background: linear-gradient(135deg, #fff 40%, #64748b);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.summary-body {
    font-size: 1.05rem;
    line-height: 1.9;
    color: var(--text-primary);
    font-weight: 300;
}

.summary-body p {
    margin-bottom: 16px;
}

.summary-body p:last-child {
    margin-bottom: 0;
}

/* ========== Chapter Navigation ========== */
.chapter-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 32px;
    gap: 12px;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background-color: rgba(30, 41, 59, 0.5);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    max-width: 48%;
}

.nav-btn:hover {
    background-color: var(--accent);
    border-color: var(--accent);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59,130,246,0.3);
}

.nav-btn:active {
    transform: translateY(0);
}

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

.nav-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.nav-btn-label {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.nav-btn-sub {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.nav-btn:hover .nav-btn-sub {
    color: rgba(255,255,255,0.7);
}

.nav-btn-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
}

.nav-btn.prev {
    text-align: left;
}

.nav-btn.next {
    margin-left: auto;
    text-align: right;
}

.nav-btn.next .nav-btn-label {
    align-items: flex-end;
}

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

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

/* ========== Tablet (<=1024px) ========== */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 300px;
    }

    .content-wrapper {
        padding: 48px 36px;
    }

    .summary-card {
        padding: 36px;
    }

    .summary-title {
        font-size: 1.8rem;
    }
}

/* ========== Mobile (<=768px) ========== */
@media (max-width: 768px) {
    .mobile-header {
        display: flex;
    }

    .app-container {
        padding-top: var(--mobile-header-h);
    }

    /* Sidebar slides in BELOW the mobile header */
    .sidebar {
        position: fixed;
        top: var(--mobile-header-h);
        left: 0;
        bottom: 0;
        width: 300px;
        min-width: 300px;
        transform: translateX(-100%);
        transition: transform var(--transition-speed) ease;
        box-shadow: 4px 0 24px rgba(0,0,0,0.4);
        z-index: 90;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* Overlay also below header */
    .sidebar-overlay.visible {
        top: var(--mobile-header-h);
    }

    .content-wrapper {
        padding: 28px 20px;
    }

    .summary-card {
        padding: 28px 24px;
        border-radius: 16px;
    }

    .summary-header {
        margin-bottom: 20px;
        padding-bottom: 16px;
    }

    .summary-chapter-num {
        font-size: 0.8rem;
    }

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

    .summary-body {
        font-size: 0.95rem;
        line-height: 1.8;
    }

    .welcome-screen {
        min-height: 50vh;
    }

    .welcome-icon {
        font-size: 3rem;
    }

    .welcome-screen h2 {
        font-size: 1.3rem;
    }

    .welcome-screen p {
        font-size: 0.9rem;
        padding: 0 12px;
    }

    .chapter-nav {
        margin-top: 24px;
    }

    .nav-btn {
        padding: 10px 14px;
        font-size: 0.85rem;
        border-radius: 10px;
    }

    .nav-btn-sub {
        font-size: 0.65rem;
    }
}

/* ========== Small Mobile (<=420px) ========== */
@media (max-width: 420px) {
    .sidebar {
        width: 85vw;
        min-width: 85vw;
    }

    .content-wrapper {
        padding: 20px 16px;
    }

    .summary-card {
        padding: 22px 18px;
        border-radius: 14px;
    }

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

    .summary-body {
        font-size: 0.9rem;
        line-height: 1.75;
    }

    .book-icon {
        width: 52px;
        height: 52px;
    }

    .book-selector select {
        font-size: 0.9rem;
        padding: 7px 10px;
    }

    .nav-btn {
        padding: 10px 12px;
        gap: 6px;
    }

    .nav-btn-title {
        font-size: 0.8rem;
    }
}
