:root {
    --bg: #FAF6F0;
    --bg-card: #FFFCF7;
    --primary: #8B4513;
    --primary-light: #C4956A;
    --accent: #C0392B;
    --accent-soft: #E8A598;
    --text: #3D2B1F;
    --text-muted: #8B7355;
    --border: #E8DDD0;
    --shadow: 0 4px 20px rgba(139, 69, 19, 0.08);
    --radius: 16px;
    --font-serif: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font-serif);
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }

/* ── Home ── */
.page-home { display: flex; flex-direction: column; min-height: 100dvh; }

.site-header {
    background: linear-gradient(135deg, #8B4513 0%, #A0522D 50%, #CD853F 100%);
    color: #FFF8F0;
    padding: 2.5rem 1.25rem 2rem;
    text-align: center;
}

.site-title { font-size: 1.75rem; font-weight: 700; letter-spacing: 0.05em; }
.site-subtitle { margin-top: 0.4rem; opacity: 0.85; font-size: 0.95rem; }

.home-main { flex: 1; padding: 1.5rem 1rem 2rem; max-width: 480px; margin: 0 auto; width: 100%; }

.module-grid { display: flex; flex-direction: column; gap: 1rem; }

.module-card {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
}

.module-card-active:active { transform: scale(0.98); }

.module-card-soon { opacity: 0.55; pointer-events: none; }

.module-icon { font-size: 2rem; margin-bottom: 0.5rem; }
.module-name { font-size: 1.2rem; color: var(--primary); margin-bottom: 0.3rem; }
.module-desc { font-size: 0.9rem; color: var(--text-muted); }
.module-badge {
    position: absolute; top: 1rem; right: 1rem;
    background: var(--accent-soft); color: var(--accent);
    font-size: 0.75rem; padding: 0.2rem 0.6rem; border-radius: 20px;
}

.site-footer { text-align: center; padding: 1rem; color: var(--text-muted); font-size: 0.85rem; }

/* ── List ── */
.page-list, .page-reader { padding-bottom: env(safe-area-inset-bottom); }

.page-header, .reader-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.25rem;
    position: sticky; top: 0; z-index: 10;
}

.back-link { font-size: 0.9rem; color: var(--primary-light); display: inline-block; margin-bottom: 0.5rem; }
.page-title, .reader-title { font-size: 1.3rem; color: var(--primary); }
.page-desc { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.2rem; }

.article-list { max-width: 480px; margin: 0 auto; padding: 1rem; }

.group-section { margin-bottom: 1.5rem; }
.group-label {
    font-size: 0.85rem; color: var(--text-muted);
    padding: 0.5rem 0.75rem; font-weight: 600;
    border-left: 3px solid var(--primary-light);
    margin-bottom: 0.75rem;
}

.article-card {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow);
    transition: transform 0.15s;
}
.article-card:active { transform: scale(0.98); }
.article-card-title { font-size: 1.15rem; color: var(--primary); margin-bottom: 0.3rem; }
.article-card-meta { font-size: 0.8rem; color: var(--text-muted); }
.article-card-intro { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.5rem; line-height: 1.5; }

/* ── Reader ── */
.reader-header { text-align: center; }
.reader-title-wrap { margin-top: 0.25rem; }

.progress-bar {
    height: 4px; background: var(--border);
    border-radius: 2px; margin: 0.75rem auto 0.4rem; max-width: 200px; overflow: hidden;
}
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 2px; transition: width 0.3s; width: 0; }
.progress-text { font-size: 0.8rem; color: var(--text-muted); }

.reader-main {
    max-width: 480px; margin: 0 auto;
    padding: 0.75rem 1rem 5.5rem;
}

.sentence-thumbs {
    display: none;
    gap: 0.5rem;
    overflow-x: auto;
    padding: 0.5rem 0 1rem;
    -webkit-overflow-scrolling: touch;
}
.sentence-thumbs .thumb {
    flex-shrink: 0;
    width: 2rem; height: 2rem;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--bg-card);
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}
.sentence-thumbs .thumb.active { border-color: var(--primary); background: var(--primary); color: #fff; }
.sentence-thumbs .thumb.done { border-color: var(--primary-light); color: var(--primary); }

.card-container { position: relative; touch-action: pan-y; }

.sentence-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.card-image-wrap {
    width: 100%;
    aspect-ratio: 3/4;
    background: linear-gradient(180deg, #F5EDE3 0%, #EDE4D8 100%);
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
    position: relative;
}
.card-image-wrap img { width: 100%; height: 100%; object-fit: cover; }
.card-image-placeholder {
    color: var(--text-muted); font-size: 0.9rem; text-align: center; padding: 2rem;
}
.card-image-loading {
    position: absolute; inset: 0;
    background: rgba(250,246,240,0.85);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.9rem; color: var(--text-muted);
}

.card-text { padding: 1.25rem; }

.original-text {
    font-size: 1.35rem;
    line-height: 2;
    text-align: center;
    color: var(--primary);
    font-weight: 600;
    letter-spacing: 0.15em;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px dashed var(--border);
}

.word-align-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.25rem 0;
    margin-bottom: 1rem;
}

.word-pair {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 1.8rem;
    padding: 0.15rem 0.1rem;
}

.word-pair .char-orig {
    font-size: 1.25rem;
    color: var(--primary);
    font-weight: 600;
    line-height: 1.4;
}

.word-pair .char-trans {
    font-size: 0.7rem;
    color: var(--accent);
    line-height: 1.3;
    min-height: 1rem;
    white-space: nowrap;
}

.full-translation {
    font-size: 0.95rem;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.7;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.reader-footer {
    position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
    display: flex; gap: 0.5rem;
    justify-content: center;
    max-width: 480px;
    margin: 0 auto;
    z-index: 20;
}

.btn {
    flex: 1;
    max-width: 140px;
    padding: 0.75rem 0.5rem;
    border: none;
    border-radius: 12px;
    font-size: 0.95rem;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.15s;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #FFF8F0; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-accent { background: var(--accent); color: #fff; flex: 0.8; }

.loading-state, .error-state {
    text-align: center; padding: 3rem 1rem;
    color: var(--text-muted);
}

.toast {
    position: fixed; bottom: 5rem; left: 50%; transform: translateX(-50%) translateY(20px);
    background: rgba(61,43,31,0.9); color: #fff;
    padding: 0.6rem 1.2rem; border-radius: 20px;
    font-size: 0.85rem; opacity: 0; pointer-events: none;
    transition: opacity 0.3s, transform 0.3s; z-index: 100;
    max-width: 80%; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Desktop ── */
@media (min-width: 768px) {
    .home-main, .article-list, .reader-main { max-width: 520px; }
    .reader-footer { left: 50%; transform: translateX(-50%); border-radius: var(--radius) var(--radius) 0 0; }
    .sentence-thumbs { display: flex; }
    .module-grid { gap: 1.25rem; }
    .original-text { font-size: 1.5rem; }
}

@media (min-width: 1024px) {
    .home-main { max-width: 640px; }
    .module-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        max-width: 900px;
        margin: 0 auto;
    }
    .page-home .home-main { max-width: 960px; }
}
