/* =============================================================================
   My Reading Timeline - Consolidated Stylesheet
   ============================================================================= */

/* =============================================================================
   CSS Variables & Base Styles
   ============================================================================= */

:root {
    --color-primary: rgb(94, 142, 87);      /* Links and accents */
    --color-text: rgb(127, 108, 76);        /* Main text color */
    --color-background: rgb(254, 250, 224); /* Page background */
    --color-card-bg: rgb(250, 237, 205);    /* Card backgrounds */
    --color-white: white;
    --color-gray-light: #f0f0f0;
    --color-gray-medium: #666;
    --color-gray-dark: #333;
    --color-border: #eee;
    --color-border-light: #ddd;
    
    /* Status colors */
    --color-finished: #d4edda;
    --color-finished-text: #155724;
    --color-progress: #fff3cd;
    --color-progress-text: #856404;
    --color-tbr: #f8d7da;
    --color-tbr-text: #721c24;
    --color-dnf: #e2e3e5;
    --color-dnf-text: #6c757d;
    
    /* Layout */
    --max-width: 800px;
    --max-width-wide: 1200px;
    --border-radius: 8px;
    --border-radius-small: 4px;
    --shadow: 0 2px 4px rgba(0,0,0,0.1);
    --shadow-hover: 0 4px 8px rgba(0,0,0,0.15);
}

/* Fonts */
@font-face {
    font-family: 'Zilla Slab';
    src: url("/static/fonts/ZillaSlab-Regular.04e9982a8594.woff2") format('woff2'),
        url("/static/fonts/ZillaSlab-Regular.0dc149380f37.ttf") format('truetype');
    font-weight: 400;
}

/* Base Styles */
body {
    font-family: "Zilla Slab", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.6;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 20px;
    background: var(--color-background);
    color: var(--color-text);
}

/* Wide layout for specific pages */
body.first-paragraphs-page,
body.stats-page {
    max-width: var(--max-width-wide);
}

/* =============================================================================
   Typography & Links
   ============================================================================= */

h1, h2, h3, h4, h5, h6 {
    color: var(--color-text);
    margin-top: 0;
}

/* Universal link styles */
a {
    text-decoration: none;
    color: var(--color-primary);
    background-image: linear-gradient(currentColor, currentColor);
    background-position: 0% 100%;
    background-repeat: no-repeat;
    background-size: 0% 1px;
    transition: background-size 0.3s ease-in-out;
}

a:hover,
a:focus {
    background-size: 100% 1px;
}

/* Header links (no underline transition) */
.header h1 a {
    background-image: none;
    color: var(--color-primary);
}

.header h1 a:hover {
    background-size: 0%;
}

/* =============================================================================
   Layout Components
   ============================================================================= */

.header {
    text-align: center;
    margin-bottom: 40px;
    border-bottom: 2px solid var(--color-border);
    padding-bottom: 20px;
}

.header h1 {
    margin: 0;
}

.header p {
    margin: 10px 0 0 0;
    color: var(--color-text);
}

/* Navigation */
.nav {
    text-align: center;
    margin-bottom: 30px;
}

.nav a {
    margin: 0 15px;
    color: var(--color-primary);
    font-weight: 500;
    padding: 5px 10px;
}

.nav a.current {
    text-decoration: underline;
}

/* =============================================================================
   Cards & Containers
   ============================================================================= */

/* Base card styles */
.card {
    background: var(--color-card-bg);
    padding: 25px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 30px;
}

.card-accent {
    /* border-left: 4px solid var(--color-primary); */
}

.card-white {
    background: var(--color-white);
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

/* Specific card applications */
.stats,
.intro-section,
/* .tag-header, */
.popular-tags,
.author-header,
.read-detail,
.read-entry,
.author-entry,
.tag-card {
    background: var(--color-card-bg);
    padding: 25px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 30px;
}
.intro-section {
    width: 50%;
    margin: 30px auto;
    padding: 5px 25px;
    /* font-size: 1.2em; */
    text-align: center;
    font-weight: 800;
}

.read-entry,
.author-entry,
.tag-card {
    /* border-left: 4px solid var(--color-primary); */
}

.search-section {
    /* background: var(--color-white); */
}

/* =============================================================================
   Search Form
   ============================================================================= */

.search-form {
    text-align: center;
    margin-bottom: 30px;
}

.search-container {
    position: relative;
    display: inline-block;
    width: 100%;
    max-width: 500px;
}

.search-form input[type="text"] {
    width: 100%;
    padding: 16px 80px 16px 20px;
    border: 2px solid #e0e0e0;
    border-radius: 50px;
    font-size: 1em;
    outline: none;
    transition: all 0.3s ease;
    background: var(--color-white);
    box-shadow: var(--shadow);
    box-sizing: border-box;
}

.search-form input[type="text"]:focus {
    border-color: var(--color-primary);
    box-shadow: 0 2px 12px rgba(94, 142, 87, 0.15);
}

.search-form input[type="text"]::placeholder {
    color: #999;
    font-size: 0.95em;
}

.search-form button {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    padding: 12px 20px;
    background: var(--color-primary);
    color: var(--color-white);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(94, 142, 87, 0.3);
}

.search-form button:hover {
    background: rgb(84, 132, 77);
    box-shadow: 0 3px 8px rgba(94, 142, 87, 0.4);
    transform: translateY(-50%) translateY(-1px);
}

/* =============================================================================
   Read Entry Components
   ============================================================================= */

.read-meta {
    font-size: 0.9em;
    color: var(--color-text);
    margin-bottom: 10px;
}

.read-title {
    font-size: 1.3em;
    font-weight: bold;
    margin-bottom: 5px;
}

.read-title a {
    color: var(--color-primary);
}

.read-subtitle {
    font-style: italic;
    color: var(--color-text);
    margin-bottom: 10px;
}

.publisher-info {
    font-size: .7em;
    color: var(--color-gray-medium);
    margin: 0;
}

.read-authors {
    margin-bottom: 10px;
    color: var(--color-text);
}

.read-notes {
    margin-top: 15px;
    font-style: italic;
    color: var(--color-text);
    border-left: 3px solid var(--color-border);
    padding-left: 15px;
}

/* =============================================================================
   Tags
   ============================================================================= */

.read-tags {
    margin-top: 15px;
}

.tag {
    display: inline-block;
    background: var(--color-gray-light);
    color: var(--color-gray-medium);
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.8em;
    margin-right: 5px;
    text-decoration: none;
    transition: all 0.3s ease;
    background-image: none;
}

.tag:hover {
    background: var(--color-primary);
    color: var(--color-white);
    background-size: 0%;
}

.tag.current-tag {
    background: var(--color-primary);
    color: var(--color-white);
}

/* Tag cloud sizing */
.tag-cloud .tag {
    padding: 8px 16px;
    border-radius: 20px;
    margin: 5px;
    border: 2px solid transparent;
}

.tag-cloud .tag:hover {
    transform: scale(1.05);
    border-color: var(--color-primary);
}

.tag-size-1 { font-size: 0.8em; }
.tag-size-2 { font-size: 0.9em; }
.tag-size-3 { font-size: 1.0em; }
.tag-size-4 { font-size: 1.1em; font-weight: bold; }
.tag-size-5 { font-size: 1.3em; font-weight: bold; }

/* =============================================================================
   Status Indicators
   ============================================================================= */

.status-indicator {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.8em;
    font-weight: bold;
    text-transform: uppercase;
}

.status-finished { 
    background: var(--color-finished); 
    color: var(--color-finished-text); 
}

.status-in_progress { 
    background: var(--color-progress); 
    color: var(--color-progress-text); 
}

.status-tbr { 
    background: var(--color-tbr); 
    color: var(--color-tbr-text); 
}

.status-dnf { 
    background: var(--color-dnf); 
    color: var(--color-dnf-text); 
}

/* =============================================================================
   Images
   ============================================================================= */

.cover-image {
    float: right;
    margin-left: 20px;
    margin-bottom: 10px;
    max-width: 80px;
    border-radius: var(--border-radius-small);
    box-shadow: var(--shadow);
}

/* Author page images */
.author-image {
    max-width: 150px;
    max-height: 200px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-hover);
}

/* Detail page covers */
.cover-section .cover-image {
    max-width: 200px;
    max-height: 300px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-hover);
    float: none;
    margin: 0;
}

/* First paragraphs book covers */
.book-cover {
    max-width: 80px;
    max-height: 120px;
    border-radius: var(--border-radius-small);
    box-shadow: var(--shadow);
}

/* =============================================================================
   Edit Links
   ============================================================================= */

.edit-link {
    display: inline-block;
    background: #f8f9fa;
    color: #6c757d;
    padding: 3px 8px;
    border-radius: var(--border-radius-small);
    font-size: 0.75em;
    border: 1px solid #dee2e6;
    margin-left: 8px;
    transition: all 0.2s ease;
    background-image: none;
}

.edit-link:hover {
    background: var(--color-primary);
    color: var(--color-white);
    border-color: var(--color-primary);
    background-size: 0%;
}

/* =============================================================================
   Pagination
   ============================================================================= */

.pagination {
    text-align: center;
    margin: 40px 0;
}

.pagination a, 
.pagination .current {
    display: inline-block;
    padding: 8px 16px;
    margin: 0 4px;
    border: 1px solid var(--color-border-light);
    color: var(--color-primary);
    background-image: none;
}

.pagination .current {
    background: var(--color-primary);
    color: var(--color-white);
}

/* =============================================================================
   Back Links
   ============================================================================= */

.back-link {
    text-align: center;
    margin: 30px 0;
}

.back-link a {
    color: var(--color-primary);
    font-weight: bold;
}

/* =============================================================================
   Author Pages
   ============================================================================= */

/* Condensed Authors List Page */
.authors-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.author-card {
    background: var(--color-card-bg);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 15px;
    align-items: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.author-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.author-card .author-image {
    max-width: 80px;
    max-height: 80px;
    border-radius: var(--border-radius-small);
    box-shadow: var(--shadow);
}

.author-card .author-info {
    min-width: 0;
}

.author-name-link {
    font-size: 1.3em;
    font-weight: bold;
    color: var(--color-primary);
}

.author-name-link:hover {
    color: var(--color-primary);
}

/* Single column layout for smaller cards */
.author-card.no-image {
    grid-template-columns: 1fr;
    text-align: center;
}

/* Individual Author Detail Page */
.author-header {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 30px;
    align-items: start;
}

.author-image-section {
    text-align: center;
}

.author-info {
    min-width: 0;
}

.author-name {
    font-size: 2.2em;
    font-weight: bold;
    margin-bottom: 10px;
    color: var(--color-text);
}

.author-dates {
    font-size: 1.1em;
    color: var(--color-text);
    margin-bottom: 15px;
}

.author-stats {
    background: #f0f8ff;
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 20px;
    border-left: 4px solid var(--color-primary);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 15px;
}

.stat-item {
    text-align: center;
}

.stat-number {
    font-size: 1.5em;
    font-weight: bold;
    color: var(--color-primary);
    display: block;
}

.stat-label {
    font-size: 0.9em;
    color: var(--color-gray-medium);
    text-transform: uppercase;
}

.author-bio {
    color: var(--color-text);
    /* font-style: italic; */
    line-height: 1.7;
}

/* =============================================================================
   Read Detail Page
   ============================================================================= */

.cover-section {
    text-align: center;
    margin-bottom: 30px;
}

.image-caption {
    font-size: 0.9em;
    color: var(--color-gray-medium);
    font-style: italic;
    margin-top: 10px;
}

.title-section {
    text-align: center;
    margin-bottom: 30px;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 20px;
}

.title {
    font-size: 2em;
    font-weight: bold;
    margin-bottom: 10px;
    color: var(--color-gray-dark);
}

.subtitle {
    font-size: 1.2em;
    font-style: italic;
    color: var(--color-gray-medium);
    margin-bottom: 15px;
}

.authors {
    font-size: 1.1em;
    margin-bottom: 10px;
}

.status-date {
    font-weight: bold;
    color: #555;
}

.details-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

.detail-section {
    background: var(--color-card-bg);
    padding: 20px;
    border-radius: 6px;
}

.detail-section h3 {
    color: var(--color-gray-dark);
    border-bottom: 2px solid var(--color-primary);
    padding-bottom: 5px;
}

.detail-item {
    margin-bottom: 10px;
}

.detail-label {
    font-weight: bold;
    color: var(--color-gray-medium);
    display: inline-block;
    min-width: 100px;
}

.content-section h3 {
    color: var(--color-gray-dark);
    border-bottom: 2px solid var(--color-primary);
    padding-bottom: 5px;
}

.first-paragraph {
    background: var(--color-card-bg);
    padding: 20px;
    border-left: 4px solid var(--color-primary);
    /* font-style: italic; */
    margin-bottom: 20px;
}

.notes {
    background: var(--color-card-bg);
    padding: 20px;
    border: 1px solid #e0e0e0;
    border-radius: var(--border-radius-small);
}

.tags-section {
    margin: 30px 0;
    text-align: center;
}

.tags-section .tag {
    padding: 6px 12px;
    border-radius: 15px;
    font-size: 0.9em;
    margin: 5px;
}

/* =============================================================================
   Search Page
   ============================================================================= */

.search-results-header {
    text-align: center;
    margin-bottom: 20px;
}

.search-query {
    font-weight: bold;
    color: var(--color-primary);
    font-size: 1.1em;
}

.search-stats {
    color: var(--color-gray-medium);
    font-size: 0.9em;
    margin-top: 5px;
}

.no-results {
    text-align: center;
    color: var(--color-gray-medium);
    font-style: italic;
    margin: 40px 0;
}

.search-suggestions {
    background: var(--color-card-bg);
    padding: 20px;
    border-radius: 6px;
    margin-top: 20px;
}

.search-suggestions h4 {
    margin-top: 0;
    color: var(--color-gray-dark);
}

.search-suggestions ul {
    margin: 10px 0;
    padding-left: 20px;
}

.search-suggestions li {
    margin-bottom: 5px;
}

/* =============================================================================
   Statistics Page
   ============================================================================= */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 25px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--color-card-bg);
    padding: 25px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    border-left: 4px solid var(--color-primary);
}

.stat-card h3 {
    color: var(--color-gray-dark);
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 10px;
    font-size: 1.2em;
}

.big-number {
    font-size: 2.5em;
    font-weight: bold;
    color: var(--color-primary);
    text-align: center;
    margin: 20px 0;
}

.stat-breakdown {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-top: 15px;
}

.progress-bar {
    background: #e0e0e0;
    border-radius: 10px;
    height: 8px;
    margin: 5px 0;
    overflow: hidden;
}

.progress-fill {
    background: linear-gradient(90deg, var(--color-primary), #0099d4);
    height: 100%;
    border-radius: 10px;
    transition: width 0.3s ease;
}

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

.top-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px dotted var(--color-border-light);
}

.top-list li:last-child {
    border-bottom: none;
}

.top-list .name {
    font-weight: 500;
    color: var(--color-gray-dark);
}

.top-list .count {
    font-weight: bold;
    color: var(--color-primary);
    background: #f0f8ff;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.9em;
}

.type-chart {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 15px;
}

.type-item {
    background: #f0f8ff;
    border: 2px solid var(--color-primary);
    border-radius: 6px;
    padding: 10px 15px;
    text-align: center;
    flex: 1;
    min-width: 100px;
}

.type-item .type-name {
    font-weight: bold;
    color: var(--color-primary);
    font-size: 0.9em;
    text-transform: uppercase;
}

.type-item .type-count {
    font-size: 1.3em;
    font-weight: bold;
    color: var(--color-gray-dark);
}

.summary-card {
    background: linear-gradient(135deg, var(--color-primary) 0%, #0099d4 100%);
    color: var(--color-white);
    grid-column: 1 / -1;
    text-align: center;
}

.summary-card h3 {
    color: var(--color-white);
    border-bottom-color: rgba(255,255,255,0.3);
}

.summary-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.summary-stat {
    text-align: center;
}

.summary-number {
    font-size: 2em;
    font-weight: bold;
}

.summary-label {
    font-size: 0.9em;
    opacity: 0.9;
    text-transform: uppercase;
}

/* =============================================================================
   Tags Pages
   ============================================================================= */

.tags-intro {
    text-align: center;
}

.tags-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.tag-name {
    /* font-size: 1.3em; */
    /* font-weight: bold; */
    /* margin-bottom: 8px; */
    /* display: flex; */
    /* align-items: center; */
    /* justify-content: space-between; */
    text-align: center;
}

.tag-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid var(--color-border-light);
}

.tag-description {
    color: var(--color-gray-medium);
    font-style: italic;
    margin-bottom: 10px;
    font-size: 0.9em;
}

.tag-count {
    color: var(--color-primary);
    font-weight: bold;
    font-size: 0.9em;
}

.tag-visual {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 15px;
    font-size: 0.8em;
    margin-top: 10px;
    background: var(--color-gray-light);
    color: var(--color-gray-medium);
}

.popular-tags h3 {
    color: var(--color-text);
    text-align: center;
    border-bottom: 2px solid var(--color-primary);
    padding-bottom: 10px;
}

.tag-cloud {
    text-align: center;
}

.tag-header {
    margin: 25px auto;
    background-color: var(--color-card-bg);
    padding: 5px 25px;
    border-radius: 20px;
    width: 50%;
}

.tag-description {
    color: var(--color-gray-medium);
    font-style: italic;
    /* margin-bottom: 15px; */
}

.tag-stats {
    color: #888;
    font-size: 0.9em;
}

/* =============================================================================
   First Paragraphs Page
   ============================================================================= */

/* =============================================================================
   Masonry Layout for First Paragraphs Page - Add to main.css
   ============================================================================= */

/* Replace the existing .books-grid styles with this: */
.books-grid {
    /* Modern CSS Grid Masonry (supported in Firefox, coming to other browsers) */
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(500px, 1fr));
    grid-template-rows: masonry; /* This creates the masonry effect */
    gap: 30px;
    margin-bottom: 30px;
    
    /* Fallback for browsers that don't support masonry yet */
    /* Will be overridden by JavaScript if masonry isn't supported */
}

/* Enhanced responsive behavior */
@media (max-width: 1200px) {
    .books-grid {
        grid-template-columns: repeat(auto-fill, minmax(450px, 1fr));
    }
}

@media (max-width: 768px) {
    .books-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}

@media (max-width: 600px) {
    .books-grid {
        gap: 15px;
    }
}

/* =============================================================================
   JavaScript Masonry Fallback Styles
   ============================================================================= */

/* When JavaScript masonry is active, we use flexbox columns */
.books-grid.js-masonry {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 30px;
}

.books-grid.js-masonry .masonry-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 30px;
}

/* Ensure cards in JS masonry mode take full width of their column */
.books-grid.js-masonry .book-card {
    width: 100%;
    margin-bottom: 0; /* Remove margin since we're using gap */
}

/* =============================================================================
   Performance Optimizations
   ============================================================================= */

/* Optimize for layout shifts during masonry arrangement */
.book-card {
    /* Prevent layout shift during JavaScript masonry initialization */
    contain: layout style paint;
    
    /* Ensure consistent spacing */
    margin-bottom: 0;
    
    /* Improve rendering performance */
    will-change: transform;
    transform: translateZ(0);
}

/* Loading state to prevent flash of unstyled content */
.books-grid:not(.masonry-ready) {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.books-grid.masonry-ready {
    opacity: 1;
}

.book-card {
    background: var(--color-card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    /* border-left: 4px solid var(--color-primary); */
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

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

.book-content {
    display: grid;
    gap: 20px;
    padding: 25px;
    align-items: start;
}

.book-content.has-image {
    grid-template-columns: auto 1fr;
}

.book-content.no-image {
    grid-template-columns: 1fr;
}

.book-info {
    min-width: 0;
}

.book-header {
    margin-bottom: 15px;
}

.book-title {
    font-size: 1.2em;
    font-weight: bold;
    margin-bottom: 5px;
    display: inline;
}

.book-title:hover {
    color: var(--color-primary);
}

.book-author {
    color: var(--color-gray-medium);
    font-size: 1em;
    display: inline;
}

.book-excerpt {
    color: var(--color-text);
    /* font-style: italic; */
    line-height: 1.7;
    /* border-left: 3px solid var(--color-primary); */
    padding-left: 15px;
    margin-top: 15px;
}

/* =============================================================================
   TBR Page
   ============================================================================= */

.empty-state {
    text-align: center;
    color: var(--color-gray-medium);
    font-style: italic;
    margin: 60px 0;
}

.empty-state h3 {
    color: var(--color-gray-dark);
    margin-bottom: 15px;
}

/* =============================================================================
   Optimized Image Display
   ============================================================================= */

/* Ensure images load smoothly */
.cover-image,
.author-image,
.book-cover {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: optimize-contrast;
    image-rendering: crisp-edges;
    transition: opacity 0.3s ease;
}

/* Loading state for images */
.cover-image[src=""],
.author-image[src=""],
.book-cover[src=""] {
    opacity: 0;
}

/* Loaded state */
.cover-image,
.author-image,
.book-cover {
    opacity: 1;
}

/* WebP fallback handling */
.no-webp .cover-image,
.no-webp .author-image,
.no-webp .book-cover {
    /* Fallback styles if WebP isn't supported (rare these days) */
}

/* Admin image preview styles */
.current-image {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 6px;
    border: 1px solid #dee2e6;
    margin-bottom: 10px;
}

.current-image img {
    display: block;
    margin-bottom: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Image optimization indicators in admin */
.optimization-status {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.8em;
    font-weight: bold;
}

.optimization-status.optimized {
    background: #d4edda;
    color: #155724;
}

.optimization-status.pending {
    background: #fff3cd;
    color: #856404;
}

/* Progressive loading enhancement */
.image-container {
    position: relative;
    overflow: hidden;
}

.image-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    z-index: 1;
}

.image-container img {
    position: relative;
    z-index: 2;
}

.image-container img[src]:not([src=""]) + ::before {
    display: none;
}

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

/* Performance optimizations */
.cover-image,
.author-image,
.book-cover {
    will-change: transform;
    transform: translateZ(0); /* Force hardware acceleration */
}

/* =============================================================================
   Responsive Design
   ============================================================================= */

@media (max-width: 768px) {
    body { 
        padding: 10px; 
    }
    
    .author-header { 
        grid-template-columns: 1fr; 
        text-align: center;
        gap: 20px;
    }
    
    .stat-grid { 
        grid-template-columns: repeat(2, 1fr); 
    }
    
    .details-grid { 
        grid-template-columns: 1fr; 
        gap: 20px; 
    }
    
    .stats-grid { 
        grid-template-columns: 1fr; 
    }
    
    .stat-breakdown { 
        grid-template-columns: 1fr; 
    }
    
    .summary-stats { 
        grid-template-columns: repeat(2, 1fr); 
    }
    
    .book-content.has-image {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    /* Center the cover image container */
    .book-cover-section {
        text-align: center;
    }

    /* Remove the left padding on excerpt in mobile to align with title */
    .book-content.has-image .book-excerpt {
        padding-left: 0;
        text-align: left;
    }

    .cover-image {
        max-width: 60px; /* Slightly smaller on mobile for better layout */
    }
    
    .author-card .author-image {
        max-width: 60px;
        max-height: 60px;
    }
    
    .title { 
        font-size: 1.5em; 
    }
    
    /* Authors page responsive */
    .authors-grid {
        grid-template-columns: 1fr;
    }
    
    .author-card {
        grid-template-columns: auto 1fr;
        gap: 12px;
    }
}

@media (max-width: 600px) {
    .cover-image { 
        float: none; 
        display: block; 
        margin: 0 auto 15px; 
    }

    .search-container {
        max-width: 100%;
    }
    
    .search-form input[type="text"] { 
        padding-right: 90px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .books-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .tags-grid { 
        grid-template-columns: 1fr; 
    }
    
    /* Authors page mobile */
    .author-card {
        grid-template-columns: 1fr;
        text-align: center;
        gap: 10px;
    }
    
    .author-card .author-image {
        justify-self: center;
    }
}

/* Retina display optimization hints */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .cover-image,
    .author-image,
    .book-cover {
        /* Images are already optimized for 2x display */
        image-rendering: -webkit-optimize-contrast;
    }
}