:root {
  --bg: #f5f5f7;
  --side: #fbfbfd;
  --card: #ffffff;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --faint: #8e8e93;
  --line: rgba(60, 60, 67, .12);
  --hair: rgba(60, 60, 67, .18);
  --grid: rgba(60, 60, 67, .05);
  --primary: #007aff;
  --primary-soft: #e8f1ff;
  --green: #34c759;
  --green-soft: #e7f8ec;
  --red: #ff3b30;
  --red-soft: #ffeceb;
  --orange: #ff9500;
  --orange-soft: #fff3e0;
  --field: #ffffff;
  --seg: #e8e8ed;
  --fill: #f2f2f4;
  --fill-hover: #e9e9ec;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .06);
  --shadow-lg: 0 10px 36px rgba(0, 0, 0, .14);
  --header-h: 56px;
  --sidebar-w: 300px;
  --ease: cubic-bezier(.4, 0, .2, 1);
}

html[data-theme="dark"] {
  --bg: #000000;
  --side: #1c1c1e;
  --card: #1c1c1e;
  --ink: #f5f5f7;
  --muted: #98989d;
  --faint: #636366;
  --line: rgba(84, 84, 88, .36);
  --hair: rgba(84, 84, 88, .5);
  --grid: rgba(255, 255, 255, .045);
  --primary: #0a84ff;
  --primary-soft: #0a2a4d;
  --green: #30d158;
  --green-soft: #0c3320;
  --red: #ff453a;
  --red-soft: #3a1413;
  --orange: #ff9f0a;
  --orange-soft: #3a2a08;
  --field: #2c2c2e;
  --seg: #3a3a3c;
  --fill: #2c2c2e;
  --fill-hover: #3a3a3c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px rgba(0, 0, 0, .5);
  --shadow-lg: 0 10px 36px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.01em;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background .3s, color .3s;
}


/* Header */
header {
  height: var(--header-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: rgba(251, 251, 253, .8);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}
html[data-theme="dark"] header { background: rgba(28, 28, 30, .8); }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo-link { display: inline-flex; align-items: center; text-decoration: none; flex-shrink: 0; }
.logo { position: relative; display: inline-flex; align-items: center; height: 30px; flex-shrink: 0; }
.logo-img { height: 30px; width: auto; max-width: 170px; object-fit: contain; display: block; }
.logo-dark { display: none; }
[data-theme="dark"] .logo-light { display: none; }
[data-theme="dark"] .logo-dark { display: block; }
.logo-fallback { display: none; align-items: center; justify-content: center; height: 30px; padding: 0 11px; border-radius: 8px; background: linear-gradient(135deg, #0a84ff, #5e5ce6); color: #fff; font-weight: 700; font-size: 15px; letter-spacing: .01em; white-space: nowrap; }
.logo.img-fail .logo-fallback { display: inline-flex; }
.brand-text { min-width: 0; line-height: 1.15; }
.brand-text .t { font-size: 16px; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; }
.brand-text .s { font-size: 11px; color: var(--faint); font-weight: 500; white-space: nowrap; margin-top: 1px; }
.spacer { flex: 1; }

.more-link { display: inline-flex; align-items: center; gap: 5px; padding: 7px 13px; border-radius: 980px; background: var(--fill); color: var(--muted); font-size: 13px; text-decoration: none; transition: all .15s var(--ease); }
.more-link:hover { background: var(--fill-hover); color: var(--ink); }
.more-link svg { width: 14px; height: 14px; }

.icon-btn { width: 34px; height: 34px; border: none; background: transparent; cursor: pointer; border-radius: 8px; color: var(--muted); display: flex; align-items: center; justify-content: center; transition: all .15s var(--ease); flex-shrink: 0; }
.icon-btn:hover { background: var(--fill); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }
.sun-icon { display: none; }
html[data-theme="dark"] .sun-icon { display: block; }
html[data-theme="dark"] .moon-icon { display: none; }

/* Layout */
.layout { flex: 1; display: flex; min-height: 0; }

/* Sidebar */
aside { width: var(--sidebar-w); flex-shrink: 0; background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; overflow: hidden; }
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 14px 0 18px; }
.sidebar-scroll::-webkit-scrollbar { width: 6px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: rgba(120, 120, 128, .35); border-radius: 3px; }

.group { padding: 0 16px; }
.group + .group { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.group-label { font-size: 11px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 8px; padding: 0 2px; }

/* 分段控件（重命名模式） */
.seg { display: flex; background: var(--seg); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: none; background: transparent; padding: 8px 4px; font-size: 12.5px; font-weight: 500; color: var(--muted); border-radius: 7px; cursor: pointer; font-family: inherit; transition: all .15s var(--ease); white-space: nowrap; }
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); font-weight: 600; }
.mode-desc { font-size: 11.5px; color: var(--faint); line-height: 1.55; margin-top: 8px; padding: 0 2px; }

/* 提示与示例 */
.hint { font-size: 11.5px; color: var(--faint); line-height: 1.55; margin: 0 2px 10px; }
.hint b { color: var(--muted); font-weight: 600; }
.hint code { background: var(--fill); padding: 1px 5px; border-radius: 5px; font-size: 11px; color: var(--primary); font-family: ui-monospace, "SF Mono", Consolas, monospace; }
.example { margin: 4px 2px 0; padding: 8px 10px; background: var(--primary-soft); border-radius: 9px; font-size: 11.5px; color: var(--ink); line-height: 1.5; word-break: break-all; }
.example b { color: var(--primary); font-weight: 600; font-family: ui-monospace, "SF Mono", Consolas, monospace; }
.opt-label em.ex { display: block; font-style: normal; font-size: 10.5px; color: var(--faint); margin-top: 2px; }

.opt { display: flex; align-items: center; gap: 12px; padding: 7px 4px; cursor: pointer; min-height: 38px; border-radius: 6px; transition: background .1s; }
.opt:hover { background: var(--card); }
.opt-label { font-size: 13px; flex: 1; color: var(--ink); }
.opt-control { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.opt-control.full { flex: 1; width: 100%; }
.opt.stack { flex-direction: column; align-items: stretch; gap: 6px; padding: 6px 4px; }
.opt.stack .opt-label { flex: none; }

.opt-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 4px; margin-top: 2px; }
.mini-field { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); }
.mini-field span { padding-left: 2px; }

/* Switch (iOS style, green) */
.switch { position: relative; width: 38px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .track { position: absolute; inset: 0; background: var(--hair); border-radius: 980px; transition: background .2s var(--ease); }
.switch .thumb { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); transition: transform .2s var(--ease); }
.switch input:checked ~ .track { background: var(--green); }
.switch input:checked ~ .thumb { transform: translateX(16px); }

/* Select */
.sel {
  padding: 6px 26px 6px 10px; border: 1px solid var(--hair); border-radius: 8px; font-size: 12.5px; font-family: inherit;
  background: var(--field) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath d='M2 3.5l3 3 3-3' stroke='%238e8e93' stroke-width='1.4' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 8px center;
  -webkit-appearance: none; appearance: none; color: var(--ink); cursor: pointer; max-width: 100%;
}
.sel:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* Inputs */
.field { border: 1px solid var(--hair); border-radius: 9px; padding: 9px 12px; font-size: 13.5px; font-family: inherit; background: var(--field); color: var(--ink); transition: all .15s var(--ease); width: 100%; }
.field::placeholder { color: var(--faint); }
.field:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.field.sm { padding: 8px 10px; font-size: 12.5px; }
.field.num { padding: 7px 8px; text-align: center; -moz-appearance: textfield; }
.field.num::-webkit-outer-spin-button, .field.num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.reset-btn { display: inline-flex; align-items: center; gap: 6px; margin: 16px 16px 0; width: calc(100% - 32px); justify-content: center; padding: 9px; border: 1px dashed var(--hair); background: transparent; color: var(--muted); font-size: 12.5px; font-weight: 500; border-radius: 9px; cursor: pointer; font-family: inherit; transition: .15s; }
.reset-btn:hover { background: var(--fill); color: var(--ink); border-color: var(--primary); }
.reset-btn svg { width: 14px; height: 14px; }

/* Buttons */
.btn { padding: 9px 16px; border: none; border-radius: 980px; font-size: 13.5px; font-weight: 500; cursor: pointer; transition: all .15s var(--ease); display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-family: inherit; white-space: nowrap; letter-spacing: -0.01em; }
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #0a6ee0; }
.btn-primary:active { background: #0a5ec0; }
.btn-primary:disabled { background: var(--seg); color: var(--faint); cursor: not-allowed; }
.btn-fill { background: var(--fill); color: var(--ink); }
.btn-fill:hover { background: var(--fill-hover); }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover { background: #2bb24c; }
.btn-green:disabled { background: var(--seg); color: var(--faint); cursor: not-allowed; }
.btn-sm { padding: 8px 14px; font-size: 12.5px; }

.mini-btn { padding: 4px 11px; border: 1px solid var(--hair); background: var(--fill); color: var(--muted); font-size: 12px; border-radius: 8px; cursor: pointer; font-family: inherit; transition: .15s; }
.mini-btn:hover:not(:disabled) { background: var(--fill-hover); color: var(--ink); }
.mini-btn:disabled { opacity: .4; cursor: not-allowed; }

/* Main */
main { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.main-inner { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 14px; padding: 18px 22px; width: 100%; max-width: none; margin: 0; }

/* File card */
.file-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; flex-shrink: 0; }
.file-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.fc-title { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; }
.fc-title svg { width: 18px; height: 18px; color: var(--primary); }
.fc-actions { display: flex; align-items: center; gap: 10px; }
.fc-count { font-size: 12.5px; color: var(--muted); }

.dropzone { border: 1.5px dashed var(--hair); border-radius: var(--radius-sm); padding: 24px 16px; text-align: center; cursor: pointer; transition: all .2s var(--ease); background: var(--bg); }
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: var(--primary-soft); }
.dz-icon { color: var(--faint); margin-bottom: 6px; }
.dz-icon svg { width: 30px; height: 30px; }
.dropzone:hover .dz-icon, .dropzone.dragover .dz-icon { color: var(--primary); }
.dz-title { font-size: 14px; font-weight: 500; color: var(--ink); }
.dz-sub { font-size: 12px; color: var(--faint); margin-top: 3px; }
.dz-btns { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }

/* Preview card */
.preview-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; flex: 1 1 auto; min-height: 260px; overflow: hidden; }
.preview-sub { padding: 0 16px 11px; font-size: 12px; color: var(--faint); }
.preview-head { display: flex; align-items: center; justify-content: space-between; padding: 13px 16px; border-bottom: 1px solid var(--line); gap: 10px; flex-shrink: 0; }
.ph-title { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 7px; }
.ph-title .count { color: var(--faint); font-weight: 500; font-variant-numeric: tabular-nums; }
.ph-badges { display: flex; gap: 6px; }
.badge { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 980px; }
.badge-conflict { background: var(--red-soft); color: var(--red); }
.badge-warn { background: var(--orange-soft); color: var(--orange); }

.preview-list { flex: 1; overflow-y: auto; min-height: 180px; }
.preview-list::-webkit-scrollbar { width: 8px; }
.preview-list::-webkit-scrollbar-thumb { background: rgba(120, 120, 128, .35); border-radius: 4px; }
.list-empty { padding: 36px 24px; text-align: center; color: var(--faint); }
.list-empty svg { width: 28px; height: 28px; margin-bottom: 10px; opacity: .45; }
.list-empty .t { font-size: 13.5px; color: var(--muted); }
.list-empty .s { font-size: 12px; margin-top: 3px; }

.r-row { display: flex; align-items: center; gap: 10px; padding: 8px 16px; border-bottom: 1px solid var(--line); transition: background .12s; }
.r-row:last-child { border-bottom: none; }
.r-row:hover { background: var(--bg); }
.r-row.conflict { background: var(--red-soft); }
.r-row.invalid { background: var(--orange-soft); }
.r-idx { color: var(--faint); font-size: 11px; min-width: 30px; text-align: right; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.r-old { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.r-name { font-size: 12.5px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace; }
.r-dir { font-size: 10.5px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-arrow { color: var(--faint); flex-shrink: 0; }
.r-arrow svg { width: 16px; height: 16px; }
.r-new { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.r-new .r-name { color: var(--primary); font-weight: 500; }
.r-row.conflict .r-new .r-name { color: var(--red); }
.r-row.invalid .r-new .r-name { color: var(--orange); }
.r-tag { font-size: 10px; font-weight: 600; padding: 1px 6px; border-radius: 5px; margin-top: 2px; }
.r-tag.cf { background: rgba(255, 59, 48, .16); color: var(--red); }
.r-tag.iv { background: rgba(255, 149, 0, .16); color: var(--orange); }
.r-unchanged .r-new .r-name { color: var(--faint); font-weight: 400; }

/* Action bar */
.actionbar { flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); flex-wrap: wrap; }
.ab-hint { font-size: 12.5px; color: var(--faint); }
.ab-btns { display: flex; gap: 8px; align-items: center; }

/* Export dropdown */
.export-wrap { position: relative; }
.export-menu { position: absolute; right: 0; bottom: calc(100% + 8px); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: 4px; min-width: 196px; z-index: 50; display: none; }
.export-menu.show { display: block; }
.export-menu button { display: flex; width: 100%; padding: 9px 12px; border: none; background: transparent; cursor: pointer; font-size: 13px; color: var(--ink); border-radius: 7px; text-align: left; align-items: center; gap: 9px; font-family: inherit; }
.export-menu button:hover { background: var(--fill); }
.export-menu button svg { width: 15px; height: 15px; color: var(--muted); flex-shrink: 0; }
.export-menu .fmt { font-size: 10.5px; color: var(--faint); margin-left: auto; }

.hidden { display: none !important; }

/* Toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(120px); background: rgba(29, 29, 31, .96); color: #fff; padding: 11px 20px; border-radius: var(--radius-sm); font-size: 13.5px; box-shadow: var(--shadow-lg); z-index: 1000; backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); transition: transform .35s var(--ease), opacity .3s; opacity: 0; display: flex; align-items: center; gap: 8px; max-width: 90vw; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast svg { width: 15px; height: 15px; flex-shrink: 0; }
.toast.ok svg { color: var(--green); }
.toast.err svg { color: var(--red); }

@media (max-width: 860px) {
  :root { --sidebar-w: 252px; }
  .main-inner { padding: 14px; }
  .opt-row { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  body { overflow: auto; }
  .layout { flex-direction: column; }
  main { order: 1; overflow: visible; }
  aside { order: 2; width: 100%; max-height: none; border-right: none; border-top: 1px solid var(--line); }
  .sidebar-scroll { overflow: visible; }
  .preview-card { min-height: 0; }
  .preview-list { max-height: none; overflow: visible; }
  .main-inner { padding: 12px; overflow: visible; }
  .more-link { display: none; }
  .brand-text .s { display: none; }
}

/* 扩展项折叠 */
.ext-details { margin: 10px 2px 0; border-top: 1px dashed var(--line); padding-top: 10px; }
.ext-details > summary { list-style: none; cursor: pointer; font-size: 12px; font-weight: 600; color: var(--muted); padding: 4px 2px; display: flex; align-items: center; gap: 6px; user-select: none; }
.ext-details > summary::-webkit-details-marker { display: none; }
.ext-details > summary::before { content: "▸"; font-size: 10px; transition: transform .15s var(--ease); color: var(--faint); }
.ext-details[open] > summary::before { transform: rotate(90deg); }
.ext-details .opt { padding-left: 2px; padding-right: 2px; }

/* 通配符 chips */
.token-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 2px 0; }
.token-chip { border: 1px solid var(--hair); background: var(--fill); color: var(--primary); font-size: 11.5px; font-family: ui-monospace, "SF Mono", Consolas, monospace; padding: 4px 9px; border-radius: 7px; cursor: pointer; font-family: inherit; transition: all .15s var(--ease); }
.token-chip:hover { background: var(--primary-soft); border-color: var(--primary); }
.tpl-actions { margin: 8px 2px 0; }

/* 使用说明弹窗 */
.modal { position: fixed; inset: 0; z-index: 2000; display: none; align-items: center; justify-content: center; padding: 20px; }
.modal.show { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .4); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.modal-card { position: relative; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-lg); max-width: 440px; width: 100%; padding: 22px; animation: modalIn .2s var(--ease); }
.modal-close { position: absolute; top: 12px; right: 12px; width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; border: none; background: transparent; color: var(--muted); font-size: 22px; line-height: 1; border-radius: 8px; cursor: pointer; transition: background .15s, color .15s; }
.modal-close:hover { background: var(--fill); color: var(--ink); }
@keyframes modalIn { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 14px; padding-right: 34px; }
.modal-steps { margin: 0; padding-left: 20px; }
.modal-steps li { font-size: 13px; line-height: 1.7; color: var(--ink); margin-bottom: 8px; }
.modal-steps code { background: var(--fill); padding: 1px 6px; border-radius: 5px; font-size: 12px; color: var(--primary); font-family: ui-monospace, "SF Mono", Consolas, monospace; }
.modal-steps strong { color: var(--ink); font-weight: 600; }
.modal-card .btn { margin-top: 16px; width: 100%; }

/* 脚本弹窗：脚本内容 + 复制 / 下载 */
.script-box { margin-top: 4px; border: 1px solid var(--hair); border-radius: 12px; overflow: hidden; background: var(--fill); }
.sb-head { display: flex; align-items: baseline; gap: 8px; padding: 9px 12px; border-bottom: 1px solid var(--hair); background: var(--card); flex-wrap: wrap; }
.sb-name { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 13px; font-weight: 600; color: var(--primary); }
.sb-tip { font-size: 11.5px; color: var(--muted); }
.sb-code { margin: 0; max-height: 230px; overflow: auto; padding: 12px; font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 12px; line-height: 1.55; color: var(--ink); white-space: pre; user-select: text; }
.sb-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--hair); background: var(--card); }
.sb-actions .btn { margin-top: 0; width: auto; flex: 1; }

