: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;
}

.module-card-game {
    background: linear-gradient(135deg, #F5FAF3 0%, #E8F2E5 100%);
    border-color: #C5D9C0;
}

.module-card-game .module-name { color: #4A7C59; }
.module-card-game .module-badge { background: #D4E8D0; color: #4A7C59; }

.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 {
    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: 520px; margin: 0 auto; padding: 1rem; }

/* ── Bookshelf ── */
.bookshelf-grid {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 0.5rem 0 1rem;
}

.book-link {
    display: block;
    color: inherit;
    transition: transform 0.2s;
}

.book-link:active { transform: scale(0.98); }

.book-link .book-cover { margin-bottom: 0; }

@media (min-width: 480px) {
    .bookshelf-grid {
        flex-direction: row;
        align-items: stretch;
        gap: 1rem;
    }

    .bookshelf-grid .book-link { flex: 1; min-width: 0; }
}

.book-section { margin-bottom: 2rem; }

.book-cover {
    position: relative;
    display: flex;
    border-radius: 4px 14px 14px 4px;
    overflow: hidden;
    box-shadow:
        0 8px 24px rgba(139, 69, 19, 0.18),
        0 2px 6px rgba(61, 43, 31, 0.08),
        inset -2px 0 8px rgba(0, 0, 0, 0.06);
    margin-bottom: 1rem;
    min-height: 120px;
}

.book-cover-up {
    background: linear-gradient(135deg, #6B3A12 0%, #8B4513 42%, #A0522D 100%);
}

.book-cover-down {
    background: linear-gradient(135deg, #4A3728 0%, #6B4423 42%, #8B6914 100%);
}

.book-cover-compact {
    min-height: 96px;
    margin-bottom: 1.25rem;
}

.book-spine {
    width: 18px;
    flex-shrink: 0;
    background: linear-gradient(90deg, rgba(0,0,0,0.25) 0%, rgba(255,255,255,0.08) 50%, rgba(0,0,0,0.15) 100%);
    border-right: 1px solid rgba(255,255,255,0.12);
}

.book-face {
    flex: 1;
    padding: 1.1rem 1.25rem 1.1rem 1rem;
    color: #FFF8F0;
}

.book-series {
    font-size: 20px;
    font-weight: 600;
    opacity: 0.82;
    letter-spacing: 0.12em;
    margin-bottom: 0.35rem;
}

.book-title {
    font-size: 1.85rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    line-height: 1.2;
}

.book-cover-compact .book-title { font-size: 1.5rem; }

.book-subtitle {
    margin-top: 0.35rem;
    font-size: 0.88rem;
    opacity: 0.88;
}

.group-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
}

.group-grid-single { margin-top: 0.25rem; }

.book-page-section { margin-top: 1.5rem; }

.catalog-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.catalog-section-head .section-heading { margin-bottom: 0; }

.catalog-edit-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.42rem 0.8rem;
    border: 1.5px solid var(--border);
    border-radius: 999px;
    background: var(--bg-card);
    color: var(--primary);
    font-size: 0.82rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, border-color 0.15s, transform 0.15s;
    box-shadow: 0 2px 8px rgba(139, 69, 19, 0.06);
}

.catalog-edit-btn:active { transform: scale(0.96); }

.catalog-edit-btn[aria-pressed="true"] {
    background: rgba(139, 69, 19, 0.1);
    border-color: var(--primary-light);
    color: var(--primary);
}

.section-heading {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 0.75rem;
    letter-spacing: 0.06em;
}

.catalog-wrap {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.catalog-group + .catalog-group {
    border-top: 1px solid var(--border);
}

.catalog-group-label {
    padding: 0.65rem 1rem;
    font-size: 0.82rem;
    color: var(--text-muted);
    background: rgba(139, 69, 19, 0.04);
    border-bottom: 1px solid var(--border);
}

.catalog-list { display: flex; flex-direction: column; }

.catalog-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.catalog-item-link {
    flex: 1;
    display: flex;
    align-items: baseline;
    gap: 0.65rem;
    min-width: 0;
    padding: 0.75rem 1rem;
    color: var(--text);
}

.catalog-wrap.is-edit-mode .catalog-item-link {
    padding-right: 0.35rem;
}

.catalog-item-bookmark {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    margin-right: 0.35rem;
    padding: 0;
    border-radius: 50%;
    border: 1.5px solid rgba(196, 149, 106, 0.35);
    background: #fff;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.15s;
}

.catalog-item-bookmark:active {
    transform: scale(0.94);
}

.catalog-item-bookmark.is-active {
    color: var(--primary);
    border-color: var(--primary-light);
    background: rgba(139, 69, 19, 0.1);
}

.catalog-item-bookmark.is-active svg {
    fill: rgba(139, 69, 19, 0.18);
}

.catalog-item.is-bookmarked {
    background: rgba(139, 69, 19, 0.04);
}

.catalog-item.is-bookmarked .catalog-title {
    font-weight: 600;
}

.catalog-wrap.is-edit-mode .catalog-item-bookmark {
    margin-right: 0.15rem;
}

.catalog-item-edit {
    display: none;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    margin-right: 0.65rem;
    border-radius: 50%;
    border: 1.5px solid rgba(196, 149, 106, 0.45);
    background: #fff;
    color: var(--primary);
    transition: background 0.15s, transform 0.15s;
}

.catalog-wrap.is-edit-mode .catalog-item-edit {
    display: inline-flex;
}

.catalog-item-edit:active {
    transform: scale(0.94);
    background: rgba(139, 69, 19, 0.08);
}

.catalog-item:last-child { border-bottom: none; }

.catalog-item-link:active { background: rgba(139, 69, 19, 0.06); }

.catalog-lesson {
    flex-shrink: 0;
    min-width: 4.2rem;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.catalog-title {
    font-size: 0.95rem;
    color: var(--primary);
}

.group-card {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.85rem 0.9rem;
    box-shadow: var(--shadow);
    transition: transform 0.15s, border-color 0.15s;
}

.group-card:active { transform: scale(0.98); }
.group-card:hover { border-color: var(--primary-light); }

.group-card-name {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.2rem;
}

.group-card-theme {
    font-size: 0.82rem;
    color: var(--text);
    line-height: 1.45;
    margin-bottom: 0.25rem;
}

.group-card-range {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.group-card-count {
    margin-top: 0.45rem;
    font-size: 0.72rem;
    color: var(--primary-light);
    font-weight: 600;
}

.group-nav-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.85rem;
}

.group-nav-current {
    text-align: center;
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 600;
}

.group-nav-counter {
    color: var(--primary-light);
    font-weight: 500;
}

.group-nav-btn {
    display: inline-block;
    padding: 0.55rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--primary);
    font-size: 0.82rem;
    font-weight: 600;
    text-align: center;
    box-shadow: var(--shadow);
    white-space: nowrap;
}

.group-nav-btn.is-disabled {
    opacity: 0.45;
    pointer-events: none;
}

.reader-header .group-nav-row {
    margin: 0;
}

.nav-back-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.85rem;
}

.nav-back {
    display: inline-block;
    font-size: 0.88rem;
    color: var(--primary);
    font-weight: 600;
}

.nav-back-muted { color: var(--text-muted); font-weight: 500; }

.breadcrumb-link { color: var(--primary-light); }

.group-section { margin-bottom: 1.5rem; }
.group-section-active { margin-bottom: 0; }
.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 ── */
.page-reader {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    background:
        radial-gradient(ellipse 120% 80% at 50% -20%, rgba(196, 149, 106, 0.12), transparent 55%),
        var(--bg);
}

.reader-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(255, 252, 247, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(232, 221, 208, 0.85);
    padding:
        calc(0.65rem + env(safe-area-inset-top, 0px))
        1rem
        0.75rem;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset;
}

.reader-topbar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.65rem;
}

.reader-back {
    font-size: 0.88rem;
    color: var(--primary-light);
    font-weight: 600;
    white-space: nowrap;
    padding: 0.35rem 0;
}

.reader-title {
    font-size: 1.05rem;
    color: var(--primary);
    font-weight: 700;
    text-align: center;
    line-height: 1.35;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    letter-spacing: 0.02em;
}

.reader-settings-btn {
    width: 2.25rem;
    height: 2.25rem;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--bg);
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.15s;
}

.reader-settings-btn:active { transform: scale(0.94); background: rgba(139, 69, 19, 0.06); }

.reader-group-nav {
    margin-top: 0.65rem;
}

.reader-group-nav .group-nav-row {
    margin-bottom: 0;
    gap: 0.4rem;
}

.reader-group-nav .group-nav-btn {
    padding: 0.4rem 0.65rem;
    font-size: 0.75rem;
    box-shadow: none;
    background: rgba(139, 69, 19, 0.05);
}

.reader-group-nav .group-nav-current {
    font-size: 0.75rem;
}

.reader-progress-wrap {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    margin-top: 0.75rem;
}

.reader-progress-bar {
    flex: 1;
    height: 3px;
    background: rgba(139, 69, 19, 0.1);
    border-radius: 999px;
    overflow: hidden;
}

.reader-progress-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--primary-light), var(--primary));
    border-radius: 999px;
    transition: width 0.35s ease;
}

.reader-progress-text {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    min-width: 2.8rem;
    text-align: right;
}

.sentence-thumbs {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 0.45rem;
    overflow-x: auto;
    padding: 0;
    margin-top: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.sentence-thumbs::-webkit-scrollbar { display: none; }

.sentence-thumbs .thumb {
    flex-shrink: 0;
    min-width: 1.5rem;
    height: 1.5rem;
    padding: 0 0.35rem;
    border-radius: 999px;
    border: 1.5px solid var(--border);
    background: var(--bg);
    font-size: 0.72rem;
    font-weight: 600;
    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;
    box-shadow: 0 2px 8px rgba(139, 69, 19, 0.25);
}

.sentence-thumbs .thumb.done:not(.active) {
    border-color: var(--primary-light);
    color: var(--primary);
    background: rgba(196, 149, 106, 0.1);
}

.sentence-thumbs .thumb-full {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.05em;
}

.sentence-thumbs .thumb-full.active {
    background: var(--accent);
    border-color: var(--accent);
}

.reader-main {
    flex: 1;
    max-width: 520px;
    width: 100%;
    margin: 0 auto;
    padding: 0.85rem 1rem calc(6.5rem + env(safe-area-inset-bottom));
}

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

.sentence-card {
    background: var(--bg-card);
    border: 1px solid rgba(232, 221, 208, 0.9);
    border-radius: calc(var(--radius) + 4px);
    box-shadow:
        0 1px 2px rgba(139, 69, 19, 0.04),
        0 8px 32px rgba(139, 69, 19, 0.08);
    overflow: hidden;
    animation: fadeIn 0.35s ease;
    position: relative;
}

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

.card-sentence-badge {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 2;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--primary);
    background: rgba(255, 252, 247, 0.92);
    backdrop-filter: blur(6px);
    padding: 0.3rem 0.65rem;
    border-radius: 999px;
    border: 1px solid rgba(232, 221, 208, 0.9);
    letter-spacing: 0.04em;
}

.card-image-wrap {
    width: 100%;
    aspect-ratio: 4 / 3;
    background: linear-gradient(165deg, #F5EDE3 0%, #E8DDD0 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.88rem;
    text-align: center;
    padding: 2rem;
    line-height: 1.6;
}

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

.card-text {
    padding: 1.15rem 1.25rem 1.35rem;
}

.original-text {
    font-size: 1.28rem;
    line-height: 2.05;
    text-align: center;
    color: var(--primary);
    font-weight: 700;
    letter-spacing: 0.12em;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px dashed rgba(232, 221, 208, 0.95);
}

.original-text .char-pinyin-note,
.fulltext-original .char-pinyin-note {
    font-size: 0.72em;
    font-weight: 600;
    color: #c45a2a;
    letter-spacing: 0.02em;
}

.word-pair .char-py {
    font-size: 0.62rem;
    font-weight: 600;
    color: #c45a2a;
    line-height: 1.1;
    min-height: 0.85rem;
    white-space: nowrap;
}

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

.word-pair {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 1.75rem;
    padding: 0.2rem 0.08rem;
}

.word-pair .char-orig {
    font-size: 1.2rem;
    color: var(--primary);
    font-weight: 700;
    line-height: 1.35;
}

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

.full-translation {
    font-size: 0.92rem;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.75;
    padding-top: 0.85rem;
    border-top: 1px solid rgba(232, 221, 208, 0.85);
}

.fulltext-card .card-text { padding: 0 1.25rem 1.5rem; }

.fulltext-header {
    padding: 1.25rem 1.25rem 0.85rem;
    text-align: center;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, #F5EDE3 0%, var(--bg-card) 100%);
}

.fulltext-badge {
    display: inline-block;
    font-size: 0.78rem;
    color: var(--accent);
    background: rgba(192, 57, 43, 0.08);
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-weight: 700;
    letter-spacing: 0.08em;
}

.fulltext-meta {
    margin-top: 0.55rem;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.fulltext-intro {
    margin-top: 0.4rem;
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.6;
}

.fulltext-body { padding-top: 1.15rem; }

.fulltext-original {
    font-size: 1.22rem;
    line-height: 2.15;
    letter-spacing: 0.1em;
    color: var(--text);
}

.fulltext-original.is-verse {
    text-align: center;
    padding: 0.25rem 0.5rem 0.5rem;
}

.fulltext-original.is-prose {
    text-align: left;
    letter-spacing: 0.04em;
}

.fulltext-original .poem-line {
    display: block;
    margin: 0;
    padding: 0.12em 0;
}

.fulltext-original .poem-line-blank {
    height: 0.75em;
    padding: 0;
}

.fulltext-translation {
    margin-top: 1.15rem;
    padding-top: 1rem;
    border-top: 1px dashed var(--border);
    font-size: 0.95rem;
    line-height: 1.9;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

.fulltext-translation.is-verse {
    text-align: center;
}

.fulltext-translation.is-prose {
    text-align: left;
}

.fulltext-translation .poem-line {
    display: block;
    margin: 0;
    padding: 0.28em 0;
}

.fulltext-translation .poem-line-blank {
    height: 0.55em;
    padding: 0;
}

.reader-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 25;
    padding: 0.55rem 0.85rem calc(0.65rem + env(safe-area-inset-bottom));
    background: rgba(255, 252, 247, 0.94);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid rgba(232, 221, 208, 0.9);
    display: flex;
    align-items: center;
    gap: 0.55rem;
    max-width: 520px;
    margin: 0 auto;
}

.reader-footer-inner {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
    min-width: 0;
}

.reader-icon-btn {
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    border: 2.5px solid var(--border);
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-family: inherit;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.15s, background 0.15s, border-color 0.15s, color 0.15s;
    box-shadow: 0 3px 0 rgba(139, 69, 19, 0.1), 0 2px 10px rgba(139, 69, 19, 0.06);
}

.reader-icon-btn:active:not(:disabled) {
    transform: scale(0.9) translateY(2px);
    box-shadow: 0 1px 0 rgba(139, 69, 19, 0.08);
}

.reader-icon-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    box-shadow: none;
}

.reader-icon-svg {
    display: block;
    flex-shrink: 0;
}

.reader-icon-btn-nav {
    color: var(--primary-light);
    border-color: rgba(196, 149, 106, 0.45);
    background: #fff;
}

.reader-icon-btn-primary {
    background: linear-gradient(145deg, #A05A2C 0%, var(--primary) 100%);
    border-color: #7A3E10;
    color: #FFF8F0;
    box-shadow: 0 3px 0 #5C2E0A, 0 3px 12px rgba(139, 69, 19, 0.22);
}

.reader-icon-btn-primary:active:not(:disabled) {
    box-shadow: 0 1px 0 #5C2E0A;
}

.reader-icon-btn-primary.is-fulltext-mode .icon-next { display: none; }
.reader-icon-btn-primary.is-fulltext-mode .icon-fulltext { display: block; }
.reader-icon-btn-primary .icon-fulltext { display: none; }

.reader-icon-btn-read {
    width: 3.1rem;
    height: 3.1rem;
    border-width: 2.5px;
    border-color: #7A3E10;
    color: #FFF8F0;
    box-shadow: 0 4px 0 #5C2E0A, 0 4px 14px rgba(139, 69, 19, 0.25);
}

.reader-icon-btn-read:active:not(:disabled) {
    box-shadow: 0 1px 0 #5C2E0A;
}

.reader-icon-btn-read .icon-stop,
.reader-icon-btn-read .icon-loading { display: none; }
.reader-icon-btn-read.is-playing .icon-read { display: none; }
.reader-icon-btn-read.is-playing .icon-stop { display: block; }
.reader-icon-btn-read.is-loading .icon-read,
.reader-icon-btn-read.is-loading .icon-stop { display: none; }
.reader-icon-btn-read.is-loading .icon-loading {
    display: block;
    animation: reader-spin 0.8s linear infinite;
}

@keyframes reader-spin {
    to { transform: rotate(360deg); }
}

.reader-icon-btn-pdf {
    color: var(--accent);
    border-color: rgba(192, 57, 43, 0.28);
    background: rgba(255, 245, 243, 0.95);
    box-shadow: 0 3px 0 rgba(192, 57, 43, 0.12), 0 2px 10px rgba(192, 57, 43, 0.08);
}

.reader-icon-btn-pdf:active:not(:disabled) {
    background: rgba(192, 57, 43, 0.1);
    box-shadow: 0 1px 0 rgba(192, 57, 43, 0.1);
}

.tts-settings-toggle { display: none; }

.tts-settings-backdrop {
    position: fixed;
    inset: 0;
    border: none;
    padding: 0;
    margin: 0;
    background: rgba(61, 43, 31, 0.42);
    z-index: 35;
    cursor: default;
}

.tts-settings-panel {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(5rem + env(safe-area-inset-bottom));
    width: calc(100% - 2rem);
    max-width: 448px;
    max-height: min(72dvh, calc(100dvh - 7rem - env(safe-area-inset-top)));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(139, 69, 19, 0.18);
    padding: 1rem 1.1rem calc(1rem + env(safe-area-inset-bottom));
    z-index: 40;
}
.tts-settings-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.85rem;
    font-weight: 600;
    color: var(--primary);
}
.tts-settings-close {
    border: none;
    background: none;
    font-size: 1.4rem;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.2rem 0.4rem;
}
.tts-label { display: block; margin-bottom: 0.85rem; }
.tts-label-text { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.35rem; }
.tts-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.35rem;
}
.tts-speed-meta { font-size: 0.8rem; color: var(--text-muted); }
.tts-speed-meta strong { color: var(--primary); font-size: 0.95rem; }
.tts-select {
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
}
.tts-speed-range {
    width: 100%;
    accent-color: var(--primary);
    margin: 0.25rem 0 0.5rem;
}
.tts-speed-presets {
    display: flex;
    gap: 0.5rem;
}
.tts-speed-preset {
    flex: 1;
    padding: 0.45rem 0;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg);
    color: var(--text-muted);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
}
.tts-speed-preset.active {
    border-color: var(--primary);
    background: rgba(139, 69, 19, 0.08);
    color: var(--primary);
    font-weight: 600;
}
.tts-preview-btn {
    width: 100%;
    max-width: none;
    margin-top: 0.25rem;
    padding: 0.65rem;
    font-size: 0.9rem;
}
.tts-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.85rem;
}
.tts-toggle-row .tts-label-text { margin-bottom: 0; }
.tts-switch-wrap {
    position: relative;
    display: inline-flex;
    cursor: pointer;
}
.tts-switch-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}
.tts-switch {
    display: block;
    width: 2.75rem;
    height: 1.55rem;
    border-radius: 999px;
    background: var(--border);
    transition: background 0.2s;
    position: relative;
}
.tts-switch::after {
    content: '';
    position: absolute;
    top: 0.15rem;
    left: 0.15rem;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    transition: transform 0.2s;
}
.tts-switch-input:checked + .tts-switch {
    background: var(--primary);
}
.tts-switch-input:checked + .tts-switch::after {
    transform: translateX(1.2rem);
}

body.tts-settings-open {
    overflow: hidden;
}

.btn {
    flex: 1;
    max-width: 120px;
    padding: 0.75rem 0.4rem;
    border: none;
    border-radius: 12px;
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.15s, background 0.2s;
}
.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; }
.btn-pdf { flex: 0.65; max-width: 72px; font-size: 0.85rem; }
.btn-read {
    background: linear-gradient(145deg, #C4956A 0%, #8B4513 100%);
    color: #FFF8F0;
}
.btn-read.is-loading { opacity: 0.85; pointer-events: none; }
.btn-read.is-playing {
    background: linear-gradient(145deg, #E8A598 0%, #C0392B 100%);
    border-color: #A93226;
    box-shadow: 0 4px 0 #8B2917, 0 0 0 3px rgba(192, 57, 43, 0.18);
}
.btn-read.is-loop:not(.is-playing):not(.is-loading) {
    box-shadow: 0 4px 0 #5C2E0A, 0 0 0 3px rgba(196, 149, 106, 0.35);
}

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

.toast {
    position: fixed; bottom: calc(5.5rem + env(safe-area-inset-bottom)); 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); }

/* ── Tablet 竖屏 / 中等宽度 ── */
@media (min-width: 768px) {
    .home-main, .article-list { max-width: 720px; }
    .reader-main { max-width: 680px; }
    .reader-header {
        max-width: 680px;
        width: 100%;
        margin-left: auto;
        margin-right: auto;
    }
    .reader-footer {
        max-width: 680px;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: 100%;
        border-radius: var(--radius) var(--radius) 0 0;
    }
    .group-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .original-text { font-size: 1.55rem; line-height: 2.15; }
    .word-pair { min-width: 2rem; padding: 0.25rem 0.12rem; }
    .word-pair .char-orig { font-size: 1.42rem; }
    .word-pair .char-trans { font-size: 0.78rem; }
    .word-pair .char-py { font-size: 0.72rem; }
    .full-translation { font-size: 1.05rem; line-height: 1.85; }
    .fulltext-original { font-size: 1.38rem; line-height: 2.15; }
    .fulltext-translation { font-size: 1.05rem; line-height: 1.95; }
    .module-grid { gap: 1.25rem; }
    .bookshelf-grid {
        flex-direction: row;
        justify-content: center;
        gap: 1.5rem;
    }
    .bookshelf-grid .book-link { flex: 0 1 280px; }
    .tts-settings-panel {
        max-width: 420px;
        left: 50%;
        transform: translateX(-50%);
        width: min(420px, calc(100% - 2rem));
    }
}

@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; }
    .article-list { max-width: 860px; }
    .catalog-wrap {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 1rem 1.25rem;
        align-items: start;
    }
    .catalog-group { margin-bottom: 0; }
}

/* ── iPad / 平板横版：阅读器图文并排，充分利用横向空间 ── */
@media (orientation: landscape) and (min-width: 740px) {
    .page-reader {
        --reader-chrome: 8.75rem;
    }

    .reader-header {
        max-width: min(1100px, 100%);
        width: 100%;
        margin-left: auto;
        margin-right: auto;
        padding-top: calc(0.45rem + env(safe-area-inset-top, 0px));
        padding-bottom: 0.5rem;
        padding-left: max(1rem, env(safe-area-inset-left, 0px));
        padding-right: max(1rem, env(safe-area-inset-right, 0px));
    }

    .reader-title { font-size: 1.12rem; }
    .sentence-thumbs { gap: 0.55rem; }
    .sentence-thumbs .thumb {
        min-width: 1.7rem;
        height: 1.7rem;
        font-size: 0.78rem;
    }

    .reader-main {
        max-width: min(1100px, 100%);
        padding:
            0.65rem
            max(1rem, env(safe-area-inset-right, 0px))
            calc(5.25rem + env(safe-area-inset-bottom, 0px))
            max(1rem, env(safe-area-inset-left, 0px));
    }

    .reader-footer {
        max-width: min(1100px, 100%);
        padding-left: max(0.75rem, env(safe-area-inset-left, 0px));
        padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
    }

    /* 分句卡：左图右文 */
    .sentence-card:not(.fulltext-card) {
        display: grid;
        grid-template-columns: minmax(280px, 0.92fr) minmax(300px, 1.08fr);
        grid-template-rows: minmax(0, 1fr);
        align-items: stretch;
        height: calc(100dvh - var(--reader-chrome) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        max-height: calc(100dvh - var(--reader-chrome) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        min-height: 0;
    }

    .sentence-card:not(.fulltext-card) .card-sentence-badge {
        top: 0.65rem;
        left: 0.65rem;
    }

    .sentence-card:not(.fulltext-card) .card-image-wrap {
        aspect-ratio: auto;
        height: 100%;
        min-height: 0;
        max-height: none;
        align-self: stretch;
        border-right: 1px solid rgba(232, 221, 208, 0.9);
    }

    .sentence-card:not(.fulltext-card) .card-text {
        display: flex;
        flex-direction: column;
        justify-content: center;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 1rem 1.35rem 1.15rem;
        max-height: inherit;
    }

    .sentence-card:not(.fulltext-card) .original-text {
        font-size: clamp(1.5rem, 2.8vw, 1.9rem);
        line-height: 2.15;
        margin-bottom: 0.85rem;
        padding-bottom: 0.85rem;
    }

    .sentence-card:not(.fulltext-card) .word-pair {
        min-width: 2.15rem;
        padding: 0.28rem 0.14rem;
    }

    .sentence-card:not(.fulltext-card) .word-pair .char-orig {
        font-size: clamp(1.4rem, 2.4vw, 1.7rem);
    }

    .sentence-card:not(.fulltext-card) .word-pair .char-trans {
        font-size: 0.85rem;
    }

    .sentence-card:not(.fulltext-card) .word-pair .char-py {
        font-size: 0.78rem;
    }

    .sentence-card:not(.fulltext-card) .full-translation {
        font-size: clamp(1.05rem, 1.8vw, 1.2rem);
        line-height: 1.9;
    }

    .fulltext-card {
        max-height: calc(100dvh - var(--reader-chrome) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .fulltext-original {
        font-size: clamp(1.35rem, 2.4vw, 1.65rem);
        line-height: 2.2;
    }

    .fulltext-translation {
        font-size: clamp(1.05rem, 1.8vw, 1.2rem);
        line-height: 1.95;
    }

    .tts-settings-panel {
        bottom: calc(4.75rem + env(safe-area-inset-bottom));
        max-height: min(70dvh, 520px);
        overflow-y: auto;
    }

    /* 书架 / 目录 */
    .article-list {
        max-width: min(980px, 100%);
        padding-left: max(1.25rem, env(safe-area-inset-left, 0px));
        padding-right: max(1.25rem, env(safe-area-inset-right, 0px));
    }

    .bookshelf-grid {
        flex-direction: row;
        justify-content: center;
        gap: 2rem;
        padding: 0.5rem 0 1rem;
    }

    .bookshelf-grid .book-link { flex: 0 1 300px; }

    .book-cover-compact {
        max-width: 420px;
        margin-left: auto;
        margin-right: auto;
    }

    .catalog-wrap {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.85rem 1.5rem;
        align-items: start;
    }

    /* 首页模块 */
    .home-main {
        max-width: min(960px, 100%);
        padding-left: max(1.25rem, env(safe-area-inset-left, 0px));
        padding-right: max(1.25rem, env(safe-area-inset-right, 0px));
    }

    .module-grid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 1rem;
    }

    .site-header {
        padding: 1.6rem 1.5rem 1.35rem;
    }
}

/* 大屏 iPad Pro 横版（更宽） */
@media (orientation: landscape) and (min-width: 1100px) {
    .reader-header {
        max-width: min(1180px, 100%);
    }

    .reader-main,
    .reader-footer {
        max-width: min(1180px, 100%);
    }

    .sentence-card:not(.fulltext-card) {
        grid-template-columns: minmax(340px, 1fr) minmax(380px, 1.1fr);
    }

    .module-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .catalog-wrap {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .article-list { max-width: min(1080px, 100%); }
}

/* 横版且高度偏矮：进一步压缩垂直空间 */
@media (orientation: landscape) and (min-width: 740px) and (max-height: 700px) {
    .page-reader { --reader-chrome: 7.5rem; }

    .reader-header {
        padding-top: calc(0.3rem + env(safe-area-inset-top, 0px));
        padding-bottom: 0.35rem;
    }

    .reader-main {
        padding-top: 0.4rem;
        padding-bottom: calc(4.6rem + env(safe-area-inset-bottom, 0px));
    }

    .sentence-card:not(.fulltext-card) .card-text {
        padding: 0.75rem 1.1rem 0.9rem;
    }

    .sentence-card:not(.fulltext-card) .original-text {
        font-size: 1.38rem;
        line-height: 2;
        margin-bottom: 0.55rem;
        padding-bottom: 0.55rem;
    }

    .sentence-card:not(.fulltext-card) .word-pair .char-orig { font-size: 1.28rem; }
    .sentence-card:not(.fulltext-card) .word-pair .char-trans { font-size: 0.78rem; }
    .sentence-card:not(.fulltext-card) .full-translation {
        font-size: 1rem;
        padding-top: 0.55rem;
    }

    .fulltext-original { font-size: 1.28rem; }
    .fulltext-translation { font-size: 1rem; }
}

