/* Học cùng Định — style chung, mobile-first */
:root {
  --bg: #f0f4ff;
  --card: #ffffff;
  --text: #1e2a4a;
  --muted: #6b7a99;
  --primary: #4f6df5;
  --primary-dark: #3a54d0;
  --green: #22b573;
  --red: #e5484d;
  --amber: #f5a623;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(30, 42, 74, .08);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg); color: var(--text); min-height: 100vh; line-height: 1.55;
}
#app { max-width: 720px; margin: 0 auto; padding: 16px 14px 90px; }

h1 { font-size: 1.35rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
a { color: var(--primary); text-decoration: none; }
.muted { color: var(--muted); font-size: .875rem; }
.center { text-align: center; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 12px;
}
.card.tap { cursor: pointer; transition: transform .1s; user-select: none; }
.card.tap:active { transform: scale(.98); }

.row { display: flex; align-items: center; gap: 12px; }
.row .grow { flex: 1; min-width: 0; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

button, .btn {
  font: inherit; border: 0; border-radius: 12px; padding: 12px 18px; cursor: pointer;
  background: var(--primary); color: #fff; font-weight: 600; transition: background .15s;
  display: inline-block; text-align: center;
}
button:active, .btn:active { background: var(--primary-dark); }
button:disabled { opacity: .5; cursor: default; }
.btn-ghost { background: #e8edff; color: var(--primary); }
.btn-green { background: var(--green); }
.btn-red { background: var(--red); }
.btn-sm { padding: 7px 12px; font-size: .85rem; border-radius: 10px; }
.btn-block { width: 100%; display: block; }

input, select, textarea {
  font: inherit; width: 100%; padding: 11px 13px; border: 1.5px solid #d6ddf0;
  border-radius: 12px; background: #fff; color: var(--text); margin-bottom: 10px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
textarea { min-height: 110px; resize: vertical; }
label { font-size: .85rem; font-weight: 600; color: var(--muted); display: block; margin-bottom: 4px; }

/* header + tabbar */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.topbar .logo { font-size: 1.2rem; font-weight: 800; color: var(--primary); }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid #e3e9f8;
  display: flex; justify-content: space-around; padding: 6px 0 max(8px, env(safe-area-inset-bottom)); z-index: 50;
}
.tabbar a {
  flex: 1; text-align: center; color: var(--muted); font-size: .7rem; font-weight: 600; padding: 4px 0;
}
.tabbar a .ico { display: block; font-size: 1.35rem; }
.tabbar a.on { color: var(--primary); }

/* subject grid */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.subject-card { text-align: center; padding: 20px 10px; }
.subject-card .ico { font-size: 2.2rem; }
.subject-card .name { font-weight: 700; margin-top: 6px; font-size: .95rem; }

/* quiz */
.option {
  display: block; width: 100%; text-align: left; background: #fff; color: var(--text);
  border: 2px solid #d6ddf0; border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; font-weight: 500;
}
.option:active { background: #eef2ff; }
.option.picked { border-color: var(--primary); background: #eef2ff; }
.option.right { border-color: var(--green); background: #e9f9f1; }
.option.wrong { border-color: var(--red); background: #fdeeee; }
.explain { background: #fff8e8; border-left: 4px solid var(--amber); border-radius: 8px; padding: 10px 12px; margin-top: 10px; font-size: .9rem; }

/* timer */
.timer {
  position: sticky; top: 0; z-index: 40; background: var(--primary); color: #fff;
  border-radius: 12px; padding: 10px 16px; font-weight: 700; text-align: center; margin-bottom: 14px;
  font-variant-numeric: tabular-nums;
}
.timer.warn { background: var(--red); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .75; } }

.qnav { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.qnav button {
  width: 38px; height: 38px; padding: 0; border-radius: 10px; background: #e3e9f8; color: var(--text); font-weight: 700;
}
.qnav button.done { background: var(--primary); color: #fff; }
.qnav button.cur { outline: 3px solid var(--amber); }

/* score */
.score-big { font-size: 3.2rem; font-weight: 800; }
.score-big.good { color: var(--green); } .score-big.mid { color: var(--amber); } .score-big.bad { color: var(--red); }
.badge { display: inline-block; background: #e8edff; color: var(--primary); border-radius: 999px; padding: 3px 12px; font-size: .8rem; font-weight: 700; }
.badge.green { background: #e9f9f1; color: var(--green); }
.badge.red { background: #fdeeee; color: var(--red); }
.badge.amber { background: #fff4dd; color: #b57900; }

/* markdown content */
.md h1 { font-size: 1.4rem; margin: .6em 0 .4em; } .md h2 { font-size: 1.15rem; margin: .8em 0 .3em; }
.md h3 { font-size: 1rem; margin: .8em 0 .3em; }
.md p { margin: .5em 0; } .md ul, .md ol { margin: .5em 0 .5em 1.4em; }
.md code { background: #eef2ff; padding: 2px 6px; border-radius: 6px; font-size: .9em; }
.md pre { background: #1e2a4a; color: #e8edff; padding: 12px; border-radius: 10px; overflow-x: auto; margin: .6em 0; }
.md pre code { background: none; color: inherit; padding: 0; }
.md img { max-width: 100%; border-radius: 10px; }
/* banner tom tat / cong thuc / meo — khoi trich dan */
.md blockquote {
  background: linear-gradient(135deg, #eef2ff, #e9f9f1);
  border-left: 5px solid var(--primary); border-radius: 10px;
  padding: 12px 14px; margin: .8em 0; color: var(--text); font-weight: 500;
  box-shadow: 0 1px 4px rgba(30,42,74,.06);
}
.md blockquote b, .md blockquote strong { color: var(--primary-dark); }
.md h2 {
  background: #eef2ff; border-radius: 10px; padding: 8px 12px;
  margin: 1.1em 0 .5em; color: var(--primary-dark); font-size: 1.1rem;
}
.md h3 { color: var(--primary-dark); border-bottom: 2px solid #e3e9f8; padding-bottom: 3px; }
.md table { box-shadow: 0 1px 5px rgba(30,42,74,.07); border-radius: 8px; overflow: hidden; }
.md table tr:first-child td { background: var(--primary); color: #fff; font-weight: 700; }
.md table tr:nth-child(even) td { background: #f7f9ff; }
.md ul li::marker { color: var(--primary); }

/* cong thuc toan */
.math { font-family: 'Cambria Math', 'Times New Roman', Georgia, serif; font-size: 1.05em; white-space: nowrap; }
.math-block { display: block; text-align: center; margin: .7em 0; font-size: 1.15em; }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; margin: 0 .18em; line-height: 1.15; }
.frac .fnum { padding: 0 .3em; border-bottom: 1.5px solid currentColor; }
.frac .fden { padding: 0 .3em; }
.math sup, .math sub { font-size: .72em; }
.sqrt .sqrtb { border-top: 1.5px solid currentColor; padding: 0 .18em; }
.md table td .math, .md table th .math { white-space: normal; }
.cases { display: inline-block; border-left: 2px solid currentColor; padding-left: .5em; margin-left: .2em; text-align: left; }
.md table { border-collapse: collapse; width: 100%; margin: .6em 0; }
.md th, .md td { border: 1px solid #d6ddf0; padding: 6px 10px; font-size: .9rem; }

/* login */
.login-wrap { max-width: 380px; margin: 12vh auto 0; padding: 0 18px; }
.login-logo { text-align: center; font-size: 3rem; }
.login-title { text-align: center; font-size: 1.5rem; font-weight: 800; color: var(--primary); margin-bottom: 20px; }

/* misc */
.list-item { padding: 13px 4px; border-bottom: 1px solid #edf1fb; }
.list-item:last-child { border-bottom: 0; }
.err { color: var(--red); font-size: .875rem; margin: 6px 0; }
.ok-msg { color: var(--green); font-size: .875rem; margin: 6px 0; }
.stat-row { display: flex; gap: 10px; }
.stat { flex: 1; text-align: center; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 6px; }
.stat .num { font-size: 1.5rem; font-weight: 800; color: var(--primary); }
.stat .lbl { font-size: .72rem; color: var(--muted); font-weight: 600; }

/* admin desktop */
@media (min-width: 900px) { .admin #app { max-width: 1000px; } }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
table.data { border-collapse: collapse; width: 100%; background: #fff; border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
table.data th { background: #eef2ff; text-align: left; font-size: .8rem; color: var(--muted); }
table.data th, table.data td { padding: 9px 12px; border-bottom: 1px solid #edf1fb; font-size: .88rem; }
.modal-bg { position: fixed; inset: 0; background: rgba(20,28,50,.45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 20px; overflow-y: auto; }
.modal { background: #fff; border-radius: var(--radius); padding: 20px; width: 100%; max-width: 560px; margin-top: 4vh; }

/* thanh tien do + so thu tu bai */
.bar { height: 7px; background: #e3e9f8; border-radius: 99px; margin-top: 7px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--green)); border-radius: 99px; transition: width .3s; }
.stt { display: inline-block; min-width: 22px; height: 22px; line-height: 22px; text-align: center; background: var(--primary);
  color: #fff; border-radius: 50%; font-size: .75rem; font-weight: 700; }
