/* Audiobook Panel Styles */

/* Theme variables for audiobook - uses force-theme-* classes from rfw-themes.css */
.audiobook-panel,
.audiobook-drawer,
.audiobook-chapters-drawer {
    /* Default to nature/green theme */
    --audiobook-primary: var(--primary, #4caf50);
    --audiobook-primary-dark: var(--primary-dark, #2e7d32);
    --audiobook-primary-light: var(--primary-light, #81c784);
    --audiobook-accent: var(--accent, #66bb6a);
}

/* Nav bar audiobook button (reusable - can appear multiple times on page) */
.start-audiobook-btn.top-nav-link {
    background: none;
    border: none;
    cursor: pointer;
    color: white;
    font-size: inherit;
    padding: 0;
}

.start-audiobook-btn.top-nav-link:hover {
    opacity: 0.8;
}

.audiobook-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s ease;
    /* Required for absolute positioned children like chapters drawer */
}

.audiobook-panel.showing {
    transform: translateY(0);
}

.audiobook-panel.hidden {
    display: none;
}

.audiobook-content {
    background: linear-gradient(135deg, var(--audiobook-primary-dark) 0%, color-mix(in srgb, var(--audiobook-primary-dark) 60%, black) 100%);
    color: white;
    padding: 1rem 1.5rem;
    border-top-left-radius: 1rem;
    border-top-right-radius: 1rem;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}

/* Header */
.audiobook-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.audiobook-title-section {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.audiobook-icon {
    font-size: 1.25rem;
}

.audiobook-title {
    font-weight: 600;
    font-size: 1rem;
}

.audiobook-close-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    transition: background 0.2s;
}

.audiobook-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Loading */
.audiobook-loading {
    position: absolute;
    top: 4rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 2rem;
    z-index: 10;
    opacity: 1;
    transition: opacity 0.2s;
    font-size: 0.875rem;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.audiobook-loading.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Error */
.audiobook-error {
    position: absolute;
    top: 4rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.625rem 1.25rem;
    background: rgba(180, 50, 50, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 2rem;
    z-index: 10;
    opacity: 1;
    transition: opacity 0.2s;
    font-size: 0.875rem;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.audiobook-error.hidden {
    opacity: 0;
    pointer-events: none;
}

.audiobook-retry-btn {
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 1rem;
    color: white;
    padding: 0.25rem 0.75rem;
    font-size: 0.8125rem;
    cursor: pointer;
    transition: background 0.2s;
}

.audiobook-retry-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.audiobook-spinner {
    width: 1rem;
    height: 1rem;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Info */
.audiobook-info {
    text-align: center;
    margin-bottom: 0.75rem;
}

.audiobook-section {
    font-size: 0.75rem;
    opacity: 0.8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.audiobook-page-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin-top: 0.25rem;
}

/* Progress */
.audiobook-progress-container {
    margin-bottom: 0.75rem;
}

.audiobook-progress-bar {
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    cursor: pointer;
    overflow: hidden;
}

.audiobook-progress-fill {
    height: 100%;
    background: white;
    border-radius: 3px;
    width: 0%;
    transition: width 0.1s linear;
}

.audiobook-time {
    display: flex;
    justify-content: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    opacity: 0.8;
    margin-top: 0.25rem;
}

/* Controls */
.audiobook-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.audiobook-btn {
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.audiobook-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.audiobook-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.audiobook-nav-btn {
    width: 2.5rem;
    height: 2.5rem;
}

.audiobook-play-btn {
    width: 3.5rem;
    height: 3.5rem;
    background: white;
    color: var(--audiobook-primary-dark);
    font-size: 1.25rem;
}

.audiobook-play-btn:hover {
    background: #f0f0f0;
}

/* Footer */
.audiobook-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.875rem;
}

.audiobook-page-indicator {
    opacity: 0.8;
}

.audiobook-voice-select {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.audiobook-voice-select label {
    opacity: 0.8;
}

.audiobook-voice-select select {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 0.25rem;
    color: white;
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    cursor: pointer;
}

.audiobook-voice-select select option {
    background: var(--audiobook-primary-dark);
    color: white;
}

/* Visual Content Prompt */
.audiobook-visual-prompt {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    border-top-left-radius: 1rem;
    border-top-right-radius: 1rem;
}

.audiobook-visual-prompt.hidden {
    display: none;
}

.visual-prompt-content {
    text-align: center;
    padding: 2rem;
}

.visual-prompt-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.visual-prompt-content h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.visual-prompt-content p {
    opacity: 0.8;
    margin-bottom: 1.5rem;
}

.visual-prompt-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.visual-prompt-buttons .btn {
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-view {
    background: transparent;
    border: 2px solid white;
    color: white;
}

.btn-view:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-continue {
    background: white;
    border: 2px solid white;
    color: var(--audiobook-primary-dark);
}

.btn-continue:hover {
    background: #f0f0f0;
}

/* Audiobook Start Button */
.audiobook-entry {
    display: flex;
    justify-content: center;
    margin: 1rem 0;
}

.audiobook-start-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: linear-gradient(135deg, var(--audiobook-primary-dark) 0%, color-mix(in srgb, var(--audiobook-primary-dark) 60%, black) 100%);
    color: white;
    border: none;
    border-radius: 2rem;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 8px color-mix(in srgb, var(--audiobook-primary-dark) 30%, transparent);
}

.audiobook-start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px color-mix(in srgb, var(--audiobook-primary-dark) 40%, transparent);
}

.audiobook-start-btn .btn-icon {
    font-size: 1.25rem;
}

/* ==========================================
   Phase 2: Header Buttons
   ========================================== */

.audiobook-header-buttons {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.audiobook-icon-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    transition: background 0.2s;
}

.audiobook-icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ==========================================
   Phase 2: Chapters Drawer
   ========================================== */

.audiobook-chapters-drawer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 80vh;
    background: linear-gradient(180deg, var(--audiobook-primary-dark) 0%, color-mix(in srgb, var(--audiobook-primary-dark) 60%, black) 100%);
    border-top-left-radius: 1rem;
    border-top-right-radius: 1rem;
    transform: translateY(0);
    transition: transform 0.3s ease-out, background 0.3s ease;
    overflow-y: auto;
    z-index: 1100;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
    color: white;
}

.audiobook-chapters-drawer.hidden {
    transform: translateY(100%);
    pointer-events: none;
}

.chapters-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    position: sticky;
    top: 0;
    background: linear-gradient(180deg, var(--audiobook-primary-dark) 0%, color-mix(in srgb, var(--audiobook-primary-dark) 90%, black) 100%);
    z-index: 1;
}

.chapters-title {
    font-weight: 600;
    font-size: 1.125rem;
    color: white;
}

.chapters-close-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    cursor: pointer;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.2s;
}

.chapters-close-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.chapters-list {
    padding: 0.5rem 0 1rem 0;
}

.chapter-section {
    margin-bottom: 0.25rem;
}

.chapter-section-name {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255, 255, 255, 0.7);
    padding: 1rem 1.5rem 0.5rem;
    margin: 0;
    font-weight: 600;
}

.chapter-pages {
    list-style: none;
    margin: 0;
    padding: 0;
}

.chapter-page {
    display: flex;
    align-items: center;
    padding: 0.875rem 1.5rem;
    cursor: pointer;
    transition: background 0.2s;
    gap: 0.75rem;
    color: white !important;
    text-decoration: none !important;
}

.chapter-page:visited,
.chapter-page:link,
.chapter-page:active {
    color: white !important;
}

.chapter-page:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white !important;
    text-decoration: none !important;
}

.chapter-page.current {
    background: rgba(255, 255, 255, 0.15);
}

.chapter-indicator {
    width: 1.25rem;
    font-size: 0.875rem;
    flex-shrink: 0;
    color: var(--audiobook-primary-light) !important;
}

.chapter-title {
    flex: 1;
    font-size: 0.9375rem;
    color: white !important;
}

.chapter-page.current .chapter-title {
    font-weight: 600;
    color: white !important;
}

.chapter-visual {
    opacity: 0.8;
    flex-shrink: 0;
    font-size: 0.875rem;
    color: white !important;
}

/* Force all text in chapters drawer to be white */
.audiobook-chapters-drawer,
.audiobook-chapters-drawer * {
    color: white !important;
}

.audiobook-chapters-drawer .chapter-section-name {
    color: rgba(255, 255, 255, 0.7) !important;
}

.audiobook-chapters-drawer .chapter-indicator {
    color: var(--audiobook-primary-light) !important;
}

/* ==========================================
   Phase 2b: Audiobook Mode (Full Page)
   ========================================== */

/* Hide normal page content when in audiobook mode */
body.audiobook-mode .rfw-nav,
body.audiobook-mode .rfw-header,
body.audiobook-mode .rfw-course-header,
body.audiobook-mode .rfw-footer,
body.audiobook-mode .page-content,
body.audiobook-mode .course-nav,
body.audiobook-mode main.rfw-main {
    display: none !important;
}

body.audiobook-mode {
    overflow: hidden;
}

/* ==========================================
   Phase 2b: Full-Screen Mode (Default)
   ========================================== */

.audiobook-panel.fullscreen {
    top: 0;
    border-radius: 0;
}

.audiobook-panel.fullscreen .audiobook-content {
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for iOS Safari */
    display: flex;
    flex-direction: column;
    padding: 0;
    border-radius: 0;
}

/* Header with Exit/Course Name/Voice */
.audiobook-panel.fullscreen .audiobook-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    margin-bottom: 0;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.audiobook-exit-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.audiobook-course-name {
    font-weight: 600;
    font-size: 1rem;
    opacity: 0.9;
}

/* Text buttons */
.audiobook-text-btn {
    background: transparent;
    border: none;
    color: white;
    font-size: 0.9375rem;
    cursor: pointer;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.audiobook-text-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Main player area (centered) */
.audiobook-player-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    text-align: center;
    position: relative;
    overflow: hidden;
}

/* Theme background image overlay */
.audiobook-player-main::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: var(--audiobook-bg-image);
    background-size: cover;
    background-position: center;
    opacity: 0.4;
    pointer-events: none;
    z-index: 0;
}

/* Ensure content appears above the background */
.audiobook-player-main > * {
    position: relative;
    z-index: 1;
}

.audiobook-player-main .audiobook-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.audiobook-player-main .audiobook-section {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    opacity: 0.7;
    margin-bottom: 0.5rem;
}

.audiobook-player-main .audiobook-page-title {
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 2rem;
}

.audiobook-panel.fullscreen .audiobook-progress-container {
    width: 100%;
    max-width: 500px;
    margin-bottom: 2rem;
}

.audiobook-panel.fullscreen .audiobook-controls {
    margin-bottom: 1.5rem;
}

.audiobook-panel.fullscreen .audiobook-play-btn {
    width: 5rem;
    height: 5rem;
    font-size: 2rem;
}

.audiobook-panel.fullscreen .audiobook-nav-btn {
    width: 3rem;
    height: 3rem;
}

.audiobook-panel.fullscreen .audiobook-nav-btn svg {
    width: 28px;
    height: 28px;
}

.audiobook-panel.fullscreen .audiobook-page-indicator {
    text-align: center;
    opacity: 0.8;
    font-size: 0.875rem;
}

/* Bottom action buttons */
.audiobook-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding: 1.5rem;
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px)); /* iOS home indicator */
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.audiobook-action-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 2rem;
    color: white;
    font-size: 0.9375rem;
    font-weight: 500;
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.audiobook-action-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

.audiobook-action-btn svg {
    flex-shrink: 0;
}

/* ==========================================
   Phase 2b: Drawer Styles (Contents & Read Along)
   ========================================== */

.audiobook-drawer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 85vh;
    max-height: 85dvh; /* Dynamic viewport height for iOS Safari */
    background: linear-gradient(180deg, var(--audiobook-primary-dark) 0%, color-mix(in srgb, var(--audiobook-primary-dark) 60%, black) 100%);
    border-top-left-radius: 1rem;
    border-top-right-radius: 1rem;
    transform: translateY(0);
    transition: transform 0.3s ease-out, background 0.3s ease;
    z-index: 1100;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
    color: white;
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom, 0px); /* iOS home indicator */
}

.audiobook-drawer.hidden {
    transform: translateY(100%);
    pointer-events: none;
}

/* Drawer Backdrop (click to close) */
.audiobook-drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1050;
    opacity: 0;
    transition: opacity 0.3s ease-out;
}

.audiobook-drawer-backdrop.showing {
    opacity: 1;
}

.audiobook-drawer-backdrop.hidden {
    display: none;
}

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--audiobook-primary-dark) 0%, color-mix(in srgb, var(--audiobook-primary-dark) 90%, black) 100%);
}

.drawer-title {
    font-weight: 600;
    font-size: 1.125rem;
    color: white;
}

.drawer-close-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    cursor: pointer;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.2s;
}

.drawer-close-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.drawer-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0 1rem 0;
}

/* Contents list styling */
.contents-section {
    margin-bottom: 0.25rem;
}

.contents-section-name {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255, 255, 255, 0.7);
    padding: 1rem 1.5rem 0.5rem;
    margin: 0;
    font-weight: 600;
}

.contents-pages {
    list-style: none;
    margin: 0;
    padding: 0;
}

.contents-page {
    display: flex;
    align-items: center;
    padding: 0.875rem 1.5rem;
    cursor: pointer;
    transition: background 0.2s;
    gap: 0.75rem;
    color: white;
}

.contents-page:hover {
    background: rgba(255, 255, 255, 0.1);
}

.contents-page.current {
    background: rgba(255, 255, 255, 0.15);
}

.contents-indicator {
    width: 1.25rem;
    font-size: 0.875rem;
    flex-shrink: 0;
    color: var(--audiobook-primary-light);
}

.contents-title {
    flex: 1;
    font-size: 0.9375rem;
}

.contents-page.current .contents-title {
    font-weight: 600;
}

.contents-visual {
    opacity: 0.8;
    flex-shrink: 0;
    font-size: 0.875rem;
}

/* Contents drawer white background */
#audiobook-contents-drawer .drawer-content {
    background: white;
    margin: 0.5rem;
    border-radius: 0.5rem;
    padding: 0;
}

#audiobook-contents-drawer .contents-section-name {
    padding: 1rem 1rem 0.5rem;
}

/* Section title theme colors - each section has its own theme color */
#audiobook-contents-drawer .contents-section-name.section-theme-nature {
    color: #2e7d32;
}
#audiobook-contents-drawer .contents-section-name.section-theme-sky {
    color: #1565c0;
}
#audiobook-contents-drawer .contents-section-name.section-theme-mystical {
    color: #7b1fa2;
}
#audiobook-contents-drawer .contents-section-name.section-theme-sunset {
    color: #d84315;
}
#audiobook-contents-drawer .contents-section-name.section-theme-ocean {
    color: #00838f;
}

#audiobook-contents-drawer .contents-page {
    color: #333;
    padding: 0.75rem 1rem;
}

#audiobook-contents-drawer .contents-page:hover {
    background: color-mix(in srgb, var(--audiobook-primary-dark) 10%, transparent);
}

#audiobook-contents-drawer .contents-page.current {
    background: color-mix(in srgb, var(--audiobook-primary-dark) 15%, transparent);
}

#audiobook-contents-drawer .contents-indicator {
    color: var(--audiobook-primary-dark);
}

#audiobook-contents-drawer .contents-title {
    color: #333;
}

#audiobook-contents-drawer .contents-visual {
    color: #666;
}

/* Read Along content styling - white background for readability */
.readalong-content {
    padding: 1rem 1.5rem;
    background: white;
    border-radius: 0.5rem;
    margin: 0.5rem;
}

.readalong-loading,
.readalong-error {
    text-align: center;
    padding: 2rem;
    color: #666;
}

/* Audiobook page content styles (loaded via API) */
.audiobook-page-content {
    color: #333;
    line-height: 1.7;
    font-size: 1rem;
}

.audiobook-page-content .content-element {
    margin-bottom: 1.25rem;
}

.audiobook-page-content .text-element p {
    margin-bottom: 0.75rem;
    color: #333;
}

.audiobook-page-content .text-element p:last-child {
    margin-bottom: 0;
}

.audiobook-page-content .text-element h2,
.audiobook-page-content .text-element h3,
.audiobook-page-content .text-element h4 {
    color: var(--audiobook-primary-dark);
    margin-bottom: 0.75rem;
    margin-top: 1rem;
}

.audiobook-page-content .text-element h2:first-child,
.audiobook-page-content .text-element h3:first-child,
.audiobook-page-content .text-element h4:first-child {
    margin-top: 0;
}

.audiobook-page-content .image-element img {
    max-width: 100%;
    border-radius: 0.5rem;
    margin: 0.5rem 0;
}

.audiobook-page-content .image-caption {
    font-size: 0.875rem;
    color: #666;
    font-style: italic;
    margin-top: 0.5rem;
}

.audiobook-page-content .list-element h4 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--audiobook-primary-dark);
}

.audiobook-page-content .list-element ul {
    list-style: disc;
    padding-left: 1.5rem;
    margin: 0;
    color: #333;
}

.audiobook-page-content .list-element li {
    margin-bottom: 0.5rem;
}

.audiobook-page-content .accordion-element h4,
.audiobook-page-content .tabs-element h4 {
    font-size: 1.125rem;
    font-weight: 600;
    margin: 1rem 0 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid color-mix(in srgb, var(--audiobook-primary-dark) 20%, transparent);
    color: var(--audiobook-primary-dark);
}

.audiobook-page-content .interactive-placeholder {
    background: color-mix(in srgb, var(--audiobook-primary-dark) 10%, transparent);
    border-radius: 0.5rem;
    padding: 1rem;
}

.audiobook-page-content .interactive-notice {
    margin: 0;
    color: #555;
    font-style: italic;
}

/* Book grid styling in Read Along */
.audiobook-page-content .book-grid-element {
    margin: 1.5rem 0;
}

.audiobook-page-content .book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 1rem;
    justify-items: center;
}

.audiobook-page-content .book-item {
    text-align: center;
}

.audiobook-page-content .book-item img {
    max-width: 100%;
    height: auto;
    max-height: 150px;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s;
}

.audiobook-page-content .book-item img:hover {
    transform: scale(1.05);
}

.audiobook-page-content .book-cover {
    cursor: pointer;
}

.audiobook-page-content .book-title {
    font-size: 0.75rem;
    margin-top: 0.5rem;
    color: #555;
    line-height: 1.3;
}

/* ==========================================
   Phase 2: Mini-Player Mode
   ========================================== */

.audiobook-mini {
    display: none;
    align-items: center;
    padding: 0.75rem 1rem;
    gap: 0.75rem;
    background: linear-gradient(135deg, var(--audiobook-primary-dark) 0%, color-mix(in srgb, var(--audiobook-primary-dark) 60%, black) 100%);
    border-top-left-radius: 1rem;
    border-top-right-radius: 1rem;
    color: white;
}

.audiobook-panel.minimized .audiobook-content {
    display: none;
}

.audiobook-panel.minimized .audiobook-mini {
    display: flex;
}

.mini-play-btn {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    background: white;
    color: var(--audiobook-primary-dark);
    border: none;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.mini-play-btn:hover {
    background: #f0f0f0;
}

.mini-play-icon {
    margin-left: 2px; /* Visual centering for play icon */
}

.mini-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
    min-width: 0;
}

.mini-progress {
    width: 80px;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    flex-shrink: 0;
}

.mini-progress-fill {
    height: 100%;
    background: white;
    border-radius: 2px;
    width: 0%;
    transition: width 0.1s linear;
}

.mini-time {
    font-size: 0.75rem;
    opacity: 0.8;
    min-width: 70px;
    text-align: right;
    flex-shrink: 0;
}

.mini-expand-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.mini-expand-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Responsive */
@media (max-width: 640px) {
    .audiobook-content {
        padding: 0.75rem 1rem;
    }

    .audiobook-footer {
        flex-direction: column;
        gap: 0.5rem;
    }

    .visual-prompt-buttons {
        flex-direction: column;
    }

    /* Mini-player mobile adjustments */
    .mini-progress {
        width: 60px;
    }

    .mini-time {
        min-width: 60px;
        font-size: 0.7rem;
    }

    /* Chapters drawer mobile */
    .audiobook-chapters-drawer {
        max-height: 80vh;
    }

    /* Phase 2b: Mobile adjustments */
    .audiobook-panel.fullscreen .audiobook-header {
        padding: 0.75rem 1rem;
    }

    .audiobook-course-name {
        display: none;
    }

    .audiobook-player-main .audiobook-page-title {
        font-size: 1.375rem;
    }

    .audiobook-player-main .audiobook-icon {
        display: none;
    }

    .audiobook-panel.fullscreen .audiobook-play-btn {
        width: 4rem;
        height: 4rem;
        font-size: 1.5rem;
    }

    .audiobook-actions {
        padding: 1rem;
        gap: 0.75rem;
    }

    .audiobook-action-btn {
        padding: 0.625rem 1rem;
        font-size: 0.875rem;
    }

    /* Drawer mobile */
    .audiobook-drawer {
        max-height: 80vh;
    }

    .drawer-header {
        padding: 0.875rem 1rem;
    }

    .contents-page {
        padding: 0.75rem 1rem;
    }

    .readalong-content {
        padding: 0.875rem 1rem;
    }
}
