:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #1d2330;
  --muted: #6d7688;
  --line: #e3e8f1;
  --accent: #2f6df6;
  --accent-soft: #eaf0ff;
  --danger: #e5484d;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(23, 39, 74, .07);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.6 "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  max-width: 1400px; margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff; font-weight: 700; font-size: 20px;
  box-shadow: 0 6px 16px rgba(47, 109, 246, .28);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-text strong { font-size: 17px; letter-spacing: .5px; }
.brand-text span { font-size: 12px; color: var(--muted); }
.steps { display: flex; gap: 8px; flex-wrap: wrap; }
.step-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 20px;
  background: var(--accent-soft); color: #2b4d9c;
  font-size: 12px;
}
.step-chip i {
  font-style: normal; width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 11px;
  display: grid; place-items: center;
}

.top-nav { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.nav-link {
  padding: 6px 10px; border-radius: 8px; font-size: 12.5px;
  color: var(--muted); text-decoration: none; white-space: nowrap; transition: .15s;
}
.nav-link:hover { background: #f1f5fd; color: var(--ink); }
.nav-link.active { background: var(--accent-soft); color: #2b4d9c; font-weight: 600; }
.stage-steps { justify-content: flex-start; margin: 14px 0 10px; }

/* ---------- 首页新功能横幅 ---------- */
.promo-bar {
  max-width: 1400px; margin: 14px auto 0; padding: 0 20px;
}
.promo-inner {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 13px 18px; border: 1px solid #dbe6ff; border-radius: 14px;
  background:
    radial-gradient(420px 120px at 88% -30%, rgba(124, 58, 237, .16), transparent 70%),
    linear-gradient(135deg, #f5f8ff, #eef3ff 60%, #f7f3ff);
}
.promo-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.promo-text strong { font-size: 13.5px; color: #2b4d9c; }
.promo-text span { font-size: 12px; color: var(--muted); }
.promo-btn {
  flex: none; padding: 8px 16px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #5b4bff); color: #fff;
  font-size: 12.5px; font-weight: 600; text-decoration: none; white-space: nowrap;
  box-shadow: 0 6px 16px rgba(47, 109, 246, .26);
}
.promo-btn:hover { transform: translateY(-1px); }
@media (max-width: 820px) {
  .promo-bar { padding: 0 12px; }
  .promo-inner { flex-direction: column; align-items: flex-start; }
  .promo-btn { align-self: stretch; text-align: center; }
}

/* ---------- layout ---------- */
.workspace {
  max-width: 1400px; margin: 0 auto; padding: 18px 20px 40px;
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr) 356px;
  gap: 16px;
  align-items: start;
}
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px;
}
.panel-title {
  font-size: 14px; margin: 0 0 12px; padding-left: 10px;
  border-left: 3px solid var(--accent); line-height: 1.2;
}
.panel-title-toggle { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel-title + .panel-title { margin-top: 22px; }
.panel-sub {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; color: var(--muted); margin: 16px 2px 8px;
}
.count { color: var(--ink); font-weight: 600; }
.tpl-toggle { display: none; align-items: center; gap: 5px; font-size: 12px; color: var(--ink); cursor: pointer; user-select: none; }
.tpl-toggle input { width: 14px; height: 14px; margin: 0; accent-color: var(--accent); }

/* ---------- upload ---------- */
.upload-zone {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 16px 12px; border: 1.5px dashed #c7d4ec; border-radius: 12px;
  background: #f8faff; text-align: center; cursor: pointer;
  transition: .18s;
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent); background: var(--accent-soft);
}
.upload-icon { font-size: 22px; color: var(--accent); line-height: 1; }
.upload-zone strong { font-size: 13px; }
.upload-tip { font-size: 12px; color: var(--muted); }

/* ---------- template grid ---------- */
.template-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  max-height: 520px; overflow-y: auto; padding-right: 2px;
}
.tpl {
  position: relative; border: 1.5px solid transparent; border-radius: 10px;
  background: #f4f6fb; overflow: hidden; padding: 0; text-align: left;
  transition: .16s;
}
.tpl img {
  display: block; width: 100%; aspect-ratio: 4 / 3;
  object-fit: cover; background: #dfe5f0;
}
.tpl .tpl-name {
  display: block; padding: 5px 7px 6px; font-size: 11px; color: #4b5466;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tpl:hover { border-color: #b7caf3; transform: translateY(-1px); }
.tpl.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tpl.active .tpl-name { color: var(--accent); font-weight: 600; }
.tpl .tpl-badge {
  position: absolute; top: 5px; right: 5px;
  background: rgba(17, 24, 39, .62); color: #fff;
  font-size: 10px; padding: 1px 6px; border-radius: 8px;
}

/* ---------- stage ---------- */
.stage { min-width: 0; }
.canvas-wrap {
  position: relative; background:
    linear-gradient(45deg, #e9edf5 25%, transparent 25%, transparent 75%, #e9edf5 75%) 0 0/18px 18px,
    linear-gradient(45deg, #e9edf5 25%, #f6f8fc 25%, #f6f8fc 75%, #e9edf5 75%) 9px 9px/18px 18px;
  border: 1px solid var(--line); border-radius: var(--radius);
  min-height: 380px; display: grid; place-items: center; padding: 18px;
  overflow: hidden;
}
#preview { max-width: 100%; max-height: 68vh; display: none; }
#preview.show { display: block; width: 100%; max-width: 640px; height: auto; }

/* ---------- 文字位置拖拽 ---------- */
.drag-overlay {
  position: absolute; inset: 0; pointer-events: none;
  border-radius: inherit;
  background: transparent;
}
.drag-overlay.active {
  pointer-events: auto; cursor: move;
  background: repeating-linear-gradient(45deg, rgba(47,109,246,.08) 0 6px, transparent 6px 12px);
  outline: 2px dashed rgba(47,109,246,.55);
  outline-offset: -4px;
}
.drag-overlay.active::before {
  content: attr(data-hint);
  position: absolute; left: 8px; top: 6px;
  background: rgba(0,0,0,.6); color: #fff;
  font-size: 12px; padding: 3px 8px; border-radius: 10px;
  letter-spacing: .3px; opacity: .92;
  pointer-events: none;
}
.drag-overlay.dragging { cursor: grabbing; background: repeating-linear-gradient(45deg, rgba(47,109,246,.18) 0 6px, transparent 6px 12px); }

.drag-pos-hint {
  margin: 2px 0 6px; font-size: 12px; color: var(--muted);
  min-height: 14px; letter-spacing: .3px;
}
.style-grid .drag-pos-hint { width: 100%; }
.empty-hint {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  color: var(--muted); text-align: center; padding: 40px 20px;
}
.empty-hint strong { font-size: 16px; color: #45506a; }
.empty-hint span { font-size: 13px; }
.busy {
  position: absolute; inset: 0; display: none; place-items: center; gap: 10px;
  background: rgba(255, 255, 255, .78); font-size: 13px; color: #3a4664;
}
.busy.show { display: grid; }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid #c9d6f2; border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- transport / timeline ---------- */
.transport {
  display: flex; align-items: center; gap: 12px; margin-top: 14px;
  padding: 10px 14px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.icon-btn {
  width: 34px; height: 34px; flex: none; border-radius: 50%;
  border: 1px solid var(--line); background: #f7f9fe; color: var(--accent);
  font-size: 13px; display: grid; place-items: center;
}
.icon-btn:hover { background: var(--accent-soft); }
.time-label {
  flex: none; font-variant-numeric: tabular-nums; font-size: 12px; color: var(--muted);
  min-width: 96px;
}
.timeline {
  position: relative; flex: 1; height: 34px; cursor: crosshair; user-select: none;
  touch-action: none;
}
.track {
  position: absolute; left: 0; right: 0; top: 50%; height: 6px;
  transform: translateY(-50%); border-radius: 4px; background: #e8edf7;
}
.segments { position: absolute; inset: 0; }
.seg {
  position: absolute; top: 7px; height: 20px; border-radius: 6px;
  background: #cfdcff; border: 1px solid #a9c1f8;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: #2c4f9e; overflow: hidden;
  cursor: grab; padding: 0 4px; min-width: 10px;
}
.seg.sel { background: #adc6ff; border-color: var(--accent); box-shadow: 0 0 0 2px #dfe9ff; }
.seg-label { pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg .seg-handle {
  position: absolute; top: 0; bottom: 0; width: 8px; cursor: ew-resize;
  background: rgba(47, 109, 246, .25);
}
.seg .seg-handle.l { left: 0; border-radius: 6px 0 0 6px; }
.seg .seg-handle.r { right: 0; border-radius: 0 6px 6px 0; }
.playhead {
  position: absolute; top: 2px; bottom: 2px; width: 2px; left: 0;
  background: var(--danger); pointer-events: none; border-radius: 2px;
}
.meta {
  margin-top: 8px; font-size: 12px; color: var(--muted);
  display: flex; gap: 14px; flex-wrap: wrap;
}
.meta b { color: var(--ink); font-weight: 600; }
.timeline-tip { margin-top: 2px; font-size: 11px; color: #9aa3b5; }
.timeline-tip .tip-note { color: #e23e3e; font-weight: 600; letter-spacing: .2px; }

/* ---------- captions ---------- */
.caption-list { display: flex; flex-direction: column; gap: 8px; max-height: 340px; overflow-y: auto; padding-right: 2px; }
.caption-empty { font-size: 12px; color: var(--muted); padding: 10px 0; }
.cap {
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px;
  background: #fbfcff; transition: .15s;
}
.cap.active { border-color: #ffd0d1; background: #fff7f7; }
.cap.sel { border-color: var(--brand); background: #eef4ff; box-shadow: 0 0 0 2px rgba(47,109,246,.12); }
.cap.sel .cap-idx { background: var(--brand); }
.cap-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cap-idx { font-size: 11px; color: #fff; background: #b8c4da; border-radius: 10px; padding: 0 8px; line-height: 18px; }
.cap.active .cap-idx { background: var(--danger); }
.cap-del {
  border: none; background: none; color: #a6afc0; font-size: 12px; padding: 2px 4px;
}
.cap-del:hover { color: var(--danger); }
.cap-text {
  width: 100%; border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 9px; background: #fff; transition: .15s;
}
.cap-text:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.cap-times { display: grid; grid-template-columns: 1fr auto; gap: 6px 8px; align-items: center; margin-top: 6px; }
.cap-times label { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.cap-times input {
  width: 100%; max-width: 96px; min-width: 0; border: 1px solid var(--line); border-radius: 7px;
  padding: 4px 6px; font-variant-numeric: tabular-nums; background: #fff;
}
.cap-times input:focus { outline: none; border-color: var(--accent); }
.mini-btn {
  border: 1px solid #cfdcf4; background: #f2f6ff; color: #2f6df6;
  border-radius: 7px; font-size: 11px; padding: 4px 7px; white-space: nowrap;
}
.mini-btn:hover { background: #e3ecff; }

.ghost-btn {
  width: 100%; margin-top: 10px; padding: 9px;
  border: 1px dashed #c2d0ea; background: #f8faff; color: #3557a3;
  border-radius: 10px; font-size: 13px;
}
.ghost-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.ghost-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- style grid ---------- */
.style-grid { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.field > span b { color: var(--ink); }
.field input[type=range] { width: 100%; accent-color: var(--accent); }
.field-row { flex-direction: row; align-items: center; gap: 8px; flex-wrap: wrap; }
.field-row input[type=color] {
  width: 34px; height: 26px; padding: 0; border: 1px solid var(--line);
  border-radius: 7px; background: #fff;
}
.field select {
  border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; background: #fff;
}
.hint { font-size: 11px; color: #97a0b2; margin: 6px 0 0; font-style: normal; }

.primary-btn {
  width: 100%; margin-top: 16px; padding: 12px;
  border: none; border-radius: 11px; color: #fff; font-size: 15px; font-weight: 600;
  background: linear-gradient(135deg, var(--accent), #5b4bff);
  box-shadow: 0 8px 20px rgba(47, 109, 246, .28);
  transition: .16s;
}
.primary-btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 12px 24px rgba(47, 109, 246, .34); }
.primary-btn:disabled { opacity: .55; cursor: not-allowed; box-shadow: none; }
.progress { height: 5px; border-radius: 3px; background: #e9eefb; margin-top: 10px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #7c3aed); transition: width .15s; }

/* ---------- toast / footer ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px);
  background: #202737; color: #fff; padding: 9px 18px; border-radius: 10px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: .22s; z-index: 50;
  max-width: 80vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.site-footer {
  text-align: center; padding: 22px 20px 34px; color: #97a0b2; font-size: 12px;
}
.site-footer p { margin: 2px 0; }
.site-footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.site-footer a:hover { text-decoration: underline; }

/* ---------- 原字幕清理 ---------- */
.clean-grid { display: flex; flex-direction: column; gap: 10px; }
.clean-grid input[type=range] { width: 100%; accent-color: var(--accent); }
.mask-toggle { justify-content: space-between; font-size: 13px; color: var(--ink); font-weight: 600; }
.mask-toggle input { width: 16px; height: 16px; accent-color: var(--accent); }
.mask-panel {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px; border: 1px dashed #dbe3f2; border-radius: 10px; background: #fbfcff;
  transition: opacity .16s;
}
.mask-panel.off { opacity: .45; pointer-events: none; }
.mask-panel select {
  border: 1px solid var(--line); border-radius: 7px; padding: 3px 6px; background: #fff;
}

/* ---------- share ---------- */
.share-btn { width: 100%; margin-top: 10px; padding: 10px; }
.gif-result { margin: 12px 0 0; text-align: center; }
.gif-result img {
  display: block; max-width: 100%; margin: 0 auto;
  border: 1px solid var(--line); border-radius: 10px;
}
.gif-result .hint { margin: 8px 0 0; }

.modal {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: 20px; background: rgba(19, 26, 43, .45);
  backdrop-filter: blur(2px);
}
.modal[hidden] { display: none; }
.modal-card {
  width: 100%; max-width: 460px; max-height: 86vh; overflow: auto;
  background: #fff; border-radius: 16px; padding: 18px 20px;
  box-shadow: 0 24px 60px rgba(15, 26, 51, .22);
  animation: modalIn .18s ease-out;
}
@keyframes modalIn { from { transform: translateY(10px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-head .icon-btn { flex: none; }
.modal-tip { font-size: 12px; color: var(--muted); margin: 8px 0 12px; }
.modal-tip.muted { margin: 10px 0 0; }
.share-row { display: flex; gap: 8px; }
.share-row input {
  flex: 1; min-width: 0; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 9px; background: #f8faff; font-size: 13px;
}
.mini-btn.strong { border-style: solid; background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .workspace { grid-template-columns: 260px minmax(0, 1fr); }
  .panel-editor { grid-column: 1 / -1; }
  .caption-list { max-height: none; }
}
@media (max-width: 820px) {
  .workspace { grid-template-columns: 1fr; padding: 12px; }
  .header-inner { flex-direction: column; align-items: flex-start; }
  .template-grid { grid-template-columns: repeat(3, 1fr); max-height: 320px; }
  .tpl-toggle { display: inline-flex; }
  .template-grid.tpl-hidden { display: none; }
  .clean-grid.clean-hidden { display: none; }
  .style-grid.style-hidden { display: none; }
  .canvas-wrap { min-height: 240px; }
  .caption-list { max-height: none; }
}

/* 手机输入框防自动放大：iOS Safari 聚焦字号 <16px 会缩放 */
@media (max-width: 640px) {
  input, select, textarea {
    font-size: 16px !important;
  }
}
