:root {
  --bg: #f7f6f3;
  --bg-elev: #ffffff;
  --bg-soft: #efede8;
  --bg-hover: #e8e5df;
  --sidebar: #f0eee9;
  --text: #1f1e1c;
  --text-2: #5c5953;
  --text-3: #8d8a83;
  --border: #e2dfd8;
  --border-strong: #d2cec5;
  --accent: #d9534f;
  --accent-2: #e8735a;
  --accent-soft: rgba(217, 83, 79, 0.1);
  --ok: #2f9e6b;
  --warn: #c98a1b;
  --err: #d14343;
  --err-soft: rgba(209, 67, 67, 0.08);
  --shadow: 0 1px 2px rgba(20, 18, 14, 0.06), 0 6px 24px rgba(20, 18, 14, 0.06);
  --radius: 14px;
  --font: 'Inter', 'PingFang SC', 'Microsoft YaHei', 'Noto Sans CJK SC', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'Cascadia Code', Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #1c1b19;
    --bg-elev: #262522;
    --bg-soft: #2c2b28;
    --bg-hover: #34322e;
    --sidebar: #171614;
    --text: #ecebe7;
    --text-2: #b4b1aa;
    --text-3: #85827b;
    --border: #36342f;
    --border-strong: #46433d;
    --accent-soft: rgba(232, 115, 90, 0.14);
    --err-soft: rgba(209, 67, 67, 0.14);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 28px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #1c1b19;
  --bg-elev: #262522;
  --bg-soft: #2c2b28;
  --bg-hover: #34322e;
  --sidebar: #171614;
  --text: #ecebe7;
  --text-2: #b4b1aa;
  --text-3: #85827b;
  --border: #36342f;
  --border-strong: #46433d;
  --accent-soft: rgba(232, 115, 90, 0.14);
  --err-soft: rgba(209, 67, 67, 0.14);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 28px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14.5px/1.6 var(--font); -webkit-font-smoothing: antialiased; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent-2); }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }

.app { display: grid; grid-template-columns: 264px 1fr auto; height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar { background: var(--sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-width: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 12px; font-weight: 650; font-size: 16px; letter-spacing: 0.2px; }
.brand-logo { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, var(--accent), #f0a35e); display: grid; place-items: center; color: #fff; box-shadow: 0 4px 14px rgba(217, 83, 79, 0.35); }
.brand-logo svg { width: 17px; height: 17px; }
.brand small { display: block; font-weight: 450; font-size: 11.5px; color: var(--text-3); letter-spacing: 0; }
.side-actions { padding: 4px 12px 8px; display: flex; flex-direction: column; gap: 2px; }
.side-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 9px; background: transparent; text-align: left; color: var(--text-2); }
.side-btn:hover { background: var(--bg-hover); color: var(--text); }
.side-btn.active { background: var(--bg-elev); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.side-btn.primary { color: var(--text); font-weight: 550; }
.side-label { padding: 14px 22px 6px; font-size: 11.5px; color: var(--text-3); font-weight: 600; letter-spacing: 0.4px; }
.session-list { flex: 1; overflow-y: auto; padding: 0 12px 12px; }
.session { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 9px; color: var(--text-2); cursor: pointer; position: relative; }
.session:hover { background: var(--bg-hover); color: var(--text); }
.session.active { background: var(--bg-elev); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.session .t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13.5px; }
.session .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-2); animation: pulse 1.2s infinite; flex: none; }
.session .del { opacity: 0; border: 0; background: transparent; padding: 2px; border-radius: 6px; color: var(--text-3); display: grid; }
.session:hover .del { opacity: 1; }
.session .del:hover { color: var(--err); background: var(--err-soft); }
.session .del svg { width: 15px; height: 15px; }
.side-foot { border-top: 1px solid var(--border); padding: 10px 12px; display: flex; align-items: center; gap: 6px; }
.side-foot .side-btn { flex: 1; }
.conn { font-size: 11.5px; color: var(--text-3); display: flex; align-items: center; gap: 6px; padding: 0 6px; white-space: nowrap; }
.conn i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.conn.ok i { background: var(--ok); }
.conn.bad i { background: var(--err); }

/* ---------- main ---------- */
.main { min-width: 0; display: flex; flex-direction: column; position: relative; }
.view { display: flex; flex-direction: column; height: 100vh; min-height: 0; }
.topbar { height: 52px; display: flex; align-items: center; gap: 10px; padding: 0 18px; border-bottom: 1px solid transparent; flex: none; }
.topbar.bordered { border-bottom-color: var(--border); }
.topbar .title { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 4px 8px; border-radius: 8px; border: 1px solid transparent; outline: none; max-width: 60%; }
.topbar .title[contenteditable='true']:hover { border-color: var(--border); }
.topbar .title[contenteditable='true']:focus { border-color: var(--border-strong); background: var(--bg-elev); }
.topbar .spacer { flex: 1; }
.icon-btn { width: 34px; height: 34px; display: grid; place-items: center; border: 0; background: transparent; border-radius: 9px; color: var(--text-2); }
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.on { color: var(--accent-2); background: var(--accent-soft); }
.menu-btn { display: none; }
#view-studio .topbar { display: none; }

.chat-scroll { flex: 1; overflow-y: auto; scroll-behavior: auto; }
.thread { max-width: 820px; margin: 0 auto; padding: 18px 24px 40px; display: flex; flex-direction: column; gap: 14px; }

/* welcome */
.welcome { max-width: 860px; margin: 0 auto; padding: 9vh 24px 24px; }
.welcome h1 { font-size: 30px; font-weight: 600; letter-spacing: -0.3px; margin: 0 0 6px; text-align: center; font-family: Georgia, 'Songti SC', 'Noto Serif CJK SC', serif; }
.welcome p.sub { text-align: center; color: var(--text-3); margin: 0 0 28px; }
.examples { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.examples .example:last-child:nth-child(3n+1) { grid-column: 1 / -1; }
.example { text-align: left; border: 1px solid var(--border); background: var(--bg-elev); border-radius: var(--radius); padding: 14px 14px 13px; transition: transform .15s, border-color .15s, box-shadow .15s; display: flex; flex-direction: column; gap: 6px; }
.example:hover { border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-1px); }
.example .k { display: flex; align-items: center; gap: 7px; font-weight: 600; font-size: 13px; }
.example .k svg { width: 16px; height: 16px; color: var(--accent-2); }
.example .d { color: var(--text-2); font-size: 12.8px; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* message blocks */
.msg-user { align-self: flex-end; max-width: 78%; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.bubble { background: var(--bg-soft); border: 1px solid var(--border); padding: 9px 14px; border-radius: 16px 16px 4px 16px; white-space: pre-wrap; word-break: break-word; }
.user-meta { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.tag { font-size: 11.5px; color: var(--text-3); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; background: var(--bg-elev); }
.att-row { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.att-thumb { width: 84px; height: 60px; border-radius: 9px; overflow: hidden; border: 1px solid var(--border); background: #000; position: relative; cursor: pointer; }
.att-thumb img, .att-thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.att-thumb .badge { position: absolute; right: 4px; bottom: 4px; font-size: 10.5px; background: rgba(0,0,0,.6); color: #fff; padding: 0 5px; border-radius: 5px; }
.att-thumb.audio { display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, #6d5bd0, #3b82f6); }

.msg-ai { display: flex; gap: 12px; align-items: flex-start; }
.avatar { width: 28px; height: 28px; border-radius: 8px; flex: none; background: linear-gradient(135deg, var(--accent), #f0a35e); display: grid; place-items: center; color: #fff; margin-top: 2px; }
.avatar svg { width: 15px; height: 15px; }
.avatar.ghost { visibility: hidden; }
.ai-body { flex: 1; min-width: 0; }
.md { word-break: break-word; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md h2, .md h3, .md h4, .md h5 { margin: 16px 0 8px; line-height: 1.35; }
.md h2 { font-size: 18px; } .md h3 { font-size: 16px; } .md h4, .md h5 { font-size: 14.5px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin: 2px 0; }
.md code { font-family: var(--mono); font-size: 12.5px; background: var(--bg-soft); border: 1px solid var(--border); padding: 0 5px; border-radius: 5px; }
.md pre { background: var(--bg-soft); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; overflow-x: auto; }
.md pre code { border: 0; background: transparent; padding: 0; }
.md blockquote { margin: 0 0 10px; padding: 2px 14px; border-left: 3px solid var(--border-strong); color: var(--text-2); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.md-table { overflow-x: auto; margin: 0 0 12px; border: 1px solid var(--border); border-radius: 10px; }
.md table { border-collapse: collapse; width: 100%; font-size: 13px; }
.md th, .md td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.md th { background: var(--bg-soft); font-weight: 600; white-space: nowrap; }
.md tr:last-child td { border-bottom: 0; }
.md-check { display: inline-block; width: 13px; height: 13px; border: 1.5px solid var(--text-3); border-radius: 4px; margin-right: 6px; vertical-align: -2px; }
.md-check.on { background: var(--ok); border-color: var(--ok); }
.cursor::after { content: ''; display: inline-block; width: 7px; height: 15px; background: var(--text-2); margin-left: 2px; vertical-align: -2px; animation: blink 1s steps(2) infinite; border-radius: 1px; }

details.thinking { margin: 0 0 8px; color: var(--text-3); font-size: 13px; }
details.thinking summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 6px; user-select: none; }
details.thinking summary::-webkit-details-marker { display: none; }
details.thinking summary svg { width: 14px; height: 14px; transition: transform .15s; }
details.thinking[open] summary svg { transform: rotate(90deg); }
details.thinking .think-body { white-space: pre-wrap; border-left: 2px solid var(--border); padding: 4px 0 4px 12px; margin-top: 6px; max-height: 280px; overflow-y: auto; }

/* tool card */
.tool { border: 1px solid var(--border); background: var(--bg-elev); border-radius: 12px; overflow: hidden; }
.tool-head { display: flex; align-items: center; gap: 10px; padding: 9px 12px; cursor: pointer; user-select: none; }
.tool-head:hover { background: var(--bg-soft); }
.tool-ico { width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; background: var(--bg-soft); color: var(--text-2); flex: none; }
.tool-ico svg { width: 15px; height: 15px; }
.tool.running .tool-ico { color: var(--accent-2); background: var(--accent-soft); }
.tool.done .tool-ico { color: var(--ok); }
.tool.error .tool-ico { color: var(--err); background: var(--err-soft); }
.tool-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; }
.tool-title b { font-weight: 600; font-size: 13.5px; white-space: nowrap; }
.tool-title span { color: var(--text-3); font-size: 12.8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool-status { font-size: 12px; color: var(--text-3); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.tool-status .retry { display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 9px; border-radius: 7px; border: 1px solid color-mix(in srgb, var(--err) 45%, transparent); background: var(--bg-elev); color: var(--err); font: inherit; font-size: 12px; cursor: pointer; }
.tool-status .retry svg { width: 13px; height: 13px; }
.tool-status .retry:hover { background: color-mix(in srgb, var(--err) 10%, var(--bg-elev)); }
.tool-status .retry:disabled { opacity: .5; cursor: default; }
.tool-status .spin { width: 13px; height: 13px; border: 2px solid var(--border-strong); border-top-color: var(--accent-2); border-radius: 50%; animation: spin .8s linear infinite; }
.tool-chev { color: var(--text-3); transition: transform .15s; }
.tool-chev svg { width: 15px; height: 15px; }
.tool.open .tool-chev { transform: rotate(90deg); }
.tool-progress { height: 2px; background: var(--bg-soft); position: relative; overflow: hidden; }
.tool-progress i { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .4s; }
.tool-progress.indet i { width: 30% !important; animation: indet 1.4s ease-in-out infinite; }
.tool-msg { padding: 0 12px 9px 48px; font-size: 12.5px; color: var(--text-2); margin-top: -3px; }
.tool-body { display: none; border-top: 1px solid var(--border); padding: 10px 12px 12px; font-size: 13px; }
.tool.open .tool-body { display: block; }
.kv { display: grid; grid-template-columns: 76px 1fr; gap: 4px 10px; color: var(--text-2); }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.tool-err { color: var(--err); font-size: 12.8px; padding: 0 12px 10px 48px; white-space: pre-wrap; word-break: break-word; }
.tool-assets { padding: 0 12px 12px 48px; display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.tool-assets.single { grid-template-columns: minmax(0, 420px); }
.tool-assets.hero { grid-template-columns: minmax(0, 1fr); padding-left: 12px; }
.media { position: relative; border-radius: 10px; overflow: hidden; background: #000; border: 1px solid var(--border); }
.media img { display: block; width: 100%; height: auto; max-height: 340px; object-fit: contain; cursor: zoom-in; background: #0d0d0d; }
.media video { display: block; width: 100%; max-height: 420px; background: #000; }
.hero .media video { max-height: 520px; }
.media .mbar { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.media:hover .mbar { opacity: 1; }
.mbar button, .mbar a { width: 28px; height: 28px; border-radius: 7px; border: 0; background: rgba(0,0,0,.62); color: #fff; display: grid; place-items: center; text-decoration: none; }
.mbar svg { width: 15px; height: 15px; }
.media .cap { position: absolute; left: 6px; bottom: 6px; font-size: 11px; color: #fff; background: rgba(0,0,0,.58); padding: 1px 6px; border-radius: 5px; pointer-events: none; }
.media video + .cap { bottom: auto; top: 6px; }
.render-actions { display: flex; gap: 8px; padding: 0 12px 12px; flex-wrap: wrap; }
.media.audio { background: var(--bg-soft); padding: 8px 10px 6px; }
.media.audio audio { display: block; width: 100%; height: 36px; }
.audio-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; }
.audio-row svg { width: 15px; height: 15px; color: var(--accent-2); }
.audio-row span { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.audio-row a { margin-left: auto; color: var(--text-3); display: grid; }
.audio-row a:hover { color: var(--text); }

.btn { display: inline-flex; align-items: center; gap: 7px; padding: 7px 13px; border-radius: 9px; border: 1px solid var(--border-strong); background: var(--bg-elev); font-size: 13px; text-decoration: none; color: var(--text); }
.btn:hover { background: var(--bg-soft); }
.btn svg { width: 15px; height: 15px; }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.primary:hover { opacity: .9; }
.btn.danger { color: var(--err); }
.btn:disabled { opacity: .5; cursor: default; }

/* plan */
.plan { border: 1px solid var(--border); background: var(--bg-elev); border-radius: 12px; padding: 10px 14px; }
.plan h4 { margin: 0 0 6px; font-size: 12.5px; color: var(--text-3); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.plan h4 svg { width: 14px; height: 14px; }
.plan ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.plan li { display: flex; align-items: center; gap: 9px; font-size: 13.5px; }
.plan li .box { width: 16px; height: 16px; border-radius: 50%; border: 1.6px solid var(--border-strong); flex: none; display: grid; place-items: center; }
.plan li.done { color: var(--text-3); text-decoration: line-through; }
.plan li.done .box { background: var(--ok); border-color: var(--ok); }
.plan li.done .box::after { content: ''; width: 7px; height: 4px; border: 2px solid #fff; border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.plan li.in_progress { font-weight: 550; }
.plan li.in_progress .box { border-color: var(--accent-2); }
.thread.running .plan li.in_progress .box { border-top-color: transparent; animation: spin 1s linear infinite; }

.question { border: 1px solid var(--border); background: var(--bg-elev); border-radius: 12px; padding: 12px 14px; }
.question .q { font-weight: 550; margin-bottom: 10px; }
.question .opts { display: flex; flex-direction: column; gap: 6px; }
.question .opt { text-align: left; border: 1px solid var(--border); background: var(--bg); border-radius: 9px; padding: 8px 12px; }
.question .opt:hover:not(:disabled) { border-color: var(--accent-2); background: var(--accent-soft); }
.question .opt:disabled { opacity: .55; cursor: default; }

.notice { align-self: center; font-size: 12.5px; color: var(--text-3); background: var(--bg-soft); padding: 3px 12px; border-radius: 999px; }
.error-box { border: 1px solid color-mix(in srgb, var(--err) 35%, transparent); background: var(--err-soft); color: var(--text); border-radius: 12px; padding: 10px 14px; font-size: 13.5px; white-space: pre-wrap; word-break: break-word; display: flex; gap: 10px; align-items: flex-start; }
.error-box svg { color: var(--err); margin-top: 2px; }
.error-box .btn { margin-top: 8px; }

.typing { display: flex; gap: 4px; padding: 8px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }

/* composer */
.composer-wrap { flex: none; padding: 0 24px 18px; }
.composer-inner { max-width: 820px; margin: 0 auto; }
.modes { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.mode { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg-elev); font-size: 12.8px; color: var(--text-2); white-space: nowrap; }
.mode svg { width: 14px; height: 14px; }
.mode:hover { color: var(--text); border-color: var(--border-strong); }
.mode.active { color: var(--accent-2); border-color: color-mix(in srgb, var(--accent-2) 55%, transparent); background: var(--accent-soft); font-weight: 550; }
.composer { border: 1px solid var(--border-strong); background: var(--bg-elev); border-radius: 18px; box-shadow: var(--shadow); padding: 10px 10px 8px 14px; transition: border-color .15s; }
.composer:focus-within { border-color: color-mix(in srgb, var(--accent-2) 50%, var(--border-strong)); }
.composer.drag { border-color: var(--accent-2); border-style: dashed; }
.composer textarea { width: 100%; border: 0; outline: 0; resize: none; background: transparent; min-height: 26px; max-height: 240px; line-height: 1.55; padding: 4px 0; font-size: 15px; }
.composer textarea::placeholder { color: var(--text-3); }
.c-atts { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.c-att { position: relative; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--bg-soft); display: grid; place-items: center; font-size: 11px; color: var(--text-3); }
.c-att img, .c-att video { width: 100%; height: 100%; object-fit: cover; }
.c-att .x { position: absolute; top: 3px; right: 3px; width: 18px; height: 18px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; display: grid; place-items: center; padding: 0; }
.c-att .x svg { width: 11px; height: 11px; stroke-width: 2.4; }
.c-att .prog { position: absolute; inset: auto 0 0 0; height: 3px; background: rgba(0,0,0,.3); }
.c-att .prog i { display: block; height: 100%; background: var(--accent-2); }
.c-att .lbl { position: absolute; left: 3px; bottom: 3px; font-size: 10px; background: rgba(0,0,0,.6); color: #fff; padding: 0 4px; border-radius: 4px; }
.c-bar { display: flex; align-items: center; gap: 4px; margin-top: 4px; }
.c-bar .spacer { flex: 1; }
.chip-btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; border-radius: 9px; border: 0; background: transparent; color: var(--text-2); font-size: 12.8px; white-space: nowrap; }
.chip-btn:hover { background: var(--bg-hover); color: var(--text); }
.chip-btn svg { width: 16px; height: 16px; }
.send { width: 34px; height: 34px; border-radius: 10px; border: 0; background: var(--text); color: var(--bg); display: grid; place-items: center; }
.send:disabled { opacity: .3; cursor: default; }
.send.stop { background: var(--bg-soft); color: var(--text); border: 1px solid var(--border-strong); }
.send svg { width: 17px; height: 17px; stroke-width: 2.2; }
.c-hint { text-align: center; font-size: 11.5px; color: var(--text-3); margin-top: 8px; }

/* popover */
.pop { position: absolute; z-index: 30; background: var(--bg-elev); border: 1px solid var(--border-strong); border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.18); padding: 14px; width: 340px; }
.pop.wide { width: 440px; max-width: calc(100vw - 16px); max-height: min(70vh, 560px); overflow-y: auto; }
.pop .voice-list { margin-top: 2px; }
.pop .voice-list .vnote { margin: 0 0 6px; font-size: 12px; color: var(--text-3); }
.pop h5 { margin: 0 0 6px; font-size: 12px; color: var(--text-3); font-weight: 600; }
.pop .row { margin-bottom: 12px; }
.pop .row:last-child { margin-bottom: 0; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg button { border: 1px solid var(--border); background: var(--bg); border-radius: 8px; padding: 4px 9px; font-size: 12.5px; color: var(--text-2); }
.seg button.on { border-color: var(--accent-2); color: var(--accent-2); background: var(--accent-soft); font-weight: 600; }
.range-row { display: flex; align-items: center; gap: 10px; }
.range-row input { flex: 1; accent-color: var(--accent-2); }
.range-row b { font-size: 13px; min-width: 34px; text-align: right; }
select.sel, input.inp, textarea.inp { width: 100%; padding: 7px 10px; border: 1px solid var(--border); background: var(--bg); border-radius: 9px; outline: none; }
select.sel:focus, input.inp:focus, textarea.inp:focus { border-color: var(--accent-2); }
textarea.inp { resize: vertical; min-height: 46px; line-height: 1.45; }

/* preview panel */
.preview { width: 0; overflow: hidden; border-left: 1px solid transparent; background: var(--bg-elev); transition: width .2s; display: flex; flex-direction: column; }
.preview.open { width: 440px; border-left-color: var(--border); }
.preview-inner { width: 440px; display: flex; flex-direction: column; height: 100vh; }
.pv-head { height: 52px; display: flex; align-items: center; gap: 8px; padding: 0 10px 0 16px; border-bottom: 1px solid var(--border); flex: none; }
.pv-head b { flex: 1; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pv-body { flex: 1; overflow-y: auto; padding: 14px 16px; }
.pv-media { border-radius: 12px; overflow: hidden; background: #000; }
.pv-media img, .pv-media video { display: block; width: 100%; max-height: 62vh; object-fit: contain; background: #000; }
.pv-media audio { width: 100%; }
.pv-meta { margin-top: 12px; }
.pv-meta .kv { grid-template-columns: 64px 1fr; font-size: 12.8px; }
.pv-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.pv-strip-title { margin: 18px 0 8px; font-size: 12px; color: var(--text-3); font-weight: 600; }
.pv-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.pv-strip .att-thumb { width: auto; height: 64px; }
.pv-strip .att-thumb.sel { outline: 2px solid var(--accent-2); outline-offset: 1px; }
.pv-empty { color: var(--text-3); font-size: 13px; padding: 30px 0; text-align: center; }

/* studio */
.studio-head { display: flex; align-items: center; gap: 12px; padding: 18px 28px 6px; flex-wrap: wrap; }
.studio-head h2 { margin: 0; font-size: 20px; font-weight: 600; flex: 1; font-family: Georgia, 'Songti SC', serif; }
.studio-body { flex: 1; overflow-y: auto; padding: 12px 28px 40px; }
.studio-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.card { border: 1px solid var(--border); background: var(--bg-elev); border-radius: 14px; overflow: hidden; cursor: pointer; transition: box-shadow .15s, transform .15s; }
.card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.card .thumb { aspect-ratio: 16 / 10; background: #111; position: relative; overflow: hidden; }
.card .thumb img, .card .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .thumb .kind { position: absolute; left: 8px; top: 8px; font-size: 11px; padding: 1px 7px; border-radius: 6px; background: rgba(0,0,0,.6); color: #fff; }
.card .thumb .kind.render { background: var(--accent); }
.card .thumb .kind.breakdown { background: #2563eb; }
.card .thumb .kind.whitemodel { background: #7c3aed; }
.card .thumb .dur { position: absolute; right: 8px; bottom: 8px; font-size: 11px; padding: 0 6px; border-radius: 5px; background: rgba(0,0,0,.6); color: #fff; }
.card .thumb .play { position: absolute; inset: 0; display: grid; place-items: center; opacity: 0; transition: opacity .15s; color: #fff; }
.card:hover .thumb .play { opacity: 1; }
.card .thumb .play svg { width: 40px; height: 40px; filter: drop-shadow(0 2px 6px rgba(0,0,0,.5)); fill: rgba(255,255,255,.92); stroke: none; }
.card .info { padding: 9px 12px 11px; }
.card .info .t { font-size: 13.2px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .info .s { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.empty-state { text-align: center; color: var(--text-3); padding: 80px 20px; }
.empty-state svg { width: 40px; height: 40px; margin-bottom: 10px; opacity: .6; }

/* settings */
dialog.modal { border: 1px solid var(--border-strong); border-radius: 18px; padding: 0; width: min(620px, calc(100vw - 32px)); max-height: calc(100vh - 40px); background: var(--bg-elev); color: var(--text); box-shadow: 0 24px 80px rgba(0,0,0,.3); }
dialog.modal::backdrop { background: rgba(10, 9, 8, .5); }
.modal-head { display: flex; align-items: center; padding: 16px 18px 6px 22px; }
.modal-head h3 { margin: 0; flex: 1; font-size: 17px; }
.modal-body { padding: 8px 22px 6px; overflow-y: auto; max-height: calc(100vh - 170px); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 22px 18px; }
.fs { border: 0; padding: 0; margin: 0 0 18px; }
.fs legend { font-size: 12px; color: var(--text-3); font-weight: 650; letter-spacing: .4px; margin-bottom: 8px; padding: 0; }
.field { display: grid; grid-template-columns: 120px 1fr; align-items: center; gap: 10px; margin-bottom: 10px; }
.field label { font-size: 13px; color: var(--text-2); }
.field .help { grid-column: 2; font-size: 12px; color: var(--text-3); margin-top: -4px; }
.field .inline { display: flex; gap: 8px; }
.field .inline .inp { flex: 1; }
.test-result { font-size: 12.5px; grid-column: 2; }
.test-result.ok { color: var(--ok); }
.test-result.bad { color: var(--err); }
.tts-tabs { margin: 2px 0 12px; }
.tts-tabs button { display: inline-flex; align-items: center; gap: 6px; }
.tts-tabs button i { width: 7px; height: 7px; border-radius: 50%; background: var(--border-strong); }
.tts-tabs button i.on { background: var(--ok); }
.tts-panel { display: none; }
.tts-panel.active { display: block; }
.field .help code { font-family: var(--mono); font-size: 11.5px; background: var(--bg-soft); padding: 0 4px; border-radius: 4px; }
.field:has(> .voice-list) { align-items: start; }
.voice-list { max-height: 230px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; background: var(--bg-soft); }
.voice-list .vg { margin-bottom: 6px; }
.voice-list .vg:last-child { margin-bottom: 0; }
.voice-list .vg h5 { margin: 2px 0 4px; font-size: 11.5px; font-weight: 600; color: var(--text-3); }
.voice-list .vg h5 small { font-weight: 450; margin-left: 4px; }
.voice-list .chips { display: flex; flex-wrap: wrap; gap: 5px; }
.vchip { border: 1px solid var(--border); background: var(--bg-elev); color: var(--text); border-radius: 999px; padding: 2px 9px; font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap; }
.vchip small { color: var(--text-3); margin-left: 3px; }
.vchip:hover { border-color: var(--accent-2); }
.vchip.on { border-color: var(--accent-2); background: var(--accent-soft); color: var(--accent-2); }
.vchip.busy { opacity: .6; cursor: progress; }
.voice-list .vnote { font-size: 12px; color: var(--text-3); margin: 0 0 6px; }
.test-result .linkish { border: 0; background: none; color: var(--accent-2); cursor: pointer; font: inherit; padding: 0 0 0 6px; text-decoration: underline; }
#s-tts-audio { width: 100%; height: 36px; }

/* GPT-SoVITS: server status, cloned voices, clone form */
.linkish { border: 0; background: none; color: var(--accent-2); cursor: pointer; font: inherit; font-size: 12px; padding: 0; text-decoration: underline; }
.linkish:disabled { opacity: .5; cursor: default; }
.sovits-status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12.5px; min-height: 30px; }
.sovits-status i { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); flex: none; }
.sovits-status i.starting { background: var(--warn); animation: pulse 1.2s infinite; }
.sovits-status i.running { background: var(--ok); }
.sovits-status i.error { background: var(--err); }
.sovits-status .msg { flex: 1; min-width: 140px; color: var(--text-2); word-break: break-word; }
.sovits-status .btn { padding: 4px 10px; font-size: 12.5px; }
.sovits-log { grid-column: 2; margin: 0; font-family: var(--mono); font-size: 11.5px; line-height: 1.45; max-height: 180px; overflow: auto; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; white-space: pre-wrap; word-break: break-all; color: var(--text-2); }
.field:has(> .sovits-voices) { align-items: start; }
.sovits-voices { max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; background: var(--bg-soft); }
.sovits-voices .svh { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-3); margin-bottom: 6px; }
.sovits-voices .svh .btn { margin-left: auto; padding: 3px 9px; font-size: 12px; }
.sovits-voices .vnote { font-size: 12px; color: var(--text-3); margin: 0; }
.sovits-voices .vnote.bad { color: var(--err); }
.svc { border: 1px solid var(--border); border-radius: 9px; background: var(--bg-elev); padding: 7px 10px 6px; margin-bottom: 6px; }
.svc:last-child { margin-bottom: 0; }
.svc .svc-main { cursor: pointer; }
.svc .svc-main b { font-size: 13px; font-weight: 600; }
.svc .meta { font-size: 12px; color: var(--text-3); margin-left: 6px; }
.svc .meta em { font-style: normal; color: var(--accent-2); }
.svc .desc { display: block; font-size: 12px; color: var(--text-3); margin-top: 1px; }
.svc .btns { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 3px; }
.svc .refs { border-top: 1px dashed var(--border); margin-top: 6px; padding-top: 6px; display: grid; gap: 8px; }
.svc .ref { display: grid; gap: 4px; }
.svc .ref-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--text-3); }
.svc .ref-row audio { height: 30px; flex: 1; min-width: 160px; }
.svc .ref-tools { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-3); }
.svc .ref-msg.bad { color: var(--err); }
.svc .edit { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; margin-top: 6px; border-top: 1px dashed var(--border); padding-top: 8px; }
.svc .edit label { display: grid; gap: 2px; font-size: 11.5px; color: var(--text-3); }
.svc .edit .full { grid-column: 1 / -1; }
.svc .edit .btn { padding: 4px 10px; font-size: 12.5px; }
.sovits-new { border: 1px solid var(--border-strong); border-radius: 12px; padding: 12px 12px 2px; margin: -2px 0 12px; background: var(--bg-elev); }
.sovits-new h5 { margin: 0 0 10px; font-size: 13px; }
.sovits-new .src-seg { margin-bottom: 8px; }
.sovits-new .src-pane { display: none; }
.sovits-new .src-pane.on { display: block; }
.sovits-new .src-pane .help { margin-top: 4px; }
.sovits-new .rec-row { display: flex; align-items: center; gap: 10px; }
.sovits-new .rec-btn.rec { color: var(--err); border-color: var(--err); animation: pulse 1.2s infinite; }
.sovits-new .rec-time { font-family: var(--mono); font-size: 12.5px; color: var(--text-3); }
.sovits-new input[type=file] { font-size: 12.5px; max-width: 100%; }
.sovits-new .start-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12.5px; color: var(--text-2); }
.sovits-new .start-row .inp { width: 110px; }
.sovits-new .src-result { margin-top: 6px; font-size: 12.5px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.sovits-new .src-result:empty { display: none; }
.sovits-new .src-result audio { height: 32px; width: 100%; }
.sovits-new .acts { align-items: center; }
.sovits-note { font-size: 12px; color: var(--text-3); line-height: 1.55; margin: 2px 0 6px; }
.switch { position: relative; width: 38px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border-strong); border-radius: 999px; transition: .2s; cursor: pointer; }
.switch span::after { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(16px); }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 10px; font-size: 13px; z-index: 100; box-shadow: var(--shadow); animation: rise .2s; }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.86); z-index: 90; display: grid; place-items: center; cursor: zoom-out; }
.lightbox img { max-width: 94vw; max-height: 92vh; border-radius: 8px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }
@keyframes indet { 0% { left: -30%; } 100% { left: 100%; } }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 6px); } }

/* responsive */
@media (max-width: 1100px) {
  .preview.open { position: fixed; right: 0; top: 0; bottom: 0; z-index: 40; box-shadow: -10px 0 40px rgba(0,0,0,.2); }
  .preview.open, .preview-inner { width: min(440px, 100vw); }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 280px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 10px 0 40px rgba(0,0,0,.25); }
  .menu-btn { display: grid; }
  #view-studio .topbar { display: flex; }
  .examples { grid-template-columns: 1fr 1fr; }
  .examples .example:last-child:nth-child(3n+1) { grid-column: auto; }
  .thread { padding: 14px 16px 30px; }
  .composer-wrap { padding: 0 12px 12px; }
  .msg-user { max-width: 90%; }
  .tool-assets, .tool-msg, .tool-err { padding-left: 12px; }
  .studio-head, .studio-body { padding-left: 16px; padding-right: 16px; }
  .field { grid-template-columns: 1fr; gap: 4px; }
  .field .help, .test-result, .sovits-log { grid-column: 1; }
  .svc .edit { grid-template-columns: 1fr; }
  .welcome { padding-top: 5vh; }
}
@media (max-width: 520px) {
  .examples { grid-template-columns: 1fr; }
  .welcome h1 { font-size: 24px; }
}


/* ---------- web version: key gate, data notice, cost card, my voice, local badges ---------- */
.keygate { width: min(520px, calc(100vw - 32px)); }
.keygate .modal-body { padding-bottom: 18px; }
.kg-intro { margin: 4px 0 14px; color: var(--text-2); font-size: 13.5px; line-height: 1.6; }
.kg-field { grid-template-columns: 1fr; gap: 6px; }
.kg-field label { font-weight: 600; }
.kg-links { display: flex; gap: 8px; font-size: 13px; margin-top: 8px; flex-wrap: wrap; }
.kg-note { font-size: 12px; color: var(--text-3); margin: 12px 0 0; line-height: 1.5; }
.kg-handoff { display: flex; align-items: center; gap: 10px; background: var(--bg-soft); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 13px; }
.spin { width: 14px; height: 14px; border: 2px solid var(--border-strong); border-top-color: var(--accent-2); border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
.inp.readonly { display: block; background: var(--bg-soft); color: var(--text-2); font-family: var(--mono); font-size: 12.5px; line-height: 1.6; }

.data-notice { display: flex; gap: 12px; align-items: flex-start; margin: 22px auto 0; max-width: 720px; text-align: left; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; font-size: 13px; color: var(--text-2); }
.data-notice svg { width: 20px; height: 20px; color: var(--accent-2); margin-top: 2px; }
.data-notice b { display: block; color: var(--text); margin-bottom: 2px; }
.data-notice .linkish { display: block; margin-top: 6px; }
.data-box p { margin: 0 0 8px; font-size: 13px; color: var(--text-2); line-height: 1.6; }
.data-usage { font-size: 12.5px; color: var(--text-3); margin-bottom: 8px; }
.data-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.data-actions .btn { display: inline-flex; align-items: center; gap: 6px; }
.data-actions .btn svg { width: 15px; height: 15px; }
.session .local { color: var(--text-3); display: grid; }
.session .local svg { width: 13px; height: 13px; }
.card .thumb .local-badge { position: absolute; right: 8px; top: 8px; background: rgba(0,0,0,.6); color: #fff; border-radius: 6px; padding: 2px 4px; display: grid; }
.card .thumb .local-badge svg { width: 13px; height: 13px; }

.cost-card { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--bg-elev); }
.cost-total { display: flex; align-items: baseline; gap: 8px; padding: 10px 14px; background: var(--accent-soft); }
.cost-total span { font-size: 12.5px; color: var(--text-2); }
.cost-total b { font-size: 20px; color: var(--accent); }
.cost-total small { color: var(--text-3); }
.cost-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.cost-table th, .cost-table td { text-align: left; padding: 6px 14px; border-top: 1px solid var(--border); }
.cost-table th { color: var(--text-3); font-weight: 600; font-size: 11.5px; border-top: 0; }
.cost-table td:nth-child(2), .cost-table td:nth-child(3), .cost-table th:nth-child(2), .cost-table th:nth-child(3) { text-align: right; white-space: nowrap; }
.cost-foot { padding: 8px 14px 10px; font-size: 12px; color: var(--text-3); border-top: 1px solid var(--border); }
.price-line { font-size: 12px; color: var(--text-3); margin-top: 6px; }

.myvoice-intro { font-size: 12.5px; color: var(--text-2); line-height: 1.6; margin-bottom: 8px; }
.myvoice-list .svh { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-3); margin-bottom: 6px; }
.myvoice-list .svh .btn { margin-left: auto; padding: 4px 10px; font-size: 12.5px; }
.myvoice-list .vnote { font-size: 12px; color: var(--text-3); margin: 0 0 6px; }
.myvoice-list .vnote.bad { color: var(--err); }
.clone-form { border: 1px solid var(--border-strong); border-radius: 12px; padding: 12px 14px; margin: 6px 0 10px; background: var(--bg-elev); }
.clone-form h5 { margin: 0 0 8px; font-size: 13.5px; }
.clone-form .consent { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; color: var(--text-2); line-height: 1.5; margin-bottom: 10px; }
.clone-form .consent input { margin-top: 3px; }
.clone-form .step { border-top: 1px dashed var(--border); padding-top: 10px; margin-top: 10px; }
.clone-form .step b { display: block; font-size: 13px; margin-bottom: 4px; }
.clone-form .help { font-size: 12px; color: var(--text-3); margin: 0 0 6px; line-height: 1.5; }
.clone-form .rec-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.clone-form .rec-btn.rec { color: var(--err); border-color: var(--err); animation: pulse 1.2s infinite; }
.clone-form .rec-time { font-family: var(--mono); font-size: 12.5px; color: var(--text-3); min-width: 40px; }
.clone-form .challenge-text { font-size: 14px; font-weight: 600; color: var(--accent); }
.clone-form .src-result { margin-top: 6px; font-size: 12.5px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--text-3); }
.clone-form .src-result:empty { display: none; }
.clone-form .src-result audio { height: 32px; flex: 1; min-width: 200px; }
.clone-form .acts { display: flex; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.clone-form .btn svg { width: 15px; height: 15px; vertical-align: -3px; margin-right: 4px; }
.svc .btns .linkish { font-size: 12px; }

body.embedded .brand { display: none; }
body.embedded .side-actions { padding-top: 14px; }

/* settings: voice picker rows live in the value column, not under the label */
.field > .voice-list, .field > .myvoice-list, .field > .myvoice-new { grid-column: 2; }
.field .inline .inp { min-width: 0; }
.field .inline .sel { width: auto; flex: 0 0 auto; max-width: 180px; }
.myvoice-note { font-size: 12.5px; color: var(--text-2); background: var(--bg-soft); border-radius: 10px; padding: 8px 10px; margin: 0 0 8px; line-height: 1.55; }
.myvoice-note.bad { color: var(--err); }
