:root {
  --bg: #faf8f5;
  --panel: #ffffff;
  --text: #2b2b2b;
  --muted: #8a8a8a;
  --line: #e8e4de;
  --accent: #f0a030;
  --accent-soft: #fdf1dd;
  --nav-w: 220px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a18;
    --panel: #242320;
    --text: #ece8e2;
    --muted: #9a958d;
    --line: #36332e;
    --accent: #f4b04a;
    --accent-soft: #3a2f1e;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
}
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- 密碼 / 登入畫面 ---------- */
.screen { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px 28px;
  width: min(380px, 100%);
  text-align: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .06);
}
.card h1 { margin: 0 0 8px; font-size: 24px; }
.card p { color: var(--muted); }
.card input {
  width: 100%;
  font-size: 20px;
  padding: 10px 12px;
  text-align: center;
  letter-spacing: 2px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 12px;
}
.card button {
  width: 100%;
  padding: 10px;
  font-size: 18px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
}
.msg { min-height: 1.5em; color: #d0543c !important; font-size: 14px; }

/* ---------- 主畫面 ---------- */
#app { height: 100%; display: flex; flex-direction: column; }
header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
header h1 { font-size: 18px; margin: 0; white-space: nowrap; }
#current-label { color: var(--muted); white-space: nowrap; }
.spacer { flex: 1; }
.icon {
  background: none;
  border: none;
  font-size: 20px;
  width: 36px;
  height: 36px;
  border-radius: 8px;
}
.icon:hover { background: var(--accent-soft); }
#menu-btn { display: none; }

.body { flex: 1; display: flex; min-height: 0; }

/* 左側時間軸 */
#timeline {
  width: var(--nav-w);
  flex-shrink: 0;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 12px 8px 40px;
}
#timeline ul { list-style: none; margin: 0; padding: 0; }
#timeline button {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
}
#timeline button:hover { background: var(--accent-soft); }
.year-btn { font-size: 17px; font-weight: 700; }
.year-btn::before { content: "▸ "; color: var(--muted); }
.year.open > .year-btn::before { content: "▾ "; }
.months { margin-left: 14px !important; border-left: 2px solid var(--line); }
.month-btn { font-size: 15px; position: relative; }
.month-btn::before {
  content: "";
  position: absolute;
  left: -7px; top: 50%;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--line);
  transform: translateY(-50%);
}
.month.active > .month-btn { color: var(--accent); font-weight: 700; }
.month.active > .month-btn::before { background: var(--accent); }
.days { margin-left: 16px !important; }
.day-btn { font-size: 13px; color: var(--muted); padding: 3px 10px !important; }
#timeline button { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 右側相片 */
#gallery { flex: 1; overflow-y: auto; padding: 8px 20px 60px; }
.day-section { scroll-margin-top: 8px; }
/* 最後一天也能捲到最上面，點左邊日期時才會對齊 */
.day-section:last-child { min-height: calc(100vh - 120px); min-height: calc(100dvh - 120px); }
.day-section h2 {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0;
  padding: 12px 0 8px;
  background: var(--bg);
  font-size: 18px;
}
.day-title { margin-left: 12px; color: var(--accent); }
.count { color: var(--muted); font-size: 13px; font-weight: normal; margin-left: 10px; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}
.tile {
  position: relative;
  padding: 0;
  border: none;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 1;
  background: var(--line);
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.tile:hover img { transform: scale(1.04); }
.badge {
  position: absolute;
  right: 6px; bottom: 6px;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  border-radius: 50%;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  font-size: 13px;
}
.loading, .empty { color: var(--muted); }
.error { color: #d0543c; white-space: pre-wrap; }

/* ---------- 大圖 ---------- */
#lightbox {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(0, 0, 0, .92);
  display: flex;
  align-items: center;
  justify-content: center;
}
#lb-stage { flex: 1; height: 100%; display: flex; align-items: center; justify-content: center; padding: 48px 8px; }
#lb-stage img { max-width: 100%; max-height: 100%; object-fit: contain; }
#lb-stage iframe { width: min(100%, 1200px); height: 100%; border: 0; }
#lightbox .icon { color: #fff; font-size: 28px; }
#lightbox .icon:hover { background: rgba(255, 255, 255, .12); }
#lightbox .icon:disabled { opacity: .2; cursor: default; }
#lightbox .nav { font-size: 48px; width: 56px; height: 80px; flex-shrink: 0; }
#lb-close { position: absolute; top: 8px; right: 8px; }
#lb-caption {
  position: absolute;
  bottom: 12px; left: 0; right: 0;
  text-align: center;
  color: #ddd;
  font-size: 14px;
  padding: 0 16px;
}

/* ---------- 手機 ---------- */
@media (max-width: 720px) {
  #menu-btn { display: inline-block; }
  header h1 { font-size: 16px; }
  #timeline {
    position: fixed;
    top: 53px; bottom: 0; left: 0;
    z-index: 5;
    transform: translateX(-100%);
    transition: transform .2s;
    box-shadow: 4px 0 20px rgba(0, 0, 0, .15);
  }
  body.nav-open #timeline { transform: none; }
  #gallery { padding: 4px 16px 60px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 4px; }
  #lightbox .nav { display: none; }
}
