/* Global Box Sizing Reset */
*,
*:before,
*:after {
    box-sizing: border-box;
}

:root {
    --primary-color: #6a11cb;
    --secondary-color: #2575fc;
    --text-color: #333;
    --bg-color: #f8f9fa;
    /* Slightly lighter for cleaner look */
    --card-bg: #ffffff;
    --nav-bg: #ffffff;
    --border-radius: 12px;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    /* Softer shadow */
    --font-heading: 'Merriweather', serif;
    --font-body: 'Inter', sans-serif;
    --nav-logo: brightness(0) saturate(100%) invert(0%) sepia(0%) saturate(0%) hue-rotate(48deg) brightness(93%) contrast(105%);
}

/* Dark Mode Variables */
html.dark-mode {
    --text-color: #e0e0e0;
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --nav-bg: #1e1e1e;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    --nav-logo: brightness(0) saturate(100%) invert(100%) sepia(10%) saturate(581%) hue-rotate(295deg) brightness(116%) contrast(100%);
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Push footer directly */
body>.container,
body>.auth-container {
    flex: 1;
    width: 100%;
    /* Ensure full width for flex children */
}

/* Allow story-content to expand if it's the direct child (rare) */
.story-content {
    flex: 1;
}

/* --- Footer --- */
.site-footer {
    background-color: var(--card-bg);
    /* Match header/card style or use separate color */
    border-top: 1px solid var(--border-color);
    padding: 2rem 0;
    margin-top: auto;
    /* Double insurance for flex */
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Navigation */
nav {
    background-color: var(--nav-bg);
    padding: 1rem 2rem;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
    transition: background-color 0.3s;
}

nav .logo {
    font-size: 1.5rem;
    font-weight: bold;
    background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-decoration: none;
}

nav .nav-logo {
    filter: var(--nav-logo);
    height: 7vh;
    max-height: 60px;
    min-height: 40px;
    transition: filter 0.3s ease-in-out;
}

nav ul {
    list-style: none;
    display: flex;
    align-items: center;
    /* Align items vertically */
    gap: 1.5rem;
    margin: 0;
    padding: 0;
}

nav a {
    text-decoration: none;
    color: var(--text-color);
    font-weight: 500;
    transition: color 0.3s;
}

nav a:hover {
    color: var(--primary-color);
}

/* Theme Toggle Button */
.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.3s;
}

.btn-icon:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

html.dark-mode .btn-icon:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Show/Hide Icons based on mode */
.icon-sun {
    display: none;
}

.icon-moon {
    display: inline;
}

html.dark-mode .icon-sun {
    display: inline;
}

html.dark-mode .icon-moon {
    display: none;
}


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

/* Auth Forms */
.auth-container {
    max-width: 400px;
    margin: 4rem auto;
    padding: 2rem;
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.form-group {
    margin-bottom: 1.5rem;
}

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

.form-group input:not([type="checkbox"]):not([type="radio"]),
.form-group select,
.form-group textarea,
select,
textarea {
    width: 100%;
    padding: 0.8rem 1rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    background-color: var(--card-bg);
    color: var(--text-color);
    box-sizing: border-box;
    font-size: 1rem;
    transition: border-color 0.3s, box-shadow 0.3s;
    font-family: var(--font-family);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(106, 17, 203, 0.1);
}

/* Custom Select Styling */
select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23333%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 0.8rem auto;
    padding-right: 2.5rem;
    /* Space for arrow */
    cursor: pointer;
    min-width: 150px;
    /* Prevent skinny dropdowns */
}

/* Fix for Dark Mode Arrow */
html.dark-mode select {
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23e0e0e0%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
}

/* Button Fixes */
.btn-primary,
.btn-danger {
    display: inline-block;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    width: auto;
    min-width: 120px;
    text-align: center;
    transition: transform 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
    padding: 0.6rem 1.5rem;
}

.btn-danger {
    background: linear-gradient(to right, #e53935, #c62828);
    padding: 0.8rem 1.5rem;
}

.btn-primary:hover,
.btn-danger:hover {
    transform: translateY(-2px);
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.alert.error {
    background-color: #ffebee;
    color: #c62828;
}

.alert.success {
    background-color: #e8f5e9;
    color: #2e7d32;
}

/* Grid Layouts */
.genre-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    transition: transform 0.3s, background-color 0.3s;
    text-decoration: none;
    color: var(--text-color);
    display: block;
}

.card:hover {
    transform: translateY(-5px);
}

.card.no-hover:hover {
    transform: none;
    box-shadow: var(--shadow);
    /* Keep original shadow, don't increase it */
}

.card h3 {
    margin-top: 0;
    color: var(--primary-color);
    transition: color 0.3s;
}

/* Genre Card Specifics */
.genre-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1rem 0.5rem;
    position: relative;
    overflow: hidden;
    border: 1px solid transparent;
}

.genre-card:hover {
    border-color: var(--primary-color);
}

.genre-card h3 {
    font-size: 1.1rem;
    margin-bottom: 0.3rem;
}

.genre-count {
    font-size: 0.8rem;
    color: #888;
    background: rgba(0, 0, 0, 0.05);
    padding: 0.1rem 0.6rem;
    border-radius: 20px;
    transition: background 0.3s, color 0.3s;
}

.genre-card:hover .genre-count {
    background: var(--primary-color);
    color: white;
}

html.dark-mode .genre-count {
    background: rgba(255, 255, 255, 0.1);
}

/* Tabs */
.tab-container {
    margin-bottom: 1rem;
    border-bottom: 1px solid #ddd;
}

.tab-btn {
    background: none;
    border: none;
    padding: 1rem;
    cursor: pointer;
    font-size: 1rem;
    border-bottom: 2px solid transparent;
    color: var(--text-color);
    /* Fix for Dark Mode */
    transition: color 0.3s, border-bottom-color 0.3s;
}

.tab-btn:hover {
    color: var(--primary-color);
}

.tab-btn.active {
    border-bottom-color: var(--primary-color);
    color: var(--primary-color);
    font-weight: bold;
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease-in-out;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

#editor {
    height: 300px;
    background: white;
    /* Keep editor white for readability */
    color: #333;
    /* Force black text inside editor */
}

/* Story Content Readability */
.story-content {
    color: var(--text-color);
    line-height: 1.8;
    font-size: 1.1rem;
}

.story-content * {
    color: var(--text-color) !important;
}

/* Ensure headings inside cards/content are visible */
h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-color);
}



/* Social Actions */
.social-bar {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin: 1rem 0;
}

.heart-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #ccc;
    transition: color 0.2s;
}

.heart-btn.active {
    color: #e91e63;
}

.stars {
    display: inline-flex;
    gap: 0.2rem;
    cursor: pointer;
}

.star {
    font-size: 1.5rem;
    color: #ccc;
}

.star.active {
    color: #ffc107;
}

.comment-box {
    margin-top: 2rem;
    border-top: 1px solid #eee;
    padding-top: 1rem;
}

/* Honeypot */
.website-field {
    display: none;
}

/* Home Page Specifics */
.home-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.hero-header {
    text-align: center;
    margin-bottom: 4rem;
    padding: 3rem 1rem;
    background: linear-gradient(135deg, rgba(106, 17, 203, 0.05), rgba(37, 117, 252, 0.05));
    border-radius: var(--border-radius);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

html.dark-mode .hero-header {
    background: linear-gradient(135deg, rgba(106, 17, 203, 0.1), rgba(37, 117, 252, 0.1));
    border-color: rgba(255, 255, 255, 0.05);
}

.hero-header h1 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hero-header p {
    font-size: 1.2rem;
    color: var(--text-color);
    opacity: 0.8;
    max-width: 600px;
    margin: 0 auto 1.5rem auto;
}

/* Genre Sections */
.genres-section {
    margin-bottom: 4rem;
}

.genre-category {
    margin-bottom: 3rem;
}

.category-title {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid rgba(0, 0, 0, 0.1);
    color: var(--text-color);
    display: inline-block;
}

html.dark-mode .category-title {
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

/* Genre Card Updates */
.genre-grid {
    gap: 1rem;
    /* tighter gap for cleaner look */
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    /* slightly smaller cards */
}

.genre-card {
    padding: 1.2rem 1rem;
}

.genre-card h3 {
    font-size: 1rem;
}

/* Featured Stories */
.featured-section {
    margin-top: 4rem;
}

.section-subtitle {
    font-size: 1.1rem;
    color: var(--text-color);
    opacity: 0.7;
    margin-bottom: 2rem;
}

.featured-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
}

.featured-card {
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: transform 0.3s, box-shadow 0.3s;
    border: 1px solid transparent;
}

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

.featured-content {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.featured-content h3 {
    font-size: 1.3rem;
    margin-bottom: 0.5rem;
    color: var(--text-color);
    font-weight: 700;
}

.featured-content .meta {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 1rem;
    display: flex;
    gap: 1rem;
    align-items: center;
}

.featured-content .genre-tag {
    background: rgba(106, 17, 203, 0.1);
    color: var(--primary-color);
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}

.featured-content .summary {
    font-size: 1rem;
    color: var(--text-color);
    opacity: 0.9;
    flex-grow: 1;
}

html.dark-mode .featured-content .meta {
    color: #aaa;
}

.stats-row {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 0.8rem;
    font-size: 0.95rem;
    font-weight: 500;
}

.rating-display {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    color: #fbc02d;
    /* Gold */
}

.rating-display .stars-icon {
    font-size: 1.1rem;
}

.comment-display {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: #666;
}

html.dark-mode .comment-display {
    color: #999;
}

/* Collapsible Genres */
.category-title {
    cursor: pointer;
    display: flex;
    /* Changed from inline-block to flex for alignment */
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.category-title .chevron {
    font-size: 0.8em;
    transition: transform 0.3s ease;
    margin-left: 1rem;
    opacity: 0.5;
}

.genre-category.expanded .category-title .chevron {
    transform: rotate(180deg);
}

.genre-grid-wrapper {
    display: none;
    /* Collapsed by default */
    padding-top: 1rem;
    animation: slideDown 0.3s ease-out;
}

.genre-category.expanded .genre-grid-wrapper {
    display: block;
    /* Show when expanded */
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

.dropdown-content {
    display: none;
    position: absolute;
    background-color: var(--card-bg);
    min-width: 160px;
    box-shadow: var(--shadow);
    border-radius: 8px;
    z-index: 1001;
    top: 100%;
    left: 0;
    padding: 0.5rem 0;
}

@media (min-width: 769px) {
    .dropdown:hover .dropdown-content {
        display: block;
    }
}

.dropdown-content a {
    color: var(--text-color);
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    transition: background-color 0.3s;
}

.dropdown-content a:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--primary-color);
}

html.dark-mode .dropdown-content a:hover {
    background-color: rgba(255, 255, 255, 0.05);
}


/* Safety Ratings */
.safety-tag {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: bold;
    color: white;
    background-color: #666;
    margin-right: 0.5rem;
}

.safety-G {
    background-color: #4caf50;
}

/* Green */
.safety-T {
    background-color: #ff9800;
}

/* Orange */
.safety-M {
    background-color: #f44336;
}

/* Red */
.safety-E {
    background-color: #d32f2f;
    border: 1px solid #b71c1c;
}

/* Dark Red */

/* Search Bar */
.search-item {
    margin-left: auto;
    margin-right: 1rem;
}

.search-form {
    display: flex;
    align-items: center;
    background: var(--bg-color);
    border-radius: 20px;
    padding: 2px 10px;
    border: 1px solid #ddd;
}

html.dark-mode .search-form {
    border-color: #444;
}

.search-form input {
    border: none;
    background: transparent;
    padding: 5px;
    outline: none;
    color: var(--text-color);
    font-size: 0.9rem;
    width: 200px;
}

.search-form button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
}

/* Comment Section Improvements */
.comment-item {
    border-bottom: 1px solid #eee;
    padding: 1rem 0;
    display: flex;
    gap: 1rem;
}

html.dark-mode .comment-box {
    border-top-color: #333;
}

html.dark-mode .comment-item {
    border-bottom-color: #333;
}

html.dark-mode .form-group input:not([type="checkbox"]):not([type="radio"]),
html.dark-mode .form-group select,
html.dark-mode .form-group textarea,
html.dark-mode select,
html.dark-mode textarea {
    background-color: #252525;
    border-color: #444;
    color: #e0e0e0;
}

/* =========================================
   HOME PAGE REDESIGN
   ========================================= */

/* Atmospheric Intro */
.atmospheric-intro {
    text-align: center;
    padding: 4rem 1rem;
    max-width: 800px;
    margin: 0 auto;
}

.atmospheric-intro h1 {
    font-family: var(--font-heading);
    font-size: 2.5rem;
    margin-bottom: 1.5rem;
    color: var(--text-color);
    font-weight: 700;
}

.atmospheric-intro p {
    font-size: 1.2rem;
    line-height: 1.8;
    color: var(--text-color);
    opacity: 0.8;
    font-style: italic;
    font-family: var(--font-heading);
}

.intro-divider {
    width: 60px;
    height: 3px;
    background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
    margin: 2rem auto;
    border-radius: 2px;
}

/* Grid Layout (Wrapping) */
.category-row {
    margin-bottom: 3rem;
}

.category-header {
    margin-bottom: 1.5rem;
    padding-left: 0.5rem;
    border-left: 4px solid var(--primary-color);
}

.category-header h2 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    margin: 0;
    padding-left: 0.5rem;
    color: var(--text-color);
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 2rem;
    padding: 0.5rem;
}

/* Minimalist Paper Cards */
.vibrant-card {
    /* Keeping class name to minimize PHP churn, but restyling */
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 180px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    /* Sharper corners for paper feel */
    text-decoration: none;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    padding: 1.5rem;
}

/* Book Spine Effect on Left */
.vibrant-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 6px;
    background: var(--primary-color);
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
    opacity: 0.7;
}

.vibrant-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.08);
    border-color: #ccc;
}

html.dark-mode .vibrant-card {
    background: #1e1e1e;
    border-color: #333;
}

.card-info {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
    /* Add internal padding if background differs */
    padding: 1rem;
    border-radius: 6px;
}

.card-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-color);
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

.card-meta {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 1rem;
    font-style: italic;
    font-family: var(--font-heading);
}

.stats-row {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px dashed #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

html.dark-mode .stats-row {
    border-top-color: #333;
}

/* Hide unused elements from previous design if referenced styles persist */
.card-cover {
    display: none;
}

.scroll-btn {
    display: none;
}

.scroll-wrapper {
    display: block;
}

.scroll-container {
    display: contents;
}

/* Fallback if structure remains */

/* Compact Grid for Genres */
.compact-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
    padding: 0.5rem;
}

.compact-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 1rem;
    text-decoration: none;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    min-height: 100px;
    position: relative;
}

/* Spine effect for compact cards too, but smaller */
.compact-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 5px;
    bottom: 5px;
    width: 4px;
    background: var(--primary-color);
    border-radius: 2px;
    opacity: 0.5;
}

.compact-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08);
    border-color: var(--primary-color);
}

.compact-card .card-title {
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
}

/* Re-using and adapting the badge style */
.compact-card .genre-count {
    font-size: 0.8rem;
    color: #888;
    background: rgba(0, 0, 0, 0.05);
    padding: 0.2rem 0.8rem;
    border-radius: 20px;
    transition: background 0.3s, color 0.3s;
    font-weight: 500;
}

.compact-card:hover .genre-count {
    background: var(--primary-color);
    color: white;
}

/* Ensure Dark Mode visibility for badge text */
html.dark-mode .compact-card .genre-count {
    background: rgba(255, 255, 255, 0.1);
    color: #ccc;
}

html.dark-mode .compact-card:hover .genre-count {
    background: var(--primary-color);
    color: white;
}

html.dark-mode .compact-card {
    background: #1e1e1e;
    border-color: #333;
}

/* Dark mode adjustments for new items */
html.dark-mode .atmospheric-intro h1 {
    color: #f0f0f0;
}

html.dark-mode .atmospheric-intro p {
    color: #ccc;
}

html.dark-mode .category-header h2 {
    color: #f0f0f0;
}

html.dark-mode .card-info {
    background: #252525;
}

html.dark-mode .card-title {
    color: #f0f0f0;
}

html.dark-mode .card-meta {
    color: #aaa;
}

html.dark-mode .form-group input:focus,
html.dark-mode textarea:focus {
    background-color: #2a2a2a;
    border-color: var(--primary-color);
}

/* Dark Mode Link Visibility */
html.dark-mode a:not(.btn-primary):not(.btn-danger):not(.tab-btn) {
    color: #8ab4f8;
    /* Light Blue for better contrast */
}

html.dark-mode a:not(.btn-primary):not(.btn-danger):not(.tab-btn):visited {
    color: #c58af9;
    /* Light Purple for visited links */
}

html.dark-mode nav a {
    color: var(--text-color) !important;
    /* Keep nav links neutral */
}

/* Fix Story Content Links overriding */
html.dark-mode .story-content a {
    color: #8ab4f8 !important;
}

/* Profile Page Styles */
.profile-header-container {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 2rem;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.profile-avatar-large {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid var(--bg-color);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    margin-bottom: 1rem;
}

.profile-name {
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.profile-joined {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.profile-stats {
    display: flex;
    justify-content: center;
    gap: 3rem;
    margin-top: 2rem;
    border-top: 1px solid #eee;
    padding-top: 1.5rem;
}

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

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

.stat-label {
    font-size: 0.85rem;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

html.dark-mode .profile-header-container {
    background: #1e1e1e;
}

html.dark-mode .profile-avatar-large {
    border-color: #121212;
}

html.dark-mode .profile-stats {
    border-top-color: #333;
}

html.dark-mode .profile-joined,
html.dark-mode .stat-label {
    color: #aaa;
}

/* Profile Tabs */
.profile-nav {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 2rem;
    border-bottom: 2px solid rgba(0, 0, 0, 0.05);
    padding-bottom: 0;
}

.profile-tab {
    padding: 1rem 1.5rem;
    color: var(--text-color);
    text-decoration: none;
    font-weight: 500;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
    opacity: 0.7;
}

.profile-tab:hover {
    color: var(--primary-color);
    opacity: 1;
}

.profile-tab.active {
    border-bottom-color: var(--primary-color);
    color: var(--primary-color);
    opacity: 1;
}

html.dark-mode .profile-nav {
    border-bottom-color: rgba(255, 255, 255, 0.05);
}

.edit-profile-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(0, 0, 0, 0.05);
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s;
    color: var(--text-color);
    text-decoration: none;
}

.edit-profile-btn:hover {
    background: rgba(0, 0, 0, 0.1);
}

html.dark-mode .edit-profile-btn {
    background: rgba(255, 255, 255, 0.1);
}

html.dark-mode .edit-profile-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Reader Settings UI */
.reader-settings-toggle {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 50px;
    height: 50px;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    z-index: 1000;
    transition: transform 0.2s;
}

.reader-settings-toggle:hover {
    transform: scale(1.1);
}

.reader-settings-panel {
    position: fixed;
    bottom: 80px;
    right: 2rem;
    width: 300px;
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    display: none;
    /* Hidden by default */
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.reader-settings-panel.active {
    display: block;
}

.reader-section {
    margin-bottom: 1.5rem;
}

.reader-section h4 {
    margin-top: 0;
    margin-bottom: 0.8rem;
    font-size: 0.9rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Controls */
.reader-btn-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.reader-btn {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid #ddd;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-color);
    text-align: center;
}

.reader-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* Themes Preview Buttons */
.theme-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid #ddd;
    cursor: pointer;
}

.theme-btn.default {
    background: linear-gradient(135deg, #fff 50%, #333 50%);
}

/* System */
.theme-btn.light {
    background: #fff;
    color: #333;
}

.theme-btn.dark {
    background: #222;
}

.theme-btn.sepia {
    background: #f4ecd8;
}

.theme-btn.black {
    background: #000;
}

/* Font Controls */
.font-control {
    display: flex;
    align-items: center;
    gap: 1rem;
    justify-content: space-between;
    background: rgba(0, 0, 0, 0.05);
    padding: 0.5rem;
    border-radius: 4px;
}

/* --- Reader Content Styles (High Specificity) --- */
/* --- Reader Content Styles (High Specificity) --- */
.story-content {
    transition: background 0.3s, color 0.3s, font-size 0.3s, line-height 0.3s;
    padding: 1rem;
    /* Base padding */
    border-radius: 8px;
    line-height: var(--reader-line-height, 1.8);
}

.story-content p {
    margin-top: 0;
    margin-bottom: var(--reader-margin-bottom, 1rem);
    /* Only indent if it's NOT the first paragraph (optional preference, but standard for books) */
}

/* Indent ALL paragraphs if indentation is ON */
.story-content p {
    text-indent: var(--reader-indent, 0);
}

/* Book Mode Override */
.story-content.book-mode p {
    --reader-margin-bottom: 0;
    --reader-indent: 1.5rem;
}

/* Fonts - Use !important to override inherited fonts */
.story-content.font-serif {
    font-family: 'Merriweather', serif !important;
}

.story-content.font-sans {
    font-family: 'Inter', sans-serif !important;
}

.story-content.font-dyslexic {
    font-family: 'OpenDyslexic', 'Comic Sans MS', sans-serif !important;
}

/* Themes - Use !important to ensure background/color applies over card styles */
/* Light */
.story-content.theme-light {
    background-color: #ffffff !important;
    color: #1a1a1a !important;
    padding: 2rem !important;
}

/* Dark */
.story-content.theme-dark {
    background-color: #2a2a2a !important;
    color: #e0e0e0 !important;
    padding: 2rem !important;
}

.story-content.theme-dark a {
    color: #8ab4f8 !important;
}

/* Sepia */
.story-content.theme-sepia {
    background-color: #f4ecd8 !important;
    color: #5b4636 !important;
    padding: 2rem !important;
}

.story-content.theme-sepia a {
    color: #8f6b4e !important;
}

/* Black (High Contrast) */
.story-content.theme-black {
    background-color: #000000 !important;
    color: #dadada !important;
    padding: 2rem !important;
}

.story-content.theme-black a {
    color: #ffff00 !important;
}

/* Dark Mode Overrides for UI Panel */
html.dark-mode .reader-settings-panel {
    border-color: #444;
    background: #1e1e1e;
}

/* =========================================
   MOBILE RESPONSIVENESS & NEW HELPERS
   ========================================= */

/* Menu Toggle Button (Default Hidden) */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
}

/* Desktop Navigation Defaults */
.nav-text {
    display: none;
    /* Hide text labels on desktop (Library, Inbox, Account) */
}

.nav-link-flex {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dropdown-flex {
    display: flex;
    align-items: center;
}

/* Discover Page Layout (Desktop Default) */
.discover-layout {
    display: flex;
    gap: 2rem;
    margin-top: 2rem;
    align-items: flex-start;
}

.discover-sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.discover-main {
    flex-grow: 1;
}

/* --- Mobile Media Query --- */
@media (max-width: 768px) {

    /* Navigation */
    .menu-toggle {
        display: block;
    }

    nav {
        flex-wrap: wrap;
        /* Allow menu to drop down if needed, or stay aligned */
        padding: 1rem;
    }

    nav ul {
        display: none;
        /* Hide menu by default */
        flex-direction: column;
        width: 100%;
        position: absolute;
        top: 100%;
        left: 0;
        background: var(--nav-bg);
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        padding: 1rem 0;
        gap: 0;
        align-items: stretch;
        /* Full width items */
        text-align: center;
        z-index: 1000;
    }

    nav ul.active {
        display: flex;
        /* Show when active */
    }

    nav ul li {
        width: 100%;
        padding: 0.8rem 0;
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    }

    html.dark-mode nav ul li {
        border-bottom-color: rgba(255, 255, 255, 0.05);
    }

    /* Reset Dropdown Flex for Mobile Stack */
    .dropdown-flex {
        display: block;
    }

    /* Fix Theme Toggle in Mobile Menu */
    #themeToggle {
        width: 100% !important;
        border-radius: 0;
        justify-content: center;
        font-size: 1rem;
        padding: 0.8rem 0 !important;
    }

    nav ul li.search-item {
        /* Search Bar in Mobile Menu */
        margin: 0;
        padding: 1rem;
        display: flex;
        justify-content: center;
    }

    /* Mobile Text vs Icon Toggling */
    .nav-text {
        display: inline;
    }

    .nav-icon {
        display: none !important;
    }

    .mobile-center-flex {
        justify-content: center;
        width: 100%;
    }

    /* Mobile Dropdowns - Expand Inline */
    .dropdown {
        display: block;
        width: 100%;
    }

    .dropdown-content {
        display: none;
        /* Hidden by default on mobile, toggled via JS */
        position: static;
        width: 100%;
        box-shadow: none;
        background: rgba(0, 0, 0, 0.02);
        /* Slight contrast */
        padding: 0;
    }

    .dropdown.active .dropdown-content {
        display: block;
        animation: fadeIn 0.2s;
    }

    .dropdown-content a {
        padding: 1rem;
        font-size: 0.95rem;
        color: var(--text-color);
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    }

    /* Mobile Badge Positioning Fix */
    .nav-badge {
        position: static !important;
        display: inline-flex !important;
        margin-left: 0.5rem;
    }

    .search-form {
        width: 100%;
        max-width: 300px;
    }

    .search-form input {
        width: 100%;
    }

    /* Grids */
    .card-grid,
    .genre-grid,
    .featured-grid,
    .compact-grid {
        grid-template-columns: 1fr;
        /* Single column */
        gap: 1.5rem;
    }

    /* Discover Page Mobile */
    .discover-layout {
        flex-direction: column;
        /* Stack Sidebar on top of Content */
    }

    .discover-sidebar {
        width: 100%;
        /* Full width */
        margin-bottom: 1.5rem;
    }
}

/* Genre Selection Styling */
.genre-selection-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    background: var(--card-bg);
    padding: 1rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    max-height: 400px;
    overflow-y: auto;
    color: var(--text-color);
}

html.dark-mode .genre-selection-container {
    border-color: rgba(255, 255, 255, 0.1);
}

.genre-group h4 {
    margin: 0 0 0.5rem 0;
    font-size: 0.95rem;
    color: var(--text-color);
    opacity: 0.7;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    padding-bottom: 0.3rem;
}

html.dark-mode .genre-group h4 {
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

.genre-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Hidden Checkbox */
.genre-checkbox {
    display: none;
}

/* Styled Label */
.genre-label {
    display: inline-block;
    padding: 0.4rem 0.8rem;
    border: 1px solid #ccc;
    border-radius: 20px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    background: var(--bg-color);
    color: var(--text-color);
}

html.dark-mode .genre-label {
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.05);
}

.genre-label:hover {
    border-color: var(--primary-color);
    transform: translateY(-1px);
}

/* Checked State */
.genre-checkbox:checked+.genre-label {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}