:root {
  --bg: #f4f6f4;
  --bg-soft: #eaf0ec;
  --card: #ffffff;
  --ink: #0e1512;
  --ink-2: #3c4a44;
  --ink-3: #6b7a73;
  --line: #dde5e0;
  --line-2: #eef3f0;
  --accent: #0f766e;
  --accent-2: #10b981;
  --accent-soft: #e3f4ee;
  --warn: #b45309;
  --danger: #b91c1c;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(14, 21, 18, .04), 0 8px 24px -12px rgba(14, 21, 18, .18);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 12% -10%, #dff1e8 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 0%, #e6efff 0%, transparent 55%),
    var(--bg);
  min-height: 100vh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }

button, input, textarea, select { font: inherit; color: inherit; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 40px) 10px;
  max-width: 1480px;
  margin: 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(140deg, #0f766e, #10b981);
  box-shadow: 0 6px 16px -6px rgba(15, 118, 110, .7);
}

.brand-mark svg { width: 26px; height: 26px; }

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 18px; letter-spacing: .01em; }
.brand-text small { color: var(--ink-3); font-size: 12px; }

.topnav { display: flex; gap: 8px; }

/* ---------- 布局 ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 20px;
  max-width: 1360px;
  margin: 0 auto;
  padding: 8px clamp(16px, 4vw, 40px) 32px;
  align-items: start;
}

@media (max-width: 1120px) {
  .layout { grid-template-columns: minmax(0, 1fr) 380px; }
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- 标签页 ---------- */
.builder { overflow: hidden; }

.tabs {
  display: flex;
  gap: 2px;
  padding: 10px 10px 0;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fbfdfc, #f7faf8);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  padding: 11px 16px 13px;
  border-radius: 10px 10px 0 0;
  color: var(--ink-2);
  font-size: 14px;
  cursor: pointer;
  position: relative;
  white-space: nowrap;
  transition: color .15s, background .15s;
}

.tab .ti { margin-right: 6px; font-size: 14px; }

.tab:hover { color: var(--ink); background: #f1f6f3; }

.tab.is-active { color: var(--accent); font-weight: 600; background: #fff; }

.tab.is-active::after {
  content: "";
  position: absolute;
  left: 12px; right: 12px; bottom: -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.panes { padding: 22px 22px 6px; }

.pane[hidden] { display: none; }

@keyframes paneIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.pane.is-active { animation: paneIn .18s ease-out; }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; min-width: 0; }
.field.sub { margin: 10px 0 0; }

.label { font-size: 13px; color: var(--ink-2); font-weight: 550; display: flex; align-items: baseline; gap: 8px; }
.label em { font-style: normal; font-weight: 400; color: var(--ink-3); font-size: 12px; }

input[type=text], input[type=url], input[type=tel], input[type=email], textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fbfdfc;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}

textarea { resize: vertical; min-height: 88px; line-height: 1.6; }

input:focus, textarea:focus, select:focus {
  border-color: var(--accent-2);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, .14);
}

::placeholder { color: #9aa8a1; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.span2 { grid-column: span 2; }

@media (max-width: 560px) {
  .grid2 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .tab { padding: 10px 9px 12px; font-size: 12.5px; }
  .tab .ti { display: none; }
  .panes { padding: 18px 16px 6px; }
  .preview-stage { min-height: 240px; }
}

.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); margin-bottom: 16px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.check.inline { margin: 0; }

.input-affix { position: relative; display: block; }
.input-affix input { padding-right: 60px; }

.mini {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; color: var(--ink-3);
  font-size: 12px; padding: 4px 6px; cursor: pointer; border-radius: 6px;
}
.mini:hover { background: var(--line-2); color: var(--ink); }

.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; }
.row.gap { gap: 8px; }
.row.wrap { flex-wrap: wrap; }

.hint { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.note {
  margin: 2px 0 16px;
  font-size: 12.5px;
  color: var(--ink-3);
  line-height: 1.6;
}

.chips { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  border: 1px dashed var(--line);
  background: #fff;
  color: var(--ink-2);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12px;
  cursor: pointer;
  transition: all .15s;
}
.chip:hover { border-color: var(--accent-2); color: var(--accent); background: var(--accent-soft); }

/* ---------- 分段控件 ---------- */
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--bg-soft);
  border-radius: 10px;
  flex-wrap: wrap;
}

.seg {
  border: 0;
  background: transparent;
  padding: 7px 13px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}

.seg:hover { color: var(--ink); }
.seg.is-active { background: #fff; color: var(--accent); font-weight: 600; box-shadow: 0 1px 3px rgba(14,21,18,.12); }

.msg-fields { margin-top: 18px; }

/* ---------- 文件模式 ---------- */
.file-modes { display: grid; gap: 10px; margin-bottom: 18px; }

.mode-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  transition: all .15s;
  background: #fbfdfc;
}

.mode-card:hover { border-color: #bcd9cd; }

.mode-card:has(input:checked) {
  border-color: var(--accent-2);
  background: linear-gradient(180deg, #f2fbf7, #edf8f4);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, .1);
}

.mode-card input { margin-top: 3px; accent-color: var(--accent); }
.mode-body { display: flex; flex-direction: column; gap: 3px; }
.mode-body strong { font-size: 14px; }
.mode-body small { color: var(--ink-3); font-size: 12.5px; line-height: 1.55; }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  padding: 26px 18px;
  border: 1.5px dashed #c3d6cc;
  border-radius: 14px;
  background: #f9fcfa;
  cursor: pointer;
  transition: all .15s;
  margin-bottom: 14px;
}

.dropzone:hover, .dropzone.drag { border-color: var(--accent-2); background: var(--accent-soft); }
.dz-icon { font-size: 22px; color: var(--accent); line-height: 1; }
.dz-title { font-weight: 600; font-size: 14px; }
.dz-sub { color: var(--ink-3); font-size: 12px; max-width: 380px; }

.file-info {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  padding: 10px 12px;
  margin-bottom: 14px;
  border-radius: 10px;
  background: var(--line-2);
  font-size: 12.5px;
  color: var(--ink-2);
}
.file-info b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------- 底部容量条 ---------- */
.builder-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 22px 16px;
  border-top: 1px solid var(--line-2);
  background: #fbfdfc;
}

.capacity { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }

.cap-bar {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: var(--line-2);
  overflow: hidden;
  max-width: 260px;
}

.cap-bar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .2s ease, background .2s;
}

.cap-bar i.warn { background: linear-gradient(90deg, #f59e0b, #f97316); }
.cap-bar i.over { background: linear-gradient(90deg, #ef4444, #dc2626); }

#capText { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- 预览 ---------- */
.side { display: flex; flex-direction: column; gap: 16px; }

@media (min-width: 901px) {
  .preview-card { position: sticky; top: 84px; }
}

.preview-card { padding: 16px 16px 14px; }

.preview-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.preview-head h2 { font-size: 15px; }

.badge {
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--line-2);
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.badge.err { background: #fee2e2; color: var(--danger); }

.preview-stage {
  position: relative;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: linear-gradient(180deg, #f8fbf9 0%, #f2f7f4 100%);
  display: grid;
  place-items: center;
  padding: 12px;
  min-height: 300px;
}

#qrCanvas {
  width: 100%;
  height: auto;
  max-width: 100%;
  border-radius: 6px;
  display: block;
  background: #fff;
  box-shadow: 0 2px 10px rgba(14, 21, 18, .08);
}

.empty-mask {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(248, 251, 249, .82);
  color: var(--ink-3);
  font-size: 13px;
  backdrop-filter: blur(1.5px);
}
.empty-mask span { padding: 8px 14px; border-radius: 999px; background: #fff; border: 1px solid var(--line); }

.meta {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 12px 0 0;
  padding: 10px 4px 0;
  border-top: 1px solid var(--line-2);
}
.meta div { display: flex; flex-direction: column; gap: 1px; }
.meta dt { font-size: 11px; color: var(--ink-3); }
.meta dd { margin: 0; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.actions .btn:last-child { grid-column: span 2; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 9px 15px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}

.btn svg { width: 17px; height: 17px; }

.btn:hover { border-color: #c4d4cb; background: #fbfdfc; transform: translateY(-1px); }
.btn:active { transform: none; }

.btn.primary {
  background: linear-gradient(140deg, #0f766e, #0e9f6e);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 16px -8px rgba(15, 118, 110, .9);
}
.btn.primary:hover { filter: brightness(1.06); }

.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: rgba(15, 118, 110, .07); color: var(--accent); }

.btn.sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

/* ---------- 样式面板 ---------- */
.style-card { padding: 0; overflow: hidden; }

.style-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: transparent;
  border: 0;
  cursor: pointer;
}
.style-head h2 { font-size: 15px; }
.chev { color: var(--ink-3); font-size: 12px; transition: transform .2s; }
.style-head[aria-expanded="false"] .chev { transform: rotate(-90deg); }

.style-body { padding: 2px 16px 14px; border-top: 1px solid var(--line-2); display: block; }
.style-body[hidden] { display: none; }

.style-body .field { margin: 14px 0; }
.style-body .field:first-child { margin-top: 14px; }

input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  outline: none;
  margin: 6px 0;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid var(--accent);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
input[type=range]::-moz-range-thumb {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid var(--accent);
  cursor: pointer;
}

.color-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

.swatch { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-2); cursor: pointer; }
.swatch input[type=color] {
  -webkit-appearance: none;
  width: 30px; height: 30px;
  padding: 0; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; cursor: pointer;
}
.swatch input[type=color]::-webkit-color-swatch-wrapper { padding: 3px; }
.swatch input[type=color]::-webkit-color-swatch { border: 0; border-radius: 5px; }

/* ---------- 页脚 ---------- */
.foot {
  max-width: 1360px;
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 40px) 34px;
  color: var(--ink-3);
  font-size: 12px;
}
.foot .dot { margin: 0 6px; opacity: .6; }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 24px; }
.modal[hidden] { display: none; }
.modal-mask { position: absolute; inset: 0; background: rgba(10, 18, 14, .42); backdrop-filter: blur(3px); animation: fadeIn .15s ease-out; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

.modal-card {
  position: relative;
  width: min(560px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .45);
  animation: popIn .18s ease-out;
}
.modal-card.wide { width: min(880px, 100%); }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line-2);
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 2;
  border-radius: 18px 18px 0 0;
}
.modal-head h3 { font-size: 15px; }

.icon-btn {
  border: 0; background: transparent; font-size: 14px;
  color: var(--ink-3); width: 30px; height: 30px; border-radius: 8px; cursor: pointer;
}
.icon-btn:hover { background: var(--line-2); color: var(--ink); }

.modal-body { padding: 18px; }

/* ---------- 扫码 ---------- */
.scan-stage {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 12px;
  overflow: hidden;
  background: #0b1210;
  margin-bottom: 12px;
}
#scanVideo { width: 100%; height: 100%; object-fit: cover; display: none; }
#scanVideo.live { display: block; }

.scan-frame i {
  position: absolute; width: 26px; height: 26px;
  border: 2.5px solid var(--accent-2);
  opacity: .9;
}
.scan-frame i:nth-child(1) { top: 12px; left: 12px; border-right: 0; border-bottom: 0; border-radius: 8px 0 0 0; }
.scan-frame i:nth-child(2) { top: 12px; right: 12px; border-left: 0; border-bottom: 0; border-radius: 0 8px 0 0; }
.scan-frame i:nth-child(3) { bottom: 12px; left: 12px; border-right: 0; border-top: 0; border-radius: 0 0 0 8px; }
.scan-frame i:nth-child(4) { bottom: 12px; right: 12px; border-left: 0; border-top: 0; border-radius: 0 0 8px 0; }

.scan-placeholder {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: #93a29a; font-size: 13px; text-align: center; padding: 20px;
}

.scan-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 传输 ---------- */
.xfer-tabs { margin-bottom: 14px; }

.xfer-grid { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 16px; align-items: start; }

@media (max-width: 720px) {
  .xfer-grid { grid-template-columns: 1fr; }
}

.xfer-canvas-wrap {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  place-items: center;
}
#animCanvas { width: 100%; height: auto; display: block; }

.xfer-canvas-wrap.recv {
  background: #0b1210;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  position: relative;
  padding: 0;
}
#recvVideo { width: 100%; height: 100%; object-fit: cover; }
.recv-hint {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: #93a29a; font-size: 12.5px; text-align: center; padding: 24px;
}

.xfer-side { display: flex; flex-direction: column; gap: 6px; }

.xfer-file {
  font-weight: 600; font-size: 13.5px;
  word-break: break-all;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line-2);
  margin-bottom: 4px;
}

.kv { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; color: var(--ink-3); }
.kv b { color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 600; }

.progress { height: 8px; border-radius: 999px; background: var(--line-2); overflow: hidden; margin-bottom: 8px; }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .2s; }

/* ---------- 帮助 ---------- */
.help-body h4 { font-size: 14px; margin: 18px 0 6px; color: var(--accent); }
.help-body h4:first-child { margin-top: 0; }
.help-body p { margin: 0 0 10px; font-size: 13px; color: var(--ink-2); line-height: 1.7; }
.help-body ul { margin: 0 0 10px; padding-left: 20px; font-size: 13px; color: var(--ink-2); line-height: 1.7; }
.help-body li { margin-bottom: 4px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 16px);
  background: rgba(14, 21, 18, .92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: all .2s ease;
  z-index: 90;
  max-width: min(560px, calc(100vw - 32px));
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: rgba(153, 27, 27, .95); }

/* ---------- 深色模式 ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1310;
    --bg-soft: #16211c;
    --card: #121b17;
    --ink: #e8f0ec;
    --ink-2: #b7c6bf;
    --ink-3: #85958d;
    --line: #24312b;
    --line-2: #1a2621;
    --accent: #34d399;
    --accent-2: #10b981;
    --accent-soft: #10312a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
  }
  body {
    background:
      radial-gradient(1200px 600px at 12% -10%, #123128 0%, transparent 60%),
      radial-gradient(900px 500px at 100% 0%, #16233a 0%, transparent 55%),
      var(--bg);
  }
  .tab.is-active { background: var(--card); }
  .seg.is-active { background: #1d2b25; }
  input, textarea, select { background: #0f1a15; }
  .btn { background: #16211c; }
  .btn.ghost:hover { background: rgba(52, 211, 153, .1); }
  .preview-stage { background: #0f1a15; }
  .empty-mask { background: rgba(12, 19, 16, .8); }
  .dropzone { background: #0f1a15; }
  .mode-card { background: #0f1a15; }
  .mode-card:has(input:checked) {
    background: linear-gradient(180deg, #143b2e, #102a22);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(52, 211, 153, .12);
  }
  .modal-card, .modal-head { background: var(--card); }
  .builder-foot { background: #0f1a15; }
  .tabs { background: #0f1a15; }
  .preview-stage .empty-mask span { background: var(--card); }
}
