/* ============ 全局 ============ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Segoe UI', 'PingFang SC', Roboto, 'Helvetica Neue', sans-serif;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
}

body {
  background: linear-gradient(160deg, #1b2242 0%, #2a2f5e 40%, #3b3160 70%, #4a3a6b 100%);
  background-attachment: fixed;
  color: #e6e9ff;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 1rem;
  padding-top: calc(1rem + env(safe-area-inset-top));
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}

/* 星空 */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(2px 2px at 20% 30%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 60% 15%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 80% 40%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 15% 70%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 45% 85%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 90% 80%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 35% 50%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 70% 65%, #fff 50%, transparent 51%);
  opacity: 0.7;
  animation: twinkle 6s ease-in-out infinite alternate;
  pointer-events: none;
  z-index: 0;
}

@keyframes twinkle {
  0% { opacity: 0.5; }
  100% { opacity: 0.9; }
}

/* 返回按钮 */
.back-fab {
  position: fixed;
  top: calc(1rem + env(safe-area-inset-top));
  left: 1rem;
  z-index: 9999;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #e6e9ff;
  font-size: 1.3rem;
  text-decoration: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  transition: all 0.22s ease;
}
.back-fab:active { transform: scale(0.92); }

/* ============ 主容器 ============ */
.gallery-app {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding-top: 3.5rem;
}

/* 头部 */
.app-header {
  text-align: center;
  padding: 0.4rem 0.6rem 1rem;
}

.title-icon {
  font-size: 2.4rem;
  margin-bottom: 0.3rem;
  filter: drop-shadow(0 0 16px rgba(255, 220, 160, 0.4));
  animation: floatIcon 3s ease-in-out infinite;
}
@keyframes floatIcon {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.title-text {
  font-size: clamp(1.4rem, 5vw, 1.8rem);
  font-weight: 700;
  letter-spacing: 1px;
  background: linear-gradient(120deg, #ffd9b3, #ffb3d9, #b3c7ff, #ffd9b3);
  background-size: 300% 300%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 6s ease-in-out infinite;
  margin-bottom: 0.3rem;
}
@keyframes shimmer {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.title-sub {
  font-size: 0.85rem;
  color: rgba(230, 235, 255, 0.6);
}

/* ============ 上传栏 ============ */
.upload-bar {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1rem;
  justify-content: center;
}

.upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.6rem;
  border-radius: 40px;
  background: linear-gradient(135deg, #a0b4ff, #c7a0ff);
  color: #1b2242;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.22s;
  box-shadow: 0 8px 22px rgba(140, 160, 240, 0.45);
  letter-spacing: 0.5px;
  user-select: none;
}
.upload-btn:active { transform: scale(0.97); }
.upload-icon { font-size: 1.1rem; }

.refresh-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  color: #e6e9ff;
  font-size: 1.15rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.22s;
}
.refresh-btn:active { transform: scale(0.92) rotate(180deg); }

/* 上传状态 */
.upload-status {
  text-align: center;
  font-size: 0.85rem;
  color: rgba(230, 235, 255, 0.7);
  min-height: 1.4em;
  margin-bottom: 0.6rem;
  transition: all 0.3s;
}
.upload-status.success { color: rgba(180, 230, 180, 0.9); }
.upload-status.error { color: rgba(255, 150, 150, 0.9); }
.upload-status.uploading { color: rgba(255, 220, 150, 0.9); }

/* ============ 瀑布流 ============ */
.masonry {
  column-count: 4;
  column-gap: 12px;
}

@media (max-width: 1024px) {
  .masonry { column-count: 3; }
}
@media (max-width: 720px) {
  .masonry { column-count: 2; column-gap: 8px; }
}
@media (max-width: 400px) {
  .masonry { column-count: 2; column-gap: 6px; }
}

.gallery-item {
  break-inside: avoid;
  margin-bottom: 12px;
  border-radius: 14px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  position: relative;
}

@media (max-width: 720px) {
  .gallery-item { margin-bottom: 8px; border-radius: 12px; }
}

.gallery-item:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 32px rgba(120, 140, 220, 0.3);
  border-color: rgba(180, 200, 255, 0.4);
}
.gallery-item:active { transform: scale(0.98); }

.gallery-item img {
  width: 100%;
  display: block;
  transition: transform 0.5s ease;
  user-select: none;
  -webkit-user-drag: none;
}
.gallery-item:hover img { transform: scale(1.04); }

/* 加载中占位 */
.gallery-item.loading {
  min-height: 120px;
  background: linear-gradient(110deg, rgba(255,255,255,0.06) 20%, rgba(255,255,255,0.12) 40%, rgba(255,255,255,0.06) 60%);
  background-size: 200% 100%;
  animation: shimmerBg 1.5s linear infinite;
}
@keyframes shimmerBg {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* ============ 空状态 ============ */
.empty-state {
  padding: 3rem 1rem;
  text-align: center;
  color: rgba(230, 235, 255, 0.5);
}
.empty-icon { font-size: 3rem; margin-bottom: 0.6rem; opacity: 0.6; }
.empty-text { font-size: 1rem; margin-bottom: 0.3rem; color: rgba(230, 235, 255, 0.75); }
.empty-sub { font-size: 0.85rem; }

/* ============ 全屏查看器 ============ */
.viewer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.94);
  z-index: 99999;
  display: none;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
}
.viewer.active { display: flex; }

.viewer-img {
  max-width: 95vw;
  max-height: 82vh;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.7);
  transition: transform 0.25s ease;
  will-change: transform;
}

.viewer-close {
  position: fixed;
  top: calc(1rem + env(safe-area-inset-top));
  right: 1rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(10px);
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.viewer-close:active { transform: scale(0.92); }

.viewer-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(10px);
  color: #fff;
  font-size: 1.6rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: background 0.2s;
}
.viewer-nav:active { background: rgba(255, 255, 255, 0.3); }
.viewer-nav.prev { left: 1rem; }
.viewer-nav.next { right: 1rem; }
.viewer-nav.disabled { opacity: 0.25; pointer-events: none; }

.viewer-counter {
  position: fixed;
  bottom: calc(1.4rem + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.9rem;
  background: rgba(0, 0, 0, 0.5);
  padding: 0.35rem 1rem;
  border-radius: 30px;
  letter-spacing: 0.5px;
}

.viewer-hint {
  position: fixed;
  bottom: calc(3.6rem + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.4);
  font-size: 0.78rem;
  white-space: nowrap;
  pointer-events: none;
}

.viewer-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.viewer-loading.show { display: flex; }
.viewer-loading .spinner {
  width: 42px;
  height: 42px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.viewer-loading .loading-text {
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.9rem;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* 小屏 */
@media (max-width: 720px) {
  .viewer-img { max-width: 100vw; max-height: 72vh; border-radius: 0; }
  .viewer-nav { width: 42px; height: 42px; font-size: 1.4rem; }
  .viewer-nav.prev { left: 0.5rem; }
  .viewer-nav.next { right: 0.5rem; }
  .viewer-close { width: 40px; height: 40px; font-size: 1.2rem; }
}