/* IndexTTS2 Studio — console theme, light/dark (based on Qwen3 TTS Studio look) */
:root {
  --bg: #f2f1ee;
  --surface: #ffffff;
  --surface-2: #f7f6f3;
  --ink: #1b1a18;
  --muted: #6f6a62;
  --faint: #a09a90;
  --border: #e3e0da;
  --primary: #d2372e;
  --primary-ink: #ffffff;
  /* --danger：错误/删除/警告徽章专用，与品牌主色 --primary 解耦——
     主按钮红与"危险操作红"可以独立调整，不再同源 */
  --danger: #d5333a;
  --accent: #1f5fe0;
  --ok: #1e9e5a;
  --warn: #c07d10;
  --meter-track: #eceae5;
  --shadow: 0 1px 2px rgba(27, 26, 24, .06), 0 8px 24px rgba(27, 26, 24, .07);
  --radius: 14px;
  --pad: 20px;
  --gap: 16px;
  /* 页面内容区的最大宽度。导航栏（.hdr-row）、工作区（main）、页脚（footer）
     三处必须同宽，否则宽屏上左右边界对不齐——曾经改过 main 忘了另外两处，
     导致工作区比导航栏宽 240px。三处都引用这个变量，改一次就不会再漏。

     为什么是 1680：生成页是三栏，固定部分是 左栏最小 520 + 历史栏 268 +
     间距 32 = 820px，中间栏拿剩下的。上限 1440 时中间栏最多只能到 484px，
     1920/2560 屏上多出来的宽度全被两侧留白吃掉，等于白买大屏。
     三栏的中文注释在 .page[data-page="gen"].cur 那里。 */
  --layout-max: 1680px;
  /* 系统字体栈：无外链依赖（Google Fonts 在离线/国内环境不可达），零阻塞 */
  --mono: "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
  --sans: "Segoe UI", system-ui, -apple-system, "Microsoft YaHei", "PingFang SC", sans-serif;
}
html[data-theme="dark"] {
  --bg: #131211;
  --surface: #1c1b19;
  --surface-2: #232120;
  --ink: #edeae4;
  --muted: #9a948b;
  --faint: #6d6862;
  --border: #2e2c29;
  --primary: #e5503f;
  --primary-ink: #ffffff;
  --danger: #f2555a;
  --accent: #7ca1f2;
  --ok: #4cc38a;
  --warn: #e0a437;
  --meter-track: #2a2826;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }

/* ---------- themed scrollbars (thin, follow light/dark) ---------- */
* { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--faint) 65%, transparent) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--faint) 60%, transparent);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--muted) 75%, transparent); background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }

body {
  background: var(--bg); color: var(--ink);
  font-family: var(--sans); font-size: 15px; line-height: 1.55;
  min-height: 100vh; display: flex; flex-direction: column;
  transition: background .25s ease, color .25s ease;
}

/* ---------- header ---------- */
header {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.hdr-row {
  max-width: var(--layout-max); margin: 0 auto; padding: 8px 24px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
/* 单行 header：波形弹性伸展吃掉中间空隙，避免大块空白堆在一处 */
#waveHeader { height: 26px; flex: 1 1 120px; min-width: 40px; max-width: 480px; opacity: .9; align-self: center; }
.meters { row-gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--primary); flex: none; }
.brand small { display: none; color: var(--muted); font-weight: 500; } /* header 单行预算紧张，副标题隐藏，品牌保留 */
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--mono); font-size: 12px; padding: 4px 11px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface); white-space: nowrap;
}
.pill .led { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
.pill[data-s="unloaded"] .led { background: var(--muted); }
.pill[data-s="loading"] .led { background: var(--warn); animation: blink 1s infinite; }
.pill[data-s="ready"] .led { background: var(--ok); }
@keyframes blink { 50% { opacity: .25; } }
.spacer { flex: 1 1 0; min-width: 0; }
.iconbtn {
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); cursor: pointer; flex: none;
  display: grid; place-items: center; transition: background .18s ease, transform .18s ease;
}
.iconbtn:hover { background: var(--surface-2); transform: translateY(-1px); }

/* ---------- two-column layout ---------- */
main {
  width: 100%; max-width: var(--layout-max); margin: 0 auto; padding: var(--gap) 24px 48px;
  display: grid; grid-template-columns: minmax(360px, 470px) minmax(0, 1fr);
  gap: var(--gap); align-items: stretch; flex: 1;
}
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: var(--pad);
  min-width: 0; display: flex; flex-direction: column;
}
.mono { font-family: var(--mono); }

/* ---------- LEFT: ops panel with step flow ---------- */
/* .ops 自己就是卡片兼滚动容器（宽屏 overflow-y:auto），.cta 是它的 sticky 子元素。
   sticky 的约束框 = 父级内容盒，所以卡片的 padding-bottom 会让 .cta 的底边永远停在
   内容盒底、比可视滚动区底高 --pad+1px；滚到中间位置时，那一条会变成"窗口"，
   高级参数里的滑块从"生成语音"下面钻出来（详见 .cta 注释）。
   底部内边距交给 .cta 自己出（它本来就带 --pad+3px 下内边距），这里置 0 让
   内容盒底与滚动视口底重合，缝就不存在了。左右上三个方向照旧。 */
.ops { position: relative; padding-bottom: 0; }
.opstep { position: relative; padding: 2px 0 18px 32px; }
.opstep + .opstep { border-top: 1px solid var(--border); padding-top: 18px; margin-top: 2px; }
.opstep::before { /* connector */
  content: ""; position: absolute; left: 9.5px; top: 24px; bottom: -20px; width: 1px;
  background: var(--border); border-radius: 1px;
}
/* 后面不再跟 opstep 的步骤（末步）：竖条止于自身底部，不伸入下方折叠面板 */
.opstep:has(+ :not(.opstep))::before { bottom: 0; }
.opstep::after { /* node */
  content: attr(data-step); position: absolute; left: 0; top: 1px;
  width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--mono); font-size: 10.5px; font-weight: 500;
  color: var(--faint); background: var(--surface-2);
  border: 1px solid var(--border);
}
.oplabel { display: block; font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.grow { display: flex; min-height: 0; }
.grow textarea { flex: 1; }
.opfoot { display: flex; justify-content: space-between; gap: 10px; margin-top: 7px; font-size: 11.5px; color: var(--faint); }

textarea, select, input[type="text"], input[type="number"] {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--ink); font-family: var(--sans); font-size: 14.5px;
  transition: border-color .18s ease, box-shadow .18s ease;
}
select {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  padding: 11px 38px 11px 13px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a09a90' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 13px center; background-size: 13px;
}
html[data-theme="dark"] select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236d6862' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
}
textarea { resize: none; overflow: hidden; min-height: 96px; max-height: 40vh; }
/* 合成文本框：固定高度 + 内部滚动，页面高度不随文本增长，长文本可滚动查看 */
#text { font-size: 16px; line-height: 1.7; height: 150px; min-height: 0; max-height: none; overflow-y: auto; padding: 13px 14px; }
/* 字数计数：接近上限时警示（配合 maxlength=2000 与后端 413 校验） */
#charCount.warn { color: var(--danger); font-weight: 700; }
textarea:focus, select:focus, input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

/* ---------- segments preview (collapsible, capped scroll) ---------- */
.seg-fold { margin-top: 8px; }
.seg-fold summary { padding: 6px 10px; font-size: 12px; }
.seg-scroll { max-height: 176px; overflow-y: auto; margin: 6px 0 2px; }
.seg-list { display: flex; flex-direction: column; gap: 4px; }
.seg-fold:not([open]) .seg-scroll { display: none; }
/* 分句 Token 滑块跟预览同属一个面板，收紧下边距避免贴到面板底边 */
.seg-fold .slider { margin: 6px 0 10px; }
.seg-fold .slider label span { font-size: 10.5px; }
.seg-item {
  display: flex; align-items: baseline; gap: 8px; padding: 6px 9px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2);
  font-size: 12px; color: var(--muted);
}
.seg-idx { font-family: var(--mono); font-size: 10.5px; color: var(--faint); flex: none; }
/* 每行显示完整分句（可换行），不再截断省略 */
.seg-text { flex: 1; min-width: 0; white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; line-height: 1.6; }
.seg-tok { font-family: var(--mono); font-size: 10.5px; color: var(--faint); flex: none; }

/* ---------- drop / reference ---------- */
.drop {
  border: 1.5px dashed var(--border); border-radius: 12px; padding: 16px 12px 13px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  text-align: center; color: var(--faint); cursor: pointer;
  transition: border-color .18s ease, background .18s ease;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--surface-2); }
/* 视觉隐藏而不是 display:none：原写法把 input 整个移出可访问性树，
   键盘 Tab 选不中、读屏软件也读不到，而这块区域鼠标点得了、上传功能正常，
   用户看不出它"存在但键盘不可用"。改成保留 1px 尺寸与可聚焦性，只是不看见。 */
.drop input {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
.drop:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.drop-ic { color: var(--faint); margin-bottom: 3px; }
.drop-main { font-size: 13px; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drop-sub { font-size: 11.5px; color: var(--faint); }
.drop.slim { padding: 10px 12px; }
#spkPlayerBox { margin-top: 10px; }
#spkPlayerBox.over canvas { border-color: var(--accent); }
#spkWave {
  width: 100%; height: 72px; display: block; border-radius: 8px;
  touch-action: none; cursor: pointer; background: var(--surface-2);
}
.refrow { display: flex; align-items: center; gap: 10px; margin-top: 7px; }
.refrow .range { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.ref-name {
  flex: 1; min-width: 0; font-size: 12.5px; font-weight: 600; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ref-change { flex: none; }

/* ---------- fold (details) ---------- */
.fold { margin-top: 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.fold summary {
  cursor: pointer; padding: 8px 12px; font-size: 12.5px; font-weight: 600;
  color: var(--muted); list-style: none; display: flex; align-items: center; gap: 8px; user-select: none;
}
.fold summary::before { content: "▸"; font-size: 11px; transition: transform .18s ease; }
.fold[open] summary::before { transform: rotate(90deg); }
.fold summary::-webkit-details-marker { display: none; }
.fold summary .q {
  width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--faint);
  display: inline-grid; place-items: center; font-size: 10px; color: var(--faint); cursor: help; flex: none;
}
.fold .chk { margin: 10px 0 0; }
/* 情感控制面板内容与高级参数完全一致（贴边、统一上间距） */
.emo-fold > select { margin: 10px 0 0; width: 100%; }
.linkbtn {
  background: none; border: none; color: var(--faint); font-size: 12px;
  cursor: pointer; text-decoration: underline; padding: 8px 0 2px; font-family: var(--sans);
}
.linkbtn:hover { color: var(--muted); }

/* ---------- sliders / checkbox ---------- */
.slider { margin: 10px 0 0; }
.slider.emo-w { margin: 12px 0 0; }
.slider label { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 600; }
.slider label span { color: var(--faint); font-weight: 400; font-family: var(--mono); font-size: 11.5px; }
.srow { display: flex; align-items: center; gap: 12px; margin-top: 5px; }
.srow input[type="range"], .edit-row input[type="range"] {
  flex: 1; appearance: none; -webkit-appearance: none; height: 5px; border-radius: 3px;
  background: linear-gradient(90deg, var(--accent) var(--fill, 50%), var(--meter-track) var(--fill, 50%));
  cursor: pointer; padding: 0; border: none; font: inherit;
}
.srow input[type="range"]::-webkit-slider-thumb,
.edit-row input[type="range"]::-webkit-slider-thumb {
  appearance: none; -webkit-appearance: none;
  width: 15px; height: 15px; border-radius: 50%; background: var(--surface);
  border: 2px solid var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s ease;
}
.srow input[type="range"]:active::-webkit-slider-thumb,
.edit-row input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.15); }
.edit-row input[type="range"]:disabled { opacity: .5; cursor: progress; }
.srow output { font-family: var(--mono); font-size: 12px; color: var(--ink); min-width: 42px; text-align: right; font-weight: 600; }
.grid-num { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.grid-num label { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; font-weight: 600; }
.grid-num label span { color: var(--faint); font-weight: 400; font-family: var(--mono); font-size: 10.5px; }
.chk { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; user-select: none; }
.chk span { color: var(--faint); font-weight: 400; font-family: var(--mono); font-size: 11px; }

/* ---------- emotion extras ---------- */
.emo-box { margin-top: 10px; }
.emo-box .hint-line { font-size: 11.5px; color: var(--warn); margin-top: 5px; }
.vec-chips { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; margin-bottom: 8px; }
.vec-chips-label { font-size: 11.5px; color: var(--faint); }
.chip {
  border: 1px solid var(--border); border-radius: 999px; cursor: pointer;
  background: var(--surface-2); color: var(--muted);
  font-family: var(--sans); font-size: 11.5px; padding: 3px 10px;
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.chip:hover { color: var(--ink); border-color: var(--accent); }
.chip.ghost { border-style: dashed; }
.vec-grid { display: grid; grid-template-columns: 1fr; gap: 6px; }
.vec-row { display: grid; grid-template-columns: 44px 1fr 42px; align-items: center; gap: 10px; }
.vec-name { font-size: 12.5px; color: var(--muted); }
.vec-val { font-family: var(--mono); font-size: 11.5px; color: var(--ink); text-align: right; }

/* ---------- switch ---------- */
.switch { display: flex; align-items: center; gap: 9px; margin-top: 10px; font-size: 13px; cursor: pointer; user-select: none; color: var(--ink); }
/* 同 .drop input：display:none 会让开关彻底无法用键盘操作。
   保留 1px 可聚焦，焦点环画到旁边的 .tk 上（:focus-visible 只在键盘操作时出现，
   鼠标点击不会多出一圈）。 */
.switch input {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
.switch input:focus-visible + .tk { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch .tk { width: 34px; height: 19px; border-radius: 999px; background: var(--meter-track); position: relative; transition: background .2s ease; flex: none; }
.switch .tk::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 15px; height: 15px;
  border-radius: 50%; background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: left .2s ease;
}
.switch input:checked + .tk { background: var(--accent); }
.switch input:checked + .tk::after { left: 17px; }

/* ---------- presets / glossary rows ---------- */
.preset-row { display: flex; gap: 8px; margin: 10px 12px 0; align-items: center; }
.preset-row select { flex: 1; min-width: 0; }
.preset-row input[type="text"] { flex: 1; min-width: 0; }
.preset-detail {
  margin: 8px 12px 0; padding: 9px 11px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border);
  font-family: var(--mono); font-size: 11.5px; line-height: 1.6; color: var(--muted);
  white-space: pre-wrap; word-break: break-all; max-height: 170px; overflow-y: auto;
}
.gl-add { display: grid; grid-template-columns: 1.3fr 1fr 1fr auto; gap: 8px; margin: 10px 12px 0; }
.gl-add input { font-size: 13px; padding: 8px 10px; }
.gl-table { margin: 8px 12px 4px; display: flex; flex-direction: column; gap: 4px; }
.gl-row {
  display: grid; grid-template-columns: 1.2fr 1fr 1fr auto; gap: 8px; font-size: 12px;
  align-items: center;
  padding: 6px 9px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
.gl-row .gl-term { font-weight: 600; color: var(--ink); min-width: 0; overflow-wrap: anywhere; }
.gl-row span:not(.gl-term) {
  color: var(--muted); font-family: var(--mono); font-size: 11px;
  min-width: 0; white-space: normal; word-break: break-word; overflow-wrap: anywhere;
}
/* 单条术语的删除按钮：默认淡出，hover 行/聚焦时才显形，避免列表一片叉号 */
.gl-del {
  width: 22px; height: 22px; padding: 0; justify-self: end;
  border: 1px solid transparent; border-radius: 6px; background: none;
  color: var(--faint); cursor: pointer; display: grid; place-items: center;
  font-size: 14px; line-height: 1; opacity: 0;
  transition: opacity .15s ease, color .15s ease, background .15s ease, border-color .15s ease;
}
.gl-row:hover .gl-del,
.gl-del:focus-visible { opacity: 1; }
.gl-del:hover {
  color: var(--danger); border-color: var(--border);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}
/* 触屏没有 hover，直接常显 */
@media (hover: none) {
  .gl-del { opacity: 1; }
}
.gl-foot { display: flex; justify-content: flex-end; margin: 4px 12px 2px; }
.gl-foot .linkbtn { font-size: 11.5px; color: var(--faint); }
.gl-foot .linkbtn:hover { color: var(--danger); }
/* 级联替换读音开关：放在术语面板最上面。
   左右 12px 是这个面板的基准（.fold summary 的 padding、.gl-add、.gl-table
   都是 12px），上边距 10px 与下面的添加行一致。 */
.gl-cascade { margin: 10px 12px 0; font-size: 12.5px; }
.gl-cascade .qinfo { vertical-align: baseline; }

/* ---------- main CTA ---------- */
.cta {
  position: sticky; bottom: 0; z-index: 3; margin-top: auto;
  /* 左右负 margin 让吸底条铺满卡片整宽（上边留给内容，不铺）。
     底部不加负 margin：sticky 的约束框是父级**内容盒**，负 margin 只会改
     滚动高度、不会把盒子推出内容盒，写了也没用——底部那条缝由父级 .ops
     的 padding-bottom:0 从结构上消掉。 */
  margin-left: calc(-1 * var(--pad)); margin-right: calc(-1 * var(--pad));
  padding: 14px var(--pad) calc(var(--pad) + 3px);
  /* 吸底条底边与卡片内底重合，得自己带圆角；
     窄屏（≤1240px，走单列）卡片不滚动、没有 overflow 裁剪，缺了它方角会戳出圆角外 */
  border-radius: 0 0 calc(var(--radius) - 1px) calc(var(--radius) - 1px);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 12px; padding: 11px 20px; font-size: 15px; font-weight: 700;
  font-family: var(--sans); cursor: pointer;
  transition: transform .16s ease, filter .16s ease, box-shadow .16s ease;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); box-shadow: 0 6px 18px color-mix(in srgb, var(--primary) 35%, transparent); }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; filter: none; box-shadow: none; }
/* 通用禁用态：ghost 变体原本一条都没有，撤销/重做/重置全部置灰后看起来照样能点 */
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; filter: none; box-shadow: none; }
.btn.ghost:disabled:hover { background: transparent; }
.btn.primary.big {
  width: 100%; padding: 17px 22px; font-size: 17px; letter-spacing: .06em;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--primary) 30%, transparent);
}
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--border); font-weight: 600; }
.btn.ghost:hover { background: var(--surface-2); }
/* ghost 变体没有 :disabled 规则：置灰后 cursor 还是 pointer、hover 还会变底色，
   看起来照样能点。模型管理的「加载模型 / 卸载模型」都是 ghost 按钮，请求进行中
   置灰全靠这条撑着。 */
.btn.ghost:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost:disabled:hover { background: transparent; }
.btn.ghost.danger { color: var(--danger); }
/* 实底 danger 只服务非 ghost 变体；ghost danger 是描边样式，
   :not(.ghost) 防止这里把红底灌给 ghost（红底红字不可读） */
.btn.danger:not(.ghost) { background: var(--danger); color: #fff; }
.btn.danger:not(.ghost):hover { filter: brightness(1.08); box-shadow: 0 6px 18px color-mix(in srgb, var(--danger) 35%, transparent); }
.btn.ghost.danger { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
/* mini 是"尺寸"而不是"ghost 的附属"，写成通用选择器，实底变体（primary mini）才能一起变小 */
.btn.mini { padding: 8px 13px; font-size: 12.5px; border-radius: 9px; flex: none; }
/* ghost 有 1px 描边、实底没有，同排 mini 按钮会差 2px 高；给实底补一圈透明描边抹平 */
.btn.primary.mini { border: 1px solid transparent; }
.hint { font-size: 11.5px; color: var(--faint); min-height: 15px; text-align: center; margin-top: 7px; }
.hint.error { color: var(--danger); }

/* ---------- GLOSSARY ---------- */
.gl-error {
  margin-top: 8px; padding: 8px 10px; border-radius: 8px;
  font-size: 12.5px; color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border));
}

/* ---------- RIGHT: result showcase ---------- */
/* 同 .ops：右栏卡片也是滚动容器，末位的 .history 是 sticky 吸底条，
   卡片的 padding-bottom 会在吸底条下方留出一条"窗口"。底部内边距交给 .history 自己出。 */
.resultcard { min-height: 520px; padding-bottom: 0; }
.ph {
  flex: 1; border: 1.5px dashed var(--border); border-radius: 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 48px 24px; min-height: 360px; margin-bottom: 6px;
  background:
    radial-gradient(220px 150px at 50% 46%, color-mix(in srgb, var(--accent) 5%, transparent), transparent);
}
.ph-disc {
  width: 88px; height: 88px; border-radius: 50%;
  display: grid; place-items: center; color: var(--faint);
  border: 2px solid var(--border); background: var(--surface-2);
  box-shadow: 0 0 0 10px var(--surface), 0 0 0 11.5px var(--border);
}
.ph-disc svg { width: 34px; height: 34px; }
.ph-wave { display: flex; align-items: center; gap: 4px; height: 52px; }
.ph-wave i {
  display: block; width: 3.5px; border-radius: 2px; background: var(--border);
  animation: phbreathe 2.6s ease-in-out infinite;
}
.ph-wave i:nth-child(odd) { animation-delay: .4s; }
@keyframes phbreathe { 0%, 100% { height: 10px; } 50% { height: 40px; } }
.ph-text { font-size: 15px; font-weight: 600; color: var(--muted); }
.ph-est { font-size: 12px; color: var(--faint); }

/* loading */
.sc-loading { flex: 1; display: flex; align-items: center; justify-content: center; gap: 22px; padding: 40px 0; flex-wrap: wrap; min-height: 280px; }
.spinner {
  width: 68px; height: 68px; border-radius: 50%; flex: none;
  border: 6px solid var(--meter-track); border-top-color: var(--primary);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.sc-info { flex: 1 1 240px; max-width: 460px; }
.sc-stage { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.pbar { height: 8px; border-radius: 4px; background: var(--meter-track); overflow: hidden; }
.pbar i {
  display: block; height: 100%; width: 0%; border-radius: 4px;
  background: linear-gradient(90deg, var(--primary), color-mix(in srgb, var(--primary) 60%, var(--accent)));
  transition: width .4s ease;
}
.pmeta { display: flex; justify-content: space-between; gap: 12px; margin-top: 7px; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.pmeta b { color: var(--ink); font-weight: 600; }
.psteps { display: flex; align-items: center; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
/* 排队/生成中的取消按钮：弱化样式，不与进度信息抢焦点 */
.cancelbtn { margin-top: 12px; align-self: flex-start; }
.cancelbtn:disabled { opacity: .5; cursor: wait; }
.pstep {
  font-family: var(--mono); font-size: 11px; color: var(--faint);
  padding: 3px 9px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2);
  transition: color .2s ease, border-color .2s ease, background .2s ease;
}
.pstep.running { color: var(--warn); border-color: var(--warn); }
.pstep.done { color: var(--ok); border-color: var(--ok); background: color-mix(in srgb, var(--ok) 8%, var(--surface)); }
.psteps i { flex: none; width: 12px; height: 1px; background: var(--border); }
/* 触顶截断提示：warn 色而非 danger —— 音频已生成，只是结尾被截，可修参重试 */
.capnote {
  margin: 10px 2px 0; padding: 9px 13px; border-radius: 10px; font-size: 13px;
  background: color-mix(in srgb, var(--warn) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--warn) 38%, var(--border));
  color: var(--warn);
}
/* 规范化退化提示：第一次完整展开，之后降级成小铃铛（见 app.js 的 normCapNoteSeen） */
.capnote-soft { align-items: flex-start; }
.capnote-soft .capnote-full { flex: 1; min-width: 0; }
.capnote-mini {
  display: none; flex: none; border: 0; background: none; cursor: pointer;
  font-size: 15px; line-height: 1; padding: 0 0 0 8px; color: var(--warn);
}
.capnote-soft.quiet { padding: 4px 8px; width: fit-content; margin-top: 6px; }
.capnote-soft.quiet .capnote-full { display: none; }
.capnote-soft.quiet .capnote-mini { display: block; }
.capnote-mini:hover { filter: brightness(1.15); }
.capnote-mini:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.err {
  display: none; margin: 12px 2px; padding: 10px 13px; border-radius: 10px; font-size: 13px;
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--border));
  color: var(--danger); overflow-wrap: anywhere;
}
.err.on { display: block; }

/* big player */
.bigplayer { display: flex; gap: 14px; align-items: stretch; }
.bigp {
  width: 54px; height: 54px; border-radius: 50%; flex: none; align-self: center;
  background: var(--primary); color: var(--primary-ink); border: none;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--primary) 30%, transparent);
}
.bigp:hover { background: var(--primary); transform: translateY(-1px) scale(1.03); filter: brightness(1.06); }
.bp-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#waveTrim { width: 100%; height: 108px; display: block; border-radius: 8px; touch-action: none; cursor: crosshair; background: var(--surface-2); }
.bp-meta { display: flex; justify-content: space-between; gap: 10px; margin-top: 7px; font-size: 12.5px; color: var(--muted); }
.trim-hint { font-size: 12px; color: var(--faint); margin-top: 12px; }
/* 源音频操作行：播放 / 选区 / 下载。
   「下载」靠右推出去，与左边三个"操作源波形"的按钮在视觉上分开 */
.sel-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.sel-actions #dlSrcBtn { margin-left: auto; }
.dl-row { margin-top: 8px; }
.dl-name { font-family: var(--mono); font-size: 12px; color: var(--faint); word-break: break-all; }
.dl-name:empty { display: none; }

/* ---------- audio editing (gain / tempo / undo stack) ---------- */
.sec-t { display: flex; align-items: baseline; gap: 8px; font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 8px; }
.sec-t em { font-style: normal; font-size: 11.5px; font-weight: 400; color: var(--faint); }

.edit-panel { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.edit-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.edit-row > b { flex: none; width: 32px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.edit-row input[type="range"] { flex: 1; min-width: 110px; }
/* 变速：滑轨吃满可用宽度（原来被 max-width 260px 掐短），刻度挂在滑轨正下方 */
.tempo-wrap { flex: 1; min-width: 140px; display: flex; flex-direction: column; gap: 2px; }
.tempo-wrap input[type="range"] { flex: none; width: 100%; min-width: 0; }
.edit-ticks { display: flex; justify-content: space-between; padding: 0 7px; }
.edit-ticks .tick {
  background: none; border: none; padding: 1px 5px; border-radius: 4px; cursor: pointer;
  font-family: var(--mono); font-size: 10.5px; line-height: 1.5; color: var(--faint);
  transition: color .12s ease, background .12s ease;
}
.edit-ticks .tick:hover { color: var(--ink); background: var(--meter-track); }
.edit-ticks .tick.on { color: var(--accent); font-weight: 700; }
.edit-ticks .tick:disabled { opacity: .5; cursor: progress; }
/* 悬停时滑块放大一点，抓取感更明确（原样式只在按下时放大） */
.edit-row input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.12); }
.edit-row input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.22); }
.edit-val { font-size: 12px; font-weight: 600; color: var(--ink); min-width: 58px; }
.edit-note { font-size: 11.5px; color: var(--faint); }
.edit-note.busy { color: var(--warn); }
.warn-peak { color: var(--warn); }

.ops-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.ops-chips { flex: 1; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-height: 27px; min-width: 0; }
.ops-empty { font-size: 11.5px; color: var(--faint); }
.op-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px;
  padding: 4px 9px; font-size: 11.5px; font-family: var(--mono); color: var(--muted);
}
.op-chip i { font-style: normal; cursor: pointer; color: var(--faint); }
.op-chip i:hover { color: var(--danger); }

#resultPreview { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.out-player { display: flex; align-items: center; gap: 10px; }
.out-play {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  background: var(--primary); color: var(--primary-ink); border: none;
}
.out-play:hover { background: var(--primary); transform: translateY(-1px); filter: brightness(1.06); }
#waveOut { flex: 1; min-width: 0; height: 28px; display: block; border-radius: 6px; background: var(--surface-2); }
.out-dur { font-size: 12px; color: var(--muted); flex: none; min-width: 52px; text-align: right; }
/* 「下载编辑结果」跟着结果区一起出现/隐藏，名字在按钮下方占满整行（放得下长中文名） */
.out-foot { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin-top: 12px; }

/* ---------- result library (presets / examples tabs, bottom of right card) ---------- */
.history {
  position: sticky; bottom: 0; z-index: 3;
  /* 底部负 margin 对 sticky 无效（约束框是父级内容盒，负 margin 只改滚动高度），
     底部那条缝由父级 .resultcard 的 padding-bottom:0 消掉，这里自己带下内边距 */
  margin: 16px calc(-1 * var(--pad)) 0;
  padding: 10px var(--pad) var(--pad);
  /* 与 .cta 同理：底边贴到卡片内底，窄屏没有 overflow 裁剪时靠自带圆角收口 */
  border-radius: 0 0 calc(var(--radius) - 1px) calc(var(--radius) - 1px);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.lib-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
/* 资源库折叠：收起时只留一行（按钮 + tabs），工具行与列表整体隐藏 */
.lib-fold-btn { width: 26px; height: 26px; border-radius: 7px; flex: none; }
.lib-fold-btn svg { transition: transform .18s ease; }
.history.lib-collapsed .lib-tools,
.history.lib-collapsed .hist-list { display: none; }
.history.lib-collapsed .lib-fold-btn svg { transform: rotate(-90deg); }
.history.lib-collapsed { margin-top: 0; }
.lib-tabs { display: flex; gap: 6px; }
.libtab {
  border: 1px solid var(--border); border-radius: 999px; cursor: pointer;
  background: var(--surface-2); color: var(--muted);
  font-family: var(--sans); font-size: 12.5px; font-weight: 600; padding: 5px 14px;
  transition: color .16s ease, background .16s ease, border-color .16s ease;
}
.libtab:hover { color: var(--ink); }
.libtab.cur { color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, var(--surface)); border-color: color-mix(in srgb, var(--primary) 35%, transparent); }
.lib-tools { display: flex; gap: 8px; align-items: center; margin-left: auto; flex-wrap: wrap; }
.lib-tools input[type="text"] { width: 140px; padding: 6px 10px; font-size: 12.5px; }
/* 库区卡片网格：一屏多列，预设多时定位快 */
.hist-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 8px; max-height: 280px; overflow-y: auto; padding: 2px; }
.hist-item {
  position: relative; display: flex; flex-direction: column; gap: 5px;
  padding: 9px 11px; padding-right: 28px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
  cursor: pointer; transition: border-color .15s ease, background .15s ease, transform .15s ease; font-size: 12.5px; min-width: 0;
}
.hist-item:hover { border-color: var(--accent); background: var(--surface); transform: translateY(-1px); }
.hist-item.cur { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 5%, var(--surface)); }
/* 名称：最多两行，溢出省略 */
.hist-item .htext {
  font-weight: 600; color: var(--ink); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; min-width: 0;
}
.hist-item .hmeta { font-family: var(--mono); font-size: 10px; color: var(--faint); flex: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 卡片右上角删除按钮（复用预设管理页 .pm-del 样式） */
.hist-item .pm-del {
  position: absolute; top: 6px; right: 6px; width: 20px; height: 20px;
  border: none; border-radius: 5px; background: none; color: var(--faint);
  cursor: pointer; display: grid; place-items: center; font-size: 12px; line-height: 1;
  opacity: 0; transition: opacity .15s ease, color .15s ease, background .15s ease;
}
.hist-item:hover .pm-del { opacity: 1; }
.hist-item .pm-del:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }

/* gen summary line above CTA */
.gen-summary {
  font-size: 11.5px; color: var(--faint); line-height: 1.6;
  padding: 6px 10px; border: 1px dashed var(--border); border-radius: 9px;
  background: var(--surface-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-bottom: 10px;
}
/* ---------- right sidebar: this-run generation history ---------- */
.histbar { padding: 0; overflow: hidden; }
.hb-body { display: flex; flex-direction: column; flex: 1; min-height: 0; padding: 14px 14px 12px; }
.hb-head { display: flex; align-items: center; gap: 8px; }
.hb-title { font-size: 13.5px; font-weight: 600; }
.hb-badge {
  font-size: 10.5px; color: var(--muted); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px;
}
.hb-collapse { width: 26px; height: 26px; border-radius: 7px; margin-left: auto; }
.hb-note { font-size: 11px; color: var(--faint); line-height: 1.5; margin: 6px 0 9px; }
.hb-list {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px; padding-right: 2px;
}
.hb-item {
  position: relative; display: flex; flex-direction: column; gap: 4px;
  padding: 8px 26px 8px 10px; min-width: 0;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2);
  cursor: pointer; font-size: 12px;
  transition: border-color .15s ease, background .15s ease;
}
.hb-item:hover { border-color: var(--accent); background: var(--surface); }
.hb-item.cur { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 6%, var(--surface)); }
.hb-text {
  color: var(--ink); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.hb-meta {
  font-family: var(--mono); font-size: 10px; color: var(--faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hb-empty { color: var(--faint); font-size: 11.5px; line-height: 1.7; text-align: center; padding: 22px 6px; }
.hb-foot {
  margin-top: 9px; padding-top: 9px; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.hb-switch { margin-top: 0; font-size: 12px; }
.hb-clear { margin-left: auto; padding: 0; font-size: 11.5px; }
/* collapsed: the panel becomes a narrow vertical rail */
.hb-rail { display: none; }
.histbar.collapsed .hb-body { display: none; }
.histbar.collapsed .hb-rail {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  width: 100%; height: 100%; padding: 14px 0; border: none; background: none;
  color: var(--muted); cursor: pointer; font-family: var(--sans);
}
.histbar.collapsed .hb-rail:hover { color: var(--ink); background: var(--surface-2); }
.hb-rail-label { writing-mode: vertical-rl; font-size: 11.5px; letter-spacing: .1em; }
.hb-rail-count { font-size: 10.5px; color: var(--faint); }

/* ---------- footer & a11y ---------- */
footer { max-width: var(--layout-max); width: 100%; margin: 0 auto; padding: 0 24px 30px; color: var(--faint); font-size: 12px; }
footer a { color: var(--muted); }

/* ---------- modal dialog (replaces native confirm/prompt) ---------- */
.modal-mask {
  position: fixed; inset: 0; z-index: 100;
  background: color-mix(in srgb, var(--ink) 32%, transparent);
  backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px;
}
.modal {
  width: min(400px, 100%); background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
  padding: 18px 20px; display: flex; flex-direction: column; gap: 12px;
  animation: modalIn .16s ease;
}
@keyframes modalIn { from { transform: translateY(8px) scale(.98); opacity: 0; } }
.modal-title { font-size: 15px; font-weight: 700; }
.modal-body { font-size: 13.5px; color: var(--muted); line-height: 1.65; overflow-wrap: anywhere; }
.modal-error { font-size: 12.5px; color: var(--danger); }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; align-items: center; margin-top: 2px; }
.modal-foot .btn { padding: 9px 18px; font-size: 13.5px; }
.modal-foot input[type="text"] { flex: 1; min-width: 0; padding: 9px 12px; font-size: 13.5px; }
.btn:focus-visible, .iconbtn:focus-visible, .fold summary:focus-visible, .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- header tab nav ---------- */
.tabs { display: flex; gap: 6px; }
.tab {
  border: 1px solid transparent; border-radius: 999px; cursor: pointer;
  background: none; color: var(--muted);
  font-family: var(--sans); font-size: 13px; font-weight: 600; padding: 6px 14px;
  transition: color .18s ease, background .18s ease, border-color .18s ease;
}
.tab:hover { color: var(--ink); background: var(--surface-2); }
.tab.cur { color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, var(--surface)); border-color: color-mix(in srgb, var(--primary) 35%, transparent); }

/* ---------- page switching (gen / presets / model) ---------- */
.page { display: none; }
.page.cur { display: block; }
main#pages { display: block; }
.page[data-page="gen"].cur {
  display: grid; grid-template-columns: minmax(520px, 560px) minmax(0, 1fr) 268px;
  gap: var(--gap); align-items: stretch;
}
.page[data-page="gen"].cur.hist-collapsed {
  grid-template-columns: minmax(520px, 560px) minmax(0, 1fr) 46px;
}

/* 宽屏改成应用式布局：页面本身不滚动，左右卡片各自内部滚动。
   这样生成按钮和资源库能真正固定在各自可视区域底部。 */
@media (min-width: 1101px) {
  body { height: 100vh; overflow: hidden; }
  main#pages { flex: 1; min-height: 0; }
  .page { height: 100%; }
  .page:not([data-page="gen"]).cur { overflow-y: auto; }
  .ops, .resultcard, .histbar { overflow-y: auto; }
}

/* ---------- header gauges (device / cpu / mem / gpu / vram) ---------- */
.meters { display: flex; gap: 14px; margin-left: 12px; flex-wrap: nowrap; justify-content: flex-end; align-items: flex-start; }
.meter { display: flex; flex-direction: column; gap: 4px; width: 86px; flex: none; font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.meter > span {
  display: flex; justify-content: space-between; align-items: baseline; gap: 6px;
  white-space: nowrap; overflow: hidden; line-height: 16px; min-width: 0;
}
.meter > span b { overflow: hidden; text-overflow: ellipsis; flex: none; }
.meter b { color: var(--ink); font-weight: 600; white-space: nowrap; }
.meter .bar { height: 4px; border-radius: 2px; background: var(--meter-track); overflow: hidden; }
.meter .bar i { display: block; height: 100%; width: 0%; background: var(--accent); border-radius: 2px; transition: width .6s ease; }
.meter.hot .bar i { background: var(--danger); }

/* ---------- manage pages shared ---------- */
.mg-card { max-width: 1080px; margin: 0 auto; width: 100%; }
.mg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.mg-grid > .mg-col { min-width: 0; display: flex; flex-direction: column; }
.mg-h { margin: 0 0 10px; font-size: 15px; font-weight: 700; }
.mg-hint { font-size: 12px; color: var(--faint); line-height: 1.7; margin-top: 4px; }
.mg-btnrow { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.mg-btnrow .btn { padding: 9px 16px; font-size: 13.5px; }
.mg-slider { margin: 12px 0 0; }
.mg-save { margin-top: 16px; padding: 10px 22px; font-size: 14px; align-self: flex-start; }

.preset-row.wide { margin: 0; }
.preset-detail.wide { margin: 10px 0 0; max-height: 260px; }

.kv {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); font-size: 13.5px;
}
.kv b { font-weight: 600; }
.kv b.ok { color: var(--ok); }
.kv b.off { color: var(--muted); }

/* quality badges (acceleration options) */
.q-legend { margin: 2px 0 12px; display: flex; flex-direction: column; gap: 4px; }
.q-legend p { margin: 0; font-size: 11.5px; color: var(--faint); }
.qzb {
  display: inline-block; font-family: var(--mono); font-size: 10px; font-weight: 600;
  padding: 2px 7px; border-radius: 999px; margin-right: 7px; border: 1px solid transparent;
  vertical-align: 1px;
}
.qzb.near { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.qzb.drop { color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); border-color: color-mix(in srgb, var(--warn) 32%, transparent); }
.qzb.warn { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); border-color: color-mix(in srgb, var(--danger) 32%, transparent); }

/* acceleration switch rows get looser spacing than the ops panel */
.mg-col .switch { margin-top: 12px; font-size: 13.5px; }
.mg-col .switch .qzb { margin-left: auto; }

/* disabled acceleration option */
.switch.cfg-disabled { opacity: .55; cursor: not-allowed; }
.switch.cfg-disabled .tk { background: var(--meter-track); }
.qinfo {
  width: 17px; height: 17px; border-radius: 50%; flex: none;
  display: inline-grid; place-items: center; margin-left: 6px;
  font-family: var(--sans); font-size: 10.5px; font-weight: 600;
  color: var(--faint); border: 1px solid var(--faint);
  cursor: help; background: var(--surface);
}
.qinfo:hover { color: var(--accent); border-color: var(--accent); }

/* mg col header row (title + inline tools) */
.mg-grid-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.mg-grid-head .mg-h { margin: 0; }
.pm-tools { display: flex; gap: 8px; align-items: center; flex: 1; justify-content: flex-end; min-width: 0; }
.pm-tools input[type="text"] { width: 180px; padding: 7px 11px; font-size: 13px; }
.wide-col { flex: 1; min-width: 0; }

/* preset card flow */
.pm-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 10px; }
.pm-card {
  position: relative; display: flex; flex-direction: column; gap: 6px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2);
  padding: 12px 13px; cursor: pointer; transition: border-color .16s ease, background .16s ease, transform .16s ease;
}
.pm-card:hover { border-color: var(--accent); background: var(--surface); transform: translateY(-1px); }
.pm-card.cur { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 5%, var(--surface)); }
.pm-name { font-size: 13.5px; font-weight: 700; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 26px; }
.pm-meta { font-family: var(--mono); font-size: 10.5px; color: var(--faint); display: flex; flex-direction: column; gap: 2px; }
.pm-del {
  position: absolute; top: 8px; right: 8px; width: 22px; height: 22px;
  border: none; border-radius: 6px; background: none; color: var(--faint);
  cursor: pointer; display: grid; place-items: center; font-size: 13px; line-height: 1;
  transition: color .15s ease, background .15s ease;
}
.pm-del:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.pm-empty { grid-column: 1 / -1; color: var(--faint); font-size: 12.5px; padding: 18px 4px; text-align: center; }

/* 预设卡片操作按钮组（改名/复制，hover 浮出，与删除按钮并排） */
.pm-acts {
  position: absolute; top: 8px; right: 34px;
  display: flex; gap: 2px;
  opacity: 0; transition: opacity .15s ease;
}
.pm-card:hover .pm-acts, .hist-item:hover .pm-acts { opacity: 1; }
.pm-act {
  border: none; border-radius: 5px; background: none; color: var(--faint);
  cursor: pointer; display: grid; place-items: center;
  width: 22px; height: 22px; padding: 0;
  font-size: 12px; line-height: 1;
  transition: color .15s ease, background .15s ease;
}
.pm-act:hover { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.pm-act:disabled { opacity: .4; cursor: wait; }
/* 库区列表行的操作按钮（同一套） */
.hist-item .pm-acts { top: 6px; right: 30px; }
.hist-item .pm-act { width: 20px; height: 20px; font-size: 11px; }

/* responsive */
/* header 单行预算约 1230px。更窄时收起波形，仪表条与 tabs+按钮同落第二行：
   第一行 = 品牌 + 模型状态 + 设备；第二行 = 仪表(左) … tabs+主题按钮(右) */
@media (max-width: 1280px) {
  #waveHeader { display: none; }
  .spacer { display: none; }
  .meters { order: 3; margin-top: 2px; }
  .meter { width: 84px; }
  #tabs { order: 4; margin-left: auto; }
  #themeBtn { order: 5; }
}
/* 单列回退点：1100 -> 1240。
   三栏的固定部分最少要 520(左) + 268(右) + 32(间距) = 820，中间栏拿剩下的。
   实测：1101px 时中间栏只剩 145px，播放按钮/波形/操作按钮/编辑滑块
   全被压扁（标题与按钮文字折行、文件名折成 4 行）。断点应该设在
   「三栏刚好够用」的位置，而不是「单列还塞得下」的位置。 */
@media (max-width: 1240px) {
  .page[data-page="gen"].cur,
  .page[data-page="gen"].cur.hist-collapsed { grid-template-columns: minmax(0, 1fr); }
  .resultcard { min-height: 300px; }
  .mg-grid { grid-template-columns: 1fr; }
  /* 单栏下侧边栏铺满整行，窄条形态没有意义，强制展开 */
  .histbar.collapsed .hb-body { display: flex; }
  .histbar.collapsed .hb-rail { display: none; }
  .hb-list { max-height: 260px; }
}
/* 宽屏档：--layout-max 的上限下，中间栏已能给到 660px；再放宽两侧固定档，
   免得 1920/2560 屏上把富余空间全浪费在留白里。 */
@media (min-width: 1600px) {
  .page[data-page="gen"].cur {
    grid-template-columns: minmax(560px, 620px) minmax(0, 1fr) 300px;
  }
}
@media (max-width: 768px) {
  :root { --pad: 16px; --gap: 12px; }
  main#pages { padding-left: 14px; padding-right: 14px; }
  .hdr-row { padding: 8px 14px; gap: 8px 10px; }
  #waveHeader { display: none; }
  footer { padding: 0 14px 24px; }
  .bigplayer { flex-direction: column; align-items: stretch; }
  .bigp { align-self: flex-start; }
  .gl-add { grid-template-columns: 1fr 1fr; }
  .gl-add button { grid-column: 1 / -1; }
  /* 窄屏放不下三列文本，术语名独占首行，读法与删除按钮挤第二行 */
  .gl-row { grid-template-columns: 1fr 1fr auto; }
  .gl-row .gl-term { grid-column: 1 / -1; }
  .gl-del { opacity: 1; }
}
@media (max-width: 480px) {
  .brand small { display: none; }
  .pill { font-size: 11px; }
  /* 极窄视口：三个选区按钮等分一行，「下载」独占下一行铺满 */
  .sel-actions { gap: 6px; }
  .sel-actions .btn { flex: 1 1 0; min-width: 0; }
  .sel-actions #dlSrcBtn { margin-left: 0; flex: 1 1 100%; }
  .out-foot { align-items: stretch; }
  .out-foot .btn { width: 100%; }
  .grid-num { grid-template-columns: 1fr; }
  /* 极窄视口：编辑行放不下"标签+滑块+数值+峰值"，让滑块独占一行 */
  .edit-row > b { width: 100%; }
  .edit-row input[type="range"] { max-width: none; min-width: 0; }
  /* 极窄视口：仪表与 tabs 各占一行铺满；主题按钮浮到 header 右上角 */
  .meter { width: 72px; }
  .meters { order: 3; width: 100%; justify-content: flex-start; margin-left: 0; }
  #tabs { order: 4; width: 100%; margin-left: 0; justify-content: flex-start; }
  .tab { flex: 1; padding: 6px 8px; }
  #themeBtn { position: fixed; top: 8px; right: 10px; order: 0; z-index: 20; }
  .mg-btnrow .btn { flex: 1; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
