/* 公民與社會 程度診斷卷 — 簡潔、行動優先 */
:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1f2430;
  --muted: #6b7280;
  --line: #e4e7ec;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --right: #16a34a;
  --wrong: #dc2626;
  --partial: #d97706;
  --pol: #7c3aed; /* 政治 */
  --law: #0891b2; /* 法律 */
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
  --eco: #ea580c; /* 經濟 */
  --soc: #db2777; /* 社會 */
  --base: #16a34a; /* 基礎層 */
  --mid: #d97706;  /* 中等層 */
  --hard: #dc2626; /* 難層 */
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC",
    "Microsoft JhengHei", "Noto Sans TC", Roboto, sans-serif;
  line-height: 1.7;
  font-size: 16px;
}
#app { max-width: 760px; margin: 0 auto; padding: 16px 14px 64px; }
.hidden { display: none !important; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

/* 按鈕 */
.btn {
  font: inherit;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: #f9fafb; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 7px 14px; font-size: 0.92rem; }

/* 起始畫面 */
.start-card { text-align: center; padding: 32px 22px; }
.start-card h1 { font-size: 1.5rem; margin: 0 0 6px; }
.subtitle { color: var(--muted); margin: 0 0 18px; }
.meta-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 20px; }
.chip {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 0.9rem;
}
.instructions { text-align: left; background: #fafbfc; border: 1px solid var(--line); border-radius: 10px; padding: 14px 18px; margin-bottom: 22px; }
.instructions ul { margin: 0; padding-left: 20px; }
.instructions li { margin: 6px 0; color: #374151; font-size: 0.95rem; }
.actions { display: flex; flex-direction: column; gap: 10px; }
.actions .btn { width: 100%; padding: 13px; font-size: 1rem; }

/* 作答頂部 */
.quiz-header { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.progress-wrap { flex: 1; }
.progress-bar { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
#progress-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.progress-text { font-size: 0.82rem; color: var(--muted); display: inline-block; margin-top: 4px; }

/* 題目卡 */
.q-top { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.q-num { color: var(--muted); font-size: 0.9rem; margin-left: auto; }
.badge { font-size: 0.78rem; padding: 3px 10px; border-radius: 999px; color: #fff; font-weight: 600; }
.d-pol { background: var(--pol); } .d-law { background: var(--law); }
.d-eco { background: var(--eco); } .d-soc { background: var(--soc); }
.badge-multi { background: var(--accent); }
.badge-diff { background: #9ca3af; }
.badge-diff.hard { background: #b91c1c; }

.group-context { margin-bottom: 16px; border: 1px dashed var(--line); border-radius: 10px; padding: 10px 14px; background: #fcfcfd; }
.group-context summary { cursor: pointer; font-weight: 600; color: var(--muted); font-size: 0.9rem; }
.passage { margin-top: 10px; white-space: normal; color: #374151; }

.stem { font-size: 1.06rem; margin: 6px 0 16px; }

.qtable { margin: 14px 0; overflow-x: auto; }
.qtable figcaption { font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
.qtable table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
.qtable th, .qtable td { border: 1px solid var(--line); padding: 7px 10px; text-align: center; }
.qtable thead th { background: #f3f4f6; }

/* 選項 */
.options { display: flex; flex-direction: column; gap: 10px; }
.opt {
  display: flex; align-items: flex-start; gap: 10px;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.opt:hover { border-color: #c7d2fe; background: #fafbff; }
.opt input { margin-top: 4px; flex-shrink: 0; }
.opt-checked { border-color: var(--accent); background: var(--accent-soft); }
.opt-key { font-weight: 700; flex-shrink: 0; }
.opt-text { flex: 1; }

/* 導覽列 */
.qnav { display: flex; gap: 8px; margin: 16px 0; }
.qnav .btn { flex: 1; }
.btn-flag.active { background: #fff7ed; border-color: #fdba74; color: #c2410c; }

/* 題目導覽板 */
.palette-wrap { margin-top: 8px; }
.palette-title { font-size: 0.92rem; color: var(--muted); margin: 0 0 10px; }
.palette { display: grid; grid-template-columns: repeat(10, 1fr); gap: 8px; }
.pcell {
  aspect-ratio: 1; border: 1px solid var(--line); background: #fff;
  border-radius: 8px; cursor: pointer; font-size: 0.9rem; position: relative;
  color: var(--ink);
}
.pcell.answered { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 700; }
.pcell.current { outline: 2px solid var(--accent); outline-offset: 1px; }
.pcell.flagged::after {
  content: ""; position: absolute; top: 3px; right: 3px;
  width: 7px; height: 7px; background: #f59e0b; border-radius: 50%;
}
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; font-size: 0.8rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend .dot { width: 12px; height: 12px; border-radius: 4px; border: 1px solid var(--line); background: #fff; display: inline-block; position: relative; }
.legend .dot.answered { background: var(--accent-soft); border-color: var(--accent); }
.legend .dot.current { outline: 2px solid var(--accent); }
.legend .dot.flagged::after { content: ""; position: absolute; top: 0; right: 0; width: 6px; height: 6px; background: #f59e0b; border-radius: 50%; }

/* 結果畫面 */
.results-summary { text-align: center; }
.results-summary h1 { font-size: 1.4rem; margin: 0 0 8px; }
.score-big { font-size: 2.6rem; font-weight: 800; color: var(--accent); line-height: 1.1; margin: 6px 0 22px; }
.score-big small { font-size: 1.1rem; color: var(--muted); font-weight: 500; }

.domain-bars { text-align: left; display: flex; flex-direction: column; gap: 14px; margin-bottom: 8px; }
.dbar-label { display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px; font-size: 0.9rem; }
.dbar-num { color: var(--muted); }
.dbar.low .dbar-num strong { color: var(--wrong); }
.dbar-track { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; }
.dbar-fill { height: 100%; border-radius: 999px; }
.dbar-fill.d-pol { background: var(--pol); } .dbar-fill.d-law { background: var(--law); }
.dbar-fill.d-eco { background: var(--eco); } .dbar-fill.d-soc { background: var(--soc); }

.advice { text-align: left; background: #fafbfc; border: 1px solid var(--line); border-radius: 10px; padding: 14px 18px; margin: 20px 0; }
.advice h2 { font-size: 1rem; margin: 0 0 8px; }
.advice p { margin: 8px 0; font-size: 0.95rem; color: #374151; }

.review-title { font-size: 1.15rem; margin: 24px 0 12px; }
.review-item { padding: 0; overflow: hidden; }
.review-item > summary { display: flex; align-items: center; gap: 8px; padding: 14px 18px; cursor: pointer; flex-wrap: wrap; list-style: none; }
.review-item > summary::-webkit-details-marker { display: none; }
.rev-mark { font-weight: 800; font-size: 1.1rem; }
.review-item.right .rev-mark { color: var(--right); }
.review-item.wrong .rev-mark { color: var(--wrong); }
.review-item.partial .rev-mark { color: var(--partial); }
.review-item.wrong { border-left: 4px solid var(--wrong); }
.review-item.partial { border-left: 4px solid var(--partial); }
.review-item.right { border-left: 4px solid var(--right); }
.rev-no { font-weight: 600; }
.rev-pts { margin-left: auto; color: var(--muted); font-size: 0.9rem; }
.rev-body { padding: 0 18px 18px; border-top: 1px solid var(--line); }
.rev-body .stem { margin-top: 14px; }

.options.review .opt { cursor: default; }
.options.review .opt:hover { border-color: var(--line); background: #fff; }
.opt.is-answer { border-color: var(--right); background: #f0fdf4; }
.opt.is-wrongpick { border-color: var(--wrong); background: #fef2f2; }
.tag { font-size: 0.72rem; padding: 2px 8px; border-radius: 999px; margin-left: 6px; flex-shrink: 0; }
.tag-ans { background: var(--right); color: #fff; }
.tag-you { background: #e5e7eb; color: #374151; }

.rev-answer { font-size: 0.92rem; color: #374151; margin: 14px 0 10px; }
.explanation { background: var(--accent-soft); border-radius: 10px; padding: 14px 16px; font-size: 0.95rem; color: #1e293b; }
.explanation em { color: var(--partial); font-style: normal; font-weight: 600; }

/* 選卷首頁 */
.home-head { text-align: center; margin: 8px 0 22px; }
.home-head h1 { font-size: 1.6rem; margin: 0 0 6px; }
.exam-list { display: flex; flex-direction: column; gap: 14px; }
.exam-card {
  display: flex; align-items: center; gap: 14px; text-align: left;
  width: 100%; font: inherit; cursor: pointer;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; transition: border-color 0.15s, transform 0.05s, box-shadow 0.15s;
}
.exam-card:hover { border-color: var(--accent); box-shadow: 0 4px 12px rgba(37, 99, 235, 0.1); }
.exam-card:active { transform: translateY(1px); }
.exam-card-main { flex: 1; }
.exam-card-main h2 { font-size: 1.15rem; margin: 0 0 4px; color: var(--ink); }
.exam-card-sub { color: var(--muted); margin: 0 0 12px; font-size: 0.92rem; }
.exam-card .meta-row { justify-content: flex-start; margin-bottom: 12px; }
.exam-status { font-size: 0.85rem; color: var(--muted); }
.exam-status.wip { color: var(--accent); font-weight: 600; }
.exam-status.done { color: var(--right); font-weight: 600; }
.exam-card-go { color: var(--accent); font-weight: 700; white-space: nowrap; }

.link-back {
  display: inline-block; background: none; border: 0; font: inherit;
  color: var(--accent); cursor: pointer; padding: 0; margin: 0 0 12px;
}
.link-back:hover { text-decoration: underline; }

/* 能力分級（鑑別卷） */
.band-box {
  background: var(--accent-soft); border: 1px solid #dbe6ff;
  border-radius: var(--radius); padding: 16px 18px; margin: 4px 0 18px;
}
.band-now { font-size: 1rem; color: var(--muted); }
.band-name { font-size: 1.5rem; color: var(--accent); margin-left: 4px; }
.band-anchor { color: #374151; font-size: 0.92rem; margin: 6px 0 12px; }
.band-scale { display: flex; gap: 6px; flex-wrap: wrap; }
.band-pill {
  flex: 1; min-width: 56px; text-align: center;
  background: #fff; border: 1px solid var(--line); color: var(--muted);
  border-radius: 999px; padding: 5px 8px; font-size: 0.82rem;
}
.band-pill.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }

.bars-title { font-size: 1rem; margin: 18px 0 12px; color: var(--ink); }

/* 難度層級長條與標籤 */
.badge.l-base, .dbar-fill.l-base { background: var(--base); }
.badge.l-mid, .dbar-fill.l-mid { background: var(--mid); }
.badge.l-hard, .dbar-fill.l-hard { background: var(--hard); }
.badge-disc { background: #64748b; }

.results-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }

@media (max-width: 480px) {
  body { font-size: 15px; }
  .palette { grid-template-columns: repeat(5, 1fr); }
  .stem { font-size: 1rem; }
  .exam-card { flex-direction: column; align-items: stretch; }
  .exam-card-go { align-self: flex-end; }
}
