:root {
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --accent: #0d9488;
  --bg: #f6f7fb;
  --card-bg: #ffffff;
  --text: #1f2430;
  --muted: #667085;
  --border: #e4e7ee;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16,24,40,.06), 0 6px 16px rgba(16,24,40,.05);
  --ok: #16a34a;
  --warn: #d97706;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  line-height: 1.6;
}

header.site {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  padding: 28px 16px 22px;
  text-align: center;
}
header.site h1 { font-size: 1.5rem; font-weight: 700; }
header.site h1 a { color: #fff; text-decoration: none; }
header.site p { margin-top: 6px; color: rgba(255,255,255,.85); font-size: .9rem; }

.wrap { max-width: 920px; margin: 0 auto; padding: 24px 16px 40px; }

.back-link {
  display: inline-block; margin-bottom: 16px;
  color: var(--primary); text-decoration: none; font-size: .9rem;
}
.back-link:hover { text-decoration: underline; }

/* 首頁工具卡片 */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 20px;
}
.tool-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 20px;
  text-decoration: none;
  color: var(--text);
  transition: transform .15s ease, box-shadow .15s ease;
}
.tool-card:hover { transform: translateY(-3px); box-shadow: 0 4px 10px rgba(16,24,40,.1), 0 12px 24px rgba(16,24,40,.08); }
.tool-card .icon { font-size: 2.2rem; margin-bottom: 10px; display: block; }
.tool-card h3 { font-size: 1.08rem; margin-bottom: 6px; }
.tool-card p { color: var(--muted); font-size: .86rem; }

.intro { margin: 18px 0 4px; color: var(--muted); font-size: .95rem; max-width: 680px; }

.privacy-banner {
  display: inline-flex; align-items: center; gap: 8px;
  background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46;
  padding: 8px 14px; border-radius: 999px; font-size: .85rem; font-weight: 600;
  margin-top: 6px;
}

/* 卡片式工具容器 */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 20px;
}
.card h2 { font-size: 1.15rem; margin-bottom: 14px; }

.field-row {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px;
}
input[type="text"], input[type="number"], select {
  font-size: 1rem;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}
input[type="number"] { width: 110px; }
select { min-width: 140px; }
button {
  font-size: .95rem;
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
}
button:hover { background: var(--primary-dark); }
button:disabled { background: #c7c9d1; cursor: not-allowed; }
button.secondary {
  background: #fff; color: var(--primary); border: 1px solid var(--primary);
}
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); font-weight: 500; }
button.ghost:hover { background: #fff; color: var(--primary); }

/* 拖放區 */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
  background: #fbfbfe;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.dropzone:hover { border-color: var(--primary); background: #f5f5ff; }
.dropzone.dragover { border-color: var(--primary); background: #eef2ff; }
.dropzone .dz-icon { font-size: 2.4rem; display: block; margin-bottom: 8px; }
.dropzone .dz-main { color: var(--text); font-weight: 600; font-size: 1rem; }
.dropzone .dz-sub { font-size: .82rem; margin-top: 4px; }
.dropzone input[type=file] { display: none; }

/* 品質滑桿 */
.range-row { display: flex; align-items: center; gap: 12px; }
input[type="range"] { flex: 1; accent-color: var(--primary); height: 6px; }
.range-val { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 48px; text-align: right; }

/* 選項按鈕群組 */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg button {
  background: #fff; color: var(--muted); border-radius: 0; font-weight: 500; padding: 8px 14px; font-size: .88rem;
  border-right: 1px solid var(--border);
}
.seg button:last-child { border-right: none; }
.seg button.active { background: var(--primary); color: #fff; }

/* 檔案清單 / 結果卡片 */
.result-list { display: flex; flex-direction: column; gap: 12px; }
.result-item {
  display: flex; gap: 14px; align-items: center;
  border: 1px solid var(--border); border-radius: 10px; padding: 12px;
  background: #fff;
}
.result-item img.thumb { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; background: #f0f0f5; flex-shrink: 0; }
.result-item .meta { flex: 1; min-width: 0; }
.result-item .fname { font-weight: 600; font-size: .92rem; word-break: break-all; }
.result-item .sizes { font-size: .85rem; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.result-item .sizes .from { text-decoration: line-through; opacity: .7; }
.result-item .sizes .saved { color: var(--ok); font-weight: 700; }
.result-item .sizes .grew { color: var(--warn); font-weight: 700; }
.result-item .badge { font-size: .72rem; padding: 2px 8px; border-radius: 999px; background: #eef2ff; color: var(--primary-dark); font-weight: 700; margin-left: 6px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px,1fr)); gap: 10px; margin: 4px 0 14px; }
.stat { background: var(--bg); border-radius: 8px; padding: 10px 12px; }
.stat .label { color: var(--muted); font-size: .76rem; }
.stat .value { font-weight: 700; font-size: 1.05rem; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* 預覽 */
.preview-box { text-align: center; margin-top: 10px; }
.preview-box img { max-width: 100%; max-height: 420px; border-radius: 10px; border: 1px solid var(--border); }
.preview-empty { color: var(--muted); font-size: .88rem; padding: 28px 0; }

.hint { color: var(--muted); font-size: .82rem; margin-top: 4px; }
.error-box { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; padding: 12px 14px; border-radius: 8px; font-size: .9rem; margin-top: 10px; }
.note-box { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; padding: 12px 14px; border-radius: 8px; font-size: .88rem; margin-top: 10px; }

/* 裁切舞台 */
.crop-stage {
  position: relative; margin: 10px 0; user-select: none; touch-action: none;
  background: #0b0b12; border-radius: 10px; overflow: hidden; line-height: 0;
}
.crop-stage canvas.base { display: block; max-width: 100%; }
.crop-stage .overlay {
  position: absolute; inset: 0; cursor: move;
}
.crop-box {
  position: absolute; border: 2px solid #fff;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.55);
}
.crop-box::before {
  content: ""; position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,.35) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.35) 1px, transparent 1px);
  background-size: 33.333% 33.333%; background-position: 0 0;
  pointer-events: none;
}
.crop-box .handle {
  position: absolute; width: 14px; height: 14px;
  background: #fff; border: 1px solid var(--primary); border-radius: 50%;
}
.crop-box .h-nw { left: -7px; top: -7px; cursor: nwse-resize; }
.crop-box .h-n  { left: 50%; top: -7px; transform: translateX(-50%); cursor: ns-resize; }
.crop-box .h-ne { right: -7px; top: -7px; cursor: nesw-resize; }
.crop-box .h-e  { right: -7px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.crop-box .h-se { right: -7px; bottom: -7px; cursor: nwse-resize; }
.crop-box .h-s  { left: 50%; bottom: -7px; transform: translateX(-50%); cursor: ns-resize; }
.crop-box .h-sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
.crop-box .h-w  { left: -7px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }

.crop-readout {
  position: absolute; top: 8px; left: 8px;
  background: rgba(0,0,0,.6); color: #fff; font-size: .78rem;
  padding: 3px 8px; border-radius: 6px; font-variant-numeric: tabular-nums;
  pointer-events: none;
}

article h2 { margin: 20px 0 8px; font-size: 1.15rem; }
article h2:first-child { margin-top: 0; }
article h3 { margin: 14px 0 6px; font-size: 1rem; }
article p, article li { color: var(--text); font-size: .95rem; margin-bottom: 8px; }
article ul { padding-left: 20px; }

footer.site {
  text-align: center; color: var(--muted); font-size: .82rem; padding: 24px 16px 40px;
}
footer.site nav { margin-bottom: 8px; }
footer.site nav a { color: var(--muted); text-decoration: none; margin: 0 8px; }
footer.site nav a:hover { text-decoration: underline; color: var(--primary); }

@media (max-width: 600px) {
  input[type="number"] { width: 90px; }
  .field-row { flex-direction: column; align-items: stretch; }
  .result-item { flex-direction: column; align-items: flex-start; }
  .result-item img.thumb { width: 100%; height: auto; max-height: 160px; }
}
