:root {
  --bg: #0a0c0f;
  --bg-soft: #11151a;
  --card: #14191f;
  --card-2: #1a2027;
  --line: #232b34;
  --text: #e8edf2;
  --muted: #8b98a6;
  --accent: #d7ff3e;
  --accent-ink: #10140a;
  --good: #4ade80;
  --bad: #fb7185;
  --warn: #fbbf24;
  --radius: 14px;
  --pad: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

body {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 0 calc(env(safe-area-inset-bottom) + 24px);
}

#app { max-width: 720px; margin: 0 auto; padding: 0 14px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h1 { font-size: 21px; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 17px; margin: 0; letter-spacing: -0.01em; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 2px 14px;
}
.topbar h1 { flex: 1; }
.topbar p { margin: 2px 0 0; font-size: 13px; }

.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  font-size: 19px;
  text-decoration: none;
  cursor: pointer;
  flex: 0 0 auto;
  transition: border-color .15s, background .15s;
}
.icon-btn:hover { border-color: #35404c; }

/* ---------- chips ---------- */
.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 14px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }

.chip {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 15px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.small { padding: 6px 11px; font-size: 13px; }

/* ---------- danh sách bài ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }

.article-card {
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  transition: border-color .15s, transform .1s;
}
.article-card:active { transform: scale(.995); }
.article-card:hover { border-color: #35404c; }

.article-card h3 { margin: 0 0 8px; font-size: 16px; font-weight: 650; line-height: 1.35; letter-spacing: -0.01em; }
.card-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 12.5px; color: var(--muted); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .02em;
  background: #23303b;
  color: #cfe3f5;
  border: 1px solid #2d3c49;
}
.badge.lv-A2 { background: #16302a; color: #6ee7b7; border-color: #1f4d40; }
.badge.lv-B1 { background: #2c2a15; color: #fde68a; border-color: #4a451c; }
.badge.lv-B2 { background: #2f1b24; color: #fda4af; border-color: #4d2735; }

.dot { width: 3px; height: 3px; border-radius: 50%; background: #3d4a57; }

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 40px 20px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

/* ---------- card ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
  margin-bottom: 12px;
}

/* ---------- practice ---------- */
.practice-bar { padding: 14px 2px; gap: 14px; }
.progress-wrap { flex: 1; }
.progress-label { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; font-weight: 600; }
.progress { height: 6px; background: #1c242c; border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 99px; transition: width .25s ease; }

.practice-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
.practice-head h2 { flex: 1; font-size: 15px; font-weight: 600; color: #cfd9e3; line-height: 1.4; }

.audio-row { display: flex; align-items: center; gap: 10px; }

.play-btn {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid; place-items: center;
  cursor: pointer;
  flex: 0 0 auto;
  transition: transform .1s, filter .15s;
}
.play-btn:active { transform: scale(.94); }
.play-btn.playing { filter: brightness(1.15); }
.play-btn svg { margin-left: 2px; }

.speed { display: flex; gap: 6px; }

.ghost-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: #c3ced9;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.ghost-btn:hover { border-color: #3a4653; background: var(--bg-soft); }
.ghost-btn:disabled { opacity: .4; cursor: default; }

.primary-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 11px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: filter .15s, transform .1s;
}
.primary-btn:active { transform: scale(.98); }
.primary-btn:disabled { opacity: .5; }
.primary-btn.wide { width: 100%; }
kbd {
  font: inherit;
  font-size: 11px;
  background: rgba(0,0,0,.18);
  border-radius: 5px;
  padding: 1px 6px;
  font-weight: 700;
}

.hint-line { font-size: 13px; margin: 12px 0 0; }

.answer {
  width: 100%;
  margin-top: 14px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  padding: 13px 14px;
  font-size: 16.5px;
  line-height: 1.55;
  font-family: inherit;
  resize: vertical;
  min-height: 84px;
}
.answer:focus { outline: none; border-color: #4a5a2a; box-shadow: 0 0 0 3px rgba(215,255,62,.08); }
.answer.correct { border-color: #2f6b46; }
.answer.wrong { border-color: #6b2f3a; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions .primary-btn { flex: 1 1 auto; }

/* ---------- kết quả ---------- */
.result { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 14px; }
.score-line { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.score-big { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.score-big.good { color: var(--good); }
.score-big.mid { color: var(--warn); }
.score-big.bad { color: var(--bad); }
.score-detail { font-size: 13px; color: var(--muted); }

.diff { display: flex; flex-wrap: wrap; gap: 4px 6px; font-size: 16px; line-height: 1.9; }
.w {
  padding: 1px 5px;
  border-radius: 6px;
  border-bottom: 2px solid transparent;
}
.w.ok { color: #6ee7b7; }
.w.bad { color: #ffd7de; background: rgba(251,113,133,.12); border-bottom-color: #fb7185; text-decoration: line-through; }
.w.missing { color: #fde68a; background: rgba(251,191,36,.1); border-bottom-color: #fbbf24; }
.w.extra { color: #94a3b8; background: rgba(148,163,184,.1); border-bottom-color: #64748b; text-decoration: line-through; }
.w .fix { color: var(--good); font-weight: 700; text-decoration: none; }

.hint-box {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 11px;
  background: #1b1f14;
  border: 1px solid #333d1c;
  font-size: 15px;
  line-height: 1.7;
  color: #e9f5c9;
  word-spacing: 2px;
}
.hint-box.reveal { background: #141d24; border-color: #24404f; color: #cfe8f7; }

.source-card { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
.source-card a { color: #a8c4dd; }

.nav-row { display: flex; gap: 10px; }
.nav-row .ghost-btn, .nav-row .primary-btn { flex: 1; }

/* ---------- form ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.field input {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
}
.field input:focus { outline: none; border-color: #4a5a2a; }

/* ---------- modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(3,5,7,.72);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: end center;
  padding: 0;
  z-index: 50;
}
.modal-box {
  width: 100%;
  max-width: 720px;
  max-height: 82dvh;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
}
.modal-box h2 { margin-bottom: 14px; }

.summary-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.summary-row:last-child { border-bottom: none; }
.summary-row .idx { color: var(--muted); font-size: 12px; width: 22px; flex: 0 0 auto; padding-top: 2px; }
.summary-row .txt { flex: 1; color: #cfd9e3; }
.summary-row .pct { font-weight: 700; font-size: 13px; }
.pct.good { color: var(--good); }
.pct.mid { color: var(--warn); }
.pct.bad { color: var(--bad); }

@media (min-width: 640px) {
  h1 { font-size: 24px; }
  .modal { place-items: center; padding: 20px; }
  .modal-box { border-radius: 18px; max-height: 76dvh; }
}

/* ---------- lịch sử ---------- */
.top-actions { display: flex; gap: 8px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px 10px;
  text-align: center;
}
.stat-num { font-size: 25px; font-weight: 800; letter-spacing: -0.02em; color: var(--accent); line-height: 1.1; }
.stat-label { font-size: 11.5px; color: var(--muted); margin-top: 5px; line-height: 1.35; }

.day-chart { display: flex; align-items: flex-end; gap: 5px; height: 130px; margin-top: 14px; }
.day-bar { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; }
.day-bar .fill { width: 100%; background: linear-gradient(180deg, #d7ff3e, #8fae1c); border-radius: 5px 5px 0 0; min-height: 3px; }
.day-bar .dlabel { font-size: 9.5px; color: var(--muted); }

.word-cloud { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.word-pill {
  border: 1px solid #4d2735;
  background: #2a1a20;
  color: #fda4af;
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 13px;
  font-weight: 600;
}
.word-pill .cnt { color: #9b6d78; font-weight: 500; margin-left: 4px; }

.attempt-row { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.attempt-row:last-child { border-bottom: none; }
.attempt-row .pct { font-weight: 700; flex: 0 0 auto; width: 42px; }
.attempt-row .txt { flex: 1; color: #cfd9e3; }
.attempt-row .day { color: var(--muted); font-size: 11.5px; flex: 0 0 auto; }
