/* =========================================================
   會考衝刺站 — 樣式（CSS 優先、行動裝置優先）
   ========================================================= */
:root {
  --bg: #f3f4f8;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --good: #16a34a;
  --warn: #d97706;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(17, 24, 39, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

/* ---------- 標題列 ---------- */
.app-header {
  background: linear-gradient(120deg, #4f46e5, #7c3aed 60%, #db2777);
  color: #fff;
  padding-top: env(safe-area-inset-top);
  position: sticky;
  top: 0;
  z-index: 20;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  max-width: 640px;
  margin: 0 auto;
}
.app-header h1 { margin: 0; font-size: 1.15rem; letter-spacing: 0.02em; }
.role-badge {
  border: 1px solid rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.8rem;
  cursor: pointer;
}

/* ---------- 主要區塊 ---------- */
main { max-width: 640px; margin: 0 auto; padding: 14px 14px 24px; }
.tab { display: none; }
.tab.active { display: block; animation: fadein 0.18s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.card h2 { margin: 0 0 8px; font-size: 1rem; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.card-head h2 { margin: 0; }
.card-inset { background: var(--accent-soft); border-radius: 10px; padding: 12px; margin-top: 10px; }
.muted { color: var(--muted); font-size: 0.85rem; }
.small { font-size: 0.78rem; }
.mini-stat { color: var(--muted); font-size: 0.8rem; }

/* ---------- 倒數卡 ---------- */
.countdown-card { text-align: center; padding: 20px 16px; }
.countdown-label { color: var(--muted); font-size: 0.9rem; }
.countdown-days { font-size: 3rem; font-weight: 800; color: var(--accent); line-height: 1.15; }
.countdown-days small { font-size: 1.1rem; font-weight: 600; color: var(--ink); }
.countdown-date { color: var(--muted); font-size: 0.85rem; }

/* ---------- 任務清單 ---------- */
.task-list { list-style: none; margin: 0 0 10px; padding: 0; }
.task-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 2px;
  border-bottom: 1px solid var(--line);
}
.task-list li:last-child { border-bottom: none; }
.task-check {
  width: 22px; height: 22px;
  flex: none;
  border: 2px solid #c7cad4;
  border-radius: 7px;
  background: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  color: transparent;
  transition: all 0.15s;
}
.task-check.done { background: var(--good); border-color: var(--good); color: #fff; }
.task-text { flex: 1; font-size: 0.95rem; word-break: break-word; }
li.done .task-text { color: var(--muted); text-decoration: line-through; }
.task-del {
  border: none; background: none; color: #c0c3cc;
  font-size: 1.05rem; cursor: pointer; padding: 4px;
}
.task-del:active { color: #ef4444; }
.subject-tag {
  flex: none;
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

/* ---------- 表單 ---------- */
.add-form { display: flex; gap: 8px; }
.add-form input[type="text"] {
  flex: 1; min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.95rem;
}
.add-form select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 6px;
  font-size: 0.9rem;
  background: #fff;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.wide-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.95rem;
}
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; }
.field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.9rem;
}

/* ---------- 按鈕 ---------- */
.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; font-size: 1rem; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 打卡 ---------- */
.checkin-card { background: linear-gradient(120deg, #fff7ed, #fef3c7); }
.checkin-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.streak-num { font-size: 1.05rem; }
.streak-num b { color: var(--warn); font-size: 1.3rem; }
.checkin-btn { background: var(--warn); border-color: var(--warn); color: #fff; font-weight: 700; }
.checkin-btn.done { background: var(--good); border-color: var(--good); }

/* ---------- 進度條 ---------- */
.progress-bar { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, #4f46e5, #7c3aed); border-radius: 999px; transition: width 0.3s; }

/* ---------- 週計畫 ---------- */
.week-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.week-title { font-weight: 700; font-size: 0.95rem; }
.subject-group { margin-bottom: 4px; }
.subject-group h3 {
  margin: 10px 2px 4px;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}
.empty-hint { text-align: center; color: var(--muted); padding: 28px 0; font-size: 0.9rem; }

/* ---------- 積分試算 ---------- */
.calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.calc-item label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; }
.calc-item select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 8px;
  font-size: 0.95rem;
  background: #fff;
}
.calc-total { font-size: 1.05rem; }
.calc-total b { font-size: 1.7rem; color: var(--accent); }
.calc-combo { margin-top: 4px; font-size: 0.9rem; color: var(--muted); }
.ref-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-bottom: 8px; }
.ref-table th, .ref-table td { border: 1px solid var(--line); padding: 5px 4px; text-align: center; }
.ref-table th { background: var(--accent-soft); color: var(--accent); }

/* ---------- 歷屆試題練習 ---------- */
.paper-list { display: flex; flex-direction: column; gap: 8px; }
.paper-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 0.95rem;
  cursor: pointer;
  text-align: left;
}
.paper-row:active { background: var(--accent-soft); }
.paper-name { font-weight: 600; }
.paper-meta { color: var(--muted); font-size: 0.8rem; flex: none; }

.quiz-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.quiz-progress { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.passage-text { font-size: 0.92rem; line-height: 1.7; color: #374151; max-height: 40vh; overflow-y: auto; }
.quiz-stem { font-size: 1rem; line-height: 1.65; margin-bottom: 12px; white-space: pre-wrap; }
.quiz-image { max-width: 100%; border-radius: 8px; margin-bottom: 10px; }
.quiz-options { display: flex; flex-direction: column; gap: 8px; }
.quiz-opt {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1.5px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 0.95rem;
  line-height: 1.5;
  cursor: pointer;
  text-align: left;
}
.quiz-opt:disabled { cursor: default; opacity: 0.9; }
.quiz-opt .opt-label {
  flex: none;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.8rem;
  display: grid;
  place-items: center;
}
.quiz-opt.right { border-color: var(--good); background: #f0fdf4; }
.quiz-opt.right .opt-label { background: var(--good); color: #fff; }
.quiz-opt.wrong { border-color: #ef4444; background: #fef2f2; }
.quiz-opt.wrong .opt-label { background: #ef4444; color: #fff; }
.quiz-feedback { margin-top: 12px; padding: 10px 12px; border-radius: 10px; font-size: 0.95rem; }
.quiz-feedback.ok { background: #f0fdf4; color: var(--good); }
.quiz-feedback.bad { background: #fef2f2; color: #b91c1c; }
.quiz-feedback .explain { margin-top: 6px; color: #374151; font-size: 0.88rem; line-height: 1.6; }
.btn.wide { width: 100%; margin-top: 12px; }

/* ---------- 家長摘要 ---------- */
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.summary-grid .cell {
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}
.summary-grid .cell b { display: block; font-size: 1.25rem; color: var(--accent); }
.summary-grid .cell span { font-size: 0.75rem; color: var(--muted); }

/* ---------- 身分切換 ---------- */
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-bottom: 8px; }
.seg button {
  flex: 1;
  border: none;
  background: #fff;
  padding: 9px;
  font-size: 0.9rem;
  cursor: pointer;
}
.seg button.active { background: var(--accent); color: #fff; font-weight: 700; }

/* ---------- 同步 ---------- */
.sync-status { margin-top: 10px; }
.sync-status.ok { color: var(--good); }
.sync-status.err { color: #dc2626; }
.setup-help { margin-top: 10px; font-size: 0.85rem; }
.setup-help summary { cursor: pointer; color: var(--accent); }
.setup-help ol { padding-left: 20px; color: var(--muted); }
.setup-help code { background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; font-size: 0.8rem; }

/* ---------- 底部分頁列 ---------- */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-top: 1px solid var(--line);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 30;
}
.tab-btn {
  flex: 1;
  border: none;
  background: none;
  padding: 8px 0 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: #9ca3af;
  font-size: 0.7rem;
  cursor: pointer;
}
.tab-btn svg {
  width: 22px; height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tab-btn.active { color: var(--accent); font-weight: 700; }
