:root {
  --bg: #eef3fb;
  --card: #ffffff;
  --ink: #22314e;
  --muted: #6b7a99;
  --primary: #3b6ef5;
  --primary-dark: #2c53c9;
  --accent: #ff7a59;
  --green: #22b573;
  --red: #ff5a76;
  --yellow: #ffb020;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(38, 64, 120, 0.12);
  --shadow-sm: 0 4px 14px rgba(38, 64, 120, 0.10);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Nunito", system-ui, -apple-system, sans-serif;
  background: linear-gradient(160deg, #eaf1ff 0%, #f7f2ff 45%, #fff5ef 100%);
  color: var(--ink);
  min-height: 100vh;
}

h1, h2, h3, h4 { font-family: "Baloo 2", "Nunito", sans-serif; margin: 0 0 .4em; }

/* ---------- TOP BAR ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  padding: 16px 28px;
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(59, 110, 245, 0.12);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo { font-size: 38px; }
.topbar h1 { font-size: 22px; color: var(--primary-dark); }
.sub { margin: 0; color: var(--muted); font-size: 13px; }

.nav { display: flex; gap: 6px; flex-wrap: wrap; }
.nav-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-weight: 700;
  font-size: 14px;
  padding: 9px 14px;
  border-radius: 12px;
  cursor: pointer;
  transition: all .15s ease;
}
.nav-btn:hover { background: rgba(59, 110, 245, 0.10); color: var(--primary-dark); }
.nav-btn.active { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }

/* ---------- LAYOUT ---------- */
#app { max-width: 900px; margin: 0 auto; padding: 26px 20px 60px; }
.view { display: none; animation: fade .25s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.view-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.view-head h2 { color: var(--primary-dark); }

/* ---------- HERO ---------- */
.hero {
  background: linear-gradient(120deg, var(--primary), #6b8cff);
  color: #fff;
  padding: 28px 30px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 22px;
}
.hero h2 { color: #fff; font-size: 26px; }
.hero p { margin: 0; opacity: .95; }

/* ---------- TYPE CARDS ---------- */
.type-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 22px; }
.type-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  text-align: center;
  border: 2px solid transparent;
  transition: transform .15s ease, border-color .15s ease;
}
.type-card:hover { transform: translateY(-4px); border-color: var(--primary); }
.type-icon { font-size: 46px; }
.type-card h3 { color: var(--primary-dark); margin-top: 8px; }
.type-card p { color: var(--muted); min-height: 44px; }

/* ---------- BUTTONS ---------- */
.btn {
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  border: none;
  border-radius: 12px;
  padding: 11px 18px;
  cursor: pointer;
  transition: all .15s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.secondary { background: #fff3ee; color: var(--accent); }
.btn.secondary:hover { background: #ffe6db; }
.btn.ghost { background: rgba(59, 110, 245, 0.08); color: var(--primary-dark); }
.btn.ghost:hover { background: rgba(59, 110, 245, 0.16); }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn.big { padding: 15px 26px; font-size: 17px; }
.btn.record { background: var(--green); color: #fff; }
.btn.record:hover { filter: brightness(.95); }
.btn.stop { background: var(--red); color: #fff; }
.btn.record.recording { background: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,90,118,.5);} 50% { box-shadow: 0 0 0 10px rgba(255,90,118,0);} }

/* ---------- PROGRESS PANEL ---------- */
.progress-panel, .tips-panel {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}
.progress-panel h3, .tips-panel h3 { color: var(--primary-dark); }
.progress-stats { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.stat {
  flex: 1;
  min-width: 130px;
  background: #f4f7ff;
  border-radius: 14px;
  padding: 16px;
  text-align: center;
}
.stat .num { font-size: 30px; font-weight: 800; font-family: "Baloo 2"; }
.stat .lbl { color: var(--muted); font-size: 13px; }
.stat.good .num { color: var(--green); }
.stat.ok .num { color: var(--yellow); }
.stat.hard .num { color: var(--red); }
.stat.streak { background: #fff2e8; }
.stat.streak .num { color: var(--accent); }
.stat.reps { background: #eaf7ff; }
.stat.reps .num { color: var(--primary); }

/* ---------- SCORE BOX (tự chấm điểm) ---------- */
.score-box {
  display: flex; align-items: center; gap: 18px;
  background: #f4f7ff; border-radius: 14px; padding: 18px; margin-bottom: 16px;
}
.score-ring {
  flex: 0 0 auto;
  width: 86px; height: 86px; border-radius: 50%;
  background: conic-gradient(var(--green) 0deg, #e6ecfb 0deg);
  display: flex; align-items: center; justify-content: center;
}
.score-ring span {
  width: 66px; height: 66px; border-radius: 50%; background: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: "Baloo 2"; font-weight: 700; font-size: 20px;
}
.score-info { flex: 1; }
.score-info h4 { margin: 0 0 8px; }
.score-line { margin: 4px 0; font-size: 14px; }
.wtags { display: inline; }
.wtag {
  display: inline-block; background: #e3f5ec; color: #1c9c63;
  padding: 2px 9px; border-radius: 999px; font-size: 13px; font-weight: 700; margin: 2px;
}
.score-line b { color: var(--ink); }
#scoreMissing .wtag { background: #ffeaea; color: #d94b62; }

/* ---------- SHADOW (nói theo mẫu) ---------- */
.shadow-context { background: #fff; border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow-sm); margin-bottom: 12px; }
.ctx-q { font-weight: 800; color: var(--primary-dark); margin-bottom: 4px; }
.ctx-vi { color: var(--muted); font-style: italic; font-size: 14px; }
.rec-controls.center { justify-content: center; margin-bottom: 14px; }
.tips-panel ul { margin: 0; padding-left: 20px; line-height: 1.8; }

/* ---------- VOICE SETTINGS ---------- */
.voice-controls {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 14px;
  margin: 12px 0;
}
.voice-controls label {
  display: flex; flex-direction: column; gap: 6px;
  font-weight: 700; font-size: 13px; color: var(--ink);
}
.voice-controls select,
.voice-controls input[type="range"] {
  font-family: inherit; font-size: 14px; font-weight: 600;
  padding: 8px 10px; border-radius: 10px; border: 1px solid #d5deef; background: #fff;
}
.voice-controls input[type="range"] { padding: 0; }
.voice-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.voice-hint { font-size: 13px; margin: 6px 0 0; line-height: 1.5; }

@media (max-width: 640px) {
  .voice-controls { grid-template-columns: 1fr; }
}

/* ---------- SEGMENTED ---------- */
.seg { display: inline-flex; background: #e6ecfb; border-radius: 12px; padding: 4px; }
.seg-btn { border: none; background: transparent; font-family: inherit; font-weight: 700; padding: 8px 16px; border-radius: 9px; cursor: pointer; color: var(--muted); }
.seg-btn.active { background: #fff; color: var(--primary-dark); box-shadow: var(--shadow-sm); }

/* ---------- BANK LIST ---------- */
.bank-desc { color: var(--muted); background: #fff; padding: 14px 18px; border-radius: 14px; box-shadow: var(--shadow-sm); }
.cat-block { margin-bottom: 22px; }
.cat-title { color: var(--primary-dark); font-size: 18px; margin: 18px 0 10px; }
.q-item {
  background: var(--card);
  border-radius: 14px;
  padding: 14px 18px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: transform .12s ease;
  border-left: 5px solid #e6ecfb;
}
.q-item:hover { transform: translateX(4px); }
.q-item.good { border-left-color: var(--green); }
.q-item.ok { border-left-color: var(--yellow); }
.q-item.hard { border-left-color: var(--red); }
.q-item .qtxt { font-weight: 700; }
.q-item .qsub { color: var(--muted); font-size: 13px; font-weight: 400; }
.q-item .go { color: var(--primary); font-weight: 800; font-size: 20px; }

/* ---------- PRACTICE ---------- */
.back-btn { margin-bottom: 12px; }
.practice-card { background: var(--card); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.practice-meta { display: flex; gap: 10px; margin-bottom: 14px; }
.pill { background: #eef3ff; color: var(--primary-dark); font-weight: 700; font-size: 13px; padding: 5px 12px; border-radius: 999px; }
.pill.count { background: #fff3ee; color: var(--accent); }

.question-box { background: #f4f7ff; border-radius: 14px; padding: 20px; margin-bottom: 16px; }
.question-box.big { padding: 26px; }
.q-en { font-size: 21px; font-weight: 800; font-family: "Baloo 2"; color: var(--ink); margin: 0 0 12px; }
.q-vi { color: var(--muted); font-style: italic; margin: 12px 0 0; }
.a-en { font-size: 17px; line-height: 1.7; margin: 0 0 8px; }
.a-vi { color: var(--muted); font-style: italic; line-height: 1.6; }

.timer-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.timer { font-family: "Baloo 2"; font-size: 30px; font-weight: 700; color: var(--primary-dark); }
.rec-controls { display: flex; gap: 8px; }

audio { width: 100%; margin-bottom: 14px; }

.transcript-box { background: #fffdf3; border: 1px dashed var(--yellow); border-radius: 14px; padding: 16px; margin-bottom: 16px; }
.transcript-box h4 { margin: 0 0 6px; }
#transcript { font-size: 16px; margin: 0 0 6px; }

.answer-toggle { margin-bottom: 12px; }
.answer-box { background: #f2fbf6; border: 1px solid #cdeede; border-radius: 14px; padding: 20px; margin-bottom: 16px; }
.answer-box h4 { color: var(--green); margin-top: 16px; }
.answer-box h4:first-child { margin-top: 0; }
.tips { background: #fff; border-radius: 10px; padding: 12px 14px; color: var(--ink); line-height: 1.6; }

.vocab-inline { display: flex; flex-direction: column; gap: 8px; }
.vchip { background: #fff; border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow-sm); }
.vchip b { color: var(--primary-dark); }
.vchip .ipa { color: var(--accent); font-style: italic; margin: 0 8px; }
.vchip .mean { color: var(--muted); }

.mark-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; padding-top: 6px; }
.mark-row span { color: var(--muted); font-weight: 700; margin-right: 4px; }
.btn.mark { background: #f0f3fa; color: var(--ink); }
.btn.mark.hard.sel { background: var(--red); color: #fff; }
.btn.mark.ok.sel { background: var(--yellow); color: #fff; }
.btn.mark.good.sel { background: var(--green); color: #fff; }

.nav-row { display: flex; justify-content: space-between; gap: 12px; }
.nav-row.center { justify-content: center; align-items: center; }

/* ---------- MOCK ---------- */
.mock-setup { background: var(--card); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow-sm); }
.mock-options { display: flex; gap: 18px; flex-wrap: wrap; margin: 18px 0; }
.mock-options label { font-weight: 700; display: flex; flex-direction: column; gap: 6px; color: var(--ink); }
.mock-options select { font-family: inherit; font-size: 15px; padding: 9px 12px; border-radius: 10px; border: 1px solid #d5deef; background: #fff; }
.mock-options .chk { flex-direction: row; align-items: center; gap: 8px; }
.mock-progress { height: 10px; background: #e6ecfb; border-radius: 999px; overflow: hidden; margin-bottom: 10px; }
#mockBar { height: 100%; width: 0; background: var(--primary); transition: width .3s ease; }
.mock-step { color: var(--muted); font-weight: 700; }
.mock-done { background: var(--card); border-radius: var(--radius); padding: 26px; box-shadow: var(--shadow); text-align: center; }
.mock-done h2 { color: var(--green); }
.rec-item { background: #f4f7ff; border-radius: 12px; padding: 14px; margin: 10px 0; text-align: left; }
.rec-item p { font-weight: 700; margin: 0 0 8px; }

/* ---------- FLASHCARD ---------- */
.flashcard { perspective: 1200px; max-width: 460px; margin: 20px auto; height: 240px; cursor: pointer; }
.flash-inner { position: relative; width: 100%; height: 100%; transition: transform .5s; transform-style: preserve-3d; }
.flashcard.flipped .flash-inner { transform: rotateY(180deg); }
.flash-front, .flash-back {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  box-shadow: var(--shadow);
  padding: 24px;
}
.flash-front { background: var(--card); }
.flash-back { background: linear-gradient(120deg, var(--primary), #6b8cff); color: #fff; transform: rotateY(180deg); }
.flash-word { font-family: "Baloo 2"; font-size: 32px; font-weight: 700; color: var(--primary-dark); text-align: center; }
.flash-ipa { color: var(--accent); font-style: italic; font-size: 18px; }
.flash-mean { font-size: 26px; font-weight: 800; text-align: center; }
.flash-count { color: var(--muted); font-weight: 700; }

/* ---------- PHRASES ---------- */
.phrase-list { display: grid; gap: 12px; }
.phrase-item { background: var(--card); border-radius: 14px; padding: 16px 18px; box-shadow: var(--shadow-sm); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.phrase-item .en { font-weight: 800; font-size: 16px; }
.phrase-item .vi { color: var(--muted); font-size: 14px; }

/* ---------- MISC ---------- */
.hidden { display: none !important; }
.muted { color: var(--muted); }
small.muted { font-size: 12px; }
.foot { text-align: center; color: var(--muted); padding: 20px; font-weight: 700; }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .topbar h1 { font-size: 18px; }
  .type-grid { grid-template-columns: 1fr; }
  .nav-btn { padding: 8px 10px; font-size: 13px; }
  .q-en { font-size: 18px; }
  .hero { padding: 22px; }
}
