:root, [data-theme="light"] {
  --bg: #ffffff;
  --surface: #f6f6f8;
  --surface-2: #ececf0;
  --border: #e2e2e8;
  --text: #111114;
  --text-secondary: #6b6b75;
  --primary: #2563eb;
  --primary-text: #ffffff;
  --ok: #16a34a;
  --danger: #dc2626;
  --ts-bg: #ecfdf5;
  --ts-text: #047857;
  --ts-border: rgba(167, 243, 208, .6);
  --shadow: 0 12px 32px rgba(17, 17, 20, .14), 0 2px 6px rgba(17, 17, 20, .08);
  --tile-bg: #ececf0;
  color-scheme: light;
}
[data-theme="dark"], html.dark {
  --bg: #000000;
  --surface: #111113;
  --surface-2: #1d1d20;
  --border: #2b2b30;
  --text: #f2f2f3;
  --text-secondary: #9a9aa3;
  --primary: #3b82f6;
  --primary-text: #ffffff;
  --ok: #22c55e;
  --danger: #ef4444;
  --ts-bg: rgba(16, 185, 129, .14);
  --ts-text: #6ee7b7;
  --ts-border: rgba(110, 231, 183, .25);
  --shadow: 0 12px 32px rgba(0, 0, 0, .6), 0 0 0 1px #2b2b30;
  --tile-bg: #1d1d20;
  color-scheme: dark;
}

:root { --hdr-h: 53px; --tray: 0px; }
html.tray { --tray: 44px; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
html.viewing, html.viewing body { overflow: hidden; }
button, input { font: inherit; color: inherit; }
button { -webkit-user-select: none; user-select: none; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg .fill { fill: currentColor; stroke: none; }
.grow { flex: 1; min-width: 0; }

.file-in { position: fixed; left: -100px; top: 0; width: 1px; height: 1px; opacity: 0; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 10px; border: 0;
  background: var(--surface-2); cursor: pointer; white-space: nowrap; font-weight: 500;
}
.btn.primary { background: var(--primary); color: var(--primary-text); }
.btn:active, .icon:active, .pick-btn:active, .mi:active { opacity: .7; }
.btn:disabled, .icon:disabled { opacity: .35; pointer-events: none; }
.icon {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 36px; height: 36px; border-radius: 10px; border: 0; padding: 0;
  background: transparent; color: var(--text); cursor: pointer;
}
@media (hover: hover) { .icon:hover { background: var(--surface-2); } }

.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px 0 6px;
  border-radius: 999px; border: 0; background: var(--surface-2); cursor: pointer;
  font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; flex: none;
}
.pill b { font-weight: 600; }
.pill svg { width: 20px; height: 20px; }
.pill.ok { color: var(--ok); }
.pill.bad { color: var(--danger); }
.pill.dim { color: var(--text-secondary); }

/* 进度环：进行中 = 蓝 */
.ring { width: 20px; height: 20px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 3; }
.ring .ring-bg { stroke: color-mix(in srgb, currentColor 18%, transparent); }
.ring .ring-fg { stroke: var(--primary); stroke-linecap: round; transition: stroke-dashoffset .3s; }

/* ---------- 启动、登录 ---------- */
.boot { position: fixed; inset: 0; display: grid; place-items: center; }
.spin {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--surface-2); border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login form { width: min(340px, 100%); display: flex; flex-direction: column; gap: 12px; }
.login-title { font-size: 20px; font-weight: 600; text-align: center; }
.login-row { display: flex; gap: 10px; }
.login input {
  flex: 1; min-width: 0; height: 46px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); font-size: 18px; letter-spacing: .15em; outline: none;
}
.login input:focus { border-color: var(--primary); }
.login .btn { height: 46px; padding: 0 20px; }
.err { margin: 0; color: var(--danger); font-size: 14px; text-align: center; }

/* ---------- 顶栏 ---------- */
.hdr {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(18px); backdrop-filter: saturate(160%) blur(18px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.bar { display: flex; align-items: center; gap: 6px; height: 52px; padding: 0 10px; }
.title { font-weight: 600; font-size: 16px; padding-left: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; max-width: 48vw; }
.stat { color: var(--text-secondary); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 100 auto; font-variant-numeric: tabular-nums; }
#btn-up span { display: inline; }
@media (max-width: 370px) { #btn-up span { display: none; } #btn-up { padding: 0 10px; } }

.chips { display: flex; gap: 6px; padding: 0 10px 10px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border);
  background: transparent; cursor: pointer; font-size: 13px; white-space: nowrap;
}
.chip i { font-style: normal; color: var(--text-secondary); font-variant-numeric: tabular-nums; margin-left: 2px; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.on i { color: inherit; opacity: .7; }

/* ---------- 网格 ---------- */
#grid { padding: 0 2px calc(28px + env(safe-area-inset-bottom)); }
.day {
  position: sticky; top: var(--hdr-h); z-index: 2;
  display: flex; align-items: center; gap: 8px; padding: 12px 8px 8px;
  background: linear-gradient(var(--bg) 70%, transparent);
}
.ts {
  display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 999px;
  background: var(--ts-bg); color: var(--ts-text); border: 1px solid var(--ts-border);
  font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums;
}
.day .n { color: var(--text-secondary); font-size: 13px; font-variant-numeric: tabular-nums; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 2px; }
@media (min-width: 720px) { .tiles { grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); } }
.tile {
  position: relative; display: block; aspect-ratio: 1 / 1; padding: 0; border: 0; overflow: hidden;
  background: var(--tile-bg); cursor: pointer; -webkit-touch-callout: none;
}
.tile img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform .15s; }
.tile .ph { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--text-secondary); font-size: 11px; padding: 8px; word-break: break-all; text-align: center; }
.tile .ph svg { width: 26px; height: 26px; }
.tile .badge {
  position: absolute; right: 5px; bottom: 5px; display: inline-flex; align-items: center; gap: 2px; height: 20px; padding: 0 6px 0 4px;
  border-radius: 999px; background: rgba(0, 0, 0, .55); color: #fff; font-size: 11px; font-variant-numeric: tabular-nums;
}
.tile .badge svg { width: 12px; height: 12px; }
.tile .badge b { font-weight: 500; }
.tile .upov { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .28); color: #fff; }
.tile .upov .ring { width: 30px; height: 30px; }
.tile .upov .ring-bg { stroke: rgba(255, 255, 255, .35); }
.tile .upov .ring-fg { stroke: #fff; }
.tile .ck {
  position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center; border: 2px solid #fff; background: rgba(0, 0, 0, .18); color: transparent;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
.tile .ck svg { width: 15px; height: 15px; stroke-width: 2.6; }
.tile.sel .ck { background: var(--primary); border-color: var(--primary); color: #fff; }
.tile.sel img { transform: scale(.9); }

.empty { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 90px 0; color: var(--text-secondary); }
.empty p { margin: 0; }

/* ---------- 面板：都从顶部出（App 的底部托盘会挡住底部） ---------- */
.pop-back { position: fixed; inset: 0; top: var(--hdr-h); z-index: 20; }
.pop {
  position: fixed; z-index: 21; top: calc(var(--hdr-h) + 6px); right: 8px;
  width: min(360px, calc(100vw - 16px)); max-height: calc(100vh - var(--hdr-h) - 24px); overflow: auto;
  background: var(--bg); border-radius: 16px; box-shadow: var(--shadow); padding: 10px;
  animation: pop-in .14s ease-out;
}
@keyframes pop-in { from { opacity: 0; transform: translateY(-6px); } }
.pop-row { display: flex; align-items: center; gap: 8px; padding: 2px 4px 10px; }
.pop-ico { color: var(--text-secondary); display: inline-flex; }
.field {
  flex: 1; min-width: 0; height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); outline: none; font-size: 16px;
}
.field:focus { border-color: var(--primary); }
.pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#pick-desk { grid-template-columns: 1fr; }
.pick-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  height: 88px; border-radius: 12px; background: var(--surface); cursor: pointer; font-weight: 500;
}
.pick-btn svg { width: 28px; height: 28px; color: var(--primary); }
.toggle { display: flex; align-items: center; gap: 10px; padding: 12px 6px 4px; cursor: pointer; font-size: 15px; }
.toggle input, .sw-in { position: absolute; opacity: 0; width: 1px; height: 1px; }
.tg { position: relative; width: 44px; height: 26px; border-radius: 999px; background: var(--surface-2); transition: background .15s; flex: none; }
.tg::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .15s; }
input:checked + .tg { background: var(--ok); }
input:checked + .tg::after { transform: translateX(18px); }

.mi {
  display: flex; align-items: center; gap: 12px; width: 100%; height: 46px; padding: 0 10px;
  border: 0; border-radius: 10px; background: transparent; cursor: pointer; text-align: left; font-size: 15px;
}
@media (hover: hover) { .mi:hover { background: var(--surface); } }
.mi-ico { display: inline-flex; color: var(--text-secondary); }

/* 上传队列 */
.pop-q { width: min(420px, calc(100vw - 16px)); padding: 0; }
.q-head { position: sticky; top: 0; display: flex; align-items: center; gap: 6px; padding: 10px 10px 10px 14px; background: var(--bg); border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.q-head b { font-weight: 600; font-size: 14px; }
.q-head .btn { height: 30px; padding: 0 10px; font-size: 13px; }
.q-need { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 13px; color: var(--danger); }
.q-need .btn { height: 30px; font-size: 13px; flex: none; }
.q-list { padding: 4px 0 6px; }
.q-row { display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 14px; }
.q-th { width: 42px; height: 42px; border-radius: 8px; overflow: hidden; background: var(--surface-2); display: grid; place-items: center; color: var(--text-secondary); flex: none; }
.q-th img { width: 100%; height: 100%; object-fit: cover; display: block; }
.q-tx { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.q-tx b { font-weight: 500; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-tx > span { font-size: 12px; color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-bar { display: block; height: 3px; border-radius: 2px; background: var(--surface-2); overflow: hidden; margin-top: 2px; }
.q-bar i { display: block; height: 100%; width: 0; background: var(--primary); transition: width .3s; }
.q-row.s-done .q-bar i, .q-row.s-dup .q-bar i { background: var(--ok); }
.q-row.s-done .q-tx > span, .q-row.s-dup .q-tx > span { color: var(--ok); }
.q-row.s-fail .q-tx > span, .q-row.s-nofile .q-tx > span { color: var(--danger); }
.q-row.s-wait .q-bar i, .q-row.s-prep .q-bar i { background: var(--text-secondary); }
.q-act { width: 32px; height: 32px; color: var(--text-secondary); }

/* 存到相册的准备条 */
.saver {
  position: fixed; z-index: 35; top: calc(var(--hdr-h) + 6px); left: 50%; transform: translateX(-50%);
  width: min(420px, calc(100vw - 16px)); display: flex; align-items: center; gap: 10px;
  padding: 8px 8px 8px 14px; border-radius: 14px; background: var(--bg); box-shadow: var(--shadow);
  font-size: 14px; font-variant-numeric: tabular-nums;
}
html.viewing .saver { top: calc(env(safe-area-inset-top) + 58px); }
.saver-ring { display: inline-flex; color: var(--primary); }
.saver .btn { height: 34px; }

/* ---------- 大图 ---------- */
.viewer { position: fixed; inset: 0; z-index: 30; color: #fff; touch-action: none; overflow: hidden; -webkit-user-select: none; user-select: none; overscroll-behavior: contain; animation: fade-in .16s ease-out; }
@keyframes fade-in { from { opacity: 0; } }
.v-back { position: absolute; inset: 0; background: #000; }
.v-track { position: absolute; inset: 0; will-change: transform; }
.v-slide { position: absolute; inset: 0; }
.v-frame { position: absolute; inset: 0; bottom: var(--tray); display: flex; align-items: center; justify-content: center; }
.v-media { display: block; max-width: none; flex: none; transform-origin: 50% 50%; -webkit-touch-callout: default; }
.v-video { max-width: 100%; max-height: 100%; width: auto; height: auto; background: #000; }
.v-none { display: flex; flex-direction: column; align-items: center; gap: 10px; color: rgba(255, 255, 255, .7); font-size: 13px; padding: 20px; text-align: center; word-break: break-all; }
.v-none svg { width: 40px; height: 40px; }
.v-upring { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.v-upring .ring { width: 56px; height: 56px; }
.v-upring .ring-bg { stroke: rgba(255, 255, 255, .3); }
.v-upring .ring-fg { stroke: #fff; }
.v-bar {
  position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: 4px;
  padding: 8px 10px 22px; padding-top: max(8px, env(safe-area-inset-top));
  background: linear-gradient(rgba(0, 0, 0, .55), transparent); transition: opacity .18s;
}
.v-bar .icon { color: #fff; }
.v-bar .icon:disabled { opacity: .35; }
@media (hover: hover) { .v-bar .icon:hover { background: rgba(255, 255, 255, .14); } }
.v-meta { display: flex; flex-direction: column; min-width: 0; padding-left: 4px; line-height: 1.25; }
.v-meta b { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.v-meta span { font-size: 12px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.v-nav {
  position: absolute; top: 50%; width: 44px; height: 64px; margin-top: -32px; border: 0; border-radius: 12px;
  background: rgba(255, 255, 255, .1); color: #fff; cursor: pointer; display: grid; place-items: center; transition: opacity .18s;
}
.v-nav.prev { left: 12px; }
.v-nav.next { right: 12px; }
.v-nav svg { width: 26px; height: 26px; }
html.touch .v-nav { display: none; }
.viewer.bare .v-bar, .viewer.bare .v-nav, .viewer.dragging .v-bar, .viewer.dragging .v-nav, .viewer.zoomed .v-nav { opacity: 0; pointer-events: none; }

/* ---------- 拖进来、提示 ---------- */
.drop {
  position: fixed; inset: 10px; z-index: 40; border: 2px dashed var(--primary); border-radius: 18px;
  background: color-mix(in srgb, var(--bg) 82%, transparent); display: grid; place-items: center;
  font-size: 18px; font-weight: 600; color: var(--primary); pointer-events: none;
}
.toast {
  position: fixed; z-index: 50; top: calc(var(--hdr-h) + 10px); left: 50%; transform: translateX(-50%);
  max-width: calc(100vw - 24px); display: flex; align-items: center; gap: 12px;
  padding: 10px 10px 10px 16px; border-radius: 12px; background: #1d1d20; color: #fff; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
html.viewing .toast { top: calc(env(safe-area-inset-top) + 60px); }
.toast:not(:has(button)) { padding-right: 16px; }
.toast.bad { background: var(--danger); }
.toast button { flex: none; height: 30px; padding: 0 12px; border-radius: 8px; border: 0; background: rgba(255, 255, 255, .18); color: #fff; font-weight: 600; cursor: pointer; }
