:root {
  --bg: #f4f5fb;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --line: #e6e8f0;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --correct-bg: #e8f8ef;
  --correct-line: #12b76a;
  --correct-text: #05603a;
  --shadow: 0 10px 30px rgba(23, 27, 48, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c;
    --card: #1b1e28;
    --text: #e9ebf3;
    --muted: #9aa1b1;
    --line: #2a2e3d;
    --accent: #8b87ff;
    --accent-soft: #262a45;
    --correct-bg: #10331f;
    --correct-line: #37d07f;
    --correct-text: #9ff0bf;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 10px) 14px 0;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand strong { font-size: 15px; letter-spacing: .2px; }
.brand span { font-size: 11px; color: var(--muted); }

.switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  flex: none;
}
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  transition: background .18s ease;
}
.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .18s ease;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(16px); }
.switch-label { white-space: nowrap; }

.tabs {
  display: flex;
  gap: 6px;
  padding: 10px 0 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.tab[aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.progress { height: 2px; background: transparent; }
.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
  transition: width .2s ease;
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 14px 18px;
}

.crumb {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--muted);
}

.jump { display: flex; align-items: center; gap: 6px; margin: 0; }
.jump input {
  width: 84px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: 13px;
}
.jump button {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.card {
  flex: 1;
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px 16px 16px;
  min-height: 320px;
}

.stem {
  margin: 0 0 14px;
  font-size: 16.5px;
  line-height: 1.7;
  font-weight: 600;
}

.stem .qno { color: var(--accent); margin-right: 4px; }

.options {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.options li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 15px;
  line-height: 1.6;
  transition: background .15s ease, border-color .15s ease;
}

.options li .key {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}

.options li.correct {
  background: var(--correct-bg);
  border-color: var(--correct-line);
}
.options li.correct .key { background: var(--correct-line); color: #fff; }
.options li.correct .text { color: var(--correct-text); font-weight: 600; }

.answer {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}
.answer strong { color: var(--accent); }

.hint {
  margin: 14px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.bottombar {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 10px;
  padding: 10px 14px calc(env(safe-area-inset-bottom) + 10px);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--line);
}

.btn {
  flex: 1;
  min-height: 46px;
  border-radius: 12px;
  border: 1px solid var(--line);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s ease, transform .05s ease;
}
.btn:active { transform: translateY(1px); }
.btn.ghost { background: var(--card); color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; flex: 1.3; }
.btn:disabled { opacity: .4; cursor: default; }

@media (min-width: 560px) {
  .stem { font-size: 17.5px; }
  .options li { font-size: 15.5px; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%);
  background: rgba(20, 22, 34, .92);
  color: #fff;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 999px;
  opacity: 0;
  transition: opacity .2s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; }
