/* 視覺風格參考 https://conversionn.com/ 重新調色：標題字型 Cardo（襯線、900 粗體），內文/按鈕字型
   Noto Sans TC；主色為紅色系（--accent 系列），輔助色為琥珀色系（--amber 系列，用在評分/提示這類
   「次要重點」上，跟紅色的「主要動作」做出區隔）；按鈕一律改成膠囊形狀＋懸停上浮＋色彩陰影。 */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;500;700;900&family=Cardo:wght@400;700&display=swap');

:root {
  --bg: #fff7ed;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #475569;
  --text-light: #94a3b8;

  /* 主色：紅色系（對應按鈕、連結、強調文字） */
  --accent: #b91c1c;
  --accent-dark: #991b1b;
  --accent-light: #fee2e2;
  --accent-pale: #fff5f5;

  /* 輔助色：琥珀色系（評分/提示等「次要重點」用，跟主色的按鈕動作做出區隔） */
  --amber: #d97706;
  --amber-dark: #b45309;
  --amber-pale: #fffbeb;

  --danger: #b91c1c;

  --radius-pill: 999px;
  --radius-md: 16px;
  --radius-sm: 10px;

  /* 素材漏斗關鍵字膠囊標籤色碼：下層=最深紅底白字，中層=主紅底白字，上層=淺紅底深紅字 */
  --funnel-lower-bg: var(--accent-dark);
  --funnel-lower-text: #ffffff;
  --funnel-middle-bg: var(--accent);
  --funnel-middle-text: #ffffff;
  --funnel-upper-bg: var(--accent-light);
  --funnel-upper-text: var(--accent-dark);
}

* { box-sizing: border-box; }

/* Any element with the `hidden` attribute must actually stay hidden, even ones (like
   .toolbar and .modal-overlay below) that also set their own `display` for when they're
   shown. Without this !important, an author `display: flex/grid/...` rule silently wins
   over the browser's built-in `[hidden] { display: none }` default - the element then
   renders regardless of the `hidden` attribute, which is exactly the "modal pops up
   immediately on page load" bug this line fixes. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", -apple-system, sans-serif;
  font-size: 15px;
}

.topbar {
  padding: 20px 32px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.brand-link { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-logo { width: 42px; height: 42px; object-fit: contain; display: block; }
.brand-name {
  font-size: 22px; font-family: Cardo, "Noto Sans TC", serif; font-weight: 900; color: var(--text);
  line-height: 1;
}
.brand-name-en { color: var(--accent); }
.back-home-link { font-size: 13px; color: var(--muted); text-decoration: none; font-weight: 600; }
.back-home-link:hover { color: var(--accent-dark); text-decoration: underline; }
.topbar h1 {
  margin: 0 0 4px; font-size: 26px; font-family: Cardo, "Noto Sans TC", serif; font-weight: 900;
  color: var(--text);
}
.subtitle { margin: 0; color: var(--muted); font-size: 14px; }
.subtitle-accent { color: var(--accent); font-weight: 900; }

/* 內部測試帳號登入徽章：固定在右上角，搜尋前後兩種版面都看得到（見 app.html 的說明註解）。 */
.account-badge {
  position: fixed; top: 14px; right: 16px; z-index: 60;
  display: flex; align-items: center; gap: 10px;
  background: var(--accent-pale); color: var(--accent-dark);
  border: 1px solid var(--accent-light); border-radius: var(--radius-pill);
  padding: 8px 14px; font-size: 13px; font-weight: 700;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}
.account-badge button {
  border: none; background: transparent; color: var(--muted); font-size: 12px;
  font-weight: 600; cursor: pointer; text-decoration: underline; padding: 0;
}
.account-badge button:hover { color: var(--accent-dark); }
@media (max-width: 480px) {
  .account-badge { top: auto; bottom: 14px; left: 12px; right: 12px; justify-content: center; }
}

main { max-width: 1200px; margin: 0 auto; padding: 24px 32px 64px; }

/* ---- 搜尋前的「Google 風格」置中首頁：logo＋輸入框都置中在畫面正中央，提交搜尋後（見
   app.js 的 submit handler 移除 body.search-idle）立刻切回原本上方固定的搜尋列版面。 ---- */
.idle-hero { display: none; }
body.search-idle .topbar { display: none; }
body.search-idle main {
  max-width: none; min-height: 100vh; margin: 0; padding: 24px 32px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
body.search-idle .idle-hero {
  display: flex; flex-direction: column; align-items: center; margin-bottom: 32px; text-align: center;
}
body.search-idle .search-form { width: 100%; max-width: 680px; }
body.search-idle .search-form input[type="text"]#keyword { font-size: 19px; padding: 16px 20px; }
body.search-idle .search-form button#search-btn { font-size: 16px; padding: 14px 28px; }
body.search-idle .advanced { text-align: center; }
body.search-idle .advanced summary { display: inline-block; }
body.search-idle .advanced-grid { text-align: left; }

.idle-hero-brand { display: flex; flex-direction: column; align-items: center; gap: 14px; text-decoration: none; margin-bottom: 14px; }
.idle-hero-logo { width: 96px; height: 96px; object-fit: contain; display: block; }
.idle-hero-name {
  font-size: 38px; font-family: Cardo, "Noto Sans TC", serif; font-weight: 900; color: var(--text); line-height: 1;
}
.idle-hero-name-en { color: var(--accent); }
.idle-hero-tagline { margin: 0; color: var(--muted); font-size: 15px; }

@media (max-width: 480px) {
  body.search-idle main { padding: 24px 20px; }
  .idle-hero-logo { width: 72px; height: 72px; }
  .idle-hero-name { font-size: 28px; }
  body.search-idle .search-form input[type="text"]#keyword { font-size: 16px; padding: 14px 16px; }
  body.search-idle .search-form button#search-btn { padding: 14px 18px; font-size: 14px; }
}

.search-form { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 18px 20px; }
.search-form .row { display: flex; gap: 10px; }
.search-form input[type="text"]#keyword {
  flex: 1; min-width: 0; padding: 12px 15px; font-size: 16px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: inherit; color: var(--text);
}
button {
  padding: 12px 24px; font-size: 15px; border: none; border-radius: var(--radius-pill);
  background: var(--accent); color: #fff; cursor: pointer; font-weight: 700;
  font-family: inherit; box-shadow: 0 4px 16px rgba(185, 28, 28, 0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}
button:hover { background: var(--accent-dark); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(185, 28, 28, 0.4); }
button:disabled { background: #c9c3b8; color: #6b6559; cursor: not-allowed; box-shadow: none; transform: none; }

.advanced { margin-top: 14px; }
.advanced summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.advanced-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px; margin-top: 12px;
}
.advanced-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.advanced-grid input[type="text"], .advanced-grid input[type="number"] {
  padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; color: var(--text);
  font-family: inherit;
}
.advanced-grid label.checkbox { flex-direction: row; align-items: center; gap: 8px; grid-column: 1 / -1; }
.advanced-grid label.advanced-full { grid-column: 1 / -1; }

.status { margin-top: 16px; padding: 12px 16px; border-radius: var(--radius-sm); font-size: 14px; }
.status.info { background: var(--amber-pale); color: var(--amber-dark); }
.status.error { background: var(--accent-pale); color: var(--danger); }
.status.loading { display: flex; align-items: center; gap: 10px; }

.spinner {
  width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid rgba(180, 83, 9, 0.25);
  border-top-color: var(--amber-dark);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toolbar {
  display: flex; align-items: center; gap: 12px; margin-top: 22px; flex-wrap: wrap;
}
.toolbar select { padding: 9px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; font-family: inherit; }
.result-summary { color: var(--muted); font-size: 13px; white-space: nowrap; }
.keyword-filter-clear {
  background: var(--accent-light); color: var(--accent-dark); border: none;
  padding: 8px 16px; font-size: 12.5px; font-weight: 700; border-radius: var(--radius-pill); white-space: nowrap;
  box-shadow: none;
}
.keyword-filter-clear:hover { background: var(--accent-dark); color: #fff; transform: translateY(-2px); box-shadow: 0 6px 16px rgba(153, 27, 27, 0.3); }

.results {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-md);
  overflow: hidden; display: flex; flex-direction: column;
}
.card .media { width: 100%; aspect-ratio: 4 / 5; background: #eee; overflow: hidden; }
.card .media img, .card .media video {
  width: 100%; height: 100%; object-fit: contain; object-position: center; display: block;
}
.card .body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.page-name { font-weight: 700; font-size: 14px; color: var(--text); text-decoration: none; }
.page-name:hover { text-decoration: underline; }
.score-badge {
  font-size: 11px; font-weight: 700; color: var(--amber-dark);
  background: var(--amber-pale); padding: 3px 10px; border-radius: var(--radius-pill); white-space: nowrap;
}
.meta-line { font-size: 11px; color: var(--text-light); }
.ad-text {
  font-size: 13px; line-height: 1.5; margin: 4px 0 0; white-space: pre-line;
  max-height: 5.4em; overflow: hidden;
}
.ad-text.expanded { max-height: none; }
.toggle-text {
  align-self: flex-start; background: none; color: var(--accent-dark); padding: 0;
  font-size: 12px; font-weight: 700; box-shadow: none;
}
.toggle-text:hover { background: none; text-decoration: underline; transform: none; box-shadow: none; }

.keyword-section { margin-top: 2px; }
.keyword-section-title {
  margin: 0 0 4px; font-size: 10.5px; font-weight: 700; color: var(--muted);
  letter-spacing: 0.02em;
}
.keyword-badges { display: flex; flex-wrap: wrap; gap: 5px; }
.keyword-badge {
  display: inline-block; font-size: 10.5px; font-weight: 700; line-height: 1.4;
  padding: 3px 9px; border-radius: var(--radius-pill); white-space: nowrap; cursor: pointer;
  border: 2px solid transparent;
}
.keyword-badge.tier-lower { background: var(--funnel-lower-bg); color: var(--funnel-lower-text); }
.keyword-badge.tier-middle { background: var(--funnel-middle-bg); color: var(--funnel-middle-text); }
.keyword-badge.tier-upper { background: var(--funnel-upper-bg); color: var(--funnel-upper-text); }
.keyword-badge:hover { opacity: 0.85; }
.keyword-badge.active { border-color: var(--text); box-shadow: 0 0 0 1px var(--text); }

.card-actions { margin-top: 6px; display: flex; gap: 8px; }
.card-actions button {
  flex: 1; font-size: 12.5px; padding: 9px 8px; border-radius: var(--radius-pill); font-weight: 700; white-space: nowrap;
}
.download-btn { background: #fff; color: var(--accent-dark); border: 2px solid var(--accent-dark); box-shadow: none; }
.download-btn:hover { background: var(--accent-pale); color: var(--accent-dark); transform: translateY(-2px); box-shadow: none; }
.apply-btn { background: var(--accent); color: #fff; border: none; }
.apply-btn:hover { background: var(--accent-dark); }

.empty-note { color: var(--muted); font-size: 14px; padding: 20px 4px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(30, 28, 24, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 1000;
}
.modal {
  background: var(--panel); border-radius: var(--radius-md); max-width: 640px; width: 100%;
  max-height: 85vh; display: flex; flex-direction: column; padding: 20px 22px 22px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-head h2 { margin: 0; font-size: 20px; font-family: Cardo, "Noto Sans TC", serif; font-weight: 900; }
.modal-close {
  background: none; border: none; font-size: 22px; line-height: 1; color: var(--muted);
  padding: 0 4px; cursor: pointer; font-weight: 400; box-shadow: none;
}
.modal-close:hover { color: var(--text); background: none; transform: none; box-shadow: none; }
.modal-hint { font-size: 12.5px; color: var(--muted); margin: 0 0 12px; line-height: 1.6; }
.modal-hint-tight { margin-bottom: 8px; }
.modal-hint strong { color: var(--text); }
.modal-note { font-size: 12px; color: var(--text-light); margin: -6px 0 16px; line-height: 1.5; }
.modal-actions { margin-top: 12px; display: flex; justify-content: flex-end; gap: 8px; }
.modal-actions-grid { justify-content: flex-start; flex-wrap: wrap; }
.modal-actions-grid button { flex: 1 1 220px; }
.modal-cta { width: 100%; font-size: 16px; padding: 16px 24px; }

.modal-links-row { display: flex; justify-content: center; gap: 24px; margin-top: 4px; }
.modal-link {
  background: none; border: none; box-shadow: none; padding: 4px 6px; margin: 0;
  color: var(--muted); font-size: 13px; font-weight: 600; text-decoration: none;
}
.modal-link:hover { background: none; transform: none; box-shadow: none; color: var(--text); text-decoration: underline; }
.modal-link:disabled,
.modal-link:disabled:hover {
  background: none; color: var(--text-light); cursor: not-allowed; text-decoration: none; box-shadow: none; transform: none;
}
.modal-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.modal-field label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.modal-field input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; color: var(--text);
  font-family: inherit;
}
.modal-error { color: var(--danger); font-size: 12.5px; margin: -6px 0 12px; }
.modal-secondary { background: #fff; color: var(--accent-dark); border: 2px solid var(--accent-dark); box-shadow: none; }
.modal-secondary:hover { background: var(--accent-pale); color: var(--accent-dark); box-shadow: none; }

#modal-video-digest { background: var(--amber-pale); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; }
#modal-digest-status { margin: 0; font-size: 12px; line-height: 1.6; color: var(--muted); }
#modal-digest-status.error { color: var(--danger); }
#modal-extract-digest { margin-top: 10px; }

.modal-toast {
  margin: 10px 0 0; padding: 8px 12px; border-radius: var(--radius-sm); font-size: 12.5px; font-weight: 600;
  background: #eaf6ec; color: #2f7a3d; border: 1px solid #bfe3c2;
}
.modal-toast.error { background: var(--accent-pale); color: var(--danger); border-color: #f0c6c6; }
.login-modal { max-width: 420px; }
.modal-toast-pop { animation: modal-toast-pop 0.22s ease-out; }
@keyframes modal-toast-pop {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Google 登入按鈕 / 帳號列 */
.account-badge .account-login-btn {
  text-decoration: none; font-size: 13px; font-weight: 700; color: var(--accent-dark);
}
.google-signin-wrap { display: flex; justify-content: center; min-height: 44px; margin: 8px 0 4px; }
