/* ===== Local Reset =====
 * 这里原本通过 CDN @import 引入 Tailwind。但项目实际并未使用任何 Tailwind 工具类
 * （HTML 中出现的 class 全部由本文件定义），@import 只是借用了它的 preflight
 * 来重置浏览器默认样式。
 * 作为纯前端工具站，多一次第三方 CDN 请求既拖慢首屏，也带来可用性与隐私上的外部依赖
 * （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; }

/* 仅供搜索引擎与屏幕阅读器识别的隐藏标题：不参与布局，也不影响视觉 */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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;
}

/* ===== Top Navigation ===== */
.app-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  /* 允许换行：德语等长文案在中等宽度下会挤爆单行，换行优于横向溢出 */
  flex-wrap: wrap;
  gap: 20px;
  row-gap: 10px;
  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); }
/* pro-tag：导航栏内说明文本（黑色粗体，紧跟 Batch 选项） */
.pro-tag {
  margin-left: 12px;
  color: #000;
  font-weight: 700;
  font-size: 13px;
  align-self: center;
  white-space: nowrap;
}
.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;
}

/* Editor layout: left params, center canvas, right export */
.editor-grid {
  display: grid;
  grid-template-columns: 300px 1fr 320px;
  gap: 18px;
  flex: 1;
  min-height: 0;
}
@media (max-width: 1200px) {
  .editor-grid { grid-template-columns: 260px 1fr; }
  .editor-grid .panel-export { grid-column: 1 / -1; }
}

/* ===== 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);
}

/* ===== 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; }
.slice-line {
  position: absolute;
  background: rgba(99, 102, 241, 0.85);
  box-shadow: 0 0 8px rgba(99, 102, 241, 0.6);
  z-index: 5;
  cursor: grab;
  transition: background 0.15s;
}
.slice-line:hover { background: var(--primary-2); }
.slice-line.dragging { background: var(--primary-3); box-shadow: 0 0 14px rgba(59, 130, 246, 0.9); }
.slice-line.h { left: 0; right: 0; height: 3px; margin-top: -1.5px; cursor: ns-resize; }
.slice-line.v { top: 0; bottom: 0; width: 3px; margin-left: -1.5px; cursor: ew-resize; }

.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: 1fr 320px;
  gap: 18px;
  flex: 1;
  min-height: 0;
}
.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; }

.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; }

/* ===== 允许栅格/弹性子项收缩 =====
 * 默认 min-width:auto 会让子项按 min-content 撑开，
 * 窄屏下（如 320px）输入框、分段按钮会把卡片顶出视口导致横向溢出。
 * 统一放开收缩下限，由百分比宽度自适应。 */
.workspace > *, .editor-grid > *, .batch-grid > *, .card, .field,
.row2 > *, .seg, .seg > button, .chip-group, .chip-group > *, .thumb-view {
  min-width: 0;
}
.input, .select { min-width: 0; }

/* ===== 语言菜单（真实 <a> 链接，触摸/鼠标均可展开） ===== */
.lang-dropdown { position: relative; font-size: 14px; }
.lang-dropdown > summary {
  list-style: none;
  cursor: pointer;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid rgba(99, 102, 241, 0.25);
  background: #fff;
  color: var(--primary-1);
  font-weight: 500;
  white-space: nowrap;
  user-select: none;
}
.lang-dropdown > summary::-webkit-details-marker { display: none; }
.lang-dropdown > summary::after { content: '▾'; margin-left: 7px; font-size: 11px; }
.lang-dropdown[open] > summary { background: var(--bg-3); }
.lang-dropdown ul {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 172px;
  max-height: 60vh;
  overflow-y: auto;
  background: #fff;
  border: 1px solid rgba(99, 102, 241, 0.12);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 18px 40px -12px rgba(31, 41, 55, 0.35);
  z-index: 60;
  max-width: calc(100vw - 24px);
}
.lang-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-1);
  text-decoration: none;
  white-space: nowrap;
}
.lang-link:hover { background: var(--bg-3); }
/* 当前语言：只加粗、不变色（与参考实现一致，避免彩色高亮抢视觉） */
.lang-link.active { font-weight: 600; }
.lang-link .mi-icon { width: 16px; display: inline-block; text-align: center; }

/* ===== 外部入口：官网外链 + 桌面版（Microsoft Store） ===== */
.nav-site { text-decoration: none; }
.store-hint {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--err);
  white-space: nowrap;
}
.store-badge { display: flex; align-items: center; }
.store-badge a { display: block; touch-action: manipulation; }
.store-badge img { display: block; height: 30px; width: auto; }

/* ==================================================================
   移动端 / 竖屏 / 触屏适配
   思路：导航与工具栏换行，工作区由「多栏」改为上下堆叠，
   放大触控目标、处理底部安全区。
   ================================================================== */

/* 触屏优化：去掉点击延迟、避免双击缩放 */
.nav-tab, .btn, .tool-btn, .chip, .seg button, .lang-link,
.lang-dropdown > summary, .view-toggle button, .checkbox {
  touch-action: manipulation;
}

@media (max-width: 860px) {
  /* 导航栏换行，避免横向溢出 */
  .app-nav { flex-wrap: wrap; gap: 10px; padding: 10px 14px; }
  .app-logo { font-size: 16px; }
  .nav-tabs { order: 3; width: 100%; }
  .nav-spacer { display: none; }
  /* 语言菜单靠右，保证其下拉面板有足够的左侧空间展开而不越界 */
  .lang-dropdown { margin-left: auto; }

  /* 工作区由左右两栏改为上下堆叠 */
  .workspace { padding: 12px 14px 18px; gap: 12px; }
  .editor-grid { grid-template-columns: 1fr; }
  .editor-grid .panel-export { grid-column: auto; }
  .batch-grid { grid-template-columns: 1fr; }
  .thumb-view { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }

  /* 状态栏换行 + 适配底部安全区 */
  .status-bar {
    flex-wrap: wrap;
    gap: 10px 18px;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  }

  /* 放大触控目标 */
  .btn, .tool-btn, .lang-dropdown > summary { min-height: 40px; }
  .seg button, .chip, .nav-tab { min-height: 34px; }
  .checkbox input { width: 20px; height: 20px; }
}

/* 手机竖屏：隐藏次要提示文案，避免拥挤 */
@media (max-width: 640px) {
  .pro-tag { display: none; }
  /* 只保留商店徽章，收起「想安装桌面版 →」文案，避免导航过挤 */
  .store-hint { display: none; }
  .store-badge img { height: 26px; }
  .hint-text { font-size: 11.5px; }
  .brand-hint { display: none; }
  .app-nav > .hint-text { display: none; }
  .logo-mark { width: 32px; height: 32px; font-size: 17px; }
  .lang-dropdown ul { min-width: 150px; }
}

/* 手机横屏（高度很矮）：恢复左右两栏，保证主视图高度 */
@media (max-height: 480px) and (orientation: landscape) {
  .editor-grid { grid-template-columns: 240px 1fr; }
  .editor-grid .panel-export { grid-column: 1 / -1; }
  .batch-grid { grid-template-columns: 1fr 260px; }
}
