:root {
  --bg: #faf8f5; --surface: #ffffff; --fg: #1f1d22; --muted: #6d6873; --line: #e8e3dc;
  --accent: #e2457a; --accent-fg: #ffffff; --mark: #ffd6e4;
  --op: #2f6fd6; --ed: #8a4fd0; --song: #c77700;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 14px rgb(0 0 0 / .05);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121115; --surface: #1c1b20; --fg: #eceaf0; --muted: #a09ba8; --line: #2d2b33;
    --accent: #ff6f9c; --accent-fg: #1a0a10; --mark: #5c2238;
    --op: #7fb0ff; --ed: #c79cff; --song: #ffbf5c;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.55 system-ui, -apple-system, "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif; }
button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- 頂部 ---------- */
.top { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.bar { max-width: 1280px; margin: 0 auto; padding: 12px 16px 8px; display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.brand { margin: 0; font-size: 19px; font-weight: 800; letter-spacing: .02em; white-space: nowrap; }
.brand span { color: var(--accent); margin-left: 4px; }
.search { flex: 1 1 320px; display: flex; }
.search input { width: 100%; padding: 10px 14px; border-radius: 999px; border: 1.5px solid var(--line);
  background: var(--surface); font-size: 17px; outline: none; transition: border-color .15s; }
.search input:focus { border-color: var(--accent); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
select, .ghost, .toggle, .seg button, .more, .lb-actions button { border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 6px 14px; cursor: pointer; }
select:disabled { opacity: .5; cursor: not-allowed; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; border-radius: 0; padding: 6px 12px; background: transparent; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
.status { max-width: 1280px; margin: 0 auto; padding: 0 16px 10px; color: var(--muted); font-size: 14px; }
.count-link { font: inherit; color: var(--fg); background: none; border: 0; padding: 0 2px; cursor: pointer;
  text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
.count-link:hover { text-decoration-color: currentColor; }
.count-link.on { font-weight: 700; text-decoration: none; }

/* ---------- 結果網格 ---------- */
main { max-width: 1280px; margin: 0 auto; padding: 16px 16px 48px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.card { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.thumb { display: block; padding: 0; border: 0; background: var(--line); cursor: zoom-in; aspect-ratio: 16 / 9; width: 100%; }
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; transition: opacity .2s; }
.thumb:hover img { opacity: .9; }
.card figcaption { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.line { margin: 0; font-size: 16px; font-weight: 600; word-break: break-word; }
.line2 { margin: 2px 0 0; font-size: 14px; word-break: break-word; }
.scr { margin: 2px 0 0; font-size: 12px; color: var(--muted); word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.line.scr-only { font-weight: 500; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3;
  -webkit-box-orient: vertical; overflow: hidden; }
.chip.pos { color: var(--muted); }
.toggle[aria-pressed="false"] { opacity: .55; text-decoration: line-through; }
.lb-extra .scr { -webkit-line-clamp: unset; display: block; font-size: 13px; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
.meta { margin: 0; color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; font-variant-numeric: tabular-nums; }
.chip { font-size: 12px; padding: 0 8px; border-radius: 999px; border: 1px solid currentColor; line-height: 1.6; }
.meta { flex-wrap: wrap; row-gap: 2px; }
.meta .where, .meta .also, .chip { white-space: nowrap; }
.meta .also { font-size: 12px; }
.chip.op { color: var(--op); } .chip.ed { color: var(--ed); } .chip.song { color: var(--song); }
.empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 48px 16px; }
.more { display: block; margin: 24px auto 0; padding: 8px 28px; }
#sentinel { height: 1px; }

/* ---------- 燈箱 ---------- */
.lb { width: min(1200px, 100vw); max-width: 100vw; max-height: 100dvh; padding: 0; border: 0; border-radius: var(--radius);
  background: var(--surface); color: var(--fg); overflow: visible; }
.lb::backdrop { background: rgb(0 0 0 / .78); }
.lb-fig { margin: 0; display: flex; flex-direction: column; max-height: 100dvh; }
/* 圖片區先固定成 16:9 的黑框（截圖都是 1920×1080）：圖還沒載入時按鈕就已經在最後的位置，不會往下跑而按錯 */
.lb-stage { background: #000; overflow: auto; border-radius: var(--radius) var(--radius) 0 0; width: 100%;
  aspect-ratio: 16 / 9; max-height: calc(100dvh - 160px); display: flex; }
.lb-stage img { display: block; margin: auto; width: 100%; height: 100%; object-fit: contain; cursor: zoom-in;
  -webkit-touch-callout: default; -webkit-user-select: auto; user-select: auto; } /* iPhone 長按 →「儲存到照片」 */
.lb-stage img.zoom { width: auto; height: auto; max-width: none; max-height: none; object-fit: fill; margin: 0; cursor: zoom-out; }
.lb-stage img.loading { visibility: hidden; } /* 換圖時先留黑，不閃上一張 */
.lb-info { padding: 12px 16px 16px; display: flex; flex-direction: column; gap: 6px; }
.lb-text { margin: 0; font-size: 20px; font-weight: 700; }
.lb-meta { margin: 0; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.lb-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.lb-actions .primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
.lb-nav, .lb-close { position: absolute; border: 0; background: rgb(0 0 0 / .55); color: #fff; cursor: pointer;
  width: 44px; height: 44px; border-radius: 50%; font-size: 26px; line-height: 1; display: grid; place-items: center; }
.lb-nav { top: 30%; }
.lb-nav.prev { left: 8px; } .lb-nav.next { right: 8px; }
.lb-nav:disabled { opacity: .25; cursor: default; }
.lb-close { top: 8px; right: 8px; font-size: 18px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--fg); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 15px;
  transition: opacity .2s, transform .2s; z-index: 100; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 手機 ---------- */
@media (max-width: 560px) {
  .bar { padding: 10px 12px 6px; gap: 8px; }
  .brand { font-size: 17px; }
  .search { flex-basis: 100%; order: 3; }
  .filters { order: 4; width: 100%; }
  .seg button { padding: 6px 10px; }
  .status { padding: 0 12px 8px; }
  main { padding: 10px 10px 40px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .card figcaption { padding: 6px 8px 8px; }
  .line { font-size: 14px; }
  .meta { font-size: 12px; flex-wrap: wrap; gap: 4px 6px; }
  .lb { border-radius: 0; }
  .lb-stage { border-radius: 0; }
  .lb-text { font-size: 17px; }
}

/* 進站問答頁（deploy/functions/_middleware.js：還沒答對時顯示） */
.gate { max-width: 32rem; margin: 18vh auto 0; padding: 0 16px; text-align: center; }
.gate h1 { font-size: 1.5rem; margin-bottom: .75rem; }
.gate-form { display: grid; gap: .75rem; margin-top: 1.5rem; }
.gate-q { font-size: 1.15rem; }
.gate-form input { font: inherit; padding: .6rem .8rem; border-radius: .5rem; border: 1px solid #8884; text-align: center; }
.gate-form button { font: inherit; padding: .6rem; border-radius: .5rem; cursor: pointer; }
.gate-note { color: #d33; margin: 0; }
