:root {
    --bg-primary: #020617;
    --bg-secondary: #0f172a;
    --bg-tertiary: #1e293b;
    --bg-hover: #334155;
    --text-primary: #e5e7eb;
    --text-secondary: #9ca3af;
    --border-color: rgba(148, 163, 184, .12);
    --accent-primary: #4f46e5;
    --accent-primary-hover: #4338ca;
    --accent-text: #a5b4fc;
    --accent-text-hover: #c7d2fe;
    --danger-text: #f43f5e;
    --header-bg: rgba(2, 6, 23, 0.9);
    --white: #fff;
    --black: #000;
}

html.light-mode {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e2e8f0;
    --bg-hover: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --accent-primary: #4f46e5;
    --accent-primary-hover: #4338ca;
    --accent-text: #4f46e5;
    --accent-text-hover: #3730a3;
    --danger-text: #dc2626;
    --header-bg: rgba(248, 250, 252, 0.9);
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    overflow-x: hidden;
    width: 100%;
}

.site-body {
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Hide header/footer on auth pages */
.auth-page .site-header,
.auth-page .site-footer {
    display: none;
}


/* Header & Navigation */
.site-header {
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(10px);
    background: var(--header-bg);
}

.nav {
    max-width: 1100px;
    margin: 0 auto;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    /* Allow wrapping for mobile menu */
}

.nav-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

@media (min-width: 768px) {
    .nav-brand {
        width: auto;
    }

    .nav {
        flex-wrap: nowrap;
    }
}

.nav-toggle {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    width: 30px;
    height: 24px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 10;
}

.nav-toggle span {
    width: 100%;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: all 0.3s linear;
}

@media (min-width: 768px) {
    .nav-toggle {
        display: none;
    }
}

.nav-menu {
    display: none;
    flex-direction: column;
    width: 100%;
    padding-top: 16px;
    gap: 16px;
    border-top: 1px solid var(--border-color);
    margin-top: 12px;
    animation: slideDown 0.3s ease-out forwards;
}

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

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

.nav-menu.active {
    display: flex;
}

@media (min-width: 768px) {
    .nav-menu {
        display: flex;
        flex-direction: row;
        width: auto;
        padding-top: 0;
        flex-grow: 1;
        justify-content: space-between;
        margin-left: 32px;
        border-top: none;
        margin-top: 0;
        animation: none;
    }
}

.nav-left,
.nav-right {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.nav-left .nav-link {
    width: 100%;
    display: block;
}

@media (min-width: 768px) {

    .nav-left,
    .nav-right {
        flex-direction: row;
        align-items: center;
        gap: 16px;
        width: auto;
    }

    .nav-left .nav-link {
        width: auto;
        display: inline-block;
    }
}

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

.logo span {
    color: var(--accent-primary);
}

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

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

.theme-toggle {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 6px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Login Partial Styles */
.login-partial-container {
    display: flex;
    align-items: center;
    gap: 16px;
}

.login-partial-container .nav-link,
.login-partial-container .btn-link {
    color: var(--text-primary);
    text-decoration: none;
}

.login-partial-container .btn-link {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
}


/* Main Content Area */
.site-main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 32px 16px 64px;
    min-height: calc(100vh - 150px);
    /* Adjusted for header/footer */
}

/* Buttons */
.btn-primary,
.btn-outline,
.btn-secondary {
    display: inline-block;
    padding: 10px 20px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.3s ease;
}

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

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

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

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

.btn-secondary {
    background-color: var(--bg-hover);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: var(--bg-tertiary);
}

/* Section Styling */
.section {
    margin-bottom: 48px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 24px;
}

.section-header h2 {
    font-size: 1.75rem;
    font-weight: 700;
}

.section-header a {
    color: var(--accent-text);
    text-decoration: none;
}

.section-header a:hover {
    text-decoration: underline;
}

.section-subtitle {
    color: var(--text-secondary);
    margin-top: -12px;
}


/* Footer */
.site-footer {
    border-top: 1px solid var(--border-color);
    padding: 24px 16px 32px;
    background: var(--bg-primary);
}

.footer-inner {
    max-width: 1100px;
    margin: 0 auto;
    display: grid;
    gap: 24px;
}

.footer-brand p {
    color: var(--text-secondary);
    max-width: 350px;
}

.footer-links h4,
.footer-meta h4 {
    color: var(--text-primary);
    margin-bottom: 12px;
    font-size: 1rem;
}

.footer-links a {
    display: block;
    color: var(--text-secondary);
    text-decoration: none;
    margin-bottom: 8px;
}

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

.footer-meta p {
    color: var(--text-secondary);
}

@media (min-width: 768px) {
    .footer-inner {
        grid-template-columns: 2fr 1fr 1fr;
    }
}

/* Home Page: Hero Section */
.hero {
    display: grid;
    grid-template-columns: 1fr;
    gap: 32px;
    align-items: center;
    padding: 48px 0;
    text-align: center;
}

@media (min-width: 768px) {
    .hero {
        grid-template-columns: 2fr 1fr;
        text-align: left;
    }
}

.hero-text h1 {
    font-size: 2.5rem;
    font-weight: 800;
    line-height: 1.2;
    margin-bottom: 16px;
}

.hero-text p {
    font-size: 1.125rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.hero-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

@media (min-width: 768px) {
    .hero-actions {
        justify-content: flex-start;
    }
}

.hero-stats {
    display: flex;
    gap: 24px;
    justify-content: center;
}

@media (min-width: 768px) {
    .hero-stats {
        flex-direction: column;
        align-items: flex-start;
    }
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.stat-number {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--accent-text);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Home Page: Story Grid */
.story-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

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

.story-card {
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.story-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px var(--black);
}

.story-cover {
    width: 100%;
    height: auto;
    aspect-ratio: 2 / 3;
    object-fit: cover;
}

.story-info {
    padding: 16px;
}

.story-info h3 {
    font-size: 1.125rem;
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.story-meta {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.story-desc {
    font-size: 0.875rem;
    color: var(--text-primary);
    line-height: 1.5;
    height: 4.5em;
    /* 3 lines */
    overflow: hidden;
}

/* Home Page: Tag List */
.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.tag {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: 9999px;
    text-decoration: none;
    font-size: 0.875rem;
    transition: background-color 0.2s ease;
}

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

/* Story List Page */
.stories-header {
    display: flex;
    flex-direction: column;
    gap: 16px;
    justify-content: space-between;
    margin-bottom: 24px;
}

@media (min-width: 768px) {
    .stories-header {
        flex-direction: row;
        align-items: center;
    }
}

.stories-header h1 {
    font-size: 2rem;
    font-weight: 800;
}

.stories-tools {
    display: flex;
    gap: 8px;
}

.stories-tools input,
.stories-tools select {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
}

.stories-tools input::placeholder {
    color: var(--text-secondary);
}

.layout-two-col {
    display: grid;
    grid-template-columns: 1fr;
    gap: 32px;
}

@media (min-width: 768px) {
    .layout-two-col {
        grid-template-columns: 240px 1fr;
    }
}

.sidebar h3 {
    font-size: 1.25rem;
    margin-bottom: 16px;
}

.filter-group {
    margin-bottom: 24px;
}

.filter-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 12px;
}

.filter-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filter-options label {
    font-weight: normal;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Story Row */
.list-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.story-row {
    display: flex;
    gap: 16px;
    background: var(--bg-secondary);
    padding: 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.story-row-cover {
    width: 80px;
    height: 120px;
    object-fit: cover;
    border-radius: 4px;
}

.story-row-body h3 {
    margin: 0 0 8px 0;
}

.story-row-body h3 a {
    color: var(--text-primary);
    text-decoration: none;
    font-size: 1.2rem;
}

.story-row-body h3 a:hover {
    color: var(--accent-text);
}

.story-row-meta {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 0 0 8px 0;
}

.story-row-desc {
    font-size: 0.875rem;
    color: var(--text-primary);
    line-height: 1.5;
    margin: 0;
    display: -webkit-box;
    line-clamp: 2;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 32px;
}

.pagination a,
.pagination span {
    color: var(--text-primary);
    text-decoration: none;
    padding: 8px 14px;
    border-radius: 6px;
    background-color: var(--bg-tertiary);
}

.pagination a:hover {
    background-color: var(--accent-primary);
    color: var(--white);
}

.pagination .active {
    background-color: var(--accent-primary);
    font-weight: bold;
    color: var(--white);
}

/* Authentication Pages */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 16px;
}

.auth-form {
    width: 100%;
    max-width: 420px;
    background-color: var(--bg-secondary);
    padding: 32px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

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

.auth-header .logo {
    display: inline-block;
    margin-bottom: 16px;
}

.auth-header h2 {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.auth-header p {
    color: var(--text-secondary);
}

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

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

.form-control {
    width: 100%;
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    box-sizing: border-box;
    /* Important */
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px #4f46e530;
}

.form-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
}



.forgot-password {
    font-size: 0.875rem;
    color: var(--accent-text);
    text-decoration: none;
}

.forgot-password:hover {
    text-decoration: underline;
}

.auth-button {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
}

.auth-footer {
    text-align: center;
    margin-top: 24px;
    color: var(--text-secondary);
}

.auth-footer a {
    color: var(--accent-text);
    text-decoration: none;
    font-weight: 500;
}

.auth-footer a:hover {
    text-decoration: underline;
}

.text-danger {
    color: var(--danger-text) !important;
}

/* Story Details Page */
.story-details-header {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
    margin-bottom: 48px;
}

@media (min-width: 768px) {
    .story-details-header {
        grid-template-columns: 250px 1fr;
        gap: 32px;
    }
}

.story-details-cover img {
    width: 100%;
    border-radius: 8px;
    aspect-ratio: 2 / 3;
    object-fit: cover;
}

.story-details-info h1 {
    font-size: 2.25rem;
    margin-bottom: 16px;
}

.info-meta {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 24px;
    color: var(--text-secondary);
}

.info-meta span strong {
    color: var(--text-primary);
}

.info-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
}

.info-description {
    line-height: 1.7;
    color: var(--text-primary);
}

.story-chapters-section h2 {
    font-size: 1.75rem;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
}

.chapters-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: 1fr;
    gap: 1px;
    background-color: var(--border-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

@media (min-width: 768px) {
    .chapters-list {
        grid-template-columns: 1fr 1fr;
    }
}


.chapters-list li a {
    display: block;
    padding: 12px 16px;
    background-color: var(--bg-secondary);
    text-decoration: none;
    color: var(--text-primary);
    transition: background-color 0.2s ease;
}

.chapters-list li a:hover {
    background-color: var(--bg-hover);
    color: var(--accent-text);
}

.chapter-number {
    font-weight: 500;
    margin-right: 12px;
}