:root {
  --bg: #f4f8fb;
  --surface: #ffffff;
  --primary: #2a9d8f;
  --primary-dark: #21867a;
  --accent: #e9c46a;
  --text: #22333b;
  --text-soft: #5b6b73;
  --border: #e2eaf0;
  --success: #43aa8b;
  --error: #e76f51;
  --shadow: 0 4px 20px rgba(42,157,143,.08);
  --radius: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* Header */
header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  padding: 1.1rem 1.5rem;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
}
.logo { font-size: 1.3rem; font-weight: 700; display: flex; align-items: center; gap: .5rem; }
.logo small { font-weight: 400; opacity: .85; font-size: .8rem; }
.streak-badge {
  background: rgba(255,255,255,.2);
  padding: .35rem .8rem;
  border-radius: 999px;
  font-size: .9rem;
  font-weight: 600;
}

/* Nav */
nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 60px;
  z-index: 90;
}
.nav-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  overflow-x: auto;
}
.nav-btn {
  flex: 1;
  min-width: 90px;
  border: none;
  background: none;
  padding: .85rem .5rem;
  cursor: pointer;
  font-size: .82rem;
  color: var(--text-soft);
  font-weight: 600;
  border-bottom: 3px solid transparent;
  transition: all .25s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .2rem;
}
.nav-btn .icon { font-size: 1.25rem; }
.nav-btn:hover { color: var(--primary); background: #f0f7f6; }
.nav-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Main */
main { max-width: 960px; margin: 0 auto; padding: 1.5rem; }
.view { animation: fadeIn .4s ease; }
.view[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

h2.view-title { font-size: 1.5rem; margin-bottom: .3rem; }
p.view-sub { color: var(--text-soft); margin-bottom: 1.4rem; }

/* Cards & buttons */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: .7rem 1.4rem;
  border-radius: 999px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .15s ease, background .2s ease;
}
.btn:hover { background: var(--primary-dark); transform: translateY(-2px); }
.btn:active { transform: translateY(0); }
.btn.secondary { background: #eef4f3; color: var(--primary-dark); }
.btn.secondary:hover { background: #e0edeb; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* Flashcard */
.flash-wrap { display: flex; flex-direction: column; align-items: center; gap: 1.2rem; }
.flashcard {
  width: 100%;
  max-width: 420px;
  height: 260px;
  perspective: 1200px;
  cursor: pointer;
}
.flash-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform .6s;
  transform-style: preserve-3d;
}
.flashcard.flipped .flash-inner { transform: rotateY(180deg); }
.flash-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  text-align: center;
  box-shadow: var(--shadow);
}
.flash-front { background: var(--surface); border: 2px solid var(--border); }
.flash-back { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; transform: rotateY(180deg); }
.flash-word { font-size: 2rem; font-weight: 700; }
.flash-ipa { color: var(--text-soft); font-size: 1.1rem; margin-top: .3rem; }
.flash-back .flash-ipa { color: rgba(255,255,255,.85); }
.flash-vi { font-size: 1.8rem; font-weight: 700; }
.flash-ex { margin-top: .8rem; font-style: italic; opacity: .9; }
.flash-topic { position: absolute; top: 12px; right: 14px; font-size: .7rem; background: var(--accent); color: #22333b; padding: .2rem .6rem; border-radius: 999px; font-weight: 700; }
.flash-hint { color: var(--text-soft); font-size: .85rem; }

.rate-row { display: flex; gap: .6rem; flex-wrap: wrap; justify-content: center; }
.rate-btn { padding: .6rem 1rem; border-radius: 12px; border: none; cursor: pointer; font-weight: 600; font-size: .85rem; transition: transform .15s; }
.rate-btn:hover { transform: translateY(-2px); }
.rate-again { background: #fde8e2; color: #c0432a; }
.rate-hard { background: #fdf2d9; color: #a97b17; }
.rate-good { background: #dcefe9; color: #21867a; }
.rate-easy { background: #d7 efdd; color: #2d7d46; }
.rate-easy { background: #d7efdd; color: #2d7d46; }

.speak-icon-btn {
  background: #eef4f3; border: none; width: 46px; height: 46px; border-radius: 50%;
  cursor: pointer; font-size: 1.2rem; transition: background .2s, transform .15s;
  display: inline-flex; align-items: center; justify-content: center;
}
.speak-icon-btn:hover { background: #dcefe9; transform: scale(1.08); }

/* Pronunciation */
.pron-list { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.pron-item { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.pron-item .pw { font-weight: 700; font-size: 1.1rem; }
.pron-item .pi { color: var(--text-soft); font-size: .9rem; }
.speed-row { display: flex; align-items: center; gap: .8rem; margin: 1rem 0 1.5rem; flex-wrap: wrap; }
.speed-row input[type=range] { flex: 1; min-width: 140px; accent-color: var(--primary); }

/* Grammar */
.lesson-list { display: grid; gap: 1rem; }
.lesson-card { cursor: pointer; transition: transform .15s, box-shadow .2s; }
.lesson-card:hover { transform: translateY(-3px); box-shadow: 0 8px 28px rgba(42,157,143,.15); }
.lesson-card h3 { color: var(--primary-dark); margin-bottom: .2rem; }
.lesson-card .vi-title { color: var(--text-soft); font-size: .9rem; }
.lesson-detail .explain-box { background: #f0f7f6; border-left: 4px solid var(--primary); padding: 1rem; border-radius: 10px; margin: 1rem 0; }
.lesson-detail .explain-box .en { margin-bottom: .6rem; }
.lesson-detail .explain-box .vi { color: var(--text-soft); }

/* Quiz / questions */
.question-block { margin-bottom: 1.2rem; }
.question-block .q-text { font-weight: 600; margin-bottom: .7rem; font-size: 1.05rem; }
.options { display: grid; gap: .55rem; }
.opt-btn {
  text-align: left; background: var(--surface); border: 2px solid var(--border);
  padding: .7rem 1rem; border-radius: 12px; cursor: pointer; font-size: .95rem;
  transition: all .18s ease;
}
.opt-btn:hover:not(:disabled) { border-color: var(--primary); background: #f0f7f6; }
.opt-btn.correct { border-color: var(--success); background: #e3f4ee; color: #1d6b56; font-weight: 600; }
.opt-btn.wrong { border-color: var(--error); background: #fbe7e0; color: #b23a1e; font-weight: 600; }
.opt-btn:disabled { cursor: default; }
.feedback { margin-top: .7rem; padding: .7rem 1rem; border-radius: 10px; font-size: .9rem; animation: fadeIn .3s; }
.feedback.ok { background: #e3f4ee; color: #1d6b56; }
.feedback.no { background: #fbe7e0; color: #b23a1e; }

.quiz-progress { color: var(--text-soft); font-size: .9rem; margin-bottom: 1rem; }
.quiz-result { text-align: center; padding: 1rem; }
.quiz-result .score-big { font-size: 3rem; font-weight: 800; color: var(--primary); }

/* Dashboard */
.stat-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); margin-bottom: 1.5rem; }
.stat-card { text-align: center; }
.stat-card .num { font-size: 2.2rem; font-weight: 800; color: var(--primary); }
.stat-card .lbl { color: var(--text-soft); font-size: .85rem; }
.bar-row { margin-bottom: .9rem; }
.bar-row .bar-label { display: flex; justify-content: space-between; font-size: .88rem; margin-bottom: .3rem; }
.bar-track { background: #e8f0ef; border-radius: 999px; height: 14px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; transition: width .8s ease; }
.bar-fill.new { background: #c9d6db; }
.bar-fill.learning { background: var(--accent); }
.bar-fill.mastered { background: var(--success); }
.topic-bars { margin-top: 1rem; }

.reset-link { background: none; border: none; color: var(--error); cursor: pointer; font-size: .85rem; text-decoration: underline; margin-top: 1rem; }

.empty { text-align: center; color: var(--text-soft); padding: 2rem 1rem; }

footer { text-align: center; padding: 2rem 1rem; color: var(--text-soft); font-size: .8rem; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(100px);
  background: var(--text); color: #fff; padding: .8rem 1.4rem; border-radius: 999px;
  font-size: .9rem; box-shadow: 0 6px 24px rgba(0,0,0,.2); opacity: 0;
  transition: all .4s ease; z-index: 200; pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

@media (max-width: 600px) {
  main { padding: 1rem; }
  .nav-btn { font-size: .72rem; }
  .flash-word { font-size: 1.6rem; }
}

/* Accessibility focus */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
