/* ============================================================
   PicSlim — 图片压缩站 v3 设计系统
   学自：Squoosh (Google) two-up 对比 · TinyPNG 滑块 · Linear 微交互
   ============================================================ */

:root {
  color-scheme: light;
  /* 淡蓝背景 + 高级感淡紫品牌 */
  --bg: #dde3f0;
  --bg-2: #d5dcec;
  --card: #ffffff;
  --ink: #1c2130;
  --ink-2: #555f77;
  --ink-3: #9aa3b8;
  --line: #dfe4ef;
  --line-2: #c8d0e0;
  --brand: #7c5cf0;
  --brand-deep: #6846e0;
  --brand-soft: #f1eefe;
  --brand-line: #dcd5fa;
  --warn: #f59e0b;
  --danger: #ef4444;
  --danger-soft: #fef2f2;
  --r-lg: 16px;
  --r-md: 12px;
  --r-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(30, 33, 50, .06);
  --shadow-md: 0 4px 16px rgba(30, 33, 50, .08);
  --shadow-lg: 0 12px 40px rgba(30, 33, 50, .14);
  --ring: 0 0 0 3px rgba(124, 92, 240, .22);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection { background: var(--brand-soft); color: var(--brand-deep); }
img { display: block; max-width: 100%; }
button { font-family: inherit; }
:focus-visible { outline: none; box-shadow: var(--ring); }

/* 细滚动条 */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--ink-3); background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ==================== 应用顶栏 ==================== */
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: 60px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 20px;
  background: rgba(221, 227, 240, .82);
  backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.brand svg { transition: transform .3s ease; }
.brand:hover svg { transform: rotate(-6deg) scale(1.05); }
.brand-name { font-weight: 700; font-size: .98rem; letter-spacing: -.01em; }
.brand-name span { color: var(--brand); }

.toolbar { display: flex; align-items: center; gap: 8px; }

/* 工具条控件：按钮/下拉/滑块共用底座 */
.ctl {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 12px;
  font-size: .82rem; font-weight: 500; color: var(--ink-2);
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-sm); cursor: pointer;
  transition: border-color .15s, color .15s, background .15s, box-shadow .15s;
  white-space: nowrap;
}
.ctl:hover { border-color: var(--line-2); color: var(--ink); }
.ctl:active { transform: translateY(0.5px); }
.ctl.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.ctl.primary:hover { background: var(--brand-deep); }
.ctl.icon { padding: 0 9px; }
.ctl svg { flex-shrink: 0; }

.ctl select, .ctl input[type="range"] { border: none; background: none; font-family: inherit; font-size: .82rem; color: var(--ink); }
.ctl select { cursor: pointer; padding-right: 4px; }

/* 滑块 */
.range-group { display: flex; align-items: center; gap: 8px; padding-left: 12px; }
.range-group .lbl { font-size: .78rem; color: var(--ink-3); font-weight: 500; }
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 110px; height: 4px; border-radius: 4px;
  background: var(--line-2); cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 2px solid var(--brand);
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: transform .12s ease;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 2px solid var(--brand); cursor: pointer;
}

/* 舞台背景切换按钮组 */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; background: var(--card); }
.seg button {
  width: 34px; height: 34px; border: none; background: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: var(--ink-3);
  transition: background .15s, color .15s;
}
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--brand-soft); color: var(--brand); }

/* ==================== 空态 hero ==================== */
.screen-empty {
  max-width: 720px; margin: 0 auto; padding: 72px 24px 48px;
  text-align: center;
  animation: fadeUp .5s ease both;
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.hero-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .75rem; font-weight: 600; color: var(--brand-deep);
  background: var(--brand-soft); border: 1px solid var(--brand-line);
  padding: 4px 12px; border-radius: 20px; margin-bottom: 20px;
}
.hero-badge .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--brand); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }
.screen-empty h1 {
  font-size: clamp(2rem, 5vw, 2.7rem);
  font-weight: 750; letter-spacing: -.03em; line-height: 1.15;
}
.screen-empty h1 em { font-style: normal; color: var(--brand); }
.screen-empty .sub { color: var(--ink-2); font-size: 1.05rem; margin-top: 12px; }

/* 拖放区 */
.dropzone {
  margin-top: 36px;
  background: var(--card);
  border: 2px dashed var(--line-2);
  border-radius: var(--r-lg);
  padding: 56px 24px;
  cursor: pointer;
  transition: border-color .2s, background .2s, box-shadow .2s, transform .2s;
}
.dropzone:hover { border-color: var(--brand); box-shadow: var(--shadow-md); }
.dropzone.drag {
  border-color: var(--brand); background: var(--brand-soft);
  box-shadow: var(--shadow-lg); transform: scale(1.01);
}
.dz-icon {
  width: 72px; height: 72px; margin: 0 auto;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: var(--brand-soft); color: var(--brand);
  transition: transform .25s ease;
}
.dropzone:hover .dz-icon, .dropzone.drag .dz-icon { transform: translateY(-4px); }
.dz-title { font-size: 1.1rem; font-weight: 650; margin-top: 18px; }
.dz-hint { font-size: .88rem; color: var(--ink-3); margin-top: 6px; }
.dz-actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; }

/* 特性行 */
.feats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 36px; }
@media (max-width: 640px) { .feats { grid-template-columns: 1fr; } }
.feat {
  display: flex; align-items: flex-start; gap: 10px;
  text-align: left; padding: 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md);
  transition: border-color .2s, box-shadow .2s;
}
.feat:hover { border-color: var(--line-2); box-shadow: var(--shadow-sm); }
.feat svg { flex-shrink: 0; margin-top: 2px; color: var(--brand); }
.feat b { display: block; font-size: .88rem; font-weight: 600; }
.feat p { font-size: .78rem; color: var(--ink-3); margin-top: 2px; line-height: 1.5; }

/* ==================== 工作区 ==================== */
.screen-work { display: none; height: calc(100vh - 60px); animation: fadeUp .3s ease both; }
.screen-work.show { display: flex; }

/* 左侧缩略图栏 */
.thumbs {
  width: 200px; flex-shrink: 0;
  border-right: 1px solid var(--line);
  background: var(--bg-2);
  display: flex; flex-direction: column;
  overflow-y: auto; padding: 12px; gap: 8px;
}
@media (max-width: 640px) { .thumbs { width: 76px; } }
.thumb {
  position: relative;
  display: flex; gap: 10px; align-items: center;
  padding: 8px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--r-md);
  cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
@media (max-width: 640px) { .thumb { padding: 6px; } }
.thumb:hover { border-color: var(--line-2); box-shadow: var(--shadow-sm); }
.thumb.active { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.thumb img { width: 52px; height: 52px; object-fit: cover; border-radius: 6px; background: #eee; flex-shrink: 0; }
@media (max-width: 640px) { .thumb img { width: 100%; height: 100%; aspect-ratio: 1; } }
.thumb .t-info { min-width: 0; }
@media (max-width: 640px) { .thumb .t-info { display: none; } }
.thumb .t-name { font-size: .72rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumb .t-pct { font-size: .68rem; color: var(--brand); font-weight: 700; font-family: var(--mono); }
.thumb .t-pct.up { color: var(--danger); }
.thumb .t-check {
  position: absolute; top: 6px; right: 6px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--brand); color: #fff;
  display: none; align-items: center; justify-content: center;
}
@media (max-width: 640px) { .thumb .t-check { top: 4px; right: 4px; } }
.thumb.active .t-check { display: flex; }

/* 对比舞台 */
.stage {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  position: relative;
}
.stage-view {
  flex: 1; position: relative;
  overflow: hidden;
  background: #dfe5f2;   /* 默认淡蓝舞台 */
  transition: background .2s;
}
.stage-view.bg-dark { background: #1c2130; }
.stage-view.bg-checker {
  background-color: #e8ecf6;
  background-image: linear-gradient(45deg, #d5dcec 25%, transparent 25%, transparent 75%, #d5dcec 75%),
                    linear-gradient(45deg, #d5dcec 25%, transparent 25%, transparent 75%, #d5dcec 75%);
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
}
.stage-view.zoom { overflow: auto; cursor: grab; }
.stage-view.zoom:active { cursor: grabbing; }

.compare {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.compare img {
  position: absolute;
  max-width: 92%; max-height: 88%;
  object-fit: contain;
  user-select: none; -webkit-user-drag: none;
  box-shadow: 0 8px 40px rgba(0,0,0,.25);
}
.stage-view.bg-checker .compare img { box-shadow: 0 8px 40px rgba(0,0,0,.12); }
.compare .layer-out { clip-path: inset(0 0 0 var(--split, 50%)); }

/* 分割线 */
.divider {
  position: absolute; top: 0; bottom: 0;
  left: var(--split, 50%); width: 2px;
  background: var(--brand);
  cursor: col-resize; z-index: 5;
  transform: translateX(-1px);
  touch-action: none;
}
.divider::after {
  content: ""; position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 36px; height: 36px; border-radius: 50%;
  background: #fff; border: 2px solid var(--brand);
  box-shadow: var(--shadow-md);
  transition: transform .15s ease;
  display: flex; align-items: center; justify-content: center;
}
.divider:hover::after { transform: translate(-50%, -50%) scale(1.08); }
.divider::before {
  content: "‹ ›"; position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  color: var(--brand); font-size: 13px; font-weight: 700; z-index: 1;
  pointer-events: none; line-height: 1;
}

/* 对比角标 */
.corner {
  position: absolute; top: 12px; z-index: 6;
  font-size: .68rem; font-weight: 700; letter-spacing: .08em;
  padding: 3px 10px; border-radius: 6px;
  text-transform: uppercase;
}
.corner.orig { left: 12px; background: rgba(24,24,27,.72); color: #fff; }
.corner.out { right: 12px; background: var(--brand); color: #fff; }

/* 空选中提示（如筛选后无图） */
.stage-empty {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-3); font-size: .9rem;
}

/* 状态栏 */
.statusbar {
  height: 64px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 20px;
  background: var(--card); border-top: 1px solid var(--line);
}
.status-left { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.status-name { font-weight: 600; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.status-sizes { font-size: .8rem; color: var(--ink-2); font-family: var(--mono); white-space: nowrap; }
.status-sizes .orig { color: var(--ink-3); text-decoration: line-through; }
.status-sizes .arr { color: var(--ink-3); margin: 0 4px; }
.status-save {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .8rem; font-weight: 700; font-family: var(--mono);
  color: var(--brand-deep); background: var(--brand-soft);
  padding: 2px 9px; border-radius: 20px;
}
.status-save.up { color: var(--danger); background: var(--danger-soft); }
.status-right { display: flex; gap: 8px; align-items: center; }

/* ===== 修复（超分）模式 ===== */
.ctl.restore { border-color: var(--brand); color: var(--brand); }
.ctl.restore.on { background: var(--brand); color: #fff; border-color: var(--brand); }

.factor-group { display: flex; align-items: center; gap: 6px; padding: 0 10px; }
.factor-group .lbl { font-size: .78rem; color: var(--ink-3); font-weight: 500; }
.factor-group select {
  border: none; background: none; font-family: inherit; font-size: .82rem; color: var(--ink); cursor: pointer;
}

/* 修复状态徽标 */
.status-restore {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .8rem; font-weight: 700;
  color: var(--brand-deep); background: var(--brand-soft);
  padding: 2px 9px; border-radius: 20px;
}
.status-restore b { font-family: var(--mono); }

/* 修复进度（覆盖在缩略图/舞台） */
.restore-overlay {
  position: absolute; inset: 0; z-index: 8;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: rgba(221, 227, 240, .65); backdrop-filter: blur(3px);
  color: var(--ink-2); font-size: .85rem; font-weight: 500;
}
.restore-overlay .spin {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--brand-line); border-top-color: var(--brand);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==================== Toast ==================== */
.toast-wrap { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: #18181b; color: #fff;
  font-size: .82rem; padding: 10px 18px; border-radius: 10px;
  box-shadow: var(--shadow-lg);
  animation: toastIn .3s cubic-bezier(.21,1.02,.73,1) both;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(10px) scale(.95); } to { opacity: 1; transform: none; } }

/* 底栏 */
.foot { max-width: 720px; margin: 0 auto; padding: 40px 24px 64px; text-align: center; font-size: .78rem; color: var(--ink-3); line-height: 1.9; }
.foot b { color: var(--brand); }

/* 响应式顶栏 */
@media (max-width: 760px) {
  .toolbar .hide-m { display: none; }
  .range-group { padding-left: 8px; }
  input[type="range"] { width: 70px; }
}

/* ==================== PWA / 移动端加固 ==================== */
.topbar { padding-top: env(safe-area-inset-top); height: calc(60px + env(safe-area-inset-top)); }
.screen-work { height: calc(100vh - 60px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
.statusbar { padding-bottom: env(safe-area-inset-bottom); height: calc(64px + env(safe-area-inset-bottom)); }
.thumbs, .statusbar, .toolbar { -webkit-tap-highlight-color: transparent; }

/* 触控目标：竖屏窄屏 ≥ 44px */
@media (max-width: 640px) {
  .ctl { height: 44px; min-width: 44px; }
  .seg button { width: 44px; height: 44px; }
  .thumb { min-height: 60px; }
  .divider::after { width: 44px; height: 44px; }
  .dropzone { padding: 44px 16px; }
  .status-sizes .orig, .status-sizes .arr { display: none; }
}

/* 宽屏（桌面）显示 PWA 提示 */
.desktop-hint {
  display: none; text-align: center; font-size: .78rem; color: var(--ink-3);
  margin-top: 16px;
}
@media (min-width: 900px) { .desktop-hint { display: block; } }

/* 安装弹窗内按钮 */
#installBtn { font-family: inherit; }
