:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --surface-2: #f2efe9;
  --ink: #1c1b19;
  --muted: #6d6a63;
  --line: #e6e2da;
  --accent: #2f6f62;
  --accent-soft: #dcebe6;
  --accent-ink: #ffffff;
  --danger: #b4432f;
  --tile: #e9e5de;
  --shadow: 0 10px 30px rgba(28, 27, 25, .14);
  --nav-h: 62px;
  --top-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121211; --surface: #1b1a19; --surface-2: #242320; --ink: #ecebe7; --muted: #9c988f;
    --line: #2d2b28; --accent: #73c7b2; --accent-soft: #1f3631; --accent-ink: #0d1f1b; --danger: #ec8a74;
    --tile: #23221f; --shadow: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121211; --surface: #1b1a19; --surface-2: #242320; --ink: #ecebe7; --muted: #9c988f;
  --line: #2d2b28; --accent: #73c7b2; --accent-soft: #1f3631; --accent-ink: #0d1f1b; --danger: #ec8a74;
  --tile: #23221f; --shadow: 0 10px 30px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Segoe UI", sans-serif;
  font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent; overscroll-behavior-y: contain;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }

/* ---------- 版面 ---------- */
.app { min-height: 100vh; }
.main { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 16px); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around; align-items: stretch;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(18px); -webkit-backdrop-filter: saturate(1.4) blur(18px);
  border-top: 1px solid var(--line);
}
.brand { display: none; }
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11.5px; letter-spacing: .02em;
}
.tab svg { width: 24px; height: 24px; padding: 3px 14px; box-sizing: content-box; border-radius: 99px; transition: background .2s; }
.tab.active { color: var(--ink); font-weight: 600; }
.tab.active svg { background: var(--accent-soft); color: var(--accent); }

.top {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-t) + 6px) 12px 6px 18px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: saturate(1.4) blur(18px); -webkit-backdrop-filter: saturate(1.4) blur(18px);
}
.top-normal, .top-select { display: flex; align-items: center; gap: 8px; min-height: 48px; }
.top-select { display: none; padding-left: 0; }
.top.selecting .top-normal { display: none; }
.top.selecting .top-select { display: flex; }
.top.selecting { padding-left: 8px; }
.title-wrap { flex: 1; min-width: 0; }
h1 { font-size: 22px; line-height: 1.2; margin: 0; font-weight: 700; letter-spacing: .01em; }
.sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: flex; align-items: center; gap: 2px; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 99px; display: grid; place-items: center; color: var(--ink);
  transition: background .15s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(.94); }
.icon-btn.on { color: var(--danger); }
.icon-btn.on svg { fill: currentColor; }
.icon-btn:disabled { opacity: .35; pointer-events: none; }
.sel-count { flex: 1; font-weight: 600; font-size: 16px; }

@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 220px 1fr; }
  .tabs {
    position: sticky; top: 0; height: 100vh; flex-direction: column; justify-content: flex-start;
    padding: 18px 12px; gap: 4px; border-top: 0; border-right: 1px solid var(--line); background: var(--bg);
  }
  .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 6px 12px 18px; }
  .brand-mark { width: 26px; height: 26px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), #c98b4f); }
  .tab { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; height: 46px; padding: 0 14px; border-radius: 99px; font-size: 14.5px; }
  .tab svg { padding: 0; background: none !important; }
  .tab.active { background: var(--accent-soft); color: var(--accent); }
  .main { padding-bottom: 40px; min-width: 0; }
  .top { padding-left: 28px; padding-right: 20px; }
}

/* ---------- 時間軸 ---------- */
.timeline { padding: 0 2px; }
.day { margin-bottom: 14px; }
.day-h {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px 8px;
  font-size: 14px; font-weight: 600; color: var(--ink); user-select: none;
}
.day-h small { color: var(--muted); font-weight: 400; font-size: 12.5px; }
.day-check {
  width: 22px; height: 22px; border-radius: 99px; border: 2px solid var(--muted);
  display: none; place-items: center; color: var(--accent-ink);
}
.day-check svg { width: 14px; height: 14px; stroke-width: 3; opacity: 0; }
.selecting-mode .day-check { display: grid; }
.day.all-selected .day-check { background: var(--accent); border-color: var(--accent); }
.day.all-selected .day-check svg { opacity: 1; }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 760px) { .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 3px; } .timeline { padding: 0 20px; } .day-h { padding-left: 4px; } }

.tile {
  position: relative; aspect-ratio: 1; overflow: hidden; background: var(--tile); display: block; width: 100%;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .25s, transform .18s; }
.tile img.ok { opacity: 1; }
.tile .ph {
  position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 11px; text-align: center; padding: 6px;
}
.tile .badge {
  position: absolute; display: flex; align-items: center; gap: 2px; color: #fff; font-size: 11px; font-weight: 600;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.6));
}
.tile .badge svg { width: 16px; height: 16px; }
.tile .b-video { right: 6px; top: 6px; }
.tile .b-fav { left: 6px; bottom: 6px; }
.tile .b-fav svg { fill: #fff; stroke: #fff; }
.tile .sel {
  position: absolute; left: 6px; top: 6px; width: 22px; height: 22px; border-radius: 99px; border: 2px solid #fff;
  background: rgba(0,0,0,.18); display: none; place-items: center; color: var(--accent-ink);
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.4));
}
.tile .sel svg { width: 14px; height: 14px; stroke-width: 3; opacity: 0; }
.selecting-mode .tile .sel { display: grid; }
.tile.selected .sel { background: var(--accent); border-color: var(--accent); }
.tile.selected .sel svg { opacity: 1; }
.tile.selected img { transform: scale(.86); border-radius: 6px; }
.tile:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }

.sentinel { height: 1px; }
.loading-row { text-align: center; color: var(--muted); padding: 24px; font-size: 13px; }
.empty { text-align: center; padding: 72px 28px; color: var(--muted); max-width: 420px; margin: 0 auto; }
.empty svg { width: 46px; height: 46px; stroke-width: 1.3; color: var(--accent); margin-bottom: 10px; }
.empty h2 { color: var(--ink); font-size: 18px; margin: 0 0 6px; }
.empty p { margin: 0 0 18px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 20px;
  border-radius: 99px; background: var(--accent); color: var(--accent-ink); font-weight: 600; text-decoration: none;
}
.btn.ghost { background: var(--surface-2); color: var(--ink); }
.btn.danger { background: var(--danger); color: #fff; }
.btn svg { width: 18px; height: 18px; }

/* ---------- 檢視器 ---------- */
.viewer { position: fixed; inset: 0; z-index: 50; background: #000; color: #fff; display: flex; flex-direction: column; }
.viewer .icon-btn { color: #fff; }
.viewer .icon-btn:hover { background: rgba(255,255,255,.12); }
.viewer .icon-btn.on { color: #ff6b5c; }
.v-bar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2; display: flex; align-items: center; gap: 6px;
  padding: calc(var(--safe-t) + 6px) 8px 8px;
  background: linear-gradient(rgba(0,0,0,.55), transparent); transition: opacity .2s;
}
.v-date { flex: 1; font-size: 13.5px; line-height: 1.3; min-width: 0; }
.v-date small { display: block; opacity: .7; font-size: 11.5px; }
.v-stage { flex: 1; position: relative; overflow: hidden; touch-action: pan-y pinch-zoom; }
.v-stage .slide { position: absolute; inset: 0; display: grid; place-items: center; transition: transform .25s ease; }
.v-stage img, .v-stage video { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.v-stage .v-low { position: absolute; max-width: 100%; max-height: 100%; filter: blur(6px); }
.v-stage .msg { opacity: .75; font-size: 14px; padding: 20px; text-align: center; }
.viewer.chrome-hidden .v-bar, .viewer.chrome-hidden .v-nav { opacity: 0; pointer-events: none; }
.v-nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; border-radius: 99px;
  background: rgba(255,255,255,.12); display: none; place-items: center; color: #fff; z-index: 2;
}
.v-nav.prev { left: 14px; } .v-nav.next { right: 14px; }
@media (hover: hover) and (min-width: 760px) { .v-nav { display: grid; } }
.v-info {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3; background: var(--surface); color: var(--ink);
  border-radius: 18px 18px 0 0; padding: 18px 20px calc(18px + var(--safe-b)); box-shadow: var(--shadow); max-height: 60vh; overflow: auto;
}
.v-info h3 { margin: 0 0 10px; font-size: 15px; }
.v-info dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13.5px; }
.v-info dt { color: var(--muted); }
.v-info dd { margin: 0; word-break: break-all; }
@media (min-width: 900px) { .v-info { left: auto; top: 0; width: 340px; border-radius: 0; } }

/* ---------- Sheet / Toast ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.35); }
.sheet {
  position: fixed; z-index: 61; left: 50%; bottom: 0; transform: translateX(-50%);
  width: min(520px, 100%); background: var(--surface); color: var(--ink);
  border-radius: 20px 20px 0 0; padding: 20px 20px calc(20px + var(--safe-b)); box-shadow: var(--shadow);
  max-height: 85vh; overflow: auto; animation: up .22s ease;
}
@media (min-width: 640px) { .sheet { bottom: auto; top: 50%; transform: translate(-50%, -50%); border-radius: 20px; animation: none; } }
@keyframes up { from { transform: translate(-50%, 30px); opacity: 0; } }
.sheet h2 { margin: 0 0 4px; font-size: 18px; }
.sheet .muted { color: var(--muted); font-size: 13.5px; margin: 0 0 14px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 14px; margin-bottom: 16px; }
.seg label { text-align: center; padding: 9px 4px; border-radius: 10px; font-size: 14px; cursor: pointer; }
.seg input { display: none; }
.seg label:has(input:checked) { background: var(--surface); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.sheet .row-btns { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }
.stat { background: var(--surface-2); border-radius: 14px; padding: 12px; }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.dev { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); font-size: 13.5px; }
.dev svg { color: var(--accent); }
.dev div { flex: 1; }
.dev small { color: var(--muted); display: block; }
.link-list a { display: flex; align-items: center; gap: 10px; padding: 12px 0; color: var(--ink); text-decoration: none; border-top: 1px solid var(--line); font-weight: 500; }

.toast {
  position: fixed; z-index: 70; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-b) + 14px);
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 14px; font-size: 14px;
  box-shadow: var(--shadow); max-width: calc(100% - 32px); display: flex; align-items: center; gap: 12px;
}
.toast .bar { width: 90px; height: 4px; border-radius: 4px; background: color-mix(in srgb, var(--bg) 30%, transparent); overflow: hidden; }
.toast .bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
@media (min-width: 900px) { .toast { bottom: 24px; } }
