/*
  Giao diện sáng, lấy tông từ ảnh minh hoạ nét vẽ tay (nền đào nhạt, chữ xanh dương).
  Quy tắc bo góc: thẻ/panel 18px, nút/ô nhập/đáp án/ô chủ đề 12px, chip và tag dạng viên thuốc.
  Một màu nhấn duy nhất: xanh dương. Xanh lá và đỏ chỉ dùng cho đúng/sai.
*/
:root {
  --paper: #fbf0e0;
  --paper-2: #f5e6cf;
  --surface: #fffdf8;
  --line: #ead9c0;
  --line-strong: #d6bf9f;

  --ink: #1c2531;
  --muted: #5d6877;

  --accent: #0f6fae;
  --accent-ink: #0b5a90;
  --accent-soft: #e0eef8;
  --on-accent: #fffdf8;

  --ok: #27793a;
  --ok-soft: #e5f2e2;
  --ok-line: #8cc79a;
  --bad: #b4313c;
  --bad-soft: #fbe4e1;
  --bad-line: #e49a9f;

  --c-mastered: #3ba445;
  --c-learned: #1481c6;
  --c-wrong: #ef555f;
  --c-new: #e3d3ba;

  --shadow: 0 1px 2px rgba(110, 70, 20, .06), 0 10px 28px rgba(110, 70, 20, .07);
  --r-card: 18px;
  --r-ctl: 12px;
  --ease: cubic-bezier(.16, 1, .3, 1);

  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ph, .ph-fill { line-height: 1; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  height: 64px; padding: 0 max(20px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand i { font-size: 24px; color: var(--accent); }
.nav { display: flex; gap: 24px; margin-left: 12px; height: 100%; }
.nav a {
  display: flex; align-items: center; height: 100%; color: var(--muted); font-weight: 600;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color 160ms var(--ease), border-color 160ms var(--ease);
}
.nav a:hover { color: var(--ink); }
.nav a.active { color: var(--accent-ink); border-bottom-color: var(--accent); }
.user-chip {
  margin-left: auto; display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 14px 7px 10px; border-radius: 999px; border: 1px solid var(--line-strong);
  background: var(--surface); font-weight: 600; font-size: 14px; max-width: 180px;
  transition: border-color 160ms var(--ease), transform 160ms var(--ease);
}
.user-chip:hover { border-color: var(--accent); }
.user-chip:active { transform: scale(.98); }
.user-chip i { font-size: 20px; color: var(--accent); flex: none; }
.user-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 560px) {
  .topbar { gap: 14px; }
  .brand span { display: none; }
  .nav { gap: 18px; margin-left: 0; }
}

/* ---------- Layout ---------- */
.app { max-width: 1040px; margin: 0 auto; padding: 32px 20px 72px; }
.narrow { max-width: 720px; margin: 0 auto; }
.view { animation: rise 320ms var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-card); box-shadow: var(--shadow); padding: 24px;
}
.section { margin-top: 40px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-head h2, .h2 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.section-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.link {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; padding: 0;
  color: var(--accent-ink); font-weight: 600; font-size: 14px;
}
.link:hover { text-decoration: underline; text-underline-offset: 3px; }
h1 { font-size: clamp(28px, 4.2vw, 40px); line-height: 1.15; margin: 0; letter-spacing: -.025em; font-weight: 700; }
.lead { color: var(--muted); margin: 10px 0 0; font-size: 16px; max-width: 46ch; }
.sub { color: var(--muted); margin: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
  padding: 11px 20px; border-radius: var(--r-ctl); border: 1px solid var(--line-strong);
  background: var(--surface); font-weight: 600;
  transition: background-color 160ms var(--ease), border-color 160ms var(--ease), color 160ms var(--ease), transform 120ms var(--ease);
}
.btn:hover { border-color: var(--accent); color: var(--accent-ink); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); color: var(--on-accent); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--paper-2); border-color: transparent; color: var(--ink); }
.btn-danger { color: var(--bad); }
.btn-danger:hover { color: var(--bad); background: var(--bad-soft); border-color: transparent; }
.btn-block { width: 100%; }
.btn-lg { padding: 14px 24px; font-size: 16px; }
.kbd {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 6px; font-size: 12px; font-weight: 700; flex: none;
  background: var(--paper-2); color: var(--muted); border: 1px solid var(--line);
}
.btn-primary .kbd { background: rgba(255, 253, 248, .2); color: var(--on-accent); border-color: transparent; }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: var(--r-ctl); flex: none;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--muted); font-size: 18px;
  transition: color 160ms var(--ease), border-color 160ms var(--ease);
}
.icon-btn:hover { color: var(--ink); border-color: var(--accent); }

/* ---------- Form ---------- */
.field { display: grid; gap: 6px; text-align: left; }
.field label { font-weight: 600; font-size: 14px; }
.input {
  width: 100%; padding: 13px 14px; border-radius: var(--r-ctl); border: 1.5px solid var(--line-strong);
  background: var(--surface); outline: none; color: var(--ink);
  transition: border-color 160ms var(--ease), box-shadow 160ms var(--ease);
}
.input::placeholder { color: #7a8493; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.form-grid { display: grid; gap: 14px; }
.form-error { color: var(--bad); font-size: 14px; font-weight: 600; }
.form-error:empty { display: none; }

/* ---------- Login ---------- */
.login { min-height: calc(100dvh - 104px); display: grid; align-items: center; }
.login-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 56px; align-items: center; }
.art {
  margin: 0; border-radius: var(--r-card); overflow: hidden; border: 1px solid var(--line); box-shadow: var(--shadow);
  aspect-ratio: 1200 / 740; background: #f7e3ca;
}
.art img { display: block; width: 100%; height: 100%; object-fit: cover; }
.login-form h1 { font-size: clamp(26px, 3.4vw, 34px); }
.tabs-line { display: flex; gap: 24px; border-bottom: 1px solid var(--line-strong); margin: 24px 0 20px; }
.tabs-line button {
  border: 0; background: none; padding: 0 0 10px; margin-bottom: -1px; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; transition: color 160ms var(--ease), border-color 160ms var(--ease);
}
.tabs-line button:hover { color: var(--ink); }
.tabs-line button.active { color: var(--accent-ink); border-bottom-color: var(--accent); }
.hint-box {
  margin-top: 18px; padding: 12px 14px; border-radius: var(--r-ctl); background: var(--paper-2);
  font-size: 14px; color: var(--muted);
}
.hint-box b { color: var(--ink); }
@media (max-width: 860px) {
  .login { align-items: start; min-height: 0; }
  .login-grid { grid-template-columns: 1fr; gap: 24px; }
  .art { aspect-ratio: 16 / 8; }
}

/* ---------- Home ---------- */
.hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 48px; align-items: center; }
@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; gap: 24px; }
  .hero .art { order: -1; aspect-ratio: 16 / 8; }
}
.progress-line { margin-top: 24px; }
.hero-stats { display: grid; grid-template-columns: repeat(4, auto); justify-content: start; gap: 6px 28px; margin: 14px 0 0; }
.hero-stats div { display: flex; flex-direction: column; min-width: 0; }
.hero-stats dt { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 500; order: 2; }
.hero-stats dd { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.swatch { display: inline-block; width: 9px; height: 9px; border-radius: 3px; flex: none; }
.swatch.mastered { background: var(--c-mastered); }
.swatch.learned { background: var(--c-learned); }
.swatch.wrong { background: var(--c-wrong); }
.swatch.new { background: var(--c-new); }
@media (max-width: 560px) { .hero-stats { grid-template-columns: repeat(2, auto); } }

.stackbar { display: flex; height: 6px; border-radius: 999px; overflow: hidden; background: var(--c-new); }
.stackbar.lg { height: 10px; }
.stackbar > span { display: block; height: 100%; transition: width 500ms var(--ease); }
.stackbar .mastered { background: var(--c-mastered); }
.stackbar .learned { background: var(--c-learned); }
.stackbar .wrong { background: var(--c-wrong); }

.mode-groups { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 700px) { .mode-groups { grid-template-columns: 1fr; } }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); padding: 18px 12px 12px; }
.panel-title { padding: 0 8px 10px; }
.panel-title h3 { margin: 0; font-size: 16px; font-weight: 700; }
.panel-title p { margin: 0; color: var(--muted); font-size: 13px; }
.opt {
  width: 100%; display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  text-align: left; padding: 12px 10px; border-radius: var(--r-ctl); border: 1.5px solid transparent; background: transparent;
  transition: background-color 160ms var(--ease), border-color 160ms var(--ease);
}
.opt + .opt { margin-top: 2px; }
.opt:hover { background: var(--paper); }
.opt.selected { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.radio {
  width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line-strong); background: var(--surface);
  transition: border-color 160ms var(--ease), background-color 160ms var(--ease), box-shadow 160ms var(--ease);
}
.opt.selected .radio { border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 4px var(--surface); }
.opt strong { display: block; font-size: 15px; line-height: 1.3; }
.opt .desc { display: block; color: var(--muted); font-size: 13px; line-height: 1.4; }
.opt > i { font-size: 22px; color: var(--muted); }
.opt.selected > i { color: var(--accent-ink); }
.mode-mix { margin-top: 16px; padding: 6px 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; border-radius: 999px;
  border: 1.5px solid var(--line-strong); background: var(--surface); font-weight: 600; font-size: 14px;
  transition: border-color 160ms var(--ease), background-color 160ms var(--ease), color 160ms var(--ease);
}
.chip:hover { border-color: var(--accent); }
.chip small { color: var(--muted); font-weight: 500; font-size: 13px; }
.chip.selected { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.chip.selected small { color: var(--accent-ink); }
.options-row { display: flex; flex-wrap: wrap; gap: 12px 28px; align-items: center; justify-content: space-between; }

.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-size: 14px; font-weight: 500; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle .track { width: 40px; height: 24px; border-radius: 999px; background: var(--line-strong); position: relative; flex: none; transition: background-color 200ms var(--ease); }
.toggle .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--surface); transition: transform 200ms var(--ease); box-shadow: 0 1px 2px rgba(60, 40, 10, .25); }
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track::after { transform: translateX(16px); }
.toggle input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.topic-item {
  text-align: left; padding: 14px; border-radius: var(--r-ctl); background: var(--surface);
  border: 1.5px solid var(--line); display: grid; gap: 10px; align-content: start;
  transition: border-color 160ms var(--ease), background-color 160ms var(--ease);
}
.topic-item:hover { border-color: var(--line-strong); }
.topic-item.selected { border-color: var(--accent); background: var(--accent-soft); }
.t-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.t-name { font-weight: 600; font-size: 14px; line-height: 1.35; }
.t-en { color: var(--muted); font-size: 13px; line-height: 1.35; }
.t-count { color: var(--muted); font-size: 13px; }
.t-count .bad { color: var(--bad); font-weight: 600; }
.check {
  width: 20px; height: 20px; border-radius: 6px; border: 1.5px solid var(--line-strong); flex: none;
  display: grid; place-items: center; font-size: 13px; color: var(--on-accent); background: var(--surface);
  transition: background-color 160ms var(--ease), border-color 160ms var(--ease);
}
.topic-item.selected .check { background: var(--accent); border-color: var(--accent); }

.start-bar {
  position: sticky; bottom: 16px; margin-top: 36px; display: flex; gap: 16px; align-items: center;
  padding: 12px 12px 12px 20px; border-radius: var(--r-card); background: var(--surface);
  border: 1px solid var(--line-strong); box-shadow: 0 12px 32px rgba(110, 70, 20, .14); z-index: 10;
}
.start-bar .summary { flex: 1; min-width: 0; font-size: 14px; color: var(--muted); line-height: 1.4; }
.start-bar .summary b { color: var(--ink); font-size: 15px; }
@media (max-width: 560px) {
  .start-bar { padding-left: 14px; gap: 10px; }
  .start-bar .summary { font-size: 13px; }
  .start-bar .btn-lg { padding: 13px 18px; }
}

/* ---------- Quiz ---------- */
.quiz-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.progress { flex: 1; height: 8px; border-radius: 999px; background: var(--paper-2); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width 400ms var(--ease); }
.score { display: flex; align-items: center; gap: 14px; font-weight: 700; font-size: 14px; white-space: nowrap; }
.score span { display: inline-flex; align-items: center; gap: 4px; }
.score .ok { color: var(--ok); }
.score .bad { color: var(--bad); }

.q-card { padding: 32px 28px 28px; text-align: center; }
.q-meta { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-bottom: 22px; }
.tag {
  display: inline-flex; align-items: center; padding: 3px 11px; border-radius: 999px;
  font-size: 13px; font-weight: 600; background: var(--paper-2); color: var(--muted);
}
.tag.mastered { background: var(--ok-soft); color: var(--ok); }
.tag.learned { background: var(--accent-soft); color: var(--accent-ink); }
.tag.wrong { background: var(--bad-soft); color: var(--bad); }
.q-label { color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.q-prompt { font-size: clamp(30px, 6vw, 44px); font-weight: 700; letter-spacing: -.025em; line-height: 1.15; word-break: break-word; }
.q-prompt.vi { font-size: clamp(24px, 5vw, 34px); letter-spacing: -.015em; }
.q-sub { margin-top: 12px; color: var(--muted); display: flex; justify-content: center; align-items: center; gap: 10px; flex-wrap: wrap; }
.speak {
  border: 0; background: var(--accent-soft); color: var(--accent-ink); border-radius: 999px; width: 34px; height: 34px;
  display: inline-grid; place-items: center; font-size: 18px; flex: none;
  transition: background-color 160ms var(--ease), transform 120ms var(--ease);
}
.speak:hover { background: #cfe4f4; }
.speak:active { transform: scale(.94); }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 26px; }
@media (max-width: 560px) { .choices { grid-template-columns: 1fr; } }
.choice {
  display: grid; grid-template-columns: auto minmax(0, 1fr) 22px; align-items: center; gap: 12px; text-align: left;
  padding: 14px 16px; border-radius: var(--r-ctl); border: 2px solid var(--line); background: var(--surface);
  font-weight: 600; font-size: 16px; min-height: 62px;
  transition: border-color 160ms var(--ease), background-color 160ms var(--ease), color 160ms var(--ease), transform 120ms var(--ease), opacity 160ms var(--ease);
}
.choice:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.choice:active:not(:disabled) { transform: scale(.985); }
.choice:disabled { cursor: default; }
.choice .mark { font-size: 22px; opacity: 0; }
.choice.correct { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); }
.choice.correct .mark { opacity: 1; }
.choice.correct .kbd { background: var(--ok); border-color: var(--ok); color: var(--on-accent); }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); animation: shake 360ms; }
.choice.wrong .mark { opacity: 1; }
.choice.wrong .kbd { background: var(--bad); border-color: var(--bad); color: var(--on-accent); }
.choice.dim { opacity: .45; }
.choice.pending { border-color: var(--accent); }

.write { margin-top: 26px; display: flex; gap: 10px; }
.write .input { font-size: 18px; font-weight: 600; padding: 15px 16px; }
.write .input.correct { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); }
.write .input.wrong { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); animation: shake 360ms; }
.hint { margin-top: 12px; color: var(--muted); font-size: 14px; text-align: center; }
.hint button { border: 0; background: none; padding: 0; color: var(--accent-ink); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
@media (max-width: 480px) { .write { flex-direction: column; } }

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

.feedback { margin-top: 20px; padding: 18px 20px; border-radius: var(--r-ctl); border: 1.5px solid; text-align: left; animation: rise 240ms var(--ease) both; }
.feedback.ok { border-color: var(--ok-line); background: var(--ok-soft); }
.feedback.bad { border-color: var(--bad-line); background: var(--bad-soft); }
.fb-head { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.fb-head i { font-size: 24px; }
.feedback.ok .fb-head { color: var(--ok); }
.feedback.bad .fb-head { color: var(--bad); }
.fb-answer { margin-top: 8px; }
.fb-answer b { font-size: 18px; }
.fb-note { margin-top: 6px; color: #8a5a00; font-size: 14px; font-weight: 600; }
.fb-word { margin-top: 14px; padding-top: 14px; border-top: 1px solid rgba(60, 40, 10, .12); }
.fb-word-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.fb-word strong { font-size: 17px; }
.fb-word .ipa { color: var(--muted); }
.fb-meaning { margin: 4px 0 0; color: var(--ink); }
.fb-status { margin-top: 10px; color: var(--muted); font-size: 14px; }
.fb-status .streak-dots { margin-left: 8px; vertical-align: middle; }
.fb-status b { color: var(--ink); }
.streak-dots { display: inline-flex; gap: 4px; align-items: center; }
.streak-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--c-new); display: block; }
.streak-dots i.on { background: var(--c-mastered); }

.next-row { display: flex; justify-content: flex-end; align-items: center; margin-top: 16px; gap: 14px; }
.auto-next { color: var(--muted); font-size: 14px; }
.auto-bar { height: 3px; border-radius: 3px; background: var(--ok); width: 100%; margin-top: 14px; transform-origin: left; animation: shrink linear forwards; }
@keyframes shrink { to { transform: scaleX(0); } }

/* ---------- Result ---------- */
.result { text-align: center; padding: 36px 24px 32px; }
.ring { --p: 0; width: 148px; height: 148px; border-radius: 50%; margin: 0 auto 20px; display: grid; place-items: center;
  background: conic-gradient(var(--c-mastered) calc(var(--p) * 1%), #f4cfcb 0); }
.ring > div { width: 118px; height: 118px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; }
.ring b { font-size: 32px; font-weight: 700; letter-spacing: -.02em; }
.result h1 { font-size: clamp(24px, 4vw, 30px); }
.result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 24px; }
.ok-text { color: var(--ok); font-weight: 700; }
.bad-text { color: var(--bad); font-weight: 700; }

/* ---------- Word list ---------- */
.word-list { display: grid; }
.word-row {
  display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.4fr) auto; gap: 16px; align-items: center;
  padding: 14px 0; border-bottom: 1px solid var(--line);
}
.word-row:last-child { border-bottom: 0; }
.word-row .w { font-weight: 700; }
.word-row .w small { display: block; font-weight: 400; color: var(--muted); font-size: 13px; }
.word-row .m { font-size: 15px; }
.word-row .m small { display: block; color: var(--muted); font-size: 13px; }
.word-row .r { text-align: right; font-size: 13px; white-space: nowrap; display: grid; gap: 4px; justify-items: end; }
.word-row .r .ok { color: var(--ok); font-weight: 700; }
.word-row .r .bad { color: var(--bad); font-weight: 700; }
@media (max-width: 560px) {
  .word-row { grid-template-columns: 1fr auto; gap: 4px 12px; }
  .word-row .m { grid-column: 1 / -1; grid-row: 2; }
}

/* ---------- Stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 760px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat {
  padding: 18px; border-radius: var(--r-card); background: var(--surface); border: 1.5px solid var(--line);
  box-shadow: var(--shadow); text-align: left;
  transition: border-color 160ms var(--ease), background-color 160ms var(--ease);
}
.stat:hover { border-color: var(--line-strong); }
.stat.active { border-color: var(--accent); background: var(--accent-soft); }
.stat .label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; font-weight: 600; }
.stat .value { font-size: 32px; font-weight: 700; letter-spacing: -.03em; line-height: 1.2; margin-top: 6px; }
.stat .value small { font-size: 14px; color: var(--muted); font-weight: 600; margin-left: 6px; letter-spacing: 0; }
.stat .desc { color: var(--muted); font-size: 13px; line-height: 1.4; margin-top: 2px; }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 560px) { .kpis { grid-template-columns: 1fr 1fr; } .kpis > :last-child { grid-column: 1 / -1; } }
.kpi { padding: 18px 20px; box-shadow: none; }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; display: flex; align-items: center; gap: 8px; }
.kpi .value i { color: #d9722b; font-size: 24px; }
.kpi .label { color: var(--muted); font-size: 14px; }

.chart { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 8px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; height: 100%; min-width: 0; }
.chart .bars { flex: 1; width: 100%; max-width: 28px; display: flex; flex-direction: column-reverse; justify-content: flex-start; gap: 2px; border-bottom: 1px solid var(--line-strong); }
.chart .bars span { display: block; width: 100%; border-radius: 4px 4px 0 0; transition: height 500ms var(--ease); }
.chart .bars .c { background: var(--c-mastered); }
.chart .bars .w { background: var(--c-wrong); }
.chart .day { font-size: 12px; color: var(--muted); }
.chart .col.today .day { color: var(--accent-ink); font-weight: 700; }
.legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }

.topic-table { display: grid; gap: 14px; }
.topic-line { display: grid; grid-template-columns: minmax(0, 1fr) 2fr 84px; gap: 16px; align-items: center; }
.topic-line .name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topic-line .nums { font-size: 13px; color: var(--muted); white-space: nowrap; text-align: right; }
.topic-line .nums .bad { color: var(--bad); font-weight: 600; }
@media (max-width: 560px) { .topic-line { grid-template-columns: 1fr auto; gap: 6px 12px; } .topic-line .stackbar { grid-column: 1 / -1; grid-row: 2; } }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 8px; }
.toolbar .input { flex: 1; min-width: 180px; padding: 10px 14px; }
.toolbar select.input { flex: 0 1 240px; }
.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 12px; scrollbar-width: none; }
.tabs .chip { white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 36px 16px; }

/* ---------- Modal / toast / skeleton ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px;
  background: rgba(60, 40, 10, .35); animation: fade 160ms ease both;
}
.modal { width: 100%; max-width: 400px; animation: rise 220ms var(--ease) both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--surface); padding: 11px 18px; border-radius: var(--r-ctl); font-weight: 600; font-size: 14px;
  transition: opacity 220ms var(--ease), transform 220ms var(--ease); z-index: 50; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.skeleton { border-radius: var(--r-ctl); background: linear-gradient(90deg, var(--paper-2) 25%, #fbf3e6 50%, var(--paper-2) 75%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

@media (max-width: 560px) {
  .next-row .auto-next { display: none; }
  .next-row .btn { width: 100%; }
  .next-row .btn .kbd { display: none; }
}
