/* ==================== 颜色变量定义 ==================== */
:root {
    --primary: #007bff;
    --primary-dark: #0056b3;
    --accent: #ff69b4;
    --bg-light: #f8f9fa;
    --text-main: #333;
    --text-light: #6c757d;
    --border: #dee2e6;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --radius: 6px;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* ==================== 基础样式 ==================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: #fff;
    color: var(--text-main);
    line-height: 1.5;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

h1 {
    text-align: center;
    margin-bottom: 1.5rem;
    font-size: 1.8em;
    font-weight: 400;
    background: linear-gradient(135deg, var(--accent), var(--primary));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

a {
    color: var(--primary);
    text-decoration: none;
    cursor: pointer;
}

/* ==================== 布局 ==================== */
.layout {
    display: grid;
    grid-template-columns: 1fr 420px;
    gap: 16px;
}

@media (max-width: 800px) {
    .layout {
        grid-template-columns: 1fr;
    }
}

/* ==================== 左侧输入区 ==================== */
.editor-wrapper {
    position: relative;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding-top: 10px;
}

textarea {
    width: 100%;
    min-height: 400px;
    padding: 16px;
    border: none;
    font-size: 16px;
    line-height: 1.6;
    resize: vertical;
    transition: border-color 0.2s;
}

textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-light);
    font-size: 14px;
}

.toolbar-group {
    display: flex;
    gap: 10px;
    align-items: center;
}

.btn-text {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-weight: 600;
}

.btn-text:hover {
    text-decoration: underline;
}

.pause-input {
    width: 80px;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    text-align: center;
}

/* ==================== 右侧控制区 ==================== */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* 标签页 */
.tabs {
    display: flex;
    background: var(--bg-light);
    padding: 4px;
    border-radius: var(--radius);
}

.tab-btn {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    font-weight: 600;
    color: var(--text-light);
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.tab-btn.active {
    background: #fff;
    color: var(--primary);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.tab-content {
    display: none;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

/* 表单控件 */
.control-group {
    margin-bottom: 16px;
}

label {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-light);
    margin-bottom: 6px;
}

select,
input[type=text],
input[type=number] {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    background: #fff;
    color: var(--text-main);
    outline-color: var(--primary);
}

/* 滑块 */
.slider-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.slider-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.range-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}

input[type=range] {
    flex: 1;
    accent-color: var(--primary);
}

.val-display {
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    width: 40px;
    text-align: right;
}

/* 选项折叠 */
details {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    margin-bottom: 16px;
}

summary {
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
}

.checkbox-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 10px;
}

.checkbox-item {
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

/* 按钮通用 */
.action-row {
    display: flex;
    gap: 10px;
    align-items: stretch;
}

.btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.1s, box-shadow 0.2s;
}

.btn:active {
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.25);
}

.btn-nano {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
}

.btn-nano:hover {
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-search {
    background: var(--warning);
    color: #fff;
}

/* 新增：行内停止按钮样式 */
.btn-stop-inline {
    background: var(--error);
    color: white;
    width: auto;
    flex: 0 0 80px;
    /* 固定宽度 */
    display: none;
    /* 默认隐藏 */
}

.btn-stop-inline:hover {
    background: #d32f2f;
}

/* ==================== 统一播放器样式 ==================== */
.global-player {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: sticky;
    bottom: 0;
}

.player-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--text-light);
    background: var(--bg-light);
    padding: 6px 10px;
    border-radius: 4px;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.status-dot-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ccc;
}

.status-dot.playing {
    background: var(--success);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

.status-dot.loading {
    background: var(--warning);
    animation: pulse 1s infinite;
}

/* 下载链接样式 */
.download-link {
    color: var(--text-main);
    text-decoration: none;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.3;
    pointer-events: none;
    transition: all 0.2s;
    padding: 2px 6px;
    border-radius: 4px;
}

.download-link.active {
    opacity: 1;
    pointer-events: auto;
    color: var(--primary);
    background: rgba(0, 123, 255, 0.1);
}

.download-link.active:hover {
    background: rgba(0, 123, 255, 0.2);
}

audio {
    width: 100%;
    height: 32px;
    margin-top: 4px;
}

/* 动画 */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }

    100% {
        opacity: 1;
    }
}

.loading-spin {
    width: 16px;
    height: 16px;
    border: 2px solid #fff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* 通知 */
#notificationContainer {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.notification {
    background: white;
    padding: 12px 16px;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-left: 4px solid var(--primary);
    animation: slideIn 0.3s;
    max-width: 300px;
    font-size: 14px;
}

.notif-error {
    border-left-color: var(--error);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* 书籍搜索结果样式 */
.book-results {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 280px);
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-height: 414px;
    padding: 15px;
}

.book-item {
    padding: 15px;
    border-bottom: 1px solid #eee;
    transition: background-color 0.2s;
}

.book-item:hover {
    background-color: #f8f9fa;
}

.book-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.book-name {
    font-size: 16px;
    font-weight: bold;
    color: var(--primary);
    text-decoration: none;
}

.book-name:hover {
    text-decoration: underline;
}

.book-status {
    font-size: 12px;
    padding: 2px 6px;
    background: #eee;
    border-radius: 4px;
    color: #666;
}

.book-meta {
    font-size: 13px;
    color: #666;
    margin-bottom: 8px;
    display: flex;
    gap: 15px;
}

.book-summary {
    font-size: 14px;
    color: var(--text-main);
    line-height: 1.5;
    margin-bottom: 10px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: #888;
}

.book-latest {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 10px;
}

.btn-read {
    display: inline-block;
    padding: 4px 12px;
    background: var(--primary);
    color: white;
    border-radius: 4px;
    text-decoration: none;
    font-size: 13px;
    transition: background 0.2s;
}

.btn-read:hover {
    background: var(--primary-dark);
}

.book-empty {
    text-align: center;
    padding: 30px;
    color: #999;
}

/* ==================== 书籍目录样式（新增） ==================== */
.book-directory-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 5px 10px 5px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 10px;
    /* 新增：固定在顶部 */
    position: sticky;
    top: -15px;
    background-color: #fff;
    /* 确保背景色，防止内容滚动时穿透 */
    z-index: 10;
    /* 确保在滚动内容之上 */
    padding-top: 5px;
    /* 增加一点顶部间距 */
}

.book-directory-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--primary);
}

.directory-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chapter-item {
    display: flex;
    padding: 8px 5px;
    transition: background-color 0.1s;
    border-radius: var(--radius);
}

.chapter-item:hover {
    background-color: var(--bg-light);
}

.chapter-index {
    width: 40px;
    color: var(--text-light);
    font-size: 13px;
    flex-shrink: 0;
}

.chapter-name {
    flex-grow: 1;
    color: var(--text-main);
    text-decoration: none;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chapter-name:hover {
    color: var(--primary);
}
/* ==================== 设置与模态框样式 ==================== */

/* 头部设置按钮 */
.header-actions {
    position: absolute;
    top: 25px;
    right: 25px;
    z-index: 100;
}

@media (max-width: 800px) {
    .header-actions {
        top: 15px;
        right: 15px;
    }
}

.btn-icon {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
    transition: all 0.2s;
    color: var(--text-main);
}

.btn-icon:hover {
    background: var(--bg-light);
    transform: rotate(30deg);
    color: var(--primary);
}

/* 模态框遮罩 */
.modal-overlay {
    display: none; /* 默认隐藏 */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
    animation: fadeIn 0.2s ease;
}

.modal-overlay.open {
    display: flex;
}

/* 模态框内容 */
.modal-content {
    background: #fff;
    border-radius: var(--radius);
    width: 90%;
    max-width: 450px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
    color: var(--text-main);
}

.btn-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-light);
    cursor: pointer;
    line-height: 1;
}

.btn-close:hover {
    color: var(--error);
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: var(--bg-light);
    border-bottom-left-radius: var(--radius);
    border-bottom-right-radius: var(--radius);
}