:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --fg: #0f172a;
  --muted: #64748b;
  --accent: #ff4d4f;
  --accent-2: #ff7a3d;
  --line: #e6ebf1;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --accent-grad: linear-gradient(135deg, #ff5a5f, #ff8a3d);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; overflow-x: hidden; }
body {
  margin: 0;
  width: 100%;
  overflow-x: hidden;
  font: 16px/1.7 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--fg);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }

/* ===== Header（参考 Ace Notes：浅背景 + 底边，移动端让位底部 Tab） ===== */
.site-header {
  position: relative;
  text-align: center;
  padding: calc(env(safe-area-inset-top) + 40px) 20px 24px;
  background: linear-gradient(180deg, #ffffff 0%, rgba(255, 255, 255, 0) 100%);
  border-bottom: 1px solid var(--line);
}
.album-title {
  margin: 0;
  font-size: clamp(30px, 6vw, 52px);
  font-weight: 800;
  letter-spacing: 1px;
  background: linear-gradient(90deg, #ff4d4f, #ff8a00, #ffd000);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.album-subtitle { margin: 12px 0 0; color: var(--muted); font-size: 15px; }
.admin-link {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 16px);
  right: 16px;
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  border: 1px solid var(--accent);
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.admin-link:hover { background: var(--accent); color: #fff; }

/* ===== Gallery 网格 ===== */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
}
.card {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  cursor: pointer;
  aspect-ratio: 4 / 3;
  transition: transform .25s ease, box-shadow .25s ease;
}
.card:hover { transform: translateY(-4px); box-shadow: 0 14px 34px rgba(15, 23, 42, 0.14); }
.card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-title {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 22px 12px 10px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.65));
  opacity: 0;
  transition: opacity .25s ease;
}
.card:hover .card-title { opacity: 1; }

/* ===== 加载更多 / 空状态 ===== */
.more-wrap { text-align: center; padding: 10px 0 56px; }
.more-btn {
  background: var(--accent-grad);
  color: #fff;
  border: none;
  padding: 12px 30px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(255, 77, 79, 0.28);
}
.more-btn:hover { filter: brightness(1.05); }
.more-btn:disabled { opacity: .55; cursor: default; box-shadow: none; }
.empty-hint { color: var(--muted); padding: 40px 20px; }

/* ===== Lightbox（看图场景用深色遮罩，功能需要；其余均明亮） ===== */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: calc(env(safe-area-inset-top) + 20px) 16px calc(env(safe-area-inset-bottom) + 20px);
}
.lightbox[hidden] { display: none; }
.lb-figure {
  margin: 0;
  max-width: 94vw;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.lb-img {
  max-width: 94vw;
  max-height: 70vh;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  object-fit: contain;
}
.lb-caption { color: #fff; font-size: 16px; font-weight: 600; text-align: center; }
.lb-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.lb-copy {
  background: var(--accent-grad);
  color: #fff;
  border: none;
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(255, 77, 79, 0.3);
}
.lb-copy:hover { filter: brightness(1.05); }
.lb-close, .lb-nav {
  position: absolute;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: none;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background .2s ease;
}
.lb-close { top: calc(env(safe-area-inset-top) + 16px); right: 16px; width: 44px; height: 44px; font-size: 28px; }
.lb-nav { top: 50%; transform: translateY(-50%); width: 50px; height: 50px; font-size: 30px; }
.lb-prev { left: 12px; }
.lb-next { right: 12px; }
.lb-close:hover, .lb-nav:hover { background: rgba(255, 255, 255, 0.28); }

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 28px);
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 1100;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  max-width: 90vw;
  text-align: center;
}
.toast[hidden] { display: none; }

/* ===== Admin ===== */
.admin-main {
  max-width: 900px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 16px) 16px 80px;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}
.panel h2 { margin-top: 0; }
.form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.form input[type=text],
.form input[type=password],
.title-edit,
.form input[type=file] {
  flex: 1;
  min-width: 0;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 16px;
  background: var(--surface);
  color: var(--fg);
}
.form input[type=file] { flex-basis: 100%; padding: 6px 10px; font-size: 14px; color: var(--muted); }
.form input[type=file]::file-selector-button {
  background: var(--accent-grad);
  color: #fff;
  border: none;
  padding: 9px 22px;
  margin-right: 12px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(255, 77, 79, 0.28);
  -webkit-appearance: none;
  appearance: none;
}
.form input[type=file]::file-selector-button:hover { filter: brightness(1.05); }
.primary-btn {
  background: var(--accent-grad);
  color: #fff;
  border: none;
  padding: 11px 24px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(255, 77, 79, 0.28);
}
.primary-btn:hover { filter: brightness(1.05); }
.ghost-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 9px 18px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
}
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); }
.admin-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.upload-form { margin-bottom: 8px; }
.error { color: #d92d20; font-size: 14px; }
.ok { color: #067647; font-size: 14px; }
.manage-list { display: flex; flex-direction: column; gap: 12px; }
.manage-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}
.manage-row .thumb {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 10px;
  flex-shrink: 0;
}
.manage-row .title-edit { flex: 1; min-width: 0; }
.save-btn, .del-btn {
  padding: 9px 16px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}
.save-btn { background: #2563eb; color: #fff; }
.del-btn { background: #ef4444; color: #fff; }

/* ===== 底部 Tab 栏（移动端原生 App 风格，桌面隐藏；参考 Ace Notes） ===== */
.tab-bar {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 56px;
  padding: 6px 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
.tab-item svg { width: 22px; height: 22px; }
.tab-item.active { color: var(--accent); }
.tab-item:active { opacity: 0.6; }

/* ===== 移动端适配（≤600px；参考 Ace Notes 全套手段） ===== */
@media (max-width: 600px) {
  /* Header 让位底部 Tab；右上链接移入 Tab，避免与标题重叠 */
  .site-header { padding: calc(env(safe-area-inset-top) + 28px) 16px 18px; }
  .album-title { font-size: clamp(28px, 8vw, 38px); }
  .album-subtitle { font-size: 14px; }
  .admin-link { display: none; }

  /* 网格固定 2 列，缩间距，避免窄屏单列留白多或溢出 */
  .gallery {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 14px;
  }
  /* 手机无 hover，标题常显并压低字号 */
  .card-title { opacity: 1; padding: 18px 8px 8px; font-size: 13px; }

  /* 管理列表：窄屏改为纵向堆叠（大图 + 说明框 + 两个按钮），清晰不挤压 */
  .manage-row { display: block; padding: 12px; }
  .manage-row .thumb { width: 100%; height: 180px; margin-bottom: 10px; }
  .manage-row .title-edit { display: block; width: 100%; margin-bottom: 10px; }
  .manage-row .save-btn,
  .manage-row .del-btn { width: 48%; }

  .admin-main { padding: calc(env(safe-area-inset-top) + 12px) 14px 80px; }
  .panel { padding: 18px; }

  /* 表单控件 ≥16px，避免 iOS Safari 聚焦时整页放大导致溢出 */
  .form input[type=text],
  .form input[type=password],
  .title-edit { font-size: 16px; }

  /* 灯箱：箭头缩小贴边、图片降高，复制按钮允许换行铺满 */
  .lb-nav { width: 42px; height: 42px; font-size: 26px; }
  .lb-prev { left: 6px; }
  .lb-next { right: 6px; }
  .lb-img { max-height: 64vh; }
  .lb-copy { flex: 1 1 auto; }

  /* 显示底部 Tab，页面底部留白避免被遮 */
  .tab-bar { display: flex; }
  body { padding-bottom: calc(56px + env(safe-area-inset-bottom)); }
}

@media (max-width: 380px) {
  .gallery { gap: 8px; padding: 10px; }
}
