/* 
Truyen.Web - Main Stylesheet
Mobile-First Responsive Design
Eye Protection Mode Support
*/

/* CSS Variables for Theming */
:root {
    /* Light Theme (Default) */
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --bg-card: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --accent: #4CAF50;
    --accent-hover: #45a049;
    --border: #e0e0e0;
    --shadow: rgba(0,0,0,0.1);
    
    /* Reading Font */
    --font-family: 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-size-base: 16px;
    --line-height: 1.6;
    --content-width: 800px;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-card: #2d2d2d;
    --text-primary: #e0e0e0;
    --text-secondary: #c0c0c0;
    --border: #404040;
    --shadow: rgba(0,0,0,0.3);
}

/* Eye Protection (Sepia) */
[data-theme="sepia"] {
    --bg-primary: #f4ecd8;
    --bg-secondary: #ebe0c9;
    --bg-card: #f4ecd8;
    --text-primary: #5b4636;
    --text-secondary: #7a6548;
}

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

html {
    font-size: var(--font-size-base);
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: var(--line-height);
    min-height: 100vh;
    transition: background 0.3s, color 0.3s;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px;
}

/* Header */
.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    gap: 16px;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    text-decoration: none;
    white-space: nowrap;
}

.nav {
    display: flex;
    gap: 16px;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 8px 12px;
    border-radius: 8px;
    transition: background 0.2s;
}

.nav-link:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.lang-select, .theme-btn {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
}

.theme-btn {
    font-size: 1.2rem;
}

/* Main Content */
.main {
    min-height: calc(100vh - 200px);
    padding: 24px 0;
}

/* Story Cards Grid */
.stories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
}

@media (min-width: 768px) {
    .stories-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 24px;
    }
}

.story-card {
    background: var(--bg-card);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
    text-decoration: none;
    color: inherit;
}

.story-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 16px var(--shadow);
}

.story-cover {
    width: 100%;
    aspect-ratio: 3/4;
    object-fit: cover;
    background: var(--bg-secondary);
}

.story-info {
    padding: 12px;
}

.story-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.story-genre {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.story-stats {
    display: flex;
    gap: 12px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 8px;
}

/* Chapter Reading Page */
.reading-container {
    max-width: var(--content-width);
    margin: 0 auto;
    padding: 16px;
}

.reading-header {
    text-align: center;
    margin-bottom: 24px;
}

.reading-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.reading-meta {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.reading-content {
    font-size: var(--font-size-base);
    line-height: 1.8;
    text-align: justify;
}

.reading-content p {
    margin-bottom: 16px;
}

/* Reading Settings Panel */
.reading-settings {
    position: fixed;
    bottom: 80px;
    right: 16px;
    background: var(--bg-card);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 4px 20px var(--shadow);
    width: 280px;
    display: none;
}

.reading-settings.active {
    display: block;
}

.setting-group {
    margin-bottom: 16px;
}

.setting-label {
    display: block;
    font-size: 0.9rem;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.setting-control {
    width: 100%;
}

/* Chapter Navigation */
.chapter-nav {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-top: 32px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.chapter-nav a {
    flex: 1;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: 8px;
    text-align: center;
    text-decoration: none;
    color: var(--text-primary);
    transition: background 0.2s;
}

.chapter-nav a:hover {
    background: var(--accent);
    color: white;
}

/* Comment Section */
.comments-section {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.comment-form {
    margin-bottom: 24px;
}

.comment-input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
    resize: vertical;
    min-height: 100px;
    margin-bottom: 12px;
}

.comment-meta {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.comment-meta input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
}

.rating-input {
    display: flex;
    gap: 4px;
}

.star {
    font-size: 1.5rem;
    cursor: pointer;
    color: #ddd;
}

.star.active {
    color: #ffc107;
}

.btn {
    padding: 12px 24px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.2s;
}

.btn:hover {
    background: var(--accent-hover);
}

.btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Comment List */
.comment-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.comment-item {
    background: var(--bg-secondary);
    padding: 16px;
    border-radius: 12px;
}

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

.comment-user {
    font-weight: 600;
}

.comment-rating {
    color: #ffc107;
}

.comment-date {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.comment-content {
    line-height: 1.6;
}

/* Donation Section */
.donation-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    margin-top: 24px;
}

.donation-card {
    background: var(--bg-secondary);
    padding: 24px;
    border-radius: 12px;
    text-align: center;
}

.donation-card h3 {
    margin-bottom: 16px;
}

.qr-code {
    max-width: 200px;
    margin: 16px auto;
    display: block;
}

/* Footer */
.footer {
    background: var(--bg-secondary);
    padding: 48px 0 24px;
    margin-top: 48px;
}

.footer-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 32px;
    margin-bottom: 24px;
}

.footer-section h3 {
    margin-bottom: 16px;
}

.footer-section ul {
    list-style: none;
}

.footer-section a {
    color: var(--text-secondary);
    text-decoration: none;
    display: block;
    padding: 4px 0;
}

.footer-section a:hover {
    color: var(--accent);
}

.footer-bottom {
    text-align: center;
    padding-top: 24px;
    border-top: 1px solid var(--border);
    color: var(--text-secondary);
}

/* Loading & States */
.loading {
    display: flex;
    justify-content: center;
    padding: 48px;
}

.loading::after {
    content: '';
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Responsive Adjustments */
@media (max-width: 768px) {
    .header-content {
        flex-wrap: wrap;
    }
    
    .nav {
        order: 3;
        width: 100%;
        justify-content: center;
        padding-top: 8px;
        border-top: 1px solid var(--border);
        margin-top: 8px;
    }
    
    .stories-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .reading-content {
        font-size: 1.1rem;
    }
    
    .chapter-nav {
        flex-direction: column;
    }
}
