/* ============================================================
   图仓 · 样式
   底色取自素材本身的低饱和中性调；强调色为墨梅，只用于焦点与状态。
   层级靠底色差和发丝线，不靠阴影和圆角堆叠。
   ============================================================ */

:root {
  --paper:      #ede9e5;
  --surface:    #faf8f6;
  --surface-2:  #f3f0ec;
  --ink:        #1b1719;
  --dim:        #6e6864;
  --faint:      #7c7570;
  --limit:      #6e6864;   /* 对 paper #ede9e5 为 4.54:1，既是"安静"的又能看清 */
  --line:       #dcd6d0;
  --line-strong:#c9c2bb;
  --accent:     #7a3b5c;
  --accent-ink: #fff8fa;
  --danger:     #9d3b33;
  --ok:         #2f6b46;

  --shell: 1280px;
  --gap: 10px;
  --row-gap: 26px;
  --cap: 24px;
  --r: 4px;
  --r-lg: 7px;

  --step-1: 0.72rem;
  --step-2: 0.8rem;
  --step-3: 0.9rem;
  --step-4: 1.05rem;
  --step-5: 1.4rem;

  --sans: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
          "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "Liberation Mono", monospace;

  --shadow-pop: 0 10px 30px -12px rgba(27, 23, 25, 0.28), 0 2px 6px -2px rgba(27, 23, 25, 0.12);
  --shadow-lift: 0 14px 34px -16px rgba(27, 23, 25, 0.4);
}

:root[data-theme="dark"] {
  --paper:      #161415;
  --surface:    #1f1c1d;
  --surface-2:  #272324;
  --ink:        #efebe8;
  --dim:        #a39b96;
  --faint:      #8b837e;
  --limit:      #928a85;
  --line:       #302b2d;
  --line-strong:#443d3f;
  --accent:     #c98aa6;
  --accent-ink: #1b1719;
  --danger:     #d98a83;
  --ok:         #86c9a3;
  --shadow-pop: 0 10px 30px -12px rgba(0, 0, 0, 0.6), 0 2px 6px -2px rgba(0, 0, 0, 0.4);
  --shadow-lift: 0 14px 34px -16px rgba(0, 0, 0, 0.7);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:      #161415;
    --surface:    #1f1c1d;
    --surface-2:  #272324;
    --ink:        #efebe8;
    --dim:        #a39b96;
    --faint:      #8b837e;
    --limit:      #928a85;
    --line:       #302b2d;
    --line-strong:#443d3f;
    --accent:     #c98aa6;
    --accent-ink: #1b1719;
    --danger:     #d98a83;
    --ok:         #86c9a3;
    --shadow-pop: 0 10px 30px -12px rgba(0, 0, 0, 0.6), 0 2px 6px -2px rgba(0, 0, 0, 0.4);
    --shadow-lift: 0 14px 34px -16px rgba(0, 0, 0, 0.7);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.7;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

img { max-width: 100%; display: block; }
a { color: inherit; }
button { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.shell {
  max-width: var(--shell);
  margin: 0 auto;
  padding: clamp(18px, 3.4vw, 34px) clamp(14px, 3vw, 28px) 40px;
}

/* ================= 顶栏 ================= */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: clamp(16px, 2.6vw, 24px);
}

.brand {
  display: inline-flex; align-items: center; gap: 9px;
  text-decoration: none;
  font-size: var(--step-4);
  font-weight: 600;
  letter-spacing: 0.02em;
}
.mark { flex: none; color: var(--accent); }

.spacer { flex: 1; }

/* ================= 上传区 ================= */

.upload {
  position: relative;
  min-height: clamp(84px, 12vw, 116px);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  padding: clamp(18px, 3vw, 28px) clamp(18px, 3vw, 30px);
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: border-color 150ms ease-out, background 150ms ease-out;
}
.upload:hover { border-color: var(--line-strong); }
.upload.is-over {
  border-color: var(--accent);
  background: var(--surface-2);
}

.upload-text { flex: 1; min-width: 0; }
.upload-text strong {
  display: block;
  font-size: clamp(1.08rem, 2.1vw, 1.38rem);
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.3;
}

/* 技术约束，不是使用说明 —— 留一行最小的，别抢注意力 */
.limit {
  flex: none;
  color: var(--limit);
  font-family: var(--mono);
  font-size: var(--step-1);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.note { margin: 6px 0 0; color: var(--faint); font-size: var(--step-2); }

.alert {
  margin-bottom: 14px;
  padding: 11px 14px;
  border-radius: var(--r);
  font-size: var(--step-3);
  border: 1px solid transparent;
}
.alert.error { background: color-mix(in srgb, var(--danger) 10%, transparent); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 24%, transparent); }
.alert.ok    { background: color-mix(in srgb, var(--ok) 10%, transparent);     color: var(--ok);     border-color: color-mix(in srgb, var(--ok) 24%, transparent); }

/* ================= 按钮 ================= */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px;
  padding: 6px 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  background: var(--surface);
  font-size: var(--step-3);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background 130ms ease-out, border-color 130ms ease-out, color 130ms ease-out;
}
.btn:hover { background: var(--surface-2); border-color: var(--dim); }
.btn:active { background: var(--line); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}
.btn.primary:hover { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.btn.ghost { background: transparent; border-color: transparent; color: var(--dim); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); border-color: transparent; }

.btn.danger { color: var(--danger); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); border-color: color-mix(in srgb, var(--danger) 34%, transparent); }

.btn.icon { width: 34px; padding: 0; }
.btn.tiny { min-height: 28px; padding: 3px 9px; font-size: var(--step-2); }
.btn.copied { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }

/* ================= 区块标题 ================= */

.section { margin-top: clamp(30px, 5vw, 48px); }

.section-head {
  display: flex; align-items: baseline; gap: 10px;
  padding-bottom: 9px;
  margin-bottom: var(--row-gap);
  border-bottom: 1px solid var(--line);
}
.section-head h2 {
  margin: 0;
  font-size: var(--step-4);
  font-weight: 600;
  letter-spacing: 0.01em;
}
.section-head .count {
  color: var(--faint);
  font-size: var(--step-2);
  font-family: var(--mono);
}
.section-head .head-note {
  margin-left: auto;
  color: var(--faint);
  font-size: var(--step-1);
  font-family: var(--mono);
}

/* ================= 图墙：按行自适应 =================
   行高固定、宽度按 aspect-ratio 分配，原图比例完整保留。
   ================================================= */

.grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--row-gap) var(--gap);
  align-items: flex-start;
}
.grid > .shot { margin: 0; }

.shot {
  position: relative;
  min-width: 0;
  flex: none;
}

/* JS 可测量前的占位：所有图排成一行，测完立即接管 */
.grid:not([data-laid]) .shot { width: 300px; }

.shot-open {
  display: block;
  position: relative;
  width: 100%;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface-2);
  overflow: hidden;
  cursor: zoom-in;
  transition: border-color 140ms ease-out;
}
.shot-open:hover { border-color: var(--line-strong); }
.shot-open img {
  width: 100%;
  height: auto;
  vertical-align: top;
}

.shot-cap {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--cap);
  margin-top: 5px;
}
.shot-meta {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  font-size: var(--step-1);
  color: var(--faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.shot-cap .btn.icon {
  width: 28px; min-height: 28px;
  color: var(--faint);
  border-color: transparent;
  background: transparent;
}
.shot:hover .shot-cap .btn.icon { color: var(--dim); }
.shot-cap .btn.icon:hover { color: var(--ink); background: var(--surface-2); border-color: var(--line); }

/* 窄屏：单列，自然高度，绝不裁切 */
@media (max-width: 720px) {
  .grid { gap: 22px 0; }
  .grid > .shot, .grid:not([data-laid]) .shot { width: 100%; }
  .shot-open { cursor: pointer; }
}

/* ================= 复制菜单 ================= */

.menu {
  position: fixed;
  /* 必须高于灯箱（90）：灯箱里的「其他格式」也复用这个菜单，
     否则菜单会开在灯箱遮罩下面，看起来像点了没反应。 */
  z-index: 95;
  min-width: 172px;
  padding: 5px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
  display: none;
}
.menu.open { display: block; }
.menu button {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  font-size: var(--step-3);
  text-align: left;
  cursor: pointer;
}
.menu button:hover, .menu button:focus-visible { background: var(--surface-2); }
.menu button .k { color: var(--faint); font-family: var(--mono); font-size: var(--step-1); }

/* ================= 上传队列 ================= */

.queue { display: none; flex-direction: column; gap: 6px; margin-top: var(--row-gap); }
.queue.visible { display: flex; }

.qitem {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
}
.qitem-thumb {
  width: 36px; height: 36px; flex: none;
  object-fit: cover; border-radius: 3px;
  background: var(--surface-2);
}
.qitem-body { flex: 1; min-width: 0; }
.qitem-name { font-size: var(--step-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qitem-track { margin-top: 5px; height: 2px; background: var(--line); overflow: hidden; }
.qitem-fill { height: 100%; width: 0; background: var(--accent); transition: width 180ms ease-out; }
.qitem-state {
  flex: none; min-width: 42px; text-align: right;
  font-size: var(--step-2); color: var(--dim); font-family: var(--mono);
}
.qitem.done .qitem-state { color: var(--ok); }
.qitem.error .qitem-state { color: var(--danger); }

/* ================= 空状态 ================= */

.empty {
  padding: clamp(30px, 6vw, 52px) 20px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  text-align: center;
}
.empty strong {
  display: block;
  font-size: var(--step-3);
  font-weight: 500;
  color: var(--faint);
  letter-spacing: 0.4em;
  text-indent: 0.4em;
}

/* ================= 灯箱 ================= */

.lb {
  position: fixed; inset: 0; z-index: 90;
  display: none;
  /* 纯深色，不做半透明也不做毛玻璃。
     用 94% 透明 + blur 时，浅色页面会透出一层灰雾，
     糊掉的缩略图还会跟正在看的图抢注意力 —— 灯箱的意义就是排除干扰。
     固定深色也意味着它不跟着 --ink 翻转（暗色模式下 --ink 接近白色）。 */
  background: #131011;
}
.lb.open { display: block; }

.lb-bar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 12px clamp(12px, 2.4vw, 22px);
  color: var(--paper);
}
.lb-count { font-family: var(--mono); font-size: var(--step-2); opacity: 0.92; }
.lb-bar .spacer { flex: 1; }
.lb-bar .btn {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.2);
  color: #fff;
}
.lb-bar .btn:hover { background: rgba(255, 255, 255, 0.18); border-color: rgba(255, 255, 255, 0.34); }
.lb-bar .btn.copied { color: #a8e6c1; border-color: rgba(168, 230, 193, 0.5); }

.lb-stage {
  position: absolute;
  inset: 56px clamp(12px, 4vw, 56px) 52px;
  display: flex; align-items: center; justify-content: center;
}
.lb-stage img {
  max-width: 100%; max-height: 100%;
  width: auto; height: auto;
  object-fit: contain;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.04);
}

/* 原图可能有好几 MB，加载期间给个明确的转圈，
   否则打开灯箱只看到一片黑，像坏了。 */
.lb-loading {
  position: absolute;
  width: 30px; height: 30px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-top-color: rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  animation: lb-spin 720ms linear infinite;
}
.lb-loading[hidden] { display: none; }
@keyframes lb-spin { to { transform: rotate(360deg); } }

.lb-foot {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 13px 16px;
  color: var(--paper);
  font-family: var(--mono);
  font-size: var(--step-2);
  opacity: 0.92;
  text-align: center;
}
.lb-foot span.sep::before { content: "·"; margin-right: 10px; opacity: 0.45; }

.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  transition: background 140ms ease-out;
}
.lb-nav:hover { background: rgba(255, 255, 255, 0.2); }
.lb-nav[disabled] { opacity: 0.25; cursor: default; }
.lb-prev { left: clamp(8px, 2vw, 22px); }
.lb-next { right: clamp(8px, 2vw, 22px); }

@media (max-width: 720px) {
  /* 手机上把翻页键放到图片下方两侧，避免压住画面主体 */
  .lb-nav {
    top: auto; bottom: 34px; transform: none;
    width: 48px; height: 48px;
  }
  .lb-prev { left: 16px; }
  .lb-next { right: 16px; }
  /* 说明行要排在翻页键之上，否则会压在按钮上 */
  .lb-stage { inset: 52px 10px 168px; }
  .lb-foot { bottom: 100px; }
}

/* ================= 轻提示 ================= */

.toast {
  position: fixed;
  left: 50%; bottom: 26px;
  transform: translate(-50%, 10px);
  z-index: 100;
  max-width: min(90vw, 420px);
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-size: var(--step-2);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease-out, transform 160ms ease-out;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); color: #fff; }

/* ================= 表单 / 登录 ================= */

.field { margin-bottom: 13px; }
.field label {
  display: block; margin-bottom: 5px;
  color: var(--dim); font-size: var(--step-2);
}
.field input, .field select {
  width: 100%; min-height: 40px;
  padding: 8px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--ink);
  font: inherit; font-size: var(--step-3);
}
.field input:focus, .field select:focus {
  outline: 2px solid var(--accent); outline-offset: 0;
  border-color: var(--accent);
}

.auth {
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: clamp(16px, 4vw, 32px);
}
.auth-card {
  width: 100%; max-width: 336px;
  padding: clamp(22px, 4vw, 30px);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
}
.auth-card h1 {
  margin: 0 0 5px;
  font-size: var(--step-5); font-weight: 600;
}
.auth-card .sub { margin: 0 0 20px; color: var(--dim); font-size: var(--step-2); }
.auth-card .mark { margin-bottom: 12px; }

/* ================= 管理台 ================= */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  overflow: hidden;
  margin-bottom: clamp(20px, 3.4vw, 30px);
}
.stat { padding: 14px 16px; border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; }
.stat .k { color: var(--dim); font-size: var(--step-2); }
.stat .v {
  margin-top: 2px;
  font-size: 1.3rem; font-weight: 600;
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.panel {
  margin-bottom: clamp(18px, 3vw, 26px);
  padding: clamp(14px, 2.4vw, 20px);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
}
.panel h3 {
  margin: 0 0 13px;
  font-size: var(--step-3); font-weight: 600;
  letter-spacing: 0.02em;
}

.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-bottom: 13px;
}
.toolbar input, .toolbar select {
  min-height: 34px;
  padding: 5px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--ink);
  font: inherit; font-size: var(--step-2);
}

.table { width: 100%; border-collapse: collapse; font-size: var(--step-2); }
.table th, .table td {
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table th {
  color: var(--dim); font-size: var(--step-1);
  font-weight: 500; letter-spacing: 0.03em;
  border-bottom-color: var(--line-strong);
}
.table td { font-variant-numeric: tabular-nums; }
.table img {
  width: 42px; height: 42px; object-fit: cover;
  border-radius: 3px; background: var(--surface-2);
}

.log {
  max-height: 260px; overflow-y: auto;
  padding: 10px 12px;
  border-radius: var(--r);
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: var(--step-1);
  color: var(--dim);
  line-height: 1.9;
}

@media (max-width: 620px) {
  .stat { border-right: 0; border-bottom: 1px solid var(--line); }
  .stat:last-child { border-bottom: 0; }
  /* 窄屏放不下「拖入」和约束行并排，约束行挪到下面独占一行 */
  .upload {
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 10px;
    min-height: 0;
  }
}

/* ================= 动效（只保留有意义的） ================= */

.lb.open .lb-stage img { animation: lb-in 180ms ease-out; }
@keyframes lb-in {
  from { opacity: 0; transform: scale(0.985); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
