/* ==========================================================================
   CSS Design Tokens & Reset
   ========================================================================== */
:root {
    --bg-main: hsl(220, 20%, 8%);
    --bg-card: hsla(220, 16%, 13%, 0.7);
    --bg-sidebar: hsl(220, 18%, 10%);
    --border-color: hsla(220, 15%, 20%, 0.5);
    
    --accent-blue: hsl(210, 100%, 60%);
    --accent-purple: hsl(260, 85%, 65%);
    --accent-glow: hsla(210, 100%, 60%, 0.25);
    
    --text-primary: hsl(210, 15%, 90%);
    --text-secondary: hsl(210, 10%, 65%);
    --text-muted: hsl(210, 8%, 45%);
    
    --font-heading: 'Outfit', 'Inter', -apple-system, sans-serif;
    --font-body: 'Inter', -apple-system, sans-serif;
    
    --glass-blur: blur(16px);
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-body);
    overflow: hidden;
    height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   App Layout
   ========================================================================== */
.app-container {
    display: grid;
    grid-template-columns: 280px 1fr;
    height: 100vh;
    width: 100vw;
    transition: var(--transition-smooth);
}

.app-container.sidebar-collapsed {
    grid-template-columns: 0px 1fr;
}

/* ==========================================================================
   Sidebar Component
   ========================================================================== */
.sidebar {
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    transition: var(--transition-smooth);
    z-index: 10;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: var(--font-heading);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-icon {
    font-size: 24px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-header .subtitle {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-top: 6px;
    margin-left: 2px;
}

.tree-nav {
    flex: 0 0 auto;
    padding: 20px 20px 10px 20px;
}

.tree-nav h3 {
    font-family: var(--font-heading);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
}

.tree-root {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* ── Book node ── */
.tree-book {
    border-radius: 10px;
    overflow: hidden;
}

.tree-book-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    cursor: pointer;
    border-radius: 10px;
    border: 1px solid transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    transition: var(--transition-smooth);
    user-select: none;
}

.tree-book-header:hover {
    background-color: hsla(220, 15%, 20%, 0.3);
    color: var(--text-primary);
}

.tree-book.active > .tree-book-header {
    background: linear-gradient(135deg, hsla(210, 100%, 60%, 0.15), hsla(260, 85%, 65%, 0.15));
    border-color: hsla(210, 100%, 60%, 0.3);
    color: var(--accent-blue);
    box-shadow: 0 4px 20px hsla(0, 0%, 0%, 0.2);
}

.tree-book-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Chevron arrow ── */
.tree-arrow {
    font-size: 10px;
    flex-shrink: 0;
    transition: transform 0.25s ease;
    color: var(--text-muted);
}

.tree-book.open > .tree-book-header .tree-arrow,
.tree-chapter.open > .tree-chapter-header .tree-arrow {
    transform: rotate(90deg);
}

/* ── Chapters list (collapsible) ── */
.tree-chapters {
    list-style: none;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    padding-left: 12px;
}

.tree-book.open > .tree-chapters {
    max-height: 2000px;
}

/* ── Chapter node ── */
.tree-chapter {
    border-radius: 8px;
    margin: 2px 0;
}

.tree-chapter-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    cursor: pointer;
    border-radius: 8px;
    border: 1px solid transparent;
    color: var(--text-secondary);
    font-size: 12.5px;
    font-weight: 500;
    transition: var(--transition-smooth);
    user-select: none;
}

.tree-chapter-header:hover {
    background-color: hsla(220, 15%, 20%, 0.3);
    color: var(--text-primary);
}

.tree-chapter.active > .tree-chapter-header {
    background-color: hsla(210, 100%, 60%, 0.08);
    border-color: hsla(210, 100%, 60%, 0.2);
    color: var(--accent-blue);
    font-weight: 600;
}

.tree-chapter-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-chapter-page {
    font-family: monospace;
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.tree-chapter.active > .tree-chapter-header .tree-chapter-page {
    color: var(--accent-blue);
}

/* ── Audio list (collapsible) ── */
.tree-audios {
    list-style: none;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    padding-left: 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tree-chapter.open > .tree-audios {
    max-height: 1000px;
    padding-top: 4px;
    padding-bottom: 6px;
}

/* ── Audio leaf node ── */
.tree-audio {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 12px;
    transition: var(--transition-smooth);
    border: 1px solid transparent;
}

.tree-audio:hover {
    background-color: hsla(220, 15%, 20%, 0.25);
    color: var(--text-secondary);
}

.tree-audio.playing {
    background-color: hsla(210, 100%, 60%, 0.08);
    border-color: hsla(210, 100%, 60%, 0.15);
    color: var(--accent-blue);
}

.tree-play-icon {
    font-size: 9px;
    flex-shrink: 0;
    width: 12px;
    text-align: center;
}

.tree-audio span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.book-nav { display: none; }
.toc-panel { display: none !important; }

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.words-panel {
    flex: 0 0 auto;
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
}

.book-nav h3, .settings-panel h3 {
    font-family: var(--font-heading);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
}

.words-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.words-item {
    background-color: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
    transition: var(--transition-smooth);
}

.words-item:hover {
    background-color: hsla(220, 15%, 20%, 0.3);
    color: var(--text-primary);
}

.words-item.active {
    background-color: hsla(260, 85%, 65%, 0.08);
    border-color: hsla(260, 85%, 65%, 0.2);
    color: var(--accent-purple);
    font-weight: 600;
}

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

.btn-words-download {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-smooth);
}

.btn-words-download:hover {
    color: var(--accent-purple);
    transform: scale(1.1);
}

.words-info {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
}

.words-info span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.words-page {
    font-family: monospace;
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.words-item.active .words-page {
    color: var(--accent-purple);
}

.words-item .play-icon-mini {
    color: var(--text-muted);
    font-size: 12px;
    width: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.words-item.active .play-icon-mini {
    color: var(--accent-purple);
}

.toc-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.toc-item {
    background-color: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
    transition: var(--transition-smooth);
}

.toc-item:hover {
    background-color: hsla(220, 15%, 20%, 0.3);
    color: var(--text-primary);
}

.toc-item.active {
    background-color: hsla(210, 100%, 60%, 0.08);
    border-color: hsla(210, 100%, 60%, 0.2);
    color: var(--accent-blue);
    font-weight: 600;
}

.toc-item .toc-page {
    font-family: monospace;
    font-size: 11px;
    color: var(--text-muted);
}

.toc-item.active .toc-page {
    color: var(--accent-blue);
}

.book-nav h3, .settings-panel h3 {
    font-family: var(--font-heading);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
}

.book-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.book-item {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 10px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition-smooth);
}

.book-item i {
    font-size: 16px;
    transition: var(--transition-smooth);
}

.book-item:hover {
    background-color: hsla(220, 15%, 20%, 0.3);
    color: var(--text-primary);
}

.book-item.active {
    background: linear-gradient(135deg, hsla(210, 100%, 60%, 0.15), hsla(260, 85%, 65%, 0.15));
    border-color: hsla(210, 100%, 60%, 0.3);
    color: var(--accent-blue);
    box-shadow: 0 4px 20px hsla(0, 0%, 0%, 0.2);
}

.book-item.active i {
    color: var(--accent-blue);
    transform: scale(1.1);
}

.settings-panel {
    padding: 20px;
    background-color: hsla(220, 18%, 8%, 0.5);
    border-top: 1px solid var(--border-color);
}

.setting-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.setting-label {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.badge {
    background-color: var(--accent-blue);
    color: var(--bg-main);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 11px;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--border-color);
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-blue);
    box-shadow: 0 0 10px var(--accent-blue);
    transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.setting-tip {
    font-size: 11px;
    color: var(--text-muted);
}

/* ==========================================================================
   Main Content Layout
   ========================================================================== */
.main-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    position: relative;
}

/* ==========================================================================
   Toolbar Component
   ========================================================================== */
.toolbar {
    background-color: hsla(220, 18%, 10%, 0.8);
    backdrop-filter: var(--glass-blur);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    padding: 0 20px;
    z-index: 5;
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 500;
    height: 36px;
    padding: 0 14px;
    transition: var(--transition-smooth);
}

.btn-secondary:hover {
    background-color: hsla(220, 15%, 20%, 0.5);
    border-color: var(--text-muted);
    color: var(--text-primary);
}

.page-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

.page-indicator input {
    background-color: hsla(220, 18%, 8%, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-weight: 600;
    text-align: center;
    width: 50px;
    height: 32px;
    outline: none;
    transition: var(--transition-smooth);
}

.page-indicator input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 10px var(--accent-glow);
}

.page-indicator .separator {
    color: var(--text-muted);
}

.book-title-display {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 16px;
    color: var(--text-primary);
}

/* ==========================================================================
   PDF Viewer Area
   ========================================================================== */
.viewer-container {
    flex: 1;
    overflow: auto;
    padding: 30px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background-color: var(--bg-main);
    background-image: radial-gradient(circle at center, hsla(220, 20%, 15%, 0.4) 0%, transparent 80%);
    position: relative;
}


.pdf-wrapper {
    position: relative;
    box-shadow: 0 12px 40px hsla(0, 0%, 0%, 0.6);
    border-radius: 12px;
    overflow: visible;
    border: 1px solid var(--border-color);
    background-color: white; /* fallback for pdf canvas background */
}

#pdf-canvas {
    display: block;
    border-radius: 12px;
}

.page-img {
    display: block;
    width: 100%;
    max-width: 900px;
    height: auto;
    border-radius: 12px;
    margin: 0 auto;
    transition: opacity 0.15s ease;
    transform-origin: top center;
}

.page-img.page-loading {
    opacity: 0.4;
}

/* ==========================================================================
   Floating Audio Overlay
   ========================================================================== */
.floating-audio-panel {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 260px;
    background-color: hsla(220, 20%, 10%, 0.75);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 14px;
    box-shadow: 0 8px 32px hsla(0, 0%, 0%, 0.4);
    transition: var(--transition-smooth);
    opacity: 0;
    transform: translateY(-10px);
    pointer-events: none;
}

.floating-audio-panel.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 13px;
    color: var(--accent-blue);
    margin-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 6px;
}

.page-audio-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 250px;
    overflow-y: auto;
    padding-right: 4px;
}

.audio-track-item {
    background-color: hsla(220, 15%, 20%, 0.3);
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 500;
    transition: var(--transition-smooth);
}

.audio-track-item:hover {
    background-color: hsla(220, 15%, 20%, 0.6);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.audio-track-item.playing {
    background: linear-gradient(135deg, hsla(210, 100%, 60%, 0.15), hsla(260, 85%, 65%, 0.15));
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

.audio-track-item .track-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 10px;
    flex: 1;
}

.audio-track-item .play-icon-mini {
    color: var(--text-muted);
}

.audio-track-item.playing .play-icon-mini {
    color: var(--accent-blue);
}

/* ==========================================================================
   Global Audio Player Bar
   ========================================================================== */
.audio-player-bar {
    background-color: hsla(220, 18%, 10%, 0.8);
    backdrop-filter: var(--glass-blur);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 80px;
    padding: 0 30px;
    z-index: 5;
}

.player-left {
    width: 25%;
}

.audio-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.audio-info .track-name {
    font-family: var(--font-heading);
    font-weight: 500;
    font-size: 14px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.audio-info .book-name {
    font-size: 11px;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

.player-center {
    width: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.player-controls {
    display: flex;
    align-items: center;
    gap: 20px;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 18px;
    transition: var(--transition-smooth);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    color: var(--text-primary);
    transform: scale(1.1);
}

.btn-play {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    color: var(--bg-main) !important;
    border-radius: 50%;
    font-size: 16px;
    width: 42px;
    height: 42px;
    box-shadow: 0 4px 15px hsla(210, 100%, 60%, 0.4);
}

.btn-play:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 20px hsla(210, 100%, 60%, 0.6);
}

.progress-container {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.time-label {
    font-family: monospace;
    font-size: 11px;
    color: var(--text-muted);
}

.progress-bar-wrapper {
    flex: 1;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    position: relative;
    cursor: pointer;
}

.progress-bar {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 0%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple));
}

.progress-knob {
    position: absolute;
    top: 50%;
    left: 0%;
    transform: translate(-50%, -50%);
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: var(--text-primary);
    box-shadow: 0 0 8px rgba(0,0,0,0.5);
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}

.progress-bar-wrapper:hover .progress-knob {
    opacity: 1;
}

.player-right {
    width: 25%;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 24px;
}

/* Playback Speed Controller */
.speed-control {
    position: relative;
}

.speed-menu {
    position: absolute;
    bottom: calc(100% + 12px);
    right: 0;
    background-color: hsla(220, 20%, 12%, 0.85);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 8px 32px hsla(0, 0%, 0%, 0.5);
    display: flex;
    flex-direction: column;
    padding: 6px;
    list-style: none;
    width: 120px;
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    transition: var(--transition-smooth);
}

.speed-menu.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.speed-menu li {
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    padding: 8px 10px;
    border-radius: 6px;
    transition: var(--transition-smooth);
}

.speed-menu li:hover {
    background-color: hsla(220, 15%, 20%, 0.6);
    color: var(--text-primary);
}

.speed-menu li.active {
    background-color: var(--accent-blue);
    color: var(--bg-main);
    font-weight: 600;
}

/* Wave visualizer */
.wave-visualizer {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 18px;
    width: 25px;
}

.wave-visualizer span {
    background: linear-gradient(180deg, var(--accent-blue), var(--accent-purple));
    border-radius: 1px;
    display: inline-block;
    width: 3px;
    height: 3px;
    transition: var(--transition-smooth);
}

.wave-visualizer.playing span {
    animation: wave-bounce 1s infinite alternate;
}

.wave-visualizer.playing span:nth-child(1) { animation-delay: 0.1s; }
.wave-visualizer.playing span:nth-child(2) { animation-delay: 0.3s; }
.wave-visualizer.playing span:nth-child(3) { animation-delay: 0.5s; }
.wave-visualizer.playing span:nth-child(4) { animation-delay: 0.2s; }
.wave-visualizer.playing span:nth-child(5) { animation-delay: 0.4s; }

@keyframes wave-bounce {
    0% { height: 3px; }
    100% { height: 18px; }
}

/* ==========================================================================
   Audio-Only View Styling
   ========================================================================== */
.audio-only-view {
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    max-height: 100%;
}

.audio-only-header {
    text-align: center;
    margin-bottom: 30px;
}

.audio-only-header .header-icon {
    font-size: 48px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 15px;
    animation: pulse-glow 2s infinite alternate;
}

.audio-only-header h2 {
    font-family: var(--font-heading);
    font-size: 26px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.audio-only-header p {
    font-size: 14px;
    color: var(--text-secondary);
}

.audio-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    width: 100%;
    padding-bottom: 40px;
}

.audio-card {
    background-color: var(--bg-card);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 140px;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.audio-card:hover {
    transform: translateY(-4px);
    border-color: var(--accent-blue);
    box-shadow: 0 8px 24px var(--accent-glow);
}

.audio-card.playing {
    background: linear-gradient(135deg, hsla(210, 100%, 60%, 0.1), hsla(260, 85%, 65%, 0.1));
    border-color: var(--accent-blue);
    box-shadow: 0 4px 16px var(--accent-glow);
}

.audio-card .card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}

.audio-card .audio-icon-wrapper {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background-color: hsla(220, 15%, 20%, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 16px;
    transition: var(--transition-smooth);
}

.audio-card.playing .audio-icon-wrapper {
    background-color: var(--accent-blue);
    color: var(--bg-main);
}

.audio-card .play-btn-wrapper {
    font-size: 18px;
    color: var(--text-muted);
    transition: var(--transition-smooth);
}

.audio-card:hover .play-btn-wrapper {
    color: var(--accent-blue);
    transform: scale(1.1);
}

.audio-card.playing .play-btn-wrapper {
    color: var(--accent-blue);
}

.audio-card .card-bottom {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.audio-card .card-title {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.3;
}

.audio-card .card-subtitle {
    font-size: 11px;
    color: var(--text-muted);
}

@keyframes pulse-glow {
    0% { transform: scale(1); filter: drop-shadow(0 0 2px var(--accent-glow)); }
    100% { transform: scale(1.05); filter: drop-shadow(0 0 10px var(--accent-blue)); }
}

/* ==========================================================================
   Audio Download Action Styles
   ========================================================================== */
.track-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-track-download, .card-download-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-smooth);
}

.btn-track-download:hover, .card-download-btn:hover {
    color: var(--accent-blue);
    transform: scale(1.1);
}

.audio-card .card-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ==========================================================================
   Responsive — Mobile & Tablet
   ========================================================================== */

/* Utility: hide/show per breakpoint */
.mobile-only { display: none; }
.desktop-only { display: flex; }

/* --------------------------------------------------------------------------
   Tablet (≤ 900px): sidebar becomes floating overlay
   -------------------------------------------------------------------------- */
@media (max-width: 900px) {
    /* Sidebar backdrop */
    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: hsla(220, 20%, 5%, 0.7);
        backdrop-filter: blur(4px);
        z-index: 99;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }
    .sidebar-backdrop.active {
        opacity: 1;
        pointer-events: auto;
    }

    /* App becomes single column */
    .app-container {
        grid-template-columns: 1fr !important;
        height: 100dvh;
    }

    /* Sidebar slides in from left as overlay */
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 300px;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        border-right: 1px solid var(--border-color);
        box-shadow: 4px 0 24px hsla(0, 0%, 0%, 0.5);
    }
    .sidebar.mobile-open {
        transform: translateX(0);
    }

    /* Hide desktop sidebar toggle, show hamburger */
    .mobile-only { display: flex; }
    #toggle-sidebar { display: none; }

    /* Toolbar adjustments */
    .toolbar {
        padding: 0 12px;
        height: 52px;
    }
    .toolbar-center .book-title-display {
        font-size: 13px;
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .toolbar-right { gap: 6px; }
    .toolbar-left  { gap: 6px; }

    /* Viewer gets full width */
    .viewer-container {
        padding: 16px 8px;
    }

    /* Player bar — compact two-row layout */
    .audio-player-bar {
        height: auto;
        padding: 10px 16px;
        flex-direction: column;
        gap: 8px;
    }
    .player-left  { width: 100%; }
    .player-center { width: 100%; }
    .player-right {
        width: 100%;
        justify-content: space-between;
    }
    .player-controls { gap: 16px; }

    /* Float panel: full-width bottom sheet instead of right-corner */
    .floating-audio-panel {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        border-radius: 16px 16px 0 0;
        max-height: 50vh;
        overflow-y: auto;
        z-index: 200;
        transform: translateY(100%);
    }
    .floating-audio-panel.visible {
        transform: translateY(0);
        opacity: 1;
    }
    .page-audio-list { max-height: none; }
}

/* --------------------------------------------------------------------------
   Mobile (≤ 600px): extra compact
   -------------------------------------------------------------------------- */
@media (max-width: 600px) {
    /* Safe area for notched phones */
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .toolbar { height: 48px; padding: 0 10px; }

    /* Hide zoom percent badge on small screens */
    #zoom-percent { display: none; }

    /* Hide book title in toolbar — too cramped */
    .toolbar-center { display: none; }

    /* Viewer full bleed */
    .viewer-container { padding: 8px 4px; }
    .pdf-wrapper {
        border-radius: 8px;
        box-shadow: 0 8px 24px hsla(0, 0%, 0%, 0.5);
    }

    /* Player bar — stacked, touch-friendly */
    .audio-player-bar {
        padding: 10px 12px 14px;
        padding-bottom: calc(14px + env(safe-area-inset-bottom));
    }
    .audio-info .track-name { font-size: 12px; }
    .audio-info .book-name  { font-size: 10px; }

    .btn-play { width: 46px; height: 46px; font-size: 18px; }
    .btn-icon  { width: 38px; height: 38px; font-size: 16px; }

    /* Download text label hidden — icon only */
    #player-download .fa-cloud-arrow-down { margin: 0; }
    #player-download { padding: 0 10px; font-size: 0; }
    #player-download i { font-size: 14px; }

    /* Audio-only grid: 1 column */
    .audio-grid {
        grid-template-columns: 1fr;
    }

    /* Audio-only header */
    .audio-only-header h2 { font-size: 20px; }
    .audio-only-header .header-icon { font-size: 36px; }

    /* Book nav buttons — larger touch targets */
    .book-item {
        padding: 12px 14px;
        font-size: 14px;
    }
    .toc-item { padding: 10px 8px; font-size: 12px; }

    /* Speed menu anchors top on mobile */
    .speed-menu {
        bottom: auto;
        top: calc(100% + 8px);
        right: 0;
    }

    /* Settings panel hidden on mobile (rarely needed) */
    .settings-panel { display: none; }

    /* Sidebar 90% width, close on tap-outside */
    .sidebar { width: 88vw; max-width: 320px; }
}

/* --------------------------------------------------------------------------
   Touch: remove hover effects that don't apply on touch screens
   -------------------------------------------------------------------------- */
@media (hover: none) and (pointer: coarse) {
    .audio-card:hover       { transform: none; }
    .book-item:hover        { transform: none; }
    .btn-icon:hover         { transform: none; }
    .btn-play:hover         { transform: none; }
    .audio-track-item:hover { background-color: hsla(220, 15%, 20%, 0.3); }

    /* Larger tap targets */
    .btn { min-height: 44px; min-width: 44px; }
    .audio-track-item { padding: 12px; }
    .toc-item { padding: 12px 8px; }
    .progress-bar-wrapper {
        height: 10px;
        border-radius: 5px;
    }
    .progress-knob { opacity: 1; width: 18px; height: 18px; }
}

/* ==========================================================================
   PDF 加载进度条
   ========================================================================== */
#pdf-load-progress {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    background: radial-gradient(ellipse at center, hsla(220, 20%, 10%, 0.85) 0%, transparent 70%);
    pointer-events: none;
}

.pdf-progress-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 28px 36px;
    background: hsla(220, 20%, 12%, 0.8);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 8px 32px hsla(0,0%,0%,0.5);
    min-width: 240px;
}

.pdf-progress-label {
    font-family: var(--font-heading);
    font-size: 14px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.pdf-progress-label i {
    color: var(--accent-blue);
    font-size: 18px;
}

.pdf-progress-track {
    width: 100%;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    overflow: hidden;
}

.pdf-progress-fill {
    height: 100%;
    width: 0%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple));
    transition: width 0.3s ease;
    box-shadow: 0 0 8px var(--accent-glow);
}


