/* 深色为默认主题：直接写进 :root，避免 JS 执行前首屏闪白 */
:root {
  --bg: #14121c;
  --surface: #1e1b29;
  --surface-2: #262233;
  --border: #322c44;
  --text: #ece9f5;
  --text-dim: #9a94b2;
  --text-soft: #7b73a0;
  --primary: #9a80ff;
  --primary-dim: #8467ff;
  --danger: #ff6b85;
  --ok: #2ecc84;
  --shadow: 0 8px 30px rgba(0, 0, 0, .38);
  --radius: 14px;
}

/* 浅色需显式声明 data-theme="light" */
:root[data-theme="light"] {
  --bg: #f7f6fb;
  --surface: #ffffff;
  --surface-2: #f2f1f8;
  --border: #e5e3ef;
  --text: #221f2e;
  --text-dim: #7b7690;
  --text-soft: #a8a3be;
  --primary: #7c5cff;
  --primary-dim: #6a49f2;
  --danger: #ef4d6b;
  --ok: #21b573;
  --shadow: 0 8px 30px rgba(60, 40, 130, .10);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------- 通用控件 ---------- */

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: transform .12s, background .18s, box-shadow .18s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}
.btn.primary:hover { background: var(--primary-dim); }
.btn.ghost { background: transparent; color: var(--text-dim); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.tiny { padding: 6px 12px; font-size: 12.5px; border-radius: 8px; }
.btn.block { width: 100%; margin-top: 10px; }

.icon-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  padding: 6px 8px;
  border-radius: 8px;
  color: var(--text-dim);
  line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); }

input[type="text"], input[type="password"], input[type="number"], textarea, .select, .mini-select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .18s, box-shadow .18s;
}
input:focus, textarea:focus, .select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124, 92, 255, .14);
}
textarea { resize: vertical; line-height: 1.6; }

.mini-select { width: auto; padding: 6px 10px; font-size: 13px; }

.field { position: relative; display: flex; align-items: center; }
.field input { padding-right: 42px; }
.field .icon-btn { position: absolute; right: 4px; }

.lbl {
  display: block;
  font-size: 12.5px;
  color: var(--text-dim);
  margin: 14px 0 6px;
  font-weight: 500;
}
.row { display: flex; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.hint { font-size: 12.5px; color: var(--danger); margin: 8px 0 0; min-height: 16px; }
.meta { font-size: 12px; color: var(--text-dim); }

.range { width: 100%; accent-color: var(--primary); }

.checks { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 16px; }
.checks label, .remember {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
}
.checks input, .remember input { accent-color: var(--primary); width: auto; }

/* ---------- 吉祥物 ---------- */

.mascot-svg { width: 96px; height: 96px; }
.mascot-svg.small { width: 44px; height: 44px; }
.m-face { fill: var(--primary); }
.m-eye { fill: #fff; }
.m-glint { fill: var(--primary); opacity: .55; }
.m-blush { fill: #ff9ec4; opacity: .5; }
.m-mouth { fill: none; stroke: #fff; stroke-width: 3.4; stroke-linecap: round; }
.m-antenna { stroke: var(--primary); stroke-width: 3.4; stroke-linecap: round; }
.m-bulb { fill: #ffd166; }
.m-shadow { fill: rgba(0, 0, 0, .08); }

.m-body { transform-origin: 60px 70px; animation: float 3.4s ease-in-out infinite; }
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

/* ---------- 登录弹窗 ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal.hidden { display: none !important; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 6, 16, .62);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal-dialog {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 36px 30px 28px;
  box-shadow: var(--shadow);
  text-align: center;
  animation: modalIn .28s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-close {
  position: absolute;
  top: 14px; right: 16px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  border-radius: 8px;
  transition: background .15s, color .15s;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }

.modal-mascot { margin-bottom: 4px; }
.modal-title { font-size: 22px; margin: 0 0 8px; }
.modal-desc {
  font-size: 13.5px;
  color: var(--text-dim);
  line-height: 1.65;
  margin: 0 0 16px;
}

.modal-dialog .field { text-align: left; }
.modal-dialog .remember { justify-content: center; margin-top: 12px; }

.login-msg { font-size: 13px; min-height: 18px; margin: 12px 0 0; color: var(--text-dim); }
.login-msg.err { color: var(--danger); }
.login-msg.ok { color: var(--ok); }

.modal-foot {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.8;
}
.modal-foot a { color: var(--primary); text-decoration: none; }
.modal-foot a:hover { text-decoration: underline; }
.modal-foot .dot { margin: 0 6px; }

/* ---------- 主框架 ---------- */

.app { max-width: 1160px; margin: 0 auto; padding: 0 20px 40px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 0 14px;
  gap: 12px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 4px rgba(124, 92, 255, .18);
}
.brand-name { font-weight: 700; font-size: 16.5px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.usage-summary {
  flex: 1 1 520px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}
.usage-item,
.usage-total,
.usage-details {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-dim);
  font-size: 11.5px;
  line-height: 1.35;
  white-space: nowrap;
}
.usage-total {
  border-color: rgba(255, 193, 7, .45);
  color: #e6a817;
  font-weight: 700;
}
.usage-details { white-space: normal; }
.usage-sync {
  border-color: rgba(33, 181, 115, .3);
  color: var(--ok);
  font-size: 10.5px;
  padding: 3px 6px;
}
:root[data-theme="light"] .usage-total { color: #9a6b00; }

.badge {
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
}
.badge.green { background: rgba(33, 181, 115, .14); color: var(--ok); }
.badge.gray { background: var(--surface-2); color: var(--text-dim); }

.needkey {
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(255, 107, 133, .1);
  border: 1px solid rgba(255, 107, 133, .3);
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 12px;
  line-height: 1.5;
}
.cost-warn {
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(255, 193, 7, .08);
  border: 1px solid rgba(255, 193, 7, .25);
  color: #e6a817;
  font-size: 13px;
  margin-bottom: 12px;
  line-height: 1.5;
}
:root[data-theme="light"] .cost-warn { color: #b8860b; }

.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: 12px;
  margin-bottom: 20px;
  overflow-x: auto;
  /* 隐藏滚动条但保留可滚动性：视觉更干净 */
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1;
  min-width: 92px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 9px 14px;
  border-radius: 9px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background .18s, color .18s;
}
.tab.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .06), inset 0 -2px 0 var(--accent);
}

.panel { display: none; animation: fade .25s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

/* ---------- 图片面板 ---------- */

#panel-image.active { display: grid; grid-template-columns: 340px 1fr; gap: 24px; }

.col-form, .col-view {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.col-form .lbl:first-child { margin-top: 0; }

.stage {
  min-height: 380px;
  border-radius: 12px;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.stage-empty { color: var(--text-dim); font-size: 13.5px; padding: 20px; text-align: center; }
.result-img { width: 100%; height: auto; display: block; }
.result-audio, .result-video { width: 100%; max-width: 100%; display: block; }

.stage-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 对话面板 ---------- */

.chat-setting, .chat-box, .chat-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.chat-setting { margin-bottom: 14px; }
.chat-setting .lbl { margin-top: 0; }

.sys { margin-top: 14px; }
.sys summary {
  font-size: 12.5px;
  color: var(--text-dim);
  cursor: pointer;
  margin-bottom: 8px;
}

.chat-box {
  height: 46vh;
  min-height: 300px;
  overflow-y: auto;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-empty { margin: auto; color: var(--text-dim); font-size: 13.5px; }

.msg { display: flex; flex-direction: column; max-width: 78%; position: relative; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; }

.msg-body {
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
}
.msg.user .msg-body {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.assistant .msg-body {
  background: var(--surface-2);
  border-bottom-left-radius: 4px;
}
.msg-pending {
  color: var(--text-dim);
  animation: breathe 1.4s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { opacity: .45; }
  50% { opacity: 1; }
}

.copy-btn {
  align-self: flex-start;
  margin-top: 4px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 11.5px;
  cursor: pointer;
  padding: 2px 4px;
}
.copy-btn:hover { color: var(--primary); }

.chat-input { display: flex; gap: 8px; align-items: flex-end; }
.chat-input textarea { flex: 1; max-height: 140px; overflow-y: auto; }

/* ---------- 历史面板 ---------- */

.hist-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.hist-list { display: flex; flex-direction: column; gap: 10px; }

.hist-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}
.hist-thumb {
  width: 54px; height: 54px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--surface-2);
  flex-shrink: 0;
}
.hist-thumb.txt {
  display: grid;
  place-items: center;
  color: var(--primary);
  font-weight: 700;
}
.hist-info { flex: 1; min-width: 0; }
.hist-prompt {
  font-size: 13.5px;
  margin-bottom: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hist-sub, .hist-time {
  font-size: 11.5px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 助手浮窗 ---------- */

.assistant {
  position: fixed;
  right: 24px;
  bottom: 24px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  z-index: 40;
  touch-action: none;
}

.assistant.dragging { user-select: none; }

/* 默认（助手在屏幕右侧）：气泡在 mascot 左侧，向左生长 */
.assistant .bubble {
  max-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 13px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(6px) scale(.94);
  transform-origin: bottom right;
  transition: opacity .2s, transform .22s cubic-bezier(.34, 1.56, .64, 1);
}
.bubble.pop { opacity: 1; transform: translateY(0) scale(1); }

/* 拖到屏幕左侧时：翻转主气泡方向，气泡出现在 mascot 右侧，向右生长，
   避免气泡溢出左边界被裁切。靠 JS 在 onUp / resize / init 时切换 class */
.assistant.flip { flex-direction: row-reverse; }
.assistant.flip .bubble { transform-origin: bottom left; }

.mascot-btn {
  width: 58px; height: 58px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: grab;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: transform .2s;
}
.mascot-btn:active { cursor: grabbing; }
.mascot-btn:hover { transform: scale(1.08); }
.mascot-btn.bounce { animation: bounce .5s ease; }
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  35% { transform: translateY(-9px); }
  65% { transform: translateY(-3px); }
}
.mascot-btn.thinking .m-bulb { animation: blink .7s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .25; } }

/* ---------- 轻提示 ---------- */

.toast {
  position: fixed;
  left: 50%;
  top: 64px;
  transform: translate(-50%, -20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s, transform .22s;
  z-index: 60;
  max-width: 84vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 响应式 ---------- */

@media (max-width: 860px) {
  #panel-image.active { grid-template-columns: 1fr; }
  .app { padding: 0 14px 90px; }
  .bubble { max-width: 170px; }
  .chat-box { height: 52vh; }
  .usage-summary { order: 3; flex-basis: 100%; justify-content: flex-start; }
  .usage-details { flex: 1 1 100%; }
}

/* 窄屏：让选项卡换行而非横向滚动，
   保证点选的选项文字始终完整可见、不被裁切 */
@media (max-width: 720px) {
  .tabs {
    flex-wrap: wrap;
    overflow: visible;
  }
  .tab {
    flex: 1 1 auto;     /* 基准为内容宽度，行内剩余空间均分 */
    min-width: 0;       /* 允许 flex 收缩，但 white-space:nowrap 保证文字不换行/不截断 */
    padding: 8px 10px;
    font-size: 12.5px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- 模式切换 ---------- */

.mode-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 10px;
}
.mode-toggle button {
  flex: 1;
  padding: 7px 12px;
  border: none;
  background: transparent;
  color: var(--text-soft);
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, color .15s;
  border-right: 1px solid var(--border);
}
.mode-toggle button:last-child { border-right: none; }
.mode-toggle button:first-child { border-radius: 7px 0 0 7px; }
.mode-toggle button:last-child { border-radius: 0 7px 7px 0; }
.mode-toggle button.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.12);
}

/* ---------- 上传区 ---------- */

.upload-area {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.upload-area:hover { border-color: var(--accent); background: var(--surface); }
.upload-area.has-image { padding: 8px; }
.upload-area img { max-width: 100%; max-height: 180px; border-radius: 6px; }

/* ---------- 工具面板 ---------- */

.tool-section { display: flex; flex-direction: column; gap: 16px; }
.tool-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}
.tool-card h3 { margin: 0 0 12px; font-size: 15px; }
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 28px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop-zone:hover, .drop-zone.dragover { border-color: var(--accent); background: var(--surface); }
.drop-zone img { max-width: 100%; max-height: 300px; border-radius: 8px; }

/* 视频转换预览 */
.vconv-preview {
  width: 100%;
  max-height: 320px;
  border-radius: 8px;
  background: #000;
  display: block;
}
.quality-row { display: flex; align-items: center; gap: 10px; }

/* ---------- 站点页脚 ---------- */
.site-footer {
  text-align: center;
  padding: 18px 16px 14px;
  color: var(--text-soft);
  font-size: 12px;
  letter-spacing: .3px;
  border-top: 1px solid var(--border);
  margin-top: 28px;
}
.site-footer a { color: var(--primary); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
