/* ===== 图片格式转换 样式（独立一份；色板与科研导航站、RegexLab、ImgCompress 一致） =====
   ① 上传区是整块可点区域，.over 是拖拽悬停态；按钮要 stopPropagation，
      否则点「选择图片」会同时冒泡到 dropzone 再触发一次。
   ② 格式按钮是数据驱动的小卡片：名称 + 质量/alpha 标记 + 一行说明，窄屏自动换行。
   ③ 预览图统一 object-fit: contain，绝不裁切，也绝不拉伸变形。 */
:root {
  --bg: #f5f6f8;
  --bg-card: #ffffff;
  --bg-hover: #f0f2f5;
  --text: #2c3e50;
  --text-sub: #7f8c9b;
  --border: #e8ebef;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, .1);
  --accent-text: #fff;
  --danger: #e2544d;
  --ok: #2f9e5f;
  --warn: #d97706;
  --shadow: 0 2px 8px rgba(30, 40, 60, .06);
  --bar-bg: #f7f8fa;
  --code-bg: #f4f6f9;
  --tag-bg: #eef2f7;
  --checker: #e9edf2;
}

html[data-theme="dark"] {
  --bg: #060a17;
  --bg-card: #0d1424;
  --bg-hover: #1a2336;
  --text: #dce3ec;
  --text-sub: #8794a8;
  --border: #1e2a44;
  --accent: #4d94ff;
  --accent-soft: rgba(77, 148, 255, .16);
  --danger: #ff6b64;
  --ok: #4ade80;
  --warn: #fbbf24;
  --shadow: 0 2px 10px rgba(0, 0, 0, .5);
  --bar-bg: #0a1120;
  --code-bg: #101a30;
  --tag-bg: #16213a;
  --checker: #16203a;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.6;
  font-variant-numeric: tabular-nums;
  transition: background .25s, color .25s;
}
.mono, input[type="number"], .out-fmt, .fmt-name { font-family: "Cascadia Code", Consolas, ui-monospace, monospace; }

/* 只给读屏用的隐藏元素（文件选择框不能 display:none，否则无法被脚本 click 触发） */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ===== 顶栏（全站统一骨架） ===== */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px; background: var(--bar-bg);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.topbar .back { color: var(--accent); text-decoration: none; font-size: 14px; white-space: nowrap; }
.topbar .back:hover { text-decoration: underline; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-text { min-width: 0; overflow: hidden; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; flex: none; }
.brand-mark img { width: 26px; height: 26px; }
.brand-text h1 { font-size: 17px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text p { font-size: 12px; color: var(--text-sub); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
.icon-btn {
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 15px; line-height: 1;
}
.icon-btn:hover { background: var(--bg-hover); }
.lang-switch { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.lang-btn {
  border: none; background: var(--bg-card); color: var(--text-sub);
  padding: 6px 10px; font-size: 13px; cursor: pointer; text-decoration: none;
}
.lang-btn + .lang-btn { border-left: 1px solid var(--border); }
.lang-btn.active { background: var(--accent); color: var(--accent-text); }

/* ===== 通用控件 ===== */
.btn {
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  border-radius: 8px; padding: 7px 12px; font-size: 13px; cursor: pointer; font-family: inherit;
}
.btn:hover { background: var(--bg-hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.06); }

/* ===== 上传区 ===== */
.dropzone {
  border: 2px dashed var(--border); border-radius: 12px;
  padding: 22px 18px; text-align: center; cursor: pointer;
  transition: border-color .18s, background .18s; background: var(--bg);
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); outline: none; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dz-icon { font-size: 30px; line-height: 1.2; }
.dz-title { font-size: 15px; font-weight: 600; margin: 6px 0 2px; }
.dz-sub { font-size: 13px; color: var(--text-sub); }
.dz-hint { font-size: 12.5px; color: var(--text-sub); margin: 8px auto 12px; max-width: 620px; }

/* ===== 原图信息 ===== */
.src-wrap { display: flex; gap: 16px; margin-top: 14px; align-items: flex-start; flex-wrap: wrap; }
.src-preview {
  flex: 0 0 auto; width: 168px; min-height: 120px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
  display: flex; align-items: center; justify-content: center; overflow: hidden; padding: 8px;
}
/* 棋盘格底：让透明区域一眼可见，这是图片工具的关键细节 */
.src-preview {
  background-image:
    linear-gradient(45deg, var(--checker) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.src-preview img { max-width: 100%; max-height: 168px; object-fit: contain; display: block; }
.src-meta { flex: 1 1 240px; min-width: 0; }
.src-empty { font-size: 13.5px; color: var(--text-sub); text-align: center; }
.kv-list { display: flex; flex-direction: column; gap: 6px; }
.kv { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.kv .k { flex: none; min-width: 68px; font-size: 12.5px; color: var(--text-sub); }
.kv .v { font-size: 13.5px; overflow-wrap: anywhere; }

/* ===== 格式选择 ===== */
.fmt-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 8px; margin-bottom: 6px; }
.fmt-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg-card);
  padding: 8px 10px; cursor: pointer; text-align: left; color: var(--text);
  font-family: inherit; min-width: 0;
}
.fmt-btn:hover { background: var(--bg-hover); border-color: var(--accent); }
.fmt-btn.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.fmt-name { font-size: 13.5px; font-weight: 700; }
.fmt-meta { font-size: 10.5px; color: var(--text-sub); font-family: inherit; }
.fmt-btn.on .fmt-meta { color: var(--accent); }
.fmt-tip { font-size: 11.5px; color: var(--text-sub); line-height: 1.4; }

/* ===== 设置项 ===== */
.field { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.field[hidden] { display: none; }
.field-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.field-head label { font-size: 14px; font-weight: 600; }
.field-val { font-size: 13px; color: var(--accent); font-weight: 700; }
.check { display: flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--text-sub); cursor: pointer; font-weight: 400; }
.color-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.color-row .hint { margin: 0; flex: 1 1 220px; }
input[type="color"] {
  width: 46px; height: 30px; padding: 2px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg-card);
}
.size-row { display: flex; gap: 10px; flex-wrap: wrap; }
.size-cell { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; color: var(--text-sub); flex: 1 1 130px; }
.size-cell input {
  border: 1px solid var(--border); background: var(--code-bg); color: var(--text);
  border-radius: 8px; padding: 7px 10px; font-size: 14px; width: 100%;
}
.size-cell input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

/* ===== 转换结果 ===== */
.out-box { min-height: 90px; }
.out-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.out-fmt { font-size: 15px; font-weight: 700; color: var(--accent); }
.out-dim { font-size: 12.5px; color: var(--text-sub); }
.out-preview {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px;
  display: flex; align-items: center; justify-content: center; min-height: 140px; max-height: 320px;
  background-image:
    linear-gradient(45deg, var(--checker) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.out-preview img { max-width: 100%; max-height: 300px; object-fit: contain; display: block; }

/* ===== 说明正文（全站统一） ===== */
.doc {
  max-width: 900px; margin: 24px auto 40px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); padding: 22px 26px 26px;
}
.doc h2 { font-size: 18px; margin: 22px 0 8px; }
.doc h2:first-child { margin-top: 0; }
.doc p { margin: 8px 0; color: var(--text); }
.doc ul { margin: 8px 0 8px 22px; }
.doc li { margin: 6px 0; }
.doc dl dt { font-weight: 700; margin-top: 12px; }
.doc dl dd { margin: 4px 0 10px; color: var(--text); }
.doc a { color: var(--accent); }
.rel-note { font-size: 13px; color: var(--text-sub); font-style: italic; }
.ver { margin-top: 24px; font-size: 13px; color: var(--text-sub); text-align: center; }
.rel-links { display: flex; flex-wrap: wrap; gap: 8px 16px; list-style: none; margin-left: 0; }
.rel-links li { margin: 0; }
.rel-links a { color: var(--accent); text-decoration: none; }
.rel-links a:hover { text-decoration: underline; }

/* ===== 提示条 ===== */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px);
  background: #1f2937; color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  z-index: 200; max-width: min(90vw, 560px); word-break: break-word;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ===== 响应式 ===== */
@media (max-width: 700px) {
  .brand-text p { display: none; }
  .topbar { flex-wrap: wrap; row-gap: 6px; }
  .src-preview { width: 100%; }
  .fmt-row { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}
@media (max-width: 560px) {
  .topbar .spacer { display: none; }
  .topbar .lang-switch { order: 5; }
  .doc { padding: 18px 16px 20px; }
}
@media (prefers-reduced-motion: reduce) {
  .dropzone, .toast, body { transition: none; }
}

.out-stats { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 10px; }
.out-delta { font-size: 13px; color: var(--ok); margin-top: 6px; }
.out-warn { font-size: 12.5px; color: var(--warn); margin-top: 6px; }
.out-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.mini {
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text-sub);
  border-radius: 6px; padding: 2px 7px; font-size: 11px; cursor: pointer; font-family: inherit;
}
.mini:hover { background: var(--bg-hover); color: var(--text); }
.note { font-size: 13px; color: var(--text-sub); }

/* ===== 主体 ===== */
.imgconvert { max-width: 1000px; margin: 0 auto; padding: 16px 16px 4px; }
.card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); padding: 14px 16px 18px; margin-bottom: 14px; min-width: 0;
}
.card h2 { font-size: 17px; margin: 2px 0 8px; }
.card h2.sub, h3.sub { font-size: 14px; margin: 14px 0 4px; color: var(--text); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.head-actions { display: flex; align-items: center; gap: 8px; }
.hint { font-size: 13px; color: var(--text-sub); margin-bottom: 10px; }
