:root {
  --accent: #ff8fb8;
  --accent-2: #9a8bff;
  --bg-1: #fff6fb;
  --bg-2: #f4ecff;
  --bg-3: #eaf4ff;
  --ink: #5a4a60;
  --muted: #9b8aa3;
  --card: #fffdfe;
  --tape: rgba(255, 255, 255, 0.62);
  --star: rgba(255, 175, 205, 0.55);
  --paper: rgba(255, 253, 254, 0.86);
  --shadow: 0 8px 22px rgba(160, 120, 180, 0.16);
  --radius: 18px;
}

html[data-theme='candy'] {
  --accent: #ff9a64;
  --accent-2: #3fc7a4;
  --bg-1: #fff8ef;
  --bg-2: #ffeef2;
  --bg-3: #e9faf3;
  --ink: #5f4a3f;
  --muted: #a08c80;
  --star: rgba(255, 190, 140, 0.5);
  --shadow: 0 8px 22px rgba(200, 140, 110, 0.16);
}

html[data-theme='forest'] {
  --accent: #6cbf80;
  --accent-2: #6f9fe0;
  --bg-1: #f5fbf0;
  --bg-2: #e9f6ec;
  --bg-3: #e8f2fb;
  --ink: #43584c;
  --muted: #84988b;
  --star: rgba(140, 200, 160, 0.45);
  --shadow: 0 8px 22px rgba(90, 140, 110, 0.16);
}

* { box-sizing: border-box; }

/* 覆盖层用 grid 会把 hidden 的默认样式顶掉，必须显式压回去。 */
[hidden] { display: none !important; }

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

body {
  touch-action: manipulation;
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg-1) 0%, var(--bg-2) 52%, var(--bg-3) 100%);
  background-attachment: fixed;
  font: 16px/1.55 "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle, var(--star) 1.6px, transparent 1.7px),
    radial-gradient(circle, var(--star) 1px, transparent 1.1px);
  background-size: 130px 130px, 86px 86px;
  background-position: 12px 26px, 58px 74px;
  opacity: 0.65;
}

/* ---------- 背景装饰 ---------- */

.sky { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }

.cloud {
  position: absolute;
  width: 190px;
  height: 62px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  filter: blur(1px);
}
.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: inherit;
}
.cloud::before { width: 84px; height: 84px; left: 26px; top: -40px; }
.cloud::after { width: 62px; height: 62px; right: 28px; top: -28px; }
.cloud-a { top: 108px; left: -70px; animation: drift 38s ease-in-out infinite; }
.cloud-b { top: 44%; right: -84px; transform: scale(0.8); animation: drift 46s ease-in-out infinite reverse; }

.star {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 2px;
  transform: rotate(45deg);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.9);
  opacity: 0.85;
  animation: twinkle 4.5s ease-in-out infinite;
}
.star-a { top: 24%; left: 12%; }
.star-b { top: 62%; left: 82%; animation-delay: 1.2s; transform: rotate(45deg) scale(0.7); }
.star-c { top: 84%; left: 18%; animation-delay: 2.4s; transform: rotate(45deg) scale(0.55); }

@keyframes drift {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(26px); }
}
@keyframes twinkle {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 0.95; }
}

/* ---------- 顶栏 ---------- */

header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(180deg, var(--paper), rgba(255, 253, 254, 0.62));
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.75);
}

.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }

.logo {
  width: 34px;
  height: 34px;
  flex: none;
  fill: var(--accent);
  filter: drop-shadow(0 3px 6px rgba(255, 143, 184, 0.35));
  animation: sway 6s ease-in-out infinite;
}

@keyframes sway {
  0%, 100% { transform: rotate(-8deg) scale(1); }
  50% { transform: rotate(8deg) scale(1.06); }
}

.brand-text { min-width: 0; }
h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-text p {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.6px;
}

.tools { display: flex; align-items: center; gap: 8px; flex: none; }

button { font: inherit; color: inherit; }

.pill {
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 14px rgba(180, 130, 200, 0.28);
  cursor: pointer;
}
.pill:active { transform: scale(0.96); }
.pill.on { background: #fff; color: var(--muted); box-shadow: 0 2px 8px rgba(160, 120, 180, 0.12); }

.round {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 4px 12px rgba(160, 120, 180, 0.16);
  cursor: pointer;
}
.round svg { width: 21px; height: 21px; fill: var(--accent-2); }
.round:active { transform: scale(0.94); }

/* ---------- 照片墙 ---------- */

main {
  position: relative;
  z-index: 1;
  max-width: 1000px;
  margin: 0 auto;
  padding: 16px 12px calc(120px + env(safe-area-inset-bottom));
}

#gallery { columns: 2; column-gap: 12px; }

@media (min-width: 680px) { #gallery { columns: 3; column-gap: 16px; } main { padding: 20px 18px 120px; } }
@media (min-width: 1000px) { #gallery { columns: 4; } }

.card {
  position: relative;
  margin: 0 0 16px;
  break-inside: avoid;
  padding: 6px;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  transform: rotate(var(--tilt, 0deg));
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.card:nth-child(3n + 1) { --tilt: -1.1deg; }
.card:nth-child(3n) { --tilt: 0.9deg; }
.card:active { transform: rotate(0deg) scale(0.98); }

/* 像贴在相册上的胶带 */
.card::before {
  content: "";
  position: absolute;
  top: -7px;
  left: 50%;
  width: 44px;
  height: 15px;
  margin-left: -22px;
  border-radius: 3px;
  background: var(--tape);
  box-shadow: 0 1px 3px rgba(120, 90, 140, 0.12);
  transform: rotate(-2.5deg);
  pointer-events: none;
}

.card img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 13px;
  background: #f4eef7;
  cursor: zoom-in;
  image-orientation: from-image;
}

.card .date {
  position: absolute;
  left: 12px;
  bottom: 13px;
  padding: 2px 9px;
  font-size: 11px;
  letter-spacing: 0.4px;
  color: #7c6b83;
  background: rgba(255, 255, 255, 0.86);
  border-radius: 999px;
  pointer-events: none;
}

.card .del {
  position: absolute;
  top: -7px;
  right: -6px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #fff;
  color: #e2739a;
  border: 1px solid rgba(226, 115, 154, 0.28);
  box-shadow: 0 4px 10px rgba(180, 110, 140, 0.24);
  cursor: pointer;
}
.card .del svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.card .del:active { transform: scale(0.9); }

/* ---------- 空状态 ---------- */

.empty {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 46px 20px 20px;
  text-align: center;
}
.empty-art { width: 190px; height: auto; margin-bottom: 6px; }
.e-moon { fill: #ffe9a8; }
.e-moon-cut { fill: var(--bg-1); opacity: 0.95; }
.e-cloud { fill: #fff; filter: drop-shadow(0 6px 10px rgba(160, 130, 180, 0.14)); }
.e-star { fill: #ffd47a; }
.e-star.s2 { fill: #b8a9ff; }
.empty-title { margin: 0; font-size: 17px; font-weight: 700; }
.empty-sub { margin: 0; font-size: 13px; color: var(--muted); }

.ghost {
  margin-top: 12px;
  padding: 10px 22px;
  border: 1.5px dashed var(--accent);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

/* ---------- 添加照片按钮 ---------- */

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 15;
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  box-shadow: 0 12px 26px rgba(180, 120, 200, 0.42);
  cursor: pointer;
}
.fab svg { width: 30px; height: 30px; fill: none; stroke: #fff; stroke-width: 2.8; stroke-linecap: round; }
.fab:active { transform: scale(0.93); }

/* ---------- 上传进度 ---------- */

.sheet {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(94px + env(safe-area-inset-bottom));
  z-index: 14;
  max-width: 440px;
  max-height: 42vh;
  margin: 0 auto;
  padding: 12px 14px;
  overflow: auto;
  border-radius: 20px;
  background: rgba(255, 253, 254, 0.96);
  box-shadow: 0 14px 34px rgba(150, 110, 170, 0.24);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 700;
}
.link {
  border: none;
  background: none;
  padding: 2px 4px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}

#upList { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
#upList li { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 12px; }
#upList .fn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
#upList .st { flex: none; color: var(--accent); font-weight: 600; }
#upList .st.bad { color: #e2697c; }

/* ---------- 拖拽提示 ---------- */

.drop-hint {
  position: fixed;
  inset: 12px;
  z-index: 20;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  background: rgba(255, 255, 255, 0.86);
  border: 2px dashed var(--accent);
  border-radius: 24px;
  pointer-events: none;
}

/* ---------- 轻提示 ---------- */

.toast {
  position: fixed;
  left: 50%;
  top: calc(64px + env(safe-area-inset-top));
  z-index: 40;
  transform: translateX(-50%);
  padding: 8px 18px;
  font-size: 13px;
  color: #fff;
  background: rgba(90, 74, 96, 0.86);
  border-radius: 999px;
  box-shadow: 0 8px 20px rgba(90, 74, 96, 0.25);
}

/* ---------- 大图 ---------- */

#lightbox {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  align-items: center;
  justify-items: center;
  padding: calc(52px + env(safe-area-inset-top)) 12px calc(16px + env(safe-area-inset-bottom));
  background: rgba(255, 249, 252, 0.97);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.lb-bar {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  z-index: 31;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}
#lbCount { font-size: 13px; color: var(--muted); padding-left: 6px; }

.lb-btn {
  border: none;
  background: #fff;
  color: var(--ink);
  border-radius: 50%;
  box-shadow: 0 6px 16px rgba(160, 120, 180, 0.2);
  cursor: pointer;
  pointer-events: auto;
}

.lb-close { width: 40px; height: 40px; font-size: 16px; line-height: 1; }
.lb-prev, .lb-next {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 31;
  width: 42px;
  height: 42px;
  font-size: 24px;
  line-height: 1;
  color: var(--accent);
  opacity: 0.85;
}
.lb-prev { left: 8px; }
.lb-next { right: 8px; }

#lightbox figure {
  margin: 0;
  display: grid;
  justify-items: center;
  gap: 10px;
  max-width: 100%;
}

#lbImg {
  max-width: 94vw;
  max-height: 74vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 14px;
  border: 5px solid #fff;
  background: #fff;
  box-shadow: 0 18px 40px rgba(140, 100, 160, 0.28);
  image-orientation: from-image;
}

#lightbox figcaption {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 12px;
  color: var(--muted);
}
#lightbox figcaption a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 4px 12px rgba(160, 120, 180, 0.14);
}

@media (max-width: 420px) {
  .lb-prev, .lb-next { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
