:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --text: #2b2724;
  --muted: #8a827a;
  --line: #ebe5dc;
  --accent: #d97757;
  --accent-text: #ffffff;
  --danger: #c4453b;
  --placeholder: #efe9e0;
  --shadow: 0 6px 24px rgba(60, 40, 20, 0.12);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1816;
    --surface: #26231f;
    --text: #efe9e2;
    --muted: #9c948b;
    --line: #36322d;
    --accent: #e58a6b;
    --placeholder: #2e2a26;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); min-height: 1.5em; margin: 0; font-size: 14px; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  border-radius: 10px;
  padding: 12px;
  font-weight: 600;
}
.btn-primary:disabled { opacity: 0.6; }
.btn-text { background: none; border: 0; padding: 8px 4px; color: var(--muted); }
.btn-text.strong { color: var(--accent); font-weight: 600; }
.btn-text.danger { color: var(--danger); }
.btn-text:disabled { opacity: 0.4; }

/* 登录 */
.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}
.login-logo { font-size: 44px; }
.login-card h1 { margin: 0; font-size: 24px; }
.login-card p { margin: 0 0 8px; }
.login-card input {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 12px 14px;
  outline: none;
}
.login-card input:focus { border-color: var(--accent); }

/* 顶栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.topbar h1 { margin: 0; font-size: 20px; }

/* 天数 */
.days-card {
  margin: 4px 16px 8px;
  padding: 18px 16px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
  max-width: 560px;
}
@media (min-width: 600px) { .days-card { margin: 4px auto 12px; } }
.days-card p { margin: 0; }
.days-label { color: var(--muted); font-size: 14px; }
.days-count {
  color: var(--accent);
  font-size: 52px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.days-count small { font-size: 18px; font-weight: 600; margin-left: 4px; color: var(--text); }

/* 照片墙 */
.wall { padding: 0 8px 120px; max-width: 1200px; margin: 0 auto; }
.month { margin-bottom: 20px; }
.month h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  margin: 12px 4px 8px;
}
.cols { display: flex; gap: 6px; align-items: flex-start; }
.col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.tile {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 10px;
  overflow: hidden;
  background: var(--placeholder);
}
.tile img { display: block; width: 100%; height: 100%; object-fit: cover; }
.tile .cap {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 18px 8px 6px;
  font-size: 12px;
  text-align: left;
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.55));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty { text-align: center; padding: 80px 16px; }
.empty-icon { font-size: 48px; }
.empty p { margin: 4px 0; }
.sentinel { height: 1px; }

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 30px;
  box-shadow: var(--shadow);
  cursor: pointer;
  z-index: 20;
}

/* 上传面板 */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet-panel {
  width: 100%;
  max-width: 560px;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.previews { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.previews img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: var(--placeholder); }
.sheet textarea {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  resize: vertical;
  outline: none;
}
.sheet textarea:focus { border-color: var(--accent); }
.sheet p { margin: 0; }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

/* 大图查看 */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #000;
  color: #f2f2f2;
  display: flex;
  flex-direction: column;
}
.viewer-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  touch-action: pan-y;
}
.viewer-stage img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; }
.viewer-close {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  right: 8px;
  z-index: 2;
  background: rgba(255, 255, 255, 0.12);
  border: 0;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 18px;
}
.viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.12);
  border: 0;
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 28px;
  line-height: 1;
}
.viewer-nav.prev { left: 8px; }
.viewer-nav.next { right: 8px; }
@media (hover: none) { .viewer-nav { display: none; } }
.viewer-info { padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); }
.viewer-info p { margin: 0; }
.viewer-caption { white-space: pre-wrap; margin-bottom: 4px !important; }
.viewer .muted { color: #a8a8a8; }
.viewer-actions { display: flex; gap: 16px; margin-top: 4px; }
.viewer .btn-text { color: #cfcfcf; padding-left: 0; }
.viewer .btn-text.danger { color: #ff8a80; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(100px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  background: rgba(30, 30, 30, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 14px;
  max-width: calc(100% - 32px);
}
