:root {
  --bg: #f8f6fb;
  --text: #2f3140;
  --muted: #6c6f80;
  --hero: #e9ebff;
  --card: #e3e4ee;
  --wrong-card: #dfe3f7;
  --fav-card: #ead0ff;
  --primary: #4653a8;
  --primary-soft: #e8eaff;
  --ok: #dff3e4;
  --bad: #f8dfe3;
  --border: #d6d6e0;
  --surface: #ffffff;
  --shadow: 0 6px 20px rgba(45, 48, 70, 0.06);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, "Microsoft JhengHei", "PingFang TC", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; }
button { color: inherit; }

#app {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
}

.loading-card, .empty-card, .error-card {
  margin-top: 15vh;
  padding: 24px;
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
  line-height: 1.7;
}
.error-card { background: #fff1f2; }

.hero-card {
  background: var(--hero);
  border-radius: 24px;
  padding: 24px 20px 20px;
  margin-bottom: 14px;
}
.hero-card h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
}
.hero-meta { margin: 14px 0 0; font-size: 15px; }
.hero-version { margin: 8px 0 0; font-size: 12px; color: #55596b; line-height: 1.5; }
.hero-note { margin: 9px 0 0; font-size: 11px; color: #55596b; line-height: 1.55; }

.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.stat-card {
  border: 0;
  background: var(--wrong-card);
  border-radius: 18px;
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
}
.stat-card.favorite { background: var(--fav-card); }
.stat-title { font-size: 16px; }
.stat-value { margin-top: 8px; font-size: 20px; font-weight: 700; }

.section-title { font-size: 20px; margin: 8px 0 12px; }
.menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.menu-card, .mock-card, .selection-card {
  border: 0;
  border-radius: 18px;
  background: var(--card);
  padding: 20px 14px;
  text-align: left;
  cursor: pointer;
  min-height: 88px;
}
.mock-card { width: 100%; margin-top: 10px; min-height: 74px; }
.menu-card:active, .mock-card:active, .selection-card:active, .stat-card:active { transform: scale(0.99); }
.menu-title { font-size: 16px; font-weight: 600; line-height: 1.3; }
.menu-subtitle { margin-top: 6px; font-size: 13px; line-height: 1.4; color: var(--muted); }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  min-height: 42px;
}
.topbar-title { flex: 1; font-size: 20px; font-weight: 700; text-align: center; padding-right: 58px; }
.back-button, .ghost-button {
  border: 0;
  background: transparent;
  padding: 8px 4px;
  cursor: pointer;
  font-size: 15px;
}

.panel {
  background: var(--surface);
  border-radius: 20px;
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.selection-list { display: grid; gap: 10px; }
.selection-card { width: 100%; min-height: 70px; }
.selection-title { font-size: 16px; font-weight: 700; }
.selection-subtitle { margin-top: 6px; color: var(--muted); font-size: 13px; }

.practice-shell { font-size: calc(16px * var(--font-scale, 1)); }
.font-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  margin: 2px 0 12px;
}
.font-controls button {
  border: 0;
  background: transparent;
  padding: 7px 12px;
  color: var(--primary);
  cursor: pointer;
}
.font-controls button:disabled { opacity: .35; cursor: default; }
.font-controls span { min-width: 48px; text-align: center; font-size: 13px; }

.practice-progress { color: var(--muted); font-size: calc(13px * var(--font-scale, 1)); margin-bottom: 8px; }
.practice-header { color: var(--muted); font-size: calc(14px * var(--font-scale, 1)); line-height: 1.6; margin-bottom: 14px; }
.practice-question { font-size: calc(20px * var(--font-scale, 1)); line-height: 1.55; font-weight: 500; margin-bottom: 18px; }
.practice-options { display: grid; gap: 9px; }
.option-button {
  width: 100%;
  border: 0;
  border-radius: 16px;
  background: #e4e5ee;
  padding: 13px 14px;
  text-align: left;
  line-height: 1.5;
  font-size: calc(15px * var(--font-scale, 1));
  cursor: pointer;
}
.option-button.selected { background: #dfe4ff; outline: 2px solid #9fa8e6; }
.option-button.correct { background: var(--ok); outline: 2px solid #7fbd8d; }
.option-button.wrong { background: var(--bad); outline: 2px solid #d58c98; }
.option-button:disabled { color: inherit; cursor: default; opacity: 1; }

.answer-feedback {
  margin-top: 14px;
  border-radius: 16px;
  padding: 13px 14px;
  line-height: 1.55;
  font-size: calc(14px * var(--font-scale, 1));
}
.answer-feedback.correct { background: var(--ok); }
.answer-feedback.wrong { background: var(--bad); }
.info-block {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: calc(14px * var(--font-scale, 1));
  line-height: 1.6;
}
.info-title { font-weight: 700; margin-bottom: 4px; }

.practice-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}
.action-button {
  border: 0;
  border-radius: 15px;
  padding: 13px 12px;
  background: #e5e5ed;
  cursor: pointer;
}
.action-button.primary { background: #dfe3f7; font-weight: 700; }
.action-button.danger { background: #f6e3e6; }
.action-button:disabled { opacity: .4; cursor: default; }
.action-wide { grid-column: 1 / -1; }

.favorite-toggle {
  border: 0;
  background: transparent;
  padding: 6px 0;
  margin: 4px 0 8px;
  cursor: pointer;
  font-size: calc(14px * var(--font-scale, 1));
}

.search-box {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  outline: none;
  font-size: 16px;
}
.search-box:focus { border-color: #9ca4d9; box-shadow: 0 0 0 3px #e9ebff; }
.search-summary { color: var(--muted); font-size: 13px; margin: 10px 2px; }
.search-results { display: grid; gap: 9px; }
.search-result {
  border: 0;
  border-radius: 15px;
  background: var(--surface);
  padding: 13px 14px;
  text-align: left;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.search-result-meta { color: var(--muted); font-size: 12px; margin-bottom: 5px; }
.search-result-q { font-size: 14px; line-height: 1.45; }

.mock-header-card {
  background: var(--hero);
  border-radius: 20px;
  padding: 16px;
  margin-bottom: 12px;
}
.mock-header-title { font-size: 17px; font-weight: 700; }
.mock-header-meta { margin-top: 6px; font-size: 13px; color: var(--muted); }
.mock-top-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.mock-time { font-variant-numeric: tabular-nums; }
.mock-submit { border: 1px solid #bfc1d0; border-radius: 14px; background: transparent; padding: 8px 12px; cursor: pointer; }

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 12px 0;
}
.result-card { background: var(--surface); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); }
.result-label { font-size: 12px; color: var(--muted); }
.result-value { margin-top: 5px; font-size: 21px; font-weight: 700; }

.review-answer-line { margin: 9px 0; font-size: calc(15px * var(--font-scale, 1)); line-height: 1.5; }
.review-options { display: grid; gap: 8px; margin-top: 14px; }
.review-option { border-radius: 15px; background: #e4e5ee; padding: 12px 14px; line-height: 1.45; font-size: calc(14px * var(--font-scale, 1)); }
.review-option.correct { background: var(--ok); }
.review-option.wrong { background: var(--bad); }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #333746;
  color: white;
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 50;
  box-shadow: var(--shadow);
}

@media (min-width: 720px) {
  #app { padding-top: 28px; }
}
