/* ---------- 设计变量 ---------- */
:root {
  --bg: #fbfbfa;
  --surface: #ffffff;
  --surface-2: #f4f4f2;
  --border: #e3e3df;
  --text: #1f1f1d;
  --text-muted: #71716b;
  --accent: #2f6f4f;
  --accent-text: #ffffff;
  --danger: #a4342b;
  --warn: #8a5a00;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 12px rgb(0 0 0 / 4%);
  --maxw: 1180px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --surface: #1f2023;
    --surface-2: #26272b;
    --border: #34363a;
    --text: #e8e8e4;
    --text-muted: #9a9a94;
    --accent: #5fae86;
    --accent-text: #0d1a13;
    --danger: #e0796d;
    --warn: #d8a852;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 14px rgb(0 0 0 / 25%);
  }
}

*, *::before, *::after { box-sizing: border-box; }

/* hidden 属性必须能压过组件自己的 display。
   浏览器默认样式表里的 [hidden]{display:none} 属于 UA 层，
   任何作者样式里的 display（.lightbox 的 grid、.upload-list 的 grid…）
   都会盖掉它 —— 于是 el.hidden = true 看着生效实则毫无作用。
   这里用 !important 把它拉回来，这是这条规则唯一正确的写法。 */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 system-ui, -apple-system, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

img { max-width: 100%; height: auto; display: block; }

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}
pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  overflow-x: auto;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; flex: none; }
.brand:hover { text-decoration: none; }
.brand-mark { font-size: 18px; }

.search { flex: 1; min-width: 0; }
.search input {
  width: 100%;
  max-width: 420px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: inherit;
  font: inherit;
}
.search input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.nav { display: flex; align-items: center; gap: 14px; flex: none; color: var(--text-muted); }
.nav a:hover, .nav button:hover { color: var(--text); }

.share-badge {
  margin-left: auto;
  font-size: 13px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
}

/* ---------- 布局 ---------- */
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 28px 20px 64px; }
.narrow { max-width: 460px; margin: 40px auto; }
.center { text-align: center; }

.footer {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 24px 20px 40px;
  color: var(--text-muted);
  font-size: 13px;
  border-top: 1px solid var(--border);
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.page-head h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: -0.01em; }
h2 { font-size: 17px; margin: 28px 0 10px; }

.lede { margin: 6px 0; color: var(--text); }
.muted { color: var(--text-muted); font-size: 14px; margin: 4px 0; }
.warn { color: var(--warn); }
.ok { color: var(--accent); }
.break { word-break: break-all; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar { display: flex; justify-content: flex-end; margin-bottom: 14px; }

.empty, .empty-state {
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
}
.empty-state .btn { margin-top: 10px; }

.error-code { font-size: 56px; font-weight: 700; margin: 0; color: var(--text-muted); }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-block;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 85%, black); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 10%, var(--surface)); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.linklike {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--border);
}
.linklike:hover { color: var(--text); }
.linklike-danger { color: var(--danger); }
.inline { display: inline; }

/* ---------- 提示 ---------- */
.flashes { margin-bottom: 20px; display: grid; gap: 8px; }
.flash {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 14px;
  word-break: break-word;
}
.flash-success { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.flash-error { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); color: var(--danger); }

.badge {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgb(0 0 0 / 62%);
  color: #fff;
  backdrop-filter: blur(4px);
}
.badge-private { position: static; margin-left: 6px; vertical-align: middle; }
.badge-warn { background: rgb(138 90 0 / 82%); }
h1 .badge-private { font-size: 12px; font-weight: 400; }

/* ---------- 相册列表 ---------- */
.album-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
}
.album-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease;
}
.album-card:hover { transform: translateY(-2px); }
.album-card a:hover { text-decoration: none; }
.album-cover { position: relative; aspect-ratio: 4 / 3; background: var(--surface-2); }
.album-cover img { width: 100%; height: 100%; object-fit: cover; }
.album-cover-blank {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 13px;
}
.album-info { padding: 12px 14px 14px; }
.album-info h2 { margin: 0 0 2px; font-size: 16px; }

/* ---------- 照片网格 ---------- */
.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}
.grid-item { min-width: 0; }
.tile {
  position: relative;
  display: block;
  /* 统一 3:4 竖版。刻意不用每张照片各自的比例 —— 那样每行高低参差，
     视线没有稳定的基线；固定比例后网格才是整齐的矩阵。
     横图、方图溢出的部分交给 object-fit 居中裁掉。 */
  aspect-ratio: 3 / 4;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;       /* 填满并裁切，绝不拉伸变形 */
  object-position: center; /* 从中心裁，主体通常在中间 */
}
.tile:hover img { opacity: 0.92; }

.tile-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
}
.tile-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile-date, .tile-album { flex: none; }
.tile-actions {
  display: flex;
  gap: 10px;
  margin-top: 2px;
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.grid-item:hover .tile-actions,
.grid-item:focus-within .tile-actions { opacity: 1; }

/* ---------- 照片详情 ---------- */
.breadcrumb { margin-bottom: 16px; color: var(--text-muted); font-size: 14px; }

.photo-view {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 28px;
  align-items: start;
}
@media (max-width: 860px) {
  .photo-view { grid-template-columns: 1fr; }
}
.photo-stage { margin: 0; }
.photo-stage img {
  width: 100%;
  max-height: 76vh;
  object-fit: contain;
  background: var(--surface-2);
  border-radius: var(--radius);
}
.photo-stage figcaption {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}
.photo-side h1 { font-size: 20px; margin: 0 0 8px; word-break: break-word; }
.photo-side h2 { font-size: 14px; text-transform: none; color: var(--text-muted); margin: 22px 0 8px; }

.meta-list { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0; font-size: 14px; }
.meta-list dt { color: var(--text-muted); }
.meta-list dd { margin: 0; }
.meta-grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 20px; }
.meta-grid dt { grid-column: 1; }

/* ---------- 标签 ---------- */
.tag-list { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; padding: 0; }
.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
}
.tag:hover { background: var(--surface-2); text-decoration: none; }
.tag-count { color: var(--text-muted); font-size: 0.8em; }
.tag-cloud {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: baseline;
  margin: 0;
  padding: 0;
}

/* ---------- 表单 ---------- */
.form { max-width: 560px; }
.form-compact { max-width: none; }
.field { display: block; margin-bottom: 16px; }
.field-label { display: block; margin-bottom: 4px; font-size: 14px; color: var(--text-muted); }
.field-label em { color: var(--danger); font-style: normal; }
.field-hint { display: block; margin-top: 4px; font-size: 12.5px; color: var(--text-muted); }
.field-error { display: block; margin-top: 4px; font-size: 13px; color: var(--danger); }
.field-check { display: flex; gap: 8px; align-items: flex-start; }

input[type="text"], input[type="password"], input[type="search"], textarea, select {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: inherit;
  font: inherit;
}
textarea { resize: vertical; }
select { width: auto; }
input:focus-visible, textarea:focus-visible, select:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.form-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.form-row label { font-size: 14px; color: var(--text-muted); }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; flex-wrap: wrap; }

/* ---------- 上传 ---------- */
.uploader { margin-bottom: 28px; }
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); }
.dropzone.is-over {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}
.dropzone-title { margin: 0 0 4px; font-size: 15px; }

.upload-list { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 6px; }
.upload-row {
  display: grid;
  grid-template-columns: 1fr 90px auto;
  gap: 10px;
  align-items: center;
  font-size: 13px;
  padding: 7px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.upload-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-bar { height: 5px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.upload-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s ease; }
.upload-status { font-size: 12px; color: var(--text-muted); text-align: right; }
.upload-row.is-error { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.upload-row.is-error .upload-status { color: var(--danger); }
.upload-row.is-done .upload-status { color: var(--accent); }

/* ---------- 面板 / 表格 ---------- */
.panel, .panel-open {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 22px;
}
.panel > summary { cursor: pointer; font-weight: 600; }
.panel[open] > summary { margin-bottom: 14px; }
.panel-open > h2:first-child { margin-top: 0; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 10px 0 4px; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table th { color: var(--text-muted); font-weight: 500; font-size: 13px; }
.table tbody tr:last-child td { border-bottom: 0; }
.row-muted { color: var(--text-muted); }
.col-check { width: 32px; }
.thumb-xs { width: 44px; height: 44px; object-fit: cover; border-radius: 4px; }

.copyable { cursor: pointer; border-bottom: 1px dotted var(--text-muted); }

/* ---------- 灯箱 ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: rgb(0 0 0 / 88%);
  padding: 24px;
}
.lightbox img {
  max-width: 100%;
  max-height: calc(100vh - 96px);
  object-fit: contain;
  border-radius: 4px;
}
.lightbox-caption {
  position: absolute;
  bottom: 18px;
  left: 0;
  right: 0;
  text-align: center;
  color: #d8d8d4;
  font-size: 13px;
  padding: 0 60px;
}
.lightbox-close, .lightbox-prev, .lightbox-next {
  position: absolute;
  background: rgb(255 255 255 / 12%);
  border: 0;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
}
.lightbox-close:hover, .lightbox-prev:hover, .lightbox-next:hover { background: rgb(255 255 255 / 24%); }
.lightbox-close { top: 18px; right: 18px; }
.lightbox-prev { left: 18px; top: 50%; transform: translateY(-50%); }
.lightbox-next { right: 18px; top: 50%; transform: translateY(-50%); }

/* 原图加载中的转圈。压在图片上方居中，不改变布局。 */
.lightbox.is-loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  border: 3px solid rgb(255 255 255 / 25%);
  border-top-color: #fff;
  border-radius: 50%;
  pointer-events: none; /* 纯装饰，别挡住背景点击关闭 */
  animation: lightbox-spin 0.7s linear infinite;
}
.lightbox.is-loading img { opacity: 0.35; }
@keyframes lightbox-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .lightbox.is-loading::after { animation-duration: 2.4s; }
}

@media (max-width: 600px) {
  .topbar-inner { flex-wrap: wrap; }
  .search { order: 3; flex-basis: 100%; }
  .search input { max-width: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
  .wrap { padding: 20px 14px 48px; }
}
