:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --ink: #1c2333;
  --muted: #6b7488;
  --line: #e4e8f0;
  --brand: #4f46e5;
  --brand-soft: #eef0ff;
  --ok: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
  --radius: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(100%, 440px); }
.login-card .brand { margin-bottom: 24px; }
.login-card h1 { font-size: 20px; }
.form-error { color: var(--err); margin: 0; }
.key-call-title { margin-top: 24px !important; }
#key-secret { font-family: monospace; }
#key-copy { margin-top: 10px; }
.key-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.key-item > div { min-width: 0; overflow-wrap: anywhere; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; gap: 12px; padding: 16px; }
  .status { flex-wrap: wrap; width: 100%; }
  .status .rate span { white-space: nowrap; }
  .status .rate:first-child { width: 100%; }
  .status .rate:first-child select { min-width: 0; flex: 1; }
  .tabs { padding: 0 8px; overflow-x: auto; }
  .tab { white-space: nowrap; padding: 12px 10px; }
  main { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}

a { color: var(--brand); }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 42px; height: 42px; border-radius: 12px; background: var(--brand);
  color: #fff; display: grid; place-items: center; font-weight: 700; letter-spacing: .5px;
}
.topbar h1 { margin: 0; font-size: 18px; }
.sub { margin: 0; color: var(--muted); font-size: 12px; }
.status { display: flex; gap: 8px; align-items: center; }
.status .rate { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.status .rate select { width: auto; padding: 4px 8px; font-size: 12px; }

.badge {
  padding: 4px 10px; border-radius: 999px; background: var(--brand-soft);
  color: var(--brand); font-size: 12px; font-weight: 600;
}
.badge.ghost { background: #f1f2f6; color: var(--muted); }
.badge.warn { background: #fef3c7; color: var(--warn); }
.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.err { background: #fee2e2; color: var(--err); }

.tabs { display: flex; gap: 4px; padding: 0 28px; background: var(--card); border-bottom: 1px solid var(--line); }
.tab {
  border: 0; background: none; padding: 12px 16px; cursor: pointer; color: var(--muted);
  font-size: 14px; border-bottom: 2px solid transparent;
}
.tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

main { padding: 24px 28px 60px; }
.panel { display: none; }
.panel.active { display: block; }

.config-card { max-width: 1120px; margin: 0 auto; }
.config-heading { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.config-groups { display: grid; gap: 12px; margin-top: 20px; }
.config-group { border: 1px solid var(--line); border-radius: var(--radius); }
.config-group summary { padding: 16px; font-weight: 600; cursor: pointer; min-height: 44px; }
.config-group summary:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.config-group[open] summary { border-bottom: 1px solid var(--line); }
.config-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; padding: 20px; }
.config-field { margin: 0; }
.config-label { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.config-field .hint { margin: 0; overflow-wrap: anywhere; color: #475569; }
.config-field input[type="checkbox"] { width: 22px; height: 22px; }
.config-clear { display: flex; align-items: center; gap: 8px; margin-top: 8px; min-height: 44px; cursor: pointer; }
.config-clear input { width: 18px; }
.config-notice { padding: 12px 16px; background: var(--brand-soft); color: var(--ink); border-radius: 8px; overflow-wrap: anywhere; }
.config-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; padding: 16px 0 0; position: sticky; bottom: 0; background: var(--card); border-top: 1px solid var(--line); margin-top: 20px; }
.config-actions button { min-height: 44px; }
.config-actions p { margin: 0; flex: 1; min-width: 180px; }
@media (max-width: 600px) {
  .config-grid { grid-template-columns: minmax(0, 1fr); gap: 20px; padding: 16px; }
  .config-actions p { flex-basis: 100%; }
}

.grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 20px; }
@media (max-width: 900px) { .grid { grid-template-columns: 1fr; } }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}
.card h2 { margin: 0 0 14px; font-size: 15px; }

textarea, input, select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; color: inherit; background: #fff;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }

.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12px; color: var(--muted); }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row .field { flex: 1 1 140px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.check input { width: auto; }

.actions { display: flex; gap: 10px; margin-top: 14px; }
button {
  padding: 9px 18px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; cursor: pointer; font: inherit;
}
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
button.primary:disabled { opacity: .6; cursor: not-allowed; }
button.ghost { color: var(--muted); }
button.link { border: 0; background: none; color: var(--brand); padding: 2px 6px; }
button.link.danger { color: var(--err); }

.advanced { margin: 12px 0; border-top: 1px dashed var(--line); padding-top: 10px; }
.advanced summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.advanced .row { margin-top: 10px; }

.empty { color: var(--muted); font-size: 13px; padding: 18px 0; text-align: center; }
.meta { margin-top: 10px; font-size: 12px; color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; margin-top: 12px; }
code { background: #f1f2f6; padding: 1px 5px; border-radius: 4px; }

.voice-item, .job-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.voice-item:last-child, .job-item:last-child { border-bottom: 0; }
.voice-item .name, .job-item .name { font-weight: 600; }
.voice-item .sub, .job-item .sub { font-size: 12px; color: var(--muted); }
.voice-item .ops, .job-item .ops { display: flex; gap: 4px; }

.progress { height: 8px; background: #eef0f4; border-radius: 999px; overflow: hidden; margin: 8px 0; }
.progress > i { display: block; height: 100%; background: var(--brand); transition: width .3s; }
.chapter-list { font-size: 12px; color: var(--muted); max-height: 180px; overflow: auto; }
.chapter-list div { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }

/* 连续朗读控制台 */
.reader-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.reader-head .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-seek {
  width: 100%; margin: 14px 0 6px; padding: 0; border: 0; background: none;
  accent-color: var(--brand); height: 20px; cursor: pointer;
}
.reader-seek:focus { outline: 2px solid var(--brand-soft); }
.reader-times { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 8px; }
/* 分块预览（字幕式：一行一块） */
.subs-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line);
  font-size: 12px; color: var(--muted);
}
.subs-head .sub { font-size: 12px; color: var(--muted); }
.reader-subs {
  margin-top: 8px; max-height: 260px; overflow: auto;
  border: 1px solid var(--line); border-radius: 8px; background: #fbfcfe;
}
.reader-subs .sub-line {
  display: flex; gap: 8px; align-items: baseline;
  padding: 7px 10px; border-bottom: 1px solid var(--line);
  font-size: 12.5px; line-height: 1.7; color: var(--ink); cursor: pointer;
  word-break: break-word; white-space: normal;
}
.reader-subs .sub-line:last-child { border-bottom: 0; }
.reader-subs .sub-line:hover { background: #f2f4fb; }
.reader-subs .sub-line.active { background: var(--brand-soft); box-shadow: inset 2px 0 0 var(--brand); }
.reader-subs .sub-line .idx {
  flex: 0 0 34px; color: var(--muted); font-variant-numeric: tabular-nums;
  font-weight: 600; text-align: right;
}
.reader-subs .sub-line .len { flex: 0 0 42px; color: var(--muted); font-size: 11.5px; }
#r-audio { margin-top: 0; }

audio { width: 100%; margin-top: 12px; }
.json {
  background: #0f172a; color: #d7e0f5; padding: 14px; border-radius: 10px;
  overflow: auto; font-size: 12px; max-height: 320px;
}

.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%) translateY(20px);
  background: #1c2333; color: #fff; padding: 10px 18px; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: .25s; max-width: 70vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--err); }
.toast.ok { background: var(--ok); }

.password-card { margin-bottom: 20px; }
.password-card .form { max-width: 480px; }
.password-card .hint { color: #475569; }
.password-card input, #password-submit { min-height: 44px; }
