/* ── Reset & Base ─────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
body {
    font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
    background: #f5f2eb;
    color: #2c2c2c;
    line-height: 1.7;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
a { text-decoration: none; color: inherit; }

/* ── Header ──────────────────────────────────────────── */
header {
    background: linear-gradient(135deg, #2c1810 0%, #4a2c1a 100%);
    color: #f0e6d8;
    padding: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.header-inner {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
}
.logo {
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: 1px;
}
.subtitle {
    font-size: 0.8rem;
    opacity: 0.6;
}
.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}
.user-badge {
    font-size: 0.8rem;
    background: rgba(255,255,255,0.15);
    padding: 4px 12px;
    border-radius: 20px;
}
.logout-link {
    font-size: 0.75rem;
    opacity: 0.6;
    color: #f0e6d8;
}
.logout-link:hover { opacity: 1; }

/* ── Main ────────────────────────────────────────────── */
main {
    flex: 1;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    padding: 20px 16px 80px;
}

/* ── Card Grid Shelf ─────────────────────────────────── */
.shelf-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.shelf-header h2 {
    font-size: 1.4rem;
    color: #4a2c1a;
}
.btn-add-book {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #8b5e3c;
    color: #fff;
    border: none;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(139, 94, 60, 0.3);
}
.card-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
.book-card {
    background: #fff;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    transition: transform 0.15s, box-shadow 0.15s;
    display: flex;
    flex-direction: column;
}
.book-card:active {
    transform: scale(0.97);
}
.card-cover {
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
.cover-letter {
    font-size: 3rem;
    font-weight: 800;
    color: rgba(255,255,255,0.3);
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.cover-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 1rem;
}
.card-body {
    padding: 12px 14px 14px;
    flex: 1;
    display: flex;
    flex-direction: column;
}
.card-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: #2c1810;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}
.card-meta {
    font-size: 0.75rem;
    color: #999;
    margin-bottom: 8px;
}
.progress-track-sm {
    height: 3px;
    background: #eee;
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 4px;
}
.progress-fill-sm {
    height: 100%;
    background: linear-gradient(90deg, #8b5e3c, #c49a6c);
    border-radius: 2px;
    transition: width 0.3s;
}
.card-progress {
    font-size: 0.7rem;
    color: #8b5e3c;
    margin-top: auto;
}
.card-new {
    font-size: 0.8rem;
    color: #8b5e3c;
    font-weight: 500;
    margin-top: auto;
}

@media (min-width: 600px) {
    .card-grid { grid-template-columns: 1fr 1fr 1fr; }
    .card-cover { height: 150px; }
    .cover-letter { font-size: 3.5rem; }
}

/* ── Empty State ─────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #999;
}
.empty-state p { margin-bottom: 12px; }

/* ── Chapter List ────────────────────────────────────── */
.chapter-list h2 {
    font-size: 1.2rem;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.back-link {
    color: #8b5e3c;
    font-size: 0.95rem;
}
.chapter-count {
    font-size: 0.85rem;
    color: #888;
    margin-bottom: 16px;
}
.continue-reading {
    display: block;
    text-align: center;
    background: linear-gradient(135deg, #8b5e3c, #a0764a);
    color: #fff;
    padding: 14px;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(139, 94, 60, 0.3);
}
.chapter-grid {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.chapter-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #fff;
    border-radius: 8px;
    transition: background 0.1s;
}
.chapter-link:active {
    background: #f0e6d8;
}
.chapter-link.current {
    background: #f0e6d8;
    border-left: 3px solid #8b5e3c;
}
.chapter-num {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f2eb;
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 600;
    color: #8b5e3c;
    flex-shrink: 0;
}
.chapter-title {
    font-size: 0.95rem;
    color: #444;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Reader ──────────────────────────────────────────── */
.reader {
    max-width: 700px;
    margin: 0 auto;
    position: relative;
    min-height: 60vh;
    padding-bottom: 30px;
}

/* Topbar */
.reader-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    margin-bottom: 20px;
    border-bottom: 1px solid #e0d8cc;
}
.reader-topbar .back-link {
    font-size: 0.9rem;
}
.chapter-label {
    font-size: 0.8rem;
    color: #888;
}
.font-controls {
    display: flex;
    gap: 4px;
}
.font-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid #ddd;
    background: #fff;
    font-size: 0.8rem;
    font-weight: 700;
    color: #666;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.font-btn:active { background: #f0e6d8; }

/* Chapter title */
.chapter-title-heading {
    font-size: 1.3rem;
    font-weight: 700;
    text-align: center;
    color: #2c1810;
    margin-bottom: 24px;
    line-height: 1.4;
}

/* Content */
.chapter-content {
    font-size: 18px;
    line-height: 2;
    color: #333;
    transition: font-size 0.15s;
}
.chapter-content p {
    text-indent: 2em;
    margin-bottom: 0.5em;
}

/* ── Bottom nav ──────────────────────────────────────── */
.reader-nav {
    display: flex;
    gap: 8px;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid #e0d8cc;
}
.nav-btn {
    flex: 1;
    text-align: center;
    padding: 14px 8px;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    background: #fff;
    color: #4a2c1a;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    transition: background 0.15s;
}
.nav-btn:active {
    background: #f0e6d8;
}
.nav-btn.next {
    background: #8b5e3c;
    color: #fff;
}
.nav-btn.next:active {
    background: #6d4828;
}
.nav-btn.disabled {
    opacity: 0.3;
    pointer-events: none;
}
.nav-btn.toc {
    flex: 0.5;
}

/* ── Auth Pages ──────────────────────────────────────── */
.auth-page {
    display: flex;
    justify-content: center;
    padding: 40px 16px;
}
.auth-card {
    background: #fff;
    border-radius: 16px;
    padding: 32px 28px;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}
.auth-card h2 {
    font-size: 1.4rem;
    margin-bottom: 24px;
    text-align: center;
    color: #2c1810;
}
.auth-form .form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 6px;
    font-weight: 500;
}
.form-group input[type="text"],
.form-group input[type="password"] {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #ddd;
    border-radius: 10px;
    font-size: 1rem;
    background: #fafafa;
    transition: border-color 0.2s;
}
.form-group input:focus {
    outline: none;
    border-color: #8b5e3c;
    background: #fff;
}
.auth-link {
    text-align: center;
    margin-top: 20px;
    font-size: 0.9rem;
    color: #888;
}
.auth-link a {
    color: #8b5e3c;
    font-weight: 600;
}
/* ── Buttons ─────────────────────────────────────────── */
.btn {
    display: inline-block;
    padding: 12px 24px;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    text-align: center;
    transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
    background: linear-gradient(135deg, #8b5e3c, #a0764a);
    color: #fff !important;
    box-shadow: 0 2px 6px rgba(139, 94, 60, 0.3);
}
.btn-secondary {
    background: #f0e6d8;
    color: #4a2c1a;
}
.btn-block {
    display: block;
    width: 100%;
}
/* ── Alerts ──────────────────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}
.alert-error { background: #fff0f0; color: #c0392b; border: 1px solid #f5c6cb; }
.alert-success { background: #f0fff4; color: #27ae60; border: 1px solid #c3e6cb; }
.alert-warning { background: #fff8e1; color: #8a6d3b; border: 1px solid #ffeeba; }
/* ── Disclaimer ──────────────────────────────────────── */
.disclaimer-card { max-width: 500px; }
.disclaimer-body {
    margin-bottom: 24px;
    font-size: 0.95rem;
    line-height: 1.8;
    color: #444;
}
.disclaimer-body p { margin-bottom: 12px; }
.disclaimer-body ul {
    list-style: none;
    padding: 0;
    margin: 16px 0;
}
.disclaimer-body ul li {
    padding: 8px 12px;
    background: #f9f6f0;
    border-radius: 8px;
    margin-bottom: 6px;
    font-size: 0.9rem;
}
.disclaimer-strong {
    font-weight: 600;
    color: #c0392b;
}
.disclaimer-confirm-text {
    text-align: center;
    font-weight: 600;
    color: #8b5e3c;
    padding: 12px;
    background: #f9f6f0;
    border-radius: 8px;
}
/* ── Tab Bar ─────────────────────────────────────────── */
.tab-bar {
    display: flex;
    gap: 0;
    margin-bottom: 24px;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.tab-btn {
    flex: 1;
    padding: 14px;
    border: none;
    background: #fff;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    color: #888;
    transition: all 0.15s;
}
.tab-btn.active {
    background: #8b5e3c;
    color: #fff;
    font-weight: 600;
}
/* ── Upload Dropzone ─────────────────────────────────── */
.upload-card {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.upload-card p { font-size: 0.95rem; color: #666; margin-bottom: 16px; }
.upload-dropzone {
    border: 2px dashed #ddd;
    border-radius: 16px;
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    background: #fafafa;
}
.upload-dropzone:hover {
    border-color: #8b5e3c;
    background: #f9f6f0;
}
.upload-dropzone p { font-size: 1.1rem; color: #999; margin-bottom: 0; }
.upload-hint {
    font-size: 0.8rem !important;
    color: #bbb !important;
    margin-top: 8px !important;
}
/* ── Footer ──────────────────────────────────────────── */
footer {
    text-align: center;
    padding: 20px;
    font-size: 0.75rem;
    background: #2c1810;
    color: #8a7a6a;
}
