:root {
  --bg: #f6f7f4; --panel: #ffffff; --ink: #18211f; --muted: #66706d; --line: #e3e7e3;
  --brand: #0f766e; --brand-2: #14b8a6; --brand-ink: #ffffff; --soft: #e8f4f2; --warn: #b45309;
  --hl: #fff3c4; --shadow: 0 1px 2px rgba(16, 24, 22, .06), 0 8px 24px rgba(16, 24, 22, .05);
  --radius: 14px; --font: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, "Segoe UI", sans-serif;
}
:root[data-theme="dark"] {
  --bg: #0f1413; --panel: #161d1c; --ink: #e7eeec; --muted: #94a3a0; --line: #26302e;
  --brand: #2dd4bf; --brand-2: #5eead4; --brand-ink: #062a26; --soft: #12302c; --hl: #3a3412;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .25);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1413; --panel: #161d1c; --ink: #e7eeec; --muted: #94a3a0; --line: #26302e;
    --brand: #2dd4bf; --brand-2: #5eead4; --brand-ink: #062a26; --soft: #12302c; --hl: #3a3412;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .25);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.6 var(--font); -webkit-font-smoothing: antialiased; }
button, select, input, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.grow { flex: 1; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 24px; padding: 10px 24px;
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand b { font-size: 18px; letter-spacing: 2px; }
.brand .sub { display: block; font-size: 11px; color: var(--muted); letter-spacing: 1px; margin-top: -4px; }
.logo { width: 32px; height: 32px; }
.logo rect { fill: var(--brand); }
.logo path { stroke: var(--brand-ink); stroke-width: 2.4; stroke-linecap: round; fill: none; }
.tabs { display: flex; gap: 4px; }
.tab { border: 0; background: none; padding: 8px 14px; border-radius: 10px; cursor: pointer; color: var(--muted); }
.tab.active { background: var(--soft); color: var(--brand); font-weight: 600; }
a.tab { text-decoration: none; display: inline-flex; align-items: center; }
.top-actions { margin-left: auto; display: flex; gap: 6px; }
.ghost { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 6px 12px; cursor: pointer; }
.ghost:disabled { opacity: .45; cursor: not-allowed; }

main { max-width: 1180px; margin: 0 auto; padding: 8px 24px 40px; }
.page { display: none; }
.page.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.intro { padding: 22px 2px 14px; }
.intro h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: .5px; }
.intro p { margin: 0; color: var(--muted); display: inline; }

.grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(320px, 1fr); gap: 18px; align-items: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
h2 { font-size: 14px; margin: 14px 0 8px; color: var(--muted); font-weight: 600; letter-spacing: .5px; }
.row-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row-head h2 { margin: 0; }

/* editor */
.editor { display: flex; flex-direction: column; min-height: 420px; }
.toolbar, .editor-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar select { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 5px 8px; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 12px; cursor: pointer; font-size: 13px; }
.chip:hover { border-color: var(--brand); color: var(--brand); }
textarea#text { flex: 1; min-height: 340px; margin: 12px 0; resize: vertical; border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; background: var(--bg); line-height: 1.8; font-size: 16px; outline: none; }
textarea#text:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.badge { background: var(--soft); color: var(--brand); padding: 2px 10px; border-radius: 999px; font-size: 12px; }
.karaoke { margin-top: 10px; font-size: 15px; line-height: 1.9; max-height: 180px; overflow: auto; display: none; }
.karaoke.on { display: block; border-top: 1px dashed var(--line); padding-top: 10px; }
.karaoke span { border-radius: 4px; padding: 1px 2px; transition: background .2s; color: var(--muted); }
.karaoke span.done { color: var(--ink); }
.karaoke span.now { background: var(--hl); color: var(--ink); }

/* voices */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: none; padding: 4px 10px; cursor: pointer; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--brand); color: var(--brand-ink); }
.voices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; max-height: 300px; overflow: auto; padding: 2px; }
.voice { display: flex; align-items: center; gap: 10px; text-align: left; border: 1.5px solid var(--line); background: var(--panel);
  border-radius: 12px; padding: 8px; cursor: pointer; position: relative; }
.voice:hover { border-color: color-mix(in srgb, var(--brand) 50%, var(--line)); }
.voice.sel { border-color: var(--brand); background: var(--soft); }
.voice .av { width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px; }
.voice .vt { display: flex; flex-direction: column; min-width: 0; }
.voice .vt b { font-size: 14px; }
.voice .vt small { color: var(--muted); font-size: 11.5px; line-height: 1.35; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.voice .play { margin-left: auto; width: 26px; height: 26px; flex: none; border-radius: 50%; border: 1px solid var(--line); display: grid; place-items: center; font-size: 10px; color: var(--brand); background: var(--panel); }
.voice .play.on { background: var(--brand); color: var(--brand-ink); }

.styles { display: flex; flex-wrap: wrap; gap: 6px; }
.styles .chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.instruct { width: 100%; margin-top: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--bg); }

.sliders label, label.inline { display: grid; grid-template-columns: 44px 1fr 56px; align-items: center; gap: 10px; margin: 6px 0; font-size: 14px; }
input[type=range] { accent-color: var(--brand); width: 100%; }
output { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.opts { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 12px 0 4px; }
.opts select, .controls > select { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 6px 8px; }
.controls > select { width: 100%; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.switch em { font-style: normal; }
.switch input { display: none; }
.switch span { width: 34px; height: 20px; border-radius: 999px; background: var(--line); position: relative; transition: .2s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { left: 16px; }

.primary { width: 100%; margin-top: 14px; border: 0; border-radius: 12px; padding: 12px; cursor: pointer; font-size: 16px; font-weight: 600;
  color: var(--brand-ink); background: linear-gradient(135deg, var(--brand), var(--brand-2)); display: flex; justify-content: center; align-items: center; gap: 10px; }
.primary:hover { filter: brightness(1.05); }
.primary:disabled { opacity: .55; cursor: progress; }
.primary kbd { font: 11px var(--font); opacity: .75; border: 1px solid currentColor; border-radius: 6px; padding: 0 6px; }
.primary.busy span::after { content: "…"; }

/* player */
.col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.player { position: sticky; bottom: 12px; z-index: 5; }
.pl-main { display: flex; align-items: center; gap: 14px; }
.round { width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--brand); color: var(--brand-ink); font-size: 18px; cursor: pointer; flex: none; }
.round:disabled { opacity: .4; cursor: default; }
.pl-body { flex: 1; min-width: 0; }
#viz { width: 100%; height: 56px; display: block; cursor: pointer; }
.pl-meta { display: flex; font-size: 13px; color: var(--muted); }
.metrics { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.metrics b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* history */
.history { margin-top: 18px; }
.hist { list-style: none; margin: 10px 0 0; padding: 0; }
.hist li { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-top: 1px solid var(--line); }
.hist li:first-child { border-top: 0; }
.hist .htxt { flex: 1; min-width: 0; }
.hist .htxt div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist .hbtns { display: flex; gap: 6px; }
.hist .hbtns button { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 3px 9px; cursor: pointer; font-size: 13px; }
.empty { margin: 10px 4px 0; }

.features { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-top: 28px; }
.features div { padding: 14px; border-radius: var(--radius); background: var(--soft); }
.features p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

/* srt */
.drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 150px; border: 2px dashed var(--line);
  border-radius: 12px; cursor: pointer; text-align: center; padding: 16px; }
.drop.over { border-color: var(--brand); background: var(--soft); }
.cues { margin-top: 12px; max-height: 420px; overflow: auto; font-size: 13.5px; }
.cues div { display: grid; grid-template-columns: 140px 1fr; gap: 10px; padding: 6px 4px; border-top: 1px solid var(--line); }
.cues code { color: var(--muted); font-size: 12px; }
.radios label { display: flex; gap: 8px; align-items: center; font-size: 14px; margin: 4px 0; cursor: pointer; }
.radios input { accent-color: var(--brand); }
.progress { margin-top: 12px; height: 8px; border-radius: 999px; background: var(--line); position: relative; overflow: hidden; }
.progress div { height: 100%; width: 0; background: linear-gradient(90deg, var(--brand), var(--brand-2)); transition: width .3s; }
.progress span { position: absolute; right: 0; top: 10px; font-size: 12px; color: var(--muted); }
#srtResult { margin-top: 24px; }
#srtResult audio { width: 100%; }
.dl-row { display: flex; gap: 8px; margin-top: 8px; }
.btn { flex: 1; text-align: center; border: 1px solid var(--line); border-radius: 10px; padding: 6px; text-decoration: none; color: var(--ink); background: var(--panel); }

.code pre { margin: 0; overflow: auto; font: 13px/1.6 ui-monospace, "Cascadia Code", Consolas, monospace; }
footer { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; padding: 24px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); }
footer a { color: inherit; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line); }
footer a:hover { color: var(--brand); text-decoration-color: currentColor; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 10px; z-index: 50; font-size: 14px; box-shadow: var(--shadow); }

@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
  .features { grid-template-columns: 1fr 1fr; }
  .editor { min-height: 0; }
  textarea#text { min-height: 220px; }
}
@media (max-width: 560px) {
  .topbar { padding: 8px 16px; gap: 10px; flex-wrap: wrap; }
  .tabs { order: 3; width: 100%; }
  .tabs { overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 1 0 auto; padding: 6px; white-space: nowrap; justify-content: center; font-size: 14px; }
  .tabs a[href="/about"] { display: none; }  /* phones: About stays in the footer and on the home page */
  html:lang(en) .tab { flex: 1 1 0; white-space: normal; line-height: 1.25; text-align: center; font-size: 13px; }
  main { padding: 4px 16px 32px; }
  .voices { grid-template-columns: 1fr; }
  .features { grid-template-columns: 1fr; }
  .intro h1 { font-size: 22px; }
  .pl-dl { display: none; }
  .hist li { flex-wrap: wrap; }
  .hist .hbtns { width: 100%; }
}

.warn { margin: 14px 0 0; padding: 10px 12px 10px 28px; border-radius: 10px; background: color-mix(in srgb, var(--warn) 12%, var(--panel)); color: var(--ink); font-size: 13px; line-height: 1.7; }
.warn li::marker { color: var(--warn); }

/* music bed */
.mt { margin-top: 14px; }
.tiny { font-size: 12px; }
.lbl { font-size: 14px; }
.sliders.wide label { grid-template-columns: 64px 1fr 52px; }
.drop.small { min-height: 110px; margin-top: 10px; }
.vpanel { margin-top: 10px; }
.vpanel textarea { width: 100%; min-height: 140px; resize: vertical; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--bg); }
.vpanel select { margin-top: 8px; width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 6px 8px; }
.pick { list-style: none; margin: 0; padding: 0; max-height: 236px; overflow: auto; }
.pick li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1.5px solid var(--line); border-radius: 10px; margin-bottom: 6px; cursor: pointer; }
.pick li.sel { border-color: var(--brand); background: var(--soft); }
.pick li div { flex: 1; min-width: 0; }
.pick li b { display: block; font-weight: 500; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick li small { color: var(--muted); font-size: 12px; }
.lib { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.lib button.trk { display: flex; align-items: center; gap: 10px; text-align: left; border: 1.5px solid var(--line); background: var(--panel); border-radius: 12px; padding: 8px 10px; cursor: pointer; }
.lib button.trk.sel { border-color: var(--brand); background: var(--soft); }
.lib .tt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lib .tt b { font-size: 14px; }
.lib .tt small { color: var(--muted); font-size: 11.5px; line-height: 1.35; }
.lib .play { width: 28px; height: 28px; flex: none; border-radius: 50%; border: 1px solid var(--line); display: grid; place-items: center; font-size: 10px; color: var(--brand); background: var(--panel); }
.lib .play.on { background: var(--brand); color: var(--brand-ink); }
#mPrev, #mixAudio { width: 100%; margin-top: 10px; }
#mixViz { width: 100%; height: 110px; display: block; margin-top: 8px; cursor: pointer; border-radius: 8px; background: var(--bg); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.legend em { font-style: normal; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.legend .lv { background: var(--brand); }
.legend .lm { background: #f59e0b; }
.foot-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; }
button.btn { cursor: pointer; font-size: 14px; }
.bgm-grid { grid-template-areas: "in side" "res side"; }
.bgm-in { grid-area: in; } .bgm-res { grid-area: res; } .bgm-side { grid-area: side; }
#tab-bgm .row-head { flex-wrap: wrap; row-gap: 6px; }
@media (max-width: 900px) { .bgm-grid { grid-template-areas: "in" "side" "res"; } }
@media (max-width: 560px) { .lib { grid-template-columns: 1fr; } }

/* ---------- step guide (guide.js): where you are, and a coloured ring on the next thing to fill in or click */
.steps { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 12px 0 0; padding: 0; list-style: none; }
.steps li { display: flex; align-items: center; gap: 6px; }
.steps li + li::before { content: ""; width: 16px; height: 1px; background: var(--line); }
.steps button { display: inline-flex; align-items: center; gap: 7px; padding: 3px 12px 3px 3px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); color: var(--muted); font-size: 13px; cursor: pointer; transition: background .2s, border-color .2s, color .2s; }
.steps button:hover { border-color: var(--brand); }
.steps b { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--soft); color: var(--brand); font-size: 12px; }
.steps .done b { font-size: 0; }
.steps .done b::before { content: "✓"; font-size: 12px; }
.steps .cur button { border-color: var(--brand); background: var(--soft); color: var(--ink); font-weight: 600; }
.steps .cur b { background: var(--brand); color: var(--brand-ink); }
.next { outline: 2px solid var(--brand); outline-offset: 3px; animation: vx-next 1.6s ease-out 3; }
@keyframes vx-next {
  from { box-shadow: 0 0 0 0 color-mix(in srgb, var(--brand) 45%, transparent); }
  to { box-shadow: 0 0 0 14px color-mix(in srgb, var(--brand) 0%, transparent); }
}
textarea.next, select.next, textarea#text.next { outline: none; border-color: var(--brand); animation: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.ghost.next, .btn.next { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.drop.next { outline: none; border-color: var(--brand); background: var(--soft); }
.tip { margin: 8px 2px 0; min-height: 1.3em; font-size: 13px; color: var(--brand); }
.tip:empty { visibility: hidden; }
.tip-line { margin: 8px 0 0; }
@media (max-width: 560px) {
  .steps { gap: 4px; }
  .steps li + li::before { width: 8px; }
  .steps li:not(.cur) span { display: none; }
  .steps li:not(.cur) button { padding: 3px; }
}
@media (prefers-reduced-motion: reduce) { .next { animation: none; } }
