/* ============================================
   Enhanced Visualizer Styles
   Modern, engaging UI improvements
   ============================================ */

/* ===== Enhanced Language & Book Cards ===== */

.card-tile {
    position: relative;
    overflow: visible;
}

.card-tile::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--radius-xl);
    background: var(--gradient-primary);
    opacity: 0;
    transition: opacity var(--transition-base);
    z-index: -1;
}

.card-tile:hover::before {
    opacity: 0.1;
}

/* Book Card Overlay */
.book-card {
    position: relative;
}

.book-card-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, transparent 60%);
    opacity: 0;
    transition: opacity var(--transition-base);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: var(--space-5);
    border-radius: var(--radius-xl);
}

.card-tile:hover .book-card-overlay {
    opacity: 1;
}

.book-card-preview {
    color: var(--white);
    transform: translateY(10px);
    transition: transform var(--transition-base);
}

.card-tile:hover .book-card-preview {
    transform: translateY(0);
}

.book-card-author {
    font-size: var(--text-sm);
    margin-bottom: var(--space-2);
    opacity: 0.9;
}

.book-card-description {
    font-size: var(--text-xs);
    opacity: 0.8;
    line-height: var(--leading-snug);
    margin-bottom: var(--space-3);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.play-now-button {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: var(--surface-card);
    color: var(--primary-start);
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.play-now-button:hover {
    background: var(--gradient-primary);
    color: var(--white);
    transform: scale(1.05);
}

/* Language Badge on Cover */
.language-badge {
    position: absolute;
    top: var(--space-3);
    right: var(--space-3);
    background: rgba(0, 0, 0, 0.7);
    color: var(--white);
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.language-flag-mini {
    width: 16px;
    height: 12px;
    object-fit: cover;
    border-radius: 2px;
}

/* Book Count Badge */
.book-count-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    background: var(--gradient-primary);
    color: var(--white);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
}

/* ===== Enhanced Audio Player Controls ===== */

.audio-controls {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.12) 0%, rgba(118, 75, 162, 0.08) 100%);
    border: 1px solid var(--surface-border);
}

.audio-transport .transport-button {
    backdrop-filter: blur(8px);
    border: 1px solid var(--surface-border-strong);
    box-shadow: var(--shadow-sm);
}

.audio-transport .transport-button:not(:disabled):hover {
    border-color: var(--primary-start);
    color: var(--primary-start);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.audio-transport .transport-play {
    background: var(--gradient-primary);
    color: var(--white);
    border: none;
    box-shadow: var(--shadow-lg);
}

.audio-transport .transport-play:not(:disabled):hover {
    transform: translateY(-3px) scale(1.03);
    box-shadow: var(--shadow-glow-lg);
}

.audio-transport .transport-play.playing {
    animation: pulse-play 2.4s ease-in-out infinite;
}

@keyframes pulse-play {
    0%, 100% {
        box-shadow: var(--shadow-lg);
    }
    50% {
        box-shadow: var(--shadow-glow-lg);
    }
}

.playback-speed {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--surface-muted);
    border-radius: var(--radius-lg);
}

.speed-label {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
}

.speed-buttons {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
}

.speed-button {
    padding: var(--space-1) var(--space-2);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
}

.speed-button:hover {
    border-color: var(--surface-border-strong);
    background: var(--surface-card);
}

.speed-button.active {
    background: var(--primary-start);
    color: var(--white);
    border-color: var(--primary-start);
    box-shadow: var(--shadow-sm);
}

.audio-actions .volume-group {
    background: var(--surface-muted);
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-lg);
}

.auto-scroll-toggle {
    background: var(--surface-muted);
    border: 1px solid transparent;
}

.auto-scroll-toggle:hover {
    border-color: var(--surface-border-strong);
}

.auto-scroll-toggle.active {
    background: rgba(102, 126, 234, 0.15);
    border-color: var(--primary-start);
    color: var(--primary-start);
}

/* Now Playing Banner */
.now-playing-banner {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-4);
    background: var(--gradient-primary);
    border-radius: var(--radius-xl);
    margin-bottom: var(--space-5);
    color: var(--white);
}

.now-playing-cover {
    width: 60px;
    height: 60px;
    border-radius: var(--radius-lg);
    object-fit: cover;
    box-shadow: var(--shadow-md);
}

.now-playing-info {
    flex: 1;
}

.now-playing-title {
    font-size: var(--text-lg);
    font-weight: var(--font-bold);
    margin-bottom: var(--space-1);
}

.now-playing-author {
    font-size: var(--text-sm);
    opacity: 0.9;
}

.sound-wave-indicator {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    flex-shrink: 0;
}

.wave-bar {
    width: 2px;
    height: 12px;
    background: var(--primary-start);
    border-radius: 2px;
    animation: wave 1s ease-in-out infinite;
}

.wave-bar:nth-child(2) {
    animation-delay: 0.2s;
}

.wave-bar:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes wave {
    0%, 100% {
        height: 8px;
    }
    50% {
        height: 20px;
    }
}

.audio-player-fixed .sound-wave-indicator .wave-bar {
    background: var(--primary-start);
}

/* ===== Text Display Enhancements ===== */

.text-controls {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
    padding: var(--space-3);
    background: var(--surface-muted);
    border-radius: var(--radius-lg);
    flex-wrap: wrap;
}

.text-control-group {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.text-control-label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    font-weight: var(--font-medium);
}

.icon-button {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-card);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: var(--text-sm);
}

.icon-button:hover {
    border-color: var(--primary-start);
    color: var(--primary-start);
}

.icon-button.active {
    background: var(--primary-start);
    color: var(--white);
    border-color: var(--primary-start);
}

/* Reading Modes */
.text-display.expanded .segment {
    padding: var(--space-6);
    font-size: var(--text-lg);
    line-height: var(--leading-relaxed);
}

.text-display.focus-mode .segment:not(.active) {
    opacity: 0.3;
    filter: blur(2px);
    pointer-events: none;
}

/* Speaker Color Coding */
.segment[data-speaker] {
    border-left-width: 4px;
    border-left-style: solid;
}

.segment[data-speaker="Narrator"] {
    border-left-color: var(--accent-blue);
}

.segment[data-speaker="Elizabeth"] {
    border-left-color: var(--accent-pink);
}

.segment[data-speaker="Charlotte"] {
    border-left-color: var(--accent-lilac);
}

.segment[data-speaker="Mr. Darcy"] {
    border-left-color: var(--success);
}

/* Default colors for other speakers */
.segment[data-speaker]:not([data-speaker="Narrator"]):not([data-speaker="Elizabeth"]):not([data-speaker="Charlotte"]):not([data-speaker="Mr. Darcy"]) {
    border-left-color: var(--warning);
}

/* Interactive Segment Actions */
.segment-actions {
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
    display: flex;
    gap: var(--space-1);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.segment:hover .segment-actions {
    opacity: 1;
}

.segment-action-button {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-card);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: var(--text-xs);
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-fast);
}

.segment-action-button:hover {
    background: var(--primary-start);
    color: var(--white);
    transform: scale(1.1);
}

/* Timestamp Preview on Hover */
.segment-timestamp {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    padding: var(--space-2) var(--space-3);
    background: var(--surface-contrast);
    color: var(--white);
    border-radius: var(--radius-md);
    font-size: var(--text-xs);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast);
}

.segment:hover .segment-timestamp {
    opacity: 1;
}

/* ===== Character Enhancements ===== */

.character-item-enhanced {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    margin-bottom: 0;
    border-bottom: none;
    border-left: none;
    padding-left: 0;
    cursor: pointer;
    transition: all var(--transition-base);
}

.character-item-enhanced:hover {
    background: var(--surface-card-hover);
    transform: translateX(4px);
}

.character-item-enhanced[data-speaker] .character-name-enhanced {
    color: var(--character-color, var(--text-primary));
}

.character-avatar {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    font-weight: var(--font-bold);
    color: var(--white);
    font-size: var(--text-lg);
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
    transition: all var(--transition-base);
}

/* Character avatar with image */
.character-avatar[data-has-image="true"] .character-avatar-letter {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--transition-base);
}

.character-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: var(--radius-full);
    position: absolute;
    inset: 0;
    transition: opacity var(--transition-base);
}

/* Fallback to letter when image fails or on error */
.character-avatar.character-avatar-fallback .character-avatar-letter {
    opacity: 1;
}

/* Hover effect for character avatars with images */
.character-item-enhanced:hover .character-avatar[data-has-image="true"] {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.character-details {
    flex: 1;
}

.character-name-enhanced {
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin-bottom: var(--space-1);
}

.character-voice-info {
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.speaking-time-bar {
    width: 100%;
    height: 6px;
    border-radius: var(--radius-full);
    background: var(--surface-muted);
    overflow: hidden;
}

.speaking-time-fill {
    height: 100%;
    background: var(--character-color, var(--primary-start));
    border-radius: var(--radius-full);
}

/* ===== Sidebar Enhancements ===== */

.book-cover-large {
    width: 100%;
    height: 240px;
    object-fit: cover;
    border-radius: var(--radius-xl);
    margin-bottom: var(--space-4);
    box-shadow: var(--shadow-xl);
}

.book-cover-backdrop {
    position: relative;
    margin-bottom: var(--space-5);
}

.book-cover-backdrop::before {
    content: '';
    position: absolute;
    inset: -20px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border-radius: var(--radius-2xl);
    z-index: -1;
    filter: blur(20px);
}

.metadata-badges {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

.metadata-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-3);
    background: var(--surface-muted);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    color: var(--text-secondary);
}

.progress-indicator {
    margin-bottom: var(--space-4);
}

.progress-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: var(--space-2);
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.progress-percentage {
    font-weight: var(--font-semibold);
    color: var(--primary-start);
}

.book-description {
    font-size: var(--text-sm);
    line-height: var(--leading-relaxed);
    color: var(--text-secondary);
    margin-bottom: var(--space-4);
}

.book-description.collapsed {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.expand-button {
    background: none;
    border: none;
    color: var(--primary-start);
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    cursor: pointer;
    padding: 0;
}

.expand-button:hover {
    text-decoration: underline;
}

/* Related Books Compact */
.related-book-compact {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-2);
    cursor: pointer;
    transition: all var(--transition-base);
}

.related-book-compact:hover {
    background: var(--surface-card-hover);
    transform: translateX(4px);
}

.related-book-cover-mini {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.related-book-info {
    flex: 1;
    min-width: 0;
}

.related-book-title {
    font-weight: var(--font-semibold);
    font-size: var(--text-sm);
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.related-book-author {
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

/* ===== Animations & Transitions ===== */

.view-transition-enter {
    animation: slideInRight 0.4s ease-out;
}

.view-transition-exit {
    animation: slideOutLeft 0.3s ease-in;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOutLeft {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(-30px);
    }
}

.card-tile {
    animation: fadeInScale 0.4s ease-out backwards;
}

.card-tile:nth-child(1) { animation-delay: 0.05s; }
.card-tile:nth-child(2) { animation-delay: 0.1s; }
.card-tile:nth-child(3) { animation-delay: 0.15s; }
.card-tile:nth-child(4) { animation-delay: 0.2s; }
.card-tile:nth-child(5) { animation-delay: 0.25s; }
.card-tile:nth-child(6) { animation-delay: 0.3s; }

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Ripple Effect */
.ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.6);
    transform: scale(0);
    animation: ripple-animation 0.6s ease-out;
    pointer-events: none;
}

@keyframes ripple-animation {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* Loading Skeletons */
.skeleton-card {
    background: var(--surface-card);
    border-radius: var(--radius-xl);
    padding: 0;
    overflow: hidden;
}

.skeleton-cover {
    width: 100%;
    height: 200px;
    background: linear-gradient(
        90deg,
        var(--gray-200) 0%,
        var(--gray-300) 50%,
        var(--gray-200) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

.skeleton-content {
    padding: var(--space-5);
}

.skeleton-line {
    height: 16px;
    background: var(--gray-200);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-2);
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

.skeleton-line:last-child {
    width: 60%;
}

/* ===== Empty State ===== */

.empty-state-container {
    min-height: calc(100vh - 120px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-16) var(--space-4);
}

.empty-state-content {
    text-align: center;
    max-width: 600px;
}

.empty-state-icon {
    margin-bottom: var(--space-8);
    color: var(--text-tertiary);
    animation: float 3s ease-in-out infinite;
}

.empty-state-title {
    font-size: var(--text-4xl);
    font-weight: var(--font-bold);
    color: var(--text-primary);
    margin-bottom: var(--space-4);
}

.empty-state-description {
    font-size: var(--text-lg);
    color: var(--text-secondary);
    line-height: var(--leading-relaxed);
    margin-bottom: var(--space-8);
}

.empty-state-actions {
    display: flex;
    justify-content: center;
    gap: var(--space-4);
}

/* ===== Book Hero Section ===== */

.book-hero {
    position: relative;
    background: var(--gradient-primary);
    border-radius: var(--radius-2xl);
    margin-bottom: var(--space-8);
    overflow: hidden;
}

.book-hero-background {
    position: absolute;
    inset: 0;
    background: 
        radial-gradient(circle at 20% 50%, rgba(102, 126, 234, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(118, 75, 162, 0.15) 0%, transparent 50%);
    z-index: 0;
}

.book-hero-content {
    position: relative;
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: var(--space-10);
    padding: var(--space-12);
    align-items: center;
    z-index: 1;
}

.book-hero-cover-container {
    position: relative;
}

.book-hero-cover {
    width: 100%;
    height: auto;
    border-radius: var(--radius-2xl);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    transition: transform var(--transition-base);
}

.book-hero-cover:hover {
    transform: scale(1.02);
}

.book-hero-info {
    color: var(--white);
}

.book-hero-meta {
    margin-bottom: var(--space-4);
}

.book-hero-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
}

.book-hero-title {
    font-size: var(--text-5xl);
    font-weight: var(--font-extrabold);
    margin-bottom: var(--space-3);
    line-height: var(--leading-tight);
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.book-hero-author {
    font-size: var(--text-xl);
    margin-bottom: var(--space-6);
    opacity: 0.95;
}

.book-hero-description {
    font-size: var(--text-base);
    line-height: var(--leading-relaxed);
    opacity: 0.9;
    max-width: 600px;
}

/* ===== Enhanced Navigation ===== */

.visualizer-nav {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
}

.visualizer-nav-brand {
    justify-self: start;
}

.visualizer-nav-logo {
    justify-self: center;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    justify-self: end;
}

/* ===== Sidebar Adjustments for Direct Player ===== */

.sidebar .project-info {
    display: none; /* Hide redundant book info since we have hero */
}

/* ===== Related Books Section ===== */

.project-list {
    background: var(--surface-card);
    border-radius: var(--radius-xl);
    padding: var(--space-5);
}

.project-list h3 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--text-primary);
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    margin-bottom: var(--space-4);
}

.books-count {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    font-weight: var(--font-normal);
}

.related-books-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.related-book-compact {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-base);
    border: none;
    width: 100%;
    text-align: left;
}

.related-book-compact:hover {
    background: var(--surface-card-hover);
    transform: translateX(4px);
    box-shadow: var(--shadow-md);
}

.related-book-cover-mini {
    width: 60px;
    height: 80px;
    object-fit: cover;
    border-radius: var(--radius-md);
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.related-book-info {
    flex: 1;
    min-width: 0;
}

.related-book-title {
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin-bottom: var(--space-1);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.related-book-author {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===== Library View Styles ===== */

.library-view-container {
    padding: var(--space-8) var(--space-6);
    max-width: 1400px;
    margin: 0 auto;
    background: var(--surface-card);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-md);
}

.library-header {
    text-align: center;
    margin-bottom: var(--space-8);
}

.library-title {
    font-size: var(--text-4xl);
    font-weight: var(--font-extrabold);
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: var(--space-4);
}

.library-subtitle {
    font-size: var(--text-lg);
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto;
}

/* Library Language Filter */
.library-filter {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    justify-content: center;
    margin-bottom: var(--space-8);
    padding: var(--space-4);
    background: var(--surface-card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
}

.library-filter .filter-btn {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    border: 2px solid var(--surface-border);
    border-radius: var(--radius-lg);
    background: var(--surface-card);
    color: var(--text-secondary);
    font-size: var(--text-base);
    font-weight: var(--font-semibold);
    cursor: pointer;
    transition: all var(--transition-base);
}

.library-filter .filter-btn:hover {
    border-color: var(--primary-start);
    background: var(--surface-muted);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.library-filter .filter-btn.active {
    border-color: transparent;
    background: var(--gradient-primary);
    color: var(--text-inverse);
    box-shadow: var(--shadow-lg);
}

.library-filter .filter-flag {
    width: 24px;
    height: 18px;
    border-radius: var(--radius-sm);
    object-fit: cover;
}

.library-filter .filter-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 var(--space-2);
    background: var(--surface-muted);
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
    font-weight: var(--font-bold);
}

.library-filter .filter-btn.active .filter-count {
    background: rgba(255, 255, 255, 0.18);
    color: var(--text-inverse);
}

/* Library Books Grid */
.library-books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--space-6);
    margin-bottom: var(--space-8);
}

/* Library Book Card */
.library-book-card {
    background: var(--surface-card);
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    cursor: pointer;
    transition: all var(--transition-base);
    animation: fadeInUp 0.5s ease-out;
    animation-fill-mode: both;
}

.library-book-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-xl);
}

.library-book-card.hidden-filter {
    display: none;
}

.library-book-cover-container {
    position: relative;
    width: 100%;
    aspect-ratio: 2/3;
    overflow: hidden;
}

.library-book-cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--transition-slow);
}

.library-book-card:hover .library-book-cover {
    transform: scale(1.05);
}

/* Library Book Overlay */
.library-book-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.6) 50%, transparent 100%);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: var(--space-4);
    opacity: 0;
    transition: opacity var(--transition-base);
}

.library-book-card:hover .library-book-overlay {
    opacity: 1;
}

.library-book-overlay-content {
    color: var(--white);
}

.library-book-overlay-title {
    font-size: var(--text-lg);
    font-weight: var(--font-bold);
    margin-bottom: var(--space-2);
    line-height: 1.3;
}

.library-book-overlay-author {
    font-size: var(--text-sm);
    opacity: 0.9;
    margin-bottom: var(--space-2);
}

.library-book-overlay-description {
    font-size: var(--text-xs);
    opacity: 0.85;
    line-height: 1.4;
    margin-bottom: var(--space-3);
}

.library-play-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
}

/* Library Book Info */
.library-book-info {
    padding: var(--space-4);
}

.library-book-title {
    font-size: var(--text-base);
    font-weight: var(--font-bold);
    color: var(--text-primary);
    margin-bottom: var(--space-2);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.library-book-author {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-bottom: var(--space-3);
}

.library-book-badge {
    display: inline-block;
    padding: var(--space-1) var(--space-3);
    background: rgba(102, 126, 234, 0.12);
    color: var(--primary-start);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    border-radius: var(--radius-full);
}

/* Grid Animation Stagger */
.library-book-card:nth-child(1) { animation-delay: 0.05s; }
.library-book-card:nth-child(2) { animation-delay: 0.1s; }
.library-book-card:nth-child(3) { animation-delay: 0.15s; }
.library-book-card:nth-child(4) { animation-delay: 0.2s; }
.library-book-card:nth-child(5) { animation-delay: 0.25s; }
.library-book-card:nth-child(6) { animation-delay: 0.3s; }
.library-book-card:nth-child(7) { animation-delay: 0.35s; }
.library-book-card:nth-child(8) { animation-delay: 0.4s; }

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

/* ===== Responsive Adjustments ===== */

@media (max-width: 1024px) {
    .library-books-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: var(--space-4);
    }
    
    .library-filter {
        gap: var(--space-2);
    }
    
    .library-filter .filter-btn {
        padding: var(--space-2) var(--space-4);
        font-size: var(--text-sm);
    }

    .book-hero-content {
        grid-template-columns: 1fr;
        gap: var(--space-6);
        text-align: center;
    }
    
    .book-hero-cover-container {
        max-width: 300px;
        margin: 0 auto;
    }
    
    .book-hero-description {
        margin: 0 auto;
    }
}

@media (max-width: 768px) {
    .library-view-container {
        padding: var(--space-4);
    }
    
    .library-title {
        font-size: var(--text-3xl);
    }
    
    .library-subtitle {
        font-size: var(--text-base);
    }
    
    .library-books-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: var(--space-3);
    }
    
    .library-filter {
        flex-direction: column;
        gap: var(--space-2);
    }
    
    .library-filter .filter-btn {
        width: 100%;
        justify-content: center;
    }
    
    .library-filter .filter-text {
        flex: 1;
        text-align: left;
    }

    .empty-state-title {
        font-size: var(--text-3xl);
    }
    
    .empty-state-description {
        font-size: var(--text-base);
    }
    
    .book-hero-content {
        padding: var(--space-8);
    }
    
    .book-hero-title {
        font-size: var(--text-3xl);
    }
    
    .book-hero-author {
        font-size: var(--text-lg);
    }
    
    .visualizer-nav {
        grid-template-columns: auto 1fr;
        gap: var(--space-4);
    }
    
    .visualizer-nav-logo {
        grid-column: 1 / -1;
        justify-self: center;
    }
    
    .nav-actions {
        justify-self: start;
        grid-row: 1;
    }
    
    .visualizer-nav-brand {
        grid-row: 1;
    }
    
    .player-controls-enhanced {
        gap: var(--space-2);
    }
    
    .control-button {
        width: 40px;
        height: 40px;
        font-size: var(--text-base);
    }
    
    .play-button-enhanced {
        width: 56px;
        height: 56px;
        font-size: var(--text-2xl);
    }
    
    .now-playing-banner {
        padding: var(--space-3);
    }
    
    .now-playing-cover {
        width: 48px;
        height: 48px;
    }
    
    .text-controls {
        gap: var(--space-2);
    }
    
    .character-avatar {
        width: 40px;
        height: 40px;
        font-size: var(--text-base);
    }
}

/* ===== Ambience UX Enhancements ===== */

/* Clickable panel header (wraps entire heading) */
.panel-header-toggle {
    background: transparent;
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    display: block;
    width: 100%;
    text-align: left;
    transition: all var(--transition-fast);
    border-radius: var(--radius-md);
}

.panel-header-toggle h3 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0;
    padding: var(--space-2);
    transition: all var(--transition-fast);
}

.panel-header-toggle:hover h3 {
    background: var(--surface-muted);
    border-radius: var(--radius-md);
}

.panel-header-toggle:active h3 {
    transform: scale(0.98);
}

.panel-header-toggle:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.panel-header-toggle:disabled:hover h3 {
    background: transparent;
}

.toggle-icon {
    width: 16px;
    height: 16px;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: currentColor;
    flex-shrink: 0;
    margin-left: var(--space-2);
    opacity: 0.7;
}

.panel-header-toggle:hover .toggle-icon {
    opacity: 1;
}

/* Rotate chevron when collapsed */
.panel-header-toggle[aria-expanded="false"] .toggle-icon {
    transform: rotate(-90deg);
}

/* Collapsed state for panels */
.character-list.collapsed,
#ambience-content.collapsed {
    display: none;
}

/* Ambience section organization */
.ambience-section {
    margin-bottom: var(--space-4);
}

.ambience-section-title {
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: var(--space-2);
}

.ambience-description-text {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: var(--leading-relaxed);
    margin-bottom: var(--space-3);
}

/* Clickable sound effect entries in side panel */
.sound-effect-clickable {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    padding: var(--space-3);
    background: var(--surface-card);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: left;
    margin-bottom: var(--space-2);
}

.sound-effect-clickable:hover {
    background: var(--surface-muted);
    border-color: var(--primary-start);
    transform: translateX(4px);
    box-shadow: var(--shadow-sm);
}

.sound-effect-clickable:focus-visible {
    outline: 2px solid var(--primary-start);
    outline-offset: 2px;
}

.sound-effect-icon {
    font-size: var(--text-xl);
    flex-shrink: 0;
    opacity: 0.8;
}

.sound-effect-content {
    flex: 1;
    min-width: 0;
}

.sound-effect-description {
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--text-primary);
    margin-bottom: var(--space-1);
}

.sound-effect-context {
    font-size: var(--text-xs);
    color: var(--text-muted);
    line-height: var(--leading-snug);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.sound-effect-arrow {
    font-size: var(--text-lg);
    color: var(--primary-start);
    flex-shrink: 0;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.sound-effect-clickable:hover .sound-effect-arrow {
    opacity: 1;
}

/* Background segment styling */
.background-segment {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
    border-color: rgba(102, 126, 234, 0.2);
}

.background-segment:hover {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border-color: var(--primary-start);
}

.sound-effect-range {
    font-size: var(--text-xs);
    color: var(--primary-start);
    font-weight: var(--font-medium);
    margin-top: var(--space-1);
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

/* Segment ambience indicator icon */
.segment-ambience-indicator {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    font-size: var(--text-base);
    cursor: help;
    opacity: 0.8;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.segment-ambience-indicator:hover {
    opacity: 1;
    transform: scale(1.15);
}

/* Tooltip for ambience indicator */
.segment-ambience-tooltip {
    position: fixed;
    min-width: 200px;
    max-width: 300px;
    padding: var(--space-3);
    background: var(--surface-elevated);
    border: 1px solid var(--surface-border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-fast), visibility var(--transition-fast);
    pointer-events: none;
    white-space: normal;
}

.segment-ambience-tooltip.tooltip-visible,
.segment-ambience-tooltip.tooltip-visible-keyboard {
    opacity: 1;
    visibility: visible;
}

.segment-ambience-indicator:focus-visible {
    outline: 2px solid var(--primary-start);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.tooltip-title {
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
    color: var(--primary-start);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-2);
}

.tooltip-description {
    font-size: var(--text-sm);
    color: var(--text-primary);
    line-height: var(--leading-normal);
}

.tooltip-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.tooltip-list li {
    font-size: var(--text-sm);
    color: var(--text-primary);
    line-height: var(--leading-normal);
    padding: var(--space-1) 0;
    padding-left: var(--space-3);
    position: relative;
}

.tooltip-list li::before {
    content: '•';
    position: absolute;
    left: 0;
    color: var(--primary-start);
    font-weight: var(--font-bold);
}

/* Highlight animation when jumping to segment */
.segment.ambience-highlight {
    animation: ambience-pulse 2s ease-out;
    border-color: var(--primary-start);
}

@keyframes ambience-pulse {
    0% {
        background: var(--surface-card);
        box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.4);
    }
    25% {
        background: rgba(102, 126, 234, 0.1);
        box-shadow: 0 0 0 8px rgba(102, 126, 234, 0);
    }
    50% {
        background: rgba(102, 126, 234, 0.15);
        box-shadow: 0 0 0 12px rgba(102, 126, 234, 0);
    }
    100% {
        background: var(--surface-card);
        box-shadow: 0 0 0 0 rgba(102, 126, 234, 0);
    }
}

/* Empty state for no sound effects */
.empty-state {
    text-align: center;
    padding: var(--space-4);
    color: var(--text-muted);
    font-size: var(--text-sm);
    font-style: italic;
}

/* Responsive adjustments for ambience features */
@media (max-width: 768px) {
    .segment-ambience-tooltip {
        min-width: 180px;
        max-width: calc(100vw - 16px);
    }
    
    .sound-effect-clickable {
        padding: var(--space-2);
        gap: var(--space-2);
    }
    
    .sound-effect-icon {
        font-size: var(--text-base);
    }
    
    .sound-effect-description {
        font-size: var(--text-xs);
    }
    
    .sound-effect-context {
        -webkit-line-clamp: 1;
    }
}

/* ===== Character Profile Modal ===== */

.character-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: var(--z-modal-backdrop);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    animation: modalBackdropFadeIn var(--transition-base) ease-out;
    opacity: 1;
    transition: opacity var(--transition-base) ease-out;
}

.character-modal-backdrop.hidden {
    display: none;
    opacity: 0;
}

.character-modal {
    position: relative;
    background: var(--surface-card);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-2xl);
    border: 4px solid var(--surface-border);
    max-width: 700px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    animation: modalSlideIn var(--transition-base) ease-out;
    z-index: var(--z-modal);
}

.character-modal-close {
    position: absolute;
    top: var(--space-6) !important;
    right: var(--space-6) !important;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.1);
    border: none;
    border-radius: var(--radius-full);
    font-size: 28px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    z-index: 10;
    line-height: 1;
}

.character-modal-close:hover {
    background: rgba(0, 0, 0, 0.2);
    transform: rotate(90deg) scale(1.1);
}

.character-modal-content {
    display: flex;
    flex-direction: row;
    overflow: hidden;
    height: 500px;
    padding: var(--space-4) var(--space-6) var(--space-6) var(--space-6);
    gap: var(--space-6);
}

.character-modal-image-container {
    position: relative;
    width: 300px;
    min-width: 300px;
    height: 100%;
    background: linear-gradient(135deg, var(--primary-start) 0%, var(--primary-end) 100%);
    overflow: hidden;
    flex-shrink: 0;
    border-radius: var(--radius-xl);
    border: 3px solid rgba(255, 255, 255, 0.2);
}

.character-modal-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    opacity: 1;
    transition: opacity var(--transition-base);
}

.character-modal-image-fallback {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 120px;
    font-weight: var(--font-bold);
    color: var(--white);
    opacity: 0;
    transition: opacity var(--transition-base);
}

.character-modal-image[style*="display: none"] ~ .character-modal-image-fallback,
.character-modal-image-fallback.show {
    opacity: 1;
}

.character-modal-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    overflow: hidden;
    min-width: 0;
}

.character-modal-name {
    font-size: var(--text-3xl);
    font-weight: var(--font-bold);
    color: var(--text-primary);
    margin: 0 0 var(--space-4) 0;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    flex-shrink: 0;
}

.character-modal-description {
    font-size: var(--text-base);
    line-height: var(--leading-relaxed);
    color: var(--text-secondary);
    margin: 0;
    overflow-y: auto;
    padding-right: var(--space-2);
    flex: 1;
}

.character-modal-description::-webkit-scrollbar {
    width: 6px;
}

.character-modal-description::-webkit-scrollbar-track {
    background: var(--surface-muted);
    border-radius: var(--radius-full);
}

.character-modal-description::-webkit-scrollbar-thumb {
    background: var(--primary-start);
    border-radius: var(--radius-full);
}

.character-modal-description::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

/* Modal Animations */
@keyframes modalBackdropFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Responsive Modal Styles */
@media (max-width: 768px) {
    .character-modal {
        max-width: 100%;
        max-height: 95vh;
        margin: var(--space-4);
        border-radius: var(--radius-xl);
        border-width: 3px;
    }
    
    .character-modal-content {
        flex-direction: column;
        height: auto;
        max-height: 80vh;
        padding: var(--space-4);
        gap: var(--space-4);
    }
    
    .character-modal-image-container {
        width: 100%;
        height: 300px;
        min-width: auto;
    }
    
    .character-modal-info {
        max-height: 250px;
    }
    
    .character-modal-name {
        font-size: var(--text-2xl);
        margin-bottom: var(--space-3);
    }
    
    .character-modal-description {
        font-size: var(--text-sm);
    }
    
    .character-modal-image-fallback {
        font-size: 80px;
    }
}

@media (max-width: 480px) {
    .character-modal-backdrop {
        padding: 0;
    }
    
    .character-modal {
        max-height: 100vh;
        margin: 0;
        border-radius: 0;
        border-width: 2px;
    }
    
    .character-modal-content {
        padding: var(--space-3);
        gap: var(--space-3);
    }
    
    .character-modal-image-container {
        height: 250px;
        border-width: 2px;
    }
    
    .character-modal-info {
        max-height: 200px;
    }
    
    .character-modal-name {
        font-size: var(--text-xl);
    }
    
    .character-modal-description {
        font-size: var(--text-xs);
    }
}

