:root {
  --primary: #3B6EF6;
  --primary-soft: #EEF3FF;
  --bg: #F4F5F9;
  --card: #FFFFFF;
  --text: #1B2030;
  --text-2: #5A627A;
  --text-3: #98A0B3;
  --line: #E8EAF1;
  --correct: #16A34A;
  --correct-soft: #E9F8EF;
  --wrong: #E05252;
  --wrong-soft: #FDECEC;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(27, 32, 48, .05);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

/* ---------- top ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px 10px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .2px;
}

.brand-sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-3);
}

.timer {
  flex: none;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 5px 10px;
  border-radius: 999px;
}

.progress {
  height: 3px;
  background: var(--line);
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--primary);
  transition: width .25s ease;
}

.progress-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 18px 0;
  font-size: 12px;
  color: var(--text-3);
}

/* ---------- views ---------- */
main { flex: 1; padding: 12px 14px 24px; }

.view { display: none; }
.view.active { display: block; }

/* ---------- question card ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px 8px;
}

.q-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.q-tag {
  font-size: 11px;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 6px;
  padding: 2px 7px;
}

.q-no { font-size: 12px; color: var(--text-3); }

.q-stem {
  font-size: 16px;
  line-height: 1.75;
  font-weight: 500;
  letter-spacing: .2px;
  word-break: break-word;
}

.q-items {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  counter-reset: item;
}

.q-items li {
  font-size: 14.5px;
  line-height: 1.8;
  color: var(--text-2);
  padding-left: 4px;
  word-break: break-word;
}

.q-items li + li { margin-top: 2px; }

/* ---------- options ---------- */
.options { margin-top: 14px; }

.option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: #FBFBFD;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
  font-family: inherit;
  transition: border-color .15s, background .15s, transform .1s;
  cursor: pointer;
}

.option:active { transform: scale(.995); }

.option .key {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid #C9CFDE;
  color: var(--text-2);
  font-size: 12px;
  line-height: 20px;
  text-align: center;
  margin-top: 2px;
}

.option .txt { flex: 1; word-break: break-word; }

.option:disabled { cursor: default; }

.option.is-correct {
  border-color: var(--correct);
  background: var(--correct-soft);
}

.option.is-correct .key {
  border-color: var(--correct);
  background: var(--correct);
  color: #fff;
}

.option.is-wrong {
  border-color: var(--wrong);
  background: var(--wrong-soft);
}

.option.is-wrong .key {
  border-color: var(--wrong);
  background: var(--wrong);
  color: #fff;
}

/* ---------- feedback ---------- */
.feedback {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(58px + env(safe-area-inset-bottom));
  width: calc(100% - 24px);
  max-width: 696px;
  z-index: 25;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 -2px 24px rgba(27, 32, 48, .14);
  padding: 14px 16px 16px;
  border-left: 4px solid var(--correct);
  animation: sheet-up .18s ease-out;
}

@keyframes sheet-up {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.feedback.is-wrong { border-left-color: var(--wrong); }

.fb-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.fb-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--correct);
  color: #fff;
  font-size: 12px;
  line-height: 20px;
  text-align: center;
  flex: none;
}

.feedback.is-wrong .fb-icon { background: var(--wrong); }

.fb-title { font-size: 15px; font-weight: 600; }

.fb-answer {
  margin-left: auto;
  font-size: 13px;
  color: var(--text-2);
}

.fb-note {
  margin-top: 8px;
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text-2);
  white-space: pre-wrap;
  word-break: break-word;
}

.btn-primary {
  display: block;
  width: 100%;
  margin-top: 14px;
  border: 0;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-size: 15px;
  font-family: inherit;
  padding: 12px;
  cursor: pointer;
}

.btn-primary:active { opacity: .9; }

/* ---------- done ---------- */
.done {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 20px;
  text-align: center;
}

.done h2 { font-size: 18px; margin: 0 0 8px; }
.done p { color: var(--text-2); font-size: 14px; line-height: 1.8; margin: 0; }

/* ---------- wrong book ---------- */
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 6px 4px 12px;
}

.panel-head h2 { font-size: 16px; margin: 0; }
.hint { font-size: 12px; color: var(--text-3); }

.wrong-list { display: flex; flex-direction: column; gap: 10px; }

.wrong-item {
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  cursor: pointer;
}

.wrong-top {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-3);
  margin-bottom: 6px;
}

.streak {
  margin-left: auto;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 999px;
  padding: 1px 8px;
}

.wrong-stem {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.empty {
  text-align: center;
  color: var(--text-3);
  font-size: 13.5px;
  padding: 48px 0;
}

/* ---------- stats ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat {
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.stat .k { font-size: 12px; color: var(--text-3); }
.stat .v {
  margin-top: 6px;
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.stat .v small { font-size: 12px; font-weight: 400; color: var(--text-3); margin-left: 2px; }

.settings { margin-top: 16px; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px;
  font-size: 14px;
}

.switch-row input {
  width: 42px;
  height: 24px;
  appearance: none;
  background: #D6DAE6;
  border-radius: 999px;
  position: relative;
  transition: background .2s;
  cursor: pointer;
}

.switch-row input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform .2s;
}

.switch-row input:checked { background: var(--primary); }
.switch-row input:checked::after { transform: translateX(18px); }

.foot-note {
  margin: 18px 4px 0;
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-3);
}

.btn-ghost {
  display: block;
  width: 100%;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--text-2);
  font-family: inherit;
  font-size: 14px;
  padding: 12px;
  cursor: pointer;
}

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1;
  border: 0;
  background: none;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--text-3);
  padding: 12px 0 11px;
  cursor: pointer;
  position: relative;
}

.tab.active { color: var(--primary); font-weight: 600; }

.tab em {
  position: absolute;
  top: 5px;
  right: 50%;
  transform: translateX(28px);
  font-style: normal;
  font-size: 10px;
  color: #fff;
  background: var(--wrong);
  border-radius: 999px;
  padding: 0 5px;
  line-height: 15px;
}

@media (min-width: 700px) {
  .app { box-shadow: 0 0 0 1px var(--line); background: var(--bg); }
}
