/* 全局变量与基础排版 */
:root {
    --reader-font-size: 19px;
    --reader-line-height: 1.85;
    --reader-font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --dock-height: 84px;
}

/* 主题调色板 */
body.theme-parchment {
    --bg-page: #f6f1e5;
    --bg-surface: #ede5d3;
    --bg-card: #fdfaf3;
    --text-primary: #33271d;
    --text-secondary: #705e4d;
    --border-color: #dfd4bf;
    --active-highlight: #ffebb3;
    --active-border: #f59e0b;
    --dock-bg: rgba(246, 241, 229, 0.88);
}

body.theme-white {
    --bg-page: #ffffff;
    --bg-surface: #f8fafc;
    --bg-card: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --active-highlight: #e0e7ff;
    --active-border: #6366f1;
    --dock-bg: rgba(255, 255, 255, 0.88);
}

body.theme-gray {
    --bg-page: #eaedf1;
    --bg-surface: #dde2e8;
    --bg-card: #f4f6f8;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #cbd5e1;
    --active-highlight: #dbeafe;
    --active-border: #3b82f6;
    --dock-bg: rgba(234, 237, 241, 0.88);
}

body.theme-dark {
    --bg-page: #121316;
    --bg-surface: #1a1b20;
    --bg-card: #22242b;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --border-color: #2e323b;
    --active-highlight: #2e384d;
    --active-border: #818cf8;
    --dock-bg: rgba(18, 19, 22, 0.88);
}

body.theme-green {
    --bg-page: #eaf3ea;
    --bg-surface: #dcebdc;
    --bg-card: #f4faf4;
    --text-primary: #193819;
    --text-secondary: #4a6b4a;
    --border-color: #c9dec9;
    --active-highlight: #cce9cc;
    --active-border: #10b981;
    --dock-bg: rgba(234, 243, 234, 0.88);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-page);
    color: var(--text-primary);
    font-family: var(--reader-font-family);
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
    min-height: 100vh;
    padding-bottom: calc(var(--dock-height) + 40px);
}

/* 顶部导航栏 */
.header-bar {
    position: sticky;
    top: 0;
    z-index: 50;
    height: 56px;
    background: var(--dock-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-center {
    flex: 1;
    text-align: center;
    overflow: hidden;
    padding: 0 12px;
}

.header-title-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.header-book {
    font-size: 15px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 280px;
}

.header-chapter {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 240px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
}

.icon-btn:hover {
    background: var(--bg-surface);
}

.icon-btn:active {
    transform: scale(0.95);
}

/* 阅读器主体区域 */
.reader-wrapper {
    max-width: 820px;
    margin: 24px auto 0;
    padding: 0 20px;
}

.chapter-heading {
    margin-bottom: 28px;
    padding-bottom: 14px;
    border-bottom: 1px dashed var(--border-color);
}

.chapter-title {
    font-size: calc(var(--reader-font-size) * 1.35);
    font-weight: 800;
    line-height: 1.4;
    color: var(--text-primary);
}

.reader-article {
    font-size: var(--reader-font-size);
    line-height: var(--reader-line-height);
    text-align: justify;
}

.cue-time {
    display: inline-block;
    min-width: 4.8em;
    margin-right: 0.55em;
    font-variant-numeric: tabular-nums;
    font-size: 0.72em;
    letter-spacing: 0.02em;
    color: var(--text-secondary);
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    vertical-align: 0.15em;
}

.reader-p {
    margin-bottom: 1.25em;
    text-indent: 2em;
}

.reader-p.timed-line,
.reader-p.script-line,
.reader-p.script-narr {
    text-indent: 0;
    margin-bottom: 0.7em;
}

.speaker-name {
    display: inline-block;
    min-width: 4.2em;
    margin-right: 0.45em;
    font-size: 0.82em;
    font-weight: 700;
    color: var(--text-secondary);
}

.script-skipped {
    opacity: 0.4;
}

.cast-list,
#cast-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

.cast-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px 8px;
    align-items: center;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-surface);
}

.cast-head {
    min-width: 0;
}

.cast-name {
    font-size: 14px;
    font-weight: 700;
}

.cast-count {
    color: var(--text-secondary);
    font-size: 11px;
}

.cast-skip {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
}

.cast-engine,
.cast-voice {
    grid-column: 1 / -1;
}

/* 句子高亮与点击反馈 */
.sentence {
    border-radius: 4px;
    padding: 2px 2px;
    cursor: pointer;
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
    display: inline;
}

.sentence:hover {
    background-color: var(--bg-surface);
}

.sentence.reading-active {
    background-color: var(--active-highlight);
    box-shadow: 0 0 0 2px var(--active-border);
    font-weight: 600;
    color: var(--text-primary);
    border-radius: 4px;
}

/* 底部悬浮控制栏 (Dock) */
.audio-dock-container {
    position: fixed;
    bottom: 16px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    z-index: 60;
    padding: 0 16px;
    pointer-events: none;
}

.audio-dock {
    pointer-events: auto;
    background: var(--dock-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.15);
    border-radius: 48px;
    height: var(--dock-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 14px;
    max-width: 680px;
    width: 100%;
}

.dock-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dock-center {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex: 1;
}

.dock-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-ctrl {
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.1s;
}

.btn-ctrl:hover {
    background: var(--bg-surface);
}

.btn-play-main {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--primary-color);
    color: #ffffff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
    transition: transform 0.15s, background 0.15s, box-shadow 0.2s;
}

.btn-play-main:hover {
    background: var(--primary-hover);
    transform: scale(1.04);
}

.btn-play-main.is-playing {
    background: #ef4444;
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.4);
}

.badge-speed, .badge-progress {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-surface);
    padding: 4px 10px;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.timer-pill {
    font-size: 12px;
    color: #f59e0b;
    font-weight: 700;
    display: none;
    white-space: nowrap;
}

/* 抽屉样式 (Drawer) */
.drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.drawer-overlay.overlay-open {
    opacity: 1;
    pointer-events: auto;
}

.drawer {
    position: fixed;
    top: 0;
    bottom: 0;
    width: 360px;
    max-width: 88vw;
    background: var(--bg-card);
    z-index: 101;
    box-shadow: 0 0 24px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.drawer-left {
    left: 0;
    transform: translateX(-100%);
}

.drawer-right {
    right: 0;
    transform: translateX(100%);
}

.drawer.drawer-open {
    transform: translateX(0);
}

.drawer-header {
    height: 56px;
    padding: 0 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}

.drawer-header h3 {
    font-size: 17px;
    font-weight: 700;
}

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

/* 目录项 */
.toc-search {
    width: 100%;
    padding: 9px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 14px;
    margin-bottom: 12px;
    outline: none;
}

.toc-item {
    padding: 12px 14px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    margin-bottom: 4px;
    transition: background 0.15s;
}

.toc-item:hover {
    background: var(--bg-surface);
}

.toc-item.active {
    background: var(--active-highlight);
    font-weight: 700;
}

.toc-badge {
    font-size: 12px;
    color: var(--primary-color);
    font-weight: 700;
}

/* 书架卡片 */
.book-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.2s;
}

.book-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary-color);
}

.book-card.active-book {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 1px var(--primary-color);
}

.book-card-title {
    font-size: 16px;
    font-weight: 700;
}

.book-card-meta {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    gap: 12px;
}

.book-card-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.btn-book-read {
    background: var(--primary-color);
    color: #fff;
    border: none;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
}

.btn-book-delete {
    background: transparent;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 16px;
    padding: 4px 8px;
}

.bookshelf-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.btn-action-primary {
    flex: 1;
    background: var(--primary-color);
    color: #fff;
    border: none;
    padding: 10px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-action-secondary {
    flex: 1;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

/* 设置项表单 */
.setting-section {
    margin-bottom: 22px;
}

.setting-section-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 10px;
    letter-spacing: 0.5px;
}

.setting-item {
    margin-bottom: 14px;
}

.setting-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
}

.setting-control {
    width: 100%;
    padding: 9px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
}

.setting-hint {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 10px;
}

.setting-hint.err {
    color: #dc2626;
}

.voice-add-actions {
    display: flex;
    margin-bottom: 8px;
}

.voice-search-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.voice-search-row .setting-control {
    flex: 1;
}

.voice-search-row .btn-action-secondary {
    flex: 0 0 auto;
    padding: 9px 14px;
}

.voice-result-list,
#custom-voice-list,
#fish-search-results {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.voice-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-surface);
}

.voice-row-main {
    min-width: 0;
}

.voice-row-title {
    font-size: 13px;
    font-weight: 600;
}

.voice-row-id {
    color: var(--text-secondary);
    font-size: 11px;
    word-break: break-all;
}

.btn-voice-mini {
    flex: 0 0 auto;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-primary);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.btn-voice-mini.danger {
    color: #dc2626;
}

.voice-empty {
    font-size: 12px;
    color: var(--text-secondary);
    padding: 4px 0;
}

.theme-selector {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.theme-chip {
    height: 40px;
    border-radius: 8px;
    border: 2px solid transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    transition: transform 0.15s, border-color 0.15s;
}

.theme-chip:hover {
    transform: scale(1.05);
}

.theme-chip.active {
    border-color: var(--primary-color);
}

.chip-parchment { background: #f6f1e5; color: #33271d; border: 1px solid #dfd4bf; }
.chip-white { background: #ffffff; color: #000; border: 1px solid #cbd5e1; }
.chip-gray { background: #eaedf1; color: #1e293b; border: 1px solid #cbd5e1; }
.chip-dark { background: #121316; color: #fff; border: 1px solid #333; }
.chip-green { background: #eaf3ea; color: #193819; border: 1px solid #c9dec9; }

/* 模态框 (Modal) */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 120;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-overlay.modal-open {
    display: flex;
}

.modal-box {
    background: var(--bg-card);
    width: 100%;
    max-width: 540px;
    border-radius: 16px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-box textarea {
    width: 100%;
    height: 220px;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    outline: none;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* 响应式适配 */
@media (max-width: 640px) {
    .audio-dock {
        height: 72px;
        padding: 0 12px;
        gap: 8px;
    }
    .btn-play-main {
        width: 46px;
        height: 46px;
    }
    .badge-progress {
        display: none;
    }
    .reader-wrapper {
        padding: 0 16px;
    }
}
