:root {
  --bg: #0b0d12;
  --panel: #141821;
  --card-bg: #1a1f2b;
  --text: #e8ecf3;
  --muted: #8b93a3;
  --accent: #5b8cff;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}

/* hidden 属性必须强制隐藏，避免被 flex/grid 布局覆盖 */
[hidden] { display: none !important; }

/* ---------- 顶部工具条 ---------- */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: rgba(12, 14, 20, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid #232a38;
}

.brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: linear-gradient(90deg, var(--accent), #9db8ff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.layout-switch {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.layout-btn, .icon-btn {
  border: 1px solid #2a3242;
  background: var(--panel);
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  transition: all 0.15s ease;
}

.layout-btn:hover, .icon-btn:hover {
  color: var(--text);
  border-color: #3a4ad8;
}

.layout-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---------- 主区域 ---------- */
main { padding: 20px; }
.gallery { width: 100%; }

.card {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--card-bg);
  margin: 0;
  cursor: zoom-in;
}

.card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.25s ease;
}

.card:hover img { transform: scale(1.03); }

/* ---------- 瀑布流（JS 最短列分配） ---------- */
.gallery.masonry {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.masonry-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

/* ---------- 流式（flex wrap 保持宽高比） ---------- */
.gallery.flow {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-start;
}

/* ---------- 自定义（grid） ---------- */
.gallery.custom {
  display: grid;
  border-radius: 8px;
}

/* ---------- 加载 / 空状态 / 错误 ---------- */
.loading {
  text-align: center;
  color: var(--muted);
  padding: 60px 0;
  font-size: 14px;
}
.loading::before {
  content: '';
  display: inline-block;
  width: 22px;
  height: 22px;
  margin-right: 10px;
  vertical-align: -5px;
  border: 2px solid #2a3242;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; color: var(--muted); padding: 80px 0; }
.empty .muted { margin-top: 8px; font-size: 13px; opacity: 0.7; }
.error-tip { text-align: center; color: #ff7b72; padding: 40px; }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.88);
  padding: 20px;
}

.lightbox-content {
  max-width: 94vw;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.lightbox-content img {
  max-width: 94vw;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
}

.lightbox-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.lightbox-controls button,
.lightbox-controls a {
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid #2a3242;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s ease;
}

.lightbox-controls button:hover,
.lightbox-controls a:hover { border-color: var(--accent); }

#lightboxCounter { color: var(--muted); font-size: 13px; }

/* ---------- 弹窗（二维码 / 自定义） ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  padding: 20px;
}

.modal-box {
  background: var(--panel);
  border: 1px solid #232a38;
  border-radius: 14px;
  padding: 24px;
  min-width: 300px;
  max-width: 90vw;
}

.modal-box h3 {
  margin-bottom: 16px;
  font-size: 16px;
}

.modal-box label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 14px;
}

.modal-box input[type="number"],
.modal-box input[type="color"] {
  background: #0d1017;
  border: 1px solid #2a3242;
  color: var(--text);
  border-radius: 8px;
  padding: 6px 8px;
  width: 120px;
  font-family: inherit;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 18px;
}

.modal-actions button {
  padding: 7px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
}

#cSave { background: var(--accent); color: #fff; }
#cCancel { background: #232a38; color: var(--text); }
#qrClose { background: #232a38; color: var(--text); }

#qrcode {
  display: inline-block;
  padding: 10px;
  background: #fff;
  border-radius: 8px;
  margin-bottom: 12px;
}

#qrUrl {
  color: var(--muted);
  font-size: 13px;
  word-break: break-all;
  margin-bottom: 8px;
}

body.no-scroll { overflow: hidden; }

/* ---------- 响应式 ---------- */
@media (max-width: 640px) {
  .toolbar { flex-wrap: wrap; gap: 10px; padding: 10px 12px; }
  .layout-switch { margin-left: 0; order: 3; width: 100%; }
  .layout-btn { flex: 1; text-align: center; }
  main { padding: 12px; }
  .modal-box { min-width: 0; width: 92vw; }
}
