/* Books Page Styling - Using global theme variables from theme-variables.css */
/* This file inherits theme variables for dark/light mode support */

/* Component-specific variables only */
:root {
    --book-shadow: 0 2px 8px rgba(0, 0, 0, 0.08), 0 4px 16px rgba(0, 0, 0, 0.06);
    --book-hover-shadow: 0 8px 30px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.08);
    --book-border-radius: 16px;
    --card-glow: 0 0 0 1px rgba(139, 92, 246, 0.3), 0 8px 30px rgba(139, 92, 246, 0.15);
}

[data-theme="dark"] {
    --book-shadow: 0 2px 8px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.2);
    --book-hover-shadow: 0 8px 30px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
    --card-glow: 0 0 0 1px rgba(139, 92, 246, 0.4), 0 8px 30px rgba(139, 92, 246, 0.2);
}

/* Body inherits from global theme - no overrides */

body::before {
    display: none !important;
}

.main-content {
    background: transparent !important;
}

/* Header Consistency Fix */
.header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    margin-bottom: 30px !important;
    flex-wrap: wrap !important;
    gap: 15px !important;
}

.header .header-right {
    display: flex !important;
    align-items: center !important;
    gap: 20px !important;
}

/* Content Title styling */
.content-title {
    margin-bottom: 30px;
}

.content-title h1 {
    font-size: 28px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.content-title p {
    color: var(--text-secondary);
    font-size: 16px;
}

/* =====================================================
   Hero Banner Styling
   ===================================================== */
.page-hero {
    position: relative;
    padding: 2.5rem 2rem 3rem;
    margin-bottom: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 1.5rem;
    background: var(--gradient-primary, linear-gradient(135deg, #a855f7 0%, #ec4899 100%));
    border-radius: 24px;
    overflow: hidden;
}

/* Decorative dot pattern overlay */
.page-hero::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: radial-gradient(rgba(255, 255, 255, 0.12) 1px, transparent 1px);
    background-size: 24px 24px;
    pointer-events: none;
}

/* Decorative floating circle */
.page-hero::after {
    content: '';
    position: absolute;
    top: -50px;
    right: -50px;
    width: 180px;
    height: 180px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    pointer-events: none;
}

.page-hero__content {
    max-width: 600px;
    position: relative;
    z-index: 2;
}

.page-hero__title {
    font-size: 2.25rem;
    font-weight: 800;
    color: #ffffff;
    margin: 0 0 0.75rem;
    letter-spacing: -0.02em;
    line-height: 1.2;
    text-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.page-hero__subtitle {
    font-size: 1.1rem;
    color: rgba(255, 255, 255, 0.95);
    margin: 0;
    line-height: 1.6;
    font-weight: 500;
}

.page-hero__stats {
    display: flex;
    gap: 1.5rem;
    position: relative;
    z-index: 2;
}

.page-hero__stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.75rem 1.25rem;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    min-width: 80px;
}

.page-hero__stat-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: #ffffff;
    line-height: 1;
}

.page-hero__stat-label {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.85);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

/* Category-specific hero gradients */
.page-hero--coloring {
    background: linear-gradient(135deg, #ec4899 0%, #f97316 100%);
}

.page-hero--puzzle {
    background: linear-gradient(135deg, #3b82f6 0%, #06b6d4 100%);
}

.page-hero--mandala {
    background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
}

.page-hero--activity {
    background: linear-gradient(135deg, #10b981 0%, #14b8a6 100%);
}

/* Hero responsive styles */
@media (max-width: 768px) {
    .page-hero {
        padding: 2rem 1.5rem;
        border-radius: 16px;
    }
    
    .page-hero__title {
        font-size: 1.75rem;
    }
    
    .page-hero__subtitle {
        font-size: 1rem;
    }
    
    .page-hero__stats {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .page-hero__stat {
        padding: 0.5rem 1rem;
    }
    
    .page-hero__stat-value {
        font-size: 1.25rem;
    }
    
    .page-hero__stat-label {
        font-size: 0.7rem;
    }
}

/* Books Grid */
.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 24px;
    margin-bottom: 40px;
    margin-top: 20px;
}

/* Focus effect: dim other cards when one is hovered (except during preview) */
.books-grid:hover .book-tile:not(:hover):not(.preview-active) {
    opacity: 0.7;
    transform: scale(0.98);
    filter: saturate(0.9);
}

/* Don't dim cards when a preview is active */
.books-grid:has(.preview-active) .book-tile:not(.preview-active) {
    opacity: 1;
    transform: scale(1);
    filter: none;
}

/* Smooth restore when not hovering grid */
.books-grid .book-tile {
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease;
}

/* Refined Book Tile Styling */
.book-tile {
    background: var(--bg-elevated);
    border-radius: var(--book-border-radius);
    overflow: hidden;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    display: flex;
    flex-direction: column;
    box-shadow: var(--book-shadow);
    border: 1px solid var(--border-color);
    height: 100%;  /* Make all tiles equal height */
}

.book-tile:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: var(--card-glow);
    border-color: rgba(139, 92, 246, 0.3);
    z-index: 10; /* Bring hovered card above others */
}

/* Book Cover */
.book-cover {
    position: relative;
    width: 100%;
    height: 160px;  /* Reduced height for compactness */
    background: var(--bg-elevated); /* Theme-aware background */
    /* No border - seamless transition to info */
    perspective: 1000px; /* Enable 3D space */
    overflow: visible; /* Allow pages to spill out */
}

/* Note: Shimmer effect removed - conflicts with 3D page effect pseudo-elements */

/* The Book Image Container */
.book-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top;
    transition: transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94), opacity 0.3s ease;
    transform-origin: left center;
    position: relative;
    z-index: 10;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    border-radius: 2px;
}

/* Page Effect Elements - Disabled to remove hazy white overlay */
.book-cover::before,
.book-cover::after {
    display: none;
}

/* Hover Animation - Open Book */
.book-tile:hover .book-cover img {
    transform: rotateY(-25deg) translateX(5px) scale(1.05);
    box-shadow: 5px 5px 15px rgba(0,0,0,0.4);
}

/* Disable hover effect when preview is active */
.book-tile.preview-active:hover .book-cover img {
    transform: none;
    box-shadow: none;
}

/* Hover animations for pseudo-elements removed since they are hidden */

/* Gradient overlay - removed to eliminate hazy look */
.book-cover .book-overlay {
    display: none;
}

/* Light theme overlay - removed */
[data-theme="light"] .book-cover .book-overlay {
    display: none;
}

.book-tile:hover .book-cover .book-overlay {
    opacity: 0.7; /* Slightly fade overlay on hover to reveal more of image */
}

.book-tile.preview-active:hover .book-cover .book-overlay {
    transform: none;
    opacity: 0; /* Hide overlay during preview */
}

/* Flipbook Animation Styles */
.flipbook-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    perspective: 1500px;
    z-index: 20;
    background: var(--bg-elevated); /* Theme-aware background */
    /* Spine shadow */
    box-shadow: inset 10px 0 20px -5px rgba(0,0,0,0.5);
}

/* --- Coloring Book Effect: Premium Card Stack --- */
.flipbook-container.effect-coloring {
    background: linear-gradient(145deg, #fefefe 0%, #f0f2f5 50%, #e8eaed 100%);
    perspective: none;
    overflow: hidden;
    border-radius: 6px;
    /* Premium paper texture feel */
    box-shadow: 
        inset 0 1px 0 rgba(255,255,255,0.9),
        inset 0 -1px 3px rgba(0,0,0,0.05),
        0 1px 3px rgba(0,0,0,0.08);
}

/* CLEANUP: Dedicated class for coloring pages to avoid 3D conflicts */
.coloring-page {
    position: absolute;
    top: 6px;
    left: 6px;
    right: 6px;
    bottom: 6px;
    width: auto;
    height: auto;
    background: #ffffff;
    opacity: 1;
    transform-origin: 50% 100%; /* Pivot from bottom center - like lifting a card */
    will-change: transform, opacity, filter;
    animation: coloringCardLift 10s infinite cubic-bezier(0.23, 1, 0.32, 1);
    /* Premium floating card shadow */
    box-shadow: 
        0 1px 1px rgba(0,0,0,0.04),
        0 2px 4px rgba(0,0,0,0.04),
        0 4px 8px rgba(0,0,0,0.04),
        0 8px 16px rgba(0,0,0,0.04),
        0 16px 32px rgba(0,0,0,0.04);
    border-radius: 4px;
    border: none;
    /* Subtle paper texture */
    background-image: 
        linear-gradient(to bottom, rgba(255,255,255,1) 0%, rgba(250,250,252,1) 100%);
}

.coloring-page img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    padding: 8px;
    border-radius: 2px;
    /* Crisp line art */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* 
   Premium "Card Lift" Transition - Inspired by Apple's card interactions
   - Card lifts from bottom edge like picking up paper
   - Subtle 3D rotation as it rises
   - Soft blur during motion
   - Spring-like settle when returning
*/
@keyframes coloringCardLift {
    0%, 15% { 
        opacity: 1; 
        transform: perspective(600px) rotateX(0deg) translateY(0) scale(1);
        filter: blur(0) saturate(1);
        box-shadow: 
            0 1px 1px rgba(0,0,0,0.04),
            0 2px 4px rgba(0,0,0,0.04),
            0 4px 8px rgba(0,0,0,0.04);
    }
    20% {
        opacity: 1;
        transform: perspective(600px) rotateX(-5deg) translateY(-8px) scale(1.01);
        filter: blur(0) saturate(1.05);
        box-shadow: 
            0 8px 16px rgba(0,0,0,0.08),
            0 16px 32px rgba(0,0,0,0.06);
    }
    28% { 
        opacity: 0; 
        transform: perspective(600px) rotateX(-15deg) translateY(-30px) scale(1.03);
        filter: blur(4px) saturate(1.1);
        box-shadow: 
            0 20px 40px rgba(0,0,0,0.12),
            0 30px 60px rgba(0,0,0,0.08);
    }
    85% {
        opacity: 0;
        transform: perspective(600px) rotateX(-20deg) translateY(-40px) scale(1.05);
        filter: blur(6px) saturate(1.1);
    }
    92% {
        opacity: 0.6;
        transform: perspective(600px) rotateX(-3deg) translateY(-10px) scale(1.01);
        filter: blur(1px) saturate(1.02);
    }
    100% { 
        opacity: 1; 
        transform: perspective(600px) rotateX(0deg) translateY(0) scale(1);
        filter: blur(0) saturate(1);
        box-shadow: 
            0 1px 1px rgba(0,0,0,0.04),
            0 2px 4px rgba(0,0,0,0.04),
            0 4px 8px rgba(0,0,0,0.04);
    }
}

/* Staggered depth for realistic card stack */
.coloring-page:nth-child(1) { 
    z-index: 5;
    animation-delay: 0s;
}
.coloring-page:nth-child(2) { 
    z-index: 4; 
    animation-delay: 2s;
    transform: translateY(2px) scale(0.99);
}
.coloring-page:nth-child(3) { 
    z-index: 3; 
    animation-delay: 4s;
    transform: translateY(4px) scale(0.98);
}
.coloring-page:nth-child(4) { 
    z-index: 2; 
    animation-delay: 6s;
    transform: translateY(6px) scale(0.97);
}
.coloring-page:nth-child(5) { 
    z-index: 1; 
    animation-delay: 8s;
    transform: translateY(8px) scale(0.96);
}

/* --- Puzzle Book Effect: Smart Stack --- */
.flipbook-container.effect-puzzle,
.flipbook-container.effect-sudoku,
.flipbook-container.effect-word-search {
    background: var(--bg-elevated); /* Theme-aware background */
    perspective: 1000px;
    /* Subtle premium grid */
    background-image: 
        linear-gradient(var(--border-color) 1px, transparent 1px),
        linear-gradient(90deg, var(--border-color) 1px, transparent 1px);
    background-size: 30px 30px;
}

/* Puzzle pages slide up with Apple-like spring physics */
.effect-puzzle .flip-page,
.effect-sudoku .flip-page,
.effect-word-search .flip-page {
    animation: puzzleStack 6s infinite cubic-bezier(0.2, 0.8, 0.2, 1);
    transform-origin: center bottom;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.2);
    background: var(--bg-elevated); /* Theme-aware background */
}

@keyframes puzzleStack {
    0% {
        transform: translateY(0) scale(1);
        opacity: 1;
        z-index: 10;
    }
    15% {
        transform: translateY(0) scale(1);
    }
    25% {
        /* Slide up and fade out */
        transform: translateY(-20px) scale(0.95);
        opacity: 0;
        z-index: 10;
    }
    26% {
        /* Reset to bottom immediately while invisible */
        transform: translateY(0) scale(0.9);
        opacity: 0;
        z-index: 0;
    }
    100% {
        /* Stay invisible at bottom */
        transform: translateY(0) scale(0.9);
        opacity: 0;
        z-index: 0;
    }
}

/* --- Default Page Flip (General) --- */
.flip-page {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform-origin: left center;
    transform-style: preserve-3d;
    backface-visibility: visible;
    /* Animation duration = (number of pages * delay per page) + buffer */
    animation: pageFlip 6s infinite ease-in-out;
}

/* Front of the page (Image) - for non-coloring books */
.flip-page img:not(.page-bw) {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 0 4px 4px 0;
    background: white;
    backface-visibility: hidden; /* Hide when flipped */
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
    /* Inner shadow for depth */
    box-shadow: inset 3px 0 5px rgba(0,0,0,0.1);
}

/* Back of the page (White/Paper) */
.flip-page::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #f0f0f0;
    background-image: linear-gradient(to right, #e0e0e0 0%, #f5f5f5 20%);
    transform: rotateY(180deg);
    backface-visibility: hidden;
    border-radius: 4px 0 0 4px;
    z-index: 1;
    /* Shadow to simulate curvature */
    box-shadow: inset -5px 0 10px rgba(0,0,0,0.1);
}

/* Dynamic lighting/shadow overlay */
.flip-page::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to right, rgba(0,0,0,0.4) 0%, rgba(0,0,0,0) 100%);
    opacity: 0;
    z-index: 3;
    pointer-events: none;
    transition: opacity 0.2s;
}

@keyframes pageFlip {
    0% {
        transform: rotateY(0deg);
        filter: brightness(1);
    }
    10% {
        /* Start lifting - slight shadow */
        filter: brightness(0.95);
    }
    20% {
        /* Vertical - darkest point */
        transform: rotateY(-90deg);
        filter: brightness(0.85);
    }
    35% {
        /* Landed on left */
        transform: rotateY(-180deg);
        filter: brightness(1);
        opacity: 1;
    }
    80% {
        /* Stay visible for a bit */
        transform: rotateY(-180deg);
        opacity: 1;
    }
    100% {
        /* Fade out to reset */
        transform: rotateY(-180deg);
        opacity: 0;
    }
}

/* Hide original cover elements when preview is active */
.book-tile.preview-active .book-cover > img,
.book-tile.preview-active .book-cover::before,
.book-tile.preview-active .book-cover::after,
.book-tile.preview-active .no-cover {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease;
}


.no-cover {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--bg-elevated), var(--bg-secondary));
    color: var(--text-secondary);
    position: relative;
    z-index: 10;
    transition: transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    transform-origin: left center;
}

.book-tile:hover .no-cover {
    transform: rotateY(-25deg) translateX(5px) scale(1.05);
}

.no-cover i {
    font-size: 32px;
    margin-bottom: 8px;
}

/* Book Info - Clean styling with theme support */
.book-info {
    padding: 14px 16px 16px;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    justify-content: space-between;
    /* Solid background that matches theme */
    background: var(--bg-elevated);
    position: relative;
    z-index: 2;
    border-radius: 0 0 var(--book-border-radius) var(--book-border-radius);
}

/* Book Title */
.book-title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    color: var(--text-primary);
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 40px; /* Fixed height for 2 lines of text */
    transition: color 0.2s ease;
}

/* Title color change on hover */
.book-tile:hover .book-title {
    color: var(--accent-purple, #8b5cf6);
}

/* Book Meta */
.book-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-secondary);
    font-size: 12px;
    margin: 8px 0 10px 0;
    padding: 0;
    font-weight: 500;
}

.book-rating, .book-downloads {
    display: flex;
    align-items: center;
    gap: 5px;
    background: transparent;
    padding: 4px 0;
    border-radius: 0;
    border: none;
    transition: all 0.3s ease;
    font-size: 13px;
}

/* Subtle hover effect on meta items */
.book-rating:hover, .book-downloads:hover {
    opacity: 0.8;
}

.book-rating i {
    color: #fbbf24;
    font-size: 12px;
    filter: drop-shadow(0 0 3px rgba(251, 191, 36, 0.3));
}

.book-rating span, 
.book-downloads span {
    color: var(--text-primary);
    font-weight: 600;
    letter-spacing: 0.5px;
    display: inline-block;
    font-size: 12px;
}

.book-downloads i {
    color: #60a5fa;
    font-size: 12px;
    filter: drop-shadow(0 0 3px rgba(96, 165, 250, 0.3));
}

/* Book Actions - Hidden by default, reveal on hover */
.book-actions {
    display: flex;
    justify-content: space-around;
    gap: 6px;
    margin-top: auto; /* Push to bottom */
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
    width: 100%;
    position: relative;
    min-height: 42px; /* Reserve space for buttons */
}

/* Actions hidden by default - show only on card hover */
.book-actions button,
.book-actions .btn-amazon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    position: relative;
    color: white;
    text-decoration: none;
    /* Hidden by default */
    opacity: 0;
    transform: translateY(10px) scale(0.8);
}

/* Staggered reveal animation on card hover */
.book-tile:hover .book-actions button,
.book-tile:hover .book-actions .btn-amazon {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Staggered delays for each button */
.book-tile:hover .book-actions button:nth-child(1),
.book-tile:hover .book-actions .btn-amazon:nth-child(1) { transition-delay: 0ms; }
.book-tile:hover .book-actions button:nth-child(2),
.book-tile:hover .book-actions .btn-amazon:nth-child(2) { transition-delay: 40ms; }
.book-tile:hover .book-actions button:nth-child(3),
.book-tile:hover .book-actions .btn-amazon:nth-child(3) { transition-delay: 80ms; }
.book-tile:hover .book-actions button:nth-child(4),
.book-tile:hover .book-actions .btn-amazon:nth-child(4) { transition-delay: 120ms; }
.book-tile:hover .book-actions button:nth-child(5),
.book-tile:hover .book-actions .btn-amazon:nth-child(5) { transition-delay: 160ms; }
.book-tile:hover .book-actions button:nth-child(6),
.book-tile:hover .book-actions .btn-amazon:nth-child(6) { transition-delay: 200ms; }

/* Placeholder hint when not hovered */
.book-actions::before {
    content: '• • •';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-muted);
    font-size: 18px;
    letter-spacing: 4px;
    opacity: 0.5;
    transition: opacity 0.2s ease;
}

/* Hide placeholder on hover */
.book-tile:hover .book-actions::before {
    opacity: 0;
}

.book-actions button:hover,
.book-actions .btn-amazon:hover {
    transform: translateY(-3px) scale(1.1);
}

/* Colored Glows on Hover */
.btn-quick-view:hover { box-shadow: 0 8px 20px rgba(79, 70, 229, 0.4); }
.btn-tile-download:hover { box-shadow: 0 8px 20px rgba(16, 185, 129, 0.4); }
.btn-amazon:hover { box-shadow: 0 8px 20px rgba(245, 158, 11, 0.4); }
.btn-rate:hover { box-shadow: 0 8px 20px rgba(144, 97, 249, 0.4); }
.btn-tile-favorite:hover { box-shadow: 0 8px 20px rgba(236, 72, 153, 0.4); }
.btn-preview-flip:hover { box-shadow: 0 8px 20px rgba(59, 130, 246, 0.4); }

.book-actions button i,
.book-actions .btn-amazon i {
    font-size: 14px;
}

/* Button Colors */
.btn-quick-view {
    background: linear-gradient(145deg, #4f46e5, #3b82f6);
}

.btn-preview-flip {
    background: linear-gradient(145deg, #3b82f6, #2563eb);
}

.btn-tile-download {
    background: linear-gradient(145deg, #10b981, #059669);
}

.btn-amazon {
    background: linear-gradient(145deg, #f59e0b, #d97706);
}

.btn-rate {
    background: linear-gradient(145deg, #9061f9, #6d28d9);
}

.btn-tile-favorite {
    background: linear-gradient(145deg, #ec4899, #be185d);
}

/* Active States */
.book-tile .btn-tile-favorite.favorited {
    background: linear-gradient(145deg, #be185d, #9d174d);
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.2);
}

.btn-tile-download.already-downloaded {
    background: linear-gradient(145deg, #20c997, #0ca678);
}

/* Tooltips */
.book-actions button::after,
.book-actions .btn-amazon::after {
    content: attr(aria-label);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    padding: 5px 10px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    font-size: 11px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    pointer-events: none;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.book-actions button:hover::after,
.book-actions .btn-amazon:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 40px 0;
    gap: 5px;
    flex-wrap: wrap;
    padding: 0 10px;
}

.pagination a,
.pagination span {
    min-width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 15px;
    font-size: 14px;
    font-weight: 500;
    border-radius: 8px;
    text-decoration: none;
    transition: all 0.2s ease;
    color: var(--text-primary);
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
}

.pagination a:hover {
    background: var(--accent-purple);
    color: white;
    transform: translateY(-1px);
}

.pagination .current {
    background: var(--accent-purple);
    color: white;
    font-weight: 600;
}

.pagination .disabled {
    opacity: 0.5;
    pointer-events: none;
    cursor: not-allowed;
}

/* ========================================
   Inline Rating Widget - Apple Style (Refined)
   ======================================== */
.inline-rating-widget {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    /* iOS Glassmorphism - theme aware */
    background: var(--glass-bg);
    backdrop-filter: blur(25px) saturate(180%);
    -webkit-backdrop-filter: blur(25px) saturate(180%);
    padding: 20px 16px 24px;
    border-radius: 16px 16px 12px 12px; /* Slightly more rounded top */
    border-top: 1px solid var(--border-color);
    box-shadow: 
        0 -10px 40px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 var(--border-color);
    transform: translateY(100%);
    opacity: 0;
    /* Spring animation for slide up */
    transition: 
        transform 0.5s cubic-bezier(0.19, 1, 0.22, 1),
        opacity 0.4s ease;
    z-index: 100;
    pointer-events: none;
}

.inline-rating-widget.active {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.inline-rating-widget .rating-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding: 0 4px;
}

.inline-rating-widget .rating-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.inline-rating-widget .rating-close {
    background: var(--glass-bg);
    border: none;
    color: var(--text-secondary);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
}

.inline-rating-widget .rating-close:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
    transform: scale(1.05);
}

.inline-rating-widget .star-row {
    display: flex;
    justify-content: center;
    gap: 12px; /* More spacing */
    margin-bottom: 8px;
}

.inline-rating-widget .inline-star {
    font-size: 32px; /* Larger stars */
    color: var(--text-tertiary);
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), color 0.2s ease;
    transform-origin: center;
    /* Subtle drop shadow for depth */
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.inline-rating-widget .inline-star:hover {
    transform: scale(1.15);
}

.inline-rating-widget .inline-star.hovered {
    color: #FFD60A;
    filter: drop-shadow(0 0 8px rgba(255, 214, 10, 0.4));
}

.inline-rating-widget .inline-star.selected {
    color: #FFD60A;
    filter: drop-shadow(0 0 6px rgba(255, 214, 10, 0.3));
}

.inline-rating-widget .inline-star.selected.animate {
    animation: starPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes starPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* Success State */
.inline-rating-widget .rating-success {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
}

.inline-rating-widget.success .star-row,
.inline-rating-widget.success .rating-header {
    display: none;
}

.inline-rating-widget.success .rating-success {
    display: flex;
    animation: successFadeIn 0.5s cubic-bezier(0.19, 1, 0.22, 1);
}

@keyframes successFadeIn {
    0% { opacity: 0; transform: scale(0.9) translateY(10px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

.inline-rating-widget .success-icon {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #34C759 0%, #30B350 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 22px;
    box-shadow: 0 8px 20px rgba(52, 199, 89, 0.3);
}

.inline-rating-widget .success-text {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

/* Loading State */
.inline-rating-widget.loading .star-row {
    opacity: 0.5;
    pointer-events: none;
    filter: grayscale(1);
}

.inline-rating-widget.loading .inline-star {
    animation: starPulse 1.5s ease-in-out infinite;
}

@keyframes starPulse {
    0%, 100% { opacity: 0.4; transform: scale(0.95); }
    50% { opacity: 1; transform: scale(1.05); }
}

/* Error State */
.inline-rating-widget .rating-error {
    display: none;
    text-align: center;
    padding: 10px;
    font-size: 13px;
    color: #FF453A; /* Apple Red */
    font-weight: 500;
    background: rgba(255, 69, 58, 0.1);
    border-radius: 8px;
    margin-top: 10px;
}

.inline-rating-widget.error .rating-error {
    display: block;
    animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}

/* Review Input Section */
.inline-rating-widget .review-input-section {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px;
    margin-top: 16px;
    max-height: 0;
    opacity: 0;
    overflow: visible; /* Allow button to render fully */
    pointer-events: none; /* Prevent blocking stars when collapsed */
    transition: 
        max-height 0.4s cubic-bezier(0.19, 1, 0.22, 1),
        opacity 0.3s ease,
        margin 0.3s ease;
}

.inline-rating-widget .review-hint {
    width: 100%;
    order: 1;
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: -6px;
    padding-left: 4px;
}

.inline-rating-widget.expanded .review-input-section {
    max-height: 180px;
    opacity: 1;
    pointer-events: auto; /* Re-enable interaction when expanded */
}

.inline-rating-widget .review-text {
    flex: 1;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 14px;
    line-height: 1.4;
    color: var(--text-primary);
    resize: none;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    transition: all 0.2s ease;
}

.inline-rating-widget .review-text::placeholder {
    color: var(--text-tertiary);
}

.inline-rating-widget .review-text:focus {
    outline: none;
    background: var(--input-bg);
    border-color: var(--accent-purple);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.3);
}

.inline-rating-widget .submit-review-btn {
    min-width: 44px;
    width: 44px;
    min-height: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    /* Apple Blue Gradient */
    background: linear-gradient(135deg, #0A84FF 0%, #007AFF 100%);
    color: white;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(10, 132, 255, 0.3);
}

.inline-rating-widget .submit-review-btn:disabled {
    background: var(--glass-bg);
    color: var(--text-tertiary);
    cursor: not-allowed;
    box-shadow: none;
    transform: scale(0.9);
}

.inline-rating-widget .submit-review-btn:not(:disabled):hover {
    transform: scale(1.1) translateY(-2px);
    box-shadow: 0 8px 20px rgba(10, 132, 255, 0.5);
}

.inline-rating-widget .submit-review-btn:not(:disabled):active {
    transform: scale(0.95);
}

.inline-rating-widget.success .review-input-section {
    display: none;
}

.inline-rating-widget.loading .review-input-section {
    opacity: 0.5;
    pointer-events: none;
}

/* Ensure book-tile has relative positioning for the widget */
.book-tile {
    position: relative;
    overflow: hidden;
}

/* Responsive */
@media (max-width: 768px) {
    .books-grid {
        grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
        gap: 20px;
    }
    
    .book-cover {
        height: 200px;
    }
    
    .book-info {
        padding: 12px;
    }
    
    .book-title {
        font-size: 15px;
    }
    
    .book-actions button,
    .book-actions .btn-amazon {
        width: 32px;
        height: 32px;
    }
}

@media (max-width: 576px) {
    .books-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 15px;
    }
    
    .book-cover {
        height: 180px;
    }
    
    .book-title {
        font-size: 14px;
        min-height: 36px;
    }
    
    .book-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .book-rating, .book-downloads {
        width: 100%;
        justify-content: center;
    }
    
    /* On mobile, always show action buttons since hover doesn't work */
    .book-actions button,
    .book-actions .btn-amazon {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    
    .book-actions::before {
        display: none;
    }
}
