:root {
  --bg: #131f24;
  --bg-elevated: #1b2b34;
  --surface: #202f39;
  --surface-hover: #26384433;
  --surface-hover-solid: #263844;
  --border: #2b3d47;
  --border-strong: #37464f;

  --text: #ffffff;
  --text-dim: #8ea1ac;
  --text-dimmer: #5f7480;

  --green: #58cc02;
  --green-dark: #46a302;
  --green-tint: #1a3409;

  --blue: #1cb0f6;
  --blue-dark: #1899d6;
  --blue-tint: #0e2836;

  --red: #ff4b4b;
  --red-dark: #ea2b2b;
  --red-tint: #3a1414;

  --yellow: #ffc800;
  --yellow-dark: #e5b400;
  --yellow-tint: #3a2e00;

  --purple: #ce82ff;
  --purple-dark: #a568cc;
  --purple-tint: #2a1a3a;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Noto Sans", "Noto Sans SC", "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

/* Deck's main language (set in Sửa/Tạo bộ thẻ) - .container.lang-* on <main>
   (see base.html) overrides the body font for that whole page so kanji/hanzi
   render in a proper script-native typeface instead of Noto Sans's fallback. */
.lang-ja { font-family: "Noto Serif JP", "Yu Mincho", YuMincho, "Hiragino Mincho ProN", "MS Mincho", serif; }
.lang-zh { font-family: "Noto Sans CJK SC", "Microsoft YaHei", sans-serif; }
.lang-en { font-family: "Noto Sans", "Segoe UI", Arial, sans-serif; }
.lang-vi { font-family: "Noto Sans", "Segoe UI", Arial, sans-serif; }

a { color: var(--blue); text-decoration: none; font-weight: 700; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--bg-elevated);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  font-weight: 800;
  font-size: 1.12rem;
  color: var(--green);
  letter-spacing: 0.02em;
}
.brand:hover { text-decoration: none; filter: brightness(1.1); }
.topbar nav { display: flex; align-items: center; gap: 8px; }
.topbar nav a {
  margin-left: 0;
  color: var(--text-dim);
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.topbar nav a:hover {
  background: var(--surface-hover-solid);
  color: var(--text);
  text-decoration: none;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 28px 16px 72px;
}

h1 { font-size: 1.7rem; margin-bottom: 4px; font-weight: 800; }
h2 { font-size: 1.25rem; margin-top: 32px; font-weight: 800; }
.muted { color: var(--text-dim); font-weight: 600; }
.center-text { text-align: center; }

/* ---------------------------------------------------------------- flash */
.flash-list { margin-bottom: 16px; display: flex; flex-direction: column; gap: 8px; }
.flash {
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 0.9rem;
  font-weight: 700;
  border: 2px solid transparent;
  margin-bottom: 16px;
}
.flash-success { background: var(--green-tint); color: #8fe151; border-color: var(--green-dark); }
.flash-error { background: var(--red-tint); color: #ff8a8a; border-color: var(--red-dark); }

/* ---------------------------------------------------------------- login */
.center-card {
  max-width: 380px;
  margin: 72px auto;
  text-align: center;
  background: var(--surface);
  padding: 36px 28px;
  border-radius: 20px;
  border: 2px solid var(--border-strong);
}
.center-card h1 { color: var(--green); font-size: 2rem; }
.passcode-form { margin-top: 24px; display: flex; flex-direction: column; gap: 24px; }

.passcode-dots {
  display: flex;
  justify-content: center;
  gap: 18px;
}
.passcode-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: var(--bg);
  transition: background 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}
.passcode-dot.filled {
  background: var(--green);
  border-color: var(--green-dark);
  transform: scale(1.2);
}
.passcode-dots.shake { animation: timer-shake 0.4s ease; }

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.keypad-btn {
  padding: 18px 0;
  border-radius: 16px;
  border: none;
  background: var(--bg);
  color: var(--text);
  font-size: 1.5rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--border-strong);
  transition: transform 0.05s ease, box-shadow 0.05s ease, filter 0.1s ease;
}
.keypad-btn:hover { filter: brightness(1.15); }
.keypad-btn:active { transform: translateY(4px); box-shadow: 0 0 0 var(--border-strong); }
.keypad-btn.keypad-action { font-size: 1rem; font-weight: 700; color: var(--text-dim); }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-block;
  padding: 13px 22px;
  border-radius: 16px;
  border: none;
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  cursor: pointer;
  text-align: center;
  box-shadow: 0 4px 0 var(--btn-shadow, var(--border-strong));
  background: var(--surface);
  color: var(--text);
  transition: transform 0.05s ease, box-shadow 0.05s ease, filter 0.1s ease;
  transform: translateY(0);
}
.btn:hover { text-decoration: none; filter: brightness(1.08); }
.btn:active { transform: translateY(4px); box-shadow: 0 0 0 var(--btn-shadow, var(--border-strong)); }

.btn-primary { --btn-shadow: var(--green-dark); background: var(--green); color: #0b1a00; }
.btn-ghost { --btn-shadow: var(--border-strong); background: var(--surface); color: var(--blue); border: 2px solid var(--border-strong); padding: 11px 20px; }
.btn-danger { --btn-shadow: var(--red-dark); background: var(--red); color: #2a0000; }
.btn-block { width: 100%; }
.btn-disabled { opacity: 0.4; cursor: default; pointer-events: none; box-shadow: none; }

.btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
  filter: none;
  transform: translateY(4px);
  box-shadow: 0 0 0 var(--btn-shadow, var(--border-strong));
}
.btn-loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 3px solid rgba(0, 0, 0, 0.2);
  border-top-color: rgba(0, 0, 0, 0.65);
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}
@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 16px; flex-wrap: wrap; }
.pagination-info { color: var(--text-dim); font-weight: 700; }

/* ---------------------------------------------------------------- layout bits */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.header-actions { display: flex; gap: 10px; }

.modal {
  border: 2px solid var(--border-strong);
  border-radius: 20px;
  padding: 24px;
  background: var(--surface);
  color: var(--text);
  width: min(360px, calc(100vw - 32px));
}
.modal h3 { margin: 0 0 16px; }
.modal::backdrop { background: rgba(0, 0, 0, 0.6); }
.modal .options { margin-bottom: 20px; }

.deck-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.deck-card {
  display: block;
  background: var(--surface);
  border: 2px solid var(--border-strong);
  border-radius: 18px;
  padding: 18px;
  color: var(--text);
  transition: transform 0.08s ease, border-color 0.08s ease;
}
.deck-card:hover { border-color: var(--green); transform: translateY(-2px); text-decoration: none; }
.deck-card h3 { margin: 0 0 4px; }
.deck-meta { display: flex; gap: 8px; margin-top: 14px; font-size: 0.85rem; flex-wrap: wrap; }

.badge {
  background: var(--blue-tint);
  color: var(--blue);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.badge-new { background: var(--surface-hover-solid); color: var(--text-dim); }

.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin: 20px 0 32px;
}
.action-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface);
  border: 2px solid var(--border-strong);
  border-radius: 18px;
  padding: 18px;
  color: var(--text);
  transition: transform 0.08s ease, border-color 0.08s ease;
}
.action-card:hover { border-color: var(--green); transform: translateY(-2px); text-decoration: none; }
.action-card strong { font-size: 1.05rem; }
.action-icon { font-size: 1.7rem; }

.empty-state {
  text-align: center;
  padding: 52px 16px;
  border: 2px dashed var(--border-strong);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  color: var(--text-dim);
  font-weight: 700;
}

/* ---------------------------------------------------------------- forms */
.form-card {
  background: var(--surface);
  border: 2px solid var(--border-strong);
  border-radius: 18px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 600px;
}
.form-card label {
  font-weight: 800;
  font-size: 0.85rem;
  margin-top: 10px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-dim);
}
.form-card input,
.form-card textarea,
.form-card select {
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  width: 100%;
}
.form-card input:focus,
.form-card textarea:focus,
.form-card select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(28, 176, 246, 0.2);
}
.form-actions { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 18px; flex-wrap: wrap; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-weight: 600; margin: 0; text-transform: none; color: var(--text); }
.checkbox-label input { width: auto; }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}
.toggle-row .toggle-text {
  font-weight: 800;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-dim);
}
.toggle-switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.toggle-switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border-strong);
  border-radius: 999px;
  transition: background-color 0.2s ease;
  pointer-events: none;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  background: var(--text);
  border-radius: 50%;
  transition: transform 0.2s ease;
}
.toggle-switch input:checked + .toggle-slider { background: var(--green); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }
.toggle-switch input:focus-visible + .toggle-slider { box-shadow: 0 0 0 4px rgba(28, 176, 246, 0.35); }

/* ---------------------------------------------------------------- quiz progress (sticky) */
.quiz-progress-sticky {
  position: sticky;
  top: var(--topbar-h, 60px);
  z-index: 5;
  background: var(--bg);
  padding: 10px 0 14px;
  margin-bottom: 6px;
}
.quiz-progress-info {
  display: flex;
  justify-content: space-between;
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.quiz-progress-bar-wrap {
  height: 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 2px solid var(--border-strong);
  overflow: hidden;
}
.quiz-progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--blue);
  transition: width 0.25s ease;
}
.quiz-progress-sticky .timer-bar-wrap { margin-top: 10px; }
.quiz-progress-sticky .timer-text { margin-bottom: 0; }

/* ---------------------------------------------------------------- quiz timer */
.timer-bar-wrap {
  height: 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 2px solid var(--border-strong);
  overflow: hidden;
  margin-bottom: 8px;
}
.timer-bar {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: var(--green);
}
.timer-bar.timer-warn { background: var(--yellow); }
.timer-bar.timer-danger { background: var(--red); animation: timer-pulse 0.5s ease-in-out infinite; }
.timer-text {
  text-align: right;
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--text-dim);
  margin: 0 0 14px;
}
.timer-text.timer-danger { color: var(--red); }
.timer-bar-wrap.timer-shake { animation: timer-shake 0.4s ease; }

@keyframes timer-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
@keyframes timer-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

/* ---------------------------------------------------------------- whole-test time budget bubble */
/* Laid out inline alongside the other stat badges (not fixed/floating),
   so it never overlaps the question or answer options. */
.time-budget-bubble {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--purple-tint);
  color: var(--purple);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.time-budget-bubble .tb-icon { font-size: 0.85rem; }
.time-budget-bubble.timer-danger {
  background: var(--red-tint);
  color: #ff8a8a;
  animation: timer-pulse 0.5s ease-in-out infinite;
}

.import-options { display: flex; gap: 24px; margin-top: 10px; flex-wrap: wrap; }
.import-options > div { flex: 1; min-width: 160px; }

/* ---------------------------------------------------------------- table */
.card-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 2px solid var(--border-strong);
  border-radius: 18px;
  overflow: hidden;
}
.card-table th, .card-table td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}
.card-table th {
  background: var(--surface-hover-solid);
  color: var(--text-dim);
  text-transform: uppercase;
  font-size: 0.78rem;
  letter-spacing: 0.03em;
}
.card-table tbody tr:hover { background: var(--surface-hover-solid); }
.card-table tbody tr:last-child td { border-bottom: none; }

.deck-cards-table td:nth-child(1), .deck-cards-table td:nth-child(2) { word-break: break-word; }
.deck-cards-table th:nth-child(3), .deck-cards-table td:nth-child(3),
.deck-cards-table th:nth-child(4), .deck-cards-table td:nth-child(4) { white-space: nowrap; width: 1%; }
.deck-cards-table .badge { padding: 3px 8px; font-size: 0.68rem; letter-spacing: 0; }

.row-actions { display: flex; gap: 2px; justify-content: flex-end; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 8px;
  background: none;
  font-size: 1rem;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-hover-solid); }

/* ---------------------------------------------------------------- flashcard */
.browse-wrap { display: flex; flex-direction: column; align-items: center; gap: 20px; margin-top: 24px; }
.flashcard {
  width: 100%;
  max-width: 560px;
  height: 260px;
  perspective: 1200px;
  cursor: pointer;
}
.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s;
  transform-style: preserve-3d;
}
.flashcard-inner.flipped {
  transform: rotateY(180deg);
}
.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  background: var(--surface);
  border: 2px solid var(--border-strong);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 28px;
  font-size: 1.4rem;
  box-shadow: 0 6px 0 var(--border-strong);
}
.flashcard-back {
  transform: rotateY(180deg);
  background: var(--blue-tint);
  border-color: var(--blue);
  box-shadow: 0 6px 0 var(--blue-dark);
}

.browse-controls { display: flex; align-items: center; gap: 18px; }

/* ---------------------------------------------------------------- study (SRS): 3x larger card text */
.study-page .flashcard { height: 380px; }
.study-page .flashcard-face { font-size: 4.2rem; padding: 20px; overflow-y: auto; }
.study-page .flashcard-back { font-size: 2.1rem; }

@media (max-width: 600px) {
  .study-page .flashcard { height: 260px; }
  .study-page .flashcard-face { font-size: 3.3rem; }
  .study-page .flashcard-back { font-size: 1.65rem; }
}
.browse-controls .btn { min-width: 100px; }
#counter { font-weight: 800; }

/* ---------------------------------------------------------------- study ratings */
.rating-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.btn-rating { color: #fff; min-width: 110px; }
.btn-rating-again { --btn-shadow: var(--red-dark); background: var(--red); }
.btn-rating-hard { --btn-shadow: var(--yellow-dark); background: var(--yellow); color: #2a2000; }
.btn-rating-good { --btn-shadow: var(--green-dark); background: var(--green); color: #0b1a00; }
.btn-rating-easy { --btn-shadow: var(--blue-dark); background: var(--blue); color: #00202b; }

/* ---------------------------------------------------------------- test */
.test-question {
  background: var(--surface);
  border: 2px solid var(--border-strong);
  border-radius: 18px;
  padding: 20px;
  margin-bottom: 16px;
}
.question-num { color: var(--text-dim); font-size: 0.8rem; font-weight: 800; text-transform: uppercase; margin: 0 0 6px; }
.question-prompt { font-size: 1.15rem; font-weight: 800; margin: 0 0 14px; }
.options { display: flex; flex-direction: column; gap: 10px; }
.option-label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 2px solid var(--border-strong);
  border-radius: 14px;
  cursor: pointer;
  font-weight: 700;
  background: var(--bg);
  transition: border-color 0.1s ease, background 0.1s ease;
}
.option-label:hover { border-color: var(--blue); background: var(--blue-tint); }
.option-label:has(input:checked:not(:disabled)) { border-color: var(--green); background: var(--green-tint); }
.text-answer {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-weight: 700;
}
.text-answer:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(28, 176, 246, 0.2);
}

/* ---------------------------------------------------------------- results */
.score-card {
  text-align: center;
  background: var(--surface);
  border: 2px solid var(--border-strong);
  border-radius: 20px;
  padding: 36px;
  max-width: 320px;
  margin: 0 auto 28px;
}
.score-number { font-size: 3.2rem; font-weight: 800; color: var(--green); }

.result-row {
  border-radius: 14px;
  padding: 16px 18px;
  margin-bottom: 12px;
  border: 2px solid var(--border-strong);
  border-left: 6px solid var(--border-strong);
  background: var(--surface);
}
.result-correct { border-left-color: var(--green); }
.result-wrong { border-left-color: var(--red); }
.result-row strong { color: var(--text); }

/* ---------------------------------------------------------------- test play (immediate feedback) */
.play-stats {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.badge-wrong { background: var(--red-tint); color: #ff8a8a; }

.option-label.option-correct {
  border-color: var(--green);
  background: var(--green-tint);
}
.option-label.option-wrong {
  border-color: var(--red);
  background: var(--red-tint);
}

.feedback {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  font-weight: 800;
}
.feedback-correct {
  background: var(--green-tint);
  color: #8fe151;
  animation: fx-feedback-pop 0.55s cubic-bezier(.34, 1.56, .64, 1) both;
}
.feedback-wrong { background: var(--red-tint); color: #ff8a8a; }

@keyframes fx-feedback-pop {
  0% { transform: scale(0.4); opacity: 0; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}

/* ---------------------------------------------------------------- answer feedback fx */
.fx-flash-wrong {
  position: fixed;
  inset: 0;
  background: var(--red);
  opacity: 0;
  pointer-events: none;
  z-index: 999;
  animation: fx-flash-wrong 0.5s ease-out forwards;
}
@keyframes fx-flash-wrong {
  0% { opacity: 0; }
  15% { opacity: 0.5; }
  100% { opacity: 0; }
}

.fx-confetti-wrap {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  overflow: hidden;
}

.fx-glow-correct {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 32%, rgba(88, 204, 2, 0.4), transparent 62%);
  animation: fx-glow-correct 0.9s ease-out forwards;
}
@keyframes fx-glow-correct {
  0% { opacity: 0; }
  20% { opacity: 1; }
  100% { opacity: 0; }
}

.fx-animal {
  position: absolute;
  top: 38%;
  left: 50%;
  width: 130px;
  height: 130px;
  transform: translate(-50%, -50%) scale(0);
  opacity: 0;
  animation: fx-animal-pop 1.8s cubic-bezier(.34, 1.56, .64, 1) forwards;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.25));
}
.fx-animal svg {
  display: block;
  width: 100%;
  height: 100%;
}
@keyframes fx-animal-pop {
  0% { transform: translate(-50%, -50%) scale(0) rotate(-15deg); opacity: 0; }
  15% { transform: translate(-50%, -50%) scale(1.3) rotate(10deg); opacity: 1; }
  30% { transform: translate(-50%, -50%) scale(0.92) rotate(-8deg); }
  45% { transform: translate(-50%, -55%) scale(1.1) rotate(6deg); }
  60% { transform: translate(-50%, -50%) scale(1) rotate(-4deg); }
  80% { transform: translate(-50%, -50%) scale(1) rotate(0deg); opacity: 1; }
  100% { transform: translate(-50%, -68%) scale(0.7) rotate(0deg); opacity: 0; }
}

.fx-confetti-piece {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  opacity: 1;
}
.fx-confetti-burst {
  top: 50%;
  left: 50%;
  animation: fx-confetti-burst 1s cubic-bezier(.2, .8, .3, 1) forwards;
}
@keyframes fx-confetti-burst {
  0% { transform: translate(-50%, -50%) rotate(0deg) scale(1); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--rot)) scale(0.6); opacity: 0; }
}

.fx-confetti-shower {
  top: -10vh;
  animation-name: fx-confetti-shower;
  animation-timing-function: cubic-bezier(.25, .46, .45, .94);
  animation-fill-mode: forwards;
}
@keyframes fx-confetti-shower {
  0% { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  75% { opacity: 1; }
  100% { transform: translate(var(--sway), var(--fall)) rotate(var(--rot)); opacity: 0; }
}

/* ---------------------------------------------------------------- match game */
.match-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 20px;
}
.match-tile {
  background: var(--surface);
  border: 2px solid var(--border-strong);
  border-radius: 14px;
  padding: 16px 10px;
  min-height: 72px;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.08s ease, background 0.08s ease;
}
.match-tile:hover { border-color: var(--blue); }
.match-tile.selected { border-color: var(--blue); background: var(--blue-tint); transform: scale(0.97); }
.match-tile.wrong { border-color: var(--red); background: var(--red-tint); }
.match-tile.matched {
  border-color: var(--green);
  background: var(--green-tint);
  color: var(--text-dimmer);
  cursor: default;
  opacity: 0.55;
}

/* ---------------------------------------------------------------- Kiểm tra: lighter weight, ~30% larger */
.test-page h1 { font-size: 2.2rem; font-weight: 700; }
.test-page h2 { font-size: 1.6rem; font-weight: 700; }
.test-page p,
.test-page .muted { font-size: 1.1rem; font-weight: 500; }

.test-page .action-card strong { font-weight: 600; font-size: 1.35rem; }
.test-page .action-card .muted { font-size: 1rem; }
.test-page .action-icon { font-size: 2.2rem; }

.test-page .question-num { font-weight: 500; font-size: 1.05rem; }
.test-page .question-prompt { font-weight: 500; font-size: 1.5rem; }
.test-page .option-label { font-weight: 400; font-size: 1.25rem; padding: 15px 18px; }
.test-page .text-answer { font-weight: 400; font-size: 1.25rem; }

.test-page .btn { font-weight: 500; font-size: 1.25rem; text-transform: none; letter-spacing: normal; }

.test-page .badge { font-weight: 500; font-size: 1rem; text-transform: none; }
.test-page .feedback { font-weight: 500; font-size: 1.25rem; }

.test-page .score-number { font-weight: 500; font-size: 4.15rem; }
.test-page .score-card p { font-size: 1.25rem; font-weight: 400; }

.test-page .result-row { font-size: 1.15rem; }
.test-page .result-row p { font-weight: 400; }

.test-page .card-table th { font-weight: 500; font-size: 1rem; text-transform: none; }
.test-page .card-table td { font-size: 1.1rem; }

.test-page .match-tile { font-weight: 400; font-size: 1.25rem; min-height: 90px; }

.test-page .play-stats { font-size: 1.2rem; }

#mc-setup-form,
#deck-form { margin-left: auto; margin-right: auto; }

.test-page .form-card label { font-weight: 500; font-size: 1rem; text-transform: none; }
.test-page .form-card input,
.test-page .form-card select { font-size: 1.1rem; }

.test-page .flash { font-weight: 500; font-size: 1.1rem; }

/* ---------------------------------------------------------------- table scroll (avoid page-wide horizontal scroll) */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 18px;
}
.table-scroll .card-table { border-radius: 0; }

@media (max-width: 600px) {
  .topbar { padding: 10px 14px; }
  .brand { font-size: 0.92rem; }
  .topbar nav { gap: 2px; }
  .topbar nav a { padding: 6px 10px; font-size: 0.64rem; }

  .container { padding: 16px 12px 40px; }
  h1 { font-size: 1.4rem; }
  h2 { font-size: 1.1rem; margin-top: 22px; }

  .page-header { margin-bottom: 12px; }
  .header-actions { gap: 8px; }

  .action-grid { gap: 10px; margin: 14px 0 22px; }
  .action-card { padding: 14px; gap: 2px; }
  .action-icon { font-size: 1.4rem; }

  .form-card { padding: 16px; gap: 4px; }
  .form-actions { margin-top: 14px; gap: 8px; }

  .browse-wrap { gap: 14px; margin-top: 16px; }
  .flashcard { height: 200px; }
  .flashcard-face { font-size: 1.1rem; padding: 18px; }
  .browse-controls { gap: 10px; }
  .browse-controls .btn { min-width: 84px; padding: 11px 14px; }

  .rating-row { gap: 6px; }
  .btn-rating { min-width: 0; flex: 1 1 calc(50% - 6px); padding: 11px 8px; font-size: 0.85rem; }

  .test-question { padding: 6px; margin-bottom: 12px; }
  .play-stats { margin-bottom: 12px; gap: 6px; }
  .options { gap: 8px; }
  .option-label { padding: 10px 12px; }

  .match-grid { gap: 8px; margin-top: 14px; }
  .match-tile { padding: 10px 8px; min-height: 60px; }

  .score-card { padding: 22px 18px; margin: 0 auto 18px; }
  .score-number { font-size: 2.4rem; }
  .result-row { padding: 12px 14px; margin-bottom: 8px; }

  .card-table th, .card-table td { padding: 10px 12px; font-size: 0.85rem; }
  .deck-cards-table th:nth-child(3), .deck-cards-table td:nth-child(3),
  .deck-cards-table th:nth-child(4), .deck-cards-table td:nth-child(4) { padding-left: 6px; padding-right: 6px; }
  .icon-btn { width: 26px; height: 26px; font-size: 0.9rem; }

  .center-card { margin: 40px auto; padding: 28px 20px; }
  .passcode-dots { gap: 14px; }
  .keypad { gap: 8px; }
  .keypad-btn { padding: 14px 0; font-size: 1.3rem; }

  /* Kiểm tra pages: the +30% desktop sizing overflows small screens */
  .test-page h1 { font-size: 1.5rem; margin-top: 0; }
  .test-page h2 { font-size: 1.15rem; }
  .test-page p, .test-page .muted { font-size: 0.95rem; }
  .test-page .question-num { font-size: 0.8rem; }
  .test-page .question-prompt { font-size: 1.3rem; }
  .test-page .option-label { font-size: 1.2rem; padding: 8px 10px; }
  .test-page .option-label input[type="radio"] { display: none; }
  .test-page .text-answer { font-size: 1rem; }
  .test-page .btn { font-size: 1rem; }
  .test-page .badge { font-size: 0.85rem; }
  .test-page .feedback { font-size: 1rem; }
  .test-page .score-number { font-size: 2.6rem; }
  .test-page .score-card p { font-size: 1rem; }
  .test-page .result-row { font-size: 0.95rem; }
  .test-page .match-tile { font-size: 1rem; min-height: 64px; }
  .test-page .play-stats { font-size: 0.95rem; }
}
