:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #1c1c1f;
  --text-dim: #6b6b73;
  --accent: #3a7afe;
  --accent-hover: #2c66e0;
  --danger: #d83a3a;
  --danger-hover: #b82c2c;
  --border: #e2e4e8;
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 12pt;
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(247, 247, 248, 0.9);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  padding-top: max(10px, env(safe-area-inset-top));
}

.brand {
  font-size: 12pt;
  font-weight: 700;
  letter-spacing: 0.3px;
  line-height: 1.15;
}

.actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.filter-select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12pt;
  height: 34px;
  cursor: pointer;
}

.primary-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12pt;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
  min-height: 34px;
}
.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:active { transform: scale(0.97); }

.icon-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 12pt;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--surface-2); }

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
}

.status, .empty {
  color: var(--text-dim);
  text-align: center;
  padding: 40px 16px;
  font-size: 12pt;
  line-height: 1.6;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
@media (min-width: 600px) {
  .grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
}
@media (min-width: 900px) {
  .grid { grid-template-columns: repeat(4, 1fr); gap: 10px; }
}
@media (min-width: 1200px) {
  .grid { grid-template-columns: repeat(5, 1fr); gap: 10px; }
}

.cell {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
}
.cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.25s ease;
}
.cell:hover img { transform: scale(1.04); }

.cell .time-tag {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 5px 6px;
  font-size: 9pt;
  color: #fff;
  background: linear-gradient(to top, rgba(0,0,0,0.65), rgba(0,0,0,0));
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
.cell:hover .time-tag { opacity: 1; }
@media (hover: none) {
  .cell .time-tag { opacity: 1; }
}

.cell.uploading::after {
  content: "上傳中…";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12pt;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 24, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
  touch-action: pan-y;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: 100%;
  max-height: 80vh;
  border-radius: 8px;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.lightbox-btn {
  position: absolute;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  border: none;
  font-size: 22px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.lightbox-btn:hover { background: rgba(255, 255, 255, 0.28); }
.lightbox-btn.danger { background: rgba(216, 58, 58, 0.85); }
.lightbox-btn.danger:hover { background: rgba(216, 58, 58, 1); }

.lightbox-close { top: 16px; right: 16px; }
.lightbox-delete { top: 16px; right: 70px; }
.lightbox-prev { left: 16px; top: 50%; transform: translateY(-50%); }
.lightbox-next { right: 16px; top: 50%; transform: translateY(-50%); }

.lightbox-meta {
  position: absolute;
  bottom: 24px;
  left: 0;
  right: 0;
  text-align: center;
  color: #d6d6dc;
  font-size: 12pt;
  padding: 0 16px;
}
