:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafd;
  --primary: #173a64;
  --primary-hover: #102a49;
  --primary-soft: #e8f0fa;
  --accent: #2563eb;
  --text: #162235;
  --muted: #617187;
  --border: #dfe6f0;
  --ok: #147a3f;
  --ok-bg: #e7f7ed;
  --ok-border: #a7dfc0;
  --warn: #9a5b08;
  --warn-bg: #fef4e2;
  --warn-border: #f5d491;
  --err: #b42318;
  --err-bg: #fdeceb;
  --err-border: #f5b9b4;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 6px 24px rgba(23, 58, 100, 0.06);
}

* {
  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, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.55;
  min-height: 100dvh;
}

button, input, select {
  font-family: inherit;
}

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

.loading-state {
  text-align: center;
  color: var(--muted);
  padding: 64px 16px;
  font-size: 15px;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.4px;
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Desktop inline nav inside topbar */
.desktop-nav {
  display: none;
  gap: 6px;
}

@media (min-width: 680px) {
  .app-shell {
    padding: 22px 24px 48px;
  }
  .desktop-nav {
    display: flex;
  }
  .bottom-nav {
    display: none !important;
  }
}

.nav-pill {
  padding: 7px 13px;
  border-radius: 999px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
}

.nav-pill.active {
  background: var(--primary-soft);
  color: var(--primary);
}

/* Bottom mobile nav */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  z-index: 40;
}

.bottom-nav a {
  text-decoration: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 10px;
}

.bottom-nav a.active {
  color: var(--primary);
  background: var(--primary-soft);
}

/* Cards & layout */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.card-title {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 12px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-num {
  font-size: 26px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.15;
}

.stat-num.warn { color: var(--warn); }
.stat-num.accent { color: var(--accent); }

.stat-label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

/* Controls */
.section-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  margin: 0 0 8px;
}

.pill-group {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.choice-btn {
  min-height: 46px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.choice-btn.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.choice-sub {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.choice-btn.active .choice-sub {
  color: var(--primary);
}

.count-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 18px;
}

.count-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.count-pill {
  min-width: 42px;
  min-height: 38px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.count-pill.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

/* Primary & Secondary buttons */
.btn {
  appearance: none;
  border: none;
  border-radius: 12px;
  min-height: 48px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s, transform 0.06s;
}

.btn:active {
  transform: scale(0.99);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  width: 100%;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  min-height: 52px;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface-soft);
  color: var(--primary);
  border: 1px solid var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  min-height: 38px;
  padding: 6px 12px;
  font-size: 13px;
}

.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 10px;
}

/* Banners & badges */
.banner {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.banner.warn {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn);
}

.banner.ok {
  background: var(--ok-bg);
  border-color: var(--ok-border);
  color: var(--ok);
}

.banner.err {
  background: var(--err-bg);
  border-color: var(--err-border);
  color: var(--err);
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.tag.known { background: var(--ok-bg); color: var(--ok); }
.tag.fuzzy { background: var(--warn-bg); color: var(--warn); }
.tag.forgot { background: var(--err-bg); color: var(--err); }
.tag.spell_wrong { background: var(--err-bg); color: var(--err); }
.tag.new { background: var(--primary-soft); color: var(--primary); }

/* Quiz page */
.quiz-shell {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.progress-track {
  height: 7px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 14px;
}

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

.quiz-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.word-stage {
  text-align: center;
  padding: 12px 0 18px;
}

.word-main-row {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.word-big {
  font-size: 36px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.4px;
  line-height: 1.15;
  margin: 0;
}

.speak-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 40px;
  min-height: 40px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.speak-btn:hover {
  border-color: var(--primary);
}

.word-meta {
  margin-top: 8px;
  font-size: 15px;
  color: var(--muted);
}

.reveal-box {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px dashed var(--border);
  text-align: left;
}

.def-row {
  margin-bottom: 10px;
  font-size: 15px;
}

.def-label {
  display: inline-block;
  min-width: 34px;
  font-weight: 700;
  color: var(--primary);
}

.context-box {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
}

.cloze-prompt {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 16px;
  text-align: center;
  margin: 8px 0 14px;
}

.spell-input {
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  background: #fff;
  outline: none;
}

.spell-input:focus {
  border-color: var(--primary);
}

.quiz-footer {
  margin-top: auto;
  padding-top: 8px;
}

.rate-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.rate-btn {
  min-height: 54px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  border: 1.5px solid;
}

.rate-btn.known {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: var(--ok-border);
}

.rate-btn.fuzzy {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: var(--warn-border);
}

.rate-btn.forgot {
  background: var(--err-bg);
  color: var(--err);
  border-color: var(--err-border);
}

/* Review & Library lists */
.list-item {
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
}

.list-item:last-child {
  border-bottom: none;
  padding-bottom: 4px;
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.list-word {
  font-size: 18px;
  font-weight: 800;
  color: var(--primary);
}

.search-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.text-input {
  flex: 1;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border-radius: 11px;
  border: 1.5px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: 14px;
}

.text-input:focus {
  outline: none;
  border-color: var(--primary);
}

.login-wrap {
  max-width: 400px;
  margin: 48px auto;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.occurrences-list {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.occ-chip {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  color: var(--muted);
}