/* ═══════════════════════════════════════════
   Flash Card — Học từ vựng theo ngữ cảnh
   ═══════════════════════════════════════════ */

:root {
  --bg-1: #eef1ff;
  --bg-2: #fdf2f8;
  --bg-3: #ecfeff;
  --surface: #ffffff;
  --surface-2: #f7f8fd;
  --surface-3: #eef1f9;
  --border: #e4e7f2;
  --text: #1c2035;
  --muted: #6b7288;
  --faint: #9aa0b5;
  --accent: #5b5bd6;
  --accent-soft: #eef0ff;
  --green: #0e9f6e;
  --green-soft: #e6f7f0;
  --amber: #d97706;
  --amber-soft: #fef4e6;
  --rose: #e11d48;
  --shadow-lg: 0 24px 50px -24px rgba(28, 32, 70, .38);
  --shadow-sm: 0 2px 10px -4px rgba(28, 32, 70, .18);
  --radius: 22px;
}

[data-theme="dark"] {
  --bg-1: #131728;
  --bg-2: #1a1430;
  --bg-3: #101d26;
  --surface: #1a1e30;
  --surface-2: #212639;
  --surface-3: #2a3049;
  --border: #2f3550;
  --text: #e9ebf7;
  --muted: #9ba2bd;
  --faint: #767d99;
  --accent: #8f90f5;
  --accent-soft: #262b46;
  --green: #34d399;
  --green-soft: #1b3630;
  --amber: #fbbf24;
  --amber-soft: #382c17;
  --rose: #fb7185;
  --shadow-lg: 0 24px 50px -24px rgba(0, 0, 0, .8);
  --shadow-sm: 0 2px 10px -4px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 600px at 12% -10%, var(--bg-2), transparent 60%),
    radial-gradient(900px 600px at 95% 0%, var(--bg-3), transparent 55%),
    var(--bg-1);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ─────────── Topbar ─────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  padding: 18px 28px;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; margin-right: auto; }
.brand-mark { font-size: 30px; line-height: 1; }
.brand-text h1 { font-size: 19px; letter-spacing: -.02em; }
.brand-text p { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat {
  display: flex; align-items: baseline; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12.5px; color: var(--muted); white-space: nowrap;
}
.stat b { font-size: 14px; color: var(--text); font-variant-numeric: tabular-nums; }
.stat.is-mastered b { color: var(--green); }
.stat.is-learning b { color: var(--amber); }
.stat.is-due b { color: var(--rose); }

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

.tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; }
.tab {
  border: 0; background: transparent; border-radius: 999px;
  padding: 7px 15px; font-size: 13.5px; font-weight: 500; color: var(--muted);
  transition: .18s;
}
.tab:hover { color: var(--text); }
.tab.is-active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }

.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface-2);
  font-size: 16px; display: grid; place-items: center; transition: .18s;
}
.icon-btn:hover { background: var(--surface-3); transform: translateY(-1px); }
.icon-btn.is-on { background: var(--amber-soft); border-color: var(--amber); color: var(--amber); }

/* ─────────── Layout ─────────── */

.wrap { max-width: 1120px; margin: 0 auto; padding: 26px 24px 70px; }
.view { animation: fade .3s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

.toolbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin-bottom: 22px;
}
.toolbar-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.filters { display: flex; gap: 7px; flex-wrap: wrap; }
.pill {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 500;
  color: var(--muted); transition: .18s; display: flex; align-items: center; gap: 7px;
}
.pill:hover { border-color: var(--accent); color: var(--text); }
.pill.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill .n {
  font-size: 11.5px; font-variant-numeric: tabular-nums;
  background: var(--surface-3); color: var(--muted);
  padding: 1px 7px; border-radius: 999px;
}
.pill.is-active .n { background: rgba(255,255,255,.24); color: #fff; }

.btn {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 12px; padding: 9px 16px; font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow-sm); transition: .18s;
}
.btn:hover { transform: translateY(-1px); border-color: var(--accent); }
.btn.ghost { box-shadow: none; background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.forgot:hover { background: var(--amber-soft); border-color: var(--amber); color: var(--amber); }
.btn.known:hover  { background: var(--green-soft); border-color: var(--green); color: var(--green); }
.btn:disabled { opacity: .5; pointer-events: none; }

.switch { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); cursor: pointer; user-select: none; }
.switch input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

.search, .select {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 12px; padding: 10px 15px; font: inherit; font-size: 14px;
  color: var(--text); outline: none; transition: .18s;
}
.search { flex: 1; min-width: 240px; max-width: 460px; }
.search:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ─────────── Flashcard ─────────── */

.stage { display: flex; align-items: center; gap: 16px; }

.nav {
  flex: none; width: 46px; height: 46px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--muted);
  display: grid; place-items: center; box-shadow: var(--shadow-sm); transition: .18s;
}
/* Vẽ bằng SVG chứ không dùng ký tự ‹ ›: lề hai bên của ký tự không đều nhau nên
   căn giữa kiểu gì nét mũi tên cũng lệch. Nét vẽ thì căn theo đúng hình học. */
.nav svg {
  width: 20px; height: 20px; display: block;
  fill: none; stroke: currentColor; stroke-width: 2.2;
  stroke-linecap: round; stroke-linejoin: round;
}
.nav:hover { color: var(--accent); border-color: var(--accent); transform: scale(1.06); }

.flashcard {
  flex: 1; min-width: 0;
  height: clamp(470px, 66vh, 640px);
  perspective: 1800px;
}
.card-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform .62s cubic-bezier(.2, .75, .3, 1);
}
.flashcard.flipped .card-inner { transform: rotateY(180deg); }

.face {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  overflow-y: auto; overscroll-behavior: contain;
}
.face.back { transform: rotateY(180deg); }

/* Front */
.front { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; padding: 34px; cursor: pointer; text-align: center; }
.illus { width: min(100%, 400px); border-radius: 18px; overflow: hidden; line-height: 0; }
.illus svg { width: 100%; height: auto; display: block; }
.illus-fallback { width: min(100%, 400px); aspect-ratio: 5/3; border-radius: 18px; background: var(--surface-2); display: grid; place-items: center; font-size: 76px; }

/* Ảnh minh hoạ là SVG tự mang nền pastel sáng của nó, nên ở nền tối chúng thành
   mảng chói giữa thẻ. Hạ độ sáng một chút cho đỡ nhức mắt lúc học đêm, nhưng vẫn
   giữ đủ màu để nhìn ra hình — đây là thứ giúp nhớ từ. */
[data-theme="dark"] .illus svg,
[data-theme="dark"] .wcard-illus svg { filter: brightness(.82) saturate(.9); }

.word-line { display: flex; align-items: center; gap: 12px; }
.word { font-size: clamp(36px, 6vw, 52px); font-weight: 700; letter-spacing: -.03em; line-height: 1.05; }
.meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center; }
.badge { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; padding: 4px 11px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.phonetic { font-size: 17px; color: var(--muted); font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.flip-hint { font-size: 13px; color: var(--faint); margin-top: 4px; }

.speak {
  flex: none; border: 1px solid var(--border); background: var(--surface-2);
  width: 34px; height: 34px; border-radius: 50%; font-size: 14px;
  display: inline-grid; place-items: center; transition: .18s; padding: 0;
}
.speak:hover { background: var(--accent); border-color: var(--accent); transform: scale(1.08); }
.speak.lg { width: 46px; height: 46px; font-size: 19px; }
.speak.sm { width: 26px; height: 26px; font-size: 11px; vertical-align: middle; }
.speak.is-playing { background: var(--accent); border-color: var(--accent); animation: pulse 1s ease infinite; }
@keyframes pulse { 50% { transform: scale(1.12); } }

/* Back */
.back { padding: 0; }
.back-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 20px 28px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.back-head .word { font-size: 30px; }
.back-head .phonetic { font-size: 15px; }
.back-head .btn { margin-left: auto; }
.back-body { padding: 24px 28px 34px; display: flex; flex-direction: column; gap: 26px; }

.quick {
  padding: 15px 18px; border-radius: 14px;
  background: var(--accent-soft); color: var(--text);
  font-size: 16px; line-height: 1.55; font-weight: 500;
  border-left: 3px solid var(--accent);
}
/* Nghĩa hay gặp nhất phải nổi hẳn lên, đọc một cái là nhớ. */
.core { display: block; font-size: 21px; line-height: 1.4; font-weight: 700; letter-spacing: -.01em; }
.quick-rest { display: block; margin-top: 7px; font-size: 14px; font-weight: 500; color: var(--muted); }

.sec-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em;
  color: var(--faint); margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}
.sec-title::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.ctx { padding: 16px 18px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--border); }
.ctx + .ctx { margin-top: 12px; }
.ctx-head { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 10px; }
.chip { font-size: 12.5px; font-weight: 600; padding: 4px 11px; border-radius: 999px; background: var(--accent); color: #fff; }
.chip-en { font-size: 12.5px; color: var(--faint); font-style: italic; }
.sense-en { font-size: 14.5px; line-height: 1.5; color: var(--muted); }
.sense-vi { font-size: 15.5px; line-height: 1.55; font-weight: 500; margin-top: 3px; }

.examples { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.examples li { padding-left: 13px; border-left: 2px solid var(--border); }
.ex-en { font-size: 14.5px; line-height: 1.55; }
.ex-vi { font-size: 14px; line-height: 1.55; color: var(--muted); margin-top: 2px; }

.colls { display: grid; grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); gap: 11px; }
.coll { padding: 13px 15px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); transition: .18s; }
.coll:hover { border-color: var(--accent); }
.coll-phrase { font-size: 15px; font-weight: 650; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.coll-vi { font-size: 13.5px; color: var(--accent); margin-top: 3px; font-weight: 500; }
.coll-ex { font-size: 13px; line-height: 1.5; color: var(--muted); margin-top: 7px; padding-top: 7px; border-top: 1px dashed var(--border); }
.coll-ex i { display: block; color: var(--faint); font-style: normal; }

.tags { display: flex; gap: 7px; flex-wrap: wrap; }
.tag { font-size: 13px; padding: 5px 12px; border-radius: 999px; background: var(--surface-3); color: var(--muted); }
.tag.anti { background: transparent; border: 1px dashed var(--border); }

.note { padding: 14px 16px; border-radius: 14px; background: var(--amber-soft); font-size: 14px; line-height: 1.6; border-left: 3px solid var(--amber); }

/* Gập phần dưới mặt sau — mỗi thẻ có tới ~25 câu, mở hết ra rất nản khi ôn lại */
.more-toggle {
  width: 100%; text-align: left;
  border: 1px dashed var(--border); background: transparent;
  border-radius: 12px; padding: 11px 15px;
  font-size: 13px; font-weight: 500; color: var(--muted); transition: .18s;
}
.more-toggle:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.more { display: flex; flex-direction: column; gap: 26px; }

.fam { display: flex; flex-direction: column; gap: 8px; }
.fam-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.fam-form { font-size: 15px; font-weight: 650; }
.fam-pos {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
}
.fam-vi { font-size: 13.5px; color: var(--muted); flex: 1; min-width: 140px; }

.conf { display: flex; flex-direction: column; gap: 9px; }
.conf-row {
  padding: 12px 15px; border-radius: 14px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-left: 3px solid var(--rose);
}
.conf-word { font-size: 14.5px; font-weight: 650; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.conf-word span { color: var(--rose); }
.conf-note { font-size: 13.5px; line-height: 1.55; color: var(--muted); margin-top: 4px; }

/* ─────────── Lịch ôn ─────────── */

.box-tag, .due-tag {
  display: inline-block; font-size: 11.5px; font-weight: 600;
  padding: 2px 9px; border-radius: 999px; white-space: nowrap;
}
.box-tag { background: var(--surface-3); color: var(--muted); }
.box-tag.box-4, .box-tag.box-5 { background: var(--green-soft); color: var(--green); }
.due-tag { background: transparent; color: var(--faint); padding-left: 2px; }
.due-tag.is-due { background: var(--amber-soft); color: var(--amber); padding-left: 9px; }

.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 60;
  transform: translate(-50%, 14px); opacity: 0;
  padding: 12px 22px; border-radius: 999px;
  background: var(--text); color: var(--surface);
  font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  transition: opacity .25s ease, transform .25s ease;
  pointer-events: none;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ─────────── Quiz ─────────── */

.quiz-intro, .quiz-done { text-align: center; max-width: 620px; margin: 0 auto; padding: 46px 24px; }
.quiz-art, .done-art { font-size: 62px; margin-bottom: 16px; }
.quiz-intro h2, .quiz-done h2 { font-size: 24px; letter-spacing: -.02em; margin-bottom: 12px; }
.quiz-intro p, .done-sub { color: var(--muted); font-size: 14.5px; line-height: 1.7; }
.quiz-intro em { color: var(--text); font-style: italic; }

.quiz-opts { display: flex; align-items: center; justify-content: center; gap: 20px; flex-wrap: wrap; margin: 26px 0 20px; }
.quiz-opt { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--muted); }
.quiz-warn { margin-top: 18px; font-size: 13.5px; color: var(--amber); }

.quiz-top { max-width: 720px; margin: 0 auto 18px; }
.quiz-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.quit {
  flex: none; font-size: 12.5px; font-weight: 600; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 12px; transition: .16s;
}
.quit:hover { color: var(--accent); border-color: var(--accent); }
.quiz-count { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.quiz-card {
  max-width: 720px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 30px 30px 26px;
}
.q-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--faint); margin-bottom: 14px; }
.q-sentence { font-size: 21px; line-height: 1.65; font-weight: 500; letter-spacing: -.01em; }
.q-sentence b { color: var(--accent); }
.q-gap {
  display: inline-block; min-width: 76px;
  color: var(--accent); letter-spacing: .08em;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.q-vi { font-size: 15px; line-height: 1.6; color: var(--muted); margin-top: 12px; }
.q-hint { font-size: 13px; color: var(--faint); margin-top: 8px; font-style: italic; }

.q-form { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.q-input {
  flex: 1; min-width: 200px;
  border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 12px; padding: 13px 16px; font: inherit; font-size: 17px;
  color: var(--text); outline: none; transition: .18s;
}
.q-input:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
.q-input:disabled { opacity: .6; }

.q-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 22px; }
.q-opt {
  border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 12px; padding: 14px 16px; font-size: 15.5px; font-weight: 550;
  transition: .18s;
}
.q-opt:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
.q-opt:disabled { opacity: .55; cursor: default; }
.q-opt.is-right { background: var(--green-soft); border-color: var(--green); color: var(--green); opacity: 1; }
.q-opt.is-wrong { background: var(--surface-3); border-color: var(--rose); color: var(--rose); opacity: 1; }

.q-result { margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--border); }
.q-verdict { font-size: 15.5px; font-weight: 650; }
.q-result.is-ok .q-verdict { color: var(--green); }
.q-result.is-no .q-verdict { color: var(--rose); }
.q-answer { font-size: 24px; font-weight: 700; letter-spacing: -.02em; margin-top: 8px; display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.q-full { font-size: 14.5px; line-height: 1.6; color: var(--muted); margin-top: 8px; }
.q-result .btn { margin-top: 18px; }

.done-wrong { margin-top: 28px; text-align: left; }
.done-wrong .tags { justify-content: flex-start; }
.done-wrong .tag { border: 1px solid var(--border); transition: .18s; }
.done-wrong .tag:hover { border-color: var(--accent); color: var(--accent); }
.done-actions { margin-top: 26px; }

/* ─────────── Deck bar ─────────── */

.deck-bar { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin: 20px 0 0; padding: 0 62px; }
.deck-progress { flex: 1; min-width: 190px; }
.deck-count { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.bar { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--green)); transition: width .35s ease; }
.deck-actions { display: flex; gap: 9px; flex-wrap: wrap; }

.hint { text-align: center; font-size: 12.5px; color: var(--faint); margin-top: 20px; }
kbd { font-family: inherit; font-size: 11.5px; padding: 2px 7px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); box-shadow: 0 1px 0 var(--border); }

.nodeck, .list-empty { text-align: center; padding: 60px 20px; color: var(--muted); font-size: 15px; }

/* ─────────── List view ─────────── */

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(268px, 1fr)); gap: 15px; }

.wcard {
  text-align: left; width: 100%;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 18px; padding: 0; overflow: hidden;
  box-shadow: var(--shadow-sm); transition: .2s;
  display: flex; flex-direction: column;
}
.wcard:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: var(--shadow-lg); }
.wcard-illus { line-height: 0; background: var(--surface-2); }
.wcard-illus svg { width: 100%; height: auto; display: block; }
.wcard-illus.fallback { aspect-ratio: 5/3; display: grid; place-items: center; font-size: 52px; }
.wcard-body { padding: 14px 16px 16px; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.wcard-top { display: flex; align-items: center; gap: 8px; }
.wcard-word { font-size: 19px; font-weight: 700; letter-spacing: -.02em; }
.wcard-star { margin-left: auto; font-size: 15px; color: var(--amber); }
.wcard-ph { font-size: 12.5px; color: var(--faint); font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.wcard-core { font-size: 15px; line-height: 1.45; font-weight: 650; color: var(--text); margin-top: 7px; }
.wcard-mean { font-size: 13.5px; line-height: 1.5; color: var(--muted); margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.wcard-foot { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.dot { font-size: 11.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px; }
.dot.new { background: var(--surface-3); color: var(--muted); }
.dot.learning { background: var(--amber-soft); color: var(--amber); }
.dot.mastered { background: var(--green-soft); color: var(--green); }
.wcard-date { font-size: 11.5px; color: var(--faint); margin-left: auto; }

/* ─────────── Empty ─────────── */

.empty { text-align: center; padding: 80px 24px; max-width: 560px; margin: 0 auto; }
.empty-art { font-size: 72px; margin-bottom: 18px; }
.empty h2 { font-size: 24px; letter-spacing: -.02em; margin-bottom: 10px; }
.empty p { color: var(--muted); font-size: 15px; line-height: 1.65; }
.empty-cmd {
  display: inline-block; margin: 18px 0;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 22px; font-weight: 600;
  padding: 12px 32px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border); color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.empty-sub { font-size: 13.5px; }
.empty-sub code { font-family: ui-monospace, Menlo, monospace; background: var(--surface-2); padding: 1px 6px; border-radius: 5px; }

/* ─────────── Ngữ pháp ─────────── */

.gram-head {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  margin-bottom: 24px; padding-bottom: 20px; border-bottom: 1px solid var(--border);
}
.gram-head-text { flex: 1; min-width: 260px; }
.gram-head h2 { font-size: 22px; letter-spacing: -.02em; margin-bottom: 6px; }
.gram-head p { font-size: 13.5px; line-height: 1.6; color: var(--muted); }
.gram-head b { color: var(--rose); }

.gcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 15px; }

.gcard {
  display: flex; gap: 15px; text-align: left; width: 100%;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 18px; padding: 17px 19px;
  box-shadow: var(--shadow-sm); transition: .2s;
}
.gcard:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: var(--shadow-lg); }
.gcard-emoji { font-size: 30px; line-height: 1.2; flex: none; }
.gcard-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.gcard-top { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.gcard-title { font-size: 16.5px; font-weight: 700; letter-spacing: -.02em; }
.lane {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
  padding: 2px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
}
.gcard-vi { font-size: 13.5px; color: var(--accent); font-weight: 500; }
.gcard-rule {
  font-size: 13px; line-height: 1.55; color: var(--muted); margin-top: 5px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.gcard-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 11px; }
.gcard-n { font-size: 11.5px; color: var(--faint); margin-left: auto; }
.gprog {
  font-size: 11.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px;
  background: var(--surface-3); color: var(--muted); white-space: nowrap;
}
.gprog.is-good { background: var(--green-soft); color: var(--green); }

/* chi tiết một điểm ngữ pháp */
.gram-detail { max-width: 860px; margin: 0 auto; }
.gd-head {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  margin: 20px 0 24px; padding-bottom: 20px; border-bottom: 1px solid var(--border);
}
.gd-emoji { font-size: 42px; line-height: 1; }
.gd-title { flex: 1; min-width: 200px; }
.gd-title h2 { font-size: 26px; letter-spacing: -.02em; }
.gd-title p { font-size: 14.5px; color: var(--muted); margin-top: 3px; }
.gd-body { display: flex; flex-direction: column; gap: 26px; }

.gd-formula {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13.5px; line-height: 1.8; color: var(--accent);
  padding: 13px 17px; border-radius: 12px;
  background: var(--surface-2); border: 1px dashed var(--border);
}

.ctr { padding: 16px 18px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--border); }
.ctr + .ctr { margin-top: 12px; }
.ctr-sit { font-size: 12.5px; font-weight: 600; color: var(--accent); margin-bottom: 11px; }
.ctr-right, .ctr-wrong {
  font-size: 15px; line-height: 1.55; padding-left: 13px;
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
}
.ctr-right { border-left: 3px solid var(--green); }
.ctr-right::before { content: "✅"; margin-left: -2px; }
.ctr-vi { font-size: 13.5px; color: var(--muted); padding-left: 13px; margin-top: 3px; margin-bottom: 12px; border-left: 3px solid var(--green); }
.ctr-wrong { border-left: 3px solid var(--rose); color: var(--muted); text-decoration: line-through; text-decoration-color: var(--rose); }
.ctr-wrong::before { content: "❌"; margin-left: -2px; text-decoration: none; display: inline-block; }
.ctr-why { font-size: 13.5px; line-height: 1.55; color: var(--muted); padding-left: 13px; margin-top: 5px; border-left: 3px solid var(--rose); }

.mis { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; }
.mis li { font-size: 14px; line-height: 1.65; color: var(--text); }
.mis b { color: var(--rose); }

.gd-actions { display: flex; justify-content: center; padding: 6px 0 10px; }

/* bài tập tìm lỗi */
/* Câu tìm lỗi: đọc phải ra một câu liền mạch, từng khúc gạch chân + đánh dấu
   A B C D đúng kiểu đề TOEIC. */
.fix-sentence { margin-top: 4px; }
.fix-part {
  font: inherit; color: inherit; background: none; border: 0;
  border-bottom: 2px solid var(--border);
  border-radius: 5px 5px 0 0;
  padding: 1px 3px 2px; transition: .16s;
}
.fix-tag {
  font-size: 11px; font-weight: 700; color: var(--faint);
  vertical-align: 5px; margin-right: 4px; letter-spacing: .04em;
}
.fix-part:hover:not(:disabled) { background: var(--accent-soft); border-bottom-color: var(--accent); color: var(--accent); }
.fix-part:hover:not(:disabled) .fix-tag { color: var(--accent); }
.fix-part:disabled { cursor: default; opacity: .5; }
.fix-part.is-right { background: var(--green-soft); border-bottom-color: var(--green); color: var(--green); opacity: 1; }
.fix-part.is-right .fix-tag { color: var(--green); }
.fix-part.is-wrong { background: var(--surface-3); border-bottom-color: var(--rose); color: var(--rose); opacity: 1; }
.fix-part.is-wrong .fix-tag { color: var(--rose); }

.q-cue { font-size: 14px; color: var(--muted); margin-top: 12px; }
.q-cue b { font-family: ui-monospace, "SF Mono", Menlo, monospace; color: var(--accent); font-size: 15px; }
.q-why {
  font-size: 13.5px; line-height: 1.65; color: var(--muted);
  margin-top: 12px; padding: 11px 14px; border-radius: 11px;
  background: var(--amber-soft); border-left: 3px solid var(--amber);
}
.q-faint { color: var(--faint); }

/* ─────────── Responsive ─────────── */

@media (max-width: 820px) {
  .topbar { padding: 14px 18px; gap: 14px; }
  .stats { order: 3; width: 100%; }
  .wrap { padding: 20px 16px 60px; }
  .stage { gap: 8px; }
  .nav { width: 38px; height: 38px; }
  .nav svg { width: 17px; height: 17px; }
  .flashcard { height: clamp(430px, 70vh, 560px); }
  .front { padding: 24px 20px; gap: 16px; }
  .back-head, .back-body { padding-left: 18px; padding-right: 18px; }
  .deck-bar { padding: 0; }
  .toolbar-right { margin-left: 0; width: 100%; }
  .quiz-card { padding: 22px 18px 20px; }
  .q-sentence { font-size: 18px; }
  .quiz-intro, .quiz-done { padding: 30px 6px; }
  .gcards { grid-template-columns: 1fr; }
  .gd-title h2 { font-size: 21px; }
  .fix-part { font-size: 14.5px; padding: 9px 11px; }
}

/* ─────────── Điện thoại ───────────
   Khổ 820px ở trên là cho máy tính bảng. Dưới 560px là điện thoại thật, và ở đó
   bài toán khác hẳn: màn cao chừng 780px mà thanh trên cộng thanh lọc đã ngốn
   402px — quá nửa. Phải cắt cho thẻ từ được nhìn thấy ngay, không phải cuộn.  */

@media (max-width: 560px) {

  /* Thanh trên gói lại còn hai hàng: hàng 1 tên app + hai nút tròn,
     hàng 2 là bốn tab trải đều. display:contents gỡ bọc .topbar-actions để
     ba nhóm bên trong xếp thẳng vào lưới của .topbar. */
  /* iPhone tai thỏ: chừa lề cho khuyết màn hình và vạch home, nếu không thì
     thêm app vào màn hình chính xong nội dung bị vạt mất ở mép. */
  .wrap {
    padding: 14px max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom))
             max(16px, env(safe-area-inset-left));
  }
  .topbar {
    gap: 9px 10px;
    padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
             10px max(14px, env(safe-area-inset-left));
  }
  .topbar-actions { display: contents; }
  .brand { order: 1; gap: 9px; }
  .brand-mark { font-size: 23px; }
  .brand-text h1 { font-size: 16px; }
  .brand-text p { display: none; }        /* dòng phụ, bỏ đi cho gọn */
  .sync { order: 2; }
  #themeBtn { order: 3; }
  .tabs { order: 4; width: 100%; padding: 3px; }
  .tab { flex: 1 1 0; min-width: 0; padding: 8px 2px; font-size: 11.5px; white-space: nowrap; }

  /* Bốn ô thống kê trùng thông tin với hàng lọc ngay bên dưới — trên điện thoại
     giữ cả hai là phí 75px màn hình. */
  .stats { display: none; }

  /* Hàng lọc: vuốt ngang một hàng thay vì tự xuống ba hàng. */
  .toolbar { flex-direction: column; align-items: stretch; gap: 10px; margin-bottom: 14px; }
  .filters {
    flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px;
    scrollbar-width: none; -ms-overflow-style: none;
    /* min-width:0 là bắt buộc. Mặc định flex item lấy chiều rộng nội dung làm
       kích thước tối thiểu, đè lên cả stretch lẫn overflow — thiếu dòng này thì
       hàng lọc phình ra 569px và kéo cả trang tràn ngang. */
    width: 100%; min-width: 0;
  }
  .filters::-webkit-scrollbar { display: none; }
  .pill { flex: none; }
  .toolbar-right { margin-left: 0; width: 100%; min-width: 0; justify-content: space-between; }

  /* Hai mũi tên chuyển từ nằm đè lên mép thẻ, trả lại 124px bề ngang cho thẻ. */
  .stage { position: relative; gap: 0; }
  .nav {
    position: absolute; top: 50%; transform: translateY(-50%);
    width: 40px; height: 40px; z-index: 5;
    background: color-mix(in srgb, var(--surface) 86%, transparent);
    backdrop-filter: blur(6px);
  }
  .nav:hover { transform: translateY(-50%) scale(1.06); }
  .nav { transition: opacity .25s ease; }
  #prevBtn { left: 5px; }
  #nextBtn { right: 5px; }

  /* Mặt sau đặc chữ, mũi tên đè lên là che mất. Mà chấm điểm xong app đã tự sang
     từ kế tiếp rồi, nên ở mặt sau chẳng cần tới chúng. */
  .stage:has(.flashcard.flipped) .nav { opacity: 0; pointer-events: none; }

  /* Thẻ ăn đúng phần màn hình còn lại. dvh chứ không phải vh: trên iOS, vh tính
     cả thanh địa chỉ nên thẻ bị đội xuống dưới nếp gấp. */
  /* Trừ đủ chỗ cho thanh trên, hàng lọc VÀ thanh nút chấm điểm bên dưới — mục
     tiêu là bấm 👍👎 được mà không phải cuộn. */
  .flashcard { height: clamp(320px, calc(100vh - 355px), 560px); }
  @supports (height: 100dvh) {
    .flashcard { height: clamp(320px, calc(100dvh - 355px), 560px); }
  }

  .front { padding: 20px 16px; gap: 12px; }
  .back-head, .back-body { padding-left: 14px; padding-right: 14px; }

  /* Thanh dưới thẻ: bỏ lề 62px, ba nút chính trải đều cả hàng cho dễ bấm. */
  .deck-bar { padding: 0; gap: 10px; margin-top: 14px; }
  .deck-progress { min-width: 0; width: 100%; }
  .deck-actions { width: 100%; gap: 8px; flex-wrap: nowrap; }
  .deck-actions .btn { flex: 1 1 0; min-width: 0; padding: 12px 6px; font-size: 13px; }
  .deck-actions .icon-btn { flex: none; width: 44px; height: 44px; }

  /* Không có bàn phím thì nhắc phím tắt làm gì. */
  .hint { display: none; }

  /* Ô tìm kiếm từng đặt min-width 240px — ở màn 360px là tràn ra ngoài. */
  .search { min-width: 0; max-width: none; }
  .grid, .colls { grid-template-columns: 1fr; }
  .quiz-card { padding: 18px 14px 16px; }
  .q-opts { grid-template-columns: 1fr; }
  .gram-detail, .quiz-top, .quiz-body { max-width: none; }
}

/* Màn rất hẹp (iPhone SE, 320px) — chữ trên tab phải nhỏ thêm chút nữa. */
@media (max-width: 370px) {
  .tab { font-size: 10.5px; padding: 8px 1px; }
  .brand-text h1 { font-size: 15px; }
  .deck-actions .btn { font-size: 12px; padding: 12px 4px; }
}

/* ── Gạch chân từ đang học trong câu ví dụ ── */
.tw {
  text-decoration-line: underline;
  text-decoration-style: dashed;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
  cursor: help;
  border-radius: 5px;
  padding: 0 1px;
  transition: background .12s;
}
.tw:hover, .tw:focus-visible { background: var(--accent-soft); outline: none; }

.tw-tip {
  position: fixed; left: 0; top: 0; z-index: 90;
  max-width: min(290px, calc(100vw - 24px));
  padding: 9px 12px;
  border-radius: 11px;
  background: var(--text);
  color: var(--surface);
  font-size: 12.5px; line-height: 1.55; font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateY(4px);
  transition: opacity .13s ease, transform .13s ease;
  pointer-events: none;
}
.tw-tip.is-on { opacity: 1; transform: none; }
.tw.is-good { text-decoration-color: var(--green); }
.tw.is-bad  { text-decoration-color: var(--rose); text-decoration-style: wavy; text-decoration-thickness: 1.5px; }
.ctr-wrong .tw { text-underline-offset: 5px; }
.ctr-txt { flex: 0 1 auto; min-width: 0; }

/* ─────────── Cổng đăng nhập ─────────── */

.gate { display: none; }

html.is-locked .gate {
  display: grid; place-items: center;
  min-height: 100vh; padding: 24px;
}

/* Khoá thì giấu sạch, không chừa mảnh nội dung nào. */
html.is-locked .topbar,
html.is-locked .wrap,
html.is-locked .toast,
html.is-locked .tw-tip { display: none !important; }

.gate-card {
  width: min(380px, 100%); padding: 38px 32px; text-align: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
}

.gate-mark { font-size: 46px; line-height: 1; margin-bottom: 14px; }

.gate-card h1 { font-size: 24px; font-weight: 800; color: var(--text); margin-bottom: 8px; }

.gate-msg { font-size: 14px; color: var(--muted); line-height: 1.55; margin-bottom: 22px; }

.gate-btn {
  width: 100%; padding: 13px 18px; border-radius: 13px; border: 0;
  background: var(--accent); color: #fff;
  font-size: 14.5px; font-weight: 700; transition: .18s;
}
.gate-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.gate-btn:disabled { opacity: .55; transform: none; cursor: default; }

.gate-fine {
  margin-top: 16px; font-size: 12.5px; color: var(--faint); line-height: 1.5;
  white-space: pre-line;
}

/* ─────────── Đồng bộ đám mây ─────────── */

.sync { position: relative; }

/* Trạng thái chưa đăng nhập: nở thành nút có chữ để không bị bỏ sót. */
.sync-btn.has-label {
  width: auto; border-radius: 999px; padding: 0 15px; gap: 6px;
  font-size: 13px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); border-color: var(--accent);
  white-space: nowrap;
}

.sync-btn.is-ok   { background: var(--green-soft); border-color: var(--green); }
.sync-btn.is-warn { background: var(--amber-soft); border-color: var(--amber); }
.sync-btn.is-busy { animation: syncPulse 1.1s ease-in-out infinite; }

@keyframes syncPulse { 50% { opacity: .45; } }

.sync-menu {
  position: absolute; top: 46px; right: 0; z-index: 40;
  width: 226px; padding: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow-lg);
  display: grid; gap: 8px;
  animation: fade .18s ease;
}

.sync-who {
  font-size: 13px; font-weight: 700; color: var(--text);
  word-break: break-all; line-height: 1.35;
}

.sync-note {
  font-size: 12px; color: var(--muted); line-height: 1.4;
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
}

.sync-act {
  width: 100%; padding: 9px 12px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--surface-2);
  font-size: 13px; font-weight: 600; color: var(--text);
  text-align: left; transition: .16s;
}
.sync-act:hover { background: var(--surface-3); }
.sync-act.is-danger { color: var(--rose); }
.sync-act.is-danger:hover { background: var(--surface-3); border-color: var(--rose); }
