:root {
    /* Colors */
    --color-primary: #1F8FFF;
    --color-primary-hover: #187ce6;
    --color-secondary: #22C55E;
    --color-secondary-hover: #1ba04c;
    --color-accent: #38BDF8;
    --color-bg: #F8FAFC;
    --color-text: #0F172A;
    --color-text-muted: #64748B;
    --color-surface: #FFFFFF;
    --color-border: #E2E8F0;

    /* Typography */
    --font-family: 'Inter', 'Outfit', system-ui, -apple-system, sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-md: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 2rem;
    --font-weight-regular: 400;
    --font-weight-medium: 500;
    --font-weight-bold: 700;
    --line-height-tight: 1.25;
    --line-height-normal: 1.5;
    --line-height-relaxed: 1.75;

    /* Spacing */
    --spacing-1: 0.25rem;
    --spacing-2: 0.5rem;
    --spacing-3: 0.75rem;
    --spacing-4: 1rem;
    --spacing-5: 1.25rem;
    --spacing-6: 1.5rem;
    --spacing-8: 2rem;
    --spacing-12: 3rem;

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.1), 0 2px 4px -2px rgba(15, 23, 42, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.1), 0 4px 6px -4px rgba(15, 23, 42, 0.1);
    --shadow-glow: 0 0 15px rgba(31, 143, 255, 0.3);

    /* Transitions */
    --transition-fast: 0.15s ease-in-out;
    --transition-normal: 0.3s ease-in-out;
    --transition-bounce: 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

body {
    font-family: var(--font-family);
    background-color: var(--color-bg);
    color: var(--color-text);
    line-height: var(--line-height-normal);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: var(--font-weight-bold);
    line-height: var(--line-height-tight);
    color: var(--color-text);
    margin-bottom: var(--spacing-4);
}

h1 {
    font-size: var(--font-size-3xl);
}

h2 {
    font-size: var(--font-size-2xl);
}

h3 {
    font-size: var(--font-size-xl);
}

p {
    margin-bottom: var(--spacing-4);
    color: var(--color-text-muted);
}

/* Layout Utilities */
.container {
    width: 100%;
    max-width: 480px;
    /* Mobile-first container */
    margin: 0 auto;
    padding: var(--spacing-4);
    /* Smooth scrolling for mobile */
    scroll-behavior: smooth;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
}

.section {
    margin-bottom: var(--spacing-12);
}

.section-title {
    font-size: var(--font-size-lg);
    color: var(--color-primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--spacing-6);
    font-weight: var(--font-weight-bold);
}

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.flex-col {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-4);
}

/* Typography Classes */
.text-xs {
    font-size: var(--font-size-xs);
}

.text-sm {
    font-size: var(--font-size-sm);
}

.text-md {
    font-size: var(--font-size-md);
}

.text-lg {
    font-size: var(--font-size-lg);
}

.font-medium {
    font-weight: var(--font-weight-medium);
}

.font-bold {
    font-weight: var(--font-weight-bold);
}

.text-primary {
    color: var(--color-primary);
}

.text-secondary {
    color: var(--color-secondary);
}

.text-accent {
    color: var(--color-accent);
}

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

.text-base {
    color: var(--color-text);
}

/* Components */

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-3) var(--spacing-6);
    border-radius: var(--radius-full);
    font-weight: var(--font-weight-bold);
    font-size: var(--font-size-md);
    cursor: pointer;
    transition: all var(--transition-bounce);
    border: none;
    outline: none;
    width: 100%;
    /* Mobile optimized full width */
    text-align: center;
    text-decoration: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.btn:active {
    transform: scale(0.96);
}

.btn-primary {
    background-color: var(--color-primary);
    color: white;
    box-shadow: var(--shadow-md), 0 4px 0 #1865b6;
    /* 3D effect like Duolingo */
    margin-bottom: 4px;
    /* Space for the 3D shadow jump */
}

.btn-primary:active {
    box-shadow: var(--shadow-sm), 0 0 0 #1865b6;
    transform: translateY(4px);
}

.btn-secondary {
    background-color: var(--color-secondary);
    color: white;
    box-shadow: var(--shadow-md), 0 4px 0 #189843;
    margin-bottom: 4px;
}

.btn-secondary:active {
    box-shadow: var(--shadow-sm), 0 0 0 #189843;
    transform: translateY(4px);
}

.btn-outline {
    background-color: transparent;
    color: var(--color-text);
    border: 2px solid var(--color-border);
    box-shadow: 0 4px 0 var(--color-border);
    margin-bottom: 4px;
}

.btn-outline:active {
    box-shadow: 0 0 0 var(--color-border);
    transform: translateY(4px);
}

/* Inputs */
.input-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-2);
    width: 100%;
}

.input-label {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    color: var(--color-text);
}

.input-field {
    width: 100%;
    padding: var(--spacing-4);
    border-radius: var(--radius-md);
    border: 2px solid var(--color-border);
    background-color: var(--color-surface);
    font-size: var(--font-size-md);
    color: var(--color-text);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    font-family: var(--font-family);
    outline: none;
    appearance: none;
    -webkit-appearance: none;
}

.input-field::placeholder {
    color: var(--color-text-muted);
}

.input-field:focus {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-glow);
}

/* Cards */
.card {
    background-color: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: var(--spacing-6);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--color-border);
    transition: transform var(--transition-bounce), box-shadow var(--transition-bounce);
}

.card-interactive {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.card-interactive:active {
    transform: scale(0.98);
    box-shadow: var(--shadow-sm);
}

/* Progress Bars */
.progress-container {
    width: 100%;
    height: 16px;
    background-color: var(--color-border);
    border-radius: var(--radius-full);
    overflow: hidden;
    position: relative;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
    border-radius: var(--radius-full);
    width: 0%;
    /* Set via inline style or JS */
    transition: width 1s ease-in-out;
    position: relative;
    overflow: hidden;
}

.progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.3) 0%, rgba(255, 255, 255, 0) 50%);
    border-radius: var(--radius-full);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-1) var(--spacing-3);
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge-xp {
    background: linear-gradient(135deg, #FCD34D, #F59E0B);
    color: #78350F;
    box-shadow: 0 2px 4px rgba(245, 158, 11, 0.3);
}

.badge-rank {
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    color: white;
    box-shadow: 0 2px 4px rgba(31, 143, 255, 0.3);
}

/* Showcase Specific Styles */
.color-swatch {
    width: 60px;
    height: 60px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--spacing-2);
}

.color-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--spacing-4);
    margin-bottom: var(--spacing-8);
}

.color-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

/* --- App Shell Layout --- */

body {
    /* Prevent scroll on body for PWA shell */
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background-color: var(--color-surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--spacing-4);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
    z-index: 50;
}

.app-title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--color-text);
    display: flex;
    align-items: center;
    gap: var(--spacing-2);
}

.app-title-icon {
    color: var(--color-primary);
}

.notification-btn {
    background: none;
    border: none;
    color: var(--color-text-muted);
    position: relative;
    padding: var(--spacing-2);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: color var(--transition-fast), background-color var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.notification-btn:active {
    background-color: var(--color-bg);
    color: var(--color-text);
}

.notification-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 8px;
    height: 8px;
    background-color: #EF4444;
    /* Red for alert */
    border-radius: var(--radius-full);
    border: 2px solid var(--color-surface);
}

.app-main {
    flex: 1;
    overflow-y: auto;
    padding-top: 76px;
    /* Header height + spacing */
    padding-bottom: 90px;
    /* Tab bar height + spacing */
    -webkit-overflow-scrolling: touch;
}

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--color-surface);
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: space-around;
    padding: var(--spacing-2) var(--spacing-2) max(var(--spacing-2), env(safe-area-inset-bottom, 0px));
    z-index: 50;
    height: calc(64px + max(0px, env(safe-area-inset-bottom, 0px)));
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.03);
    /* Subtle top shadow */
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex: 1;
    /* Allow items to stretch evenly */
    min-width: 0;
    /* Prevent overflow on very small devices */
    height: 100%;
    color: var(--color-text-muted);
    text-decoration: none;
    transition: color var(--transition-fast), transform var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
    border-radius: var(--radius-lg);
    padding: var(--spacing-1);
    /* Larger touch target */
}

.nav-item:active {
    background-color: var(--color-bg);
    transform: scale(0.95);
}

.nav-item.active {
    color: var(--color-primary);
}

.nav-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-label {
    font-size: clamp(10px, 2.5vw, 12px);
    /* Responsive font scaling */
    font-weight: var(--font-weight-medium);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    text-align: center;
}

/* --- Specific Components --- */

.xp-progress-card {
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    color: white;
    border: none;
}

.xp-progress-card .text-muted {
    color: rgba(255, 255, 255, 0.8);
}

.xp-progress-card .text-base,
.xp-progress-card h3 {
    color: white;
}

.xp-progress-card .progress-container {
    background-color: rgba(0, 0, 0, 0.2);
}

.xp-progress-card .progress-bar {
    background: white;
}

.xp-progress-card .progress-bar::after {
    display: none;
}

.audiobook-card {
    display: flex;
    gap: var(--spacing-4);
    align-items: center;
}

.audiobook-cover {
    width: 64px;
    height: 64px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, #a78bfa, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: var(--font-size-2xl);
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

.audiobook-info {
    flex: 1;
}

.audiobook-title {
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-bold);
    margin-bottom: var(--spacing-1);
}

.audiobook-author {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.play-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background-color: var(--color-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    box-shadow: var(--shadow-sm), 0 2px 0 #1865b6;
    cursor: pointer;
    transition: all var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.play-btn:active {
    transform: translateY(2px);
    box-shadow: 0 0 0 #1865b6;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-3);
    padding: var(--spacing-3) 0;
    border-bottom: 1px solid var(--color-border);
}

.leaderboard-item:last-child {
    border-bottom: none;
}

.leaderboard-rank {
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-muted);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

.leaderboard-rank.top-1 {
    color: #F59E0B;
    /* Restore original text colors */
}

.leaderboard-rank.top-2 {
    color: #94A3B8;
}

.leaderboard-rank.top-3 {
    color: #B45309;
}

.leaderboard-item.current-user-highlight {
    background-color: rgba(56, 189, 248, 0.1);
    border-radius: var(--radius-lg);
    padding-left: var(--spacing-3);
    padding-right: var(--spacing-3);
    margin-left: calc(-1 * var(--spacing-3));
    margin-right: calc(-1 * var(--spacing-3));
    border-bottom: none;
    box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.4);
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background-color: var(--color-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-lg);
    border: 2px solid var(--color-surface);
    box-shadow: var(--shadow-sm);
    object-fit: cover;
}

.leaderboard-user {
    flex: 1;
    font-weight: var(--font-weight-medium);
}

.leaderboard-score {
    font-weight: var(--font-weight-bold);
    color: var(--color-primary);
}

.ai-chat-bubble {
    background-color: var(--color-surface);
    border: 2px solid var(--color-primary);
    border-radius: var(--radius-lg);
    border-bottom-left-radius: var(--radius-sm);
    padding: var(--spacing-4);
    box-shadow: var(--shadow-sm);
    position: relative;
    margin-bottom: var(--spacing-4);
}

.ai-chat-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-2);
    margin-bottom: var(--spacing-2);
}

.ai-icon {
    background-color: var(--color-bg);
    color: var(--color-primary);
    width: 24px;
    height: 24px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-xs);
}

.ai-title {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    color: var(--color-primary);
}

.ai-chat-text {
    font-size: var(--font-size-md);
    color: var(--color-text);
    line-height: var(--line-height-relaxed);
}

/* --- Expanded UI Components --- */

/* Lesson Card */
.lesson-card {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-4);
    padding: var(--spacing-5);
    background-color: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border);
    transition: transform var(--transition-bounce), box-shadow var(--transition-normal);
    text-decoration: none;
    color: var(--color-text);
    -webkit-tap-highlight-color: transparent;
}

.lesson-card:active {
    transform: scale(0.98);
}

.lesson-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.lesson-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    background: var(--color-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-primary);
    font-size: var(--font-size-xl);
}

/* Dashboard Card */
.dashboard-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: var(--spacing-5);
    box-shadow: var(--shadow-md);
    text-align: center;
}

/* Vocabulary Insight Card */
.vocabulary-card {
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.1), rgba(31, 143, 255, 0.1));
    border: 1px solid rgba(31, 143, 255, 0.2);
    border-radius: var(--radius-lg);
    padding: var(--spacing-5);
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-4);
}

.vocab-word {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    color: var(--color-primary);
    margin-bottom: var(--spacing-1);
}

/* Chat UI Improvements */
.user-chat-bubble {
    background-color: var(--color-primary);
    color: white;
    border-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-sm);
    padding: var(--spacing-4);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--spacing-4);
    align-self: flex-end;
    max-width: 85%;
    margin-left: auto;
}

.user-chat-bubble .ai-chat-text {
    color: white;
}

.chat-input-container {
    display: flex;
    gap: var(--spacing-2);
    align-items: center;
    background-color: var(--color-surface);
    padding: var(--spacing-3) var(--spacing-4);
    border-top: 1px solid var(--color-border);
    position: relative;
    /* Not fixed for showcase, but in app it could be */
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.chat-input {
    flex: 1;
    border: none;
    background-color: var(--color-bg);
    padding: var(--spacing-3) var(--spacing-4);
    border-radius: var(--radius-full);
    font-family: var(--font-family);
    font-size: var(--font-size-md);
    outline: none;
}

.send-btn {
    background-color: var(--color-primary);
    color: white;
    min-width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.send-btn:active {
    transform: scale(0.9);
}

/* Gamification Elements */
.streak-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: var(--font-weight-bold);
    color: #F97316;
    /* Orange */
    background-color: rgba(249, 115, 22, 0.1);
    padding: var(--spacing-1) var(--spacing-3);
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
}

/* Interaction States */
.skeleton {
    background: linear-gradient(90deg, var(--color-bg) 25%, #E2E8F0 50%, var(--color-bg) 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: var(--radius-sm);
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

.skeleton-text {
    height: 16px;
    margin-bottom: var(--spacing-2);
    width: 100%;
}

.skeleton-text.short {
    width: 60%;
}

.skeleton-circle {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
}

.state-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--spacing-8) var(--spacing-4);
    gap: var(--spacing-4);
    background-color: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px dashed var(--color-border);
}

.state-icon {
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    background-color: var(--color-bg);
    color: var(--color-text-muted);
    font-size: 32px;
}

.state-icon.error {
    background-color: rgba(239, 68, 68, 0.1);
    color: #EF4444;
}

.state-title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--color-text);
    margin-bottom: 0;
}

.state-desc {
    color: var(--color-text-muted);
    font-size: var(--font-size-md);
    margin-bottom: var(--spacing-2);
}

/* --- Authentication Layout --- */

.auth-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: var(--spacing-6);
    background-color: var(--color-bg);
}

.auth-header {
    text-align: center;
    margin-top: 10vh;
    margin-bottom: var(--spacing-8);
}

.auth-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    background-color: var(--color-primary);
    color: white;
    border-radius: var(--radius-lg);
    font-size: 32px;
    margin-bottom: var(--spacing-4);
    box-shadow: var(--shadow-md);
}

.auth-title {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
    color: var(--color-text);
    margin-bottom: var(--spacing-2);
}

.auth-subtitle {
    color: var(--color-text-muted);
    font-size: var(--font-size-md);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-4);
    background-color: var(--color-surface);
    padding: var(--spacing-6);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--color-border);
}

.auth-footer {
    text-align: center;
    margin-top: var(--spacing-6);
    color: var(--color-text-muted);
}

.auth-link {
    color: var(--color-primary);
    font-weight: var(--font-weight-bold);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.auth-link:active {
    color: var(--color-primary-hover);
}

.error-text {
    color: #EF4444;
    /* Red */
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    margin-top: 4px;
    display: none;
    /* Hidden by default */
}

.error-text.visible {
    display: block;
}

.input-field.error {
    border-color: #EF4444;
    background-color: rgba(239, 68, 68, 0.05);
}

.input-field.error:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

/* Loading Spinner for Buttons */
.btn-text {
    transition: opacity var(--transition-fast);
}

.btn-spinner {
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast);
}

.btn.loading {
    pointer-events: none;
    position: relative;
}

.btn.loading .btn-text {
    opacity: 0;
}

.btn.loading .btn-spinner {
    opacity: 1;
}

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

/* --- Audiobooks Section --- */

/* Filter Chips */
.filter-chips {
    display: flex;
    overflow-x: auto;
    gap: var(--spacing-2);
    padding: var(--spacing-2) 0 var(--spacing-4) 0;
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE and Edge */
}

.filter-chips::-webkit-scrollbar {
    display: none;
}

.filter-chip {
    padding: var(--spacing-2) var(--spacing-4);
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition-fast);
}

.filter-chip.active {
    background-color: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

/* Audiobooks Grid */
.audiobooks-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--spacing-4);
}

/* Audiobook Details Hero */
.audiobook-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: var(--spacing-6) 0;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--spacing-6);
}

.hero-cover {
    width: 180px;
    height: 180px;
    border-radius: var(--radius-lg);
    background-color: var(--color-surface);
    box-shadow: var(--shadow-lg);
    margin-bottom: var(--spacing-4);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-primary);
    background-size: cover;
    background-position: center;
}

.hero-title {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
    margin-bottom: var(--spacing-1);
}

.hero-author {
    color: var(--color-text-muted);
    font-size: var(--font-size-md);
    margin-bottom: var(--spacing-3);
}

.hero-meta {
    display: flex;
    gap: var(--spacing-2);
    justify-content: center;
    margin-bottom: var(--spacing-4);
}

.hero-desc {
    color: var(--color-text);
    font-size: var(--font-size-md);
    line-height: 1.6;
    max-width: 600px;
    margin: 0 auto;
}

/* Chapter List */
.chapter-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-3);
}

.chapter-item {
    background-color: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: var(--spacing-4);
    display: flex;
    align-items: center;
    gap: var(--spacing-4);
    border: 1px solid var(--color-border);
}

.chapter-number {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background-color: rgba(31, 143, 255, 0.1);
    color: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-weight-bold);
    font-size: var(--font-size-sm);
    flex-shrink: 0;
}

.chapter-info {
    flex: 1;
    min-width: 0;
    /* Prevents text overflow */
}

.chapter-title {
    font-weight: var(--font-weight-medium);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chapter-duration {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

.chapter-actions {
    display: flex;
    gap: var(--spacing-2);
}

.btn-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    transition: transform var(--transition-fast), background-color var(--transition-fast);
}

.btn-icon:active {
    transform: scale(0.9);
}

.btn-icon.play-btn {
    background-color: var(--color-primary);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-icon.discuss-btn {
    background-color: var(--color-bg);
    color: var(--color-secondary);
    border: 1px solid var(--color-border);
}

/* Header Back Button */
.header-back-btn {
    background: none;
    border: none;
    color: var(--color-text);
    padding: var(--spacing-2);
    margin-left: calc(-1 * var(--spacing-2));
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* =========================
   READ ALONG
========================= */

.readalong-page {
    min-height: 100vh;
    background: #f5f7fb;
}

.readalong-header {
    position: sticky;
    top: 0;
    z-index: 100;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
}

.compact-header {
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
}

.back-button,
.reader-toggle-button {
    border: none;
    background: transparent;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    color: #1d4ed8;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chapter-title {
    font-size: 18px;
    font-weight: 700;
    text-align: center;
    flex: 1;
    color: #111827;
    padding: 0 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.audio-section {
    position: sticky;
    top: 60px;
    z-index: 95;
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    padding: 12px 16px;
    transition:
        transform 0.55s ease,
        opacity 0.55s ease,
        max-height 0.55s ease,
        padding 0.55s ease;
    transform-origin: top;
    max-height: 120px;
    opacity: 1;
    overflow: hidden;
}

.audio-section.collapsed {
    transform: translateY(-120%);
    opacity: 0;
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.audio-section audio {
    width: 100%;
    display: block;
    margin: 0;
}

.readalong-main {
    width: 100%;
}

.loading-view {
    padding: 28px 20px;
    text-align: center;
    color: #6b7280;
}

.empty-state {
    display: none;
    padding: 40px 24px;
    text-align: center;
}

.empty-state h2 {
    font-size: 22px;
    margin-bottom: 12px;
    color: #111827;
}

.empty-state p {
    font-size: 16px;
    color: #6b7280;
}

.transcript-container {
    display: none;
    max-width: 760px;
    margin: 0 auto;
    padding: 28px 20px 120px;
    font-size: 20px;
    line-height: 1.95;
    font-weight: 400;
    color: #444;
    text-align: justify;
    word-break: break-word;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: pan-y;
}

.transcript-segment {
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
    color: inherit;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.transcript-segment:hover {
    background: transparent;
    color: inherit;
}

.transcript-segment.active {
    background: #fff4b0;
    padding: 2px 4px;
    border-radius: 6px;
    color: #000;
    font-weight: 400;
    animation: highlightFade 0.4s ease;
}

@keyframes highlightFade {
    from {
        background: #fff9d0;
    }

    to {
        background: #fff4b0;
    }
}

@media (max-width: 768px) {
    .chapter-title {
        font-size: 17px;
    }

    .transcript-container {
        padding: 22px 18px 100px;
        font-size: 18px;
        line-height: 1.95;
    }

    .audio-section {
        padding: 12px;
    }
}