/* 正式前端的樣式。從原型（prototype/index.html）延伸：
   - 色彩刻意避開台灣政黨色（藍、綠、白底青、黃、橘），只用中性墨色＋一個桑椹紫強調色。
   - 只用裝置字型，不載入任何網路字型（不對第三方發請求）。
   - 沒有 inline style：版面上會變的數值由 app/dom.js 以 CSSOM 設定，CSP 才能維持 style-src 'self'。 */
:root {
  --paper: #F6F4F7;
  --surface: #FFFFFF;
  --ink: #1E1A22;
  --ink-2: #4A4450;
  --muted: #686170;
  --rule: #E3DEE6;
  --rule-strong: #C9C1CE;
  --accent: #8A2D5E;
  --accent-ink: #FFFFFF;
  --accent-soft: #F5E8F0;
  --shadow: 0 1px 2px rgb(30 26 34 / 0.06), 0 6px 20px rgb(30 26 34 / 0.06);
  --font-display: "Noto Serif TC", "Source Han Serif TC", "Songti TC", "PMingLiU", serif;
  --font-body: "PingFang TC", "Noto Sans TC", "Source Han Sans TC", "Microsoft JhengHei", "Heiti TC", system-ui, sans-serif;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #141116;
    --surface: #1D1920;
    --ink: #F2EEF4;
    --ink-2: #CEC7D3;
    --muted: #A59DAC;
    --rule: #342E39;
    --rule-strong: #4A4350;
    --accent: #E48AB8;
    --accent-ink: #1E1A22;
    --accent-soft: #3A2332;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
/* 固定的預覽橫幅（頂端）與配票列（底部）不能蓋住取得焦點的元素（WCAG 2.4.11）：
   app/main.js 量出兩者的高度設成 --covered-top／--covered-bottom，捲動時留出這段距離（多 12px 給焦點外框）。 */
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--covered-top, 0px) + 12px); scroll-padding-bottom: calc(var(--covered-bottom, 0px) + 12px); }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--font-body); font-size: 16px; line-height: 1.7; overflow-wrap: anywhere; }
.wrap { max-width: 760px; margin-inline: auto; padding-inline: 16px; padding-block: 12px 48px; }
.wrap.has-budget { padding-block-end: calc(var(--covered-bottom, 136px) + 24px); }
h1, h2, h3 { font-family: var(--font-display); font-weight: 700; text-wrap: balance; line-height: 1.35; margin: 0; }
h1 { font-size: clamp(1.5rem, 5.4vw, 2.2rem); }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.06rem; }
h1:focus { outline: none; }
p { margin: 0; }
button, input { font: inherit; color: inherit; }
a { color: var(--accent); text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* 預覽標示：只在預覽 build 出現，每個畫面都看得到 */
.preview-banner { position: sticky; top: 0; z-index: 20; margin: 0; padding: 8px 16px; text-align: center; font-weight: 700; background: var(--ink); color: var(--paper); border-bottom: 3px dashed var(--accent); }

/* 頂部 */
.topbar { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; padding-block: 8px 14px; border-bottom: 1px solid var(--rule); }
.brand { font-family: var(--font-display); font-size: 1.12rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.steps { display: flex; flex-wrap: wrap; gap: 4px 14px; list-style: none; margin: 0; padding: 0; font-size: 0.82rem; color: var(--muted); }
.steps li[aria-current="step"] { color: var(--ink); font-weight: 700; }
.steps li.done { color: var(--ink-2); }

.screen { display: flex; flex-direction: column; gap: 18px; padding-top: 22px; }
.eyebrow { font-size: 0.8rem; letter-spacing: 0.12em; color: var(--muted); }
.lead { font-size: 1.05rem; color: var(--ink-2); max-width: 38em; }
.sub { color: var(--ink-2); max-width: 38em; }
.fineprint { font-size: 0.85rem; color: var(--muted); max-width: 42em; }
.notice { font-size: 0.92rem; color: var(--ink); border-left: 3px solid var(--accent); padding: 4px 0 4px 12px; }

/* 按鈕 */
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.actions.split { justify-content: space-between; }
.btn { min-height: 46px; padding: 10px 18px; border-radius: 999px; border: 1.5px solid var(--ink); background: transparent; cursor: pointer; font-weight: 500; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { border-color: transparent; text-decoration: underline; text-underline-offset: 3px; color: var(--ink-2); padding-inline: 8px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn[aria-disabled="true"] { cursor: progress; }
.btn:not(:disabled):hover { filter: brightness(1.08); }

/* 圈選章：台灣選票用的「卜」字圈 */
.stamp { --r: -8deg; display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--accent); color: var(--accent); font-family: var(--font-display); font-weight: 700; font-size: 14px; line-height: 1; transform: rotate(var(--r)); background: var(--surface); }
.stamp.big { width: 40px; height: 40px; font-size: 21px; border-width: 2.5px; }
.stamp.new { animation: press 0.28s cubic-bezier(0.2, 0.8, 0.2, 1.2) both; }
@keyframes press { from { transform: scale(1.7) rotate(var(--r)); opacity: 0; } to { transform: scale(1) rotate(var(--r)); opacity: 1; } }

/* 步進器 */
.stepper { display: flex; align-items: center; gap: 10px; }
.step { width: 46px; height: 46px; border-radius: 50%; border: 1.5px solid var(--ink); background: var(--surface); display: grid; place-items: center; cursor: pointer; font-size: 1.3rem; line-height: 1; position: relative; }
.step small { position: absolute; bottom: -19px; left: 50%; transform: translateX(-50%); font-size: 0.74rem; color: var(--accent); font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.step.plus { border-color: var(--accent); color: var(--accent); }
.step:disabled { opacity: 0.35; cursor: not-allowed; }

/* 首頁 */
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow); }
.demo { padding: 18px; display: grid; gap: 16px; }
.demo-grid { display: grid; gap: 20px; grid-template-columns: 1fr; align-items: end; }
.demo-readout { font-variant-numeric: tabular-nums; color: var(--ink-2); margin-top: 22px; }
.demo-readout b { color: var(--ink); }
.how { margin: 0; padding: 0; list-style: none; counter-reset: how; display: grid; gap: 10px; }
.how li { counter-increment: how; border-top: 2px solid var(--ink); padding-top: 8px; font-size: 0.92rem; color: var(--ink-2); }
.how li::before { content: counter(how); font-family: var(--font-display); font-weight: 700; color: var(--accent); margin-right: 6px; }
.how b { color: var(--ink); }

/* 議題 */
.issue-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.issue { position: relative; text-align: left; padding: 12px 12px 12px 14px; min-height: 76px; border: 1.5px solid var(--rule-strong); border-radius: var(--radius); background: var(--surface); cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.issue .name { font-weight: 700; line-height: 1.4; padding-right: 30px; }
.issue .blurb { font-size: 0.82rem; color: var(--muted); line-height: 1.5; }
.issue .count { font-size: 0.78rem; color: var(--muted); }
.issue[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.issue .rank { position: absolute; top: 10px; right: 10px; }
.issue:disabled { opacity: 0.45; cursor: not-allowed; }

/* 題目 */
.progress { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 12px; font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.progress-bar { height: 4px; background: var(--rule); border-radius: 2px; overflow: hidden; margin-top: -10px; }
.progress-bar span { display: block; height: 100%; background: var(--ink); }
.tag { display: inline-block; font-size: 0.78rem; padding: 1px 8px; border: 1px solid var(--rule-strong); border-radius: 999px; color: var(--ink-2); white-space: nowrap; }
.q-context { color: var(--ink-2); font-size: 0.95rem; }
.options { display: grid; gap: 12px; grid-template-columns: 1fr; }
.option { position: relative; text-align: left; cursor: pointer; background: var(--surface); border: 1.5px solid var(--rule-strong); border-radius: var(--radius); padding: 16px 16px 14px; display: flex; flex-direction: column; gap: 10px; }
.option[aria-pressed="true"] { border-color: var(--accent); border-width: 2.5px; padding: 15px 15px 13px; background: var(--accent-soft); }
.opt-label { font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; }
.opt-text { font-size: 1rem; line-height: 1.7; }
.opt-cost { font-size: 0.9rem; color: var(--ink-2); border-top: 1px dashed var(--rule-strong); padding-top: 8px; }
.opt-cost .k { font-weight: 700; color: var(--ink); margin-right: 6px; }
.jur { align-self: flex-start; justify-self: start; font-size: 0.78rem; color: var(--ink-2); border: 1px solid var(--rule-strong); border-radius: 4px; padding: 1px 7px; background: var(--paper); }
.jur b { font-weight: 700; margin-right: 4px; color: var(--ink); }
.option .stamp.big { position: absolute; top: 10px; right: 12px; }
.alt { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.none-btn { border-style: dashed; }
.none-btn[aria-pressed="true"] { border-style: solid; border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.skipped-note { font-size: 0.88rem; color: var(--muted); }

/* 配票 */
.alloc-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.alloc-row { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px 14px 26px; display: grid; gap: 2px 16px; grid-template-columns: minmax(0, 1fr); }
.alloc-tags { font-size: 0.78rem; color: var(--muted); }
.alloc-title { font-weight: 700; line-height: 1.5; }
/* 你選：甲案／乙案與「修改」在第一行，選項文字另起一行、最多兩行（做法 ≤ 60 字，桌機通常整段看得到，手機看得到大半） */
.alloc-choice { display: flex; flex-wrap: wrap; gap: 2px 8px; align-items: baseline; min-width: 0; width: 100%; text-align: left; font-size: 0.88rem; color: var(--ink-2); background: none; border: 0; padding: 4px 0; cursor: pointer; min-height: 44px; }
.alloc-choice > span:first-child { white-space: nowrap; }
.alloc-choice b { color: var(--ink); }
.alloc-choice .snip { order: 3; flex: 1 0 100%; min-width: 0; line-height: 1.55; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
.alloc-choice .edit { flex: none; white-space: nowrap; text-decoration: underline; text-underline-offset: 3px; color: var(--accent); }
.alloc-stepper { flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.votes { margin-left: auto; min-width: 84px; text-align: right; font-variant-numeric: tabular-nums; font-size: 0.9rem; color: var(--ink-2); }
.votes b { font-size: 1.25rem; color: var(--ink); }
.votes:focus-visible, .demo-readout:focus-visible { outline-offset: 4px; border-radius: 4px; }
.skip-list { font-size: 0.9rem; color: var(--ink-2); display: grid; gap: 6px; }

.budget { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--surface); border-top: 1px solid var(--rule-strong); padding: 10px 0 calc(12px + env(safe-area-inset-bottom, 0px)); box-shadow: 0 -6px 20px rgb(0 0 0 / 0.06); }
.budget-inner { max-width: 760px; margin-inline: auto; padding-inline: 16px; display: grid; gap: 8px; }
.budget-text { display: flex; justify-content: space-between; gap: 12px; font-size: 0.92rem; font-variant-numeric: tabular-nums; }
.budget-text b { font-size: 1.2rem; }
/* 級數畫成 n×n 的方塊：格數＝點數，平方不用解釋 */
.sq { --c: 12px; display: grid; grid-template-columns: repeat(var(--n, 5), var(--c)); gap: 2px; flex: 0 0 auto; }
.sq i { width: var(--c); height: var(--c); border-radius: 2px; border: 1px dashed var(--rule-strong); }
.sq i.on { background: var(--accent); border: 1px solid var(--accent); }
.sq i.new { animation: pop 0.25s ease-out; }
.sq.lg { --c: 20px; gap: 3px; }
@keyframes pop { from { transform: scale(0.4); opacity: 0.3; } to { transform: none; opacity: 1; } }
.budget-grid { display: grid; grid-template-columns: repeat(25, 1fr); gap: 2px; max-width: 520px; }
.budget-grid i { aspect-ratio: 1; border-radius: 1px; background: var(--rule); }
.budget-grid i.a { background: var(--accent); }
.budget-grid i.b { background: var(--accent); opacity: 0.55; }
.ladder-sq { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; }
.ladder-sq figure { margin: 0; display: grid; justify-items: center; gap: 4px; font-size: 0.78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.ladder-sq figure.on { color: var(--ink); font-weight: 700; }
.ladder-sq .sq { --c: 7px; gap: 1px; }

/* 揭曉前 */
.choice-group { border: 0; padding: 0; margin: 0; display: grid; gap: 10px; }
.choice-group legend { font-weight: 700; margin-bottom: 10px; padding: 0; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { position: relative; display: inline-flex; align-items: center; min-height: 44px; padding: 8px 16px; border-radius: 999px; border: 1.5px solid var(--rule-strong); background: var(--surface); cursor: pointer; }
.pill input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.pill.on { border-color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.pill:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
.consent { display: grid; gap: 10px; padding: 14px 16px; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 3px 0 0; flex: none; accent-color: var(--accent); }
details.peek summary { cursor: pointer; color: var(--accent); min-height: 32px; }
.peek-list { margin: 8px 0 0; padding-left: 20px; font-size: 0.88rem; color: var(--ink-2); display: grid; gap: 2px; }

/* 結果：候選人以紋理區分（45° 與 135° 斜線，同密度＝同視覺重量），不用顏色 */
.pat-a { background: repeating-linear-gradient(45deg, var(--ink) 0 2px, transparent 2px 7px), var(--surface); }
.pat-b { background: repeating-linear-gradient(135deg, var(--ink) 0 2px, transparent 2px 7px), var(--surface); }
.pat-c { background: repeating-linear-gradient(90deg, var(--ink) 0 2px, transparent 2px 7px), var(--surface); }
.pat-none { background: radial-gradient(circle, var(--muted) 1.2px, transparent 1.6px) 0 0 / 7px 7px, var(--surface); }
.swatch { display: inline-block; width: 18px; height: 12px; border: 1px solid var(--ink); border-radius: 2px; vertical-align: -1px; }
.headline-kind { display: inline-block; font-size: 0.88rem; font-family: var(--font-body); font-weight: 700; border: 1.5px solid var(--ink); border-radius: 999px; padding: 2px 12px; margin-bottom: 8px; }
.stack { margin: 0; display: grid; gap: 8px; }
.stack figcaption { font-size: 0.88rem; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.88rem; }
.stackbar { display: flex; gap: 2px; height: 38px; }
.stackbar .seg { border: 1px solid var(--ink); border-radius: 4px; min-width: 6px; }
.stackbar .seg.pat-none { border-style: dashed; border-color: var(--muted); }
.stack-labels { display: flex; gap: 2px; font-size: 0.86rem; font-variant-numeric: tabular-nums; }
.stack-labels span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.facts { display: grid; gap: 10px; grid-template-columns: 1fr; }
.fact { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 14px; display: grid; gap: 8px; align-content: start; }
.fact h3 { font-size: 0.98rem; }
.fact p, .fact li { font-size: 0.92rem; color: var(--ink-2); }
.mark { font-weight: 700; color: var(--ink); }
.mirror { background: var(--accent-soft); border-radius: var(--radius); padding: 14px 16px; font-size: 0.95rem; }
.cmp-row { display: grid; gap: 6px; }
.issue-bars { display: grid; gap: 14px; }
.ib { display: grid; gap: 6px; }
.ib-head { display: flex; justify-content: space-between; gap: 4px 12px; font-size: 0.9rem; flex-wrap: wrap; }
.ib-head span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }
.ib .stackbar { height: 18px; }
.reveal-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.reveal-item { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 10px; }
.ri-meta { font-size: 0.8rem; color: var(--muted); }
.ri-options { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.ri-options > li { border-left: 3px solid var(--rule); padding: 2px 0 2px 12px; display: grid; gap: 6px; font-size: 0.92rem; }
.ri-options > li.chosen { border-left-color: var(--accent); }
.ri-who { font-weight: 700; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.ri-you { font-size: 0.8rem; color: var(--accent); font-weight: 700; }
.evidence { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 0.86rem; color: var(--ink-2); }
.evidence blockquote { margin: 0; padding: 4px 10px; border-left: 2px solid var(--rule-strong); color: var(--ink); }
.evidence li.lead blockquote { border-left-style: dashed; color: var(--ink-2); }
.claims { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.claims > li { display: grid; gap: 4px; }
details.method { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px 16px; }
details.method summary { cursor: pointer; font-weight: 700; min-height: 32px; }
details.method > div { display: grid; gap: 8px; margin-top: 10px; font-size: 0.92rem; color: var(--ink-2); }
.formula { font-variant-numeric: tabular-nums; background: var(--paper); border-radius: 6px; padding: 8px 10px; overflow-x: auto; }
.versions { font-size: 0.82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.share { display: grid; gap: 12px; }
.share img { width: 100%; max-width: 360px; height: auto; border: 1px solid var(--rule-strong); border-radius: 6px; }
.loading { color: var(--ink-2); }

@media (min-width: 640px) {
  .demo-grid { grid-template-columns: 1fr 1fr; }
  .how { grid-template-columns: repeat(4, 1fr); }
  .issue-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .options { grid-template-columns: 1fr 1fr; }
  .alloc-row { grid-template-columns: minmax(0, 1fr) auto; padding-bottom: 22px; }
  .alloc-row > :not(.alloc-stepper) { grid-column: 1; }
  .alloc-stepper { grid-column: 2; grid-row: 1 / span 3; align-self: center; margin-top: 0; flex-wrap: nowrap; }
  .facts { grid-template-columns: repeat(3, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
.tag.beta { border-style: dashed; white-space: normal; }
.beta-banner { margin: 0; padding: 8px 16px; text-align: center; font-size: 0.9rem; background: var(--paper); color: var(--ink); border-bottom: 2px dashed var(--accent); }
.evidence li.more details.peek > .evidence { margin-top: 6px; }
/* 左上角的站名：連回首頁 */
.brand a { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; min-height: 32px; }
.brand a:hover { text-decoration: underline; text-underline-offset: 4px; }

/* 說明頁（faq.html、report.html、about.html） */
.doc h2 { margin-top: 10px; }
.doc p { margin: 0; max-width: 40em; }
.doc section { display: flex; flex-direction: column; gap: 14px; scroll-margin-top: calc(var(--covered-top, 0px) + 12px); }
.doc ul { margin: 0; padding-left: 1.3em; max-width: 40em; display: flex; flex-direction: column; gap: 6px; }
.doc .toc { list-style: none; padding: 12px 16px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface); gap: 2px; }
.doc .toc a { display: inline-block; padding-block: 3px; }
.levels, .compare { margin: 0; display: flex; flex-direction: column; gap: 10px; max-width: 40em; }
.levels > div, .compare > div { border-left: 3px solid var(--rule-strong); padding: 2px 0 2px 12px; }
.levels dt, .compare dt { font-weight: 700; }
.levels dt b { display: inline-block; min-width: 2.4em; color: var(--accent); }
.levels dd, .compare dd { margin: 0; color: var(--ink-2); }
.compare > div:last-child { border-left-color: var(--accent); }
.ladder { border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 0.92rem; }
.ladder th, .ladder td { border: 1px solid var(--rule); padding: 6px 10px; text-align: center; }
.ladder th[scope="row"] { text-align: left; font-weight: 500; color: var(--ink-2); white-space: nowrap; }
.ladder thead th { background: var(--surface); }

/* 頁尾：每一頁都有（build 填進 build:footer） */
.site-footer { margin-top: 48px; padding-top: 16px; border-top: 1px solid var(--rule); display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 0 20px; }
.site-footer nav a { display: inline-flex; align-items: center; min-height: 36px; color: var(--ink-2); }
.site-footer nav a[aria-current="page"] { color: var(--ink); font-weight: 700; text-decoration: none; }
.site-footer p { margin: 0; font-size: 0.82rem; }
