:root {
    --bg: #f6f7fa; --text: #1a2233; --sub: #5b6474; --muted: #6b7484;
    --border: #e3e7ef; --border-2: #d7dce6; --card: #ffffff; --soft: #f8f9fc;
    --input: #ffffff; --code-bg: #eef1f6; --ghost-hover: #f5f8ff;
    --drop: #f8f9fc; --drop-border: #cdd5e1;
    --blue: #2563eb; --blue-hover: #1d4ed8;
    --grid: rgba(26,34,51,.03); --ring: rgba(37,99,235,.14);
    --sh-sm: 0 6px 18px rgba(16,24,40,.05);
    --sh-md: 0 12px 32px rgba(16,24,40,.07);
    --sh-cv: 0 4px 16px rgba(16,24,40,.12);
    --mask: rgba(15,23,42,.45);
    --sh-modal: 0 24px 60px rgba(15,23,42,.25);
    color-scheme: light;
  }
  html[data-theme="dark"] {
    --bg: #0f1115; --text: #e6e8ee; --sub: #a3abbd; --muted: #8b93a5;
    --border: #262d3a; --border-2: #2c3444; --card: #151a23; --soft: #12161d;
    --input: #0f1115; --code-bg: #1b2130; --ghost-hover: #1d2433;
    --drop: #12161d; --drop-border: #2c3444;
    --blue: #3b82f6; --blue-hover: #2563eb;
    --grid: rgba(255,255,255,.045); --ring: rgba(59,130,246,.25);
    --sh-sm: 0 6px 18px rgba(0,0,0,.35);
    --sh-md: 0 12px 32px rgba(0,0,0,.45);
    --sh-cv: 0 4px 16px rgba(0,0,0,.5);
    --mask: rgba(0,0,0,.65);
    --sh-modal: 0 24px 60px rgba(0,0,0,.6);
    color-scheme: dark;
  }
  * { box-sizing: border-box; }
  body {
    margin: 0; padding: 40px 16px; color: var(--text);
    font-family: system-ui, "PingFang SC", "Microsoft YaHei", sans-serif;
    background:
      radial-gradient(circle at 10% 6%, rgba(37,99,235,.06), transparent 32%),
      radial-gradient(circle at 92% 94%, rgba(124,58,237,.05), transparent 28%),
      repeating-linear-gradient(0deg, transparent 0 39px, var(--grid) 39px 40px),
      repeating-linear-gradient(90deg, transparent 0 39px, var(--grid) 39px 40px),
      var(--bg);
    min-height: 100vh; display: flex; justify-content: center; align-items: flex-start;
    transition: background-color .2s, color .2s;
  }
  .card { width: 100%; max-width: 880px; }
  h1 { font-size: 24px; margin: 0 0 6px; letter-spacing: .5px; display: flex; align-items: center; gap: 12px; }
  h1::before { content: ""; width: 15px; height: 15px; flex: none; background: var(--blue); }
  h1::after { content: ""; width: 16px; height: 14px; flex: none; background: #f59e0b; clip-path: polygon(50% 0, 100% 100%, 0 100%); }
  .sub { color: var(--sub); font-size: 13px; margin: 0 0 22px; }
  .muted { color: var(--muted); font-size: 13px; }
  .panel {
    background: var(--card); border: 1px solid var(--border); padding: 20px;
    box-shadow: var(--sh-md); position: relative; overflow: hidden;
  }
  .panel::before {
    content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px;
    background: linear-gradient(90deg,
      #2563eb 0 25%, #7c3aed 25% 50%, #f59e0b 50% 75%, #10b981 75% 100%);
  }
  .row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 12px 0; }
  .row label { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--sub); }
  .row.split .grow2 { flex: 2; }
  .row.split .grow1 { flex: 1; }
  .row.split label { min-width: 0; }
  .row.split label select { flex: 1; min-width: 0; width: auto; }
  button {
    background: var(--blue); color: #fff; border: 0;
    padding: 9px 18px; font-size: 14px; font-weight: 500; cursor: pointer;
    box-shadow: 0 2px 6px rgba(37,99,235,.25);
    touch-action: manipulation; -webkit-tap-highlight-color: transparent;
    transition: background .15s, transform .15s, box-shadow .15s, border-color .15s, color .15s;
  }
  button:hover { background: var(--blue-hover); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(37,99,235,.3); }
  button:active { transform: none; }
  button.ghost { background: var(--card); color: var(--text); border: 1px solid var(--border-2); box-shadow: none; }
  button.ghost:hover { border-color: var(--blue); color: var(--blue); background: var(--ghost-hover); }
  button:disabled { opacity: .45; cursor: wait; transform: none; }
  input[type=text], select {
    background: var(--input); color: var(--text); border: 1px solid var(--border-2);
    padding: 9px 12px; font-size: 14px; outline: none;
    transition: border-color .15s, box-shadow .15s;
  }
  input[type=text]:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--ring); }
  #key { width: 260px; max-width: 100%; }
  #recent { max-width: 190px; }
  button.mini { padding: 6px 12px; font-size: 13px; box-shadow: none; flex: none; }
  #drop {
    margin-top: 14px; border: 2px dashed var(--drop-border); background: var(--drop);
    min-height: 280px; display: flex; align-items: center; justify-content: center;
    padding: 14px; text-align: center; color: var(--muted); cursor: pointer; transition: .15s;
  }
  #drop.drag { border-color: var(--blue); background: var(--ghost-hover); color: var(--blue); }
  #cvwrap { display: none; position: relative; line-height: 0; max-width: 100%; }
  #cvwrap.selecting { cursor: crosshair; touch-action: none; }
  #cv {
    max-width: 100%; max-height: 70vh; display: block; image-rendering: pixelated;
    box-shadow: var(--sh-cv); background: #fff;
  }
  #sel { position: absolute; inset: 0; display: none; pointer-events: none; }
  .selbox {
    position: absolute; border: 2px dashed var(--blue);
    background: rgba(37,99,235,.10); box-sizing: border-box;
  }
  .selbox.drag { border-style: solid; }
  button.ghost.active { border-color: var(--blue); color: var(--blue); background: var(--ghost-hover); }
  #status { color: var(--muted); font-size: 13px; min-height: 18px; margin: 12px 0 0; }
  details {
    margin-top: 20px; background: var(--card); border: 1px solid var(--border);
    padding: 14px 18px; color: var(--sub); font-size: 13px; line-height: 1.9;
    box-shadow: var(--sh-sm);
  }
  details summary { cursor: pointer; color: var(--text); font-weight: 600; }
  details[open] summary { margin-bottom: 6px; }
  code { background: var(--code-bg); color: var(--text); padding: 1px 6px; }
  .footer { margin-top: 16px; color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 8px; }
  .footer .ver { border: 1px solid var(--border-2); padding: 1px 7px; color: var(--sub); flex: none; }
  /* ---- 自定义弹窗 ---- */
  .modal-mask {
    position: fixed; inset: 0; z-index: 100; background: var(--mask);
    display: flex; align-items: center; justify-content: center; padding: 16px;
  }
  .modal {
    background: var(--card); border: 1px solid var(--border); width: 100%; max-width: 460px;
    box-shadow: var(--sh-modal); position: relative; overflow: hidden;
  }
  .modal::before {
    content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px;
    background: linear-gradient(90deg,
      #2563eb 0 25%, #7c3aed 25% 50%, #f59e0b 50% 75%, #10b981 75% 100%);
  }
  .modal h3 { margin: 0; padding: 20px 20px 0; font-size: 16px; color: var(--text); font-weight: 600; }
  .modal-body { padding: 10px 20px 2px; color: var(--sub); font-size: 13px; line-height: 1.8; }
  .modal-body p { margin: 0 0 6px; }
  .modal-body code { word-break: break-all; }
  .modal-actions { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px 18px; }
  /* ---- 分享二维码 ---- */
  .qr-box { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 14px 20px 4px; }
  #qrcv { width: 220px; height: 220px; image-rendering: pixelated; border: 1px solid var(--border); background: #fff; }
  .qr-url { word-break: break-all; font-size: 11px; color: var(--muted); text-align: center; }
  .preview-box { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 8px 0; }
  .preview-img { max-width: 100%; max-height: 60vh; display: block; }
  /* 图片预览专用：更宽的弹窗 + 更大的图 */
  .modal.wide { width: auto; max-width: min(900px, 88vw); max-height: 92vh; }
  .modal.wide .modal-body { padding: 10px 20px 4px; }
  .modal.wide .preview-img { max-width: 100%; max-height: 70vh; display: block; }
  @media (max-width: 560px) {
    .modal.wide { max-width: 92vw; }
    .modal.wide .preview-img { max-height: 60vh; }
  }
  .preview-name { font-size: 11px; color: var(--muted); word-break: break-all; }
  #batchgrid {
    display: none; width: 100%; flex: 1 1 100%;
    grid-template-columns: repeat(auto-fill, 150px);
    gap: 14px; justify-content: center; align-content: center;
  }
  #batchgrid.show { display: grid; }
  #batchgrid img {
    width: 150px; height: 112px; object-fit: cover; display: block;
    border: 1px solid var(--border); box-shadow: var(--sh-sm);
    cursor: zoom-in; background: var(--soft);
    transition: transform .15s, box-shadow .15s, border-color .15s;
  }
  #batchgrid img:hover {
    transform: translateY(-2px); box-shadow: var(--sh-md); border-color: var(--blue);
  }
  /* 按数量定版式：1 居中铺满 / 2 并排平分 / 3 上二下一居中 / 4 四宫格平分 */
  #batchgrid.n1, #batchgrid.n2, #batchgrid.n3, #batchgrid.n4 {
    grid-template-columns: 1fr 1fr; gap: 16px; width: 100%;
  }
  #batchgrid.n1 { grid-template-columns: 1fr; }
  #batchgrid.n1 img {
    width: 100%; height: auto; max-height: 62vh; object-fit: contain;
  }
  #batchgrid.n2 img, #batchgrid.n3 img, #batchgrid.n4 img {
    width: 100%; height: 100%; aspect-ratio: 4 / 3; object-fit: cover;
  }
  #batchgrid.n3 img:nth-child(3) {
    grid-column: 1 / -1; justify-self: center; width: 50%;
  }
  #batchgrid.n4 { grid-template-rows: 1fr 1fr; }

  @media (max-width: 560px) {
    #batchgrid.n1, #batchgrid.n2, #batchgrid.n3, #batchgrid.n4 { gap: 10px; }
  }
  .warn {
    display: block; margin-top: 12px; padding: 10px 12px; background: #fff7e6; border: 1px solid #f59e0b;
    border-left: 4px solid #f59e0b; color: #8a5a00; font-size: 13px; line-height: 1.7;
  }
  html[data-theme="dark"] .warn { background: #2a2113; color: #f7c66f; border-color: #b97e10; }
  .warn[hidden] { display: none; }   /* 没有内容时彻底隐藏，避免露出空条 */

  /* ---- 移动端适配 ---- */
  @media (max-width: 560px) {
    body { padding: 24px 12px; }
    h1 { font-size: 20px; gap: 10px; }
    h1::before, h1::after { width: 12px; height: 12px; }
    .sub { margin-bottom: 16px; }
    .panel { padding: 14px; }
    .row { gap: 8px; margin: 10px 0; }
    .row.keyrow label { width: 100%; }
    .row.keyrow label input { flex: 1; min-width: 0; width: auto; }
    .row.split .grow2 { flex: 1.7; }
    .row.split .grow1 { flex: 1; }
    .row.actions button { flex: 1 1 30%; }
    #drop { min-height: 200px; }
    .hint-extra { display: none; }
    input[type=text], select, button { font-size: 16px; }
    #status { font-size: 12px; }
    .modal-actions button { flex: 1; }
    #batchgrid { grid-template-columns: repeat(auto-fill, 110px); gap: 10px; }
    #batchgrid img { width: 110px; height: 82px; }
    #qrcv { width: 180px; height: 180px; }
  }
