/* 配色和组件沿用「拼拼乐 · 一键水印」：深紫描边 / 粉色 / 薄荷绿 / 奶白。
   按小工具规范以 Chrome 61 为基线：不用 flex gap、inset、aspect-ratio、max() 等新语法 */
:root {
  --ink: #5b4a6e;
  --ink-soft: #8a7d99;
  --pink: #f3a6c0;
  --pink-deep: #e57a9f;
  --pink-pale: #fde8ef;
  --mint: #bfe9d8;
  --mint-pale: #e9f8f2;
  --lilac: #ddd1f3;
  --cream: #fffafc;
  --bg: #fdf3f6;
  --line: #ecdfe7;
  --radius: 18px;
  --border: 2px solid var(--ink);
  --pop: 0 3px 0 var(--ink);
  --checker-bg: #f7eff4;
  --sat: var(--safe-area-inset-top, 0px);
  --sab: var(--safe-area-inset-bottom, 0px);
  --sal: var(--safe-area-inset-left, 0px);
  --sar: var(--safe-area-inset-right, 0px);
  color-scheme: light;
}
@supports (top: env(safe-area-inset-top)) {
  :root {
    --sat: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
    --sab: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
    --sal: var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
    --sar: var(--safe-area-inset-right, env(safe-area-inset-right, 0px));
  }
}
/* 透明棋盘格背景：新内核增强，旧内核显示纯色 */
.checker { background-color: var(--checker-bg); }
@supports (background: repeating-conic-gradient(#000 0 25%, #fff 0 50%)) {
  .checker { background-image: repeating-conic-gradient(#efe6ec 0 25%, #fff 0 50%); background-size: 14px 14px; }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; touch-action: manipulation; }
/* 页面高度固定为屏幕高度，内容在 #app 里滚动（小工具容器不保证整页滚动） */
html, body { height: 100%; overflow: hidden; }
.app-scroll {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0;
  overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain;
  touch-action: pan-y;
}
img { -webkit-user-drag: none; }
input, textarea, select { -webkit-user-select: text; user-select: text; }
body {
  margin: 0;
  background: var(--bg) radial-gradient(circle at 1px 1px, rgba(91, 74, 110, 0.08) 1px, transparent 0) 0 0 / 18px 18px;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.muted { color: var(--ink-soft); }
.small { font-size: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* 顶部 */
.top {
  background: var(--pink);
  border-bottom: var(--border);
  padding: 14px 16px;
  padding-top: calc(14px + var(--sat));
  padding-left: calc(16px + var(--sal));
  padding-right: calc(16px + var(--sar));
}
.brand { display: flex; align-items: center; max-width: 1080px; margin: 0 auto; }
.brand > * + * { margin-left: 12px; }
.logo {
  width: 48px; height: 48px; border-radius: 14px; background: var(--pink); border: var(--border);
  box-shadow: var(--pop); flex: none; overflow: hidden;
}
/* Logo 就是小工具图标：翻角的扭蛋贴纸 */
.logo img { display: block; width: 100%; height: 100%; }
.top h1 { font-size: 19px; margin: 0; letter-spacing: 0.5px; }
.top p { margin: 0; font-size: 12px; opacity: 0.85; }
.brand-text { flex: 1; min-width: 0; }

/* 语言切换：顶栏右侧的小药丸 */
.lang-pick { position: relative; flex: none; }
.lang-pick select {
  -webkit-appearance: none; appearance: none; display: block;
  border: 2px solid var(--ink); border-radius: 999px; background: var(--cream); color: var(--ink);
  box-shadow: 0 2px 0 var(--ink); font-size: 13px; font-weight: 700; padding: 5px 26px 5px 12px; cursor: pointer;
}
.lang-pick::after {
  content: "▾"; position: absolute; right: 10px; top: 50%; -webkit-transform: translateY(-50%); transform: translateY(-50%);
  font-size: 12px; pointer-events: none;
}

/* 主体：手机单列，宽屏左边预览、右边参数 */
.layout {
  max-width: 760px; margin: 0 auto;
  padding: 14px 16px 24px;
  padding-left: calc(16px + var(--sal));
  padding-right: calc(16px + var(--sar));
  padding-bottom: calc(24px + var(--sab));
}
.col-controls { min-width: 0; }
/* 吸顶的是整列（它的父元素是整个 .layout，吸顶才能一直生效）；上下垫一条底色，滚过的卡片不会从缝里露出来 */
.col-preview {
  position: -webkit-sticky; position: sticky; top: 0; z-index: 5;
  background: var(--bg); margin: -14px -4px 0; padding: 14px 4px 0;
}
.col-preview .card { margin-bottom: 12px; }
@media (min-width: 900px) {
  .layout {
    max-width: 1080px;
    display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); grid-gap: 20px; align-items: start;
  }
  .col-preview { top: 14px; background: none; margin: 0; padding: 0; }
}

.card {
  background: var(--cream); border: var(--border); border-radius: var(--radius);
  box-shadow: 0 4px 0 var(--ink); padding: 14px; margin-bottom: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head > * + * { margin-left: 8px; }
.card-head h2 { font-size: 16px; margin: 0; display: flex; align-items: center; min-width: 0; flex: none; }
.card-head h2 .step { margin-right: 8px; flex: none; }
.step {
  width: 24px; height: 24px; border-radius: 50%; background: var(--mint); border: var(--border);
  display: inline-grid; place-items: center; font-size: 12px; font-weight: 800;
}

/* 按钮：粗描边 + 实色投影，按下时“压扁” */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: var(--border); border-radius: 999px; padding: 8px 16px; font-weight: 700;
  background: var(--cream); color: var(--ink); text-decoration: none;
  box-shadow: var(--pop); transition: transform 0.08s, box-shadow 0.08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.btn.primary { background: var(--pink); }
.btn.ghost { background: var(--mint); }
.btn.block { display: flex; width: 100%; margin-top: 14px; padding: 11px 16px; font-size: 16px; }
.btn[disabled] { opacity: 0.6; cursor: progress; }
.link { background: none; border: 0; color: var(--ink-soft); padding: 4px; }

/* 预览 */
.preview-wrap {
  position: relative; border: var(--border); border-radius: 14px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  height: 34vh; min-height: 200px; padding: 24px 14px;
}
@media (min-width: 900px) {
  .preview-wrap { height: 62vh; min-height: 360px; padding: 34px 24px; }
}
.preview-wrap canvas { display: block; max-width: 100%; max-height: 100%; width: auto; height: auto; }
.preview-wrap.dragging { outline: 3px solid var(--pink-deep); outline-offset: 3px; }
.preview-wrap[data-bg="lilac"] { background-color: var(--lilac); }
.preview-wrap[data-bg="pink"] { background-color: var(--pink); }
.preview-wrap[data-bg="mint"] { background-color: var(--mint); }
.preview-wrap[data-bg="ink"] { background-color: var(--ink); }
.preview-wrap[data-bg="white"] { background-color: #ffffff; }
.preview-wrap[data-bg="black"] { background-color: #000000; }
.preview-wrap[data-bg="checker"] { background-color: var(--checker-bg); }
@supports (background: repeating-conic-gradient(#000 0 25%, #fff 0 50%)) {
  .preview-wrap[data-bg="checker"] { background-image: repeating-conic-gradient(#efe6ec 0 25%, #fff 0 50%); background-size: 16px 16px; }
}
.preview-hint, .preview-size {
  position: absolute; bottom: 8px; font-size: 11px; color: var(--ink); font-weight: 600;
  background: var(--cream); border: 1.5px solid var(--ink); border-radius: 999px; padding: 1px 8px;
  white-space: nowrap;
}
.preview-hint { left: 8px; }
.preview-size { right: 8px; font-variant-numeric: tabular-nums; }
.preview-size:empty { display: none; }

.bg-row { display: flex; align-items: center; justify-content: flex-end; margin-top: 10px; }
.bg-row > * + * { margin-left: 8px; }
.dots { display: flex; }
.dots > * + * { margin-left: 6px; }
.dots button {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--ink); padding: 0;
}
.dots button[data-v="lilac"] { background-color: var(--lilac); }
.dots button[data-v="pink"] { background-color: var(--pink); }
.dots button[data-v="mint"] { background-color: var(--mint); }
.dots button[data-v="ink"] { background-color: var(--ink); }
.dots button[data-v="white"] { background-color: #ffffff; }
.dots button[data-v="black"] { background-color: #000000; }
/* 最后一个：自由选色，没选时显示彩虹色，选了就显示选中的颜色 */
.dot-custom {
  position: relative; display: block; flex: none; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--ink);
  overflow: hidden; background: linear-gradient(135deg, #ff9fb8, #ffe08a 35%, #9fe6c8 65%, #a9c6ff);
}
.dot-custom input {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0; border: 0; padding: 0; cursor: pointer;
}
.dots button.on, .swatch.on, .dot-custom.on { box-shadow: 0 0 0 2px var(--cream), 0 0 0 4px var(--pink-deep); }

/* 上传 */
.drop {
  display: grid; justify-items: center; grid-gap: 6px; text-align: center;
  border: 2px dashed var(--ink-soft); background: var(--pink-pale); border-radius: 14px;
  padding: 18px 12px; cursor: pointer;
}
.drop b { color: var(--ink); }
.drop-icon {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  background: var(--pink); border: var(--border); box-shadow: var(--pop); font-size: 24px; line-height: 1; font-weight: 700;
}
body.dragging .drop { outline: 3px solid var(--pink-deep); outline-offset: 3px; }

.sub { margin-top: 14px; padding-top: 12px; border-top: 2px dashed var(--line); }
.sub > * + * { margin-top: 10px; }
.sub-head { font-size: 14px; }
.note { margin: 0; }

/* 二选一按钮 */
.toggle2 { display: flex; }
.toggle2 > * + * { margin-left: 8px; }
.toggle2 button {
  flex: 1; border: 2px solid var(--ink); background: var(--cream); border-radius: 10px;
  font-size: 13px; font-weight: 700; padding: 7px 6px; color: var(--ink);
}
.toggle2 button.on { background: var(--mint); box-shadow: 0 2px 0 var(--ink); }

/* 材质卡片 */
.effects { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-gap: 8px; }
.fx {
  position: relative; display: flex; flex-direction: column; align-items: center; text-align: center;
  border: var(--border); border-radius: 14px; background: var(--cream); color: var(--ink);
  box-shadow: 0 3px 0 var(--ink); padding: 5px 4px 7px; min-width: 0;
  transition: transform 0.08s, box-shadow 0.08s;
}
.fx:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.fx canvas { display: block; width: 100%; height: auto; border-radius: 9px; background: var(--lilac); }
.fx b { font-size: 13px; line-height: 1.2; margin-top: 5px; white-space: nowrap; }
.fx small { font: 700 8.5px/1.2 ui-monospace, monospace; letter-spacing: 0.04em; color: var(--ink-soft); white-space: nowrap; }
.fx.on { background: var(--pink); }
.fx.on small { color: var(--ink); }

/* 参数框：沿用水印编辑器里「图层」的白底卡片 */
.layer {
  border: var(--border); border-radius: 14px; padding: 10px 12px 12px; margin-top: 14px;
  background: #fff; box-shadow: 0 3px 0 var(--ink);
}
.layer-head { display: flex; align-items: center; margin-bottom: 8px; }
.layer-head > * + * { margin-left: 6px; }
.layer-name { flex: 1; min-width: 0; font-size: 14px; }

.rows > * + * { margin-top: 10px; }
.field { display: flex; flex-direction: column; font-size: 13px; color: var(--ink); font-weight: 600; }
.field > * + * { margin-top: 6px; }

.slider { flex-direction: row; align-items: center; }
.field.slider > * + * { margin: 0 0 0 10px; }
.slider span { width: 4.2em; flex: none; }
/* 外文的参数名比两个汉字长 */
html[lang="en"] .slider span { width: 6.2em; }
html[lang="ja"] .slider span, html[lang="ko"] .slider span { width: 5.4em; }
.slider output { width: 2.8em; text-align: right; font-variant-numeric: tabular-nums; flex: none; }
/* 滑块：粉色轨道 + 粉色圆钮 */
.slider input[type="range"] {
  flex: 1; min-width: 0; -webkit-appearance: none; appearance: none; height: 10px; border-radius: 999px;
  background: var(--pink-pale); border: 2px solid var(--ink); margin: 0;
}
.slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%;
  background: var(--pink); border: 2px solid var(--ink); box-shadow: 0 2px 0 var(--ink);
}
.slider input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%; background: var(--pink); border: 2px solid var(--ink);
}
.slider input[type="range"]:disabled { opacity: 0.4; }

.switch-row { flex-direction: row; align-items: center; justify-content: space-between; }
.switch-row > * + * { margin: 0 0 0 10px; }

/* 开关 */
.switch { position: relative; display: inline-block; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch i {
  display: block; width: 46px; height: 26px; border-radius: 999px; border: 2px solid var(--ink);
  background: var(--pink-pale); position: relative; transition: background 0.15s;
}
.switch i::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--cream); border: 2px solid var(--ink); transition: transform 0.15s;
}
.switch input:checked + i { background: var(--mint); }
.switch input:checked + i::after { transform: translateX(20px); background: var(--pink); }

.rows.off { opacity: 0.45; }

/* 颜色色块 */
.swatches { display: flex; flex-wrap: wrap; margin: -6px 0 0 -6px; }
.swatches > * { margin: 6px 0 0 6px; }
.swatch {
  position: relative; width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--ink); padding: 0; flex: none;
  overflow: hidden;
}
.swatch input {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0; border: 0; padding: 0; cursor: pointer;
}
.swatch-clear::after {
  content: ""; position: absolute; top: 50%; left: -2px; right: -2px; height: 2px; margin-top: -1px;
  background: var(--pink-deep); -webkit-transform: rotate(-45deg); transform: rotate(-45deg);
}
.swatch-custom { background: linear-gradient(135deg, #ff9fb8, #ffe08a 35%, #9fe6c8 65%, #a9c6ff); }
.swatch-label { display: block; font-size: 12px; font-weight: 400; color: var(--ink-soft); margin-top: 6px; }

/* 光源：九宫格方向键 */
.light-row { display: flex; align-items: center; margin-bottom: 12px; }
.light-row > * + * { margin-left: 14px; }
.grid9 { display: grid; grid-template-columns: repeat(3, 34px); grid-auto-rows: 30px; grid-gap: 4px; flex: none; }
.grid9 button {
  border: 2px solid var(--ink); background: var(--cream); border-radius: 8px; font-size: 14px; padding: 0; font-weight: 700; color: var(--ink);
}
.grid9 button.on { background: var(--pink); box-shadow: 0 2px 0 var(--ink); }
.grid9 .sun { border-style: dashed; color: var(--ink-soft); cursor: default; background: transparent; }
.light-side { min-width: 0; }
.light-side p { margin: 0; }
.light-text { font-weight: 700; font-size: 15px; }

/* 结果 */
.result { margin-top: 14px; }
.result > * + * { margin-top: 8px; }
.result img {
  display: block; max-width: 100%; max-height: 360px; margin: 0 auto; border-radius: 12px; border: var(--border); cursor: zoom-in;
}
.result.stale img { opacity: 0.55; }
.result p { margin: 8px 0 0; text-align: center; }
.result-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); grid-gap: 10px; }

.foot { display: flex; justify-content: space-between; align-items: center; padding: 4px 4px 0; }
.foot .link { white-space: nowrap; flex: none; }
.foot span { min-width: 0; text-align: right; margin-left: 10px; }

/* 加载 & 提示 */
.busy {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(253, 243, 246, 0.82); z-index: 50; color: var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 700;
}
.spinner {
  width: 40px; height: 40px; border-radius: 50%; border: 5px solid var(--mint); border-top-color: var(--pink-deep);
  animation: spin 0.8s linear infinite;
}
#busyText { margin-top: 14px; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; bottom: 28px; bottom: calc(28px + var(--sab)); transform: translateX(-50%);
  background: var(--ink); color: var(--cream); padding: 9px 16px; border-radius: 999px; z-index: 60;
  font-size: 14px; max-width: calc(100% - 32px); text-align: center; box-shadow: 0 3px 0 rgba(91, 74, 110, 0.35);
}

/* 查看大图 */
dialog.viewer {
  padding: 12px; border: var(--border); border-radius: 18px; background: var(--cream); color: var(--ink);
  width: 92%; max-width: 640px; max-height: 92vh; box-shadow: 0 5px 0 var(--ink);
}
dialog.viewer::backdrop { background: rgba(91, 74, 110, 0.6); }
#viewerImg { display: block; max-width: 100%; max-height: 70vh; margin: 0 auto; border-radius: 10px; border: var(--border); }
.viewer-hint { margin: 10px 0 0; font-size: 12px; color: var(--ink-soft); text-align: center; }
.viewer-hint:empty { display: none; }
.viewer-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); grid-gap: 10px; margin-top: 12px; }
/* 浏览器里长按 / 右键保存：只有成品图允许 */
#viewerImg, .result img { -webkit-touch-callout: default; -webkit-user-select: auto; user-select: auto; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: 0.01ms !important; }
}
