:root {
  color-scheme: light;
  --bg: #f6f4f0;
  --panel: #ffffff;
  --ink: #1f1d1a;
  --ink-2: #5d5850;
  --ink-3: #8f887d;
  --line: #e6e1d8;
  --line-2: #f0ece5;
  --accent: #c2410c;
  --accent-2: #fff1e8;
  --ok: #15803d;
  --ok-bg: #e9f7ee;
  --warn: #b45309;
  --warn-bg: #fdf4e3;
  --err: #b91c1c;
  --err-bg: #fdecec;
  --narr: #475569;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(30, 20, 10, .05), 0 4px 16px rgba(30, 20, 10, .05);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
a { color: var(--accent); text-decoration: none; }
.hidden { display: none !important; }
h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: .3px; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* layout */
.layout { display: grid; grid-template-columns: 208px 1fr; min-height: 100vh; }
.side { background: #1f1d1a; color: #e9e4da; padding: 18px 12px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; padding: 0 8px 18px; letter-spacing: .5px; }
.brand.big { font-size: 22px; justify-content: center; color: var(--ink); }
.logo { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); position: relative; display: inline-block; }
.logo::after { content: ""; position: absolute; inset: 7px 7px; background: linear-gradient(90deg, #fff 0 3px, transparent 3px 5px, #fff 5px 8px, transparent 8px 10px, #fff 10px 12px); border-radius: 1px; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { color: #cfc8bb; padding: 9px 12px; border-radius: 8px; display: flex; align-items: center; justify-content: space-between; }
.side nav a:hover { background: #2c2925; color: #fff; }
.side nav a.active { background: var(--accent); color: #fff; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 8px; font-size: 12px; }
.side-foot a { color: #b5ad9f; }
.badge { background: #fff; color: var(--accent); border-radius: 10px; font-size: 11px; padding: 0 7px; font-weight: 600; }
.main { padding: 24px 28px 120px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .grow { flex: 1; }
.crumbs { color: var(--ink-3); font-size: 13px; margin-bottom: 6px; }
.crumbs a { color: var(--ink-2); }

/* controls */
.btn { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 8px; padding: 7px 14px; cursor: pointer; font: inherit; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { border-color: #cfc7b9; background: #fbfaf7; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #a9380a; }
.btn.danger { color: var(--err); }
.btn.sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon { border: none; background: none; cursor: pointer; padding: 4px 6px; border-radius: 6px; color: var(--ink-2); font-size: 14px; }
.icon:hover { background: var(--line-2); color: var(--ink); }
.link { border: none; background: none; color: #b5ad9f; cursor: pointer; padding: 0; text-align: left; font: inherit; }
input, select, textarea { font: inherit; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-2); }
textarea { resize: vertical; line-height: 1.6; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-2); }
label.field > span.hint { font-size: 12px; color: var(--ink-3); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; color: var(--ink-2); }

/* cards */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; cursor: pointer; transition: .15s; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; }
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card .title { font-size: 16px; font-weight: 600; }
.stats { display: flex; gap: 14px; color: var(--ink-3); font-size: 12px; flex-wrap: wrap; }
.stats b { color: var(--ink); font-weight: 600; }
.progress { height: 6px; background: var(--line-2); border-radius: 3px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s; }
.progress.ok > i { background: var(--ok); }
.empty { text-align: center; padding: 60px 20px; color: var(--ink-3); }
.empty .btn { margin-top: 14px; }

/* tables */
table.tbl { width: 100%; border-collapse: collapse; background: var(--panel); }
.tbl th { text-align: left; font-weight: 500; color: var(--ink-3); font-size: 12px; padding: 9px 10px; border-bottom: 1px solid var(--line); background: #fbfaf7; position: sticky; top: 0; z-index: 1; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl tr:hover td { background: #fcfbf8; }
.tbl-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); background: var(--panel); }

/* tags */
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.err { background: var(--err-bg); color: var(--err); }
.tag.accent { background: var(--accent-2); color: var(--accent); }
.tag.male { background: #e8f0fb; color: #1d4ed8; }
.tag.female { background: #fbe9f1; color: #be185d; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 4px 3px 10px; border-radius: 14px; border: 1px solid var(--line); font-size: 12px; background: #fff; }
.chip.def { border-color: var(--accent); background: var(--accent-2); }
.chip .icon { padding: 0 4px; font-size: 12px; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button { border: none; background: none; padding: 9px 14px; cursor: pointer; font: inherit; color: var(--ink-3); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--ink); border-color: var(--accent); font-weight: 600; }

/* chapter editor */
.editor { display: grid; grid-template-columns: 1fr 280px; gap: 18px; align-items: start; }
.seg-list { display: flex; flex-direction: column; gap: 6px; }
.seg { display: grid; grid-template-columns: 44px 150px 1fr auto; gap: 10px; align-items: start; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; border-left: 4px solid var(--narr); }
.seg.dialogue { border-left-color: var(--c, var(--accent)); }
.seg.sel { outline: 2px solid var(--accent); outline-offset: -1px; }
.seg .num { color: var(--ink-3); font-size: 12px; padding-top: 5px; display: flex; flex-direction: column; gap: 4px; align-items: center; }
.seg .who select { width: 100%; padding: 4px 6px; font-size: 13px; }
.seg .who .vname { font-size: 11px; color: var(--ink-3); margin-top: 4px; cursor: pointer; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seg .who .vname:hover { color: var(--accent); }
.seg .who .vname.ov { color: var(--accent); }
.seg .txt { line-height: 1.75; white-space: pre-wrap; word-break: break-word; padding: 3px 4px; border-radius: 6px; min-height: 28px; outline: none; }
.seg .txt:focus { background: #fffaf5; box-shadow: 0 0 0 1px var(--accent-2); }
.seg.dialogue .txt { color: #2a1a10; }
.seg .acts { display: flex; gap: 2px; align-items: center; }
.seg .emo { font-size: 11px; padding: 2px 4px; border-radius: 6px; width: 74px; }
.seg .err-msg { grid-column: 3 / 5; color: var(--err); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--line); }
.dot.done { background: var(--ok); }
.dot.error { background: var(--err); }
.dot.running, .dot.queued { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.side-panel { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 14px; }
.cast { display: flex; flex-direction: column; gap: 6px; max-height: 52vh; overflow: auto; }
.cast-item { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line-2); }
.cast-item:hover { border-color: var(--line); background: #fcfbf8; }
.cast-item .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.cast-item .nm { flex: 1; min-width: 0; }
.cast-item .nm b { font-weight: 600; font-size: 13px; }
.cast-item .nm div { font-size: 11px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-line { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-3); }

/* voices */
.voice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.voice { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 7px; position: relative; }
.voice.picked { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-2); }
.voice .vh { display: flex; align-items: center; gap: 8px; }
.voice .vh b { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice .vid { font-family: ui-monospace, Menlo, monospace; font-size: 11px; color: var(--ink-3); word-break: break-all; }
.voice .desc { font-size: 12px; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.voice .bound { font-size: 11px; color: var(--accent); }
.voice .vf { display: flex; gap: 6px; margin-top: auto; flex-wrap: wrap; }
.play { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); background: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; color: var(--accent); flex: none; font-size: 11px; }
.play:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.play.loading { animation: pulse 1s infinite; }
.star { cursor: pointer; color: #d6cfc2; font-size: 16px; border: none; background: none; padding: 0; }
.star.on { color: #e4a11b; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filters input[type=search] { min-width: 240px; }
.seg-btns { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.seg-btns button { border: none; background: none; padding: 6px 12px; cursor: pointer; font: inherit; color: var(--ink-2); border-right: 1px solid var(--line); }
.seg-btns button:last-child { border-right: none; }
.seg-btns button.on { background: var(--accent-2); color: var(--accent); font-weight: 600; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(25, 20, 15, .38); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow: auto; }
.modal { background: var(--panel); border-radius: 14px; width: 560px; max-width: 100%; box-shadow: 0 20px 60px rgba(0, 0, 0, .2); display: flex; flex-direction: column; max-height: 88vh; }
.modal.wide { width: 1000px; }
.modal-h { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.modal-h h2 { margin: 0; }
.modal-b { padding: 18px 20px; overflow: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-f { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

/* toasts */
.toasts { position: fixed; top: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1f1d1a; color: #fff; padding: 10px 14px; border-radius: 9px; box-shadow: var(--shadow); max-width: 420px; font-size: 13px; animation: slide .2s; white-space: pre-wrap; }
.toast.err { background: var(--err); }
.toast.ok { background: var(--ok); }
@keyframes slide { from { transform: translateY(-6px); opacity: 0; } }

/* player */
.player { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: #1f1d1a; color: #fff; border-radius: 14px; padding: 10px 12px 10px 18px; display: flex; gap: 14px; align-items: center; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); z-index: 40; width: min(760px, calc(100vw - 32px)); }
.player-info { display: flex; flex-direction: column; min-width: 0; flex: 0 1 220px; }
.player-info b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-info span { font-size: 11px; color: #b5ad9f; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player audio { flex: 1; height: 36px; min-width: 0; }
.player .icon { color: #b5ad9f; }

/* login */
.login { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
.login-card { background: #fff; padding: 36px; border-radius: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; width: 340px; border: 1px solid var(--line); }
.err { color: var(--err); font-size: 13px; min-height: 18px; }

.settings-sec { display: flex; flex-direction: column; gap: 14px; }
.settings-sec .sec-title { display: flex; align-items: center; gap: 10px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }
.lrc-view { background: #fbfaf7; border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; max-height: 300px; overflow: auto; white-space: pre-wrap; }

@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; }
  .side nav { flex-direction: row; flex-wrap: wrap; }
  .side-foot { display: none; }
  .editor { grid-template-columns: 1fr; }
  .seg { grid-template-columns: 34px 1fr auto; }
  .seg .txt { grid-column: 1 / 4; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
}
