/* ================================================================
   TOEIC Synonym Trainer — Modern Scientific Design
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@500;600;700&display=swap');

:root {
  /* Surface Colors */
  --bg:          #EEF2F7;
  --surface:     #FFFFFF;
  --surface-2:   #F8FAFC;
  --surface-3:   #F1F5F9;

  /* Brand Colors */
  --blue:        #2563EB;
  --blue-deep:   #1D4ED8;
  --blue-light:  #DBEAFE;
  --blue-pale:   #EFF6FF;

  --teal:        #0891B2;
  --teal-deep:   #0E7490;
  --teal-light:  #CFFAFE;

  --green:       #059669;
  --green-deep:  #047857;
  --green-light: #D1FAE5;

  --red:         #DC2626;
  --red-deep:    #B91C1C;
  --red-light:   #FEE2E2;

  --amber:       #D97706;
  --amber-light: #FEF3C7;

  --violet:      #7C3AED;
  --violet-light:#EDE9FE;

  /* Text */
  --text:        #0F172A;
  --text-2:      #334155;
  --text-3:      #64748B;
  --text-4:      #94A3B8;

  /* Borders */
  --border:      #CBD5E1;
  --border-2:    #E2E8F0;
  --border-focus:#93C5FD;

  /* Shadows */
  --shadow-xs:   0 1px 2px rgba(15,23,42,0.06);
  --shadow-sm:   0 1px 3px rgba(15,23,42,0.08), 0 1px 2px rgba(15,23,42,0.06);
  --shadow:      0 4px 8px rgba(15,23,42,0.08), 0 2px 4px rgba(15,23,42,0.05);
  --shadow-md:   0 8px 16px rgba(15,23,42,0.1), 0 4px 8px rgba(15,23,42,0.06);
  --shadow-lg:   0 16px 32px rgba(15,23,42,0.12), 0 8px 16px rgba(15,23,42,0.07);

  /* Radius */
  --r-sm:  6px;
  --r:     10px;
  --r-md:  14px;
  --r-lg:  18px;
  --r-xl:  24px;

  /* Typography */
  --font:      'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
button { font-family: var(--font); cursor: pointer; }

/* ===== Topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  height: 60px;
  box-shadow: var(--shadow-xs);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}

.brand-icon {
  width: 32px;
  height: 32px;
  background: var(--blue);
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  font-family: var(--font-mono);
  letter-spacing: -0.03em;
  flex-shrink: 0;
}

.brand-text {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.brand-text span {
  color: var(--blue);
}

.topnav {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Plain nav links (Thư viện, etc.) */
.topnav > a {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-3);
  padding: 6px 14px;
  border-radius: var(--r-sm);
  transition: all 0.15s ease;
  white-space: nowrap;
}
.topnav > a:hover { color: var(--text); background: var(--surface-3); }
.topnav > a.active { color: var(--blue); background: var(--blue-pale); font-weight: 600; }

/* Disabled "coming soon" items */
.nav-coming-soon {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-4);
  padding: 6px 14px;
  border-radius: var(--r-sm);
  cursor: default;
  opacity: 0.55;
  user-select: none;
  position: relative;
}
.nav-coming-soon::after {
  content: "Sắp có";
  position: absolute;
  top: -6px; right: 4px;
  font-size: 9px;
  font-weight: 700;
  background: var(--amber-light);
  color: var(--amber);
  border-radius: 4px;
  padding: 1px 4px;
  white-space: nowrap;
}

/* ── Nav group (dropdown) ── */
.nav-group {
  position: relative;
}

.nav-group-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-3);
  padding: 6px 14px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  user-select: none;
}
.nav-group-label:hover,
.nav-group:hover .nav-group-label { color: var(--text); background: var(--surface-3); }

.nav-group.active .nav-group-label {
  color: var(--blue);
  background: var(--blue-pale);
  font-weight: 600;
}
.nav-chevron { font-size: 10px; opacity: 0.7; }

/* Dropdown panel — top:100% + padding-top lấp kín khoảng hở */
.nav-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 180px;
  padding-top: 8px;   /* khoảng hở thị giác, nhưng vẫn nằm trong vùng hover */
  z-index: 200;
}

/* Panel nội dung bên trong */
.nav-dropdown-inner {
  background: var(--surface);
  border: 1.5px solid var(--border-2);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  animation: dropdown-in 0.15s ease;
}

@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.nav-group:hover .nav-dropdown,
.nav-group.nav-open .nav-dropdown { display: block; }

.nav-dropdown-header {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-4);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 6px 10px 4px;
}

.nav-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  color: var(--text-2);
  transition: background 0.12s ease;
}
.nav-dropdown-item:hover { background: var(--surface-3); }
.nav-dropdown-item.active {
  background: var(--blue-pale);
  color: var(--blue-deep);
}
.nav-dropdown-item strong {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.2;
}
.nav-dropdown-item em {
  display: block;
  font-size: 11.5px;
  font-style: normal;
  color: var(--text-4);
  margin-top: 1px;
}
.nav-dropdown-item.active em { color: var(--blue-deep); opacity: 0.7; }

/* ===== Page layout ===== */
.page {
  max-width: 960px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

/* ===== Footer ===== */
.footer {
  text-align: center;
  padding: 24px;
  font-size: 12px;
  color: var(--text-4);
  border-top: 1px solid var(--border-2);
  background: var(--surface);
}

/* ===== Hero Section ===== */
.hero {
  text-align: center;
  margin-bottom: 48px;
  padding: 48px 24px;
  background: var(--surface);
  border-radius: var(--r-xl);
  border: 1px solid var(--border-2);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--blue), var(--teal), var(--green));
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--blue-pale);
  color: var(--blue-deep);
  border: 1px solid var(--blue-light);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-mono);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 20px;
}

.hero-badge::before {
  content: "";
  width: 7px; height: 7px;
  background: var(--blue);
  border-radius: 50%;
}

.hero-title {
  font-size: 36px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.03em;
  color: var(--text);
  margin-bottom: 14px;
}

.hero-title strong { color: var(--blue); }

.hero-sub {
  max-width: 520px;
  margin: 0 auto 28px;
  color: var(--text-3);
  font-size: 15px;
  line-height: 1.65;
}

.hero-stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 999px;
  padding: 8px 20px;
}

.stat-num {
  font-size: 20px;
  font-weight: 800;
  color: var(--green);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  color: var(--text-3);
  font-size: 13px;
}

.stat-sep {
  width: 1px;
  height: 16px;
  background: var(--border-2);
}

/* ===== Mode Cards ===== */
.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.mode-card {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  padding: 28px 24px;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  overflow: hidden;
}

.mode-card::after {
  content: "";
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.mode-card--blue::after  { background: var(--blue); }
.mode-card--teal::after  { background: var(--teal); }
.mode-card--green::after { background: var(--green); }

.mode-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
  border-color: var(--border);
}

.mode-card:hover::after { opacity: 1; }

.mode-index-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mode-index {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-4);
  letter-spacing: 0.08em;
}

.mode-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.mode-card--blue .mode-icon  { background: var(--blue-pale); }
.mode-card--teal .mode-icon  { background: var(--teal-light); }
.mode-card--green .mode-icon { background: var(--green-light); }

.mode-card h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.mode-card p {
  color: var(--text-3);
  font-size: 13.5px;
  line-height: 1.6;
  flex-grow: 1;
}

.mode-cta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
}

.mode-card--blue .mode-cta  { color: var(--blue); }
.mode-card--teal .mode-cta  { color: var(--teal-deep); }
.mode-card--green .mode-cta { color: var(--green-deep); }

/* ===== Category note ===== */
.category-note {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r);
  padding: 14px 20px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}

.category-note strong { color: var(--text-2); }

/* ===== Game Header / Controls ===== */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 28px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  padding: 18px 24px;
  box-shadow: var(--shadow-xs);
}

.game-header h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.controls label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ===== Form elements ===== */
.controls select,
select.form-select {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  padding: 8px 36px 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  min-width: 140px;
}

.controls select:hover { border-color: var(--border-focus); }
.controls select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

/* ===== Buttons ===== */
.btn-ghost, .btn-primary, .btn-wrong, .btn-correct {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: var(--r-sm);
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  line-height: 1;
}

.btn-ghost {
  background: var(--surface);
  color: var(--text-2);
  border-color: var(--border);
}
.btn-ghost:hover {
  background: var(--surface-3);
  border-color: var(--border);
  color: var(--text);
}

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

.btn-wrong {
  background: var(--surface);
  color: var(--red);
  border-color: #FECACA;
  font-size: 14px;
  padding: 12px 28px;
}
.btn-wrong:hover { background: var(--red-light); border-color: var(--red); }

.btn-correct {
  background: var(--surface);
  color: var(--green);
  border-color: #A7F3D0;
  font-size: 14px;
  padding: 12px 28px;
}
.btn-correct:hover { background: var(--green-light); border-color: var(--green); }

/* ===== Progress bar ===== */
.flash-progress {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
  width: 100%;
  max-width: 540px;
}

#progress-text {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-3);
  white-space: nowrap;
  font-weight: 500;
}

.progress-bar {
  flex-grow: 1;
  height: 6px;
  background: var(--border-2);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--teal));
  border-radius: 99px;
  width: 0%;
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Flashcard ===== */
.flash-area {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.flashcard {
  width: 100%;
  max-width: 500px;
  height: 300px;
  perspective: 1400px;
  cursor: pointer;
  margin-bottom: 24px;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s cubic-bezier(.4,.2,.2,1);
  transform-style: preserve-3d;
}

.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }

.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--r-lg);
  border: 1.5px solid var(--border-2);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  text-align: center;
}

.flashcard-front {
  background: var(--surface);
}

.flashcard-front::before {
  content: "TOEIC · PART 7";
  position: absolute;
  top: 18px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--text-4);
}

.flashcard-back {
  transform: rotateY(180deg);
  background: linear-gradient(135deg, #EFF6FF 0%, #F0FDF4 100%);
  border-color: var(--blue-light);
}

/* Row: POS badge + category tag on card front */
.card-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  justify-content: center;
}

/* POS badge — color per part-of-speech */
.card-pos-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.card-pos-badge:empty { display: none; }

/* Dynamic colors via JS data-pos attribute */
[data-pos="v"]      { background: #DBEAFE; color: #1D4ED8; }
[data-pos="n"]      { background: #EDE9FE; color: #5B21B6; }
[data-pos="adj"]    { background: #FEF3C7; color: #92400E; }
[data-pos="adv"]    { background: #CFFAFE; color: #0E7490; }
[data-pos="phrase"] { background: #D1FAE5; color: #047857; }
[data-pos="prep"]   { background: #E0E7FF; color: #3730A3; }
[data-pos="conj"]   { background: #FCE7F3; color: #9D174D; }

/* Category chip on card front */
.card-category {
  display: inline-block;
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
}
.card-category:empty { display: none; }

/* Word text (front = large, back = large synonym) */
.card-word {
  font-size: 38px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1.15;
  text-align: center;
}

/* "Từ đồng nghĩa" label on back */
.back-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-4);
  margin-bottom: 14px;
}

/* Vietnamese meaning — BIG and clear */
.card-meaning {
  color: var(--text-2);
  font-size: 22px;
  font-weight: 600;
  margin-top: 12px;
  text-align: center;
  line-height: 1.4;
}

.flip-hint {
  position: absolute;
  bottom: 18px;
  font-size: 11px;
  color: var(--text-4);
  display: flex;
  align-items: center;
  gap: 4px;
}

.flip-hint::before { content: "↻"; font-size: 13px; }

.flashcard-back .flip-hint {
  transform: rotateY(180deg);
}

.flash-actions {
  display: flex;
  gap: 12px;
  margin-top: 4px;
}

.flash-done {
  text-align: center;
  padding: 48px 24px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-lg);
  max-width: 480px;
  width: 100%;
}

.flash-done h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
}

.flash-done p {
  color: var(--text-3);
  margin-bottom: 24px;
  font-size: 14.5px;
}

/* ===== Match game ===== */
.match-stats {
  display: flex;
  gap: 24px;
  justify-content: center;
  font-size: 13.5px;
  color: var(--text-3);
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r);
  padding: 12px 24px;
}

.match-stats strong { color: var(--text); font-weight: 600; }

.match-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 28px;
}

.match-tile {
  aspect-ratio: 1 / 0.9;
  border: 1.5px solid var(--border-2);
  border-radius: var(--r);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px 8px;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
  word-break: break-word;
  color: var(--text);
  line-height: 1.4;
}

.match-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--border); }

.match-tile.synonym-tile {
  background: var(--surface-2);
  color: var(--text-2);
}

.match-tile.selected {
  background: var(--blue-pale);
  border-color: var(--blue);
  color: var(--blue-deep);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

.match-tile.matched {
  background: var(--green-light);
  border-color: var(--green);
  color: var(--green-deep);
  cursor: default;
  opacity: 0.75;
}

.match-tile.wrong-flash {
  background: var(--red-light);
  border-color: var(--red);
  animation: shake 0.3s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ===== Quiz ===== */
.quiz-area {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.quiz-card {
  position: relative;
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border: 1.5px solid var(--border-2);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  padding: 36px 32px;
  text-align: center;
}

.quiz-prompt {
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text-4);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.quiz-word {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
  margin-bottom: 6px;
  line-height: 1.2;
}

.quiz-meaning {
  color: var(--text-3);
  font-size: 14px;
  margin-bottom: 28px;
}

.quiz-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.quiz-option {
  font-size: 14.5px;
  font-weight: 600;
  padding: 14px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.15s ease;
  color: var(--text);
  line-height: 1.4;
}

.quiz-option:hover:not(.disabled) {
  background: var(--surface-3);
  border-color: var(--blue);
  color: var(--blue-deep);
  transform: translateY(-1px);
}

.quiz-option.correct {
  background: var(--green-light);
  border-color: var(--green);
  color: var(--green-deep);
}

.quiz-option.incorrect {
  background: var(--red-light);
  border-color: var(--red);
  color: var(--red-deep);
}

.quiz-option.disabled { pointer-events: none; }

/* Quiz card meta row (category + pos) */
.quiz-card-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.quiz-pos {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  border-radius: 999px;
  padding: 3px 10px;
}
.quiz-pos:empty { display: none; }

/* ── Plant badge (top-right of quiz card) ── */
.plant-badge-wrap {
  position: absolute;
  top: 14px;
  right: 16px;
}
.plant-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1.5px solid;
}
.plant-badge .plant-icon { font-size: 15px; line-height: 1; }
.plant-badge .plant-label { font-size: 11.5px; }

/* Plant stage colors — badge & result */
.plant-seed   { background: #FFF7ED; border-color: #FED7AA; color: #92400E; }
.plant-sprout { background: #F0FDF4; border-color: #BBF7D0; color: #065F46; }
.plant-bloom  { background: #FDF2F8; border-color: #F9A8D4; color: #9D174D; }
.plant-mature { background: #F0FDF4; border-color: #6EE7B7; color: #047857; }
.plant-water  { background: #EFF6FF; border-color: #BFDBFE; color: #1E40AF; }

/* ── Feedback + plant result ── */
.quiz-feedback-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border-2);
}
.quiz-feedback {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-3);
  text-align: center;
}
.fb-correct { color: var(--green-deep); font-weight: 700; }
.fb-wrong   { color: var(--red-deep);   font-weight: 700; }

/* Plant result block shown after answering */
.plant-result-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  border-radius: var(--r-md);
  border: 1.5px solid;
  min-width: 220px;
  justify-content: center;
}
.plant-result-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.plant-result-text strong {
  font-size: 14px;
  font-weight: 700;
}
.plant-result-text span {
  font-size: 12px;
  opacity: 0.75;
}

/* Level-up row: old → new */
.plant-levelup {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 22px;
  line-height: 1;
}
.plant-old   { opacity: 0.45; font-size: 18px; }
.plant-arrow { font-size: 14px; color: var(--text-4); }
.plant-new   { font-size: 28px; }

/* Normal row */
.plant-result-row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.plant-icon-lg { font-size: 28px; line-height: 1; }

/* Bounce animation for new plant stage */
.plant-anim {
  display: inline-block;
  animation: plant-grow 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes plant-grow {
  0%   { transform: scale(0.4) rotate(-10deg); opacity: 0; }
  60%  { transform: scale(1.15) rotate(3deg); }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* ===== Score badge ===== */
.score-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--r);
  padding: 8px 16px;
  font-size: 14px;
  color: var(--text-2);
  margin-top: 8px;
}

.score-badge strong { color: var(--green-deep); font-size: 18px; }

/* ===== Library page ===== */
.lib-header {
  margin-bottom: 24px;
}
.lib-title {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 4px;
}
.lib-subtitle { font-size: 14px; color: var(--text-3); }

/* Stats row */
.lib-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.lib-stat-card {
  background: var(--surface);
  border: 1.5px solid var(--border-2);
  border-radius: var(--r-md);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  overflow: hidden;
}
.lib-stat-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.lib-stat--total::before   { background: var(--text-3); }
.lib-stat--mastered::before{ background: var(--green); }
.lib-stat--learning::before{ background: var(--blue); }
.lib-stat--new::before     { background: var(--text-4); }
.lib-stat--review::before  { background: var(--amber); }

.lib-stat-num {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
}
.lib-stat--total .lib-stat-num   { color: var(--text); }
.lib-stat--mastered .lib-stat-num{ color: var(--green-deep); }
.lib-stat--learning .lib-stat-num{ color: var(--blue-deep); }
.lib-stat--new .lib-stat-num     { color: var(--text-3); }
.lib-stat--review .lib-stat-num  { color: var(--amber); }
.lib-stat-label { font-size: 12px; color: var(--text-3); font-weight: 500; }

/* Forgetting curve legend */
.curve-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r);
  font-size: 12.5px;
}
.curve-legend-title { color: var(--text-3); font-weight: 500; margin-right: 4px; }

/* Controls */
.lib-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.lib-search-wrap {
  position: relative;
  flex: 1;
  min-width: 180px;
}
.lib-search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-4);
  font-size: 17px;
  pointer-events: none;
}
.lib-search {
  font-family: var(--font);
  font-size: 14px;
  width: 100%;
  padding: 8px 12px 8px 34px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.lib-search:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.lib-controls .select {
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  padding: 8px 32px 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 8px center;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  cursor: pointer;
}
.lib-controls .select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

/* Table */
.lib-table-wrap {
  background: var(--surface);
  border: 1.5px solid var(--border-2);
  border-radius: var(--r-md);
  overflow: hidden; /* clipped on desktop */
  box-shadow: var(--shadow-sm);
}
.lib-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.lib-table thead tr {
  background: var(--surface-2);
  border-bottom: 1.5px solid var(--border-2);
}
.lib-table th {
  padding: 11px 14px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.lib-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-2);
  vertical-align: middle;
}
.lib-table tbody tr:last-child td { border-bottom: none; }
.lib-table tbody tr:hover { background: var(--surface-2); }
.lib-table tbody tr.row-needs-review { background: #FFFBEB; }
.lib-table tbody tr.row-needs-review:hover { background: #FEF3C7; }

.lib-loading {
  text-align: center;
  padding: 40px;
  color: var(--text-3);
}
.lib-empty {
  text-align: center;
  padding: 48px;
  color: var(--text-3);
  font-size: 14px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--r-md);
  margin-top: 8px;
}

.word-text {
  font-weight: 700;
  color: var(--text);
  font-size: 14.5px;
}
.syn-text {
  color: var(--blue-deep);
  font-weight: 600;
}
.needs-review-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  background: var(--amber);
  color: #fff;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  margin-left: 6px;
  vertical-align: middle;
}
.cat-chip {
  display: inline-block;
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 11.5px;
  color: var(--text-2);
  white-space: nowrap;
}

/* Box badge */
.box-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.box-new      { background: var(--surface-3); color: var(--text-3); border: 1px solid var(--border-2); }
.box-1        { background: #EDE9FE; color: #5B21B6; }
.box-2        { background: var(--blue-pale); color: var(--blue-deep); }
.box-3        { background: var(--amber-light); color: #92400E; }
.box-mastered { background: var(--green-light); color: var(--green-deep); }

/* Retention bar */
.ret-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ret-bar-track {
  flex: 1;
  height: 6px;
  background: var(--border-2);
  border-radius: 99px;
  overflow: hidden;
  min-width: 60px;
}
.ret-bar-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.3s ease;
}
.ret-fill-ret-great { background: var(--green); }
.ret-fill-ret-ok    { background: var(--blue); }
.ret-fill-ret-warn  { background: var(--amber); }
.ret-fill-ret-bad   { background: var(--red); }

.ret-pct {
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-mono);
  min-width: 34px;
  text-align: right;
}
.ret-pct.ret-great { color: var(--green-deep); }
.ret-pct.ret-ok    { color: var(--blue-deep); }
.ret-pct.ret-warn  { color: var(--amber); }
.ret-pct.ret-bad   { color: var(--red-deep); }

.ret-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.ret-badge.ret-great { background: var(--green-light); color: var(--green-deep); }
.ret-badge.ret-ok    { background: var(--blue-pale);   color: var(--blue-deep); }
.ret-badge.ret-warn  { background: var(--amber-light); color: #92400E; }
.ret-badge.ret-bad   { background: var(--red-light);   color: var(--red-deep); }
.ret-badge.ret-new   { background: var(--surface-3);   color: var(--text-3); border: 1px solid var(--border-2); }

/* Re-learn button */
.btn-relearn {
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: var(--r-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn-relearn:hover {
  background: var(--blue-pale);
  border-color: var(--blue);
  color: var(--blue-deep);
}
.btn-relearn-na { color: var(--text-4); font-size: 13px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--text);
  color: #fff;
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 9999;
  white-space: nowrap;
}
.toast.toast-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Bottom Navigation (mobile only) ===== */
.bottom-nav { display: none; }

@media (max-width: 760px) {
  /* Hide desktop nav */
  .topnav { display: none; }

  /* Bottom tab bar */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: rgba(255,255,255,0.97);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-2);
    box-shadow: 0 -2px 12px rgba(15,23,42,0.08);
    z-index: 200;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .bnav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 4px 6px;
    gap: 3px;
    color: var(--text-4);
    transition: color 0.15s ease;
    min-height: 54px;
    -webkit-tap-highlight-color: transparent;
    text-decoration: none;
    user-select: none;
  }
  .bnav-item.active { color: var(--blue); }
  .bnav-item:active { opacity: 0.6; }
  .bnav-icon { width: 22px; height: 22px; flex-shrink: 0; }
  .bnav-label { font-size: 10px; font-weight: 500; line-height: 1; }

  /* Page bottom padding to clear bottom nav */
  .page {
    padding: 24px 16px calc(64px + env(safe-area-inset-bottom, 0px));
  }

  /* Topbar */
  .topbar { padding: 0 16px; }

  /* Footer hidden — bottom nav takes over */
  .footer { display: none; }

  /* ── Hero ── */
  .hero { padding: 28px 16px 24px; margin-bottom: 20px; }
  .hero-title { font-size: 23px; }
  .hero-sub { font-size: 14px; margin-bottom: 20px; }
  .hero-stats { flex-wrap: wrap; gap: 8px; }
  .stat-pill { padding: 7px 16px; font-size: 13px; }

  /* ── Mode cards ── */
  .mode-grid { grid-template-columns: 1fr; gap: 10px; margin-bottom: 20px; }
  .mode-card { padding: 20px 18px; }

  /* ── Game header ── */
  .game-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
  }
  .game-header h1 { font-size: 18px; }
  .controls { width: 100%; flex-wrap: wrap; }
  .controls select { flex: 1; min-width: 0; font-size: 14px; }

  /* ── Flashcard ── */
  .flash-progress { max-width: 100%; }
  .flashcard {
    max-width: 100%;
    height: auto;
    aspect-ratio: 3 / 2;
    min-height: 200px;
  }
  .card-word { font-size: clamp(22px, 9vw, 38px); }
  .card-meaning { font-size: clamp(15px, 5vw, 22px); }
  .flashcard-face { padding: 20px 16px; }

  /* Bigger touch targets for flash answer buttons */
  .flash-actions {
    width: 100%;
    max-width: 500px;
    gap: 10px;
  }
  .btn-wrong, .btn-correct {
    flex: 1;
    min-height: 52px;
    padding: 14px 10px;
    font-size: 15px;
    border-radius: var(--r);
  }

  /* Swipe hint */
  .swipe-hint {
    font-size: 11.5px;
    color: var(--text-4);
    text-align: center;
    margin-top: -8px;
    margin-bottom: 8px;
  }

  /* ── Match grid ── */
  .match-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .match-tile { font-size: 12px; padding: 10px 6px; }
  .match-stats { gap: 16px; font-size: 13px; padding: 10px 16px; }

  /* ── Quiz ── */
  .quiz-card { padding: 24px 16px 20px; }
  .quiz-word { font-size: clamp(22px, 8vw, 34px); }
  .quiz-options { grid-template-columns: 1fr; gap: 8px; }
  .quiz-option {
    min-height: 52px;
    padding: 14px 14px;
    font-size: 15px;
    text-align: left;
  }
  .plant-badge-wrap { top: 10px; right: 12px; }

  /* ── Library ── */
  .lib-stats { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .lib-stats .lib-stat--review { grid-column: unset; }
  .lib-stat-card { padding: 12px 14px; }
  .lib-stat-num { font-size: 22px; }
  .lib-controls { gap: 8px; }
  .lib-controls .select { font-size: 13px; }
  /* ── Library: chuyển sang dạng thẻ, tự căng theo màn hình ── */
  .lib-table-wrap { overflow: visible; border-radius: 0; border: none; box-shadow: none; background: transparent; }
  .lib-table thead { display: none; }
  .lib-table,
  .lib-table tbody { display: block; width: 100%; }
  .lib-table tr {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--border-2);
    border-radius: var(--r);
    margin-bottom: 8px;
    box-shadow: var(--shadow-xs);
  }
  .lib-table tr.row-needs-review { background: #FFFBEB; }
  .lib-table td { display: block; border: none; padding: 0; }
  .col-cat, .col-vi, .col-ret, .col-box { display: none; }
  .col-word { flex: 1; min-width: 0; }
  .col-syn  { flex: 1; min-width: 0; }
  .col-action { flex-shrink: 0; }
  .col-word .word-text { display: block; font-size: 14px; font-weight: 700; }
  .col-syn  .syn-text  { display: block; font-size: 13px; color: var(--blue-deep); }
  .needs-review-dot { vertical-align: middle; }
  .lib-table tbody tr:hover { background: var(--surface-2); }
  .curve-legend { font-size: 11px; gap: 6px; padding: 10px 12px; }

  /* ── General buttons ── */
  .btn-ghost, .btn-primary { min-height: 44px; padding: 10px 18px; }

  /* Flash done / match done */
  .flash-done { padding: 32px 16px; }
}

/* Very small phones (< 370px) */
@media (max-width: 369px) {
  .match-grid { grid-template-columns: repeat(2, 1fr); }
  .match-tile { font-size: 11.5px; }
  .hero-title { font-size: 20px; }
  .bnav-label { display: none; }
  .bnav-item { min-height: 48px; }
  .bnav-icon { width: 24px; height: 24px; }
}
