:root {
  --green: #58cc02;
  --green-dark: #46a302;
  --blue: #1cb0f6;
  --red: #ff4b4b;
  --orange: #ff9600;
  --ink: #3c3c3c;
  --muted: #777;
  --line: #e5e5e5;
  --bg: #fff;
  --card: #f7f7f7;
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
}

#app { max-width: 520px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 18px 10px;
  border-bottom: 2px solid var(--line);
  background: #fff;
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 800; font-size: 20px; color: var(--green-dark); display: flex; align-items: center; gap: 8px; }
.brand-dot { width: 12px; height: 12px; background: var(--green); border-radius: 4px; display: inline-block; }
#topbar-right { font-size: 13px; color: var(--muted); }

#view { flex: 1; padding: 18px 18px 96px; }

#bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 520px;
  display: flex; background: #fff; border-top: 2px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); z-index: 10;
}
.nav-item {
  flex: 1; background: none; border: 0; padding: 10px 0 8px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: #999; font-size: 11px; font-weight: 700; cursor: pointer;
}
.nav-item.active { color: var(--green-dark); }
.nav-icon { font-size: 22px; line-height: 1; }

h1 { font-size: 24px; margin: 0 0 4px; font-weight: 800; }
h2 { font-size: 18px; margin: 22px 0 10px; font-weight: 800; }
p.sub { color: var(--muted); margin: 0 0 18px; font-size: 14px; line-height: 1.5; }

.card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
}
.card.white { background: #fff; border: 2px solid var(--line); }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 16px 0 22px; }
.stat { background: var(--card); border-radius: 14px; padding: 14px 8px; text-align: center; }
.stat b { display: block; font-size: 24px; line-height: 1.2; }
.stat span { font-size: 11px; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 14px; padding: 14px 18px;
  font-size: 15px; font-weight: 800; cursor: pointer;
  background: var(--green); color: #fff; width: 100%;
  box-shadow: 0 4px 0 var(--green-dark); transition: transform .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--green-dark); }
.btn[disabled] { opacity: .5; box-shadow: none; cursor: not-allowed; }
.btn.blue { background: var(--blue); box-shadow: 0 4px 0 #0a8cc7; }
.btn.red { background: var(--red); box-shadow: 0 4px 0 #cf3434; }
.btn.ghost { background: #fff; color: var(--muted); border: 2px solid var(--line); box-shadow: none; }
.btn.small { width: auto; padding: 9px 14px; font-size: 13px; border-radius: 10px; }
.btn.confirming { background: var(--red) !important; color: #fff !important; box-shadow: none !important; border-color: var(--red) !important; }

.progress-track { height: 12px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 10px 0 24px; }
.progress-fill { height: 100%; background: var(--green); border-radius: 99px; transition: width .3s; }

.tag { display: inline-block; font-size: 11px; font-weight: 800; padding: 3px 8px; border-radius: 99px; }
.tag.green { background: #e5f9d0; color: var(--green-dark); }
.tag.blue { background: #dcf3ff; color: #0879ae; }
.tag.red { background: #ffe5e5; color: #cc3232; }
.tag.gray { background: #eee; color: #888; }

.unit-item { padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.unit-item:last-child { border-bottom: 0; }

.quiz-meta { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.question-box { background: #fff; border: 2px solid var(--line); border-radius: var(--radius); padding: 20px 16px; margin: 12px 0 18px; min-height: 130px; }
.question-text { font-size: 19px; font-weight: 700; line-height: 1.55; white-space: pre-wrap; }
.question-box.fill .question-text { font-size: 17px; }

.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  text-align: left; background: #fff; border: 2px solid var(--line); border-radius: 12px;
  padding: 13px 14px; font-size: 14px; line-height: 1.45; color: var(--ink); cursor: pointer;
  font-family: inherit;
}
.option:active { background: #fafafa; }
.option.selected { border-color: var(--blue); background: #eaf7ff; }
.option.correct { border-color: var(--green); background: #f0ffe4; }
.option.wrong { border-color: var(--red); background: #fff0f0; }
.option.locked { cursor: default; }

/* 答案与解析 */
.review-box { background: var(--card); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.review-list { margin-top: 8px; display: flex; flex-direction: column; gap: 7px; }
.review-item { font-size: 14px; line-height: 1.45; padding: 8px 10px; border-radius: 9px; background: #fff; border: 1px solid var(--line); }
.review-item b { margin-right: 4px; }
.review-item.right { background: #e5f9d0; border-color: #58cc02; color: #376300; }
.review-item.wrong { background: #ffe5e5; border-color: #ff9600; color: #a32020; }
.review-tag { float: right; font-size: 12px; font-weight: 800; }
.answer-box { background: #e5f9d0; color: #376300; border-radius: 12px; padding: 14px; margin-bottom: 12px; font-size: 15px; }
.explanation-box { background: var(--card); border-radius: 12px; padding: 16px; margin-bottom: 14px; }
.explanation-text { margin-top: 8px; font-size: 14px; line-height: 1.8; white-space: pre-wrap; word-break: break-word; }
.tag-title { font-weight: 800; font-size: 15px; margin: 16px 0 10px; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-top: 14px; line-height: 1.5; }
.check-row input { width: 18px; height: 18px; flex: none; }
.stat.warn b { color: var(--red); }
.stat.ok b { color: var(--green-dark); }

.answer-input {
  width: 100%; border: 2px solid var(--line); border-radius: 12px;
  padding: 14px; font-size: 16px; font-family: inherit; outline: none;
}
.answer-input:focus { border-color: var(--blue); }
.hint-line { font-size: 13px; color: var(--orange); margin: 8px 0 0; }

/* 连线题 */
.match-area { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.match-col { display: flex; flex-direction: column; gap: 8px; }
.match-col-title { font-size: 11px; font-weight: 800; color: var(--muted); text-align: center; margin-bottom: 2px; }
.match-item {
  border: 2px solid var(--line); border-radius: 10px; padding: 10px;
  font-size: 13px; line-height: 1.4; cursor: pointer; background: #fff; font-family: inherit;
  min-height: 44px;
}
.match-item.selected { border-color: var(--blue); background: #eaf7ff; }
.match-item.paired { border-color: var(--green); background: #f0ffe4; }
.match-item.wrong-pair { border-color: var(--red); background: #fff0f0; }
.match-item.locked { cursor: default; }
.match-number {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 50%; background: var(--blue); color: #fff;
  font-size: 11px; font-weight: 800; margin-right: 6px;
}

.feedback { border-radius: 14px; padding: 14px; margin: 12px 0; font-size: 14px; line-height: 1.5; }
.feedback.ok { background: #e5f9d0; color: #376300; }
.feedback.no { background: #ffe5e5; color: #a32020; }
.feedback b { display: block; margin-bottom: 4px; font-size: 16px; }

.rating-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.rating { border: 2px solid var(--line); background: #fff; border-radius: 12px; padding: 10px 2px; cursor: pointer; font-family: inherit; }
.rating b { display: block; font-size: 13px; }
.rating span { font-size: 10px; color: var(--muted); }
.rating.r1 { border-color: #ffb3b3; color: #cc3232; }
.rating.r2 { border-color: #ffd699; color: #b36b00; }
.rating.r3 { border-color: #a6e5ff; color: #0879ae; }
.rating.r4 { border-color: #b9eda0; color: var(--green-dark); }

.drop-zone {
  display: block;
  border: 2px dashed #b9d9a0; border-radius: var(--radius);
  padding: 30px 16px; text-align: center; background: #f9fff4; cursor: pointer;
}
.drop-zone.drag { background: #efffdc; }
.drop-icon { font-size: 40px; display: block; margin-bottom: 8px; }
input[type=file] { display: none; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 6px; }
.field input[type=number], .field input[type=text], .field input[type=password], .field select {
  width: 100%; padding: 12px; border: 2px solid var(--line); border-radius: 10px;
  font-size: 15px; font-family: inherit; outline: none;
}
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; }
.switch { width: 48px; height: 28px; border-radius: 99px; background: #ccc; position: relative; cursor: pointer; border: 0; flex: none; }
.switch.on { background: var(--green); }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left .2s; }
.switch.on::after { left: 23px; }

.empty { text-align: center; color: var(--muted); padding: 46px 20px; font-size: 14px; line-height: 1.7; }
.empty .big { font-size: 44px; display: block; margin-bottom: 10px; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: #333; color: #fff; padding: 11px 18px; border-radius: 99px;
  font-size: 13px; z-index: 99; max-width: 90%; text-align: center;
}
.big-result { text-align: center; padding: 28px 10px; }
.big-result .score { font-size: 52px; font-weight: 900; color: var(--green-dark); }
.muted { color: var(--muted); font-size: 13px; }
.small-note { font-size: 12px; color: var(--muted); line-height: 1.6; margin-top: 8px; }

.cat-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 14px 0; }
.cat-chip { border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 700; cursor: pointer; color: var(--muted); font-family: inherit; }
.cat-chip.active { background: var(--green); border-color: var(--green-dark); color: #fff; }
.cat-manage { border: 2px dashed var(--line); background: transparent; border-radius: 999px; padding: 7px 12px; font-size: 13px; cursor: pointer; color: var(--muted); font-family: inherit; }
.cat-manage:hover { border-color: var(--green); color: var(--green-dark); }

.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 62vh; }
.login-wrap .card { width: 100%; max-width: 380px; padding: 26px 22px; }
.login-logo { font-size: 30px; font-weight: 900; color: var(--green-dark); margin-bottom: 12px; }
.login-wrap .btn { height: 44px; }
