* {
    box-sizing: border-box;
}

:root {
    color-scheme: light dark;
    --color-brand: #E00800;
    --color-brand-secondary: #011744;
    --color-bg: #f8f9fb;
    --color-surface: #ffffff;
    --color-text: #1f1f2e;
    --color-muted: #5c5c72;
    --color-border: rgba(0, 0, 0, 0.08);
}

body.dark-mode {
    --color-bg: #0f0f18;
    --color-surface: #151526;
    --color-text: #f2f3ff;
    --color-muted: #a6aacc;
    --color-border: rgba(255, 255, 255, 0.14);
    background: var(--color-bg);
}

body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    transition: background 0.3s ease, color 0.3s ease;
}

a {
    color: inherit;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--color-border);
    border-top-color: var(--color-brand);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

main.landing {
    padding: clamp(48px, 6vw, 80px) clamp(16px, 5vw, 48px);
    padding-top: 120px;
    width: min(100%, 1240px);
    margin: 0 auto;
}

/* NAVIGATION */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px clamp(16px, 4vw, 40px);
    background: var(--color-brand);
    color: #fff;
    z-index: 100;
    box-shadow: 0 9px 16px rgba(0, 0, 0, 0.16);
}

body.dark-mode .navbar {
    background: #011744;
}

.navbar__left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.navbar__brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

.navbar__brand:hover {
    opacity: 0.9;
}

.navbar__brand img {
    height: 44px;
    width: auto;
}

.navbar__brand span {
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.navbar__actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.text-button {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 8px 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
}

.text-button:hover,
.text-button:focus {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.5);
}

.theme-toggle {
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: transparent;
    border-radius: 999px;
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    padding: 0;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.5);
}

/* Theme icon toggle */
.theme-icon {
    display: none;
}

body:not(.dark-mode) .theme-icon--light {
    display: block;
}

body.dark-mode .theme-icon--dark {
    display: block;
}

.cover-grid {
    display: grid;
    justify-items: center;
    align-items: start;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    column-gap: clamp(12px, 2.5vw, 20px);
    row-gap: clamp(12px, 2.5vw, 20px);
    max-width: 960px; /* ← ADDED THIS LINE */
    margin: 0 auto;   /* ← AND THIS LINE TO CENTER THE GRID */
}

.cover-card {
    background: var(--color-surface);
    border-radius: 18px;
    padding: 12px;
    border: 1px solid var(--color-border);
    box-shadow: 0 15px 32px rgba(0, 0, 0, 0.08);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
    text-align: center;
    width: 100%;
    max-width: 160px;
}

.cover-card img {
    width: 100%;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    border-radius: 12px;
    margin-bottom: 12px;
}
.cover-card__placeholder {
    object-fit: contain;
    background: rgba(0, 0, 0, 0.04);
    padding: 12px;
}



.cover-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 22px 50px rgba(0, 0, 0, 0.12);
}

.cover-card span {
    font-weight: 600;
}

.back-button {
    border: none;
    background: var(--color-brand);
    color: #fff;
    font-weight: 600;
    padding: 10px 18px;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 12px 25px rgba(224, 8, 0, 0.25);
}

.back-button:hover {
    filter: brightness(1.08);
}

.loading-message,
.empty-message {
    text-align: center;
    padding: 24px;
    color: var(--color-muted);
    background: var(--color-surface);
    border-radius: 16px;
    border: 1px dashed var(--color-border);
}

.lesson-audio-page {
    min-height: 100vh;
    padding: clamp(48px, 6vw, 80px) clamp(16px, 5vw, 48px);
    padding-top: 120px;
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: clamp(24px, 4vw, 40px);
}

.lesson-audio-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    text-align: center;
    padding: 20px 0;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--color-brand-secondary);
    text-decoration: none;
    font-weight: 600;
}

.back-link svg {
    width: 18px;
    height: 18px;
}

.lesson-audio-titles {
    flex: 1;
    min-width: 220px;
}

.lesson-audio-titles h1 {
    margin: 0;
    font-size: clamp(1.6rem, 3vw, 2.2rem);
}

.lesson-audio-titles p {
    margin: 0.35rem 0 0;
    color: var(--color-muted);
    font-size: 0.95rem;
}

.lesson-audio-list {
    display: grid;
    gap: clamp(18px, 4vw, 24px);
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

.audio-stack {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 16px;
    padding: clamp(16px, 3vw, 24px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.06);
    display: grid;
    gap: 0.75rem;
    width: 100%;
}

.audio-stack__label {
    margin: 0;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1rem;
}

.audio-stack audio {
    width: 100%;
}

.scrub-controls {
    display: none;
    align-items: center;
    gap: 0.75rem;
}

.scrub-controls.visible {
    display: inline-flex;
}

.scrub-button {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--color-border);
    background: var(--surface);
    color: var(--color-brand);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.scrub-button:hover,
.scrub-button:focus {
    background: var(--color-brand);
    color: #fff;
    border-color: transparent;
}

.scrub-button svg {
    width: 18px;
    height: 18px;
}

.error-detail {
    margin-top: 0.5rem;
    padding: 0.75rem 1rem;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    font-family: 'Fira Code', 'SFMono-Regular', Menlo, Consolas, monospace;
    font-size: 0.78rem;
    color: var(--color-muted);
    white-space: pre-wrap;
    word-break: break-word;
    overflow-x: auto;
}

@media (max-width: 1024px) {
    .cover-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .lesson-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    main.landing {
        padding: 96px 16px 60px;
    }

    .cover-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .lesson-audio-page {
        padding: 110px 16px 48px;
    }

    .lesson-audio-header {
        flex-direction: column;
        align-items: center;
    }
}

@media (max-width: 768px) {
    /* Hide navbar branding text on tablets and below */
    .navbar__brand span {
        display: none;
    }

    /* Hide book cover on mobile/tablet - show only pills */
    .book-cover-wrapper {
        display: none;
    }

    /* Make book page container stack vertically */
    .book-page-container {
        flex-direction: column;
        gap: 20px;
    }

    /* Reduce pill columns on smaller screens */
    .lesson-button-grid,
    .lesson-pills {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        justify-items: center;
    }
}

@media (max-width: 520px) {
    .navbar__left {
        gap: 6px;
    }

    .navbar__actions {
        gap: 4px;
    }

    .text-button {
        font-size: 10px;
        padding: 5px 6px;
    }

    .icon-button,
    .theme-toggle {
        width: 36px;
        height: 36px;
    }

    .icon-button svg,
    .theme-icon {
        width: 18px;
        height: 18px;
    }

    .navbar__brand img {
        height: 36px;
    }

    /* Further reduce pill columns on very small screens */
    .lesson-button-grid,
    .lesson-pills {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        justify-items: center;
    }
}

