/* ============================================================================
 *  去水印 · 移动端优先样式
 *  设计要点：安全区适配 / 大触控目标 / 100dvh 动态视口 / 深浅色自适应
 * ========================================================================== */

:root {
  --bg: #f5f5f7;
  --bg-elev: #ffffff;
  --bg-sunken: #ececf0;
  --fg: #1c1c1e;
  --fg-2: #6c6c72;
  --fg-3: #9a9aa1;
  --line: rgba(60, 60, 67, 0.13);
  --brand: #ff3b30;
  --brand-ink: #ffffff;
  --accent: #0a84ff;
  --ok: #34c759;
  --radius: 16px;
  --radius-s: 11px;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .05), 0 6px 20px rgba(0, 0, 0, .06);
  --shadow-2: 0 8px 34px rgba(0, 0, 0, .16);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro SC", "PingFang SC",
          "HarmonyOS Sans SC", "Noto Sans SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0c;
    --bg-elev: #16161a;
    --bg-sunken: #202026;
    --fg: #f2f2f5;
    --fg-2: #a1a1aa;
    --fg-3: #71717a;
    --line: rgba(255, 255, 255, 0.11);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .5), 0 8px 26px rgba(0, 0, 0, .45);
    --shadow-2: 0 10px 40px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-size-adjust: 100%;
}

body { overflow: hidden; }

button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
img { display: block; max-width: 100%; }
svg { display: block; }

#app { height: 100dvh; height: 100vh; width: 100%; position: relative; }
@supports (height: 100dvh) { #app { height: 100dvh; } }

/* --------------------------------------------------------------- 通用件 */

.screen { display: none; height: 100%; }
.screen.is-active { display: flex; flex-direction: column; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 46px; padding: 0 20px;
  border-radius: 999px; font-size: 15px; font-weight: 600;
  transition: transform .12s ease, opacity .12s ease, background .18s ease;
  user-select: none;
}
.btn:active { transform: scale(.965); }
.btn.primary { background: var(--brand); color: var(--brand-ink); box-shadow: 0 6px 18px rgba(255, 59, 48, .28); }
.btn.primary:disabled { opacity: .4; box-shadow: none; }
.btn.ghost { background: var(--bg-sunken); color: var(--fg); }
.btn.big { min-height: 52px; flex: 1; font-size: 16px; min-width: 0; }

.icon-btn {
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center;
  color: var(--fg); flex: none;
  transition: background .15s ease, opacity .15s ease;
}
.icon-btn svg { width: 23px; height: 23px; }
.icon-btn:active { background: var(--bg-sunken); }
.icon-btn:disabled { opacity: .28; }
.icon-btn.small { width: 34px; height: 34px; }
.icon-btn.small svg { width: 19px; height: 19px; }

.link-btn {
  display: block; width: 100%; text-align: center;
  padding: 14px; font-size: 14px; font-weight: 500;
  color: var(--accent);
}

.chip {
  padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--bg-sunken); color: var(--fg-2);
}
.chip:active { color: var(--fg); }

.seg {
  display: flex; gap: 3px; padding: 3px; flex: none;
  background: var(--bg-sunken); border-radius: 999px;
}
.seg button {
  padding: 9px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
  color: var(--fg-2); white-space: nowrap;
  transition: background .16s ease, color .16s ease;
}
.seg button.on { background: var(--bg-elev); color: var(--fg); box-shadow: var(--shadow-1); }

/* ================================================================ 首页 */

.home {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-t) + 34px) calc(var(--safe-r) + 20px)
           calc(var(--safe-b) + 30px) calc(var(--safe-l) + 20px);
  display: flex; flex-direction: column; gap: 20px;
  max-width: 560px; margin: 0 auto; width: 100%;
}

.hero { text-align: center; }
.brand {
  width: 66px; height: 66px; margin: 0 auto 14px;
  border-radius: 20px; display: grid; place-items: center;
  background: linear-gradient(145deg, #ff6b5e, #ff3b30 60%, #d9281e);
  box-shadow: 0 12px 30px rgba(255, 59, 48, .32);
}
.brand-ico { width: 36px; height: 36px; fill: #fff; }
.hero h1 { margin: 0 0 6px; font-size: 27px; font-weight: 800; letter-spacing: -.4px; }
.hero p { margin: 0; color: var(--fg-2); font-size: 14px; }

.pills { display: flex; justify-content: center; flex-wrap: wrap; gap: 7px; margin-top: 14px; }
.pill {
  font-size: 12px; font-weight: 600; color: var(--fg-2);
  padding: 5px 11px; border-radius: 999px; background: var(--bg-sunken);
}

.drop {
  position: relative;
  border-radius: var(--radius);
  background: var(--bg-elev);
  border: 1.5px dashed var(--line);
  box-shadow: var(--shadow-1);
  padding: 30px 22px 22px;
  text-align: center;
  transition: border-color .18s ease, transform .18s ease, background .18s ease;
}
.drop:active { transform: scale(.99); }
.drop.drag { border-color: var(--brand); background: rgba(255, 59, 48, .06); }
.drop-ico { width: 42px; height: 42px; margin: 0 auto 14px; color: var(--brand); opacity: .9; }
.drop-title { font-size: 17px; font-weight: 700; }
.drop-sub { font-size: 12.5px; color: var(--fg-3); margin-top: 5px; }
.drop-btns { display: flex; gap: 10px; margin-top: 20px; }
.drop-btns .btn { flex: 1; min-width: 0; }
.drop-tip { font-size: 11.5px; color: var(--fg-3); margin-top: 14px; }

.features { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.features li {
  background: var(--bg-elev); border-radius: var(--radius-s); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 3px;
}
.features b { font-size: 14px; font-weight: 700; }
.features span { font-size: 12.5px; color: var(--fg-2); line-height: 1.45; }

/* ============================================================ 编辑器 */

.topbar {
  flex: none;
  display: flex; align-items: center; gap: 4px;
  padding: calc(var(--safe-t) + 6px) calc(var(--safe-r) + 8px) 6px calc(var(--safe-l) + 8px);
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  min-height: 54px;
}
.tb-title { flex: 1; text-align: center; font-size: 16px; font-weight: 700; }
.tb-actions { display: flex; gap: 2px; flex: none; }

.stage {
  position: relative; flex: 1; min-height: 0;
  background: var(--bg-sunken);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  background-image:
    linear-gradient(45deg, rgba(127,127,127,.10) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(127,127,127,.10) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(127,127,127,.10) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(127,127,127,.10) 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
}
.stage canvas {
  position: absolute; inset: 0; display: block;
  width: 100%; height: 100%;
  touch-action: none;
}
#overlay { opacity: .62; pointer-events: none; }

.zoom-badge {
  position: absolute; left: 10px; bottom: 10px;
  font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums;
  padding: 4px 9px; border-radius: 999px;
  background: rgba(0, 0, 0, .55); color: #fff;
  backdrop-filter: blur(6px); pointer-events: none;
}

.hint-toast {
  position: absolute; left: 50%; bottom: 60px; transform: translateX(-50%);
  background: rgba(0, 0, 0, .72); color: #fff;
  font-size: 12.5px; padding: 9px 15px; border-radius: 999px;
  white-space: nowrap; pointer-events: none;
  backdrop-filter: blur(8px);
  transition: opacity .4s ease;
}
.hint-toast.hide { opacity: 0; }

.float-tools {
  position: absolute; right: 10px; top: 10px;
  display: flex; flex-direction: column; gap: 8px;
}
.fab {
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, .86); color: #1c1c1e;
  box-shadow: var(--shadow-1);
  backdrop-filter: blur(10px);
}
.fab svg { width: 21px; height: 21px; }
.fab:active { transform: scale(.93); }
@media (prefers-color-scheme: dark) {
  .fab { background: rgba(40, 40, 46, .86); color: #f2f2f5; }
}

/* 处理中遮罩 */
.busy {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(0, 0, 0, .35); backdrop-filter: blur(3px); z-index: 30;
}
.busy-card {
  background: var(--bg-elev); border-radius: var(--radius);
  padding: 22px 26px; width: min(280px, 78vw); text-align: center;
  box-shadow: var(--shadow-2);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.busy-title { font-size: 15px; font-weight: 700; margin-top: 6px; }
.busy-sub { font-size: 12px; color: var(--fg-3); }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid var(--line); border-top-color: var(--brand);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.bar {
  width: 100%; height: 4px; border-radius: 999px;
  background: var(--bg-sunken); overflow: hidden; margin-top: 6px;
}
.bar > i { display: block; height: 100%; width: 0%; border-radius: 999px; background: var(--brand); transition: width .3s ease; }

/* 工具栏 */
.tools {
  flex: none;
  display: flex; gap: 6px;
  padding: 8px calc(var(--safe-r) + 8px) 4px calc(var(--safe-l) + 8px);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  background: var(--bg-elev);
  border-top: 1px solid var(--line);
}
.tools::-webkit-scrollbar { display: none; }
.tool {
  flex: 1 0 auto; min-width: 62px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 8px 7px; border-radius: var(--radius-s);
  color: var(--fg-2); font-size: 11px; font-weight: 600;
  transition: background .16s ease, color .16s ease;
}
.tool svg { width: 23px; height: 23px; }
.tool.is-active { background: rgba(255, 59, 48, .12); color: var(--brand); }
.tool:active { background: var(--bg-sunken); }

/* 底部操作区 */
.actionbar {
  flex: none;
  padding: 8px calc(var(--safe-r) + 12px) calc(var(--safe-b) + 10px) calc(var(--safe-l) + 12px);
  background: var(--bg-elev);
  display: flex; flex-direction: column; gap: 9px;
}
.brush-row { display: flex; align-items: center; gap: 10px; }
.br-label { font-size: 12px; font-weight: 600; color: var(--fg-2); flex: none; }
.br-dot {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(255, 59, 48, .18);
  display: grid; place-items: center;
}
.br-dot::after {
  content: ''; display: block; border-radius: 50%; background: var(--brand);
  width: var(--dot, 12px); height: var(--dot, 12px);
}
.act-row { display: flex; align-items: center; gap: 10px; }
.mask-info { font-size: 11.5px; color: var(--fg-3); text-align: center; }
.mask-info.warn { color: var(--brand); }

input[type=range] {
  -webkit-appearance: none; appearance: none;
  flex: 1; height: 30px; background: transparent; margin: 0;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 999px; background: var(--bg-sunken);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; border: 1px solid rgba(0, 0, 0, .08);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
  margin-top: -9px;
}
input[type=range]::-moz-range-track { height: 4px; border-radius: 999px; background: var(--bg-sunken); }
input[type=range]::-moz-range-thumb { width: 22px; height: 22px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.3); }

/* ============================================================== 结果页 */

.compare {
  position: relative; flex: 1; min-height: 0;
  overflow: hidden; background: var(--bg-sunken);
  display: grid; place-items: center;
  background-image:
    linear-gradient(45deg, rgba(127,127,127,.10) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(127,127,127,.10) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(127,127,127,.10) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(127,127,127,.10) 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
}
.cmp-layer { position: absolute; inset: 0; display: grid; place-items: center; padding: 10px; }
.cmp-layer img {
  max-width: 100%; max-height: 100%;
  width: auto; height: auto; object-fit: contain;
  border-radius: 4px;
}
.cmp-before { clip-path: inset(0 50% 0 0); }
.cmp-handle {
  position: absolute; top: 0; bottom: 0; left: 50%;
  width: 2px; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.18);
  transform: translateX(-1px); pointer-events: none;
}
.cmp-handle svg {
  position: absolute; top: 50%; left: 50%;
  width: 38px; height: 38px; padding: 8px; box-sizing: border-box;
  transform: translate(-50%, -50%);
  border-radius: 50%; background: #fff; color: #1c1c1e;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .3);
}
#cmpRange {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; margin: 0; z-index: 5; cursor: ew-resize;
}
#cmpRange::-webkit-slider-thumb { width: 52px; height: 100%; margin-top: 0; background: transparent; box-shadow: none; border: 0; }
#cmpRange::-moz-range-thumb { width: 52px; height: 100%; background: transparent; border: 0; box-shadow: none; }
.cmp-tag {
  position: absolute; bottom: 12px; font-size: 11px; font-weight: 700;
  padding: 4px 10px; border-radius: 999px;
  background: rgba(0, 0, 0, .6); color: #fff; pointer-events: none;
  backdrop-filter: blur(6px);
}
.cmp-tag-l { left: 12px; }
.cmp-tag-r { right: 12px; }

.result-actions {
  flex: none; padding: 12px calc(var(--safe-r) + 16px) calc(var(--safe-b) + 12px) calc(var(--safe-l) + 16px);
  background: var(--bg-elev); border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 10px;
}
.result-actions .seg { width: 100%; }
.result-actions .seg button { flex: 1; }
.meta { font-size: 12px; color: var(--fg-3); text-align: center; }

/* ============================================================ 底部面板 */

.sheet-wrap { position: fixed; inset: 0; z-index: 60; }
.sheet-mask {
  position: absolute; inset: 0; background: rgba(0, 0, 0, .4);
  backdrop-filter: blur(2px);
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--bg-elev);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, .2);
  max-height: 76vh;
  display: flex; flex-direction: column;
  animation: slideUp .26s cubic-bezier(.22, 1, .36, 1);
  padding-bottom: var(--safe-b);
}
@keyframes slideUp { from { transform: translateY(100%); } }
.sheet-grip {
  width: 38px; height: 4.5px; border-radius: 999px;
  background: var(--line); margin: 8px auto 2px;
}
.sheet-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px 8px 20px;
}
.sheet-title { flex: 1; font-size: 16px; font-weight: 700; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 16px 8px; }
.sheet-foot {
  padding: 10px 16px 16px; display: flex; gap: 10px;
  border-top: 1px solid var(--line);
}
.sheet-foot .btn { flex: 1; }

.opt {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 14px; border-radius: var(--radius-s);
  background: var(--bg-sunken); margin-bottom: 8px;
  transition: background .15s ease;
}
.opt .sw {
  width: 24px; height: 24px; border-radius: 7px; flex: none;
  border: 2px solid var(--line); display: grid; place-items: center;
  transition: background .15s ease, border-color .15s ease;
}
.opt.on .sw { background: var(--brand); border-color: var(--brand); }
.opt .sw svg { width: 15px; height: 15px; color: #fff; opacity: 0; }
.opt.on .sw svg { opacity: 1; }
.opt-txt { flex: 1; min-width: 0; }
.opt-t { display: block; font-size: 14px; font-weight: 600; }
.opt-s { display: block; font-size: 11.5px; color: var(--fg-3); margin-top: 1px; }
.opt-x { font-size: 11px; color: var(--brand); }
.sheet-note { font-size: 12.5px; color: var(--fg-2); line-height: 1.55; padding: 4px 2px 10px; }
.sheet-warn { flex: 1 0 100%; font-size: 11.5px; color: var(--brand); text-align: center; padding-top: 2px; }
.sheet-foot { flex-wrap: wrap; }

/* ================================================================ 提示 */

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 88px);
  transform: translate(-50%, 12px); z-index: 90;
  background: rgba(28, 28, 30, .92); color: #fff;
  font-size: 13px; font-weight: 500;
  padding: 11px 18px; border-radius: 999px;
  opacity: 0; pointer-events: none;
  transition: opacity .24s ease, transform .24s ease;
  max-width: 88vw; text-align: center;
  backdrop-filter: blur(10px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
/* 底部面板展开时，提示挪到顶部，避免遮住列表 */
.sheet-wrap:not([hidden]) ~ .toast {
  bottom: auto;
  top: calc(var(--safe-t) + 14px);
  transform: translate(-50%, -12px);
}
.sheet-wrap:not([hidden]) ~ .toast.show { transform: translate(-50%, 0); }
.toast.error { background: rgba(255, 59, 48, .95); }
.toast.ok { background: rgba(52, 199, 89, .95); }

.global-busy {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, .35); backdrop-filter: blur(2px);
}
.global-busy .spinner { width: 32px; height: 32px; }

[hidden] { display: none !important; }

/* 横屏 / 大屏微调 */
@media (min-height: 760px) and (min-width: 420px) {
  .hero h1 { font-size: 30px; }
}
@media (orientation: landscape) and (max-height: 480px) {
  .tools .tool span { display: none; }
  .tools .tool { padding: 9px; min-width: 50px; }
  .zoom-badge { bottom: auto; top: 10px; }
  .hint-toast { display: none; }
  .hero { display: none; }
}
