/* 颜色、圆角、字体读主题的 :root 变量；后面的值是主题没写时的兜底（第二版 B「清爽画布」配色） */
.fim {
  --fim-bg: var(--color-bg, #f6f8fb);
  --fim-card: var(--color-card, #ffffff);
  --fim-sunken: var(--color-sunken, #eef2f7);
  --fim-text: var(--color-text, #0f172a);
  --fim-muted: var(--color-muted, #475569);
  --fim-subtle: var(--color-subtle, #64748b);
  --fim-primary: var(--color-primary, #2563eb);
  --fim-primary-hover: var(--color-primary-hover, #1d4ed8);
  --fim-primary-soft: var(--color-primary-soft, #e8efff);
  --fim-accent: var(--color-accent, #0f766e);
  --fim-accent-soft: var(--color-accent-soft, #ccfbf1);
  --fim-line: var(--color-line, rgba(15, 23, 42, 0.08));
  --fim-line-strong: var(--color-line-strong, rgba(15, 23, 42, 0.16));
  --fim-radius: var(--radius, 12px);
  --fim-radius-sm: var(--radius-sm, 8px);
  --fim-font-body: var(--font-body, "Geist", system-ui, -apple-system, "Segoe UI", sans-serif);
  --fim-font-mono: var(--font-mono, "Geist Mono", ui-monospace, monospace);
  --fim-shadow-1: 0 1px 2px rgba(15, 23, 42, 0.06);
  --fim-shadow-2: 0 1px 2px rgba(15, 23, 42, 0.04), 0 12px 32px -8px rgba(15, 23, 42, 0.14);
  display: flex;
  flex-direction: row;
  height: var(--fim-height, calc(100svh - 168px));
  min-height: 560px;
  background: var(--fim-card);
  color: var(--fim-text);
  font-family: var(--fim-font-body);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.fim, .fim *, .fim *::before, .fim *::after { box-sizing: border-box; }
.fim [hidden] { display: none !important; }
.fim-num { font-family: var(--fim-font-mono); font-variant-numeric: tabular-nums; }
.fim-sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- 图标（24 网格、1.75 描边、圆角端点） ---------- */
.fim-ic {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
}
.fim-ic-sm { width: 16px; height: 16px; }
.fim-ic-lg { width: 24px; height: 24px; }
.fim-ic-x { transform: rotate(45deg); }

/* ---------- 按钮规范（36 / 44 / 52 三档，主 / 次 / 幽灵三种样式） ---------- */
.fim-btn {
  --h: 44px;
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--h); min-width: 44px; padding: 0 18px;
  border-radius: var(--fim-radius-sm);
  border: 1px solid transparent;
  font-family: var(--fim-font-body); font-size: 15px; font-weight: 500; line-height: 1;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.05s;
}
.fim-btn:active:not(:disabled) { transform: translateY(1px); }
.fim-btn:focus-visible,
.fim-rail-btn:focus-visible,
.fim-starter:focus-visible,
.fim-add:focus-visible,
.fim-select:focus-visible,
.fim-number input:focus-visible,
.fim-label-input:focus-visible,
.fim-text-input:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--fim-bg), 0 0 0 5px var(--fim-primary);
}
.fim-btn-lg { --h: 52px; padding: 0 24px; font-size: 16px; border-radius: 10px; }
.fim-btn-sm { --h: 36px; padding: 0 12px; font-size: 14px; }
/* 36 px 高的按钮通过伪元素把点击区域补足到 44 px */
.fim-btn-sm::before { content: ""; position: absolute; inset: -4px; }
.fim-btn-icon { width: var(--h); min-width: var(--h); padding: 0; }
.fim-btn-primary {
  background: var(--fim-primary); color: #fff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.16);
}
.fim-btn-primary:hover:not(:disabled) { background: var(--fim-primary-hover); }
.fim-btn-secondary {
  background: var(--fim-card); color: var(--fim-text);
  border-color: var(--fim-line-strong); box-shadow: var(--fim-shadow-1);
}
.fim-btn-secondary:hover:not(:disabled) { background: var(--fim-sunken); }
.fim-btn-ghost { background: transparent; color: var(--fim-muted); }
.fim-btn-ghost:hover:not(:disabled) { background: var(--fim-sunken); color: var(--fim-text); }
.fim-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- 左侧竖排工具栏（60 px；桌面空画板隐藏，加图后显示） ---------- */
.fim-rail {
  flex: none; width: 60px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 0;
  border-right: 1px solid var(--fim-line);
  background: var(--fim-card);
}
.fim-rail-sep { width: 24px; height: 1px; background: var(--fim-line); margin: 4px 0; flex: none; }
.fim-rail-btn {
  width: 44px; height: 44px; border: 0; border-radius: var(--fim-radius-sm);
  background: transparent; color: var(--fim-muted);
  display: grid; place-items: center; cursor: pointer;
  transition: background-color 0.15s, color 0.15s, transform 0.05s;
}
.fim-rail-btn:hover:not(:disabled) { background: var(--fim-sunken); color: var(--fim-text); }
.fim-rail-btn:active:not(:disabled) { transform: translateY(1px); }
.fim-rail-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ---------- 工作区主框架：空状态整块是舞台，加图后展开 280px 面板 + 预览列 ---------- */
.fim-work {
  flex: 1; min-width: 0; min-height: 0;
  display: grid; grid-template-columns: 280px minmax(0, 1fr);
}
.fim[data-state="empty"] .fim-work { grid-template-columns: minmax(0, 1fr); }
.fim[data-state="empty"] .fim-rail,
.fim[data-state="empty"] .fim-panel,
.fim[data-state="empty"] .fim-exportbar,
.fim[data-state="empty"] .fim-tray,
.fim[data-state="empty"] .fim-preview,
.fim[data-state="empty"] .fim-pdf-preview,
.fim[data-state="empty"] .fim-crop-stage,
.fim[data-state="empty"] .fim-batch-view,
.fim[data-state="ready"] .fim-empty,
.fim[data-mode="batch"] .fim-preview,
.fim[data-mode="batch"] .fim-pdf-preview,
.fim[data-mode="merge"] .fim-batch-view,
.fim[data-pdf-preview="true"] .fim-preview,
.fim[data-cropping="true"] .fim-preview,
.fim[data-cropping="true"] .fim-pdf-preview,
.fim[data-cropping="true"] .fim-batch-view { display: none; }
.fim[data-panel-view="edit"] .fim-mode-row { display: none; }

/* ---------- 左侧参数面板（280 px） ---------- */
.fim-panel {
  border-right: 1px solid var(--fim-line);
  background: var(--fim-card);
  overflow-x: hidden; overflow-y: auto;
  min-height: 0;
}
.fim-mode-row { padding: 12px 20px; border-bottom: 1px solid var(--fim-line); }
.fim-group {
  border: 0; margin: 0; padding: 16px 20px;
  border-bottom: 1px solid var(--fim-line);
  min-width: 0;
}
.fim-group:last-child { border-bottom: 0; }
.fim-group:disabled, .fim-sub-group:disabled { opacity: 0.45; }
.fim-group:disabled *, .fim-sub-group:disabled * { cursor: not-allowed; }
.fim-sub-group { border: 0; margin: 16px 0 0; padding: 0; min-width: 0; }
.fim-sub-first { margin-top: 0; }
.fim-group legend,
.fim-sub-group legend {
  width: 100%; padding: 0; margin: 0 0 12px;
  font-size: 12px; font-weight: 500; line-height: 1;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--fim-subtle);
}
.fim-legend-row { display: flex; align-items: center; justify-content: space-between; width: 100%; }
.fim-group-body { display: grid; gap: 10px; }
.fim-pdf-group { display: grid; gap: 10px; }
.fim-sub-group .fim-select + .fim-seg { margin-top: 8px; }
.fim-sub-group .fim-layouts + .fim-range { margin-top: 10px; }

/* 布局四格：图标 + 文字，选中态 2px 主色框 + 浅蓝底 + 右上角对勾 */
.fim-layouts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.fim-layout-opt { position: relative; min-width: 0; display: block; }
.fim-layout-opt input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.fim-layout-card {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 6px; min-height: 64px; padding: 8px 2px;
  border: 1px solid var(--fim-line-strong); border-radius: var(--fim-radius-sm);
  background: var(--fim-card); color: var(--fim-muted);
  font-size: 11px; font-weight: 500; line-height: 1.15; cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, color 0.15s;
}
.fim-layout-opt:hover .fim-layout-card { border-color: var(--fim-primary); color: var(--fim-text); }
.fim-layout-opt input:checked + .fim-layout-card {
  border: 2px solid var(--fim-primary); padding: 7px 1px;
  background: var(--fim-primary-soft); color: var(--fim-text); font-weight: 600;
}
.fim-layout-opt input:checked + .fim-layout-card .fim-ic { color: var(--fim-primary); }
/* 选中态不只靠颜色：右上角加对勾 */
.fim-layout-opt input:checked + .fim-layout-card::after {
  content: ""; position: absolute; top: -6px; right: -6px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--fim-primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E") center/10px no-repeat;
  box-shadow: 0 0 0 2px var(--fim-card);
}
.fim-layout-opt input:focus-visible + .fim-layout-card {
  outline: none; box-shadow: 0 0 0 3px var(--fim-bg), 0 0 0 5px var(--fim-primary);
}

/* 分段控件（照原型 .seg） */
.fim-seg {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 3px; gap: 3px;
  background: var(--fim-sunken); border-radius: var(--fim-radius-sm);
}
.fim-seg-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.fim-seg-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.fim-seg label { position: relative; min-width: 0; display: block; }
.fim-seg input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.fim-seg span {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  min-height: 36px; padding: 0 6px; border-radius: 6px;
  background: transparent; color: var(--fim-muted);
  font-size: 13px; font-weight: 500; line-height: 1; text-align: center;
  cursor: pointer; white-space: nowrap;
  transition: background-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.fim-seg span::before { content: ""; position: absolute; inset: -4px 0; }
.fim-seg input:checked + span {
  background: var(--fim-card); color: var(--fim-text); font-weight: 600;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.1), 0 0 0 0.5px rgba(15, 23, 42, 0.06);
}
.fim-seg input:disabled + span { opacity: 0.45; cursor: not-allowed; }
.fim-seg input:focus-visible + span {
  outline: none; box-shadow: 0 0 0 3px var(--fim-bg), 0 0 0 5px var(--fim-primary);
}

/* 滑块：右侧数值放进等宽小数字框 */
.fim-range {
  display: grid; grid-template-columns: 64px minmax(0, 1fr) 42px;
  align-items: center; gap: 10px;
  min-height: 34px; font-size: 14px; color: var(--fim-text);
}
.fim-range.is-disabled { opacity: 0.45; }
.fim-range.is-disabled * { cursor: not-allowed; }
.fim-range input[type="range"] { width: 100%; accent-color: var(--fim-primary); margin: 0; cursor: pointer; }
.fim-range output {
  font-family: var(--fim-font-mono); font-size: 13px; font-weight: 500; line-height: 1;
  font-variant-numeric: tabular-nums; color: var(--fim-muted);
  text-align: center; background: var(--fim-sunken);
  border-radius: 5px; padding: 6px 0;
}

/* 下拉框与字段 */
.fim-select {
  width: 100%; height: 44px; padding: 0 36px 0 12px;
  border: 1px solid var(--fim-line-strong); border-radius: var(--fim-radius-sm);
  background: var(--fim-card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") right 10px center/16px no-repeat;
  font: 500 14px/1.2 var(--fim-font-body); color: var(--fim-text);
  appearance: none; cursor: pointer;
}
.fim-field { display: grid; gap: 6px; font-size: 14px; color: var(--fim-text); }
.fim-field > span { font-size: 13px; font-weight: 500; color: var(--fim-muted); }
.fim-help { font-size: 12.5px; color: var(--fim-muted); margin: 0; line-height: 1.4; }
.fim-number {
  display: grid; grid-template-columns: 64px minmax(0, 1fr) auto;
  align-items: center; gap: 8px; font-size: 14px;
}
.fim-number input {
  width: 100%; min-width: 0; height: 44px; padding: 0 12px;
  border: 1px solid var(--fim-line-strong); border-radius: var(--fim-radius-sm);
  background: var(--fim-card); color: var(--fim-text);
  font-family: var(--fim-font-mono); font-size: 14px; font-variant-numeric: tabular-nums;
}
.fim-unit { color: var(--fim-muted); font-size: 12px; }

.fim-label-list, .fim-text-controls { display: grid; gap: 10px; }
.fim-label-row {
  display: grid; grid-template-columns: 24px minmax(0, 1fr);
  align-items: center; gap: 8px;
}
.fim-label-no {
  font-family: var(--fim-font-mono); font-size: 12px; font-weight: 500;
  font-variant-numeric: tabular-nums; color: var(--fim-subtle);
}
.fim-label-input,
.fim-text-input {
  width: 100%; min-width: 0; height: 44px; padding: 0 12px;
  border: 1px solid var(--fim-line-strong); border-radius: var(--fim-radius-sm);
  background: var(--fim-card); color: var(--fim-text); font: inherit;
}
.fim-text-add,
.fim-text-delete { width: 100%; font-size: 14px; }
.fim-text-controls {
  padding-top: 10px;
  border-top: 1px solid var(--fim-line);
}

/* 底色圆形色块：30px 圆点居于 44×44 可点区域内，选中时外圈描边、大小不变 */
.fim-swatches { display: flex; flex-wrap: wrap; gap: 0; margin: -6px; }
.fim-swatch {
  position: relative; width: 44px; height: 44px;
  display: grid; place-items: center; cursor: pointer;
}
.fim-swatch input[type="radio"] { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.fim-swatch-dot {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--swatch);
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.16);
  transition: box-shadow 0.15s;
}
.fim-swatch-clear .fim-swatch-dot {
  background: repeating-conic-gradient(#e2e8f0 0% 25%, #fff 0% 50%) 0 0 / 10px 10px;
}
.fim-swatch input[type="radio"]:checked + .fim-swatch-dot {
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.16), 0 0 0 2px var(--fim-card), 0 0 0 4px var(--fim-primary);
}
.fim-swatch input[type="radio"]:focus-visible + .fim-swatch-dot {
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.16), 0 0 0 3px var(--fim-bg), 0 0 0 5px var(--fim-primary);
}
.fim-swatch-custom input[type="color"] {
  width: 30px; height: 30px; padding: 0; border: 0; border-radius: 50%;
  background: none; cursor: pointer; overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.16);
}
.fim-swatch-custom input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.fim-swatch-custom input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 50%; }
.fim-swatch-custom input[type="color"]::-moz-color-swatch { border: 0; border-radius: 50%; }
.fim-swatch-custom:has(input[type="radio"]:checked) input[type="color"] {
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.16), 0 0 0 2px var(--fim-card), 0 0 0 4px var(--fim-primary);
}
.fim-swatch-custom:has(input[type="radio"]:focus-visible) input[type="color"],
.fim-swatch-custom input[type="color"]:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.16), 0 0 0 3px var(--fim-bg), 0 0 0 5px var(--fim-primary);
}

/* ---------- 右侧预览列：顶部导出栏 + 点阵画布 + 托盘 ---------- */
.fim-stage-col {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  /* 按预览列自身宽度而不是窗口宽度决定何时收起 Copy 文字，避免嵌入不同宽度的页面时错位 */
  container-type: inline-size;
  container-name: fim-stage;
}

.fim-exportbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--fim-line);
  background: var(--fim-card); flex: none;
}
.fim-exportbar-left { display: flex; align-items: center; gap: 4px; flex: 1 1 auto; min-width: 0; }
.fim-exportbar-left .fim-btn { flex: none; }
/* 用块级单行容器承载信息，才能在空间不足时由浏览器原生在末尾截断并显示省略号 */
.fim-output {
  margin: 0 0 0 8px;
  font-size: 13px; line-height: 1.4; color: var(--fim-muted);
  flex: 0 1 auto; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fim-output b { font-weight: 500; color: var(--fim-text); }
.fim-sep {
  display: inline-block; width: 3px; height: 3px; border-radius: 50%;
  background: var(--fim-subtle); vertical-align: middle; margin: 0 8px;
}
.fim-exportbar-actions { display: flex; align-items: center; gap: 8px; flex: none; }

/* 预览列偏窄时先把 Copy 缩成和撤销/重做一样大小的纯图标按钮，优先保住信息行完整显示 */
@container fim-stage (max-width: 630px) {
  .fim-exportbar [data-action="copy"] {
    --h: 36px;
    width: var(--h);
    min-width: var(--h);
    padding: 0;
  }
  .fim-exportbar [data-action="copy"]::before {
    content: "";
    position: absolute;
    inset: -4px;
  }
  .fim-exportbar [data-action="copy"] span {
    display: none;
  }
}

/* ---------- 点阵舞台：空状态卡片、合并预览、裁剪、批量清单 ---------- */
.fim-stage {
  flex: 1; min-width: 0; min-height: 0; position: relative;
  background-color: var(--fim-sunken);
  background-image: radial-gradient(rgba(15, 23, 42, 0.11) 1px, transparent 1.3px);
  background-size: 20px 20px;
  overflow: hidden;
}
.fim-empty {
  width: 100%; height: 100%;
  display: grid; grid-template-columns: minmax(0, 1fr); place-items: center;
  padding: 20px 24px;
}
.fim-empty-inner { width: 100%; min-width: 0; }
.fim-drop {
  width: min(560px, 100%); margin: 0 auto; text-align: center;
  background: var(--fim-card);
  border: 1.5px dashed rgba(37, 99, 235, 0.45);
  border-radius: 16px; padding: 28px 28px 24px;
  box-shadow: var(--fim-shadow-1);
  transition: border-color 0.15s, background-color 0.15s, transform 0.15s;
}
.fim.is-dragover .fim-drop {
  border-color: var(--fim-primary); background: var(--fim-primary-soft); transform: scale(1.01);
}
.fim.is-dragover .fim-preview { outline: 2px solid var(--fim-primary); outline-offset: -4px; border-radius: var(--fim-radius); }
.fim-drop-icon {
  width: 56px; height: 56px; margin: 0 auto 14px;
  border-radius: 14px; background: var(--fim-primary-soft); color: var(--fim-primary);
  display: grid; place-items: center;
}
.fim-drop-title {
  margin: 0 0 8px; font-size: 26px; font-weight: 600;
  letter-spacing: -0.035em; line-height: 1.15;
}
.fim-drop-hint {
  color: var(--fim-muted); margin: 0 0 20px; font-size: 15px;
  display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap;
}
.fim-drop-paste { display: inline-flex; align-items: center; gap: 6px; }
.fim kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; padding: 0 6px;
  font: 500 12px/1 var(--fim-font-mono); font-variant-numeric: tabular-nums;
  color: var(--fim-text); background: var(--fim-card);
  border: 1px solid var(--fim-line-strong); border-bottom-width: 2px; border-radius: 5px;
}
.fim-drop-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.fim-private {
  font-size: 13px; margin: 16px 0 0; color: var(--fim-muted);
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.fim-private .fim-ic { color: var(--fim-accent); }

/* 空状态「从示例开始」三张卡片（照原型 .starters-wrap / .starters / .starter） */
.fim-starters-wrap { width: min(720px, 100%); margin: 24px auto 0; text-align: center; }
.fim-starters-heading {
  font: 500 13px/1 var(--fim-font-body);
  color: var(--fim-subtle);
  margin: 0 0 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.fim-starters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.fim-starter {
  display: flex; align-items: center; gap: 12px;
  min-height: 44px; min-width: 0; text-align: left;
  padding: 10px 12px 10px 10px;
  background: var(--fim-card);
  border: 1px solid var(--fim-line-strong);
  border-radius: var(--fim-radius);
  cursor: pointer; font: inherit; color: var(--fim-text);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.05s;
}
.fim-starter:hover:not(:disabled) { border-color: var(--fim-primary); box-shadow: var(--fim-shadow-1); }
.fim-starter:active:not(:disabled) { transform: translateY(1px); }
.fim-starter:disabled { opacity: 0.45; cursor: not-allowed; }
.fim-starter-thumb {
  position: relative;
  width: 64px; height: 48px; flex: none;
  border-radius: 6px; overflow: hidden;
  background: var(--fim-sunken);
  border: 1px solid var(--fim-line);
  display: grid; place-items: center;
}
.fim-starter-thumb svg { display: block; width: 100%; height: 100%; }
.fim-starter-thumb.has-photo svg { visibility: hidden; }
.fim-starter-photo {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover; display: block;
}
.fim-starter-text { min-width: 0; }
.fim-starter-text b { display: block; font-weight: 600; font-size: 14px; line-height: 1.3; color: var(--fim-text); }
.fim-starter-text span { display: block; font-size: 13px; color: var(--fim-muted); line-height: 1.3; }

.fim-preview {
  position: absolute; inset: 28px;
  display: flex; align-items: center; justify-content: center;
}
.fim-preview-canvas {
  display: block; max-width: 100%; max-height: 100%;
  box-shadow: var(--fim-shadow-2); cursor: pointer;
}
/* 所有排法都能在画布上拖图（As placed 是摆放，其余是换顺序），触屏上按住画布不滚动页面 */
.fim-preview-canvas { touch-action: none; }

/* 放大查看按钮：合并模式有图时浮在画布左上角 */
.fim-enlarge { display: none; }
.fim[data-state="ready"][data-mode="merge"]:not([data-cropping="true"]):not([data-pdf-preview="true"]) .fim-enlarge {
  display: grid; place-items: center; position: absolute; top: 8px; left: 8px; z-index: 4; --h: 36px;
  background: var(--fim-card); border: 1px solid var(--fim-line);
  border-radius: var(--fim-radius-sm); box-shadow: var(--fim-shadow-1);
}

/* 放大查看：全屏深色底，细长图上下滑、扁长条左右滑（尺寸由 computeViewerSize 算好写在 canvas 上） */
.fim-viewer {
  width: 100vw; height: 100dvh; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0; background: rgba(15, 23, 42, 0.94);
}
.fim-viewer::backdrop { background: rgba(15, 23, 42, 0.6); }
html:has(.fim-viewer[open]) { overflow: hidden; }
.fim-viewer-scroll {
  position: absolute; inset: 0; display: flex;
  overflow: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
/* margin:auto 居中，图比屏幕大时也能从头滚到尾（justify-content:center 会把开头裁掉） */
.fim-viewer-canvas { display: block; flex: none; margin: auto; }
.fim-viewer-canvas.is-transparent {
  background: repeating-conic-gradient(#e2e8f0 0% 25%, #fff 0% 50%) 0 0 / 16px 16px;
}
.fim-viewer-close {
  position: fixed; top: 12px; right: 12px; z-index: 1;
  background: rgba(15, 23, 42, 0.72); color: #fff; border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
}
.fim-preview-canvas:focus-visible { outline: 2px solid var(--fim-primary); outline-offset: 4px; }
.fim-preview-canvas.is-transparent {
  background: repeating-conic-gradient(#e2e8f0 0% 25%, #fff 0% 50%) 0 0 / 16px 16px;
}
.fim-pdf-preview {
  position: absolute; inset: 0;
  overflow-y: auto; overscroll-behavior: contain;
  padding: 24px 20px 56px;
  display: flex; flex-direction: column; align-items: center;
}
.fim-pdf-preview.is-single { justify-content: center; padding: 24px 24px 40px; }
.fim-pdf-pages {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-end;
  gap: 20px; width: 100%; max-width: 960px;
}
.fim-pdf-sheet {
  display: inline-flex; flex-direction: column; align-items: center; gap: 6px;
  min-width: 44px; min-height: 44px; padding: 0; border: 0;
  background: transparent; color: var(--fim-muted); font: inherit;
  cursor: pointer; flex: none;
}
.fim-pdf-paper {
  display: block; background: #ffffff;
  border: 1px solid var(--fim-line-strong); border-radius: 3px;
  box-shadow: var(--fim-shadow-2); overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.fim-pdf-sheet:hover .fim-pdf-paper { border-color: var(--fim-primary); }
.fim-pdf-sheet:focus-visible { outline: none; }
.fim-pdf-sheet:focus-visible .fim-pdf-paper {
  box-shadow: 0 0 0 3px var(--fim-bg), 0 0 0 5px var(--fim-primary);
}
.fim-pdf-sheet.is-selected .fim-pdf-paper {
  border-color: var(--fim-primary);
  box-shadow: 0 0 0 2px var(--fim-primary), var(--fim-shadow-2);
}
.fim-pdf-canvas { display: block; }
.fim-pdf-page-no { font-size: 11px; font-weight: 500; line-height: 1; color: var(--fim-muted); }
.fim-pdf-more {
  margin: 18px 0 0; padding: 6px 12px; border-radius: 999px;
  background: var(--fim-card); border: 1px solid var(--fim-line-strong);
  color: var(--fim-muted); font-size: 12px; font-weight: 500; line-height: 1.2;
  box-shadow: var(--fim-shadow-1);
}
.fim-crop-stage {
  position: absolute; inset: 20px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.fim-crop-canvas { display: block; touch-action: none; }

/* ---------- 状态提示（照原型 .toast 样式，放在预览区底部居中、不用 position: fixed） ---------- */
.fim-status {
  position: absolute; left: 50%; bottom: 16px; z-index: 5;
  transform: translateX(-50%);
  margin: 0; max-width: calc(100% - 32px); width: max-content;
  padding: 10px 16px; border-radius: 999px;
  background: var(--fim-text); color: #fff;
  font-size: 13px; line-height: 1.4;
  box-shadow: 0 12px 24px -8px rgba(15, 23, 42, 0.4);
}
.fim-status:empty { display: none; }

/* ---------- Batch 清单视图（照原型 .batch-list 卡片样式） ---------- */
.fim[data-mode="batch"][data-state="ready"] .fim-stage {
  display: flex; flex-direction: column;
}
.fim-batch-view {
  position: static; flex: 1; min-height: 0;
  padding: 28px 20px; overflow-y: auto; overscroll-behavior: contain;
}
.fim[data-mode="batch"][data-state="ready"] .fim-status {
  position: static; transform: none; align-self: center; flex: none;
  margin: 0 16px 12px;
}
.fim-batch-card {
  width: min(560px, 100%); margin: 0 auto;
  background: var(--fim-card);
  border: 1px solid var(--fim-line); border-radius: var(--fim-radius);
  box-shadow: var(--fim-shadow-1); overflow: hidden;
}
.fim-batch-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--fim-line);
  font-size: 13px; color: var(--fim-muted);
}
.fim-batch-head b { font-size: 15px; font-weight: 600; color: var(--fim-text); }
.fim-batch-list { margin: 0; padding: 0; list-style: none; }
.fim-batch-row {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 18px; border-bottom: 1px solid var(--fim-line);
}
.fim-batch-row:last-child { border-bottom: 0; }
.fim-batch-thumb {
  flex: none; display: block;
  width: 56px; height: 42px; padding: 0; overflow: hidden;
  border: 0; border-radius: 6px;
  background: var(--fim-sunken);
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.1);
  cursor: pointer;
}
.fim-batch-thumb canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.fim-batch-thumb:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--fim-bg), 0 0 0 5px var(--fim-primary); }
.fim-batch-thumb:disabled, .fim-remove:disabled, .fim-add:disabled { opacity: 0.45; cursor: not-allowed; }
.fim.is-busy .fim-thumb { cursor: not-allowed; }
.fim-batch-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.fim-batch-name {
  margin: 0; font-weight: 600; font-size: 14px; line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fim-batch-dims {
  margin: 0; font-family: var(--fim-font-mono); font-size: 12px; line-height: 1.3;
  color: var(--fim-muted); font-variant-numeric: tabular-nums;
}
.fim-batch-result { margin: 0; font-size: 12px; font-weight: 500; color: var(--fim-muted); }
.fim-batch-result.is-ok { color: var(--fim-accent); }
.fim-batch-result.is-error { color: #dc2626; }
.fim-batch-tag {
  flex: none; font-size: 11px; font-weight: 500; line-height: 1;
  color: var(--fim-accent); background: var(--fim-accent-soft);
  padding: 5px 7px; border-radius: 4px; white-space: nowrap;
}
.fim-batch-edit { flex: none; min-width: 48px; padding: 0 10px; font-size: 13px; }

/* ---------- 胶片托盘：76×56 缩略图、左上角等宽帧号、虚线 +、右侧计数 ---------- */
.fim-tray {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-top: 1px solid var(--fim-line);
  background: var(--fim-card);
  overflow-x: auto; flex: none;
}
.fim-frames {
  display: flex; align-items: center; gap: 10px;
  margin: 0; padding: 0; list-style: none; flex: 0 0 auto;
}
.fim-frame { position: relative; flex: none; }
.fim-thumb {
  position: relative; display: block;
  width: 76px; height: 56px; padding: 0; border: 0;
  border-radius: var(--fim-radius-sm); overflow: hidden;
  background: var(--fim-sunken);
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.12);
  cursor: grab; touch-action: none;
  transition: box-shadow 0.15s;
}
.fim-thumb canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.fim-thumb:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--fim-bg), 0 0 0 5px var(--fim-primary);
}
.fim-frame.is-selected .fim-thumb {
  box-shadow: 0 0 0 2px var(--fim-card), 0 0 0 4px var(--fim-primary);
}
.fim-frame-no {
  position: absolute; left: 4px; top: 4px;
  font-family: var(--fim-font-mono); font-size: 10px; font-weight: 500; line-height: 1;
  font-variant-numeric: tabular-nums;
  background: rgba(15, 23, 42, 0.78); color: #fff;
  padding: 3px 4px; border-radius: 4px; pointer-events: none;
}
.fim-frame.is-edited .fim-frame-no::after { content: " ·"; color: #93c5fd; }
/* 视觉上是 22×22 圆钮居于缩略图右上角，按钮本身扩到 44×44 满足触控点击区域要求 */
.fim-remove {
  position: absolute; top: -7px; right: -7px;
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; padding: 0; border: 0; background: transparent;
  color: var(--fim-text); cursor: pointer; opacity: 0;
  transition: opacity 0.15s;
}
.fim-remove span {
  display: flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid var(--fim-line-strong); background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--fim-shadow-1);
}
.fim-remove:hover span { background: var(--fim-text); border-color: var(--fim-text); color: #fff; }
.fim-frame:hover .fim-remove, .fim-remove:focus-visible { opacity: 1; }
.fim-remove:focus-visible { outline: none; }
.fim-remove:focus-visible span { box-shadow: 0 0 0 2px var(--fim-card), 0 0 0 4px var(--fim-primary); }
@media (hover: none) { .fim-remove { opacity: 1; } }
.fim-frame.is-dragging { z-index: 2; opacity: 0.85; }
.fim-frame.is-dragging .fim-thumb { cursor: grabbing; box-shadow: var(--fim-shadow-2); }
.fim-frame.is-drop-before::before,
.fim-frame.is-drop-after::after {
  content: ""; position: absolute; top: 0; height: 56px; width: 3px;
  border-radius: 2px; background: var(--fim-primary);
}
.fim-frame.is-drop-before::before { left: -7px; }
.fim-frame.is-drop-after::after { right: -7px; }

.fim-add {
  flex: none; width: 56px; height: 56px;
  border: 1.5px dashed var(--fim-line-strong); border-radius: var(--fim-radius-sm);
  display: grid; place-items: center;
  background: transparent; color: var(--fim-muted); cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background-color 0.15s;
}
.fim-add:hover:not(:disabled) { color: var(--fim-primary); border-color: var(--fim-primary); background: var(--fim-primary-soft); }
.fim-tray-count {
  margin-left: auto; padding-left: 8px; flex: none;
  font-size: 13px; color: var(--fim-muted); white-space: nowrap;
}

/* ---------- 面板内单图编辑视图（照原型 s1-edit / s1-crop） ---------- */
.fim-edit-panel { display: block; }
.fim-edit-head {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 16px 8px 8px; border-bottom: 1px solid var(--fim-line);
}
.fim-edit-heading {
  flex: 1; min-width: 0; margin: 0;
  font-size: 15px; font-weight: 600; line-height: 1.25; outline: none;
}
.fim-edit-heading:focus-visible { box-shadow: 0 0 0 2px var(--fim-primary); border-radius: 4px; }
.fim-link-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 44px; padding: 0 6px; border: 0; border-radius: 6px;
  background: transparent; color: var(--fim-primary);
  font: 500 14px/1 var(--fim-font-body); cursor: pointer; white-space: nowrap;
}
.fim-link-btn:hover:not(:disabled) { background: var(--fim-primary-soft); }
.fim-link-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.fim-link-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--fim-bg), 0 0 0 5px var(--fim-primary); }
.fim[data-cropping="true"] .fim-edit-reset { display: none; }

.fim-field-label {
  margin: 0 0 12px;
  font-size: 12px; font-weight: 500; line-height: 1;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--fim-subtle);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.fim-field-label.fim-sub { margin-top: 18px; }
.fim-edit-size { font-size: 11px; text-transform: none; letter-spacing: 0; color: var(--fim-muted); }

.fim-edit-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.fim-edit-grid button {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 5px; min-height: 60px; padding: 6px 2px;
  border: 1px solid var(--fim-line-strong); border-radius: var(--fim-radius-sm);
  background: var(--fim-card); color: var(--fim-text);
  font: 500 11.5px/1.15 var(--fim-font-body); text-align: center; cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background-color 0.15s, transform 0.05s;
}
.fim-edit-grid button:hover:not(:disabled) { border-color: var(--fim-primary); color: var(--fim-primary); }
.fim-edit-grid button:active:not(:disabled) { transform: translateY(1px); }
.fim-edit-grid button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--fim-bg), 0 0 0 5px var(--fim-primary); }
.fim-edit-grid button:disabled { opacity: 0.45; cursor: not-allowed; }

.fim-split-opts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.fim-split-opts button {
  position: relative; height: 36px; padding: 0 2px;
  border: 1px solid var(--fim-line-strong); border-radius: var(--fim-radius-sm);
  background: var(--fim-card); color: var(--fim-muted);
  font: 500 12px/1 var(--fim-font-body); cursor: pointer; white-space: nowrap;
  transition: border-color 0.15s, color 0.15s, background-color 0.15s, transform 0.05s;
}
.fim-split-opts button::before { content: ""; position: absolute; inset: -4px 0; }
.fim-split-opts button:hover:not(:disabled) { border-color: var(--fim-primary); color: var(--fim-primary); }
.fim-split-opts button:active:not(:disabled) { transform: translateY(1px); }
.fim-split-opts button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--fim-bg), 0 0 0 5px var(--fim-primary); }
.fim-split-opts button:disabled { opacity: 0.45; cursor: not-allowed; }

.fim-ratio-grid { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.fim-ratio-grid label { position: relative; display: block; }
.fim-ratio-grid input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.fim-ratio-grid span {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; height: 36px; padding: 0 12px;
  border: 1px solid var(--fim-line-strong); border-radius: var(--fim-radius-sm);
  background: var(--fim-card); color: var(--fim-muted);
  cursor: pointer; font-size: 13px; font-weight: 500; line-height: 1;
  transition: border-color 0.15s, background-color 0.15s, color 0.15s;
}
.fim-ratio-grid span::before { content: ""; position: absolute; inset: -4px 0; }
.fim-ratio-grid input:checked + span {
  border: 2px solid var(--fim-primary); padding: 0 11px;
  background: var(--fim-primary-soft); color: var(--fim-text); font-weight: 600;
}
.fim-ratio-grid input:focus-visible + span {
  outline: none; box-shadow: 0 0 0 3px var(--fim-bg), 0 0 0 5px var(--fim-primary);
}
.fim-edit-crop-actions { display: flex; justify-content: flex-end; gap: 8px; }

.fim-drawer-head,
.fim-stage-tools,
.fim-mobile-dock,
.fim-tabs,
.fim-float-hist,
.fim-tray-mobile-btn,
.fim-mobile-bar { display: none; }

/* ---------- 手机布局（900 px 及以下）：画布优先（画布 + 托盘 + 两行底部固定栏；设置底部滑出；选中时画布两侧浮出编辑按钮） ---------- */
@media (max-width: 900px) {
  .fim {
    --fim-tabs-h: 49px;
    --fim-bar-h: 67px;
    --fim-dock-h: calc(var(--fim-tabs-h) + var(--fim-bar-h));
    --fim-drawer-h: clamp(180px, 46svh, 400px);
    --fim-crop-drawer-h: clamp(236px, 36svh, 280px);
    flex-direction: column;
    height: auto; min-height: 0;
    overflow: visible;
  }
  .fim[data-state="ready"] { padding-bottom: calc(var(--fim-dock-h) + env(safe-area-inset-bottom)); }
  .fim[data-state="ready"][data-mode="batch"] { padding-bottom: calc(var(--fim-bar-h) + env(safe-area-inset-bottom)); }
  .fim[data-cropping="true"] { padding-bottom: calc(var(--fim-crop-drawer-h) + env(safe-area-inset-bottom)); }

  /* 空状态：工具栏变横排放在拖放卡片上方（手机没有 Ctrl+V，需保留粘贴入口）；加图后收起（入口移进托盘） */
  .fim-rail {
    flex-direction: row; justify-content: center;
    width: auto; border-right: 0; border-bottom: 1px solid var(--fim-line);
    padding: 4px 0;
  }
  .fim-rail-sep { width: 1px; height: 24px; margin: 0 6px; }
  .fim[data-state="empty"] .fim-rail { display: flex; }
  .fim[data-state="ready"] .fim-rail { display: none; }

  .fim-empty { padding: 20px 16px 36px; place-items: start center; }
  .fim-drop { padding: 24px 18px 20px; }
  .fim-drop-icon { width: 48px; height: 48px; margin-bottom: 12px; }
  .fim-drop-title { font-size: 22px; }
  .fim-drop-hint { font-size: 14px; margin-bottom: 18px; }
  .fim-drop-paste { display: none; }
  .fim-drop-actions .fim-btn { width: 100%; }
  .fim-starters-wrap { margin-top: 18px; }
  .fim-starters {
    display: flex; overflow-x: auto; gap: 10px; padding: 0 0 4px;
    scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }
  .fim-starter { flex: 0 0 78%; scroll-snap-align: start; }

  /* 加图后纵向顺序：画布 -> 托盘（Batch 模式面板照旧排在下面，合并模式面板收进底部抽屉） */
  .fim-work { display: flex; flex-direction: column; }
  .fim-stage-col { order: 1; }
  .fim-panel {
    order: 2; border-right: 0; border-top: 1px solid var(--fim-line);
    overflow: visible;
  }
  .fim[data-mode="merge"]:not([data-cropping="true"]) .fim-panel { display: none; }
  .fim-exportbar { display: none; }

  /* 画布优先：第一屏留给画布 + 托盘 + 两行底部固定栏（约 100svh - 页头 - 192px，最低 300px 最高 680px） */
  /* flex: none——桌面版的 flex: 1 1 0 会让 height 失效、只剩 min-height */
  .fim-stage {
    flex: none;
    height: clamp(300px, calc(100svh - var(--header-h, 56px) - 192px), 680px);
    min-height: 300px;
    scroll-margin-top: var(--header-h, 0px);
  }
  .fim[data-state="empty"] .fim-stage { height: auto; min-height: 0; }
  .fim[data-state="ready"][data-mode="merge"][data-mobile-drawer="open"]:not([data-cropping="true"]) .fim-stage {
    height: max(160px, calc(100svh - var(--header-h, 56px) - var(--fim-dock-h) - var(--fim-drawer-h)));
    min-height: 160px;
  }
  .fim-preview { inset: 14px; }
  .fim-pdf-preview {
    padding: 12px 14px;
    flex-direction: row; align-items: center;
    overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }
  .fim-pdf-preview.is-single { justify-content: center; padding: 12px 14px; }
  .fim-pdf-pages {
    flex-wrap: nowrap; width: max-content; max-width: none;
    justify-content: flex-start; align-items: flex-end; gap: 12px;
    margin: 0 auto;
  }
  .fim-pdf-more { margin: 0 0 0 12px; flex: none; align-self: center; white-space: nowrap; }
  .fim-crop-stage { inset: 10px; }
  .fim-status { bottom: 10px; max-width: calc(100% - 24px); font-size: 12.5px; padding: 8px 14px; }

  /* 悬浮撤销 / 重做（预览区右上角）与放大按钮（左上角） */
  .fim[data-state="ready"]:not([data-cropping="true"]) .fim-float-hist {
    display: flex; position: absolute; top: 8px; right: 8px; z-index: 4;
    background: var(--fim-card); border: 1px solid var(--fim-line);
    border-radius: var(--fim-radius-sm); box-shadow: var(--fim-shadow-1);
  }
  .fim-float-hist .fim-btn { --h: 44px; }
  .fim[data-state="ready"][data-mode="merge"]:not([data-cropping="true"]):not([data-pdf-preview="true"]) .fim-enlarge { --h: 44px; }

  /* 选中单图时画布左右两侧浮出的编辑工具列（置于放大与撤销按钮下方、垂直居中，不遮挡中间画布） */
  .fim[data-state="ready"][data-mode="merge"][data-panel-view="edit"]:not([data-cropping="true"]):not([data-mobile-drawer="open"]) .fim-stage-tools-left,
  .fim[data-state="ready"][data-mode="merge"][data-panel-view="edit"]:not([data-cropping="true"]):not([data-mobile-drawer="open"]) .fim-stage-tools-right,
  .fim[data-state="ready"][data-mode="merge"][data-text-selected="true"]:not([data-cropping="true"]):not([data-mobile-drawer="open"]) .fim-stage-text-tools {
    display: flex;
  }
  .fim-stage-tools {
    position: absolute;
    top: calc(50% + 18px);
    transform: translateY(-50%);
    z-index: 4;
    flex-direction: column;
    gap: 2px;
    padding: 3px;
    background: var(--fim-card);
    border: 1px solid var(--fim-line-strong);
    border-radius: var(--fim-radius);
    box-shadow: var(--fim-shadow-2);
  }
  .fim-stage-tools-left { left: 6px; }
  .fim-stage-tools-right,
  .fim-stage-text-tools { right: 6px; }
  .fim-stage-tools:has(.fim-split-popover:not([hidden])) { z-index: 7; }
  .fim-stage-tools .fim-btn { --h: 44px; color: var(--fim-text); border-radius: var(--fim-radius-sm); }
  .fim-stage-tools .fim-btn[aria-expanded="true"] {
    background: var(--fim-primary-soft);
    color: var(--fim-primary);
  }
  .fim-split-wrap { position: relative; }
  .fim-split-popover {
    position: absolute;
    right: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    z-index: 6;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    width: max-content;
    min-width: 176px;
    padding: 8px;
    background: var(--fim-card);
    border: 1px solid var(--fim-line-strong);
    border-radius: var(--fim-radius);
    box-shadow: var(--fim-shadow-2);
  }
  .fim-split-popover button {
    min-height: 44px; min-width: 76px; padding: 0 10px;
    border: 1px solid var(--fim-line-strong);
    border-radius: var(--fim-radius-sm);
    background: var(--fim-card); color: var(--fim-text);
    font: 500 13px/1 var(--fim-font-body);
    cursor: pointer; white-space: nowrap;
    transition: border-color 0.15s, color 0.15s, background-color 0.15s;
  }
  .fim-split-popover button:hover:not(:disabled) {
    border-color: var(--fim-primary); color: var(--fim-primary); background: var(--fim-primary-soft);
  }
  .fim-split-popover button:focus-visible {
    outline: none; box-shadow: 0 0 0 3px var(--fim-bg), 0 0 0 5px var(--fim-primary);
  }
  .fim-split-popover button:disabled { opacity: 0.45; cursor: not-allowed; }

  /* 托盘：手机把粘贴与清空一起放进托盘 */
  .fim-tray { padding: 8px 16px; }
  .fim-tray-mobile-btn { display: grid; }

  /* 合并设置底部抽屉：点底部入口滑出在两行底栏上方，内部可滚；Merge/Batch 切换放进 Export 组最上面 */
  .fim[data-state="ready"][data-mode="merge"][data-in-view="true"][data-mobile-drawer="open"]:not([data-cropping="true"]) .fim-panel {
    display: block;
    position: fixed;
    left: 0; right: 0;
    bottom: calc(var(--fim-dock-h) + env(safe-area-inset-bottom));
    z-index: 54;
    height: var(--fim-drawer-h);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    border-top: 1px solid var(--fim-line-strong);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -10px 30px -10px rgba(15, 23, 42, 0.22);
  }
  .fim[data-mode="merge"][data-mobile-drawer="open"]:not([data-cropping="true"]) .fim-drawer-head {
    display: block;
    position: sticky; top: 0; z-index: 2; flex: none;
    background: var(--fim-card);
    border-bottom: 1px solid var(--fim-line);
    padding: 8px 12px 6px 16px;
    touch-action: none;
  }
  .fim-drawer-handle {
    display: block;
    width: 36px; height: 4px;
    margin: 0 auto 6px;
    border-radius: 999px;
    background: var(--fim-line-strong);
  }
  .fim-drawer-bar {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    min-height: 36px;
  }
  .fim-drawer-title {
    margin: 0;
    font-size: 15px; font-weight: 600; line-height: 1.25;
    color: var(--fim-text);
  }

  .fim-mode-row { padding: 10px 16px; }
  .fim[data-mode="merge"] .fim-mode-row { display: none; }
  .fim[data-mode="merge"][data-mobile-drawer="open"][data-mobile-tab="export"]:not([data-cropping="true"]) .fim-mode-row {
    display: block;
  }

  .fim-tab-group { display: none; border-bottom: 0; min-height: 0; padding: 12px 16px 18px; }
  .fim-tab-group.is-active { display: block; }
  .fim-tab-group > legend,
  .fim-tab-group > .fim-sub-first > legend { display: none; }
  .fim-sub-group { margin-top: 10px; }
  .fim-sub-group legend { margin-bottom: 6px; }
  .fim-layout-card { min-height: 58px; }

  /* Batch 模式里的单图编辑面板照旧排在下方，6 个编辑按钮排一行只显示图标，Split 四个按钮在下一行 */
  .fim-edit-main { padding: 12px 16px; }
  .fim-edit-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .fim-edit-grid button { min-height: 48px; padding: 0; }
  .fim-edit-grid span { display: none; }
  .fim-edit-main .fim-field-label.fim-sub { margin-top: 12px; }
  .fim-split-opts button { height: 44px; }

  /* 手机裁剪模式：收起托盘、两列按钮和两行底栏，用底部抽屉显示裁剪比率与 Cancel / Apply */
  .fim[data-cropping="true"] .fim-tray { display: none; }
  .fim[data-cropping="true"] .fim-stage {
    height: max(180px, calc(100svh - var(--header-h, 56px) - var(--fim-crop-drawer-h)));
    min-height: 180px;
  }
  .fim[data-cropping="true"] .fim-panel {
    display: block;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 56;
    height: calc(var(--fim-crop-drawer-h) + env(safe-area-inset-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    border-top: 1px solid var(--fim-line-strong);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -10px 30px -10px rgba(15, 23, 42, 0.22);
  }
  .fim[data-cropping="true"] .fim-panel::before {
    content: "";
    display: block;
    width: 36px; height: 4px; flex: none;
    margin: 8px auto 2px;
    border-radius: 999px;
    background: var(--fim-line-strong);
  }
  .fim[data-cropping="true"] .fim-drawer-head { display: none; }
  .fim[data-cropping="true"] .fim-edit-head { padding: 4px 16px 6px 8px; }
  .fim[data-cropping="true"] .fim-edit-crop-controls { padding: 10px 16px 0; }
  /* 矮屏或日韩文案换行时抽屉要滚动，Cancel / Apply 始终贴在抽屉底部可点 */
  .fim[data-cropping="true"] .fim-edit-crop-actions {
    position: sticky;
    bottom: 0;
    padding: 8px 0 calc(12px + env(safe-area-inset-bottom));
    background: var(--fim-card);
  }
  .fim-ratio-grid { margin-bottom: 12px; }
  .fim-ratio-grid span { height: 44px; }

  /* 手机批量模式：撤销/重做排在清单上方独立一行，滚清单也不会压住任何一行的 Edit 按钮 */
  .fim[data-mode="batch"][data-state="ready"]:not([data-cropping="true"]) .fim-stage {
    height: auto; max-height: 46svh; min-height: 180px;
  }
  .fim[data-mode="batch"][data-state="ready"]:not([data-cropping="true"]) .fim-float-hist {
    position: static; order: -1; align-self: flex-end; flex: none;
    margin: 8px 16px 0;
  }
  .fim-batch-view { padding: 8px 16px 12px; }
  .fim-batch-head { display: none; }
  .fim-batch-row { padding: 8px 12px; gap: 10px; }
  .fim-batch-tag { display: none; }
  .fim-batch-thumb { width: 48px; height: 44px; }
  .fim-batch-edit { --h: 44px; }

  /* 固定在屏幕底部的两行栏（上行 5 个设置入口 + 下行尺寸与导出按钮；工具滚出屏幕后由 IntersectionObserver 隐藏） */
  .fim[data-state="ready"][data-in-view="true"]:not([data-cropping="true"]) .fim-mobile-dock {
    display: flex;
  }
  .fim-mobile-dock {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 55;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--fim-line);
    box-shadow: 0 -8px 24px -12px rgba(15, 23, 42, 0.18);
  }
  .fim-tabs {
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
    border-bottom: 1px solid var(--fim-line);
    background: transparent;
  }
  .fim[data-mode="batch"] .fim-tabs { display: none; }
  .fim-tabs button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    height: var(--fim-tabs-h); min-height: 44px; min-width: 0; padding: 4px 2px;
    border: 0; border-top: 2px solid transparent;
    background: none; color: var(--fim-muted);
    font: 500 11px/1.1 var(--fim-font-body);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background-color 0.15s;
  }
  .fim-tabs button span {
    max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .fim-tabs button[aria-selected="true"] {
    color: var(--fim-primary); font-weight: 600;
    border-top-color: var(--fim-primary);
    background: var(--fim-primary-soft);
  }
  .fim-tabs button:focus-visible {
    outline: none; box-shadow: inset 0 0 0 2px var(--fim-primary);
  }
  .fim-mobile-bar {
    display: flex;
    gap: 10px; align-items: center;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: transparent;
  }
  .fim-mobile-meta {
    font-size: 12px; font-weight: 500; line-height: 1.35;
    color: var(--fim-muted); margin-right: auto; min-width: 0;
  }
  .fim-mobile-meta b {
    display: block; font-weight: 500; color: var(--fim-text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .fim-mobile-meta span {
    display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .fim-mobile-bar .fim-btn { --h: 46px; }
}

@media (prefers-reduced-motion: reduce) {
  .fim *, .fim *::before, .fim *::after { transition: none !important; scroll-behavior: auto !important; }
}
