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

:root {
    --bg-primary: #0a0a0a;
    --bg-secondary: #141414;
    --bg-card: #1a1a1a;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --accent: #4a9eff;
    --accent-hover: #6bb3ff;
    --border: #2a2a2a;
    --success: #22c55e;
    --error: #ef4444;
}

html {
    font-size: 16px;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

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

/* Navbar */
.navbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-brand {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 1.25rem;
    font-weight: 600;
    transition: color 0.2s;
}

.navbar-brand:hover {
    color: var(--text-primary);
}

.navbar-menu {
    display: flex;
    list-style: none;
    gap: 0.5rem;
    justify-content: center;
}

.navbar-auth {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.navbar-username {
    color: var(--primary);
    font-weight: 500;
    padding: 0.5rem 0.75rem;
}

/* Mode Toggle */
.mode-toggle {
    display: flex;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}

.mode-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

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

.mode-btn.active {
    background: var(--primary);
    color: var(--bg-dark);
    font-weight: 500;
}

/* User Menu */
.user-menu {
    position: relative;
}

.user-menu-trigger {
    background: none;
    border: none;
    color: var(--primary);
    font-weight: 500;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 1rem;
}

.user-menu-trigger:hover {
    color: var(--primary-light);
}

.user-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    min-width: 150px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 100;
    overflow: hidden;
}

.user-dropdown.active {
    display: block;
}

.dropdown-item {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    background: none;
    border: none;
    color: var(--text-primary);
    text-align: left;
    text-decoration: none;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
}

.dropdown-item:hover {
    background: var(--bg-dark);
}

.navbar-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.navbar-link {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    transition: color 0.2s, background-color 0.2s;
}

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

.navbar-link.active {
    color: var(--accent);
    background: rgba(74, 158, 255, 0.1);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 200;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    max-width: 400px;
    width: 90%;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    padding: 0.25rem;
    transition: color 0.2s;
}

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

.modal-content h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.modal-subtitle {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

#error-modal p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

#error-modal .btn {
    width: 100%;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Claim Username Page */
.claim-username-page {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
}

.claim-username-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2.5rem;
    max-width: 450px;
    width: 100%;
    text-align: center;
}

.claim-username-section h1 {
    font-size: 1.75rem;
    margin-bottom: 0.75rem;
}

.claim-username-description {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.claim-username-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    text-align: left;
}

.claim-username-form label {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.form-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.form-hint.available {
    color: var(--success);
}

.form-hint.unavailable {
    color: var(--error);
}

/* Author Dashboard */
.author-dashboard {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 3rem 2rem;
    text-align: center;
}

.author-dashboard h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.dashboard-subtitle {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.dashboard-placeholder {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    max-width: 500px;
    text-align: left;
}

.dashboard-placeholder p {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.dashboard-placeholder ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.dashboard-placeholder li {
    padding: 0.5rem 0;
    padding-left: 1.5rem;
    position: relative;
    color: var(--text-primary);
}

.dashboard-placeholder li::before {
    content: "→";
    position: absolute;
    left: 0;
    color: var(--primary);
}

/* Rate Limit Page */
.rate-limit-page {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
}

.rate-limit-content {
    text-align: center;
    max-width: 500px;
}

.rate-limit-content h1 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    color: var(--error);
}

.rate-limit-content p {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.rate-limit-info {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
    margin: 2rem 0;
    text-align: left;
}

.rate-limit-info h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.rate-limit-info ul {
    list-style: none;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.rate-limit-info li {
    padding: 0.25rem 0;
}

/* Main Content */
.main-content {
    min-height: calc(100vh - 73px - 70px); /* viewport - navbar - footer */
    display: flex;
    flex-direction: column;
}

/* Home Page */
.home-page {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
}

.home-content {
    text-align: center;
    max-width: 600px;
}

.home-logo {
    max-width: 200px;
    width: 100%;
    height: auto;
    margin-bottom: 2rem;
}

.home-title {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

.home-subtitle {
    font-size: 1.25rem;
    color: var(--text-secondary);
}

/* Newsletter Page */
.newsletter-page {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    gap: 2rem;
}

/* Coming Soon (skeleton pages) */
.coming-soon {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 2rem;
}

.coming-soon h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.coming-soon p {
    color: var(--text-secondary);
}

/* Landing Page */
.landing {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 2rem;
}

.logo {
    max-width: 300px;
    width: 100%;
    height: auto;
    margin-bottom: 2rem;
}

.tagline {
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin-bottom: 3rem;
    max-width: 600px;
}

/* Countdown */
.countdown-section {
    margin-bottom: 3rem;
}

.countdown-title {
    font-size: 1rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 1rem;
}

.countdown {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.countdown-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem 1rem;
    min-width: 80px;
}

.countdown-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1;
}

.countdown-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.5rem;
}

/* Newsletter */
.newsletter-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2.5rem;
    max-width: 500px;
    width: 100%;
}

.newsletter-title {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.newsletter-description {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.newsletter-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-input {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.875rem 1rem;
    font-size: 1rem;
    color: var(--text-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.1);
}

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

.btn {
    background: var(--accent);
    color: var(--bg-primary);
    border: none;
    border-radius: 6px;
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

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

.btn:active {
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.form-message {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    font-size: 0.875rem;
    display: none;
}

.form-message.success {
    display: block;
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid var(--success);
    color: var(--success);
}

.form-message.error {
    display: block;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error);
    color: var(--error);
}

/* Error Page */
.error-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 2rem;
}

.error-code {
    font-size: 8rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1;
    margin-bottom: 1rem;
}

.error-title {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.error-description {
    color: var(--text-secondary);
    margin-bottom: 2rem;
    max-width: 400px;
}

.error-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.error-link:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* Footer */
.footer {
    padding: 2rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Browse Page */
.browse-page {
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

.browse-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
}

.browse-tab {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1rem;
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    border-radius: 6px;
    transition: color 0.2s, background-color 0.2s;
}

.browse-tab:hover {
    color: var(--text-primary);
    background: var(--bg-card);
}

.browse-tab.active {
    color: var(--accent);
    background: rgba(74, 158, 255, 0.1);
}

/* Series Grid */
.series-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1.5rem;
}

.series-card {
    display: block;
    text-decoration: none;
    color: var(--text-primary);
    transition: transform 0.2s;
    cursor: pointer;
}

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

.series-cover {
    aspect-ratio: 2/3;
    overflow: hidden;
    border-radius: 8px;
    margin-bottom: 0.75rem;
    background: var(--bg-card);
}

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

.series-title {
    font-size: 1rem;
    font-weight: 500;
    text-align: center;
}

/* Series Page */
.series-page {
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

.series-header {
    text-align: center;
    margin-bottom: 3rem;
}

.series-page-title {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.series-author {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.series-author a {
    color: var(--accent);
    text-decoration: none;
}

.series-author a:hover {
    text-decoration: underline;
}

.series-description {
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto;
}

/* Books Grid */
.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 2rem;
}

.book-card {
    text-decoration: none;
    color: var(--text-primary);
    transition: transform 0.2s;
}

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

.book-cover {
    aspect-ratio: 2/3;
    overflow: hidden;
    border-radius: 8px;
    margin-bottom: 1rem;
    background: var(--bg-card);
}

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

.book-info {
    text-align: center;
}

.book-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

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

.book-number {
    color: var(--accent);
}

/* Book Page */
.book-page {
    padding: 2rem;
    max-width: 1000px;
    margin: 0 auto;
}

.book-header {
    text-align: center;
    margin-bottom: 2rem;
}

.book-page-title {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.book-series-info {
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.book-series-info a {
    color: var(--accent);
    text-decoration: none;
}

.book-series-info a:hover {
    text-decoration: underline;
}

.book-author {
    color: var(--text-secondary);
}

.book-author a {
    color: var(--accent);
    text-decoration: none;
}

.book-author a:hover {
    text-decoration: underline;
}

.book-content {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 2rem;
    margin-bottom: 3rem;
}

.book-description {
    line-height: 1.8;
    color: var(--text-secondary);
}

.book-description p {
    margin-bottom: 1rem;
}

.book-sidebar {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.book-cover-large {
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-card);
}

.book-cover-large img {
    width: 100%;
    height: auto;
    display: block;
}

.book-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.btn-primary {
    background: var(--accent);
    color: var(--bg-primary);
    text-align: center;
    text-decoration: none;
}

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

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    text-align: center;
    text-decoration: none;
}

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

/* Chapter List */
.chapter-list {
    border-top: 1px solid var(--border);
    padding-top: 2rem;
}

.chapter-list h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
}

.chapter-list ul {
    list-style: none;
}

.chapter-list li {
    border-bottom: 1px solid var(--border);
}

.chapter-list li:first-child {
    border-top: 1px solid var(--border);
}

.chapter-list a {
    display: block;
    padding: 1rem;
    color: var(--text-primary);
    text-decoration: none;
    transition: background-color 0.2s;
}

.chapter-list a:hover {
    background: var(--bg-card);
}

/* Chapter Page */
.chapter-page {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem;
}

.breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 2rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

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

.breadcrumbs a:hover {
    text-decoration: underline;
}

.breadcrumbs .separator {
    color: var(--text-muted);
}

.breadcrumbs .current {
    color: var(--text-primary);
}

.chapter-content {
    margin-bottom: 3rem;
}

.chapter-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.chapter-header h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

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

.chapter-text {
    font-size: 1.125rem;
    line-height: 1.8;
    color: var(--text-primary);
}

.chapter-text p {
    margin-bottom: 1.5rem;
}

.chapter-nav {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
}

.chapter-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    border-radius: 8px;
    background: var(--bg-card);
    text-decoration: none;
    color: var(--text-primary);
    transition: background-color 0.2s;
    min-width: 120px;
}

.chapter-nav-btn:hover:not(.disabled) {
    background: var(--bg-hover);
}

.chapter-nav-btn.disabled {
    opacity: 0.3;
    cursor: default;
}

.chapter-nav-btn.prev {
    align-items: flex-start;
}

.chapter-nav-btn.next {
    align-items: flex-end;
}

.chapter-nav-btn .nav-arrow {
    font-size: 1.5rem;
    color: var(--accent);
}

.chapter-nav-btn .nav-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.chapter-nav-btn .nav-title {
    font-size: 0.875rem;
    margin-top: 0.25rem;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chapter-nav-btn.chapters {
    flex-direction: row;
    gap: 0.5rem;
}

/* Responsive */
@media (max-width: 640px) {
    .navbar {
        grid-template-columns: auto 1fr auto;
        padding: 0.75rem 1rem;
        gap: 0.5rem;
    }

    .navbar-brand {
        font-size: 1rem;
    }

    .navbar-menu {
        justify-content: center;
    }

    .navbar-link {
        padding: 0.375rem 0.75rem;
        font-size: 0.875rem;
    }

    .navbar-auth .navbar-link {
        padding: 0.375rem 0.5rem;
    }

    .home-logo {
        max-width: 150px;
    }

    .home-title {
        font-size: 1.75rem;
    }

    .home-subtitle {
        font-size: 1rem;
    }

    .logo {
        max-width: 200px;
    }

    .countdown-value {
        font-size: 2rem;
    }

    .countdown-item {
        min-width: 70px;
        padding: 1rem 0.75rem;
    }

    .newsletter-section {
        padding: 1.5rem;
    }

    .error-code {
        font-size: 5rem;
    }

    .browse-page {
        padding: 1rem;
    }

    .browse-tabs {
        flex-wrap: wrap;
    }

    .browse-tab {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }

    .series-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }

    .books-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }

    .series-page {
        padding: 1rem;
    }

    .series-page-title {
        font-size: 1.75rem;
    }

    .book-page {
        padding: 1rem;
    }

    .book-page-title {
        font-size: 1.75rem;
    }

    .book-content {
        grid-template-columns: 1fr;
    }

    .book-sidebar {
        order: -1;
    }

    .book-cover-large {
        max-width: 250px;
        margin: 0 auto;
    }

    .chapter-page {
        padding: 1rem;
    }

    .chapter-header h1 {
        font-size: 1.5rem;
    }

    .chapter-text {
        font-size: 1rem;
    }

    .chapter-nav {
        flex-direction: column;
    }

    .chapter-nav-btn {
        width: 100%;
    }

    .chapter-nav-btn.prev,
    .chapter-nav-btn.next {
        align-items: center;
    }
}
