/* app.css — SAA-C03 學習中心設計系統
   深色優先（夜讀）、手機底部導覽、桌機側欄；觸控目標 ≥44px。 */

/* ============ Design Tokens ============ */
:root {
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Segoe UI", system-ui, -apple-system, sans-serif;
  --radius: 16px;
  --radius-s: 10px;
  --maxw: 860px;
  --sidebar-w: 228px;
  --bottomnav-h: 60px;
}

:root[data-theme="dark"] {
  --bg: #0b101e;
  --surface: #131b2e;
  --surface-2: #1b2540;
  --surface-3: #232f52;
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.30);
  --text: #e9edf5;
  --text-2: #a8b1c5;
  --muted: #6f7a94;
  --primary: #2dd4bf;
  --primary-strong: #14b8a6;
  --on-primary: #06221d;
  --primary-dim: rgba(45, 212, 191, 0.14);
  --ok: #34c98a;
  --ok-dim: rgba(52, 201, 138, 0.14);
  --warn: #f5b84d;
  --warn-dim: rgba(245, 184, 77, 0.15);
  --danger: #e66767;
  --danger-dim: rgba(230, 103, 103, 0.14);
  --d1: #3987e5;
  --d2: #199e70;
  --d3: #c98500;
  --d4: #9085e9;
  --ring-track: #263252;
  --hm0: #1a2338;
  --hm1: #14403a;
  --hm2: #14655a;
  --hm3: #14907e;
  --hm4: #3fd6bf;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --grid-line: rgba(148, 163, 184, 0.12);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f2f5fa;
  --surface-3: #e8edf5;
  --border: #e3e8f0;
  --border-strong: #c9d2e0;
  --text: #1a2337;
  --text-2: #48536b;
  --muted: #7b869e;
  --primary: #0f766e;
  --primary-strong: #0d9488;
  --on-primary: #ffffff;
  --primary-dim: rgba(13, 148, 136, 0.10);
  --ok: #12813c;
  --ok-dim: rgba(18, 129, 60, 0.10);
  --warn: #a16207;
  --warn-dim: rgba(161, 98, 7, 0.10);
  --danger: #c23b3b;
  --danger-dim: rgba(194, 59, 59, 0.09);
  --d1: #2a78d6;
  --d2: #1baf7a;
  --d3: #eda100;
  --d4: #4a3aa7;
  --ring-track: #e4e9f2;
  --hm0: #eaeef5;
  --hm1: #bfe8de;
  --hm2: #6fcdb9;
  --hm3: #23a28e;
  --hm4: #0c6a5d;
  --shadow: 0 8px 24px rgba(30, 41, 66, 0.10);
  --grid-line: #e7ebf2;
  color-scheme: light;
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15.5px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { line-height: 1.35; margin: 0; font-weight: 700; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
h4 { font-size: 0.98rem; }
p { margin: 0; }
button { font-family: inherit; font-size: inherit; color: inherit; background: none; border: none; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
select, input, textarea { font-family: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }

.sub { color: var(--text-2); font-size: 0.92rem; }
.tiny { font-size: 0.8rem; }
.center { text-align: center; }
.flex-spacer { flex: 1; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 0.82rem; }

.icn { display: inline-flex; width: 22px; height: 22px; flex: none; }
.icn svg { width: 100%; height: 100%; }

/* ============ App 骨架 ============ */
.app { display: flex; min-height: 100vh; }

.sidebar {
  display: none;
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  padding: 20px 14px calc(16px + env(safe-area-inset-bottom));
  border-right: 1px solid var(--border);
  background: var(--surface);
  flex-direction: column;
  gap: 4px;
  z-index: 30;
}
.logo { display: flex; gap: 10px; align-items: center; padding: 4px 10px 18px; }
.logo b { font-size: 1.05rem; display: block; line-height: 1.2; }
.logo-icon { width: 34px; height: 34px; color: var(--primary); }

.side-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius-s);
  color: var(--text-2);
  font-weight: 500;
  position: relative;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-dim); color: var(--primary); font-weight: 700; }
.nav-badge {
  display: none;
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  min-width: 20px; height: 20px;
  border-radius: 10px;
  text-align: center;
  line-height: 20px;
  padding: 0 5px;
}
.side-mini { padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; color: var(--text-2); font-size: 0.87rem; }
.side-mini-row { display: flex; gap: 8px; align-items: center; }
.side-mini-row .icn { width: 17px; height: 17px; color: var(--primary); }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.12rem; }

main {
  flex: 1;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 16px 16px calc(24px + var(--bottomnav-h) + env(safe-area-inset-bottom));
}

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav .nav-item {
  flex: 1; flex-direction: column; gap: 3px;
  padding: 8px 4px 7px;
  border-radius: 0;
  font-size: 0.72rem;
  min-height: var(--bottomnav-h);
  justify-content: center;
}
.bottomnav .nav-item.active { background: none; }
.nav-icon-wrap { position: relative; display: inline-flex; }
.nav-icon-wrap .nav-badge { position: absolute; top: -6px; right: -14px; margin: 0; }

@media (min-width: 900px) {
  .sidebar { display: flex; }
  .content { margin-left: var(--sidebar-w); }
  .bottomnav { display: none; }
  .topbar .topbar-gear { display: none; }
  main { padding-bottom: 40px; }
}

.boot-error {
  margin: 12px 16px 0;
  padding: 12px 14px;
  background: var(--danger-dim);
  border: 1px solid var(--danger);
  border-radius: var(--radius-s);
  color: var(--danger);
  font-size: 0.88rem;
}

/* ============ 通用元件 ============ */
.view { display: flex; flex-direction: column; gap: 14px; animation: fadein 0.18s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card-title { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 1rem; }
.card-title .icn { color: var(--primary); width: 20px; height: 20px; }

.lead { color: var(--text-2); font-size: 0.92rem; padding: 2px 2px 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: 600;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  cursor: pointer;
  user-select: none;
}
.btn .icn { width: 18px; height: 18px; }
.btn.primary { background: var(--primary-strong); color: var(--on-primary); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: var(--border-strong); color: var(--text); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger-ghost { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn.danger-ghost:hover { background: var(--danger-dim); }
.btn.big { min-height: 52px; font-size: 1.02rem; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px;
  border-radius: 12px;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.sync-ind.s-ok { color: var(--ok); }
.sync-ind.s-syncing { color: var(--primary); animation: syncpulse 1.2s ease infinite; }
.sync-ind.s-offline, .sync-ind.s-blocked { color: var(--muted); }
.sync-ind.s-error { color: var(--danger); }
@keyframes syncpulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
}
.chip-ok { background: var(--ok-dim); color: var(--ok); border-color: transparent; }
.chip-bad { background: var(--danger-dim); color: var(--danger); border-color: transparent; }
.chip-now { background: var(--primary-dim); color: var(--primary); border-color: transparent; }
.chip-new { background: var(--primary-dim); color: var(--primary); border-color: transparent; }
.chip-explain { background: var(--d4); color: #fff; border-color: transparent; }
.chip-mistake { background: var(--danger-dim); color: var(--danger); border-color: transparent; }
.chip-multi { background: var(--warn-dim); color: var(--warn); border-color: transparent; }
.chip-d1 { background: color-mix(in srgb, var(--d1) 16%, transparent); color: var(--d1); border-color: transparent; }
.chip-d2 { background: color-mix(in srgb, var(--d2) 16%, transparent); color: var(--d2); border-color: transparent; }
.chip-d3 { background: color-mix(in srgb, var(--d3) 18%, transparent); color: var(--d3); border-color: transparent; }
.chip-d4 { background: color-mix(in srgb, var(--d4) 16%, transparent); color: var(--d4); border-color: transparent; }

.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.dot-d1 { background: var(--d1); }
.dot-d2 { background: var(--d2); }
.dot-d3 { background: var(--d3); }
.dot-d4 { background: var(--d4); }

.input {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
}
textarea.input { min-height: 110px; resize: vertical; }

.row-btns { display: flex; gap: 10px; }
.row-btns.wrap { flex-wrap: wrap; }
.row-btns.center { justify-content: center; }

/* Toast */
.toasts {
  position: fixed; top: calc(14px + env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px;
  z-index: 100;
  width: min(92vw, 400px);
  pointer-events: none;
}
.toast {
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: 12px;
  padding: 11px 16px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0; transform: translateY(-8px);
  transition: opacity 0.2s, transform 0.2s;
  text-align: center;
}
.toast.in { opacity: 1; transform: none; }
.toast.ok { border-color: var(--ok); }
.toast.warn { border-color: var(--warn); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(5, 9, 18, 0.62);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
.modal-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 560px;
  max-height: 86vh;
  display: flex; flex-direction: column;
  animation: slideup 0.2s ease;
}
@keyframes slideup { from { transform: translateY(24px); opacity: 0.6; } to { transform: none; opacity: 1; } }
@media (min-width: 640px) {
  .modal-overlay { align-items: center; padding: 20px; }
  .modal-panel { border-radius: 20px; }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 6px; }
.modal-body { padding: 8px 18px 16px; overflow-y: auto; }
.modal-actions { display: flex; gap: 10px; padding: 0 18px calc(16px + env(safe-area-inset-bottom)); }
.modal-actions .btn { flex: 1; }
.confirm-text { color: var(--text-2); }

/* Tooltip */
.tip {
  position: fixed; z-index: 110;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 7px 11px;
  border-radius: 10px;
  font-size: 0.8rem;
  line-height: 1.5;
  pointer-events: none;
  box-shadow: var(--shadow);
  display: none;
  max-width: 240px;
}

/* Ring */
.ring { position: relative; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.ring-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 0.72rem; font-weight: 700;
  text-align: center;
}
.ring-big { font-size: 1.45rem; font-weight: 800; }
.ring-sub { font-size: 0.72rem; color: var(--text-2); font-weight: 500; }
.ring-check { color: var(--ok); font-size: 1rem; font-weight: 800; }
.ring-check.big { font-size: 2rem; }

/* Bar rows（領域量條） */
.bar-row { display: flex; flex-direction: column; gap: 4px; padding: 6px 0; }
.bar-row-top { display: flex; justify-content: space-between; gap: 10px; font-size: 0.87rem; }
.bar-label { color: var(--text-2); font-weight: 500; }
.bar-value { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }
.bar-track { height: 9px; background: var(--ring-track); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 5px; transition: width 0.4s ease; }

/* ============ 今日（Dashboard） ============ */
.dash-hello { display: flex; align-items: center; justify-content: space-between; padding: 4px 2px 0; }
.streak-chip {
  display: flex; align-items: center; gap: 5px;
  background: var(--warn-dim);
  color: var(--warn);
  border-radius: 999px;
  padding: 7px 14px;
  font-weight: 600;
}
.streak-chip .icn { width: 18px; height: 18px; }
.streak-chip b { font-size: 1.05rem; }

.nosync-banner {
  display: flex; gap: 12px; align-items: center;
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  background: var(--warn-dim);
  text-align: left;
  cursor: pointer;
}
.nosync-banner > .icn { color: var(--warn); flex: none; }
.nosync-text { flex: 1; display: flex; flex-direction: column; gap: 1px; }

.countdown { display: flex; gap: 16px; align-items: center; }
.countdown.setup { gap: 12px; }
.countdown.setup:hover { border-color: var(--primary); }
.count-icon { width: 34px; height: 34px; color: var(--primary); }
.count-num { font-size: 2.3rem; font-weight: 800; line-height: 1.1; color: var(--primary); font-variant-numeric: tabular-nums; }
.countdown.warm .count-num { color: var(--warn); }
.countdown.hot .count-num { color: var(--danger); }
.count-label { font-size: 0.8rem; color: var(--text-2); text-align: center; }
.count-right { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.count-band { display: flex; align-items: center; gap: 7px; font-weight: 600; font-size: 0.94rem; }
.band-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

.task-list { display: flex; flex-direction: column; gap: 8px; }
.task-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  text-align: left;
  width: 100%;
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}
.task-row:hover { border-color: var(--primary); }
.task-row.done { opacity: 0.72; }
.task-check {
  width: 38px; height: 38px; flex: none;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary-dim);
  color: var(--primary);
}
.task-check.on { background: var(--ok-dim); color: var(--ok); }
.task-check .icn { width: 19px; height: 19px; }
.task-mid { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.task-go { color: var(--muted); width: 18px; height: 18px; }

.phase-topics { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.phase-topic {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  min-height: 46px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s;
}
.phase-topic:hover { border-color: var(--primary); }
.phase-topic.done { opacity: 0.75; }
.pt-icon.ok { color: var(--ok); width: 20px; height: 20px; }
.pt-pct {
  font-size: 0.72rem; font-weight: 700;
  color: var(--primary);
  background: var(--primary-dim);
  min-width: 30px; height: 24px;
  border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  font-variant-numeric: tabular-nums;
  flex: none;
}
.pt-title { flex: 1; font-weight: 500; font-size: 0.93rem; }
.pt-go { color: var(--muted); width: 16px; height: 16px; }

.quick-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 640px) { .quick-grid { grid-template-columns: repeat(4, 1fr); } }
.quick-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  min-height: 92px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.quick-btn:hover { border-color: var(--primary); }
.quick-icon { color: var(--primary); width: 24px; height: 24px; margin-bottom: 4px; }
.quick-btn b { font-size: 0.95rem; }

.today-stats {
  display: flex; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 8px;
}
.tstat { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.tstat b { font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.tstat span { font-size: 0.76rem; color: var(--text-2); }

/* ============ 學習（Roadmap / Topic） ============ */
.phase {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.phase.current { border-color: var(--primary); }
.phase-head {
  display: flex; align-items: center; gap: 14px;
  width: 100%;
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
}
.phase-head:hover { background: var(--surface-2); }
.phase-head-mid { flex: 1; min-width: 0; }
.phase-name { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 1rem; }
.phase-chev { color: var(--muted); transition: transform 0.2s; }
.phase.open .phase-chev { transform: rotate(180deg); }
.phase-body { display: none; padding: 0 16px 16px; flex-direction: column; gap: 6px; }
.phase.open .phase-body { display: flex; }

.topic-row {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s;
}
.topic-row:hover { border-color: var(--primary); }
.topic-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.topic-mid b { font-size: 0.95rem; }
.topic-chips { display: flex; gap: 4px; flex: none; }
.gate-btn { margin-top: 6px; }

.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-2);
  font-size: 0.9rem;
  padding: 6px 4px;
  min-height: 40px;
  cursor: pointer;
}
.back-link:hover { color: var(--primary); }
.back-link .icn { width: 18px; height: 18px; }

.topic-head { display: flex; flex-direction: column; gap: 8px; }
.topic-head-chips { display: flex; gap: 6px; flex-wrap: wrap; }

.essence {
  background: linear-gradient(135deg, var(--primary-dim), transparent 70%);
  border: 1px solid color-mix(in srgb, var(--primary) 35%, transparent);
  border-radius: var(--radius);
  padding: 16px;
}
.essence-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--primary); }
.essence-head .icn { width: 20px; height: 20px; }

.topic-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.topic-actions .btn { flex: 1; min-width: 150px; }

.section-card h3 { margin-bottom: 8px; color: var(--primary); font-size: 1.02rem; }

.pitfalls { border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.pitfalls h3 { display: flex; align-items: center; gap: 8px; color: var(--warn); margin-bottom: 8px; }
.pitfalls h3 .icn { width: 20px; height: 20px; }
.pit-list { margin: 0; padding: 0 0 0 2px; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.pit-list li {
  padding: 9px 12px;
  background: var(--warn-dim);
  border-radius: 10px;
  font-size: 0.9rem;
}

.cardlist h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.cardlist h3 .icn { width: 20px; height: 20px; color: var(--primary); }
.cl-row { border-bottom: 1px solid var(--border); }
.cl-row:last-child { border-bottom: none; }
.cl-front {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 11px 4px;
  text-align: left;
  min-height: 46px;
  cursor: pointer;
}
.cl-front:hover .cl-q { color: var(--primary); }
.cl-state {
  flex: none;
  font-size: 0.7rem; font-weight: 700;
  color: var(--muted);
  border: 1px solid var(--border-strong);
  padding: 2px 8px;
  border-radius: 999px;
}
.cl-state.seen { color: var(--ok); border-color: var(--ok); }
.cl-q { flex: 1; font-size: 0.9rem; }
.cl-back {
  padding: 4px 8px 14px 8px;
  font-size: 0.9rem;
  color: var(--text-2);
  border-left: 3px solid var(--primary);
  margin: 0 0 10px 6px;
}

.topic-nav { display: flex; gap: 10px; padding: 6px 0 12px; }

/* ============ 複習 ============ */
.due-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 480px) { .due-grid { grid-template-columns: repeat(2, 1fr); } }
.due-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  text-align: center;
}
.due-box b { font-size: 1.7rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.due-box.zero { opacity: 0.65; }
.due-title { font-weight: 600; font-size: 0.86rem; }

.review-actions { display: flex; flex-direction: column; gap: 10px; }

.empty-state {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 28px 16px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.empty-icon { width: 40px; height: 40px; color: var(--ok); }

/* 回合 */
.sess-head { display: flex; align-items: center; gap: 10px; padding: 2px 0 6px; }
.sess-bar { flex: 1; height: 7px; background: var(--ring-track); border-radius: 4px; overflow: hidden; }
.sess-bar-fill { height: 100%; background: var(--primary); border-radius: 4px; transition: width 0.25s ease; }
.sess-count { font-size: 0.82rem; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.sess-label { display: none; font-size: 0.82rem; color: var(--muted); }
@media (min-width: 640px) { .sess-label { display: inline; } }

.stage { display: flex; flex-direction: column; gap: 12px; }
.stage-meta { display: flex; gap: 6px; flex-wrap: wrap; }

.flashcard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 18px;
  min-height: 180px;
  cursor: pointer;
}
.flashcard.flipped { cursor: default; }
.fc-front { font-size: 1.08rem; font-weight: 600; line-height: 1.7; }
.fc-back { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--border-strong); }
.fc-hint { font-size: 0.8rem; font-weight: 700; color: var(--muted); letter-spacing: 0.05em; margin-bottom: 8px; }
.fc-divider { border-top: 1px dashed var(--border-strong); margin: 14px 0; }
.fc-why {
  display: flex; gap: 10px;
  margin-top: 14px;
  padding: 12px;
  background: var(--primary-dim);
  border-radius: 10px;
  font-size: 0.9rem;
}
.fc-why .icn { color: var(--primary); flex: none; width: 20px; height: 20px; }

.rubric { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.rubric li {
  display: flex; gap: 9px; align-items: flex-start;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.rubric li .rub-icon { width: 18px; height: 18px; color: var(--muted); flex: none; margin-top: 2px; }
.rubric li.hit { background: var(--ok-dim); border-color: var(--ok); }
.rubric li.hit .rub-icon { color: var(--ok); }

.flip-btn { border-style: dashed; }

.grade-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grade-btn {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 10px 4px 8px;
  min-height: 64px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: transform 0.06s, border-color 0.15s, background 0.15s;
}
.grade-btn:active { transform: scale(0.97); }
.grade-btn b { font-size: 0.95rem; }
.g-ivl { font-size: 0.72rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.g-key { font-size: 0.66rem; color: var(--muted); display: none; }
@media (min-width: 900px) { .g-key { display: block; } }
.g-again { border-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.g-again b { color: var(--danger); }
.g-again:hover { background: var(--danger-dim); }
.g-hard { border-color: color-mix(in srgb, var(--warn) 50%, transparent); }
.g-hard b { color: var(--warn); }
.g-hard:hover { background: var(--warn-dim); }
.g-good { border-color: color-mix(in srgb, var(--primary) 55%, transparent); }
.g-good b { color: var(--primary); }
.g-good:hover { background: var(--primary-dim); }
.g-easy { border-color: color-mix(in srgb, var(--d1) 50%, transparent); }
.g-easy b { color: var(--d1); }
.g-easy:hover { background: color-mix(in srgb, var(--d1) 12%, transparent); }

.next-btn { margin-top: 4px; }

.done-box {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  text-align: center;
  padding: 32px 16px 20px;
}

/* ============ 情境題卡 ============ */
.qcard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.q-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.q-num { font-size: 0.8rem; color: var(--muted); font-weight: 600; margin-right: 2px; }
.q-stem { font-size: 1rem; font-weight: 550; line-height: 1.75; }
.q-opts { display: flex; flex-direction: column; gap: 8px; }
.q-opt {
  display: flex; gap: 11px; align-items: flex-start;
  width: 100%;
  padding: 12px 13px;
  min-height: 48px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.q-opt:hover:not(:disabled) { border-color: var(--primary); }
.q-opt.sel { border-color: var(--primary); background: var(--primary-dim); }
.q-opt-key {
  flex: none;
  width: 26px; height: 26px;
  border-radius: 8px;
  background: var(--surface-3);
  color: var(--text-2);
  font-weight: 700; font-size: 0.82rem;
  display: inline-flex; align-items: center; justify-content: center;
  margin-top: 1px;
}
.q-opt.sel .q-opt-key { background: var(--primary-strong); color: var(--on-primary); }
.q-opt-text { flex: 1; font-size: 0.93rem; line-height: 1.65; }
.q-opt-text p { margin: 0; }
.q-opt:disabled { cursor: default; }
.q-opt.opt-correct { border-color: var(--ok); background: var(--ok-dim); }
.q-opt.opt-wrong { border-color: var(--danger); background: var(--danger-dim); }
.q-opt.opt-dim { opacity: 0.62; }
.q-opt-mark { flex: none; width: 20px; height: 20px; margin-top: 3px; }
.opt-correct .q-opt-mark { color: var(--ok); }
.opt-wrong .q-opt-mark { color: var(--danger); }
.opt-dim .q-opt-mark { color: var(--muted); opacity: 0; }

.q-why {
  font-size: 0.86rem;
  color: var(--text-2);
  padding: 4px 12px 10px 14px;
  margin: -2px 0 2px;
  border-left: 3px solid var(--border-strong);
  margin-left: 12px;
}
.q-why.why-ok { border-left-color: var(--ok); }
.q-why.why-no { border-left-color: color-mix(in srgb, var(--danger) 55%, transparent); }

.q-principle {
  background: var(--primary-dim);
  border: 1px solid color-mix(in srgb, var(--primary) 35%, transparent);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.92rem;
}
.q-principle-head { display: flex; align-items: center; gap: 7px; color: var(--primary); margin-bottom: 4px; }
.q-principle-head .icn { width: 19px; height: 19px; }

.q-result {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700;
  padding: 4px 2px 0;
}
.q-result.ok { color: var(--ok); }
.q-result.no { color: var(--danger); }
.q-result .icn { width: 20px; height: 20px; }

.q-footer { display: flex; }
.q-submit { flex: 1; }

/* ============ 測驗中心 ============ */
.domain-row {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 11px 10px;
  min-height: 56px;
  border-radius: 12px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}
.domain-row:hover { background: var(--surface-2); }
.domain-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.domain-pct { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--text-2); }
.gate-n {
  flex: none;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-2);
  font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center;
}
.topic-quiz-row { display: flex; gap: 8px; }
.topic-quiz-row .input { flex: 1; }

/* ============ 模考 ============ */
.resume-card { border-color: var(--warn); }
.exam-opt .btn { margin-top: 8px; }
.exam-head { position: sticky; top: calc(54px + env(safe-area-inset-top)); z-index: 10; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-radius: 12px; padding: 6px; }
.exam-timebox {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 6px 12px;
  font-variant-numeric: tabular-nums;
}
.exam-timebox .icn { width: 17px; height: 17px; color: var(--text-2); }
.exam-timebox.low { border-color: var(--danger); color: var(--danger); }
.exam-timebox.low .icn { color: var(--danger); }
.exam-nav { display: flex; gap: 8px; }
.exam-nav .btn { flex: 1; }
.flag-btn.on { border-color: var(--warn); color: var(--warn); background: var(--warn-dim); }

.palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; padding: 8px 0; }
.pal-cell {
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-weight: 600; font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.pal-cell.a { background: var(--primary-dim); border-color: var(--primary); color: var(--primary); }
.pal-cell.f { box-shadow: inset 0 -3px 0 var(--warn); }
.pal-cell.cur { outline: 2px solid var(--primary); }
.pal-legend { display: flex; gap: 14px; padding-top: 6px; }
.pal-key { font-size: 0.78rem; color: var(--text-2); padding-left: 18px; position: relative; }
.pal-key::before {
  content: ""; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 13px; height: 13px; border-radius: 4px;
  border: 1px solid var(--border-strong); background: var(--surface-2);
}
.pal-key.a::before { background: var(--primary-dim); border-color: var(--primary); }
.pal-key.f::before { box-shadow: inset 0 -3px 0 var(--warn); }

.exp-row { border-bottom: 1px solid var(--border); }
.exp-row:last-child { border-bottom: none; }
.exp-head {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 12px 4px;
  min-height: 48px;
  text-align: left;
  cursor: pointer;
}
.exp-head:hover .exp-stem { color: var(--primary); }
.exp-icon { flex: none; width: 19px; height: 19px; }
.exp-icon.ok { color: var(--ok); }
.exp-icon.no { color: var(--danger); }
.exp-stem { flex: 1; font-size: 0.88rem; color: var(--text-2); }
.exp-chev { color: var(--muted); width: 16px; height: 16px; }
.exp-body { padding: 0 0 14px; }

/* ============ 歷程 ============ */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex; flex-direction: column; gap: 2px;
}
.tile-icon { width: 20px; height: 20px; color: var(--primary); margin-bottom: 4px; }
.tile b { font-size: 1.45rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.2; }

.ready-flex { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.ready-bars { flex: 1; min-width: 240px; }

.heatmap { display: flex; gap: 3px; overflow-x: auto; padding: 4px 0; }
.hm-col { display: flex; flex-direction: column; gap: 3px; }
.hm-cell {
  width: 13px; height: 13px;
  border-radius: 3.5px;
  background: var(--hm0);
  flex: none;
}
.hm-cell.lv1 { background: var(--hm1); }
.hm-cell.lv2 { background: var(--hm2); }
.hm-cell.lv3 { background: var(--hm3); }
.hm-cell.lv4 { background: var(--hm4); }
.hm-cell.future { opacity: 0.25; }
.hm-cell.today { outline: 1.5px solid var(--primary); outline-offset: 1px; }
.hm-legend { display: flex; gap: 10px; align-items: center; padding-top: 8px; flex-wrap: wrap; }
.hm-key { display: inline-flex; align-items: center; gap: 4px; }

.fc-chart {
  display: flex; align-items: flex-end; gap: 4px;
  padding: 8px 0 2px;
  min-height: 110px;
}
.fc-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; }
.fc-val { font-size: 0.68rem; color: var(--text-2); font-variant-numeric: tabular-nums; height: 14px; }
.fc-bar { width: 100%; max-width: 26px; background: var(--d1); border-radius: 4px 4px 0 0; opacity: 0.85; }
.fc-bar.today { background: var(--primary); opacity: 1; }
.fc-day { font-size: 0.68rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.tl-row { display: flex; gap: 12px; align-items: center; padding: 8px 2px; }
.tl-dot {
  flex: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1.5px solid var(--border-strong);
  color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.85rem;
}
.tl-dot .icn { width: 16px; height: 16px; }
.tl-row.done .tl-dot { background: var(--ok-dim); border-color: var(--ok); color: var(--ok); }
.tl-row.cur .tl-dot { border-color: var(--primary); color: var(--primary); background: var(--primary-dim); }
.tl-mid { display: flex; flex-direction: column; }

.t-ok { color: var(--ok); }
.t-warn { color: var(--warn); }

/* ============ 設定 ============ */
.field { display: flex; gap: 14px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.field:last-child { border-bottom: none; }
.field-label { flex: 1; display: flex; flex-direction: column; gap: 1px; }
.field .input { width: 190px; flex: none; }
@media (max-width: 480px) {
  .field { flex-direction: column; align-items: stretch; gap: 8px; }
  .field .input { width: 100%; }
}
.warn-box {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--warn-dim);
  border: 1px solid color-mix(in srgb, var(--warn) 50%, transparent);
  border-radius: 12px;
  padding: 12px;
  font-size: 0.88rem;
  margin: 8px 0;
}
.warn-box .icn { color: var(--warn); flex: none; width: 20px; height: 20px; }

/* ============ 教材內文（md） ============ */
.md { font-size: 0.95rem; }
.md p { margin: 0 0 10px; }
.md p:last-child { margin-bottom: 0; }
.md h4 { margin: 14px 0 6px; color: var(--primary); }
.md ul, .md ol { margin: 0 0 10px; padding-left: 1.3em; display: flex; flex-direction: column; gap: 4px; }
.md li { line-height: 1.65; }
.md code {
  background: var(--surface-3);
  border-radius: 5px;
  padding: 1px 6px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.85em;
}
.md strong { color: var(--text); font-weight: 700; }
.table-wrap { overflow-x: auto; margin: 4px 0 10px; border: 1px solid var(--border); border-radius: 10px; }
.table-wrap table { border-collapse: collapse; width: 100%; min-width: 420px; font-size: 0.88rem; }
.table-wrap th, .table-wrap td { padding: 8px 11px; text-align: left; border-bottom: 1px solid var(--grid-line); vertical-align: top; }
.table-wrap th { background: var(--surface-2); font-weight: 700; white-space: nowrap; }
.table-wrap tr:last-child td { border-bottom: none; }

/* ============ 首次開啟登入閘門 ============ */
.welcome-overlay {
  position: fixed; inset: 0; z-index: 80;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto;
}
.welcome-card {
  max-width: 400px; width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  text-align: center;
}
.welcome-logo { width: 60px; height: 60px; color: var(--primary); }
.welcome-points {
  list-style: none; margin: 4px 0 8px; padding: 0;
  display: flex; flex-direction: column; gap: 10px;
  text-align: left; width: 100%;
}
.welcome-points li { display: flex; gap: 10px; align-items: flex-start; font-size: 0.93rem; color: var(--text-2); }
.welcome-points .icn { color: var(--ok); flex: none; width: 20px; height: 20px; }
.welcome-skip {
  color: var(--muted);
  font-size: 0.87rem;
  padding: 10px;
  min-height: 44px;
  cursor: pointer;
}
.welcome-skip:hover { color: var(--text-2); text-decoration: underline; }

/* ============ 其他 ============ */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
::selection { background: color-mix(in srgb, var(--primary) 35%, transparent); }
