/* ===== Local Reset =====
 * 这里原本通过 CDN @import 引入 Tailwind。但项目实际并未使用任何 Tailwind 工具类
 * （HTML 中出现的 class 全部由本文件定义），@import 只是借用了它的 preflight
 * 来重置浏览器默认样式。
 * 依赖 CDN 会多一次跨域请求、且离线或墙内环境直接失效，样式基线随之丢失，
 * 对「图片不上传服务器」的隐私定位也不合适。
 * 因此改为内联等价的精简 reset，做到零外部请求、在线离线表现完全一致。
 */

html {
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

/* 去掉浏览器对标题/段落的默认外边距（原先依赖 Tailwind preflight） */
h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd {
  margin: 0;
}

ul, ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

/* 表单控件继承页面字体与配色，避免各浏览器默认样式不一致 */
button, input, optgroup, select, textarea {
  font-family: inherit;
  font-size: 100%;
  font-weight: inherit;
  line-height: inherit;
  color: inherit;
  margin: 0;
}

button, select {
  text-transform: none;
}

button, [type="button"], [type="reset"], [type="submit"] {
  -webkit-appearance: button;
  background-color: transparent;
  background-image: none;
}

button, [role="button"] {
  cursor: pointer;
}

/* 媒体元素按块级渲染，避免行内基线产生额外间隙 */
img, svg, video, canvas, audio, iframe, embed, object {
  display: block;
  vertical-align: middle;
}

img, video {
  max-width: 100%;
  height: auto;
}

/* ===== Design Tokens ===== */
:root {
  --primary-1: #6366F1;
  --primary-2: #8B5CF6;
  --primary-3: #3B82F6;
  --bg-1: #F5F7FB;
  --bg-2: #FFFFFF;
  --bg-3: #EEF2FF;
  --text-1: #1F2937;
  --text-2: #6B7280;
  --text-3: #FFFFFF;
  --ok: #10B981;
  --err: #EF4444;
  --warn: #F59E0B;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px -12px rgba(99, 102, 241, 0.35);
  --shadow-soft: 0 4px 16px -6px rgba(31, 41, 55, 0.18);
  --gradient: linear-gradient(135deg, #6366F1 0%, #8B5CF6 50%, #3B82F6 100%);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg-1);
  color: var(--text-1);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(139, 92, 246, 0.10), transparent 60%),
    radial-gradient(1000px 500px at -10% 110%, rgba(59, 130, 246, 0.10), transparent 60%),
    var(--bg-1);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  /* 移动端地址栏会改变可视高度：用 dvh 兜底，避免底部状态栏被裁切 */
  min-height: 100dvh;
}

/* ===== 仅供爬虫 / 读屏使用的主标题（不参与布局） ===== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ===== Top Navigation ===== */
.app-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 28px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(99, 102, 241, 0.12);
  box-shadow: 0 4px 20px -12px rgba(99, 102, 241, 0.25);
}
.app-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  font-size: 18px;
  letter-spacing: 0.3px;
}
.app-logo .logo-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--gradient);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 20px;
  box-shadow: var(--shadow);
}
.nav-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg-3);
  padding: 5px;
  border-radius: 12px;
}
.nav-tab {
  border: none;
  background: transparent;
  padding: 8px 18px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.25s ease;
}
.nav-tab.active {
  background: #fff;
  color: var(--primary-1);
  box-shadow: var(--shadow-soft);
}
.nav-tab:hover:not(.active) { color: var(--primary-1); }

/* 导航栏署名：低调但不缺席 */
.powered {
  padding-left: 12px;
  margin-left: 2px;
  border-left: 1px solid rgba(99, 102, 241, 0.18);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.nav-spacer { flex: 1; }

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.25s ease, opacity 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn-primary {
  background: var(--gradient);
  color: #fff;
  box-shadow: var(--shadow);
}
.btn-primary:hover { box-shadow: 0 14px 34px -10px rgba(99, 102, 241, 0.55); transform: translateY(-1px); }
.btn-ghost {
  background: #fff;
  color: var(--primary-1);
  border: 1px solid rgba(99, 102, 241, 0.25);
}
.btn-ghost:hover { background: var(--bg-3); }
/* ===== 语言菜单（构建期生成真实 <a href>，触屏靠点击展开，不依赖 hover） ===== */
.lang-menu {
  position: relative;
  flex: none;
}
.lang-menu > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid rgba(99, 102, 241, 0.18);
  border-radius: 10px;
  background: #fff;
  font-size: 13.5px;
  color: var(--text-1);
  user-select: none;
  touch-action: manipulation;
}
.lang-menu > summary::-webkit-details-marker { display: none; }
.lang-menu > summary::after {
  content: '';
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--text-2);
}
.lang-menu[open] > summary { border-color: var(--primary-1); }
.lang-list {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 60;
  min-width: 168px;
  /* 13 种语言全列出约 530px 高：常见桌面/竖屏手机可一次看全，超出才滚动 */
  max-height: min(76vh, 560px);
  overflow-y: auto;
  padding: 6px;
  background: #fff;
  border: 1px solid rgba(99, 102, 241, 0.14);
  border-radius: 12px;
  box-shadow: 0 18px 40px -18px rgba(31, 41, 55, 0.4);
}
.lang-list a {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--text-1);
  text-decoration: none;
  white-space: nowrap;
}
.lang-list a:hover { background: var(--bg-3); color: var(--primary-1); }
.lang-list a.active { background: var(--gradient); color: #fff; }

/* ===== 官网外链：斜箭头表示会新窗口打开 ===== */
.nav-site::after {
  content: '↗';
  font-size: 11px;
  line-height: 1;
  opacity: 0.65;
}

/* ===== 桌面版引流：提示文案 + 官方 Microsoft Store 徽章 ===== */
.store-hint {
  color: var(--err);
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  margin-left: 8px;
}
.store-badge {
  display: flex;
  align-items: center;
  margin-left: 10px;
  margin-right: 4px;
}
.store-badge a {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  line-height: 0;
}
.store-badge img {
  height: 36px;
  width: auto;
  display: block;
  border-radius: 4px;
  transition: transform 0.15s ease, filter 0.15s ease;
  cursor: pointer;
}
.store-badge a:hover img { transform: scale(1.06); filter: brightness(1.1); }
.store-badge a:active img { transform: scale(0.97); }

.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ===== Layout ===== */
.page { flex: 1; display: none; }
.page.active { display: flex; }

.workspace {
  display: grid;
  gap: 18px;
  padding: 18px 28px 28px;
  flex: 1;
  min-height: 0;
  /* 窄屏堆叠后内容会高于视口，这里作为滚动容器兜底 */
  overflow-y: auto;
}

/* Editor layout: left preview canvas, right watermark settings */
.editor-grid {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 18px;
  flex: 1;
  min-height: 0;
}
@media (max-width: 1200px) {
  /* 窄窗口改为上下堆叠：预览保留可用高度，设置面板随后自然延展 */
  .editor-grid {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(320px, 1fr) auto;
  }
}

/* ===== Card / Panel ===== */
.card {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(99, 102, 241, 0.10);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 18px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  transition: box-shadow 0.3s ease, transform 0.3s ease;
}
.card:hover { box-shadow: 0 16px 40px -16px rgba(99, 102, 241, 0.3); }
.card-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-1);
}
.card-title .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--gradient);
}

/* ===== Form controls ===== */
.field { margin-bottom: 14px; }
.field > label {
  display: block;
  font-size: 12.5px;
  color: var(--text-2);
  margin-bottom: 6px;
  font-weight: 500;
}
.input, .select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid rgba(99, 102, 241, 0.18);
  border-radius: 10px;
  font-size: 14px;
  background: #fff;
  color: var(--text-1);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}
.input:focus, .select:focus {
  border-color: var(--primary-1);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.seg {
  display: flex;
  background: var(--bg-3);
  border-radius: 10px;
  padding: 4px;
  gap: 4px;
}
.seg button {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 6px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
}
.seg button.active {
  background: #fff;
  color: var(--primary-1);
  box-shadow: var(--shadow-soft);
}

.checkbox {
  display: flex; align-items: center; gap: 9px;
  font-size: 13.5px; color: var(--text-1);
  cursor: pointer; user-select: none;
  padding: 6px 0;
}
.checkbox input { width: 17px; height: 17px; accent-color: var(--primary-1); }

.chip-group { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  border: 1px solid rgba(99, 102, 241, 0.25);
  background: #fff;
  color: var(--text-2);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
}
.chip.active {
  background: var(--gradient);
  color: #fff;
  border-color: transparent;
  box-shadow: var(--shadow-soft);
}

/* ===== 九宫格位置选择器（单排水印定位） ===== */
.anchor-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: 132px;
}
.anchor {
  aspect-ratio: 1 / 1;
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: 7px;
  background: #fff;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.anchor:hover {
  border-color: var(--primary-1);
  transform: scale(1.06);
}
.anchor.active {
  background: var(--gradient);
  border-color: transparent;
  box-shadow: var(--shadow-soft);
  transform: scale(1.06);
}

/* ===== 滑块（透明程度等连续参数） ===== */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  margin: 8px 0 2px;
  border-radius: 999px;
  background: var(--gradient);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--primary-1);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  transition: transform 0.18s ease;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--primary-1);
  cursor: pointer;
}

/* 参数标签内嵌的数值高亮（如「透明程度 50%」） */
.field > label b {
  color: var(--primary-1);
  font-weight: 600;
}

/* ===== Canvas Stage ===== */
.stage-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.stage-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.tool-btn {
  border: 1px solid rgba(99, 102, 241, 0.2);
  background: #fff;
  border-radius: 9px;
  padding: 7px 12px;
  font-size: 13px;
  color: var(--text-1);
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex; align-items: center; gap: 6px;
}
.tool-btn:hover { background: var(--bg-3); color: var(--primary-1); }
.zoom-label {
  font-size: 13px; color: var(--text-2);
  background: var(--bg-3); padding: 7px 12px; border-radius: 9px;
  min-width: 64px; text-align: center;
}
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background:
    linear-gradient(45deg, #eceef4 25%, transparent 25%),
    linear-gradient(-45deg, #eceef4 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eceef4 75%),
    linear-gradient(-45deg, transparent 75%, #eceef4 75%);
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
  border-radius: var(--radius);
  border: 1px solid rgba(99, 102, 241, 0.12);
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stage-canvas-host {
  position: relative;
  transform-origin: top left;
}
.stage-canvas-host canvas { display: block; border-radius: 4px; }

.empty-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text-2);
  text-align: center;
  pointer-events: none;
}
.empty-hint .big {
  width: 76px; height: 76px; border-radius: 22px;
  background: var(--bg-3);
  display: grid; place-items: center;
  font-size: 38px;
}

/* ===== Status bar ===== */
.status-bar {
  display: flex;
  gap: 22px;
  padding: 10px 28px;
  font-size: 12.5px;
  color: var(--text-2);
  background: rgba(255,255,255,0.7);
  border-top: 1px solid rgba(99,102,241,0.10);
  backdrop-filter: blur(8px);
}
.status-bar b { color: var(--text-1); font-weight: 600; }

/* ===== Toast ===== */
.toast-wrap {
  position: fixed;
  right: 22px; bottom: 22px;
  z-index: 200;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  background: #fff;
  border-left: 4px solid var(--primary-1);
  border-radius: 12px;
  padding: 13px 18px;
  box-shadow: 0 14px 34px -10px rgba(31,41,55,0.35);
  font-size: 13.5px;
  color: var(--text-1);
  min-width: 240px;
  animation: toastIn 0.35s cubic-bezier(.22,1,.36,1);
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }
.toast.warn { border-left-color: var(--warn); }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}
.toast.out { opacity: 0; transform: translateX(40px); transition: all .3s; }

/* ===== Modal ===== */
.modal-mask {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(31,41,55,0.45);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center; justify-content: center;
}
.modal-mask.show { display: flex; animation: fadeIn .25s ease; }
@keyframes fadeIn { from {opacity:0} to {opacity:1} }
.modal {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px;
  width: 380px;
  box-shadow: 0 30px 60px -20px rgba(31,41,55,0.5);
  animation: modalIn .3s cubic-bezier(.22,1,.36,1);
}
@keyframes modalIn { from {opacity:0; transform: translateY(20px) scale(.97)} to {opacity:1} }
.modal h3 { margin: 0 0 16px; font-size: 17px; }
.modal .modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ===== Batch page ===== */
.batch-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr 340px;
  gap: 18px;
  flex: 1;
  min-height: 0;
}
@media (max-width: 1400px) {
  .batch-grid {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(300px, 1fr) auto auto;
  }
}
.file-list { overflow: auto; min-height: 0; }
.view-toggle { display: flex; gap: 6px; }
.thumb-view {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.thumb-card {
  background: #fff;
  border: 1px solid rgba(99,102,241,0.12);
  border-radius: 14px;
  overflow: hidden;
  transition: transform .2s, box-shadow .2s;
  cursor: default;
}
.thumb-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-soft); }
.thumb-card img { width: 100%; height: 110px; object-fit: cover; background: #f0f1f6; }
.thumb-card .meta { padding: 9px 11px; font-size: 12px; color: var(--text-2); }
.thumb-card .meta b { color: var(--text-1); display: block; font-size: 12.5px; margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.detail-row {
  display: grid;
  grid-template-columns: 40px 1fr 90px 80px;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(99,102,241,0.08);
  font-size: 13px;
}
.detail-row .ficon { font-size: 20px; }
.detail-row .fname { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.detail-row .fstat { color: var(--text-2); font-size: 12px; text-align: right; }
.detail-row .badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--bg-3); color: var(--primary-1); text-align: center; }

/* 批量预览：队列中选中项高亮，指示当前预览的是哪张图 */
.thumb-card { cursor: pointer; }
.detail-row { cursor: pointer; }
.thumb-card.selected, .detail-row.selected {
  outline: 2px solid var(--primary-1);
  outline-offset: -2px;
}

.progress-track { height: 8px; background: var(--bg-3); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.progress-fill { height: 100%; background: var(--gradient); width: 0%; transition: width .25s; border-radius: 999px; }

.hint-text { font-size: 12px; color: var(--text-2); line-height: 1.6; }
.divider { height: 1px; background: rgba(99,102,241,0.10); margin: 14px 0; }
.scroll-y { overflow-y: auto; }

/* ===== 触屏与窄屏适配 ===== */
/* 触控目标加大，并去掉移动端 300ms 点击延迟 */
button, .chip, .anchor, summary, .checkbox { touch-action: manipulation; }
.seg button, .tool-btn, .anchor { min-height: 34px; }
.chip { display: inline-flex; align-items: center; min-height: 30px; }

/* ≤860px：导航换行；工作区由左右两栏改为上下堆叠 */
@media (max-width: 860px) {
  .app-nav {
    flex-wrap: wrap;
    gap: 10px 12px;
    padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  }
  .app-logo { font-size: 16px; }
  .app-logo .powered { display: none; }
  .nav-tabs { flex-wrap: wrap; }

  .workspace { padding: 12px 14px 18px; gap: 14px; }
  .editor-grid {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(280px, 58vh) auto;
  }
  .batch-grid {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(280px, 58vh) auto auto;
  }
  .status-bar {
    flex-wrap: wrap;
    gap: 6px 18px;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  }
  .modal { width: calc(100vw - 32px); max-width: 420px; }
  .lang-list { max-height: min(64vh, 560px); }
}

/* ≤640px：隐藏次要提示文案，收紧留白与字号 */
@media (max-width: 640px) {
  .optional-hint { display: none; }   /* 含「想安装桌面版 →」提示，只留商店徽章 */
  .store-badge { margin-left: 4px; margin-right: 0; }
  .store-badge img { height: 30px; }
  .card { padding: 14px; }
  .hint-text { font-size: 11.5px; }
  .lang-menu > summary { padding: 7px 10px; }
  .btn { padding: 9px 14px; }
  .tool-btn { padding: 7px 10px; font-size: 12.5px; }
  .anchor-grid { width: 100%; max-width: 168px; }
  .toast-wrap { left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); }
  .toast { min-width: 0; }
}

/* 横屏且高度紧张：恢复左右分栏，保证主视图高度 */
@media (orientation: landscape) and (max-height: 480px) {
  .app-nav { padding: 8px 14px; gap: 8px 12px; }
  .app-logo .powered { display: none; }
  .editor-grid { grid-template-columns: 1fr 320px; grid-template-rows: minmax(0, 1fr); }
  .batch-grid { grid-template-columns: 1fr 1fr 300px; grid-template-rows: minmax(0, 1fr); }
  .status-bar { padding: 6px 14px; }
}
