:root {
  --bg: #f4f5f8;
  --bg-card: #ffffff;
  --bg-subtle: #f0f2f6;
  --text: #181b21;
  --text-muted: #5c6371;
  --border: #e2e5ea;
  --accent: #2454e0;
  --accent-hover: #1c42b8;
  --accent-soft: #e9eefd;
  --accent-text: #ffffff;
  --danger: #d6304a;
  --danger-soft: #fce8ea;
  --warn: #a05a00;
  --warn-soft: #fdf1dd;
  --ok: #147a3d;
  --ok-soft: #e3f6ea;
  --pending: #5c6371;
  --shadow-sm: 0 1px 2px rgba(20, 24, 33, 0.06);
  --shadow-md: 0 4px 16px rgba(20, 24, 33, 0.08);
  --radius: 12px;
  --radius-sm: 8px;

  /* 圖表色:政黨色是「身分色」,刻意沿用各黨代表色系(綠/藍/青/橘)讓讀者一眼認得出來,
     但原始黨徽色直接拿來畫圖表是不合格的(國民黨深藍太暗、對比不足),
     所以保留色相、把明度與彩度調到通過無障礙檢核的版本。
     這組數值是用 dataviz 的 validate_palette 實測跑過的:明度帶、彩度下限、
     色盲可辨識度(ΔE)、一般視覺可辨識度、與背景對比 5 項全數通過,淺色/深色各驗一次。
     要改色前請重跑驗證,不要憑感覺調。 */
  --chart-dpp: #1B9431;
  --chart-kmt: #2A4FD0;
  --chart-tpp: #0E97A6;
  --chart-pfp: #D95F02;
  --chart-other: #6B7280;
  --chart-bar: #2454e0;
  --chart-grid: #e2e5ea;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --bg-card: #191c22;
    --bg-subtle: #21252c;
    --text: #e9ebf0;
    --text-muted: #9aa1b1;
    --border: #2b3039;
    --accent: #6690ff;
    --accent-hover: #85a5ff;
    --accent-soft: #1c2740;
    --accent-text: #0f1115;
    --danger: #ff7a8f;
    --danger-soft: #3a1a22;
    --warn: #f0b94d;
    --warn-soft: #3a2c10;
    --ok: #5fd68e;
    --ok-soft: #123a24;
    --pending: #9aa1b1;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
    /* 深色模式不是把淺色直接翻轉,是另外挑一組再對深色背景重驗過的(同樣5項全通過) */
    --chart-dpp: #2FA848;
    --chart-kmt: #6366E8;
    --chart-tpp: #1BA3B4;
    --chart-pfp: #D66E1A;
    --chart-other: #9aa1b1;
    --chart-bar: #6690ff;
    --chart-grid: #2b3039;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115;
  --bg-card: #191c22;
  --bg-subtle: #21252c;
  --text: #e9ebf0;
  --text-muted: #9aa1b1;
  --border: #2b3039;
  --accent: #6690ff;
  --accent-hover: #85a5ff;
  --accent-soft: #1c2740;
  --accent-text: #0f1115;
  --danger: #ff7a8f;
  --danger-soft: #3a1a22;
  --warn: #f0b94d;
  --warn-soft: #3a2c10;
  --ok: #5fd68e;
  --ok-soft: #123a24;
  --pending: #9aa1b1;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --chart-dpp: #2FA848;
  --chart-kmt: #6366E8;
  --chart-tpp: #1BA3B4;
  --chart-pfp: #D66E1A;
  --chart-other: #9aa1b1;
  --chart-bar: #6690ff;
  --chart-grid: #2b3039;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 16px;
  line-height: 1.75;
  overflow-wrap: break-word;
  word-break: break-word;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
h1, h2, h3 { line-height: 1.35; letter-spacing: -0.01em; }
p { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }

header.site-header {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 10px 16px;
  padding: 14px 20px; background: var(--bg-card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
header.site-header h1 { margin: 0; font-weight: 700; }
header.site-header h1 a { color: var(--text); }
.site-brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.site-brand:hover { text-decoration: none; }
/* 國旗外框細線:深色模式下紅色邊緣才不會跟深色背景糊在一起 */
.site-flag { width: 72px; height: 48px; flex-shrink: 0; display: block;
  box-shadow: 0 0 0 1px var(--border); border-radius: 2px; }
/* 國號與站名兩行同字級、同粗細、同顏色(使用者要求:國號不能比站名小) */
.site-title { display: flex; flex-direction: column; line-height: 1.15; font-size: 26px; font-weight: 800; letter-spacing: 0.02em; }
.header-actions { display: flex; gap: 8px; align-items: center; font-size: 14px; flex-wrap: wrap; }

.disclaimer {
  background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid var(--border);
  padding: 9px 20px; font-size: 13px; text-align: center; line-height: 1.5;
}

/* 版面寬度:內容區放寬到 1280px 以善用桌機橫向空間,
   但長篇政見文字另外用 .prose 限制在 ~70 字元寬 —— 文字行太長反而難讀,
   寬度是拿來並排圖表/卡片的,不是拿來把段落拉長的。 */
main { max-width: 1280px; margin: 0 auto; padding: 24px 24px 60px; }
main.narrow { max-width: 900px; }

/* 統計數字磚 */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-tile { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm); }
.stat-tile .value { font-size: 30px; font-weight: 700; line-height: 1.15; letter-spacing: -0.02em; }
.stat-tile .label { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* 圖表區:寬螢幕並排,窄螢幕自動堆疊 */
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; margin-bottom: 16px; }
.chart-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-sm); }
.chart-card h3 { margin: 0 0 2px; font-size: 15px; }
.chart-card .chart-sub { color: var(--text-muted); font-size: 12.5px; margin-bottom: 14px; }
.chart-card svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 12px; font-size: 12.5px; color: var(--text-muted); }
.chart-legend .item { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* 選舉清單改成卡片格狀排列,比單欄清單更吃得滿橫向空間 */
.election-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.election-card {
  display: block; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px; transition: border-color .12s, transform .06s;
}
.election-card:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-1px); }
.election-card .year { font-size: 20px; font-weight: 700; color: var(--text); }
.election-card .meta { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* 麵包屑:讓使用者不必依賴瀏覽器上一頁 */
.breadcrumb { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13.5px; margin-bottom: 14px; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb .sep { color: var(--text-muted); opacity: .6; }
.breadcrumb .current { color: var(--text); font-weight: 600; }

.card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 22px; margin-bottom: 16px; box-shadow: var(--shadow-sm);
}
.card h2 { margin: 0 0 6px; font-size: 22px; }
.card h3 { margin: 0 0 14px; font-size: 16px; font-weight: 700; color: var(--text); }
.card > h3:not(:first-child) { margin-top: 4px; }
.prose { max-width: 700px; font-size: 16px; line-height: 1.85; }
.muted { color: var(--text-muted); font-size: 13.5px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 700;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.status-未開始 { background: var(--bg-subtle); color: var(--pending); }
.badge.status-進行中 { background: var(--accent-soft); color: var(--accent); }
.badge.status-已完成 { background: var(--ok-soft); color: var(--ok); }
.badge.status-跳票 { background: var(--danger-soft); color: var(--danger); }
.badge.status-存疑 { background: var(--warn-soft); color: var(--warn); }
.badge.badge-untracked { background: var(--bg-subtle); color: var(--text-muted); }
.term-countdown { margin-top: 12px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--bg-subtle); }
.term-countdown-text { font-size: 17px; font-weight: 700; }
.term-bar { height: 8px; border-radius: 999px; background: var(--border); margin-top: 10px; overflow: hidden; }
.term-bar-fill { height: 100%; border-radius: 999px; background: var(--accent); }
.term-bar-label { margin-top: 6px; font-size: 12.5px; }
.term-note { margin-top: 6px; }
.term-chip { display: inline-block; margin-top: 8px; font-size: 12.5px; font-weight: 700; padding: 3px 10px;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.term-chip-ended { background: var(--bg-subtle); color: var(--text-muted); }
.term-chip-upcoming { background: var(--warn-soft); color: var(--warn); }
/* ---- 開站宣告 ---- */
body.modal-open { overflow: hidden; }
.announce-overlay { z-index: 60; }
.announce-card { max-width: 560px; max-height: calc(100vh - 32px); overflow-y: auto; }
.announce-card h2, .announce-preview h2 { margin: 0 0 12px; text-wrap: balance; }
.announce-body p, .announce-body li { line-height: 1.8; text-wrap: pretty; }
/* 宣告文字由後台自由編輯,無法逐句用 phrases() 處理:改用 keep-all 讓中文只在空格/標點換行
   (避免「中華民/國」「當/選人」這種斷在詞中間),一行真的放不下時由 overflow-wrap 強制斷開,不會撐破版面 */
.announce-card h2, .announce-preview h2, .announce-body p, .announce-body li { word-break: keep-all; overflow-wrap: anywhere; }
.announce-body ul { padding-left: 22px; margin: 0 0 12px; }
.announce-body li { margin: 4px 0; }
.announce-actions { display: flex; justify-content: flex-end; margin-top: 18px; }
.announce-actions button { min-width: 120px; }
.announce-editor { width: 100%; font-family: inherit; line-height: 1.7; }
.announce-preview { border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: 18px; }
.winner-progress { margin: 4px 0 12px; }
.winner-progress svg { display: block; width: 100%; }
.winner-progress .chart-legend { margin-top: 8px; }
.badge.badge-untracked::before { display: none; }

.party-badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 600;
  padding: 2px 10px 2px 4px; border-radius: 999px; background: var(--bg-subtle);
  border: 1px solid var(--border);
}
.party-emblem { width: 18px; height: 18px; border-radius: 50%; flex: none; box-shadow: 0 0 0 1px rgba(0,0,0,0.06); background: #fff; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
select, input[type=text], input[type=password], input[type=number], textarea {
  background: var(--bg-card); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 12px; font-size: 15px; font-family: inherit;
}
select:focus, input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { width: 100%; resize: vertical; line-height: 1.6; }
label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 5px; color: var(--text-muted); }

button {
  background: var(--accent); color: var(--accent-text); border: none; border-radius: var(--radius-sm);
  padding: 9px 18px; font-size: 14.5px; font-weight: 600; cursor: pointer;
  transition: filter 0.12s, transform 0.05s;
}
button:hover { filter: brightness(1.1); }
button:active { transform: scale(0.98); }
button.secondary { background: var(--bg-subtle); color: var(--text); border: 1px solid var(--border); }
button.danger { background: var(--danger); color: #fff; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.list-item {
  display: block; padding: 14px 4px; border-bottom: 1px solid var(--border);
  margin: 0 -4px; border-radius: var(--radius-sm); transition: background 0.12s;
}
.list-item:hover { background: var(--bg-subtle); text-decoration: none; }
.list-item:last-child { border-bottom: none; }

.promise-item { display: block; padding: 14px 10px; margin: 0 -10px; border-bottom: 1px solid var(--border); border-radius: var(--radius-sm); transition: background 0.12s; }
.promise-item:hover { background: var(--bg-subtle); text-decoration: none; }
.promise-item:last-child { border-bottom: none; }
.promise-item .row { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; }
.promise-item .row > div:first-child { color: var(--text); }

.row { display: flex; align-items: center; gap: 10px; }

.timeline-entry { position: relative; border-left: 2px solid var(--border); padding: 2px 0 16px 18px; margin-left: 5px; font-size: 14.5px; }
.timeline-entry::before { content: ""; position: absolute; left: -6px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg-card); }
.timeline-entry:last-child { border-left-color: transparent; padding-bottom: 0; }

.vote-row { display: flex; gap: 8px; align-items: center; margin: 10px 0; flex-wrap: wrap; }
.form-error { color: var(--danger); font-size: 13px; margin-top: 6px; }
.form-ok { color: var(--ok); font-size: 13px; margin-top: 6px; }

.submission-box { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 16px; margin: 10px 0; background: var(--bg-subtle); }
.submission-box p { font-size: 15px; }
.evidence-url-row { display: flex; gap: 6px; margin-bottom: 6px; }
.evidence-url-row input { flex: 1; min-width: 0; }

table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: 0.02em; }

nav.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--border); overflow-x: auto; }
nav.tabs button { background: none; color: var(--text-muted); border: none; border-bottom: 2px solid transparent;
  border-radius: 0; padding: 10px 14px; font-weight: 600; white-space: nowrap; }
nav.tabs button:hover { color: var(--text); filter: none; }
nav.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

.source-link { display: inline-flex; align-items: center; gap: 4px; }
.source-link::before { content: "🔗"; font-size: 12px; }

.pending-years-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--danger-soft); color: var(--danger); font-weight: 700; font-size: 13.5px;
  padding: 7px 14px; border-radius: var(--radius-sm); margin: 4px 0 14px;
}

.source-item { padding: 12px 0; border-top: 1px solid var(--border); }
.source-item .source-title { font-weight: 600; margin-bottom: 2px; }
.source-item .source-link { font-size: 14px; margin-top: 4px; word-break: break-all; }
.prose-wide p { max-width: 760px; }
/* 表格在手機上寬度不夠時,讓表格自己水平捲動,不要把整個頁面撐寬 */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.totp-secret { font-family: ui-monospace, Consolas, monospace; font-size: 17px; letter-spacing: 0.08em;
  background: var(--bg-subtle); padding: 10px 12px; border-radius: var(--radius-sm); word-break: break-all; }

/* 首次登入設定名稱頁:中文長句避免斷在詞中間,pretty 讓段落最後一行不會只剩一兩個字 */
.signup-card { max-width: 560px; }
.ph { display: inline-block; }
.signup-card h2 { text-wrap: balance; }
.signup-card p, .signup-card li { text-wrap: pretty; line-height: 1.75; }
.signup-subhead { font-size: 15px; margin: 18px 0 6px; }
.signup-rules { margin: 0 0 6px; padding-left: 22px; color: var(--text-muted); }
.signup-rules li { margin: 2px 0; }
.signup-card input[type=text] { width: 100%; max-width: 360px; }
.signup-privacy { margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--border); font-size: 13.5px; line-height: 1.8; }
.modal-card p { text-wrap: pretty; line-height: 1.75; }
/* ---- 會員選單(頁首)---- */
.user-menu { position: relative; }
.user-menu-btn { display: inline-flex; align-items: center; gap: 8px; padding: 5px 10px 5px 5px; max-width: 220px; }
.user-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex-shrink: 0; }
.user-menu-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.user-menu-caret { font-size: 11px; color: var(--text-muted); }
.user-menu-panel { position: absolute; right: 0; top: calc(100% + 6px); min-width: 210px; z-index: 40;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md); padding: 6px; display: flex; flex-direction: column; }
.user-menu-panel[hidden] { display: none; }
.user-menu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.user-menu-fullname { font-weight: 700; word-break: break-all; }
.user-menu-panel a, .user-menu-panel button { display: block; width: 100%; text-align: left; padding: 10px;
  border-radius: 6px; color: var(--text); background: none; border: none; font-size: 15px; font-weight: 500; }
.user-menu-panel a:hover, .user-menu-panel button:hover { background: var(--bg-subtle); text-decoration: none; filter: none; }
.user-menu-panel .user-menu-logout { color: var(--danger); }

/* ---- 個人資料頁 ---- */
.profile-stats { grid-template-columns: repeat(5, minmax(0, 1fr)); margin: 14px 0 0; }
.profile-stats .stat-tile .value { font-size: 24px; }
.activity-item { padding: 14px 0; border-top: 1px solid var(--border); }
.activity-link { display: inline-block; margin-top: 8px; font-size: 14px; }
.review-badge { font-size: 12.5px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--bg-subtle); white-space: nowrap; }
.review-pending { color: var(--accent); }
.review-approved { color: var(--ok); }
.review-rejected, .review-hidden { color: var(--danger); }

.line-login-btn { background: #06C755; border-color: #06C755; color: #fff; }
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center;
  justify-content: center; z-index: 50; padding: 16px; }
.modal-card { width: 100%; max-width: 440px; margin: 0; }
.name-preview { font-size: 24px; font-weight: 700; text-align: center; padding: 16px; margin: 10px 0;
  border: 2px dashed var(--border); border-radius: var(--radius-sm); word-break: break-all; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--text); cursor: pointer; }
.checkbox-row input { width: auto; }

.footer-note { text-align: center; color: var(--text-muted); font-size: 12.5px; padding: 28px 20px; line-height: 1.8; }

@media (max-width: 560px) {
  header.site-header { padding: 12px 14px; }
  .site-flag { width: 54px; height: 36px; }
  .site-brand { gap: 9px; }
  .site-title { font-size: 20px; }
  /* 手機上只留頭像圓圈,名稱收進選單,頁首維持一行 */
  .user-menu-name { display: none; }
  .user-menu-btn { padding: 5px 8px 5px 5px; gap: 5px; }
  .profile-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .header-actions { font-size: 13px; }
  main { padding: 16px 14px 40px; }
  .card { padding: 16px; }
  body { font-size: 15.5px; }
}
