:root {
  --navy: #163f7a;
  --blue: #2f6fce;
  --blue-soft: #eaf2ff;
  --ink: #172033;
  --muted: #68758a;
  --line: #d9e0ea;
  --paper: #ffffff;
  --bg: #f3f6fb;
  --green: #dff3e7;
  --green-ink: #176c3a;
  --red: #fde7e4;
  --red-ink: #a9342e;
  --shadow: 0 8px 24px rgba(24, 45, 82, .08);
  --top: calc(58px + env(safe-area-inset-top));
  --bottom: calc(70px + env(safe-area-inset-bottom));
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; color-scheme: light; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
}
button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.topbar {
  position: fixed;
  z-index: 30;
  inset: 0 0 auto;
  height: var(--top);
  padding: env(safe-area-inset-top) 16px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255,255,255,.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  border: 0;
  padding: 0;
  color: var(--ink);
  background: transparent;
  font-weight: 750;
  font-size: 18px;
}
.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 10px;
  color: #fff;
  background: var(--navy);
}
.network { color: var(--muted); font-size: 13px; }
.network.online::before, .network.offline::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: #36a65f;
}
.network.offline::before { background: #e59c27; }

#app {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(var(--top) + 20px) 16px calc(var(--bottom) + 28px);
  outline: none;
}
.bottom-nav {
  position: fixed;
  z-index: 30;
  inset: auto 0 0;
  height: var(--bottom);
  padding: 7px 10px env(safe-area-inset-bottom);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(255,255,255,.97);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.bottom-nav button {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  min-width: 0;
  border: 0;
  border-radius: 12px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
}
.bottom-nav button span { font-size: 22px; line-height: 1; }
.bottom-nav button.active { color: var(--blue); background: var(--blue-soft); font-weight: 700; }
.bottom-nav.hidden { display: none; }

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(28px, 8vw, 42px); line-height: 1.15; letter-spacing: -.03em; }
h2 { margin-bottom: 12px; font-size: 22px; }
h3 { margin-bottom: 8px; font-size: 17px; }
.eyebrow { margin-bottom: 9px; color: var(--blue); font-size: 13px; font-weight: 800; letter-spacing: .08em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hero { padding: 20px 4px 18px; }
.hero p { max-width: 34rem; line-height: 1.65; }
.stats { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.pill { padding: 7px 11px; border-radius: 999px; color: var(--navy); background: #e7eef9; font-size: 13px; font-weight: 650; }

.card {
  margin-bottom: 14px;
  padding: 20px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.action-card {
  width: 100%;
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  text-align: left;
  color: var(--ink);
}
.action-card:active { transform: scale(.99); background: #f9fbff; }
.action-icon { display: grid; width: 48px; height: 48px; place-items: center; border-radius: 14px; background: var(--blue-soft); color: var(--blue); font-size: 23px; }
.action-card strong { display: block; margin-bottom: 4px; font-size: 18px; }
.action-card small { color: var(--muted); line-height: 1.45; }
.chevron { color: #8a96a8; font-size: 24px; }

.field { margin-bottom: 16px; }
.field label { display: block; margin-bottom: 7px; color: #344055; font-size: 14px; font-weight: 700; }
select, input[type="text"], input[type="search"], textarea {
  width: 100%;
  min-height: 48px;
  border: 1px solid #bfc9d7;
  border-radius: 12px;
  padding: 11px 13px;
  background: #fff;
  color: var(--ink);
  outline: none;
}
textarea { min-height: 108px; resize: vertical; line-height: 1.5; }
select:focus, input:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(47,111,206,.14); }
.primary, .secondary, .danger, .ghost {
  min-height: 46px;
  border: 0;
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 750;
}
.primary { color: white; background: var(--blue); }
.primary:disabled { color: #8190a5; background: #dbe4f1; }
.secondary { color: var(--navy); background: #e8eef7; }
.danger { color: var(--red-ink); background: var(--red); }
.ghost { color: var(--blue); background: transparent; }
.wide { width: 100%; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row > .grow { flex: 1; }

.section-title { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-title h1, .section-title h2 { margin-bottom: 0; }
.empty { padding: 42px 18px; text-align: center; color: var(--muted); }

.practice-shell { padding-bottom: 82px; }
.practice-head {
  position: sticky;
  z-index: 10;
  top: var(--top);
  margin: -20px -16px 14px;
  padding: 12px 16px;
  color: #fff;
  background: var(--navy);
}
.practice-meta { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.progress-track { height: 4px; margin-top: 10px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.25); }
.progress-fill { height: 100%; background: #fff; }
.reading-text, .question-text, .option-text {
  font-family: Georgia, "Times New Roman", "Songti SC", serif;
  font-size: 19px;
  line-height: 1.62;
  user-select: text;
  -webkit-user-select: text;
}
.question-label { display: inline-grid; width: 34px; height: 34px; margin-bottom: 12px; place-items: center; color: white; background: #202124; font-weight: 800; }
.source-line { margin-top: 14px; color: var(--muted); font-family: inherit; font-size: 12px; }
.question-image { display: block; width: 100%; height: auto; margin-top: 16px; border-radius: 10px; }
.option {
  width: 100%;
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 12px;
  align-items: start;
  margin: 10px 0;
  padding: 15px;
  border: 1.5px solid #737b87;
  border-radius: 14px;
  color: var(--ink);
  background: #fff;
  text-align: left;
}
.option.selected { border: 3px solid var(--blue); padding: 13.5px; }
.option.correct { border-color: #2a8850; background: var(--green); }
.option.wrong { border-color: #bd443c; background: var(--red); }
.letter { display: grid; width: 34px; height: 34px; place-items: center; border: 2px solid #3e4249; border-radius: 50%; font-family: Georgia, serif; font-weight: 700; }
.selected .letter { color: white; border-color: var(--blue); background: var(--blue); }
.correct .letter { color: var(--green-ink); border-color: var(--green-ink); background: #fff; }
.wrong .letter { color: var(--red-ink); border-color: var(--red-ink); background: #fff; }
.feedback { border-left: 4px solid var(--blue); }
.feedback.good { border-color: var(--green-ink); background: #f4fbf6; }
.feedback.bad { border-color: var(--red-ink); background: #fff7f6; }
.explanation { white-space: pre-wrap; line-height: 1.6; }
.qa-answer { margin-top: 12px; padding: 12px; border-radius: 10px; background: #edf3fc; line-height: 1.55; white-space: pre-wrap; }
.practice-actions {
  position: fixed;
  z-index: 25;
  inset: auto 0 var(--bottom);
  min-height: 68px;
  padding: 10px max(12px, calc((100vw - 760px) / 2 + 16px));
  display: grid;
  grid-template-columns: 1fr 1.25fr 1fr;
  gap: 8px;
  background: rgba(245,248,252,.97);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.practice-actions button { min-width: 0; padding-inline: 8px; }

.selection-tools {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: calc(var(--bottom) + 78px);
  width: min(calc(100% - 24px), 560px);
  transform: translateX(-50%);
  padding: 11px;
  border-radius: 15px;
  background: #152237;
  color: white;
  box-shadow: 0 14px 40px rgba(0,0,0,.26);
}
.selection-tools .term { overflow: hidden; margin-bottom: 8px; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.selection-tools button { min-height: 40px; color: #fff; background: #2d4567; }

.word { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.word strong { font-size: 18px; }
.word p { margin: 5px 0 0; color: var(--muted); }
.word-actions { display: flex; gap: 5px; }
.word-actions button { padding: 7px 9px; min-height: 36px; }
.search-sticky { position: sticky; z-index: 8; top: calc(var(--top) + 8px); margin-bottom: 14px; }

.bank-row { padding: 16px; }
.bank-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 9px; }
.tag { padding: 4px 7px; border-radius: 6px; color: #48607f; background: #edf2f8; font-size: 12px; }
.bank-row p { margin: 0; line-height: 1.45; }
.bank-row details { margin-top: 10px; }
.bank-row summary { color: var(--blue); }
.bank-options { padding-left: 20px; color: #48566a; font-family: Georgia, serif; line-height: 1.5; }

.review-word { margin: 18px 0 26px; font-family: Georgia, serif; font-size: 36px; }
.review-choice { width: 100%; margin: 7px 0; text-align: left; }
.review-choice.correct { color: var(--green-ink); background: var(--green); }
.review-choice.wrong { color: var(--red-ink); background: var(--red); }

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: calc(var(--bottom) + 18px);
  max-width: calc(100% - 32px);
  transform: translate(-50%, 20px);
  padding: 11px 16px;
  border-radius: 999px;
  color: #fff;
  background: rgba(21,34,55,.94);
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.modal {
  position: fixed;
  z-index: 80;
  inset: 0;
  display: grid;
  align-items: end;
  background: rgba(14,23,38,.52);
}
.sheet {
  max-height: 90vh;
  overflow: auto;
  padding: 20px 16px calc(24px + env(safe-area-inset-bottom));
  border-radius: 22px 22px 0 0;
  background: #fff;
}
.sheet-handle { width: 40px; height: 4px; margin: -8px auto 18px; border-radius: 99px; background: #c9d0da; }

@media (min-width: 760px) {
  #app { padding-inline: 24px; }
  .home-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
  .home-grid .card { margin: 0; }
  .practice-shell { width: min(100%, 980px); }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
