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

/* Prevent horizontal scroll on mobile - CRITICAL */
html {
    overflow-x: hidden;
    width: 100%;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}

body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100%;
    position: relative;
}

/* Wrapper to prevent overflow */
html, body, main, .container, header, footer {
    max-width: 100vw;
}

:root {
    --bg-color: #f5f5f5;
    --text-color: #333;
    --card-bg: white;
    --header-bg: #2c3e50;
    --font-size: 18px;
    --line-height: 1.9;
    --font-family: 'Georgia', 'Times New Roman', serif;
    --primary: #1a1a2e;
    --accent: #0f3460;
    --accent-light: #e94560;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border: #e5e7eb;
    --nav-height: 60px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    background: var(--bg-color);
    color: var(--text-color);
    transition: background 0.3s ease, color 0.3s ease;
}

/* Theme variations */
html.theme-dark, body.theme-dark {
    --bg-color: #1a1a2e;
    --text-color: #e0e0e0;
    --card-bg: #16213e;
    --header-bg: #0f0f1a;
}

html.theme-sepia, body.theme-sepia {
    --bg-color: #f4ecd8;
    --text-color: #5c4b37;
    --card-bg: #faf6eb;
    --header-bg: #8b7355;
}

html.theme-green, body.theme-green {
    --bg-color: #e8f5e9;
    --text-color: #2e4a2e;
    --card-bg: #f1f8f1;
    --header-bg: #4a6741;
}

/* Immersive reading mode - header not sticky, nav hidden */
body.immersive-mode header {
    position: relative !important; /* Not sticky - stays at top of page */
}

/* On mobile, hide nav in immersive mode */
@media (max-width: 768px) {
    body.immersive-mode .chapter-nav-fixed {
        transform: translateY(100%);
        opacity: 0;
        pointer-events: none;
    }
}

/* On desktop, always show nav (ignore immersive mode for nav) */
@media (min-width: 769px) {
    body.immersive-mode .chapter-nav-fixed {
        transform: translateX(-50%);
        opacity: 1;
        pointer-events: auto;
    }
}

body.immersive-mode .floating-toolbar {
    opacity: 0;
    pointer-events: none;
}

body.immersive-mode .chapter-breadcrumb {
    display: none;
}

body.immersive-mode .chapter-nav-top {
    display: none;
}

body.immersive-mode main.container {
    padding-bottom: 20px;
}

/* Immersive mode settings button - draggable on mobile */
.immersive-settings-btn {
    display: none;
    position: fixed;
    left: 8px;
    bottom: 30%;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--header-bg, #2c3e50);
    color: white;
    border: none;
    font-size: 18px;
    cursor: grab;
    z-index: 1001;
    opacity: 0.7;
    transition: opacity 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.immersive-settings-btn:active {
    cursor: grabbing;
}

.immersive-settings-btn.dragging {
    opacity: 1;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    transition: none;
}

/* Only show immersive settings button on mobile */
@media (max-width: 768px) {
    body.immersive-mode .immersive-settings-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 15px;
    overflow-x: hidden;
    width: 100%;
}

/* Header */
header {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: white;
    padding: 0;
    margin-bottom: 15px;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 20px rgba(0,0,0,0.15);
    overflow: visible;
}

header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    overflow: visible;
}

header a {
    color: white;
    text-decoration: none;
}

/* Logo */
.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: white;
}

.logo-icon {
    font-size: 1.5rem;
}

.logo-text {
    font-size: 1.4rem;
    font-weight: 700;
    background: linear-gradient(135deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Main Navigation */
.main-nav {
    display: flex;
    align-items: center;
    gap: 5px;
    justify-content: center;
}

.nav-link {
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    background: none;
    border: none;
    cursor: pointer;
}

.nav-link:hover {
    color: white;
    background: rgba(255,255,255,0.1);
}

/* Dropdown Menu */
.nav-dropdown {
    position: relative;
}

.dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
}

.dropdown-arrow {
    font-size: 10px;
    transition: transform 0.2s;
}

.nav-dropdown:hover .dropdown-arrow {
    transform: rotate(180deg);
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    min-width: 180px;
    padding: 8px 0;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.2s;
    z-index: 1000;
}

.nav-dropdown:hover .dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-menu a {
    display: block;
    padding: 10px 16px;
    color: #333;
    font-size: 13px;
    transition: all 0.2s;
}

.dropdown-menu a:hover {
    background: #f5f5f5;
    color: #667eea;
    padding-left: 20px;
}

/* Header Right */
.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-toggle,
.icon-btn {
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.search-toggle:hover,
.icon-btn:hover {
    background: rgba(255,255,255,0.2);
    transform: scale(1.05);
}

.user-link {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    transition: all 0.2s;
}

.user-link.login {
    background: linear-gradient(135deg, #667eea, #764ba2);
    font-weight: 500;
}

.user-link.login:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.user-link.logout {
    opacity: 0.8;
}

.user-link.logout:hover {
    opacity: 1;
}

.mobile-menu-toggle {
    display: none;
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 20px;
}

/* Header Search */
.header-search {
    display: none;
    background: rgba(0,0,0,0.3);
    padding: 15px 0;
}

.header-search.show {
    display: block;
}

.header-search-form {
    display: flex;
    gap: 10px;
    align-items: center;
}

.header-search-input {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: 25px;
    font-size: 14px;
    background: white;
}

.header-search-input:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3);
}

.header-search-btn {
    padding: 12px 25px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 25px;
    font-weight: 600;
    cursor: pointer;
}

.header-search-close {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
}

/* Mobile Menu */
.mobile-menu {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100vh;
    background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
    z-index: 2000;
    transition: left 0.3s ease;
    overflow-y: auto;
}

.mobile-menu.show {
    left: 0;
}

.mobile-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.mobile-menu-overlay.show {
    opacity: 1;
    visibility: visible;
}

.mobile-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.mobile-menu-title {
    font-size: 18px;
    font-weight: 600;
    color: white;
}

.mobile-menu-close {
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
}

.mobile-nav {
    padding: 15px;
}

.mobile-nav > a {
    display: block;
    padding: 12px 15px;
    color: white;
    text-decoration: none;
    font-size: 15px;
    border-radius: 8px;
    transition: all 0.2s;
}

.mobile-nav > a:hover {
    background: rgba(255,255,255,0.1);
}

.mobile-nav-section {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.mobile-nav-title {
    display: block;
    padding: 8px 15px;
    color: rgba(255,255,255,0.5);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.mobile-nav-section a {
    display: block;
    padding: 10px 15px 10px 25px;
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    font-size: 14px;
    transition: all 0.2s;
}

.mobile-nav-section a:hover {
    color: white;
    background: rgba(255,255,255,0.05);
}

/* Responsive Header */
@media (max-width: 992px) {
    .main-nav {
        display: none;
    }

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

    .user-link.login,
    .user-link.logout {
        display: none;
    }
}

@media (max-width: 600px) {
    .logo-text {
        font-size: 1.2rem;
    }

    .search-toggle {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }

    .icon-btn {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    overflow-x: hidden;
    max-width: 100%;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 10px 16px;
    background: var(--header-bg);
    color: white;
    text-decoration: none;
    border-radius: 5px;
    transition: all 0.2s;
    border: none;
    cursor: pointer;
    font-size: 14px;
    text-align: center;
}

.btn:hover {
    opacity: 0.9;
}

.btn-primary { background: #3498db; }
.btn-success { background: #27ae60; }
.btn-warning { background: #f39c12; }
.btn-danger { background: #e74c3c; }
.btn-secondary { background: #95a5a6; }

.btn-outline {
    background: transparent;
    border: 2px solid var(--header-bg);
    color: var(--text-color);
}

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

.btn-sm {
    padding: 6px 10px;
    font-size: 12px;
}

.btn:disabled, .btn.disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* Story Grid */
.story-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}

.story-card {
    background: var(--card-bg);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    transition: all 0.3s;
}

.story-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

.story-card a {
    text-decoration: none;
    color: inherit;
    display: block;
}

.story-cover {
    width: 100%;
    height: 250px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 3rem;
    font-weight: bold;
    position: relative;
    overflow: hidden;
}

.story-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.story-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    padding: 4px 10px;
    border-radius: 15px;
    font-size: 11px;
    font-weight: 600;
    color: white;
    z-index: 2;
}

.badge-hot { background: linear-gradient(135deg, #ff6b6b, #ee5a5a); }
.badge-translated { background: linear-gradient(135deg, #339af0, #228be6); }

.story-info {
    padding: 15px;
}

.story-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-color);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.story-author {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 10px;
}

.story-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
}

.story-chapters {
    background: #d4edda;
    color: #155724;
    padding: 3px 10px;
    border-radius: 15px;
    font-weight: 600;
}

.story-views {
    color: #666;
}

/* Chapter List */
.chapter-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    max-height: 60vh;
    overflow-y: auto;
}

.chapter-link {
    padding: 8px 12px;
    background: var(--bg-color);
    border-radius: 5px;
    text-decoration: none;
    color: var(--text-color);
    transition: all 0.2s;
    font-size: 0.9rem;
    display: block;
}

.chapter-link:hover {
    opacity: 0.8;
}

.chapter-link.reading-now {
    background: linear-gradient(135deg, #27ae60, #2ecc71);
    color: white;
    position: relative;
    box-shadow: 0 2px 8px rgba(39, 174, 96, 0.4);
}

.chapter-link.reading-now.flash {
    animation: flashHighlight 1.5s ease-out;
}

@keyframes flashHighlight {
    0% { transform: scale(1.05); box-shadow: 0 0 20px rgba(39, 174, 96, 0.8); }
    100% { transform: scale(1); box-shadow: 0 2px 8px rgba(39, 174, 96, 0.4); }
}

.chapter-link.reading-now-old {
    background: #27ae60;
    color: white;
}

.chapter-link.translated::before {
    content: '✓ ';
    color: #10b981;
}

.reading-badge {
    display: inline-block;
    font-size: 9px;
    background: white;
    color: #27ae60;
    padding: 2px 4px;
    border-radius: 3px;
    margin-left: 5px;
    font-weight: bold;
}

/* Chapter Content */
.chapter-content {
    font-family: var(--font-family);
    font-size: var(--font-size);
    line-height: var(--line-height);
    text-align: justify;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
}

.chapter-content p {
    margin-bottom: 1em;
    text-indent: 2em;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.chapter-title {
    text-align: center;
    margin-bottom: 20px;
    font-size: 1.1rem;
}

.chapter-card {
    margin-bottom: 0;
}

/* Floating Toolbar (desktop) */
.floating-toolbar {
    position: fixed;
    top: 70px;
    right: 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 99;
    transition: opacity 0.3s ease;
}

.floating-toolbar .btn {
    background: var(--card-bg);
    color: var(--text-color);
    border: 1px solid rgba(0,0,0,0.1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Chapter Navigation - Top (Desktop) */
.chapter-nav {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin: 15px 0;
    flex-wrap: wrap;
}

.chapter-nav-top {
    margin-bottom: 15px;
}

/* Fixed Bottom Navigation - Always visible on chapter pages */
.chapter-nav-fixed {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card-bg);
    padding: 8px 10px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    z-index: 100;
    justify-content: center;
    align-items: center;
    gap: 15px;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Desktop: center the nav with max-width */
@media (min-width: 769px) {
    .chapter-nav-fixed {
        left: 50%;
        transform: translateX(-50%);
        max-width: 600px;
        border-radius: 12px 12px 0 0;
        padding: 10px 20px;
    }

    .chapter-nav-fixed .nav-btn {
        flex-direction: row;
        gap: 6px;
        padding: 10px 16px;
    }

    .chapter-nav-fixed .nav-text {
        font-size: 13px;
    }

    /* Add padding for fixed nav on desktop chapter pages */
    body.chapter-page main.container {
        padding-bottom: 80px;
    }
}

.chapter-nav-fixed .nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 12px;
    background: none;
    border: none;
    color: var(--text-color);
    text-decoration: none;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
    min-width: 60px;
}

.chapter-nav-fixed .nav-btn:active {
    background: var(--bg-color);
}

.chapter-nav-fixed .nav-btn.disabled {
    opacity: 0.3;
    pointer-events: none;
}

.chapter-nav-fixed .nav-icon {
    font-size: 20px;
}

.chapter-nav-fixed .nav-text {
    font-size: 11px;
    white-space: nowrap;
}

.chapter-nav-fixed .nav-label {
    display: none;
    font-size: 12px;
}

/* Show labels on desktop */
@media (min-width: 769px) {
    .chapter-nav-fixed .nav-label {
        display: inline;
    }

    .chapter-nav-fixed .nav-icon {
        font-size: 16px;
    }
}

/* Next Chapter Hint / Swipe indicator */
.next-chapter-hint {
    padding: 30px 20px;
    text-align: center;
    opacity: 0.5;
    transition: opacity 0.3s ease;
}

.next-chapter-hint.active {
    opacity: 1;
}

.next-chapter-hint .hint-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--text-color);
    font-size: 14px;
}

.next-chapter-hint .hint-arrow {
    font-size: 24px;
    animation: bounce 1s infinite;
}

.next-chapter-hint.navigating .hint-arrow {
    animation: none;
}

.next-chapter-hint .end-story {
    font-size: 16px;
}

.hint-progress {
    width: 150px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 10px auto 0;
    overflow: hidden;
}

.hint-progress-bar {
    height: 100%;
    background: var(--success);
    width: 0%;
    transition: width 0.1s ease;
    border-radius: 2px;
}

.next-chapter-hint.navigating .hint-progress-bar {
    background: var(--accent-light);
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(5px); }
}

/* Breadcrumb */
.breadcrumb {
    margin-bottom: 12px;
    font-size: 0.85rem;
}

.breadcrumb a {
    color: var(--text-color);
    opacity: 0.7;
}

/* Headings */
h2 {
    margin-bottom: 12px;
    color: var(--text-color);
    font-size: 1.2rem;
}

/* Utilities */
.text-center { text-align: center; }
.text-muted { opacity: 0.7; }

/* Settings Modal */
.settings-modal, .chapter-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.settings-modal.show, .chapter-modal.show {
    display: flex;
}

.settings-modal-content, .chapter-modal-content {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    max-width: 95%;
    width: 400px;
    max-height: 90vh;
    overflow-y: auto;
}

.chapter-modal-content {
    width: 600px;
    display: flex;
    flex-direction: column;
}

.settings-modal-header, .chapter-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(0,0,0,0.1);
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-color);
}

.settings-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 15px;
}

.settings-label {
    font-weight: 500;
    font-size: 13px;
}

.settings-options {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.setting-btn {
    padding: 6px 10px;
    border: 1px solid var(--header-bg);
    background: transparent;
    color: var(--text-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.setting-btn:hover, .setting-btn.active {
    background: var(--header-bg);
    color: white;
}

.theme-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid #ccc;
    cursor: pointer;
}

.theme-btn.active {
    border-color: #333;
    box-shadow: 0 0 0 2px rgba(0,0,0,0.2);
}

.theme-btn-light { background: #f5f5f5; }
.theme-btn-dark { background: #1a1a2e; }
.theme-btn-sepia { background: #f4ecd8; }
.theme-btn-green { background: #e8f5e9; }

/* Toggle Switch */
.toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
}

.toggle-switch {
    position: relative;
    width: 50px;
    height: 26px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.3s;
    border-radius: 26px;
}

.toggle-slider:before {
    position: absolute;
    content: ;
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--success);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(24px);
}

.chapter-search {
    padding: 10px 0;
}

.chapter-search input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    background: var(--bg-color);
    color: var(--text-color);
}

.chapter-modal-body {
    flex: 1;
    overflow-y: auto;
    max-height: 60vh;
}

/* Save Message Toast */
.save-message {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    opacity: 0;
    transform: scale(0.9);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: none;
}

.save-message.show {
    opacity: 1;
    transform: scale(1);
}

.save-message.success {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.save-message.error {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

.settings-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(0,0,0,0.1);
}

/* Stats Banner */
.stats-banner {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin-bottom: 20px;
}

.stat-item {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.stat-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 0.8rem;
    color: #666;
    text-transform: uppercase;
}

/* Sidebar */
.main-content {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 20px;
}

.sidebar-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 15px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.sidebar-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--accent-light);
}

.ranking-list {
    list-style: none;
}

.ranking-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: all 0.2s;
}

.ranking-item:hover {
    background: var(--bg-color);
}

.ranking-number {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
    background: var(--bg-color);
}

.ranking-number.top-1 { background: linear-gradient(135deg, #FFD700, #FFA500); color: white; }
.ranking-number.top-2 { background: linear-gradient(135deg, #C0C0C0, #A0A0A0); color: white; }
.ranking-number.top-3 { background: linear-gradient(135deg, #CD7F32, #A0522D); color: white; }

.ranking-info {
    flex: 1;
    min-width: 0;
}

.ranking-title {
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ranking-stats {
    font-size: 11px;
    color: #666;
    display: flex;
    gap: 10px;
}

/* Progress Bar */
.progress-bar-container {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #11998e, #38ef7d);
    transition: width 0.3s;
}

/* Form Styles */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

.form-group input, .form-group textarea, .form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    background: var(--bg-color);
    color: var(--text-color);
}

.form-group textarea {
    min-height: 100px;
    resize: vertical;
}

/* Alert */
.alert {
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
}

.alert-warning { background: #fff3cd; color: #856404; }
.alert-success { background: #d4edda; color: #155724; }
.alert-danger { background: #f8d7da; color: #721c24; }
.alert-info { background: #d1ecf1; color: #0c5460; }

/* Responsive */
@media (max-width: 768px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .stats-banner {
        grid-template-columns: repeat(2, 1fr);
    }

    .story-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .story-cover {
        height: 180px;
    }

    .chapter-list {
        grid-template-columns: 1fr;
    }

    /* Hide floating toolbar on mobile */
    .floating-toolbar {
        display: none;
    }

    /* Hide top nav on mobile (use fixed bottom nav instead) */
    .chapter-nav-top {
        display: none;
    }

    /* Padding for fixed bottom nav */
    main.container {
        padding-bottom: calc(var(--nav-height) + 20px);
    }

    /* Chapter content on mobile */
    .chapter-card {
        border-radius: 0;
        margin-left: -10px;
        margin-right: -10px;
        padding: 10px;
        width: calc(100% + 20px);
        max-width: calc(100% + 20px);
    }

    .chapter-modal-content {
        width: 95%;
        max-height: 80vh;
    }

    /* CRITICAL: Prevent horizontal scroll on mobile */
    html, body {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
        position: relative !important;
    }

    /* Prevent any element from causing overflow */
    img, video, iframe, table, pre, code {
        max-width: 100% !important;
    }

    /* Force container width */
    .container, main, header, footer, .card {
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }
}

@media (max-width: 600px) {
    .main-nav {
        display: none;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 10px;
    }

    header h1 {
        font-size: 1.1rem;
    }

    .stats-banner {
        gap: 10px;
    }

    .stat-item {
        padding: 12px;
    }

    .stat-value {
        font-size: 1.2rem;
    }

    .chapter-nav-fixed .nav-btn {
        padding: 6px 8px;
        min-width: 50px;
    }

    .chapter-nav-fixed .nav-icon {
        font-size: 18px;
    }

    .chapter-nav-fixed .nav-text {
        font-size: 10px;
    }
}

/* Safe area for notched phones */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .chapter-nav-fixed {
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
    
    main.container {
        padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 20px);
    }
}

/* ==================== Footer Styles ==================== */
.site-footer {
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    margin-top: 40px;
    padding: 30px 0 20px;
}

.footer-grid {
    display: grid;
    grid-template-columns: 1.5fr 1fr 1fr;
    gap: 30px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

.footer-col h2 {
    font-size: 1.3rem;
    color: var(--primary-color);
    margin-bottom: 10px;
}

.footer-col > p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
}

.footer-col h4 {
    font-size: 1rem;
    color: var(--text-color);
    margin-bottom: 12px;
    font-weight: 600;
}

.footer-col ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.footer-col ul li {
    margin-bottom: 8px;
}

.footer-col ul li a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.footer-col ul li a:hover {
    color: var(--primary-color);
}

.footer-bottom {
    max-width: 1200px;
    margin: 20px auto 0;
    padding: 15px 20px 0;
    border-top: 1px solid var(--border-color);
    text-align: center;
}

.footer-bottom p {
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin: 5px 0;
}

.footer-bottom small {
    color: var(--text-secondary);
    opacity: 0.7;
    font-size: 0.75rem;
}

/* Footer responsive - tablet */
@media (max-width: 768px) {
    .site-footer {
        margin-top: 20px;
        padding: 20px 0 15px;
    }

    .footer-grid {
        grid-template-columns: 1fr 1fr;
        gap: 20px;
        padding: 0 15px;
    }

    .footer-grid .footer-col:first-child {
        grid-column: 1 / -1;
        text-align: center;
    }

    .footer-col {
        text-align: center;
    }
}

/* Footer responsive - mobile minimal */
@media (max-width: 480px) {
    .site-footer {
        margin-top: 15px;
        padding: 15px 0 10px;
    }

    .footer-grid {
        grid-template-columns: 1fr;
        gap: 15px;
        padding: 0 10px;
    }

    .footer-col h2 {
        font-size: 1.1rem;
    }

    .footer-col > p {
        font-size: 0.8rem;
    }

    /* Hide thể loại và liên kết columns on mobile */
    .footer-grid .footer-col:nth-child(2),
    .footer-grid .footer-col:nth-child(3) {
        display: none;
    }

    .footer-bottom {
        padding: 10px 10px 0;
        margin-top: 10px;
    }

    .footer-bottom p {
        font-size: 0.75rem;
    }

    .footer-bottom small {
        font-size: 0.7rem;
    }
}

/* Hide footer on chapter page mobile for better reading */
@media (max-width: 768px) {
    body.chapter-page .site-footer {
        display: none;
    }
}

/* Ensure footer doesn't overlap with fixed nav */
body:has(.chapter-nav-fixed) .site-footer {
    display: none !important;
    margin-bottom: calc(var(--nav-height) + 20px);
}

@media (max-width: 768px) {
    body:has(.chapter-nav-fixed) .site-footer {
    display: none !important;
        margin-bottom: 0;
    }
}

/* ==================== Logo Styles ==================== */
.logo-link {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

.site-icon {
    height: 32px !important;
    width: 32px !important;
    max-width: 32px !important;
    object-fit: contain;
}

.logo-text {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* Mobile - smaller icon, no text */
@media (max-width: 768px) {
    .logo-text {
        display: none !important;
    }
    
    .site-icon {
        height: 28px !important;
        width: 28px !important;
        max-width: 28px !important;
    }
}

@media (max-width: 480px) {
    .site-icon {
        height: 24px !important;
        width: 24px !important;
        max-width: 24px !important;
    }
}

/* Hide footer on chapter reading page */
body.chapter-page .site-footer {
    display: none !important;
}

/* ==================== */
/* Chapter Modal - Enhanced */
/* ==================== */

/* Override reading-now style */
.chapter-link.reading-now {
    background: linear-gradient(135deg, #27ae60, #2ecc71) !important;
    color: white !important;
    position: relative;
    box-shadow: 0 2px 8px rgba(39, 174, 96, 0.4);
    font-weight: 600;
}

/* Flash animation when opening modal */
.chapter-link.reading-now.flash {
    animation: flashHighlight 1.5s ease-out;
}

@keyframes flashHighlight {
    0% { 
        transform: scale(1.05); 
        box-shadow: 0 0 25px rgba(39, 174, 96, 0.9);
    }
    50% {
        box-shadow: 0 0 15px rgba(39, 174, 96, 0.6);
    }
    100% { 
        transform: scale(1); 
        box-shadow: 0 2px 8px rgba(39, 174, 96, 0.4);
    }
}

/* Chapter translated indicator */
.chapter-translated {
    color: #10b981;
    margin-right: 4px;
    font-weight: bold;
}

.chapter-link.reading-now .chapter-translated {
    color: rgba(255,255,255,0.9);
}

/* Reading badge improvement */
.reading-badge {
    display: inline-block;
    font-size: 10px;
    background: rgba(255,255,255,0.95);
    color: #27ae60;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 8px;
    font-weight: bold;
    white-space: nowrap;
}

.read-badge {
    display: inline-block;
    font-size: 10px;
    background: rgba(200,200,200,0.5);
    color: #888;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 8px;
    font-weight: normal;
    white-space: nowrap;
}

/* Read chapter styling in modal */
.chapter-link.chapter-read {
    opacity: 0.6;
    text-decoration: line-through;
    color: #999;
}

.chapter-link.chapter-read:hover {
    opacity: 0.8;
}

/* Chapter search box */
.chapter-search {
    margin-bottom: 12px;
}

.chapter-search input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s;
}

.chapter-search input:focus {
    outline: none;
    border-color: #27ae60;
}

/* Chapter modal body scrollable */
.chapter-modal-body {
    flex: 1;
    overflow-y: auto;
    max-height: 65vh;
    padding-right: 5px;
}

/* Custom scrollbar for chapter list */
.chapter-modal-body::-webkit-scrollbar {
    width: 6px;
}

.chapter-modal-body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.chapter-modal-body::-webkit-scrollbar-thumb {
    background: #27ae60;
    border-radius: 3px;
}

.chapter-modal-body::-webkit-scrollbar-thumb:hover {
    background: #219a52;
}

/* Chapter title text ellipsis */
.chapter-title-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Chapter link layout */
.chapter-link {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Theme dark adjustments */
.theme-dark .chapter-search input {
    background: #2d2d2d;
    border-color: #444;
    color: #fff;
}

.theme-dark .chapter-search input:focus {
    border-color: #27ae60;
}

.theme-sepia .chapter-search input {
    background: #f4ecd8;
    border-color: #d4c4a8;
}
