/* ---------- Reset & Variables ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --text: #2a2a2a;
  --muted: #6b6b6b;
  --accent: #c0392b;        /* đỏ truyền thống Trung Hoa */
  --accent-dark: #962d22;
  --border: #e5e0d8;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a1a;
    --surface: #252525;
    --text: #f0f0f0;
    --muted: #a0a0a0;
    --border: #3a3a3a;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  }
}

body {
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* Hán tự dùng font có nét bút */
.hanzi, .menu-icon, .flashcard-front, .flashcard-back .word {
  font-family: "Edukai", "Noto Serif TC", "Kaiti TC", "DFKai-SB", serif;
}

/* ---------- Layout ---------- */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.hero {
  text-align: center;
  margin-bottom: 3rem;
}

.hero h1 {
  font-family: "Edukai", "Noto Serif TC", serif;
  font-size: 4rem;
  color: var(--accent);
  letter-spacing: 0.3em;
  margin-bottom: 0.5rem;
}

.subtitle {
  color: var(--muted);
  font-size: 1.1rem;
}

/* ---------- Menu ---------- */
.menu {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-bottom: 3rem;
}

.menu-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  text-align: center;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.menu-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
}

.menu-icon {
  font-size: 3.5rem;
  color: var(--accent);
  margin-bottom: 0.75rem;
  line-height: 1;
}

.menu-card h2 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}

.menu-card p {
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---------- Stats ---------- */
.stats {
  display: flex;
  justify-content: center;
  gap: 3rem;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.stat-item {
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  font-size: 0.85rem;
  color: var(--muted);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  padding: 0.6rem 1.4rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-family: inherit;
  transition: all 0.15s ease;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

/* ---------- Page header (sub pages) ---------- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.page-header h1 {
  font-size: 1.5rem;
  margin: 0;
}

.back-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
}
.back-link:hover { color: var(--accent); }

.progress-indicator {
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-size: 1.1rem;
}

/* ---------- Mode tabs ---------- */
.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.mode-tab {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 0.5rem;
  cursor: pointer;
  text-align: center;
  font-family: inherit;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  align-items: center;
  transition: all 0.15s ease;
}

.mode-tab:hover { border-color: var(--accent); }

.mode-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.mode-icon { font-size: 1.4rem; }
.mode-hint { font-size: 0.75rem; opacity: 0.8; }

/* ---------- Card ---------- */
.flashcard-container { min-height: 450px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
  text-align: center;
}

.card.empty {
  padding: 3rem 2rem;
}

.session-stats {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-top: 1.5rem;
  font-size: 1.1rem;
  color: var(--muted);
}
.session-stats strong {
  color: var(--accent);
  font-size: 1.6rem;
  display: block;
}

/* ---------- Flashcard mặt trước ---------- */
.flashcard-front {
  padding: 2rem 0;
  position: relative;
}

.hanzi.big {
  font-size: 7rem;
  line-height: 1.1;
  color: var(--accent);
  letter-spacing: 0.05em;
}

.speak-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 1.2rem;
  cursor: pointer;
  margin-left: 1rem;
  vertical-align: middle;
  transition: all 0.15s ease;
}
.speak-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.speak-btn.small { width: 30px; height: 30px; font-size: 0.9rem; margin-left: 0.5rem; }

/* Prompts (chế độ recall/cloze) */
.prompt-meaning {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  color: var(--text);
}
.prompt-pinyin {
  font-size: 1.3rem;
  color: var(--muted);
  font-style: italic;
}
.prompt-zhuyin {
  font-size: 1.1rem;
  color: var(--muted);
  margin-top: 0.3rem;
}
.prompt-hint {
  margin-top: 1rem;
  font-size: 0.9rem;
  color: var(--muted);
}

/* Cloze */
.cloze-sentence {
  font-size: 2rem;
  line-height: 1.6;
  margin-bottom: 1rem;
}
.cloze-blank {
  color: var(--accent);
  border-bottom: 3px solid var(--accent);
  padding: 0 0.3em;
  letter-spacing: 0.15em;
}
.cloze-meaning {
  color: var(--muted);
  font-size: 1.05rem;
}

/* ---------- Recall input ---------- */
.recall-input-wrap {
  margin: 1.5rem 0;
}

.recall-input {
  width: 100%;
  max-width: 500px;
  padding: 1rem;
  font-size: 2rem;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: "Edukai", "Noto Serif TC", "Kaiti TC", serif;
}
.recall-input:focus {
  outline: none;
  border-color: var(--accent);
}

.recall-feedback {
  margin-top: 1rem;
  font-size: 1.1rem;
  min-height: 1.5rem;
}
.recall-feedback .ok  { color: #2ecc71; font-weight: 600; }
.recall-feedback .err { color: var(--accent); font-weight: 600; }

/* ---------- Card actions ---------- */
.card-actions {
  margin-top: 1.5rem;
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.card-actions.hidden, .flashcard-back.hidden { display: none; }

kbd {
  display: inline-block;
  padding: 0.1em 0.5em;
  background: rgba(0,0,0,0.1);
  border-radius: 4px;
  font-size: 0.75em;
  margin-left: 0.4em;
  font-family: monospace;
}
@media (prefers-color-scheme: dark) {
  kbd { background: rgba(255,255,255,0.15); }
}

/* ---------- Đáp án (mặt sau) ---------- */
.flashcard-back {
  border-top: 1px dashed var(--border);
  margin-top: 1.5rem;
  padding-top: 1.5rem;
}

.answer-grid {
  display: grid;
  gap: 1rem;
  text-align: left;
  max-width: 600px;
  margin: 0 auto;
}

.answer-hanzi {
  font-size: 3.5rem;
  color: var(--accent);
  text-align: center;
  line-height: 1.1;
}

.answer-readings {
  text-align: center;
  font-size: 1rem;
  color: var(--text);
  line-height: 1.8;
}
.answer-readings .label {
  color: var(--muted);
  margin-right: 0.4em;
  font-size: 0.9rem;
}
.answer-readings .zhuyin {
  font-family: "Noto Sans TC", "PingFang TC", sans-serif;
  letter-spacing: 0.05em;
}

.answer-meaning {
  font-size: 1.4rem;
  text-align: center;
  color: var(--text);
  padding: 0.5rem;
  background: var(--bg);
  border-radius: 6px;
}

.answer-example {
  padding: 0.75rem 1rem;
  background: var(--bg);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
}
.answer-example .hanzi { font-size: 1.4rem; margin-bottom: 0.3rem; }
.example-vi { color: var(--muted); font-size: 0.95rem; font-style: italic; }

.answer-tags {
  display: flex;
  gap: 0.4rem;
  justify-content: center;
  flex-wrap: wrap;
}
.tag {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-size: 0.8rem;
  color: var(--muted);
}

/* ---------- Rating buttons ---------- */
.rating-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-top: 1.5rem;
}

.rating {
  padding: 0.8rem 0.5rem;
  font-weight: 600;
  border: 2px solid var(--border);
  transition: all 0.1s ease;
}
.rating kbd { background: rgba(0,0,0,0.08); }

.rating.again { border-color: #c0392b; color: #c0392b; }
.rating.hard  { border-color: #e67e22; color: #e67e22; }
.rating.good  { border-color: #27ae60; color: #27ae60; }
.rating.easy  { border-color: #3498db; color: #3498db; }

.rating.again:hover { background: #c0392b; color: #fff; }
.rating.hard:hover  { background: #e67e22; color: #fff; }
.rating.good:hover  { background: #27ae60; color: #fff; }
.rating.easy:hover  { background: #3498db; color: #fff; }

/* ---------- Icon button & header right ---------- */
.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text);
  transition: all 0.15s ease;
}
.icon-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal.hidden { display: none; }

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.2rem; margin: 0; }

.setting-row {
  margin-bottom: 1.25rem;
}
.setting-row label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.4rem;
  font-size: 0.95rem;
}
.setting-row select,
.setting-row input[type=range] {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
}
.setting-row input[type=range] {
  padding: 0;
  accent-color: var(--accent);
}
.setting-row .hint {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 0.3rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* ============================================================
   PRACTICE PAGE
   ============================================================ */

.practice-container { min-height: 500px; }

/* ---------- MODE 1: Matching (Ghép từ) ---------- */
.matching-board {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.matching-instructions {
  text-align: center;
  color: var(--muted);
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

.matching-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 2rem;
}

.match-col {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.match-item {
  padding: 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s ease;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}

.match-item.hanzi {
  font-family: "Edukai", "Noto Serif TC", "Kaiti TC", serif;
  font-size: 1.8rem;
  color: var(--accent);
}

.match-item:hover:not(.matched) {
  border-color: var(--accent);
  background: var(--surface);
}

.match-item.selected {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  transform: scale(1.02);
}
.match-item.selected.hanzi { color: #fff; }

.match-item.matched {
  opacity: 0.35;
  pointer-events: none;
  border-color: #27ae60;
  background: rgba(39, 174, 96, 0.08);
}

.match-item.wrong {
  border-color: #e74c3c !important;
  background: rgba(231, 76, 60, 0.12) !important;
  animation: shake 0.4s;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* ---------- MODE 2: Multiple Choice ---------- */
.mc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
  text-align: center;
}

.mc-prompt {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px dashed var(--border);
}

.mc-readings {
  margin-top: 0.75rem;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  color: var(--muted);
}
.mc-readings .zhuyin { font-size: 1.2rem; letter-spacing: 0.05em; }
.mc-readings .pinyin { font-size: 1.1rem; font-style: italic; }

.mc-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.mc-option {
  padding: 1rem 1.25rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 1.05rem;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: all 0.15s ease;
  font-family: inherit;
}

.mc-option:hover:not(:disabled) {
  border-color: var(--accent);
}

.mc-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.85rem;
  flex-shrink: 0;
}

.mc-text { flex: 1; }

.mc-option.correct {
  border-color: #27ae60;
  background: rgba(39, 174, 96, 0.12);
  color: var(--text);
}
.mc-option.correct .mc-key { background: #27ae60; color: #fff; border-color: #27ae60; }

.mc-option.wrong {
  border-color: #e74c3c;
  background: rgba(231, 76, 60, 0.12);
}
.mc-option.wrong .mc-key { background: #e74c3c; color: #fff; border-color: #e74c3c; }

.mc-option.reveal { animation: pulse 0.6s; }
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.mc-feedback {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
}
.mc-feedback .ok  { color: #27ae60; font-size: 1.1rem; }
.mc-feedback .err { color: #e74c3c; font-size: 1.1rem; }
.mc-feedback .hanzi { color: var(--accent); }

.mc-example {
  margin-top: 1rem;
  padding: 0.75rem;
  background: var(--bg);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  font-size: 1.2rem;
  text-align: left;
}
.mc-example-vi {
  margin-top: 0.3rem;
  padding: 0 0.75rem;
  color: var(--muted);
  font-style: italic;
  text-align: left;
  font-size: 0.95rem;
}
.mc-feedback button { margin-top: 1.25rem; }

/* ---------- MODE 3: Cloze ---------- */
.cloze-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
  text-align: center;
}

.recall-input.correct {
  border-color: #27ae60;
  background: rgba(39, 174, 96, 0.08);
}
.recall-input.wrong {
  border-color: #e74c3c;
  background: rgba(231, 76, 60, 0.08);
}

/* ============================================================
   WRITING PAGE (Luyện viết)
   ============================================================ */

.writing-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  position: relative;
}

.writing-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px dashed var(--border);
  flex-wrap: wrap;
}

.writing-meta {
  flex: 1;
  text-align: right;
  font-size: 0.95rem;
  line-height: 1.7;
}
.writing-meta .label {
  color: var(--muted);
  margin-right: 0.4em;
  font-size: 0.85rem;
}
.writing-meta .zhuyin {
  font-family: "Noto Sans TC", "PingFang TC", sans-serif;
  letter-spacing: 0.05em;
}

.char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.char-cell {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  transition: border-color 0.2s ease;
}

.char-cell.done {
  border-color: #27ae60;
  background: rgba(39, 174, 96, 0.08);
}

.char-canvas {
  width: 220px;
  height: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  position: relative;
}

/* Hanzi-writer dùng SVG; bỏ outline mặc định để gọn */
.char-canvas svg { display: block; }

.char-label {
  font-size: 1.5rem;
  color: var(--accent);
  font-family: "Edukai", "Noto Serif TC", serif;
}

.char-stats {
  font-size: 0.82rem;
  color: var(--muted);
  min-height: 1.2em;
}

.char-buttons {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  justify-content: center;
}

.btn.small {
  padding: 0.35rem 0.7rem;
  font-size: 0.82rem;
}

.char-err {
  color: var(--accent);
  padding: 1rem;
  font-size: 0.85rem;
}

.writing-actions {
  display: flex;
  justify-content: center;
  margin-top: 1rem;
}

/* Banner đánh giá sau khi xong */
.writing-grade-banner {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  padding: 0.8rem 1.5rem;
  border-radius: 999px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  animation: slideUp 0.3s ease;
}
.writing-grade-banner small {
  font-weight: 400;
  font-size: 0.8rem;
  opacity: 0.9;
}
.writing-grade-banner .btn {
  background: rgba(255,255,255,0.25);
  color: #fff;
  border-color: rgba(255,255,255,0.4);
  padding: 0.3rem 0.8rem;
  font-size: 0.85rem;
}
.writing-grade-banner .btn:hover {
  background: rgba(255,255,255,0.4);
}
@keyframes slideUp {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* Lookup mode */
.lookup-input-row {
  text-align: center;
  margin-bottom: 1.5rem;
}
.lookup-input-row .recall-input {
  max-width: 320px;
  font-size: 1.6rem;
}

/* ============================================================
   MANAGE PAGE (Quản lý từ vựng)
   ============================================================ */

.manage-page { max-width: 1280px; }

.manage-stats {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.stat-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  color: var(--muted);
}
.stat-pill strong {
  color: var(--accent);
  font-size: 1.1rem;
  margin-right: 0.3em;
}
.stat-pill.warn strong { color: #e67e22; }

/* Controls */
.manage-controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.control-row {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.control-row:last-child { margin-bottom: 0; }

.control-row label {
  font-size: 0.9rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.control-row select {
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
}

.search-input {
  flex: 1;
  min-width: 250px;
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}
.search-input:focus { outline: none; border-color: var(--accent); }

.result-count {
  color: var(--muted);
  font-size: 0.9rem;
}
.result-count strong { color: var(--accent); }

/* Table */
.manage-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  max-height: 70vh;
}

.manage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.manage-table thead {
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
  box-shadow: 0 1px 0 var(--border);
}

.manage-table th {
  text-align: left;
  padding: 0.65rem 0.75rem;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
}

.manage-table td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.manage-table tr:hover td { background: rgba(192, 57, 43, 0.04); }

.hanzi-cell, .simp-cell {
  font-family: "Edukai", "Noto Serif TC", "Kaiti TC", serif;
  font-size: 1.25rem;
  color: var(--accent);
  white-space: nowrap;
}
.simp-cell { color: var(--muted); font-size: 1.1rem; }

.pinyin-cell { font-style: italic; min-width: 100px; }
.zhuyin-cell { letter-spacing: 0.05em; font-size: 0.9rem; min-width: 100px; }

.meaning-cell {
  max-width: 320px;
}
.meaning-en {
  color: var(--muted);
  font-style: italic;
  font-size: 0.82rem;
  margin-top: 0.2rem;
}

.pos-info {
  color: var(--muted);
  font-size: 0.8rem;
  font-style: italic;
}

.deck-cell { white-space: nowrap; }
.deck-cell .tag {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 0.15rem 0.5rem;
  border-radius: 8px;
  font-size: 0.75rem;
  color: var(--muted);
}

.srs-cell {
  font-size: 0.8rem;
  white-space: nowrap;
}
.srs-cell .muted { color: var(--muted); font-size: 0.75rem; }

.actions-cell {
  text-align: right;
  white-space: nowrap;
}
.actions-cell .btn { padding: 0.25rem 0.5rem; font-size: 0.85rem; }

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 8px;
  font-size: 0.7rem;
  margin-left: 0.3rem;
}
.badge.warn { background: rgba(230, 126, 34, 0.15); color: #e67e22; }
.badge.mute { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }

/* Pagination */
.pagination {
  display: flex;
  gap: 0.25rem;
  justify-content: center;
  margin: 1rem 0;
  flex-wrap: wrap;
}

.page-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  min-width: 36px;
}
.page-btn:hover:not(:disabled):not(.active) { border-color: var(--accent); }
.page-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.page-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.page-ellipsis {
  padding: 0.4rem 0.3rem;
  color: var(--muted);
}

/* Tools section */
.manage-tools {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: 1.5rem;
}
.manage-tools .btn { margin-right: 0.5rem; margin-bottom: 0.3rem; }

/* Modal edit form */
.modal-large {
  max-width: 720px;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}
.form-row {
  display: flex;
  flex-direction: column;
}
.form-row.span-2 { grid-column: 1 / -1; }
.form-row label {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
}
.form-row input, .form-row textarea, .form-row select {
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}
.form-row input.hanzi, .form-row textarea.hanzi {
  font-family: "Edukai", "Noto Serif TC", serif;
}
.form-row input:focus, .form-row textarea:focus, .form-row select:focus {
  outline: none;
  border-color: var(--accent);
}
.form-row textarea { resize: vertical; min-height: 50px; }

.modal-header .muted {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 400;
}

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  .hero h1 { font-size: 3rem; }
  .stats { flex-direction: column; gap: 1rem; }
  .mode-tabs { grid-template-columns: 1fr; }
  .hanzi.big { font-size: 5rem; }
  .recall-input { font-size: 1.5rem; }
  .rating-row { grid-template-columns: repeat(2, 1fr); }
  .matching-grid { gap: 0.5rem 0.75rem; }
  .match-item { padding: 0.7rem 0.5rem; font-size: 0.95rem; min-height: 50px; }
  .match-item.hanzi { font-size: 1.4rem; }
  .mc-options { grid-template-columns: 1fr; }
  .writing-meta { text-align: left; }
  .char-canvas { width: 180px; height: 180px; }
  .form-grid { grid-template-columns: 1fr; }
  .manage-table { font-size: 0.8rem; }
  .manage-table th, .manage-table td { padding: 0.4rem 0.5rem; }
  .zhuyin-cell, .pinyin-cell { display: none; }
}

/* ---------- Streak panel (index) ---------- */
.streak-panel {
  display: flex;
  align-items: center;
  gap: 2rem;
  background: linear-gradient(135deg, #fff4e6 0%, #ffe8d1 100%);
  border: 1px solid #f4c789;
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow);
}

@media (prefers-color-scheme: dark) {
  .streak-panel {
    background: linear-gradient(135deg, #3a2a18 0%, #4a3320 100%);
    border-color: #8a5a2a;
  }
}

.streak-panel.quota-completed {
  background: linear-gradient(135deg, #e6f7e9 0%, #d4f0d8 100%);
  border-color: #6fbf73;
}

@media (prefers-color-scheme: dark) {
  .streak-panel.quota-completed {
    background: linear-gradient(135deg, #1f3a22 0%, #294a2d 100%);
    border-color: #4a8a4f;
  }
}

.streak-main {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.streak-flame {
  font-size: 2.5rem;
  line-height: 1;
}

.streak-number {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.streak-sub {
  font-size: 0.85rem;
  color: var(--muted);
}

.streak-quota {
  flex: 1;
  min-width: 200px;
}

.quota-bar {
  height: 10px;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

@media (prefers-color-scheme: dark) {
  .quota-bar { background: rgba(255, 255, 255, 0.1); }
}

.quota-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #f39c12 0%, #e67e22 50%, #c0392b 100%);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.streak-panel.quota-completed .quota-bar-fill {
  background: linear-gradient(90deg, #6fbf73 0%, #27ae60 100%);
}

.quota-label {
  font-size: 0.95rem;
  color: var(--text);
}

/* Quota indicator trên Practice/Writing header */
.quota-indicator {
  background: rgba(243, 156, 18, 0.12);
  border: 1px solid rgba(243, 156, 18, 0.4);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-size: 0.85rem;
  color: var(--text);
  white-space: nowrap;
}

.quota-indicator.quota-done {
  background: rgba(39, 174, 96, 0.12);
  border-color: rgba(39, 174, 96, 0.5);
}

/* Streak banner — pop-up khi vừa đạt mục tiêu */
.streak-banner {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--surface);
  border: 1px solid #f4c789;
  border-left: 4px solid #e67e22;
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  padding: 1rem 1.25rem;
  z-index: 1000;
  animation: streakSlideIn 0.4s ease;
  max-width: 360px;
}

@keyframes streakSlideIn {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

.streak-banner-content {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.streak-banner-emoji {
  font-size: 2rem;
  line-height: 1;
}

.streak-banner-title {
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.streak-banner-sub {
  font-size: 0.85rem;
  color: var(--muted);
}

@media (max-width: 600px) {
  .streak-panel { flex-direction: column; align-items: stretch; gap: 1rem; }
  .streak-banner { left: 1rem; right: 1rem; bottom: 1rem; max-width: none; }
  .quota-indicator { font-size: 0.75rem; padding: 0.25rem 0.5rem; }
}

