/* ============================================================
 * 聆阅 · 盲人导读志愿服务平台 —— 样式系统
 * 设计原则：大字号、高对比、大按钮、清晰反馈、全年龄适配
 * ============================================================ */

/* ---------- 主题变量 ---------- */
:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #edf2f9;
  --text: #1c2733;
  --muted: #5b6b7c;
  --primary: #0f6cbf;
  --primary-dark: #0b548f;
  --primary-soft: #e3f0fc;
  --accent: #e8842c;
  --danger: #d0342c;
  --danger-soft: #fdecea;
  --ok: #1e8e5a;
  --warn: #b06e00;
  --warn-soft: #fff6e0;
  --border: #d5dfeb;
  --radius: 14px;
  --radius-s: 10px;
  --shadow: 0 2px 12px rgba(23, 43, 77, 0.08);
  --focus: #1d4ed8;
  --base: 18px;
}

/* 夜间模式 */
html.theme-dark {
  --bg: #10161f;
  --surface: #1a2330;
  --surface-2: #222e3f;
  --text: #e8eef5;
  --muted: #9fb0c3;
  --primary: #4da3e8;
  --primary-dark: #76b8f0;
  --primary-soft: #1c344d;
  --accent: #f0a05c;
  --border: #2c3a4d;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  --focus: #7cc0ff;
}

/* 高对比模式（视障友好） */
html.theme-hc {
  --bg: #000000;
  --surface: #0a0a0a;
  --surface-2: #161616;
  --text: #ffffff;
  --muted: #e6e6e6;
  --primary: #ffd400;
  --primary-dark: #ffdf70;
  --primary-soft: #2b2600;
  --accent: #ffd400;
  --danger: #ff6a5e;
  --danger-soft: #2a0805;
  --ok: #3ddc84;
  --warn: #ffd400;
  --warn-soft: #2b2600;
  --border: #ffffff;
  --shadow: none;
  --focus: #ffd400;
}

/* ---------- 字号档位 ---------- */
html.fs-s { --base: 16px; }
html.fs-m { --base: 18px; }
html.fs-l { --base: 21px; }
html.fs-xl { --base: 25px; }

/* ---------- 基础 ---------- */
* { box-sizing: border-box; }
html { font-size: var(--base); scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "system-ui", -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: underline; text-underline-offset: 3px; }
button { font-family: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 999;
  background: var(--primary); color: #fff; padding: 10px 18px; border-radius: 0 0 10px 0;
}
.skip-link:focus { left: 0; }

/* ---------- 顶栏 ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow);
}
.topbar-inner {
  max-width: 1100px; margin: 0 auto; padding: 10px 16px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
}
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.logo img { width: 40px; height: 40px; border-radius: 9px; }
.logo b { font-size: 1.25rem; letter-spacing: 2px; }
.logo small { display: block; color: var(--muted); font-size: 0.72rem; letter-spacing: 1px; }

.main-nav {
  display: flex; flex-wrap: wrap; gap: 4px; margin-left: auto;
}
.main-nav button {
  background: none; border: 2px solid transparent; color: var(--text);
  padding: 9px 14px; font-size: 1rem; cursor: pointer; border-radius: 10px;
  min-height: 44px;
}
.main-nav button:hover { background: var(--surface-2); }
.main-nav button[aria-current="page"] {
  background: var(--primary-soft); color: var(--primary-dark);
  border-color: var(--primary); font-weight: 700;
}
html.theme-hc .main-nav button[aria-current="page"] { color: var(--text); font-weight: 800; }

.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.8rem; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px;
  background: var(--surface);
}
.status-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); }
.status-pill.offline .dot { background: var(--danger); }

/* ---------- 布局 ---------- */
main { max-width: 1100px; margin: 0 auto; padding: 22px 16px 60px; }
footer {
  border-top: 1px solid var(--border); color: var(--muted);
  text-align: center; padding: 22px 16px 34px; font-size: 0.85rem;
}
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 6px 0 18px; }
.page-head h1 { font-size: 1.5rem; margin: 0; }
.page-head .spacer { flex: 1; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 22px; margin-bottom: 18px;
}
.card h2 { margin: 0 0 12px; font-size: 1.2rem; }
.card h3 { margin: 0 0 10px; font-size: 1.05rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; text-align: center;
}
.stat .num { font-size: 1.9rem; font-weight: 800; color: var(--primary); }
html.theme-hc .stat .num { color: var(--primary); }
.stat .label { color: var(--muted); font-size: 0.85rem; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 20px; font-size: 1rem; cursor: pointer;
  border-radius: 11px; border: 2px solid transparent;
  background: var(--surface-2); color: var(--text);
  transition: transform 0.06s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
html.theme-hc .btn-primary { background: var(--primary); color: #000; font-weight: 800; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); border-color: var(--primary-dark); }
html.theme-hc .btn-primary:hover:not(:disabled) { background: var(--primary-dark); color: #000; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { min-height: 38px; padding: 6px 13px; font-size: 0.9rem; border-radius: 9px; }
.btn-lg { min-height: 60px; font-size: 1.15rem; padding: 14px 28px; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- 表单 ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 700; margin-bottom: 6px; }
.field .hint { color: var(--muted); font-size: 0.82rem; margin-top: 4px; }
.input, .select, .textarea {
  width: 100%; min-height: 48px; padding: 10px 14px; font-size: 1rem;
  font-family: inherit; color: var(--text);
  background: var(--surface); border: 2px solid var(--border); border-radius: 11px;
}
.textarea { min-height: 140px; resize: vertical; line-height: 1.8; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); outline: none; }
.field-error { color: var(--danger); font-size: 0.85rem; margin-top: 4px; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; min-height: 44px; }
.switch input { width: 22px; height: 22px; accent-color: var(--primary); }

.seg { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  border: 2px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; min-height: 44px; font-size: 0.95rem;
}
.seg button[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); font-weight: 700; }
html.theme-hc .seg button[aria-pressed="true"] { color: var(--text); }

input[type="range"] { width: 100%; accent-color: var(--primary); height: 34px; }

/* ---------- 表格 ---------- */
table.data { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
table.data th, table.data td { border: 1px solid var(--border); padding: 10px 12px; text-align: left; vertical-align: top; }
table.data th { background: var(--surface-2); }
table.data tr:hover td { background: var(--primary-soft); }
.table-wrap { overflow-x: auto; }

/* ---------- 徽章 / 标签 ---------- */
.badge {
  display: inline-block; padding: 3px 12px; border-radius: 999px;
  font-size: 0.8rem; border: 1px solid var(--border); background: var(--surface-2);
}
.badge.ok { background: #e4f6ec; color: var(--ok); border-color: var(--ok); }
.badge.err { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
html.theme-dark .badge.ok { background: #123527; }
html.theme-dark .badge.err { background: #3a1512; }
html.theme-dark .badge.warn { background: #3a2e10; }
.kind-chip {
  display: inline-block; font-size: 0.72rem; padding: 1px 9px; border-radius: 6px;
  background: var(--primary-soft); color: var(--primary-dark); margin-right: 8px; white-space: nowrap;
}

/* ---------- 列表 ---------- */
.list-item {
  display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap;
  padding: 14px 4px; border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-item .grow { flex: 1; min-width: 240px; }
.list-item .ops { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 拖放区 ---------- */
.dropzone {
  border: 3px dashed var(--border); border-radius: var(--radius);
  background: var(--surface); padding: 42px 20px; text-align: center; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: var(--primary-soft); }
.dropzone .big { font-size: 1.3rem; font-weight: 700; margin: 8px 0; }
.dropzone .tip { color: var(--muted); font-size: 0.88rem; }

/* ---------- 进度条 ---------- */
.progress { height: 14px; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.progress > div { height: 100%; background: var(--primary); border-radius: 999px; transition: width 0.25s; }
html.theme-hc .progress > div { background: var(--primary); }
.file-row { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.file-row:last-child { border-bottom: none; }
.file-row .grow { flex: 1; min-width: 220px; }
.file-row .name { font-weight: 700; word-break: break-all; }
.file-row .meta { color: var(--muted); font-size: 0.82rem; }
.status-tag { white-space: nowrap; font-size: 0.85rem; font-weight: 700; }
.status-tag.ok { color: var(--ok); }
.status-tag.err { color: var(--danger); }
.status-tag.run { color: var(--primary); }
.status-tag.wait { color: var(--muted); }

/* ---------- 校对面板 ---------- */
.proof-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .proof-grid { grid-template-columns: 1fr; } }
.source-pane, .script-pane {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  padding: 16px; min-height: 320px; max-height: 56vh; overflow: auto;
}
.source-pane .block { padding: 8px 0; border-bottom: 1px dashed var(--border); }
.source-pane .block:last-child { border-bottom: none; }
#scriptTextarea { min-height: 46vh; }

/* 聆听模式 */
.listen-mode { text-align: center; }
.now-reading {
  font-size: 1.7rem; line-height: 2; min-height: 6em;
  background: var(--primary-soft); border-radius: var(--radius);
  padding: 26px 20px; margin: 14px 0; font-weight: 600;
}
html.theme-hc .now-reading { background: var(--surface-2); }
.listen-pos { color: var(--muted); font-size: 0.9rem; margin-top: 4px; }
.listen-controls { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin: 18px 0; }
.btn-round {
  width: 84px; height: 84px; border-radius: 50%; font-size: 2rem;
  border: none; cursor: pointer; background: var(--surface-2); color: var(--text);
  border: 2px solid var(--border);
}
.btn-round.primary { background: var(--primary); color: #fff; border-color: var(--primary); width: 104px; height: 104px; }
html.theme-hc .btn-round.primary { color: #000; }

/* ---------- Toast / 弹窗 ---------- */
#toastHost { position: fixed; left: 50%; top: 18px; transform: translateX(-50%); z-index: 300; width: min(92vw, 560px); }
.toast {
  background: var(--text); color: var(--bg); border-radius: 12px;
  padding: 14px 18px; margin-bottom: 10px; box-shadow: var(--shadow); font-size: 0.95rem;
  display: flex; gap: 10px; align-items: flex-start;
}
.toast.err { background: var(--danger); color: #fff; }
html.theme-hc .toast { background: #ffd400; color: #000; }

#modalHost .overlay {
  position: fixed; inset: 0; background: rgba(10, 20, 40, 0.55); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--surface); color: var(--text); border-radius: var(--radius);
  max-width: 640px; width: 100%; max-height: 88vh; overflow: auto; padding: 24px;
  border: 2px solid var(--primary);
}
.modal h2 { margin-top: 0; }
.modal .modal-ops { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs button {
  border: 2px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 18px; border-radius: 10px; cursor: pointer; font-size: 1rem; min-height: 44px;
}
.tabs button[aria-selected="true"] { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 700; }
html.theme-hc .tabs button[aria-selected="true"] { color: #000; }

/* ---------- 首页 ---------- */
.hero {
  background: linear-gradient(120deg, var(--primary-soft), var(--surface));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 30px 26px; margin-bottom: 20px;
}
html.theme-hc .hero { background: var(--surface); }
.hero h1 { margin: 0 0 10px; font-size: 1.7rem; }
.hero p { color: var(--muted); margin: 0 0 18px; max-width: 640px; }
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-top: 18px; }
.step {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; position: relative;
}
.step .no {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff;
  font-weight: 800; margin-bottom: 8px;
}
html.theme-hc .step .no { color: #000; }
.step b { display: block; margin-bottom: 4px; }
.step span { color: var(--muted); font-size: 0.88rem; }

/* ---------- 帮助 ---------- */
details.guide { border: 1px solid var(--border); border-radius: var(--radius-s); padding: 12px 16px; margin-bottom: 10px; background: var(--surface); }
details.guide summary { cursor: pointer; font-weight: 700; min-height: 44px; display: flex; align-items: center; }
details.guide[open] summary { margin-bottom: 8px; }

/* ---------- 自检面板 ---------- */
.check-row { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px dashed var(--border); }
.check-row:last-child { border-bottom: none; }
.check-row .ic { font-size: 1.2rem; }
.check-row .detail { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }

/* ---------- 杂项 ---------- */
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.spacer { flex: 1; }
hr.sep { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
code.kbd {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 1px 8px; font-size: 0.9em;
}
.privacy-box { background: var(--surface-2); border-radius: var(--radius-s); padding: 14px 18px; }
.term-highlight { color: var(--primary); font-weight: 700; }

@media (max-width: 640px) {
  .main-nav { width: 100%; }
  .logo small { display: none; }
  .proof-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
