/* ── Domine 本地字体 ── */
@font-face {
  font-family: 'Domine';
  src: url('../fonts/Domine-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Domine';
  src: url('../fonts/Domine-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
/* ── 方正可变兰亭黑 GBK（子集化，仅含英文+数字+标点） ── */
@font-face {
  font-family: 'FZLanTingHei';
  src: url('../fonts/FZLanTingHei-subset.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

* { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
html, body {
  height: 100%; width: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', sans-serif;
  overflow: hidden;
  background: #1a1a1a;
}
/* 桌面端：居中显示窄屏，模拟手机比例 */
body {
  display: flex; align-items: center; justify-content: center;
}
/* 主容器 — 手机全屏 / 桌面居中窄屏 */
.app-container {
  width: 100%; height: 100%;
  max-width: 430px;
  position: relative;
  overflow: hidden;
  background: #fff;
}
/* 桌面端给容器加圆角和阴影 */
@media (min-width: 500px) {
  body { background: #0a0a0a; }
  .app-container {
    max-height: 932px;
    border-radius: 20px;
    box-shadow: 0 20px 80px rgba(0,0,0,0.6);
  }
}
/* 仅在非输入容器上禁止选中 */
.app-container, .shelf-card, .nav-back-pill, .edit-tool, .tp-variant-card,
.te-font-card, .te-color-dot, .te-align-btn, .te-preset-card, .te-style-btn,
#bookContainer, #pageIndicator {
  user-select: none; -webkit-user-select: none;
}
/* 确保所有输入类元素可以正常输入 */
input[type="text"], input[type="color"], input[type="range"],
input:not([type]), textarea {
  user-select: text !important; -webkit-user-select: text !important;
}

/* 状态栏 */
.status-bar {
  position: absolute; top: 0; left: 0; right: 0; height: 52px;
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: 0 24px 8px; z-index: 200; pointer-events: none;
}
.status-bar.dark .sb-time, .status-bar.dark .sb-icons { color: #000; }
.sb-time { font-size: 15px; font-weight: 600; letter-spacing: -0.3px; }
.sb-icons { display: flex; align-items: center; gap: 5px; }
.sb-icons svg { width: 16px; height: 12px; }

/* 顶部导航 (v=h: z-index 提到 800，高于所有浮层；返回按钮永远可点) */
.top-nav {
  position: absolute; top: 56px; left: 0; right: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px; z-index: 800;
  pointer-events: none; /* 容器不拦截事件，只让里面的按钮接收点击，避免遮挡浮层 */
}
.top-nav > * { pointer-events: auto; }
.nav-back-pill {
  width: 52px; height: 44px; min-width: 52px; min-height: 44px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 2px 16px rgba(0,0,0,0.10), 0 0 0 0.5px rgba(0,0,0,0.05);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: transform 0.15s, background 0.15s;
}
.nav-back-pill:active { transform: scale(0.92); background: #f5f5f5; }
.nav-back-pill svg { width: 18px; height: 18px; stroke: #1a1a1a; stroke-width: 2.2; fill: none; }

/* ★ v=am8: 撤销/重做上移到顶栏，紧贴返回键右边的小药丸 */
.edit-history-group {
  height: 44px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 2px 16px rgba(0,0,0,0.10), 0 0 0 0.5px rgba(0,0,0,0.05);
  display: flex; align-items: center;
  padding: 0 6px; gap: 2px;
  flex-shrink: 0;
}
.edit-history-group > * { pointer-events: auto; }
.history-btn {
  width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.history-btn:active { transform: scale(0.88); background: #f5f5f5; }
.history-btn svg {
  width: 20px; height: 20px;
}
.history-btn svg path { stroke: #1a1a1a; }
.history-btn.disabled {
  pointer-events: none;
  opacity: 0.35;
}
.history-btn.disabled svg path { stroke: #9a9a9a; }
.nav-toolbar-pill {
  flex: none; margin-left: auto;
  height: 44px; border-radius: 14px;
  background: #fff;
  box-shadow: 0 2px 16px rgba(0,0,0,0.10), 0 0 0 0.5px rgba(0,0,0,0.05);
  display: flex; align-items: center;
  padding: 0 8px; gap: 2px;
}
.nav-tool-icon {
  width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background 0.15s;
  /* iOS Safari 稳：禁双击缩放 / 禁高亮 / 禁选中 */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
}
.nav-tool-icon:active { background: rgba(0,0,0,0.06); }
/* SVG 及内部 circle/path 全部穿透，确保 click 命中的永远是 .nav-tool-icon 本身 */
.nav-tool-icon svg { width: 18px; height: 18px; stroke: #2a2a2a; stroke-width: 1.7; fill: none; pointer-events: none; }
.nav-tool-icon svg * { pointer-events: none; }
.nav-divider { width: 1px; height: 20px; background: #e5e5e5; margin: 0 2px; }

/* 更多下拉菜单 */
.more-menu-wrap { position: relative; }
.more-menu {
  position: absolute; top: 42px; right: 0;
  background: #fff; border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.14), 0 0 0 0.5px rgba(0,0,0,0.06);
  min-width: 140px; padding: 6px 0;
  opacity: 0; transform: scale(0.9) translateY(-4px); transform-origin: top right;
  pointer-events: none; transition: opacity 0.18s, transform 0.18s;
  z-index: 1500;
}
.more-menu.mm-open { opacity: 1; transform: scale(1) translateY(0); pointer-events: auto; }
.more-menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; font-size: 13px; color: #1a1a1a;
  cursor: pointer; transition: background 0.12s; white-space: nowrap;
  /* 触屏稳定：禁止 300ms 延迟、禁止双指缩放、禁止高亮 */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
}
.more-menu-item:active { background: #f5f5f5; }
/* 点中 SVG 子元素时事件穿透到父 menu-item，避免命中 svg 不响应 */
.more-menu-item svg { width: 16px; height: 16px; stroke: #555; stroke-width: 1.8; fill: none; flex-shrink: 0; pointer-events: none; }

/* ════════════════════════════════════════
   状态1：书架
════════════════════════════════════════ */
#shelfView {
  position: absolute; inset: 0;
  background: #fff; overflow: hidden;
}
#shelfAppName {
  position: absolute; top: 56px; left: 20px;
  height: 44px; display: flex; align-items: center;
  font-size: 30px; font-weight: 800; color: #0d0d0d;
  letter-spacing: -0.8px; z-index: 300; pointer-events: none;
}
/* 首页右上角按钮组 */
.shelf-top-actions {
  position: absolute; top: 60px; right: 16px;
  display: flex; align-items: center; gap: 8px; z-index: 300;
}
.shelf-action-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(0,0,0,0.06);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 0.2s;
  border: none; outline: none;
}
.shelf-action-btn:hover { background: rgba(0,0,0,0.10); }
.shelf-action-btn:active { transform: scale(0.9); background: rgba(0,0,0,0.14); }
.shelf-action-btn svg { width: 16px; height: 16px; }
/* 新建按钮特殊样式 */
.shelf-action-btn.btn-create {
  background: #1a1a1a; width: 40px; height: 40px;
}
.shelf-action-btn.btn-create svg { stroke: #fff; }
.shelf-action-btn.btn-create:hover { background: #333; }
.shelf-action-btn.btn-create:active { background: #555; }

/* 首页右上角"更多"圆形小按钮 — 兼容旧 id */
#shelfMoreBtn {
  position: absolute; top: 62px; right: 20px;
  width: 32px; height: 32px; border-radius: 50%;
  background: rgba(0,0,0,0.06);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; z-index: 300;
  transition: background 0.15s;
  display: none; /* 用新按钮组替代 */
}
#shelfMoreBtn:active { background: rgba(0,0,0,0.13); }
#shelfMoreBtn svg { width: 16px; height: 16px; }

/* 删除确认弹窗 */
.confirm-overlay {
  position: absolute; inset: 0; z-index: 600;
  background: rgba(0,0,0,0.45);
  display: none; align-items: center; justify-content: center;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.confirm-overlay.co-open { display: flex; }
.confirm-panel {
  background: #fff; border-radius: 20px;
  padding: 28px 24px 20px; width: 280px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: confirmIn 0.25s ease;
}
@keyframes confirmIn { from { transform: scale(0.85); opacity: 0; } }
.confirm-panel h3 { font-size: 17px; font-weight: 700; color: #1a1a1a; margin-bottom: 8px; }
.confirm-panel p { font-size: 13px; color: #888; margin-bottom: 20px; line-height: 1.5; }
.confirm-btns { display: flex; gap: 10px; }
.confirm-btn {
  flex: 1; height: 44px; border: none; border-radius: 12px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}
.confirm-btn:active { transform: scale(0.96); }
.confirm-btn.cb-cancel { background: #f0f0f0; color: #666; }
.confirm-btn.cb-danger { background: #ff4444; color: #fff; }

/* 新建 Zine 色盘弹窗 */
.create-zine-overlay {
  position: absolute; inset: 0; z-index: 600;
  background: rgba(0,0,0,0.45);
  display: none; align-items: center; justify-content: center;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.create-zine-overlay.czo-open { display: flex; }
.create-zine-panel {
  background: #fff; border-radius: 24px;
  padding: 28px 24px 24px; width: 300px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.3);
  animation: confirmIn 0.25s ease;
}
.create-zine-panel h3 { font-size: 18px; font-weight: 700; color: #1a1a1a; margin-bottom: 4px; letter-spacing: -0.3px; }
.create-zine-panel .czp-sub { font-size: 12px; color: #aaa; margin-bottom: 18px; }
.czp-input-group { margin-bottom: 16px; }
.czp-input-group label { font-size: 11px; color: #999; display: block; margin-bottom: 6px; letter-spacing: 0.3px; text-transform: uppercase; }
.czp-input {
  width: 100%; height: 44px; border: 1.5px solid #e5e5e5; border-radius: 12px;
  padding: 0 14px; font-size: 15px; color: #1a1a1a; outline: none;
  font-family: inherit; transition: border-color 0.2s;
  user-select: text; -webkit-user-select: text;
}
.czp-input:focus { border-color: #1a1a1a; }
.czp-colors { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.czp-color-dot {
  width: 36px; height: 36px; border-radius: 10px;
  cursor: pointer; border: 1.5px solid rgba(0,0,0,0.07);
  transition: transform 0.12s;
  position: relative;
}
.czp-color-dot:active { transform: scale(0.88); }
.czp-color-dot.czp-selected::after {
  content: '✓'; position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: rgba(255,255,255,0.8);
}
.czp-btns { display: flex; gap: 10px; }
.czp-btn {
  flex: 1; height: 48px; border: none; border-radius: 14px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: transform 0.15s;
}
.czp-btn:active { transform: scale(0.96); }
.czp-btn.czp-cancel { background: #f0f0f0; color: #666; }
.czp-btn.czp-create { background: #1a1a1a; color: #fff; }

/* 背景选择器浮层 */
#bgPickerOverlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0); z-index: 490; display: none;
}
#bgPicker {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: #fff; border-radius: 20px 20px 0 0;
  padding: 12px 0 0; z-index: 500;
  transform: translateY(100%);
  transition: transform 0.36s cubic-bezier(0.25,0.46,0.45,0.94);
  box-shadow: 0 -4px 32px rgba(0,0,0,0.10);
  max-height: 78%;
  display: flex; flex-direction: column;
  overflow: hidden;
}
#bgPicker .bp-handle,
#bgPicker .bp-title {
  flex: 0 0 auto;
  padding-left: 20px;
  padding-right: 20px;
}
#bgPicker .bp-handle {
  padding-left: 0; padding-right: 0;
}
.bp-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: scroll;                 /* 强制 scroll 而非 auto，确保 iOS 有滚动条区域 */
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0 20px;
  /* 底部大 padding：24 页边距 + 32 手势区 + 系统安全区，确保最后一个按钮完全露出 */
  padding-bottom: calc(60px + env(safe-area-inset-bottom, 0));
}
#bgPicker.bp-open { transform: translateY(0); }
.bp-handle { width: 36px; height: 4px; background: #e0e0e0; border-radius: 2px; margin: 0 auto 18px; }
.bp-title { font-size: 14px; font-weight: 600; color: #1a1a1a; margin-bottom: 16px; letter-spacing: -0.2px; }
.bp-section-label { font-size: 11px; color: #aaa; letter-spacing: 0.5px; text-transform: uppercase; margin-bottom: 10px; margin-top: 16px; }
.bp-swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.bp-swatch {
  width: 38px; height: 38px; border-radius: 10px;
  cursor: pointer; flex-shrink: 0;
  /* 用内阴影代替 border，极淡，浅色（米/白）上不会显得"有外框选中感" */
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.04);
  transition: transform 0.12s, box-shadow 0.15s; position: relative;
}
.bp-swatch:active { transform: scale(0.88); }
/* 只有真的被选中的色才显示外框（明显的黑色外环 + 阴影） */
.bp-swatch.bp-selected {
  box-shadow: 0 0 0 2.5px #1a1a1a, inset 0 0 0 1px rgba(0,0,0,0.04);
}
/* 白色块默认：加一圈细灰边，否则跟白底浮层融在一起看不见 */
.bp-swatch.bp-swatch-white { box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12); }
/* 白色块选中态：外环 + 细灰边一起 */
.bp-swatch.bp-swatch-white.bp-selected {
  box-shadow: 0 0 0 2.5px #1a1a1a, inset 0 0 0 1px rgba(0,0,0,0.12);
}
/* 自定义色块单独一行：按钮在左，灰字在右 */
.bp-color-row, .bp-custom-row {
  display: flex; flex-direction: row; align-items: center;
  gap: 10px; margin-top: 14px;
}
.bp-custom-hint { font-size: 12px; color: #aaa; letter-spacing: 0.2px; }
.bp-color-input-wrap {
  display: inline-block;
  width: 44px; height: 44px; border-radius: 50%;
  overflow: hidden; flex-shrink: 0; cursor: pointer; position: relative;
  /* 默认彩虹底，13 段 HSL 均匀色相，过渡更柔和、首尾平滑衔接 */
  background: conic-gradient(from 0deg,
    hsl(0,90%,60%),   hsl(30,90%,58%),  hsl(60,90%,56%),
    hsl(90,80%,52%),  hsl(120,75%,50%), hsl(150,75%,52%),
    hsl(180,80%,55%), hsl(210,85%,58%), hsl(240,85%,62%),
    hsl(270,80%,62%), hsl(300,80%,60%), hsl(330,85%,60%),
    hsl(360,90%,60%));
  /* 选中态由 JS 切纯色，给选中态预留外环位置 */
  transition: box-shadow 0.15s;
}
/* 自定义色被使用时显示的选中外环（JS 加 .bp-selected） */
.bp-color-input-wrap.bp-selected {
  box-shadow: 0 0 0 2.5px #1a1a1a;
}
.bp-color-input-wrap input[type="color"] {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  border: none; padding: 0; margin: 0; cursor: pointer;
  opacity: 0; background: transparent;
  -webkit-appearance: none; appearance: none;
  z-index: 2;
}
.bp-upload-btn {
  height: 50px; border: 1.5px dashed #dedede; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer; transition: background 0.15s; margin-top: 14px;
}
.bp-upload-btn:active { background: rgba(0,0,0,0.03); }
.bp-upload-btn span { font-size: 12px; color: #999; }

/* 预设图片缩略图网格（一行 3 个，4:5 比例，跟 zine 页比例一致） */
.bp-bg-thumbs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 4px;
}
.bp-bg-thumb {
  aspect-ratio: 4 / 5;
  border-radius: 10px;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  cursor: pointer;
  position: relative;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.06);
  transition: transform 0.12s, box-shadow 0.15s;
}
.bp-bg-thumb:active { transform: scale(0.93); }
.bp-bg-thumb.bp-selected {
  box-shadow: inset 0 0 0 2px #1a1a1a, 0 0 0 2px rgba(0,0,0,0.06);
}

/* 封面编辑面板 */
#coverEditorOverlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0); z-index: 490; display: none;
}
#coverEditor {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: #fff; border-radius: 20px 20px 0 0;
  padding: 12px 20px 0; z-index: 500;
  transform: translateY(100%);
  transition: transform 0.36s cubic-bezier(0.25,0.46,0.45,0.94);
  box-shadow: 0 -4px 32px rgba(0,0,0,0.10);
  /* 半屏高：头部固定、内容区滚动（见 .ce-scroll） */
  max-height: 56vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
/* 头部（handle + 标题 + 关闭）固定不滚，只有 .ce-scroll 滚 */
#coverEditor .ce-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0 4px 32px;   /* 左右留 4px，防止选中黑圈外环被 overflow 裁切 */
  margin: 0 -4px;         /* 负 margin 抵消，保持内容视觉对齐 */
}
#coverEditor.ce-open { transform: translateY(0); }
/* 封面模板选项卡 */
.ce-tpl-row { display: flex; gap: 8px; }
.ce-tpl-opt {
  flex: 1; height: 40px; border-radius: 10px;
  border: 1.5px solid #e5e5e5; background: #fafafa;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 500; color: #888; cursor: pointer;
  transition: all 0.15s;
}
.ce-tpl-opt:active { transform: scale(0.97); }
.ce-tpl-opt.ce-tpl-active {
  border-color: #1a1a1a; background: #1a1a1a; color: #fff;
}
/* 镂空窗口位置选择：两个简笔缩略图 */
.ce-pos-row { display: flex; gap: 10px; }
.ce-pos-opt {
  flex: 1;
  border-radius: 10px;
  border: 1.5px solid #e5e5e5; background: #fafafa;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 0 8px;
  cursor: pointer; transition: all 0.15s;
}
.ce-pos-opt:active { transform: scale(0.97); }
.ce-pos-thumb { width: 34px; height: auto; display: block; }
.ce-pos-label { font-size: 12px; font-weight: 500; color: #888; transition: color 0.15s; }
.ce-pos-opt.ce-pos-active {
  border-color: #1a1a1a; background: #fff;
}
.ce-pos-opt.ce-pos-active .ce-pos-label { color: #1a1a1a; font-weight: 600; }
.ce-color-row {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.ce-color-row .bp-swatch { width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0; }
/* 色轮嵌入色块行末尾 —— 默认彩虹底（跟 bgPicker 自定义色块一致） */
.ce-color-wheel-wrap {
  width: 38px; height: 38px; border-radius: 10px;
  overflow: hidden; flex-shrink: 0; cursor: pointer;
  position: relative;
  /* 默认彩虹底，13 段 HSL 均匀色相 */
  background: conic-gradient(from 0deg,
    hsl(0,90%,60%),   hsl(30,90%,58%),  hsl(60,90%,56%),
    hsl(90,80%,52%),  hsl(120,75%,50%), hsl(150,75%,52%),
    hsl(180,80%,55%), hsl(210,85%,58%), hsl(240,85%,62%),
    hsl(270,80%,62%), hsl(300,80%,60%), hsl(330,85%,60%),
    hsl(360,90%,60%));
  /* 用内阴影替代 border，避免土黄色 input 透出来 */
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.06);
  transition: box-shadow 0.15s;
}
.ce-color-wheel-wrap.bp-selected {
  box-shadow: inset 0 0 0 2px #1a1a1a, 0 0 0 2px rgba(0,0,0,0.06);
}
.ce-color-wheel-wrap.bp-selected::after {
  content: ''; /* 选中态不再显示 ✓，靠外环表达即可（跟 bgPicker 自定义色块行为一致） */
}
.ce-color-wheel-wrap input[type="color"] {
  position: absolute; top: -6px; left: -6px;
  width: calc(100% + 12px); height: calc(100% + 12px);
  border: none; padding: 0; cursor: pointer;
  background: none;
  opacity: 0;  /* 关键：隐藏 input 自身的默认色，只保留点击调起选色器的能力 */
  -webkit-appearance: none; appearance: none;
}
.ce-text-color-row {
  display: flex; align-items: center; gap: 8px; margin-top: 4px;
}
.ce-text-swatch {
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer;
  border: 1.5px solid rgba(0,0,0,0.07); flex-shrink: 0;
  transition: transform 0.12s; position: relative;
}
.ce-text-swatch:active { transform: scale(0.88); }
.ce-text-swatch.ce-selected {
  box-shadow: 0 0 0 2.5px #1a1a1a;
}
.ce-title-input {
  width: 100%; border: 1.5px solid #e0e0e0; border-radius: 10px;
  padding: 10px 12px; font-size: 14px; font-weight: 600;
  letter-spacing: 0.5px; text-transform: uppercase; resize: none;
  outline: none; font-family: inherit; margin-top: 4px;
}
.ce-title-input:focus { border-color: #1a1a1a; }
.ce-apply-btn {
  width: 100%; height: 44px; border: none; border-radius: 12px;
  background: #1a1a1a; color: #fff; font-size: 14px; font-weight: 600;
  cursor: pointer; margin-top: 16px; transition: opacity 0.15s;
}
.ce-apply-btn:active { opacity: 0.7; }
.ce-upload-btn {
  flex: 1; height: 38px; border: 1.5px solid #e0e0e0; border-radius: 10px;
  background: #fff; color: #333; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: background 0.15s;
}
.ce-upload-btn:active { background: #f0f0f0; }
.ce-remove-btn { color: #c44; border-color: #e0c0c0; }

/* 书架轨道 */
.shelf-stage {
  position: absolute;
  top: 100px; left: 0; right: 0; bottom: 150px;
  display: flex; align-items: center; overflow: hidden;
}
.shelf-track {
  display: flex; align-items: center; padding: 0;
  transition: transform 0.42s cubic-bezier(0.25,0.46,0.45,0.94);
  will-change: transform; cursor: grab;
}
.shelf-track:active { cursor: grabbing; }
.shelf-card {
  /* ★ 书本统一比例：160 / 226（与工作台 #bookContainer 完全一致）
     宽 225 → 高 = 225 × 226/160 = 317.8px。所有出现"书"的地方都必须用这个比例 */
  flex-shrink: 0; width: 225px; aspect-ratio: 160 / 226; border-radius: 0 3px 3px 0;
  background: #EEEAE3;
  /* 书页厚度：右+下方向叠加少量冷灰硬边，薄薄一层，与底部阴影自然融合 */
  box-shadow:
    1px 0 0 #c9c9ce,
    2px 1px 0 #b8b8bf,
    3px 2px 4px rgba(0,0,0,0.12),
    0 14px 36px rgba(0,0,0,0.16),
    0 4px 12px rgba(0,0,0,0.09);
  position: relative; overflow: hidden; cursor: pointer;
  transition: transform 0.42s cubic-bezier(0.25,0.46,0.45,0.94),
              box-shadow 0.42s cubic-bezier(0.25,0.46,0.45,0.94), opacity 0.42s;
  margin: 0 18px;
}
.shelf-card.s-active {
  transform: scale(1.0);
  box-shadow:
    1px 0 0 #c9c9ce,
    2px 1px 0 #b8b8bf,
    4px 3px 6px rgba(0,0,0,0.13),
    0 22px 52px rgba(0,0,0,0.20),
    0 6px 14px rgba(0,0,0,0.11);
  z-index: 3;
}
.shelf-card.s-side { transform: scale(0.88); opacity: 0.55; box-shadow: 1px 0 0 #bcbcc2, 2px 2px 5px rgba(0,0,0,0.10), 0 8px 22px rgba(0,0,0,0.09); z-index: 2; }
.shelf-card.s-far  { transform: scale(0.82) translateY(8px); opacity: 0.45; z-index: 1; }
.shelf-card-inner {
  width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 30px 24px; position: relative;
}
/* 当封面使用纹理背景时，去掉 padding 让纹理填满整张卡片 */
.shelf-card-inner:has(> .cover-page),
.shelf-card-inner:has(> .cover-cutout) {
  padding: 0;
}
.sc-num   { font-size: 9px; color: #aaa; letter-spacing: 2.5px; text-transform: uppercase; margin-bottom: 20px; }
.sc-title { font-size: 22px; font-weight: 700; color: #1a1a1a; text-align: center; line-height: 1.15; letter-spacing: -0.3px; margin-bottom: 14px; }
.sc-divider { width: 18px; height: 1px; background: rgba(0,0,0,0.2); margin-bottom: 14px; }
.sc-sub   { font-size: 8px; color: #999; text-align: center; line-height: 1.7; }
.shelf-dots {
  position: absolute; bottom: 40px; left: 0; right: 0;
  height: 20px; display: flex; justify-content: center; align-items: center; gap: 6px;
}
.sh-dot { width: 5px; height: 5px; border-radius: 50%; background: #d0d0d0; transition: all 0.3s; }
.sh-dot.active { background: #333; width: 18px; border-radius: 2.5px; }
.shelf-tab-bar {
  position: absolute; bottom: 0; left: 0; right: 0; height: 60px;
  background: #fff; border-top: 0.5px solid #ebebeb;
  display: flex; align-items: center; justify-content: space-around;
}
.tab-item { display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; padding: 4px 20px; }
.tab-item svg { width: 26px; height: 26px; stroke-width: 1.6; fill: none; transition: stroke 0.15s; }
.tab-item.tab-active svg { stroke: #000; stroke-width: 2; }
.tab-item:not(.tab-active) svg { stroke: #b0b0b0; }

/* ── 轮播页左上角：收集页入口 ── */
.shelf-grid-entry {
  position: absolute; top: 60px; left: 18px;
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(0,0,0,0.06);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; z-index: 300;
  transition: background 0.2s, transform 0.15s;
}
.shelf-grid-entry:active { transform: scale(0.9); background: rgba(0,0,0,0.13); }
.shelf-grid-entry svg { width: 18px; height: 18px; }

/* ── 轮播页当前书信息（书名可编辑 + 小字） ── */
.shelf-meta {
  position: absolute; left: 0; right: 0; bottom: 148px;
  text-align: center; z-index: 250; pointer-events: none;
  padding: 0 32px;
}
.shelf-meta-title {
  display: inline-block;
  font-size: 21px; font-weight: 800; color: #0d0d0d;
  letter-spacing: -0.5px; line-height: 1.15;
  pointer-events: auto; cursor: text;
  padding: 2px 10px; border-radius: 8px;
  max-width: 100%; word-break: break-word;
  transition: background 0.15s;
}
.shelf-meta-title:active { background: rgba(0,0,0,0.04); }
/* 就地编辑输入框 */
.shelf-meta-title.editing {
  background: rgba(0,0,0,0.04);
  outline: 1.5px solid #1a1a1a;
}
.shelf-meta-sub {
  margin-top: 6px;
  font-size: 12px; color: #b0b0b0; letter-spacing: 0.2px;
}

/* ════════════════════════════════════════
   收集页：所有 Zine 网格总览
════════════════════════════════════════ */
#collectionView {
  position: absolute; inset: 0;
  background: #fff;
  flex-direction: column;
  z-index: 400;
  /* 默认完全不渲染，避免常驻合成层拖累其他页面动画 */
  display: none;
  opacity: 0;
  pointer-events: none;
}
/* 挂载态：参与渲染但仍透明 */
#collectionView.cv-mounted {
  display: flex;
  transition: opacity 0.3s ease;
}
#collectionView.cv-show {
  opacity: 1;
  transition: opacity 0.3s ease;
  pointer-events: auto;
}
/* 书本主体渐显 + 轻微上浮（仅进入时） */
.cv-card {
  opacity: 0;
  transform: translateY(10px);
}
#collectionView.cv-show .cv-card {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.42s ease, transform 0.42s cubic-bezier(0.22, 0.61, 0.36, 1);
}
.collection-top {
  position: relative; flex-shrink: 0;
  height: 100px;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0 18px 12px;
}
.collection-back, .collection-select-btn {
  position: absolute; bottom: 8px;
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(0,0,0,0.06);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background 0.2s, transform 0.15s;
}
.collection-back { left: 18px; }
.collection-select-btn { right: 18px; }
.collection-back:active, .collection-select-btn:active { transform: scale(0.9); background: rgba(0,0,0,0.13); }
.collection-back svg, .collection-select-btn svg { width: 18px; height: 18px; }
/* 多选态左上角"取消"文字按钮 */
.collection-cancel {
  position: absolute; left: 18px; bottom: 8px;
  height: 40px; display: none; align-items: center;
  font-size: 15px; color: #1a1a1a; cursor: pointer;
  padding: 0 4px;
}
.collection-title {
  font-size: 18px; font-weight: 700; color: #0d0d0d;
  letter-spacing: -0.3px; padding-bottom: 2px;
}
/* 多选态：隐藏返回和垃圾桶，显示取消 */
#collectionView.cv-select .collection-back,
#collectionView.cv-select .collection-select-btn { display: none; }
#collectionView.cv-select .collection-cancel { display: flex; }

.collection-scroll {
  flex: 1; min-height: 0; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 28px 24px calc(48px + env(safe-area-inset-bottom, 0));
}
/* 所有 zine：两列网格（对齐 demo：居中书名、无分区无隔板） */
.collection-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 32px 22px;
}
/* 单本卡片 —— 缩到约 80%，在各自列内居中 */
.cv-card { cursor: pointer; position: relative; width: 80%; margin: 0 auto; }
.cv-card-cover {
  /* ★ 书本统一比例 160/226，与轮播页/工作台完全一致 */
  width: 100%; aspect-ratio: 160 / 226;
  border-radius: 0 3px 3px 0; overflow: hidden; position: relative;
  background: #EEEAE3;
  /* 淡投影，让书轻轻浮起 */
  box-shadow: 0 6px 18px rgba(0,0,0,0.10), 0 2px 5px rgba(0,0,0,0.06);
  transition: transform 0.15s, box-shadow 0.2s;
}
.cv-card:active .cv-card-cover { transform: scale(0.96); }
/* 把 cover-page 内容缩放填满卡片 */
.cv-card-cover > .cover-page,
.cv-card-cover > .cover-cutout {
  position: absolute; inset: 0; width: 100%; height: 100%;
}
.cv-card-title {
  margin-top: 11px;
  font-size: 12px; font-weight: 700; color: #1a1a1a;
  letter-spacing: -0.2px; line-height: 1.25;
  text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cv-card-sub {
  margin-top: 3px;
  font-size: 11px; color: #b5b5b5; letter-spacing: 0.2px;
}

/* ── 多选态：勾选圈 + 选中反馈 ── */
.cv-check {
  position: absolute; top: 8px; left: 8px;
  width: 24px; height: 24px; border-radius: 50%;
  background: rgba(255,255,255,0.9);
  box-shadow: 0 1px 4px rgba(0,0,0,0.2), inset 0 0 0 1.5px rgba(0,0,0,0.15);
  display: none; align-items: center; justify-content: center;
  z-index: 5; pointer-events: none;
}
.cv-check svg { width: 14px; height: 14px; stroke: #fff; stroke-width: 3; fill: none; opacity: 0; }
#collectionView.cv-select .cv-check { display: flex; }
.cv-card.cv-selected .cv-check {
  background: #ff4444; box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.cv-card.cv-selected .cv-check svg { opacity: 1; }
.cv-card.cv-selected .cv-card-cover {
  box-shadow: 0 0 0 2.5px #ff4444, 0 4px 16px rgba(0,0,0,0.10);
}

/* ── 多选态底部操作栏 ── */
.collection-selbar {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: calc(64px + env(safe-area-inset-bottom, 0));
  padding: 0 20px calc(0px + env(safe-area-inset-bottom, 0));
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 0.5px solid #eee;
  display: none; align-items: center; justify-content: space-between;
  transform: translateY(100%); transition: transform 0.28s cubic-bezier(0.32,0.72,0,1);
  z-index: 60;
}
#collectionView.cv-select .collection-selbar { display: flex; transform: translateY(0); }
.csb-count { font-size: 14px; color: #666; }
.csb-del-btn {
  height: 40px; padding: 0 24px; border: none; border-radius: 12px;
  background: #ff4444; color: #fff; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: opacity 0.15s, transform 0.15s;
}
.csb-del-btn:active { transform: scale(0.96); }
.csb-del-btn:disabled { background: #e5e5e5; color: #aaa; cursor: not-allowed; }

/* ════════════════════════════════════════
   统一工作台（cover + reader + edit）
════════════════════════════════════════ */
#studioView {
  position: absolute; inset: 0;
  background: #E9EAEC; display: none;
  transition: background 0.3s;
}

/* 三态层 — 通过 st-active 类切换可见 */
#stCover, #stReader, #stEdit {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  transition: opacity 0.36s ease, transform 0.42s cubic-bezier(0.34,1.05,0.64,1);
  opacity: 0; transform: scale(0.88);
}
/* ★ v=am8b: 阅读态书页与顶栏保持安全距离
   （编辑态由 JS calcZoomTransform 里 topBarH 保证，此处只管封面/阅读态） */
#stCover {
  padding-top: 40px;
  box-sizing: border-box;
}
#stCover { flex-direction: column; gap: 16px; overflow: hidden; }
#stEdit { flex-direction: column; align-items: stretch; justify-content: flex-start; }
#stCover.st-active, #stReader.st-active, #stEdit.st-active {
  opacity: 1; transform: scale(1); pointer-events: auto;
}

/* 封面+阅读 统一书本容器
   封面态: 160px宽，只显示封面（coverFlip在left:0）
   阅读态: 320px宽，coverFlip翻开=左页 + bookBase=右页
   
   关键原理：
   封面态 coverFlip left:0, 容器160px → 封面居中显示
   翻开时 coverFlip 移到 left:160px（书脊位置），然后绕左边缘翻转180°
   翻完后 coverFlip 落在 0~160px = 左页，bookBase 160~320px = 右页，紧贴！
*/
#bookContainer {
  position: relative;
  width: 160px; height: 226px;
  perspective: 1200px;
  -webkit-perspective: 1200px;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  margin-top: -10px;
  /* 提示浏览器在 Retina 屏幕上以高分辨率光栅化 transform 内容，避免缩放后文字模糊 */
  will-change: transform;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* am9Q7：书页整个范围禁用双击缩放，避免手指点到文字外触发 Safari zoom */
  touch-action: manipulation;
}
#bookContainer.reader-mode { width: 320px; }

/* 右页（翻开后才可见） */
#bookBase {
  position: absolute; top: 0; left: 160px;
  width: 160px; height: 226px;
  background: #FFFFFF; border-radius: 0 3px 3px 0;
  overflow: hidden;
  box-shadow: 4px 24px 72px rgba(0,0,0,0.22), 2px 4px 16px rgba(0,0,0,0.12);
}
/* 封面态：右页完全隐藏（含阴影），无过渡直接消失 */
#bookContainer.cover-mode #bookBase { opacity: 0; pointer-events: none; box-shadow: none; }

/* 封面翻页层
   封面态: left:0, 显示封面正面
   翻开时: JS 先把 left 改为 160px，然后 rotateY(-180deg)
   翻完后: 视觉上落在 0~160px（左页背面）
*/
#coverFlip {
  position: absolute; top: 0; left: 0;
  width: 160px; height: 226px;
  transform-style: preserve-3d;
  transform-origin: left center;
  transform: rotateY(0deg);
  z-index: 10; cursor: pointer;
  box-shadow: 0 24px 72px rgba(0,0,0,0.30), 0 4px 16px rgba(0,0,0,0.16);
}
/* 假厚度 — 底边+右侧露出细细的纸页边缘。
   改为半透明深色（自适应任意背景）+ 大幅弱化，避免固定米灰在深背景上突兀。 */
#coverFlip::after {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: calc(100% + 1px); height: calc(100% + 1px);
  background: rgba(0,0,0,0.16);
  border-radius: 0 3px 3px 0;
  z-index: -1;
  opacity: 0.5;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s;
}
/* 翻开后隐藏假厚度 */
#bookContainer.reader-mode #coverFlip::after { opacity: 0; }
#coverFlipFront {
  position: absolute; top: 0; right: 0; bottom: 0; left: -1px;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  -webkit-transform: translateZ(0.5px);
  transform: translateZ(0.5px);
  overflow: hidden;
  border-radius: 0 3px 3px 0;
  /* 封面 cover-page 直接填满，左边多出 1px 遮盖白边 */
}
#coverFlipBack {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  transform: rotateY(180deg);
  background: #FFFFFF; overflow: hidden;
  border-radius: 3px 0 0 3px;
}
/* 翻开后封面不可点击 */
#bookContainer.reader-mode #coverFlip { pointer-events: none; box-shadow: -4px 24px 72px rgba(0,0,0,0.13), -2px 4px 16px rgba(0,0,0,0.07); }


/* 书本 3D */
.book-scene { perspective: 1400px; perspective-origin: center center; position: relative; }
.book-spread {
  position: relative; display: flex; align-items: stretch;
  transform-style: preserve-3d; border-radius: 3px;
  box-shadow: 0 24px 72px rgba(0,0,0,0.30), 0 4px 16px rgba(0,0,0,0.16);
}
.page-left  { width: 160px; height: 226px; position: relative; border-radius: 3px 0 0 3px; overflow: hidden; background: #FFFFFF; flex-shrink: 0;
  text-rendering: geometricPrecision; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
.page-right { width: 160px; height: 226px; position: relative; border-radius: 0 3px 3px 0; overflow: hidden; background: #FFFFFF; flex-shrink: 0;
  text-rendering: geometricPrecision; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
#bindingCrease { position: absolute; top: 0; left: 152px; width: 16px; height: 226px; pointer-events: none; z-index: 60; opacity: 0; }
#bookContainer.reader-mode #bindingCrease { opacity: 1; }
#bindingCrease svg { display: block; }
#flipper {
  position: absolute; top: 0; width: 160px; height: 226px;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  display: none; z-index: 50;
  will-change: transform;
  left: 160px;
  transform-origin: left center;
  -webkit-transform-origin: left center;
}
.flipper-front, .flipper-back {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  overflow: hidden; background: #FAFAF8; border-radius: 0 3px 3px 0;
}
.flipper-back {
  transform: rotateY(180deg);
  -webkit-transform: rotateY(180deg);
}
.page-content {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  padding: 14px 13px; display: flex; flex-direction: column;
}
/* ★ 2x 高清渲染层：320×452 渲染，scale(0.5) 回到 160×226 */
.hires-wrap {
  position: absolute; top: 0; left: 0;
  width: 320px; height: 452px;
  transform: scale(0.5);
  transform-origin: 0 0;
}
.page-number { position: absolute; bottom: 9px; font-size: 7.5px; color: #c0c0c0; letter-spacing: 0.5px; }
.page-left  .page-number { left: 13px; }
.page-right .page-number { right: 13px; }
.page-title   { font-size: 7.5px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: #333; margin-bottom: 8px; }
.page-body    { font-size: 6.5px; color: #666; line-height: 1.7; }
.page-img     { width: 100%; background: #ededeb; border-radius: 3px; margin: 6px 0; display: flex; align-items: center; justify-content: center; }
.page-tag     { display: inline-block; font-size: 5.5px; color: #aaa; border: 0.5px solid #e0e0e0; padding: 1.5px 5px; border-radius: 20px; letter-spacing: 0.5px; text-transform: uppercase; margin-top: 6px; }
.empty-page-clickable {
  color: #b9b9b9;
  transition: color 0.15s ease, transform 0.15s ease;
}
.empty-page-clickable .empty-page-plus path {
  stroke: currentColor;
}
.empty-page-hint {
  display: none;
  font-size: 7px;
  line-height: 1;
  color: currentColor;
  letter-spacing: 0.4px;
  font-weight: 500;
}
body[data-studio-state="edit"] .empty-page-clickable {
  color: #a8a8a8;
  cursor: pointer;
}
body[data-studio-state="edit"] .empty-page-hint {
  display: block;
}
body[data-studio-state="edit"] .empty-page-clickable:active {
  transform: scale(0.96);
  color: #777;
}
.cover-page {
  width: 100%; height: 100%;
  position: relative;
  background-color: var(--cover-color, #C8B862);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  overflow: hidden;
  box-sizing: border-box;
  /* ★ 容器查询基准：封面内部所有尺寸用 cqw（容器宽度的 1%），
     保证同一封面在轮播/工作台/收集页任意大小下都等比缩放、字号一致。
     设计基准宽度 160px：1cqw = 1.6px */
  container-type: inline-size;
}
/* 灰度纹理叠加层 — multiply 混合保留肌理、书脊等细节 */
.cover-page::before {
  content: '';
  position: absolute; inset: 0;
  background: url('../images/cover-texture.png') center/cover no-repeat;
  filter: grayscale(1);
  mix-blend-mode: multiply;
  pointer-events: none;
  z-index: 0;
  /* ★ 纹理本身是浅色，multiply 后底色几乎被冲淡到看不见（iOS Safari 尤其明显）
     降低不透明度让底色清晰可见，同时保留一些布纹质感 */
  opacity: 0.5;
}
/* 自定义封面图模式：隐藏纹理层 */
/* 自定义整图封面：不显示纹理层，也不显示书脊压痕线（书脊线只属于基础/镂空模板） */
.cover-page-img::before,
.cover-page-img::after { display: none; }
/* ★ 装订压痕：定义在 .cover-page 上，用 cqw 等比 →
   所有出现封面的地方（轮播/工作台/收集页）自动一致，无需各处重复 */
.cover-page::after {
  content: ''; position: absolute;
  left: 2.2cqw; top: 0; bottom: 0; width: 2.7cqw;
  z-index: 2; pointer-events: none;
  background: linear-gradient(to right,
    rgba(0,0,0,0) 0%,
    rgba(0,0,0,0.09) 45%,
    rgba(0,0,0,0.07) 55%,
    rgba(0,0,0,0) 100%);
}
.cover-main-title {
  position: relative; z-index: 1;
  color: var(--cover-text, #E8E0C8);
  font-family: 'FZLanTingHei', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
  /* cqw 基准 160px：9px = 5.625cqw（等比缩放，各处大小一致） */
  font-size: 5.625cqw; font-weight: 600;
  letter-spacing: 0.1875cqw;
  text-align: center; line-height: 1.35;
}
.cover-bottom-text {
  position: absolute; bottom: 8.75cqw; left: 0; right: 0;
  text-align: center;
  z-index: 1;
  color: var(--cover-text, #E8E0C8);
  font-family: 'Domine', Georgia, serif;
  font-size: 2.1875cqw; font-weight: 400;
  letter-spacing: 0.05cqw;
  text-transform: uppercase;
}

/* ════════════════════════════════════════
   镂空笔记本封面模板 (.cover-cutout)
   黄色皮质 + 轻纸张肌理 + 中部凹陷镂空窗口（放图）
   所有尺寸用 cqw，保证轮播/工作台/收集页等比一致
════════════════════════════════════════ */
.cover-cutout {
  width: 100%; height: 100%;
  position: relative;
  background-color: var(--cover-color, #efe287);
  overflow: hidden;
  box-sizing: border-box;
  container-type: inline-size;
}
/* 皮质纸张肌理：加强，皮面布纹更清晰 */
.cover-cutout::before {
  content: '';
  position: absolute; inset: 0;
  background: url('../images/cover-texture.png') center/cover no-repeat;
  filter: grayscale(1) contrast(1.15);
  mix-blend-mode: multiply;
  opacity: 0.38;              /* 0.18 → 0.38，肌理更明显 */
  pointer-events: none;
  z-index: 0;
}
/* 皮面体积：整体顶光 + 上边缘窄高光 + 下边缘窄阴影（书封受光/厚度） */
.cover-cutout::after {
  content: '';
  position: absolute; inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    /* 上边缘：窄窄一条高光线（对齐下边缘窄度、降透明度、少渐变） */
    linear-gradient(to bottom, rgba(255,255,255,0.32) 0%, rgba(255,255,255,0.22) 0.5%, rgba(255,255,255,0) 1.05%),
    /* 下边缘：很窄的一条暗色条（书封底边厚度），高度约为原来的 2/3 */
    linear-gradient(to top, rgba(0,0,0,0.30) 0%, rgba(0,0,0,0.20) 0.5%, rgba(0,0,0,0) 1.05%),
    /* 整体柔和顶光渐变，增加体积 */
    linear-gradient(135deg, rgba(255,255,255,0.12) 0%, rgba(255,255,255,0) 38%, rgba(0,0,0,0.05) 100%);
}
/* 装订压痕（左侧竖折痕，和基础封面一致） */
.cover-cutout .cc-crease {
  position: absolute; left: 2.2cqw; top: 0; bottom: 0; width: 2.7cqw;
  z-index: 3; pointer-events: none;
  background: linear-gradient(to right,
    rgba(0,0,0,0) 0%, rgba(0,0,0,0.09) 45%, rgba(0,0,0,0.07) 55%, rgba(0,0,0,0) 100%);
}
/* 镂空窗口：白窗本身干净。切口厚度做在窗口外的【黄色皮面】上（见下方 box-shadow）。 */
.cover-cutout .cc-window {
  position: absolute;
  left: 34.5cqw; width: 31cqw;
  top: 30cqw; height: 41cqw;
  z-index: 2;
  overflow: hidden;
  background: #ffffff;
  /* 外投 box-shadow：投在四周黄色皮面上 = 皮面切出的凹槽壁。
     光从左上来 → 上壁/左壁暗（棕），下壁/右壁亮（高光，弱化 + 贴边对齐角点）。 */
  box-shadow:
    0 0 0 0.1cqw rgba(60,45,20,0.16),
    /* 左上：背光暗壁 */
    -0.45cqw -0.5cqw 0.9cqw -0.1cqw rgba(60,45,20,0.34),
    /* 右下：受光高光壁（弱化、收窄 blur，贴边让拐角更接近窗角） */
    0.4cqw 0.4cqw 0.5cqw -0.05cqw rgba(255,252,235,0.4),
    inset 0 0 0 0.08cqw rgba(0,0,0,0.10);
}
/* 镂空窗口位置：右上（只覆盖 left/top，宽高与阴影完全沿用居中态） */
.cover-cutout .cc-window--topright {
  left: 60cqw;
  top: 9cqw;
}
.cover-cutout .cc-window::after { display: none; }
/* 凹槽上壁投在图片上的一点点阴影（符合物理：光从上来，上壁遮挡）。窄而淡。 */
.cover-cutout .cc-window::before {
  content: '';
  position: absolute; inset: 0;
  z-index: 3;
  pointer-events: none;
  background:
    linear-gradient(to bottom, rgba(0,0,0,0.22) 0%, rgba(0,0,0,0.06) 2%, rgba(0,0,0,0) 5%),
    linear-gradient(to right, rgba(0,0,0,0.10) 0%, rgba(0,0,0,0) 3%);
}
/* 窗口外圈：极细的一圈提亮，像皮面被切开露出的斜口高光 */
.cover-cutout .cc-window::after {
  content: '';
  position: absolute; inset: -0.5cqw;
  border-radius: 0.3cqw;
  box-shadow: 0 0.4cqw 0.8cqw rgba(0,0,0,0.12);
  pointer-events: none;
}
/* 窗口内图片 */
.cover-cutout .cc-window img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  z-index: 1;
  user-select: none; -webkit-user-drag: none;
}
/* 图片区保持干净：不在图片上叠切口阴影（切口体积做在窗口外的黄色皮面上） */
/* 底部文字 TIME TO ZINE（复用普通封面参数） */
.cover-cutout .cc-bottom-text {
  position: absolute; bottom: 8.75cqw; left: 0; right: 0;
  text-align: center; z-index: 3;
  color: var(--cover-text, #3a3320);
  font-family: 'Domine', Georgia, serif;
  font-size: 2.1875cqw; font-weight: 400;
  letter-spacing: 0.05cqw;
  text-transform: uppercase;
}
.page-indicator {
  position: absolute;
  /* 默认：阅读/封面态，缩略图栏贴底部（fallback 永远是底部，:has() 判错也不会飘） */
  bottom: calc(20px + env(safe-area-inset-bottom, 0));
  left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  z-index: 401;  /* 高于工具栏 400，保证可见 */
  max-width: 85%; padding: 6px 10px;
  background: rgba(255,255,255,0.92);
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}
/* 编辑态：工具栏 ~120px 高，缩略图栏上移避开 */
body:has(#editToolbar.toolbar-in) .page-indicator {
  bottom: calc(120px + env(safe-area-inset-bottom, 0));
}
/* 中间滚动区：按钮 flex 在两侧固定，缩略图在此横向滚动 */
.page-indicator-scroll {
  display: flex; align-items: center; gap: 6px;
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  min-width: 0;
}
.page-indicator-scroll::-webkit-scrollbar { display: none; }
.indicator-thumb {
  flex-shrink: 0;
  cursor: pointer;
  border-radius: 3px;
  border: 1.5px solid transparent;
  transition: border-color 0.2s, transform 0.15s;
  overflow: hidden;
  background: #fff;
  /* iOS：允许横滑滚动缩略图栏（pan-x），阻止其他手势（缩放/纵向滚/系统菜单） */
  touch-action: pan-x;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.indicator-thumb:active { transform: scale(0.94); }
.indicator-thumb.active { border-color: #1a1a1a; }
/* ── 长按拖拽换 spread 顺序：视觉反馈 ── */
/* 拖起来的克隆：跟手漂浮 + 半透明放大 + 无过渡 */
.indicator-thumb-drag-clone {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  transform: scale(1.35);
  opacity: 0.9;
  box-shadow: 0 6px 20px rgba(0,0,0,0.35);
  border-radius: 3px;
  transition: none;
  will-change: transform, left, top;
}
/* 拖起源占位：变白 + 虚线边框，明确"这只是原来的位置" */
.indicator-thumb.dragging-source {
  opacity: 1;
  border: 1.5px dashed #999 !important;
  background: #fff;
}
.indicator-thumb.dragging-source > * {
  opacity: 0;
}
/* 落点指示：目标格稳定高亮，不区分左右不放大，避免闪烁 */
.indicator-thumb.drop-target {
  background: #fff5c2;
  box-shadow: 0 0 0 2px #1a1a1a;
  border-radius: 4px;
}
/* 拖拽期间：不改 overflow（自动滚动要用），仅屏蔽用户手动横滑（通过 pointer preventDefault 已够） */
.page-indicator-scroll.is-dragging {
  scroll-behavior: auto;
}
/* 拖拽期间禁用页面文字选择 + 禁 iOS 原生手势 */
body.is-dragging-thumb {
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  -webkit-touch-callout: none;
}
body.is-dragging-thumb * {
  touch-action: none !important;
}
/* 缩略图内部容器：等比缩放至 36px 宽（单页）或 48px（跨页） */
.thumb-cover {
  width: 28px; height: 40px;
  position: relative; overflow: hidden;
}
.thumb-spread {
  width: 48px; height: 36px;
  display: flex;
}
.thumb-half {
  width: 24px; height: 36px;
  position: relative; overflow: hidden;
}
/* 缩略图里禁用所有交互 + 缩放 page-content */
.indicator-thumb .page-content,
.indicator-thumb [data-cutout-root],
.indicator-thumb img {
  pointer-events: none !important;
}
.thumb-cover > *, .thumb-half > * {
  position: absolute !important;
  inset: 0 !important;
  transform: scale(0.15) !important;
  transform-origin: top left !important;
  width: 160px !important;
  height: 226px !important;
}
.page-manage-btn {
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(255,255,255,0.85);
  border: none; cursor: pointer;
  display: none; /* 默认隐藏，reader/edit 态才显示 */
  align-items: center; justify-content: center;
  box-shadow: 0 1px 6px rgba(0,0,0,0.10);
  transition: transform 0.15s, opacity 0.2s;
  padding: 0; flex-shrink: 0;
}
.page-manage-btn:active { transform: scale(0.85); }
.page-manage-btn svg { width: 12px; height: 12px; stroke: #555; stroke-width: 2.2; fill: none; stroke-linecap: round; }
.page-manage-btn.pm-visible { display: flex; }

/* 编辑态 */
.edit-page-tag-inline { font-size: 11px; color: #999; letter-spacing: 0.3px; padding: 0 8px 0 4px; }
#editToolbar {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: #fff; border-radius: 20px 20px 0 0;
  padding: 6px 0 calc(12px + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32,0.72,0,1);
  z-index: 400; box-shadow: 0 -1px 0 rgba(0,0,0,0.06), 0 -4px 24px rgba(0,0,0,0.08);
}
#editToolbar.toolbar-in { transform: translateY(0); }
/* ★ v=am8e: toolbar-handle 已删除（原本是灰色小横条，无用还占空间） */
.toolbar-tools  { display: flex; justify-content: center; gap: 4px; padding: 0 16px; }
.edit-tool {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  cursor: pointer; transition: transform 0.15s; flex: 1; max-width: 58px;
  padding: 4px 0;
}
.edit-tool:active { transform: scale(0.88); }
.edit-tool-icon {
  width: 44px; height: 44px; border-radius: 14px;
  background: #f5f5f5;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.edit-tool:active .edit-tool-icon { background: #ebebeb; }
.edit-tool-icon svg { width: 20px; height: 20px; stroke: #444; stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.edit-tool-label { font-size: 10px; color: #777; letter-spacing: 0.2px; font-weight: 500; }

/* 模版操作浮层 */
#templatePicker {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: #fff; border-radius: 20px 20px 0 0;
  padding: 12px 0 0; z-index: 450;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32,0.72,0,1);
  box-shadow: 0 -4px 32px rgba(0,0,0,0.12);
  max-height: 60%; overflow: hidden;
  display: flex; flex-direction: column;
}
#templatePicker.tp-open { transform: translateY(0); }

/* ─── 素材库面板 ─── */
#assetPanel {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: #fff; border-radius: 20px 20px 0 0;
  padding: 12px 0 env(safe-area-inset-bottom, 0); z-index: 460;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32,0.72,0,1);
  box-shadow: 0 -4px 32px rgba(0,0,0,0.12);
  /* am9M: 对齐模板浮层高度，防止内容少时浮层缩太小导致书页缩放算错 */
  min-height: 40vh; max-height: 60%; overflow: hidden;
  display: flex; flex-direction: column;
}
#assetPanel.ap-open { transform: translateY(0); }
.ap-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 20px 0 20px;              /* am9R3：左右都留 20px，视觉留白 */
  margin-bottom: 10px; flex-shrink: 0;
  position: relative;
  z-index: 3;
  gap: 12px;
}
.ap-header-left { flex: 1; min-width: 0; padding-right: 4px; }
.ap-header-right {
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
  padding-right: 44px;                   /* am9R3：给右上角 X 按钮留出安全区 */
}
/* am9R2：本页不放图按钮（灰底小胶囊） */
.ap-noimg-btn {
  height: 32px; padding: 0 12px;
  border-radius: 8px; border: 1px solid #e8e8e8;
  background: #fff; color: #555;
  font-size: 12px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
.ap-noimg-btn:active { background: #f5f5f5; }
/* am9R2：应用 / 删除按钮（副标题右侧灰底方块） */
.ap-side-btn {
  width: 34px; height: 34px; padding: 0;
  border-radius: 8px; border: none;
  background: #f3f3f3; color: #333;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
.ap-side-btn:active { background: #e8e8e8; }
.ap-title { font-size: 15px; font-weight: 600; color: #1a1a1a; }
.ap-subtitle { font-size: 11px; color: #999; margin-top: 2px; }
.ap-close {
  /* 44×44 真实命中区，视觉圆 26px（用 radial-gradient 画出灰底） */
  width: 44px; height: 44px;
  border-radius: 50%;
  color: #888; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; flex-shrink: 0;
  background:
    radial-gradient(circle at center, #f3f3f3 0, #f3f3f3 13px, transparent 13.5px);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  z-index: 2;
}
.ap-close:active {
  background:
    radial-gradient(circle at center, #e5e5e5 0, #e5e5e5 13px, transparent 13.5px);
}

/* ═════════ 通用浮层关闭按钮（绝对定位，44×44 命中区） ═════════
 * 用法：直接放在浮层 (#bgPicker / #coverEditor / #templatePicker) 内部任意位置
 * 命中区 44×44，视觉是 28px 灰圆，位置固定在浮层右上角内侧
 * 不依赖 header 布局、不受 overflow:hidden 裁切影响
 */
.panel-close {
  position: absolute;
  top: 4px; right: 4px;
  width: 44px; height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: #888;
  background:
    radial-gradient(circle at center, #f3f3f3 0, #f3f3f3 14px, transparent 14.5px);
  -webkit-tap-highlight-color: transparent;
  z-index: 10;
  user-select: none; -webkit-user-select: none;
}
.panel-close:active {
  background:
    radial-gradient(circle at center, #e5e5e5 0, #e5e5e5 14px, transparent 14.5px);
}
.ap-action-row {
  display: flex; gap: 8px; padding: 0 16px 10px;
  flex-shrink: 0;
}
.ap-add-btn, .ap-apply-btn {
  flex: 1; min-height: 38px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  gap: 6px; font-size: 13px; font-weight: 500;
  border: none; cursor: pointer; transition: opacity 0.2s, background 0.2s;
}
/* 添加图片：黑底白字 */
.ap-add-btn { background: #1a1a1a; color: #fff; }
.ap-add-btn:active { opacity: 0.8; }
/* 应用到当前页：灰底黑字（不抢戏，跟添加图片同级） */
.ap-apply-btn { background: #f3f3f3; color: #1a1a1a; }
.ap-apply-btn:active { background: #e8e8e8; }
.ap-apply-btn:disabled { opacity: 0.4; cursor: not-allowed; }
/* 批量删除按钮：方形 icon，灰底，选中数为 0 时禁用 */
.ap-del-batch-btn {
  width: 38px; min-height: 38px; padding: 0;
  border-radius: 10px; border: none; cursor: pointer;
  background: #f3f3f3; color: #1a1a1a;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s, background 0.2s;
}
.ap-del-batch-btn:active { background: #e8e8e8; }
.ap-del-batch-btn:disabled { opacity: 0.4; cursor: not-allowed; }
/* 网格：3 列正方形格子，图按原比例完整显示（contain，不裁切） */
/* 关键：grid + grid-auto-rows + width 计算，比 aspect-ratio 在 iOS Safari 更稳 */
.ap-grid {
  display: grid !important;
  grid-template-columns: repeat(3, 1fr) !important;
  grid-auto-rows: 1fr !important;
  gap: 8px !important;
  padding: 4px 20px 20px;                /* am9R3：与标题左右留白对齐 */
  overflow-y: auto;
  flex: 1; min-height: 0;
}
/* 每个格子：用 padding-bottom: 100% 强制正方形（iOS Safari 100% 支持，比 aspect-ratio 更兼容） */
.ap-grid-item {
  position: relative !important;
  width: 100% !important;
  padding-bottom: 100% !important;  /* 高度 = 宽度，强制正方形 */
  height: 0 !important;
  border-radius: 8px;
  background: #f3f3f3;
  cursor: pointer;
  border: 2px solid transparent;
  overflow: hidden;
}
.ap-grid-item.ap-selected { border-color: #2a8b3f; }
.ap-grid-item > img {
  position: absolute !important;
  top: 0 !important; left: 0 !important;
  width: 100% !important; height: 100% !important;
  object-fit: contain !important;
  background: #fafafa;
  pointer-events: none;
}
.ap-grid-item.ap-selected { border-color: #1a1a1a; }
.ap-grid-item.ap-selected::after {
  content: ''; position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.18);
}
.ap-grid-item .ap-sel-badge {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; color: #1a1a1a; font-size: 12px; font-weight: 700;
  display: none; align-items: center; justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.ap-grid-item.ap-selected .ap-sel-badge { display: flex; }
.ap-grid-item .ap-del-btn {
  position: absolute; top: 3px; right: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(0,0,0,0.55); color: #fff;
  font-size: 11px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; opacity: 0; transition: opacity 0.15s;
}
.ap-grid-item:hover .ap-del-btn { opacity: 1; }
.ap-grid-item.ap-selected .ap-del-btn { display: none; }
.ap-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 20px 20px 30px; gap: 10px;
}
/* am9R2：空态时浮层收紧一点，避免圆和标题距离太远 */
#assetPanel.ap-empty-mode { min-height: 32vh; }
/* am9R：空态大圆按钮 */
.ap-empty-circle {
  width: 72px; height: 72px; border-radius: 50%;
  background: #f3f3f3; color: #666;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.ap-empty-circle:active { background: #e5e5e5; }
.ap-empty-hint { color: #888; font-size: 13px; }
/* am9R：网格末尾"+"卡片，虚线正方形 */
.ap-add-tile {
  position: relative !important;
  width: 100% !important;
  padding-bottom: 100% !important;
  height: 0 !important;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  border: 1.5px dashed #d0d0d0;
  box-sizing: border-box;
  transition: background 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.ap-add-tile:active { background: #f5f5f5; border-color: #aaa; }
.ap-add-tile > svg {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  color: #bbb;
}
/* am9R2：删除废弃的 .ap-topbar / .ap-top-* / .ap-source-* 样式（这些结构已不用） */
.tp-handle { width: 36px; height: 4px; background: #e0e0e0; border-radius: 2px; margin: 0 auto 10px; flex-shrink: 0; }
.tp-header-row {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 0 20px; margin-bottom: 14px; flex-shrink: 0;
}
.tp-title { font-size: 15px; font-weight: 700; color: #1a1a1a; margin-bottom: 4px; letter-spacing: -0.3px; }
.tp-subtitle { font-size: 11px; color: #aaa; }
.tp-close-btn {
  width: 28px; height: 28px; border-radius: 50%; background: #f0f0f0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: #999; cursor: pointer; flex-shrink: 0;
  transition: background 0.15s;
}
.tp-close-btn:active { background: #e0e0e0; }
.tp-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 32px; }
.tp-body::-webkit-scrollbar { display: none; }

/* Step 1: 选择图片来源 */
.tp-source-row {
  display: flex; gap: 10px; padding: 0 20px; margin-bottom: 16px;
}
.tp-source-btn {
  flex: 1; height: 64px; border-radius: 16px;
  border: 1.5px solid #eee; background: #fafafa;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; cursor: pointer; transition: all 0.15s;
}
.tp-source-btn:active { transform: scale(0.96); background: #f0f0f0; }
.tp-source-btn .tp-src-icon { display: flex; align-items: center; justify-content: center; }
.tp-source-btn .tp-src-icon svg { width: 22px; height: 22px; stroke: #444; stroke-width: 1.8; fill: none; }
.tp-source-btn .tp-src-label { font-size: 11px; color: #666; font-weight: 500; }

/* 已上传图片预览 */
.tp-uploaded-row {
  padding: 0 20px; margin-bottom: 16px; display: none;
}
.tp-uploaded-row.has-imgs { display: block; }
.tp-uploaded-label { font-size: 11px; color: #aaa; letter-spacing: 0.3px; margin-bottom: 8px; text-transform: uppercase; }
.tp-uploaded-grid {
  display: flex; gap: 6px; flex-wrap: wrap;
}
.tp-uploaded-thumb {
  width: 52px; height: 52px; border-radius: 10px;
  overflow: hidden; position: relative; flex-shrink: 0;
  border: 1.5px solid #eee;
}
.tp-uploaded-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tp-uploaded-thumb .tp-thumb-del {
  position: absolute; top: 2px; right: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: rgba(0,0,0,0.5); color: #fff;
  font-size: 10px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; line-height: 1;
}
.tp-uploaded-add {
  width: 52px; height: 52px; border-radius: 10px;
  border: 1.5px dashed #ddd; background: #fafafa;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: #ccc; cursor: pointer;
  transition: background 0.15s;
}
.tp-uploaded-add:active { background: #f0f0f0; }

/* Step 2: 模版变体选择 */
.tp-variants-section { padding: 0 20px; margin-bottom: 16px; display: none; }
.tp-variants-section.has-imgs { display: block; }
.tp-variants-label { font-size: 11px; color: #aaa; letter-spacing: 0.3px; margin-bottom: 10px; text-transform: uppercase; }
/* 排版分类 tab */
.tp-variants-tabs {
  display: flex; gap: 0; margin-bottom: 12px; border-radius: 8px;
  overflow: hidden; border: 1.5px solid #eee;
}
.tp-variants-tab {
  flex: 1; padding: 7px 0; text-align: center;
  font-size: 12px; font-weight: 600; color: #999;
  background: #fafafa; cursor: pointer;
  transition: all 0.18s; border: none; outline: none;
  letter-spacing: 0.2px;
}
.tp-variants-tab:not(:last-child) { border-right: 1.5px solid #eee; }
.tp-variants-tab.tp-tab-active {
  background: #1a1a1a; color: #fff;
}
.tp-variants-tab:active { opacity: 0.7; }
.tp-variants-grid {
  display: flex; gap: 8px; overflow-x: auto;
  -webkit-overflow-scrolling: touch; padding-bottom: 4px;
}
.tp-variants-grid::-webkit-scrollbar { display: none; }
.tp-variant-card {
  flex-shrink: 0; width: 80px; cursor: pointer;
  transition: transform 0.15s;
}
.tp-variant-card:active { transform: scale(0.95); }
.tp-variant-preview {
  width: 80px; height: 113px; border-radius: 8px;
  border: 2px solid #eee; overflow: hidden;
  position: relative; background: #FFFFFF;
  transition: border-color 0.2s;
}
/* ★ 模板预览卡片：把 render() 出来的原始尺寸内容等比缩到 80x113
   render 内容按 .hires-wrap 基准尺寸 320x452 编写（字号、padding 都基于此），
   缩到 80x113 即 scale = 80/320 = 0.25
   必须强制清 inset：render 根元素带 position:absolute;inset:0 会撑满父容器 */
.tp-variant-preview > * {
  position: absolute !important;
  top: 0 !important; left: 0 !important;
  right: auto !important; bottom: auto !important;
  transform: scale(0.25) !important;
  transform-origin: top left !important;
  width: 320px !important;
  height: 452px !important;
  pointer-events: none !important;
}
.tp-variant-card.tp-v-selected .tp-variant-preview { border-color: #1a1a1a; }
.tp-variant-name { font-size: 10px; color: #999; text-align: center; margin-top: 5px; letter-spacing: 0.2px; }

/* 色块颜色选择 */
.tp-color-section { padding: 0 20px; margin-bottom: 16px; display: none; }
.tp-color-section.has-imgs { display: block; }
.tp-color-label { font-size: 11px; color: #aaa; letter-spacing: 0.3px; margin-bottom: 8px; text-transform: uppercase; }
.tp-color-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tp-color-dot {
  width: 28px; height: 28px; border-radius: 50%;
  cursor: pointer;
  /* 不再用 border 占透明边（会把彩虹挤小），改用 box-shadow 做选中外环 */
  transition: transform 0.12s, box-shadow 0.15s;
  position: relative;
}
.tp-color-dot:active { transform: scale(0.88); }
/* 只有真正被选中的色才出现外环 */
.tp-color-dot.tp-c-selected { box-shadow: 0 0 0 2px #1a1a1a; }
/* 自定义色圆点：彩虹渐变（默认）。用户选完色后由 JS 改 inline style.background 覆盖，
   所以不能用 !important，否则 JS 改不动 */
.tp-color-dot.tp-custom-dot {
  background: conic-gradient(from 0deg,
    hsl(0,90%,60%),hsl(30,90%,58%),hsl(60,90%,56%),
    hsl(90,80%,52%),hsl(120,75%,50%),hsl(150,75%,52%),
    hsl(180,80%,55%),hsl(210,85%,58%),hsl(240,85%,62%),
    hsl(270,80%,62%),hsl(300,80%,60%),hsl(330,85%,60%),
    hsl(360,90%,60%));
  overflow: hidden;
}
/* 编辑排版浮层的"自定义颜色"独占下一行：彩虹按钮在左，灰字在右 */
.tp-custom-row {
  width: 100%; display: flex; flex-direction: row; align-items: center;
  gap: 10px; margin-top: 8px;
}
.tp-custom-hint-inline { font-size: 12px; color: #aaa; letter-spacing: 0.2px; }
/* RGB 色板行 */
.tp-color-picker-row {
  display: none; margin-top: 10px; align-items: center; gap: 8px;
}
.tp-color-picker-row.tp-picker-open { display: flex; }
.tp-color-picker-row input[type="color"] {
  -webkit-appearance: none; appearance: none;
  width: 36px; height: 36px; border: 2px solid #e0e0e0; border-radius: 50%;
  padding: 0; cursor: pointer; background: none; overflow: hidden;
}
.tp-color-picker-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.tp-color-picker-row input[type="color"]::-webkit-color-swatch { border: none; border-radius: 50%; }
.tp-color-hex {
  font-size: 12px; color: #999; font-family: 'SF Mono', 'Menlo', monospace;
  letter-spacing: 0.3px; min-width: 60px;
}

/* 确认按钮 sticky 在浮层底部，永远可见（v=h: 强制 display block，不依赖 has-imgs） */
#templatePicker .tp-confirm-row {
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom, 0));
  display: block !important; flex-shrink: 0;
  background: #fff;
  border-top: 1px solid #f0f0f0;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.04);
}
.tp-confirm-btn {
  width: 100%; height: 48px; border: none; border-radius: 14px;
  background: #1a1a1a; color: #fff; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: transform 0.15s, opacity 0.15s;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.tp-confirm-btn:active { transform: scale(0.97); opacity: 0.85; }
.tp-confirm-btn.tp-disabled { opacity: 0.4; }
.tp-confirm-btn.tp-disabled:active { transform: none; opacity: 0.4; }

/* 导出浮层 */
#exportOverlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.5); z-index: 600;
  display: none; align-items: center; justify-content: center;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
#exportOverlay.ex-open { display: flex; }
#exportPanel {
  background: #fff; border-radius: 20px;
  padding: 24px; width: 300px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  animation: exportIn 0.3s ease;
}
@keyframes exportIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.ex-title { font-size: 18px; font-weight: 700; color: #1a1a1a; margin-bottom: 6px; letter-spacing: -0.3px; }
.ex-desc { font-size: 12px; color: #999; margin-bottom: 20px; }
.ex-btn {
  width: 100%; height: 48px; border: none; border-radius: 14px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform 0.15s, background 0.15s;
  margin-bottom: 10px;
}
.ex-btn:active { transform: scale(0.97); }
.ex-btn-primary { background: #1a1a1a; color: #fff; }
.ex-btn-secondary { background: #f4f4f4; color: #333; }
.ex-btn-cancel { background: none; color: #999; font-size: 13px; font-weight: 400; margin-bottom: 0; }
.ex-progress {
  width: 100%; height: 4px; background: #f0f0f0; border-radius: 2px;
  margin: 12px 0; overflow: hidden; display: none;
}
.ex-progress-bar {
  height: 100%; background: #1a1a1a; border-radius: 2px;
  width: 0%; transition: width 0.3s;
}
.ex-status { font-size: 11px; color: #aaa; text-align: center; display: none; }

/* 抠图 loading：当前页加毛玻璃模糊（位置反馈），小条挂屏幕顶部（状态反馈） */
.cutout-loading-overlay {
  position: absolute; inset: 0; z-index: 600;
  background: rgba(255,255,255,0.3);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  pointer-events: none;
}
.cutout-loading-card {
  position: fixed;
  top: 24px; left: 50%; transform: translateX(-50%);
  background: rgba(255,255,255,0.96);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex; align-items: center; gap: 8px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
  z-index: 9999;
}
.cutout-spinner {
  width: 14px; height: 14px;
  border: 2px solid #e0e0e0; border-top-color: #1a1a1a;
  border-radius: 50%;
  animation: cutoutSpin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes cutoutSpin { to { transform: rotate(360deg); } }
.cutout-loading-text {
  font-size: 12px; color: #1a1a1a; letter-spacing: 0.2px;
}
.cutout-loading-progress {
  font-size: 11px; color: #999; font-variant-numeric: tabular-nums;
  margin-left: 2px;
}

/* 抠图元素交互编辑 */
.cutout-item {
  position: absolute; touch-action: none;
  cursor: grab;
}
.cutout-item:active { cursor: grabbing; }
.cutout-item img {
  width: 100%; height: auto; display: block;
  pointer-events: none; user-select: none;
  -webkit-user-drag: none;
}
/* 选中态：灰色细虚线框（外边） + z-index 提升 */
.cutout-item.cutout-selected {
  z-index: 100 !important;
  outline: 1px dashed #999;
  outline-offset: 2px;
}
/* 抠图选中态按钮组容器 */
.cutout-btn-group {
  position: absolute;
  left: 50%; top: -6px;
  transform: translate(-50%, -100%);
  display: flex;
  gap: 6px;
  z-index: 300;
  pointer-events: auto;
}
/* 加入素材库 / 删除 气泡按钮：白底黑字，简洁风 */
.cutout-asset-btn, .cutout-del-btn {
  background: #fff;
  color: #333;
  border: none;
  border-radius: 10px;
  padding: 3px 9px;
  font-size: 10px;
  font-family: -apple-system, 'Helvetica Neue', sans-serif;
  font-weight: 400;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.cutout-asset-btn:active, .cutout-del-btn:active { background: #f5f5f5; }
/* Toast 提示（白底黑字，简洁） */
.simple-toast {
  position: fixed;
  top: 20%;
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  color: #333;
  padding: 8px 16px;
  border-radius: 16px;
  font-size: 12px;
  font-family: -apple-system, 'Helvetica Neue', sans-serif;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.simple-toast.show { opacity: 1; }

/* ★ v=am3/am5/am6：模板序号(07)可点击热区扩大
   用 ::after 伪元素做透明覆盖层，不影响原元素盒模型 → 布局不会被撑大 */
.tpl-num-editable {
  -webkit-tap-highlight-color: rgba(0,0,0,0.08);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
  /* ★ v=am7d：极高 z-index 保证永远在图片之上 */
  z-index: 999 !important;
  pointer-events: auto !important;
}
/* 只在编辑模式（body.is-editing）下加透明点击热区 */
body.is-editing .tpl-num-editable::after {
  content: '';
  position: absolute;
  left: -12px; right: -12px;
  top: -10px; bottom: -10px;
  /* 透明但可点击 */
  background: transparent;
  z-index: 1;
  pointer-events: auto;
}

/* ★ v=am7d：装饰文字（[Mind]/[ball]/body 等）在编辑态强制置顶 */
body.is-editing [data-tt-editable] {
  position: relative;
  z-index: 999 !important;
  pointer-events: auto !important;
  -webkit-tap-highlight-color: rgba(0,0,0,0.08);
}
/* am9P: 装饰文字始终禁用 Safari 双击缩放（不管是否编辑态） */
[data-tt-editable] {
  touch-action: manipulation;
}
/* 装饰文字热区扩大（编辑态） */
body.is-editing [data-tt-editable]::after {
  content: '';
  position: absolute;
  left: -8px; right: -8px;
  top: -6px; bottom: -6px;
  background: transparent;
  z-index: 1;
  pointer-events: auto;
}

/* ★ v=am3/am5/am6：抠图黄色序号 badge 点击热区扩大（伪元素透明层） */
.cutout-badge[data-badge-editable] {
  -webkit-tap-highlight-color: rgba(0,0,0,0.08);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  position: absolute; /* 已有的，确认一下 */
}
body.is-editing .cutout-badge[data-badge-editable]::after {
  content: '';
  position: absolute;
  left: -10px; right: -10px;
  top: -8px; bottom: -8px;
  background: transparent;
  z-index: 1;
}
/* 拖拽中：只提升 z-index，不加 filter，保持画面干净 */
.cutout-item.cutout-dragging {
  z-index: 200 !important;
}

/* ── 抠图操纵杆面板 ── */
#cutoutJoystick {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: #fff; border-radius: 20px 20px 0 0;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 420;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32,0.72,0,1);
  box-shadow: 0 -4px 24px rgba(0,0,0,0.10);
}
#cutoutJoystick.cj-open { transform: translateY(0); }

.cj-handle { width: 36px; height: 4px; background: #e0e0e0; border-radius: 2px; margin: 0 auto 6px; }
.cj-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.cj-title { font-size: 13px; font-weight: 600; color: #1a1a1a; letter-spacing: -0.2px; }
.cj-close-btn {
  width: 26px; height: 26px; border-radius: 50%; background: #f0f0f0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: #999; cursor: pointer; transition: background 0.15s;
}
.cj-close-btn:active { background: #e0e0e0; }

/* 元素选择条 */
.cj-items-row {
  display: flex; gap: 6px; overflow-x: auto; padding: 0 0 8px;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.cj-items-row::-webkit-scrollbar { display: none; }
.cj-item-thumb {
  width: 40px; height: 40px; border-radius: 10px; overflow: hidden;
  border: 2px solid transparent; flex-shrink: 0; cursor: pointer;
  background: #f5f5f5; display: flex; align-items: center; justify-content: center;
  transition: border-color 0.15s, transform 0.15s;
}
.cj-item-thumb:active { transform: scale(0.92); }
.cj-item-thumb.cj-thumb-active { border-color: #ff5a5a; }
.cj-item-thumb img {
  width: 100%; height: 100%; object-fit: contain;
  pointer-events: none; user-select: none;
}

/* 控制区域 */
.cj-controls {
  display: none; /* 未选中时隐藏 */
  gap: 12px; align-items: center; padding-top: 6px;
}
.cj-controls.cj-has-selection { display: flex; }

/* 摇杆 */
.cj-joystick-wrap {
  width: 90px; height: 90px; flex-shrink: 0;
  position: relative;
}
.cj-joystick-ring {
  width: 100%; height: 100%; border-radius: 50%;
  border: 2px solid #e8e8e8; background: #fafafa;
  position: relative; touch-action: none;
}
.cj-joystick-knob {
  width: 32px; height: 32px; border-radius: 50%;
  background: #1a1a1a; position: absolute;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  cursor: grab; touch-action: none;
  transition: box-shadow 0.15s;
}
.cj-joystick-knob:active { cursor: grabbing; box-shadow: 0 0 0 4px rgba(26,26,26,0.15); }
.cj-joystick-crosshair {
  position: absolute; top: 50%; left: 50%;
  width: 60%; height: 60%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.cj-joystick-crosshair::before,
.cj-joystick-crosshair::after {
  content: ''; position: absolute; background: #e0e0e0;
}
.cj-joystick-crosshair::before {
  width: 1px; height: 100%; left: 50%; top: 0;
}
.cj-joystick-crosshair::after {
  height: 1px; width: 100%; top: 50%; left: 0;
}

/* 滑块区域 */
.cj-sliders {
  flex: 1; display: flex; flex-direction: column; gap: 10px;
  min-width: 0;
}
.cj-slider-row {
  display: flex; align-items: center; gap: 8px;
}
.cj-slider-label {
  font-size: 10px; color: #999; width: 24px; flex-shrink: 0;
  text-align: right; letter-spacing: 0.2px;
}
.cj-slider-track {
  flex: 1; height: 28px; position: relative;
  display: flex; align-items: center;
}
.cj-slider-track input[type="range"] {
  width: 100%; height: 4px; -webkit-appearance: none; appearance: none;
  background: #eee; border-radius: 2px; outline: none;
}
.cj-slider-track input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px;
  border-radius: 50%; background: #1a1a1a; cursor: pointer;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.cj-slider-value {
  font-size: 10px; color: #bbb; width: 30px; text-align: left;
  font-variant-numeric: tabular-nums;
}

/* 层级按钮 */
.cj-layer-btns {
  display: flex; gap: 4px; justify-content: center; padding-top: 4px;
}
.cj-layer-btn {
  width: 32px; height: 26px; border-radius: 6px;
  border: 1.5px solid #eee; background: #fafafa;
  font-size: 12px; cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  color: #888; transition: all 0.15s;
}
.cj-layer-btn:active { background: #eee; transform: scale(0.92); }

/* ═══ 文字系统 ═══ */

/* 页面上的文字元素（渲染在书页内，跟着 scale 走） */
.te-text-item {
  position: absolute; z-index: 50;
  padding: 2px 4px;
  cursor: default;
  word-break: break-word; line-height: 1.4;
  pointer-events: auto;
  -webkit-user-select: none; user-select: none;
  /* am9O: 禁用 Safari 双击缩放，只保留 tap/pan */
  touch-action: manipulation;
}
/* ★ v=al7：装饰文字转来的 textItem 不换行，宽度自适应 */
.te-text-item.te-nowrap {
  white-space: nowrap !important;
  word-break: normal !important;
  width: auto !important;
  max-width: none !important;
}
/* ★ v=al7：装饰文字转来的 textItem 不换行，宽度自适应 */
.te-text-item.te-nowrap {
  white-space: nowrap !important;
  word-break: normal !important;
  width: auto !important;
  max-width: none !important;
}
/* 编辑模式下的文字 — 可点击/可拖拽 */
.te-text-item.te-editable {
  cursor: grab; border: 1px dashed transparent; border-radius: 3px;
  transition: border-color 0.15s;
  /* am9Q6：改 none → manipulation 阻止 Safari 双击缩放；拖动是手动 pointerdown 处理，不受影响 */
  touch-action: manipulation;
  -webkit-user-drag: none;
  /* 空文字也有最小可见区，让用户能看到位置 + 手柄不塌陷 */
  min-width: 24px; min-height: 16px;
}
.te-text-item.te-editable:hover { border-color: rgba(0,120,255,0.35); }
.te-text-item.te-text-item-active {
  border-color: rgba(0,120,255,0.7) !important;
  box-shadow: 0 0 0 2px rgba(0,120,255,0.12);
}

/* 右下角缩放手柄 — 仅编辑态显示 */
.te-sticker-resize {
  display: none;
  position: absolute;
  right: -7px; bottom: -7px;
  width: 14px; height: 14px;
  background: #fff;
  border: 1.5px solid rgba(0,120,255,0.8);
  border-radius: 50%;
  cursor: nwse-resize;
  touch-action: none;
  z-index: 2;
  box-shadow: 0 1px 4px rgba(0,0,0,0.18);
}
/* ★ v=am8l：手柄默认不显示，只在 hover / 选中(active) 时才显示
   之前 .te-editable 就显示 → 用户拖文字时手指容易误触手柄，把宽度改成很小 */
.te-text-item.te-editable:hover .te-sticker-resize,
.te-text-item.te-text-item-active .te-sticker-resize {
  display: block;
  background: #1080ff;
  border-color: #fff;
}

/* ── 文字编辑高浮层（v=am9 轻量版） ── */
#teInputBar {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: #fff; border-radius: 20px 20px 0 0;
  z-index: 480; transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32,0.72,0,1);
  box-shadow: 0 -4px 24px rgba(0,0,0,0.10);
  padding: 0 0 env(safe-area-inset-bottom, 0px);
  /* v=am9：不再限制 max-height + 滚动 —— 浮层内容极简，一屏必然够 */
}
#teInputBar.te-open { transform: translateY(0); }

/* v=am9：轻量 header —— 只保留标题居中，无按钮 */
.te-ib-header-lite {
  display: flex; align-items: center; justify-content: center;
  padding: 4px 16px 6px;
  background: #fff;
}
.te-ib-header-lite .te-ib-title {
  font-size: 13px; font-weight: 500; color: #666;
}

/* v=am9：tab 横条 */
.te-tabbar {
  display: flex; align-items: center; gap: 4px;
  padding: 4px 16px 8px;
  border-bottom: 1px solid #f2f2f2;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.te-tabbar::-webkit-scrollbar { display: none; }
.te-tab {
  flex-shrink: 0;
  padding: 6px 12px;
  font-size: 13px; color: #999; font-weight: 500;
  cursor: pointer;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
  user-select: none; -webkit-user-select: none;
}
.te-tab:active { background: #f5f5f5; }
.te-tab.te-tab-active {
  color: #1a1a1a; font-weight: 700;
}

/* v=am9：tab 内容行 —— 默认全部隐藏，只在对应 tab 激活时显示 */
.te-row-tab { display: none !important; }
.te-row-tab.te-row-tab-active { display: flex !important; }

/* 顶部拖把（仿其他浮层） */
.te-ib-grabber {
  width: 36px; height: 4px; background: #e0e0e0; border-radius: 2px;
  margin: 8px auto 4px;
  flex-shrink: 0;
}

/* 头部：取消 / 标题 / 完成 */
.te-ib-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 16px 8px;
  position: sticky; top: 0; background: #fff; z-index: 2;
  border-bottom: 1px solid #f2f2f2;
}
.te-ib-title { font-size: 14px; font-weight: 600; color: #1a1a1a; }
.te-ib-btn {
  height: 32px; padding: 0 16px; border-radius: 8px; border: none;
  font-size: 13px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.te-ib-btn:active { transform: scale(0.95); }
.te-ib-btn-done { background: #1a1a1a; color: #fff; }
.te-ib-btn-cancel { background: #f0f0f0; color: #666; }

/* 输入框 */
.te-ib-input-wrap { padding: 12px 16px 4px; }
#teInput {
  width: 100%; min-height: 40px; max-height: 100px;
  border: 1.5px solid #e8e8e8; border-radius: 12px;
  padding: 8px 12px; font-size: 15px; line-height: 1.4;
  resize: none; outline: none; font-family: inherit;
  transition: border-color 0.15s; background: #fafafa;
  box-sizing: border-box;
}
#teInput:focus { border-color: #1a1a1a; background: #fff; }

/* 控件分行容器 */
.te-ib-rows { padding: 8px 16px 16px; min-height: 44px; }
.te-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0;
  /* v=am9：轻量版一次只显示 1 行 tab 内容，不再需要行间分隔线 */
}
.te-row:last-child { border-bottom: none; }
.te-row-label {
  /* v=am9：tab 已经在上面标了名，这里 label 不再需要 */
  display: none;
}
.te-row-ctrl {
  flex: 1; display: flex; align-items: center; gap: 10px;
  min-width: 0; /* 允许子元素 ellipsis */
}
.te-row-scroll {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  gap: 8px; padding-right: 8px;
}
.te-row-scroll::-webkit-scrollbar { display: none; }

/* 颜色圆点（行内）：所有色块尺寸严格等大 */
.te-color-dot {
  width: 24px; height: 24px; border-radius: 50%; cursor: pointer;
  border: 1px solid #e0e0e0; /* 固定细边，不会动盒子 */
  box-sizing: border-box;
  flex-shrink: 0;
  transition: transform 0.12s, box-shadow 0.15s;
  padding: 0;
  background-clip: padding-box; /* 防止白色色块被边色透出来 */
}
.te-color-dot:active { transform: scale(0.88); }
.te-color-dot.te-c-active {
  /* 选中：用 box-shadow 做双圈，盒模型不变 */
  box-shadow: 0 0 0 2px #1a1a1a, inset 0 0 0 2px #fff;
}

/* 彩虹自定义色块（首位） */
.te-color-dot-rainbow {
  background: conic-gradient(
    from 0deg,
    #ff4d4d, #ffae00, #ffe600, #6fd64d,
    #4dc8ff, #4d6aff, #c14dff, #ff4dbf, #ff4d4d
  );
  position: relative;
  /* 当它是 <label> 时，确保对内部 input 的点击穿透到 label */
  display: inline-block;
}
.te-color-dot-rainbow::after {
  /* 中心小白点提示这是"自定义" */
  content: ''; position: absolute;
  left: 50%; top: 50%;
  width: 8px; height: 8px;
  background: #fff;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 2px rgba(0,0,0,0.2);
  pointer-events: none; /* 不挡 label 点击 */
}

/* 隐藏的原生 color picker：必须留在文档流里，iOS 才弹得出 */
.te-color-picker-hidden {
  position: absolute;
  left: 50%; top: 0;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
  border: 0;
}

/* （字体卡片已移除：不再让用户选字体） */

/* 通用滑块 */
.te-slider {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 4px; border-radius: 2px; background: #e5e5e5; outline: none;
  min-width: 80px;
}
.te-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: #1a1a1a; cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.te-slider::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%; border: none;
  background: #1a1a1a; cursor: pointer;
}
.te-slider-val {
  font-size: 12px; color: #555; min-width: 36px; text-align: right;
  font-variant-numeric: tabular-nums;
}

/* 格式按钮组 */
.te-fmt-row { gap: 10px; }
.te-style-btn {
  width: 36px; height: 36px; border-radius: 8px; border: 1.5px solid #eee;
  background: #fafafa; display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 0.15s; flex-shrink: 0;
  font-size: 14px; color: #555; font-weight: 600;
}
.te-style-btn:active { transform: scale(0.9); }
.te-style-btn.te-active { background: #1a1a1a; color: #fff; border-color: #1a1a1a; }

/* ★ 装饰文字模式（模板 body / [ball] / Music* 等）：
   v=am9 更新：只显示"字号" tab，其他 tab 隐藏，避免用户误触发丑陋样式 */
#teInputBar.te-tt-decor-mode .te-tab:not([data-tab="size"]) {
  display: none !important;
}
#teInputBar.te-tt-decor-mode .te-row-tab:not([data-tab="size"]) {
  display: none !important;
}

/* ── v=am9：文字/贴纸头顶操作条 ── */
#teActionBar {
  position: absolute;
  z-index: 470;
  background: #fff;
  border-radius: 999px;
  padding: 4px 6px;
  display: flex;
  align-items: center;
  gap: 2px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.14), 0 0 0 1px rgba(0,0,0,0.04);
  pointer-events: auto;
  transition: opacity 0.15s;
}
.te-act-btn {
  width: 36px; height: 36px;
  border: none; background: transparent;
  border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: #333;
  transition: background 0.12s, transform 0.1s;
}
.te-act-btn:active { transform: scale(0.9); background: #f0f0f0; }
.te-act-btn.te-act-btn-danger { color: #d33; }

/* 删除按钮：右下角浮动（中性灰，符合黑白灰视觉规范） */
.te-ib-btn-del {
  position: absolute;
  right: 14px;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  width: 38px; height: 38px; border-radius: 50%;
  background: #fafafa; border: 1.5px solid #e5e5e5;
  color: #666; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  transition: all 0.15s; padding: 0;
  z-index: 3;
}
.te-ib-btn-del:active { transform: scale(0.9); background: #f0f0f0; }

/* ═════════════════════════════════════════════════
   导出第二步：缩略图勾选面板
   ═════════════════════════════════════════════════ */
#exPickerOverlay {
  position: fixed; inset: 0; z-index: 1300;
  background: rgba(0,0,0,0.55);
  display: none; align-items: stretch; justify-content: center;
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
#exPickerPanel {
  width: 100%; max-width: 480px; margin: auto;
  height: 90vh; max-height: 760px;
  background: #fff; border-radius: 18px;
  display: flex; flex-direction: column;
  overflow: hidden; box-shadow: 0 12px 48px rgba(0,0,0,0.25);
}
.exp-header {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 10px; border-bottom: 1px solid #f0f0f0;
}
.exp-title { font-size: 16px; font-weight: 600; color: #1a1a1a; }
.exp-close {
  width: 28px; height: 28px; border-radius: 50%;
  background: #f3f3f3; color: #666;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; cursor: pointer; user-select: none;
}
.exp-close:active { background: #e5e5e5; }
.exp-toolbar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px; border-bottom: 1px solid #f5f5f5;
}
.exp-tool-btn {
  padding: 5px 12px; font-size: 12px;
  border: 1px solid #ddd; border-radius: 14px;
  background: #fff; color: #333; cursor: pointer;
}
.exp-tool-btn:active { background: #f3f3f3; }
.exp-count { margin-left: auto; font-size: 12px; color: #888; }
.exp-grid {
  flex: 1 1 auto; overflow-y: auto;
  display: grid; grid-template-columns: repeat(3, 1fr); /* ★ 一排 3 个 */
  gap: 10px; padding: 14px;
  -webkit-overflow-scrolling: touch;
}
.exp-card {
  position: relative; cursor: pointer; user-select: none;
  border-radius: 10px; overflow: hidden;
  border: 2px solid transparent;
  background: #fafafa;
  opacity: 0.55; /* ★ 默认未选中：半透明灰 */
  transition: border-color .15s, transform .1s, opacity .15s, box-shadow .15s;
}
.exp-card.selected {
  border-color: #1a1a1a;
  opacity: 1; /* ★ 选中：黑色边框 + 完全不透明 */
  box-shadow: 0 0 0 1px rgba(0,0,0,0.06);
}
.exp-card:active { transform: scale(0.97); }
/* ★ 缩略图：正方形（aspect-ratio 兜底 + JS 强写 height = width） */
.exp-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1; /* CSS 兜底 */
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
/* ★ inner 容器按真实页尺寸 640x904 渲染，居中后用 scale 整体缩放至完全装进正方形 thumb（letterbox 留白） */
.exp-thumb-inner {
  position: absolute;
  left: 50%; top: 50%;
  width: 640px;
  height: 904px;
  transform-origin: center center;
  transform: translate(-50%, -50%) scale(var(--exp-scale, 0.15));
  pointer-events: none;
  background: #fff;
}
.exp-check {
  position: absolute; top: 6px; right: 6px;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(255,255,255,0.92);
  color: #bbb; border: 1.5px solid #d8d8d8;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
  transition: all .15s;
}
.exp-card.selected .exp-check {
  background: #1a1a1a; color: #fff; border-color: #1a1a1a;
}
.exp-label {
  text-align: center; font-size: 11px; color: #666;
  padding: 6px 0 4px;
}
.exp-footer {
  flex: 0 0 auto;
  padding: 12px 18px 16px;
  border-top: 1px solid #f0f0f0;
  background: #fff;
}
.exp-confirm-btn {
  width: 100%; height: 44px; border-radius: 22px;
  background: #1a1a1a; color: #fff; font-size: 15px; font-weight: 600;
  border: none; cursor: pointer;
}
.exp-confirm-btn:disabled {
  background: #e0e0e0; color: #999; cursor: not-allowed;
}
.exp-confirm-btn:not(:disabled):active { background: #000; }
.exp-tip {
  text-align: center; font-size: 11px; color: #aaa;
  margin-top: 8px;
}

/* ════════════════════════════════════════
   模板内的占位文字（如 "点击「文字」添加内容"）
   - 默认 pointer-events:none，不挡其它操作
   - 只在编辑态变成可点（由 body[data-studio-state="edit"] 控制）
   - 导出路径会直接剥掉这类节点（_stripPlaceholders），所以不会出现在成品里
   ════════════════════════════════════════ */
.tpl-placeholder {
  pointer-events: none;
  user-select: none;
  font-style: italic;
  opacity: 0.85;
  transition: color 0.15s, opacity 0.15s;
}
body[data-studio-state="edit"] .tpl-placeholder {
  pointer-events: auto;
  cursor: pointer;
}
body[data-studio-state="edit"] .tpl-placeholder:hover {
  color: #888 !important;
  opacity: 1;
}

/* ── am9L：文字头顶操作条 ── */
#teQuickBar {
  position: fixed;
  z-index: 490;
  display: flex;
  gap: 4px;
  padding: 4px;
  background: #1a1a1a;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  transform: translate(-50%, -100%);
  /* JS 会设置 left/top，这里只定基础样式 */
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
}
#teQuickBar .te-qb-btn {
  width: 28px; height: 28px;
  padding: 0;
  background: transparent;
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.12s;
}
#teQuickBar .te-qb-btn:active {
  background: rgba(255,255,255,0.15);
}
/* 底部小三角，指向文字 */
#teQuickBar::after {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid #1a1a1a;
}

/* ── am9M：纯享模式（阅读态隐藏所有工具栏） ── */
body.pure-view #studioNav,
body.pure-view #pageIndicator,
body.pure-view #editToolbar {
  display: none !important;
}
/* 纯享模式提示 toast */
.pure-view-toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.82);
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 99999;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s;
}
.pure-view-toast.show { opacity: 1; }
