:root {
    --primary: #8B4513; /* SaddleBrown */
    --primary-light: #D2691E;
    --background: #FDFBF7; /* Warm paper */
    --foreground: #2C1810; /* Dark brown text */
    --muted: #8D7B68;
    --border: #E6DCC8;
    --card-bg: #FFFFFF;
    --font-serif: 'Playfair Display', serif;
    --font-sans: 'Lato', sans-serif;
    --font-quote: 'Libre Baskerville', serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    background-color: var(--background);
    color: var(--foreground);
    line-height: 1.6;
}

.paper-texture {
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23noise)' opacity='0.05'/%3E%3C/svg%3E");
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.main-header {
    padding: 20px 0;
    border-bottom: 1px solid var(--border);
    background: rgba(253, 251, 247, 0.9);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(5px);
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Logo Styles */
.logo-img {
    margin-right: 15px;
    border-radius: 4px;
}

.logo-text-container {
    display: flex;
    flex-direction: column;
}

.logo-title {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    line-height: 1;
    color: var(--foreground);
}

.logo-subtitle {
    font-size: 0.75rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

@media (max-width: 768px) {
    .logo-subtitle {
        display: none;
    }
}

.btn {
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-family: var(--font-sans);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
}

.btn-outline:hover {
    background: var(--primary);
    color: white;
}

/* Hero */
.hero-section {
    text-align: center;
    padding: 60px 0 40px;
}

.author-badge {
    background: rgba(139, 69, 19, 0.1);
    color: var(--primary);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
}

.main-title {
    font-family: var(--font-serif);
    font-size: 3.5rem;
    margin: 20px 0;
    line-height: 1.2;
}

.main-title .highlight {
    color: var(--primary);
    font-style: italic;
}

.hero-description {
    max-width: 600px;
    margin: 0 auto;
    color: var(--muted);
    font-size: 1.1rem;
}

/* Search */
.search-container {
    max-width: 600px;
    margin: 0 auto 40px;
}

.search-wrapper {
    position: relative;
}

.search-icon {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
}

#searchInput {
    width: 100%;
    padding: 15px 15px 15px 45px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    background: white;
    transition: border-color 0.2s;
}

#searchInput:focus {
    outline: none;
    border-color: var(--primary);
}

/* Part Selector */
.part-selector {
    display: flex;
    justify-content: center;
    margin-bottom: 40px;
}

.selector-bg {
    background: #F0EAE0;
    padding: 5px;
    border-radius: 8px;
    display: inline-flex;
}

.part-btn {
    padding: 10px 20px;
    text-decoration: none;
    color: var(--muted);
    border-radius: 6px;
    font-weight: 600;
    transition: all 0.2s;
}

.part-btn.active {
    background: white;
    color: var(--primary);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

/* Grid */
.chapters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 25px;
    margin-bottom: 60px;
}

.chapter-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 25px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
}

.chapter-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.05);
    border-color: var(--primary-light);
}

.card-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
}

.chapter-number {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--muted);
    font-weight: 700;
}

.chapter-title {
    font-family: var(--font-serif);
    font-size: 1.4rem;
    margin-bottom: 15px;
    line-height: 1.3;
}

.chapter-preview {
    color: var(--muted);
    font-size: 0.95rem;
    margin-bottom: 20px;
    flex-grow: 1;
}

.card-footer {
    border-top: 1px solid #F0F0F0;
    padding-top: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.read-more {
    color: var(--primary);
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 5px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    backdrop-filter: blur(3px);
}

.modal-content {
    background-color: #FDFBF7;
    margin: 2% auto;
    padding: 0;
    border-radius: 12px;
    width: 90%;
    max-width: 800px;
    height: 90dvh; /* Dynamic viewport height for mobile */
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.close-modal {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 28px;
    font-weight: bold;
    color: var(--muted);
    background: none;
    border: none;
    cursor: pointer;
    z-index: 10;
}

.close-modal:hover {
    color: var(--foreground);
}

#modalBody {
    overflow-y: auto;
    padding: 40px;
    flex: 1;
}

/* Modal Content Styles */
.modal-header {
    margin-bottom: 30px;
    padding-right: 30px;
}

.modal-chapter-num {
    color: var(--primary);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: block;
    margin-bottom: 10px;
}

.modal-title {
    font-family: var(--font-serif);
    font-size: 2.5rem;
    line-height: 1.1;
}

.modal-section {
    margin-bottom: 30px;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--primary);
}

.section-title::before {
    content: '';
    display: block;
    width: 4px;
    height: 20px;
    background: var(--primary);
    border-radius: 2px;
}

.summary-text {
    font-size: 1.1rem;
    line-height: 1.8;
    color: #4A4A4A;
}

.summary-text::first-letter {
    font-family: var(--font-serif);
    font-size: 3.5rem;
    float: left;
    line-height: 0.8;
    margin-right: 10px;
    color: var(--primary);
}

.character-card {
    background: #F5F0E6;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 10px;
}

.character-name {
    font-weight: 700;
    display: block;
    margin-bottom: 5px;
}

.quote-block {
    font-family: var(--font-quote);
    font-style: italic;
    font-size: 1.2rem;
    color: var(--foreground);
    border-left: 4px solid var(--primary);
    padding-left: 20px;
    margin: 20px 0;
}

/* Audio Controls */
.audio-controls {
    background: #F0EAE0;
    padding: 15px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 30px;
}

.audio-btn {
    background: var(--primary);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.audio-btn:hover {
    background: var(--primary-light);
}

/* Dropdown */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    background-color: #f9f9f9;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
    border-radius: 8px;
    overflow: hidden;
}

.dropdown-content a {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    font-size: 0.9rem;
}

.dropdown-content a:hover {background-color: #f1f1f1}

.dropdown:hover .dropdown-content {display: block;}

/* Mobile */
@media (max-width: 768px) {
    .main-title { font-size: 2.5rem; }
    .modal-content { width: 100%; height: 100dvh; margin: 0; border-radius: 0; }
    #modalBody { padding: 20px; padding-bottom: 80px; }
    .close-modal { top: 15px; right: 15px; }
}

/* Voice Selector Buttons */
.voice-selector-simple {
    display: flex;
    gap: 5px;
    margin-top: 5px;
}

.voice-btn {
    background: #e0e0e0;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.voice-btn:hover {
    background: #d0d0d0;
}

.voice-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
