:root {
  --bg: #f5f2ec;
  --card: #ffffff;
  --ink: #241f1b;
  --muted: #7c736a;
  --line: #e7e1d6;
  --accent: #c0392b;
  --accent-dark: #a52f22;
  --accent-soft: #fbe9e6;
  --ink-btn: #2c2a28;
  --ok: #2f855a;
  --ok-soft: #e6f3ec;
  --bad: #c0392b;
  --bad-soft: #fbe9e6;
  --gold: #c9a227;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 6px 24px rgba(40, 30, 20, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
}

.app {
  max-width: 620px;
  margin: 0 auto;
  padding: 18px 16px 56px;
  min-height: 100vh;
}

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease, border-color 0.15s ease,
    opacity 0.15s ease;
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--ink-btn);
  color: #fff;
  border-color: var(--ink-btn);
}
.btn-accent {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-accent:hover:not(:disabled) {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.btn-ghost:hover:not(:disabled) {
  color: var(--ink);
  background: rgba(0, 0, 0, 0.045);
}
.btn-sm {
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 10px;
}
.btn-block {
  width: 100%;
}

/* ---------- Header / brand ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.app-header.compact {
  margin-bottom: 20px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  border-radius: 14px;
  font-size: 26px;
  box-shadow: var(--shadow);
}
h1 {
  font-size: 20px;
  margin: 0;
}
h2 {
  font-size: 18px;
  margin: 0;
}
.head-title {
  flex: 1;
  text-align: center;
}
.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}
.pill {
  font-size: 12px;
  font-weight: 700;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 5px 12px;
  white-space: nowrap;
}
.pill-ghost {
  font-weight: 500;
  color: var(--muted);
}

/* ---------- Stats ---------- */
.stats {
  display: flex;
  gap: 8px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  text-align: center;
  min-width: 64px;
}
.stat-num {
  display: block;
  font-size: 18px;
  font-weight: 700;
}
.stat-label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 6px 0 14px;
}
.toolbar-actions {
  display: flex;
  gap: 6px;
}
.sel-count {
  font-size: 13px;
  color: var(--muted);
}

/* ---------- Categories ---------- */
.categories {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.category {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.category summary {
  list-style: none;
  cursor: pointer;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.category summary::-webkit-details-marker {
  display: none;
}
.cat-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.cat-title::before {
  content: "▸";
  color: var(--muted);
  font-size: 12px;
  transition: transform 0.15s ease;
}
.category[open] .cat-title::before {
  transform: rotate(90deg);
}
.cat-name {
  font-weight: 700;
  font-size: 16px;
}
.cat-hanzi {
  color: var(--muted);
  font-size: 14px;
}
.cat-meta {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.subcats {
  list-style: none;
  margin: 0;
  padding: 0 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.subcat {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.12s ease;
}
.subcat:hover {
  background: #faf7f2;
}
.subcat input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  flex: none;
}
.subcat-name {
  flex: 1;
  font-size: 15px;
}
.subcat-hanzi {
  color: var(--muted);
  font-size: 13px;
}
.subcat-count {
  font-size: 12px;
  color: var(--muted);
  background: #f1ece3;
  border-radius: 20px;
  padding: 2px 9px;
}

.home-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}
.home-actions .btn {
  flex: 1;
  padding: 15px;
  font-size: 16px;
}
.home-actions .btn-wide {
  flex: 1 0 100%;
}
.foot-hint {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin-top: 14px;
}

/* ---------- Study / flashcards ---------- */
.flashcard {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 34px 22px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.flash-hanzi {
  font-size: 84px;
  line-height: 1.1;
  font-weight: 600;
}
.flash-pinyin {
  font-size: 22px;
  color: var(--accent);
  font-weight: 600;
  transition: opacity 0.15s ease;
}
.flash-pinyin.is-hidden {
  color: #d8d1c6;
  letter-spacing: 4px;
}
.flash-english {
  font-size: 20px;
  font-weight: 600;
  color: var(--ink);
}
.btn-play {
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-color: transparent;
  border-radius: 24px;
  padding: 10px 20px;
}
.btn-play-lg {
  font-size: 18px;
  padding: 16px 34px;
  margin: 8px auto;
  border-radius: 30px;
}
.study-nav {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}
.study-nav .btn {
  flex: 1;
}
.quiz-pinyin {
  font-size: 20px;
  color: var(--accent);
  font-weight: 600;
  margin-top: 4px;
}

/* ---------- Words in sentences ---------- */
.sentence-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px 22px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.sentence-hanzi {
  font-size: 34px;
  line-height: 1.5;
  font-weight: 600;
}
.sentence-hanzi .hit {
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-radius: 6px;
  padding: 0 3px;
}
.sentence-pinyin {
  font-size: 18px;
  color: var(--accent);
  font-weight: 600;
}
.sentence-pinyin.is-hidden {
  color: #d8d1c6;
  letter-spacing: 4px;
}
.sentence-english {
  font-size: 16px;
  color: var(--ink);
  max-width: 46ch;
}
.sentence-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 6px;
}
.sentence-word {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-top: 14px;
  padding: 12px 16px;
}
.sw-hanzi {
  font-size: 26px;
  font-weight: 600;
}
.sw-pinyin {
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
}
.sw-english {
  color: var(--muted);
  font-size: 14px;
}
.sentence-word .btn {
  margin-left: auto;
}

/* ---------- Quiz setup ---------- */
.setup {
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.field-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 10px;
}
.mode-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.mode-card {
  text-align: left;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.mode-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.mode-icon {
  font-size: 26px;
  line-height: 1;
  margin-bottom: 4px;
}
.mode-title {
  font-weight: 700;
  font-size: 15px;
}
.mode-desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.chip.active {
  background: var(--ink-btn);
  color: #fff;
  border-color: var(--ink-btn);
}
.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
}
.switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

/* ---------- Quiz card ---------- */
.quiz-head {
  gap: 12px;
}
.bar {
  flex: 1;
  height: 8px;
  background: var(--line);
  border-radius: 20px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 20px;
  transition: width 0.25s ease;
}
.quiz-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 22px;
  text-align: center;
}
.prompt-label {
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 14px;
}
.quiz-hanzi {
  font-size: 88px;
  line-height: 1.1;
  font-weight: 600;
  margin-bottom: 6px;
}
.answer-form {
  display: flex;
  gap: 8px;
  margin-top: 22px;
}
.answer-form input {
  flex: 1;
  font-size: 16px;
  padding: 13px 16px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fbf9f5;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s ease;
}
.answer-form input:focus {
  border-color: var(--accent);
  background: #fff;
}
.answer-form input:disabled {
  color: var(--muted);
}
.options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}
.option {
  background: #fbf9f5;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 15px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}
.option:hover:not(:disabled) {
  border-color: var(--accent);
}
.option:disabled {
  cursor: default;
}
.option.is-correct {
  background: var(--ok-soft);
  border-color: var(--ok);
  color: var(--ok);
}
.option.is-wrong {
  background: var(--bad-soft);
  border-color: var(--bad);
  color: var(--bad);
}
.option.is-dim {
  opacity: 0.5;
}

/* ---------- Feedback ---------- */
.feedback {
  margin-top: 22px;
  border-radius: 14px;
  padding: 16px;
  border: 1px solid transparent;
}
.feedback.is-ok {
  background: var(--ok-soft);
  border-color: #bfe0cd;
}
.feedback.is-bad {
  background: var(--bad-soft);
  border-color: #f0c9c3;
}
.feedback-title {
  font-weight: 800;
  font-size: 16px;
  margin-bottom: 8px;
}
.feedback.is-ok .feedback-title {
  color: var(--ok);
}
.feedback.is-bad .feedback-title {
  color: var(--bad);
}
.feedback-word {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
}
.fb-hanzi {
  font-size: 30px;
  font-weight: 600;
}
.fb-pinyin {
  color: var(--accent);
  font-weight: 600;
}
.fb-english {
  color: var(--ink);
  font-weight: 600;
}
.feedback-given {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}
.feedback .btn {
  margin-top: 10px;
}

/* ---------- Results ---------- */
.results {
  text-align: center;
}
.results-score {
  font-size: 64px;
  font-weight: 800;
  line-height: 1;
  margin-top: 8px;
}
.results-of {
  font-size: 30px;
  color: var(--muted);
  font-weight: 700;
}
.results-pct {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  margin-top: 4px;
}
.results-msg {
  color: var(--muted);
  margin: 8px 0 22px;
}
.review {
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 18px;
}
.review h3 {
  margin: 0 0 10px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.review ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.review li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.review li:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
.rv-hanzi {
  font-size: 24px;
  font-weight: 600;
}
.rv-pinyin {
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
}
.rv-english {
  color: var(--muted);
  font-size: 14px;
}
.results-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- Empty / loading / error ---------- */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty h2 {
  color: var(--ink);
  margin-bottom: 8px;
}
.empty .btn {
  margin-top: 16px;
}
.empty code {
  background: #ece6db;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 13px;
}
.loading {
  text-align: center;
  color: var(--muted);
  padding: 80px 20px;
}
noscript {
  display: block;
  text-align: center;
  padding: 20px;
}

/* ---------- Small screens ---------- */
@media (max-width: 430px) {
  .app {
    padding: 14px 12px 40px;
  }
  .flash-hanzi {
    font-size: 72px;
  }
  .quiz-hanzi {
    font-size: 72px;
  }
  .sentence-hanzi {
    font-size: 28px;
  }
  .mode-cards {
    grid-template-columns: 1fr;
  }
  .stats {
    gap: 6px;
  }
  .stat {
    min-width: 54px;
    padding: 6px 8px;
  }
  .cat-hanzi,
  .subcat-hanzi {
    display: none;
  }
}



