/* Luyện Toán THCS — giao diện. Mỗi lớp một màu (body[data-grade]); màu đặt bằng biến để đổi sáng / tối. */
:root {
  --bg: #edf5fc; --card: #ffffff; --ink: #0f2440; --muted: #51657f; --line: #d5e5f4; --soft: #e5f0fa;
  --ocean: linear-gradient(115deg, #082a63 0%, #0d47a1 48%, #0288d1 100%);
  --wave: #0288d1;
  --g6: #1769d1; --g6b: #29a8f0; --t6: #e2f0fd;
  --g7: #00897b; --g7b: #22bcd2; --t7: #dff5f3;
  --g8: #3949ab; --g8b: #2196f3; --t8: #e7e9f8;
  --g9: #0b3d91; --g9b: #00acc1; --t9: #dff3fb;
  --accent: var(--g6); --accent2: var(--g6b); --tint: var(--t6); --accent-ink: #fff;
  --orange: #e8590c; --ok: #12875a; --ok-bg: #e5f7ee; --bad: #d32f45; --bad-bg: #fdebee; --mid: #c27c00; --warn-bg: #fff5dc;
  --shadow: 0 1px 2px rgba(24, 33, 58, .05), 0 6px 20px rgba(24, 33, 58, .06);
  --shadow-up: 0 2px 4px rgba(24, 33, 58, .06), 0 14px 34px rgba(24, 33, 58, .12);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --math: "Cambria Math", Cambria, "Times New Roman", "Noto Serif", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #08162b; --card: #0f2139; --ink: #e6f0fb; --muted: #94a9c4; --line: #1e3658; --soft: #142b4a;
    --ocean: linear-gradient(115deg, #041a3d 0%, #0a3477 50%, #035f94 100%); --wave: #38b6ff;
    --g6: #5aa9ff; --g6b: #4fd1ff; --t6: #12305a; --g7: #2ed3c0; --g7b: #4fd8ea; --t7: #0f3438;
    --g8: #8c9eff; --g8b: #5cb8ff; --t8: #1d2757; --g9: #4fc3f7; --g9b: #26e0d0; --t9: #0d3149;
    --accent-ink: #0d1220; --orange: #ff9a4d;
    --ok: #4bd492; --ok-bg: #11301f; --bad: #ff7d8d; --bad-bg: #3a1820; --mid: #f2b843; --warn-bg: #33290f;
    --shadow: 0 1px 0 rgba(255, 255, 255, .03); --shadow-up: 0 10px 30px rgba(0, 0, 0, .45); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #08162b; --card: #0f2139; --ink: #e6f0fb; --muted: #94a9c4; --line: #1e3658; --soft: #142b4a;
  --ocean: linear-gradient(115deg, #041a3d 0%, #0a3477 50%, #035f94 100%); --wave: #38b6ff;
  --g6: #5aa9ff; --g6b: #4fd1ff; --t6: #12305a; --g7: #2ed3c0; --g7b: #4fd8ea; --t7: #0f3438;
  --g8: #8c9eff; --g8b: #5cb8ff; --t8: #1d2757; --g9: #4fc3f7; --g9b: #26e0d0; --t9: #0d3149;
  --accent-ink: #0d1220; --orange: #ff9a4d;
  --ok: #4bd492; --ok-bg: #11301f; --bad: #ff7d8d; --bad-bg: #3a1820; --mid: #f2b843; --warn-bg: #33290f;
  --shadow: 0 1px 0 rgba(255, 255, 255, .03); --shadow-up: 0 10px 30px rgba(0, 0, 0, .45); color-scheme: dark;
}
body[data-grade="7"] { --accent: var(--g7); --accent2: var(--g7b); --tint: var(--t7); }
body[data-grade="8"] { --accent: var(--g8); --accent2: var(--g8b); --tint: var(--t8); }
body[data-grade="9"] { --accent: var(--g9); --accent2: var(--g9b); --tint: var(--t9); }
:root { --grad: linear-gradient(135deg, var(--accent), var(--accent2)); }
body { --grad: linear-gradient(135deg, var(--accent), var(--accent2)); }
/* nền tối: dải màu đậm hơn để chữ trắng trên nút / banner luôn rõ */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) body { --grad: linear-gradient(135deg, color-mix(in srgb, var(--accent) 60%, #031634), color-mix(in srgb, var(--accent2) 55%, #031634)); }
}
:root[data-theme="dark"] body { --grad: linear-gradient(135deg, color-mix(in srgb, var(--accent) 60%, #031634), color-mix(in srgb, var(--accent2) 55%, #031634)); }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; color: var(--ink); font: 16px/1.55 var(--font); background-color: var(--bg);
  background-image: radial-gradient(1100px 520px at 90% -12%, color-mix(in srgb, var(--wave) 22%, transparent), transparent 65%),
    radial-gradient(900px 520px at -12% 18%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 62%),
    linear-gradient(180deg, transparent 0%, color-mix(in srgb, var(--wave) 7%, transparent) 100%);
  background-attachment: fixed; min-height: 100vh; }
/* sóng biển mờ ở chân màn hình */
body::after { content: ""; position: fixed; left: 0; right: 0; bottom: 0; height: 160px; z-index: -1; pointer-events: none; opacity: .14;
  background: var(--wave);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 160' preserveAspectRatio='none'%3E%3Cpath d='M0 70C180 20 360 20 540 60s360 70 540 30 270-60 360-40V160H0Z' opacity='.6'/%3E%3Cpath d='M0 110c200-40 380-30 560 0s380 40 560 5 230-40 320-25V160H0Z'/%3E%3C/svg%3E") center bottom / 100% 100% no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 160' preserveAspectRatio='none'%3E%3Cpath d='M0 70C180 20 360 20 540 60s360 70 540 30 270-60 360-40V160H0Z' opacity='.6'/%3E%3Cpath d='M0 110c200-40 380-30 560 0s380 40 560 5 230-40 320-25V160H0Z'/%3E%3C/svg%3E") center bottom / 100% 100% no-repeat; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; line-height: 1.25; margin: .15em 0 .4em; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 1.5em 0 .6em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.wrap { max-width: 920px; margin: 0 auto; padding: 18px 16px; min-height: 72vh; }
.muted { color: var(--muted); } .small { font-size: .88rem; } .center { text-align: center; } .pad { padding: 20px; }
.ell { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.goodt { color: var(--ok); } .midt { color: var(--mid); } .lowt { color: var(--bad); }

/* ---------- đầu trang ---------- */
.top { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 10px 18px;
  background: var(--ocean); color: #fff; box-shadow: 0 6px 22px -8px rgba(8, 42, 99, .55); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.1rem; color: #fff; text-decoration: none; letter-spacing: .01em; }
.brand img { border-radius: 10px; box-shadow: 0 0 0 2px rgba(255, 255, 255, .55), 0 6px 14px rgba(0, 0, 0, .25); }
.brand em { font-style: normal; color: #7fd6ff; }
.nav { display: flex; gap: 6px; order: 3; width: 100%; overflow-x: auto; }
.nav a { padding: 7px 16px; border-radius: 99px; color: rgba(255, 255, 255, .82); text-decoration: none; font-weight: 700; white-space: nowrap;
  transition: background .15s, color .15s; }
.nav a:hover { background: rgba(255, 255, 255, .14); color: #fff; }
.nav a.on { background: #fff; color: #0d47a1; box-shadow: 0 4px 12px rgba(0, 0, 0, .18); }
.right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .35); background: rgba(255, 255, 255, .14); color: #fff;
  font-size: 18px; cursor: pointer; }
.icon-btn:hover { background: rgba(255, 255, 255, .26); }
.top .btn.sm { min-height: 36px; padding: 6px 16px; border: 0; border-radius: 99px; background: #fff; color: #0d47a1; box-shadow: 0 4px 12px rgba(0, 0, 0, .18); }
.top .btn.sm .av { display: inline-grid; place-items: center; width: 26px; height: 26px; margin: -2px 4px -2px -8px; border-radius: 50%;
  background: var(--ocean); color: #fff; font-size: .72rem; font-weight: 800; letter-spacing: .02em; }
.nav-me { display: none !important; }
@media (min-width: 680px) { .nav { order: 0; width: auto; margin-left: 14px; } .nav .ni { display: none; } }

/* Điện thoại: đầu trang 1 hàng, menu thành thanh dưới cùng như ứng dụng */
@media (max-width: 679px) {
  .top { flex-wrap: nowrap; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
  .brand { font-size: 1rem; gap: 8px; min-width: 0; }
  .brand img { width: 30px; height: 30px; }
  .brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .right { gap: 6px; }
  .icon-btn { width: 34px; height: 34px; font-size: 16px; }
  .top .btn.sm { min-height: 34px; padding: 4px; border-radius: 50%; }
  .top .btn.sm .av { width: 28px; height: 28px; margin: 0; font-size: .74rem; }
  .top .btn.sm .mename { display: none; }
  .top #meBtn:not(:has(.av)) { padding: 4px 12px; border-radius: 99px; }
  .nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 8; order: 0; width: auto; margin: 0; gap: 0; overflow: visible;
    display: flex; justify-content: space-around; background: var(--card); border-top: 1px solid var(--line);
    padding: 4px 4px max(6px, env(safe-area-inset-bottom)); box-shadow: 0 -6px 20px rgba(8, 42, 99, .10); }
  .nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 5px 2px; border-radius: 12px;
    color: var(--muted); font-size: .72rem; font-weight: 700; }
  .nav a .ni { font-size: 1.25rem; line-height: 1.2; filter: grayscale(1); opacity: .7; }
  .nav a:hover { background: transparent; color: var(--ink); }
  .nav a.on { background: var(--tint); color: var(--accent); box-shadow: none; }
  .nav a.on .ni { filter: none; opacity: 1; }
  .nav-me { display: flex !important; }
  body:has(.nav:not([hidden])) { padding-bottom: 76px; }
  .wrap { padding: 14px 14px; }
  .hero { padding: 20px 16px; border-radius: 20px; }
}
.foot { text-align: center; color: var(--muted); font-size: .84rem; padding: 26px 16px 40px; line-height: 1.7; }
.foot-author { font-weight: 700; }
.foot a { color: inherit; text-decoration: none; }

/* ---------- nút ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 8px 18px; border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent); background: var(--tint); color: var(--accent);
  font: 700 .95rem var(--font); text-decoration: none; cursor: pointer; transition: transform .15s, box-shadow .15s, background .15s; }
.btn:hover { background: color-mix(in srgb, var(--accent) 16%, var(--card)); transform: translateY(-1px); box-shadow: var(--shadow); }
.btn.pri { background: var(--grad); border: 0; color: #fff; box-shadow: 0 8px 18px -6px color-mix(in srgb, var(--accent) 70%, transparent); }
.btn.pri:hover { filter: brightness(1.06); }
.btn.big { min-height: 50px; padding: 10px 26px; font-size: 1.02rem; border-radius: 14px; }
.btn.sm { min-height: 32px; padding: 4px 12px; font-size: .85rem; border-radius: 9px; }
.btn.danger { color: var(--bad); background: var(--bad-bg); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }
.btn:disabled { opacity: .6; cursor: default; transform: none; }
.row { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0 0; }
.row.end { justify-content: flex-end; } .row.center { justify-content: center; }
.back { display: inline-flex; align-items: center; gap: 4px; margin: 0 0 12px; text-decoration: none; font-weight: 700; color: var(--muted); }
.back:hover { color: var(--accent); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.kicker { margin: 0; color: var(--accent); font-weight: 800; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }

/* ---------- trang chủ ---------- */
.hero { position: relative; overflow: hidden; display: flex; align-items: center; gap: 16px; padding: 26px 24px; border-radius: 24px;
  background: var(--grad); color: #fff; box-shadow: 0 16px 40px -12px var(--accent); animation: rise .5s ease both; }
.hero::after { content: ""; position: absolute; inset: auto -60px -90px auto; width: 260px; height: 260px; border-radius: 50%; background: rgba(255, 255, 255, .1); }
.hero-txt { position: relative; z-index: 1; flex: 1; min-width: 0; }
.eyebrow { margin: 0 0 6px; font-weight: 700; opacity: .92; }
.hero h1 { font-size: clamp(1.55rem, 4.6vw, 2.25rem); margin: 0 0 10px; font-weight: 800; }
.hero h1 span { color: #ffe08a; }
.lead { margin: 0 0 16px; opacity: .92; max-width: 52ch; }
.hero-stats { display: flex; flex-wrap: wrap; gap: 10px; }
.hero-stats span { display: grid; padding: 8px 14px; border-radius: 14px; background: rgba(255, 255, 255, .17); font-size: .8rem; line-height: 1.25;
  backdrop-filter: blur(4px); }
.hero-stats b { font-size: 1.25rem; }
.hero-art { position: relative; z-index: 1; width: 200px; flex: none; color: #fff; }
@media (max-width: 600px) { .hero-art { position: absolute; right: -40px; top: 6px; width: 170px; opacity: .25; } .hero { padding: 22px 18px; } }

.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 18px 0 6px; }
.gtab { position: relative; display: grid; gap: 1px; padding: 12px 6px 10px; border-radius: 16px; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); font: inherit; cursor: pointer; box-shadow: var(--shadow); overflow: hidden; transition: transform .15s, box-shadow .15s; }
.gtab::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px; background: var(--gc); }
.gtab b { font-size: 1.08rem; color: var(--gc); } .gtab small { color: var(--muted); font-size: .78rem; }
.gtab:hover { transform: translateY(-2px); box-shadow: var(--shadow-up); }
.gtab[aria-selected="true"] { background: var(--grad); border-color: transparent; box-shadow: 0 10px 24px -8px var(--accent); }
.gtab[aria-selected="true"] b, .gtab[aria-selected="true"] small { color: #fff; }
.gsub { margin: 4px 2px 14px; color: var(--muted); font-size: .9rem; text-align: center; }

.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 10px; margin-bottom: 14px; }
.qbtn { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-radius: 16px; text-decoration: none; color: #fff;
  background: var(--grad); box-shadow: 0 10px 22px -10px var(--accent); transition: transform .15s, box-shadow .15s; }
.qbtn:hover { transform: translateY(-2px); box-shadow: 0 14px 28px -10px var(--accent); }
.qbtn.warm { background: linear-gradient(135deg, #f57c00, #ef5350); box-shadow: 0 10px 22px -10px #ef5350; }
.qbtn b { display: block; } .qbtn small { color: rgba(255, 255, 255, .85); }
.qi { display: grid; place-items: center; flex: none; width: 42px; height: 42px; border-radius: 12px; background: rgba(255, 255, 255, .2); font-size: 1.3rem; }

.chap { margin-top: 18px; }
.chap-h { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; margin: 0 2px 10px; font-size: 1.02rem; }
.chap-n { padding: 2px 10px; border-radius: 99px; background: var(--grad); color: #fff; font-size: .78rem; font-weight: 800; letter-spacing: .03em; white-space: nowrap; }
.bai { color: var(--accent); font-weight: 800; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.skill { display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: 18px; text-decoration: none; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); animation: rise .45s ease both; animation-delay: var(--d, 0ms);
  transition: transform .18s, box-shadow .18s, border-color .18s; }
.skill:hover { transform: translateY(-3px); box-shadow: var(--shadow-up); border-color: var(--accent); }
.sicon { display: grid; place-items: center; flex: none; width: 52px; height: 52px; border-radius: 16px; background: var(--tint); font-size: 1.6rem; }
.sicon.big { width: 64px; height: 64px; font-size: 2rem; border-radius: 20px; }
.sbody { display: grid; gap: 4px; flex: 1; min-width: 0; } .sbody > b { line-height: 1.3; }
.go { flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--soft); color: var(--accent);
  font-size: 1.3rem; font-weight: 700; transition: background .18s, color .18s; }
.skill:hover .go { background: var(--grad); color: #fff; }
.meta { color: var(--muted); font-size: .85rem; }
.bar { display: block; height: 7px; border-radius: 9px; background: var(--soft); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 9px; background: var(--grad); }
.bar i.good { background: var(--ok); } .bar i.mid { background: var(--mid); } .bar i.low { background: var(--bad); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- chọn số câu ---------- */
.setup { padding: 24px; border-radius: 22px; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); animation: rise .4s ease both; }
.setup-head { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; }
.setup-head h1 { margin: 2px 0 0; }
.mastery { margin: 6px 0 0; }
.label { margin: 20px 0 10px; font-weight: 800; }
.counts { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.count { display: grid; gap: 2px; padding: 16px 10px; border-radius: 16px; border: 2px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; cursor: pointer; transition: transform .15s, border-color .15s, box-shadow .15s; }
.count b { font-size: 1.9rem; line-height: 1.1; color: var(--accent); } .count small { color: var(--muted); }
.count:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: var(--shadow-up); }
.count.hot { background: var(--grad); border-color: transparent; } .count.hot b, .count.hot small { color: #fff; }
.levels { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.lvbtn { display: grid; gap: 2px; justify-items: start; text-align: left; padding: 12px 14px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; cursor: pointer; transition: border-color .15s, background .15s, transform .15s; }
.lvbtn:hover { transform: translateY(-2px); border-color: var(--accent); }
.lvbtn b { font-size: 1.02rem; } .lvbtn small { color: var(--muted); font-size: .8rem; }
.lvdots { font-size: .85rem; letter-spacing: .1em; color: var(--accent); font-weight: 800; }
.lvbtn.lv1 .lvdots { color: var(--ok); } .lvbtn.lv2 .lvdots { color: var(--mid); } .lvbtn.lv3 .lvdots { color: var(--bad); }
.lvbtn[aria-checked="true"] { border-color: var(--accent); background: var(--tint); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.lvbtn[aria-checked="true"] b::after { content: " ✓"; color: var(--accent); }
.tips { list-style: none; padding: 0; margin: 18px 0 0; display: flex; flex-wrap: wrap; gap: 8px 18px; color: var(--muted); font-size: .88rem; }

/* ---------- làm bài ---------- */
.qtop { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.qtop .back { margin: 0; }
.qtitle { flex: 1; color: var(--muted); font-weight: 600; }
.score { padding: 4px 12px; border-radius: 99px; background: var(--card); border: 1px solid var(--line); font-weight: 800; }
.prog { height: 10px; background: var(--soft); border-radius: 99px; overflow: hidden; margin-bottom: 14px; }
.prog i { display: block; height: 100%; background: var(--grad); border-radius: 99px; transition: width .4s ease; }
.qcard { position: relative; padding: 22px 20px 20px; border-radius: 22px; background: var(--card); border: 1px solid var(--line);
  box-shadow: var(--shadow-up); overflow: hidden; animation: rise .35s ease both; }
.qcard::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 5px; background: var(--grad); }
.qcard.is-ok::before { background: var(--ok); } .qcard.is-bad::before { background: var(--bad); }
.qmeta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.qnum { font-weight: 800; font-size: 1.05rem; } .qnum small { color: var(--muted); font-weight: 600; }
.lvl { padding: 3px 10px; border-radius: 99px; font-size: .78rem; font-weight: 800; letter-spacing: .02em; background: var(--soft); }
.lvl.lv1 { color: var(--ok); } .lvl.lv2 { color: var(--mid); } .lvl.lv3 { color: var(--bad); }
.pill { padding: 3px 10px; border-radius: 99px; background: var(--tint); font-size: .8rem; font-weight: 700; }
.stem { font-size: 1.15rem; line-height: 1.75; }
.figbox { margin: 14px 0 4px; padding: 12px; border-radius: 16px; background: var(--soft); overflow-x: auto; }
.opts { display: grid; gap: 10px; margin-top: 18px; }
@media (min-width: 640px) { .opts { grid-template-columns: 1fr 1fr; } }
.opt { display: flex; align-items: center; gap: 12px; min-height: 58px; padding: 10px 14px; text-align: left; border-radius: 16px;
  border: 2px solid var(--line); background: var(--card); color: var(--ink); font: 1.06rem var(--font); cursor: pointer;
  transition: transform .12s, border-color .12s, background .12s, box-shadow .12s; }
.opt:hover:not(:disabled) { border-color: var(--accent); background: var(--tint); transform: translateY(-2px); box-shadow: var(--shadow); }
.opt:active:not(:disabled) { transform: scale(.98); }
.opt .key { flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 11px; background: var(--tint); color: var(--accent); font-weight: 800; }
.opt.ok { border-color: var(--ok); background: var(--ok-bg); animation: pop .35s ease; } .opt.ok .key { background: var(--ok); color: #fff; }
.opt.bad { border-color: var(--bad); background: var(--bad-bg); animation: shake .35s ease; } .opt.bad .key { background: var(--bad); color: #fff; }
.opt.dim { opacity: .5; } .opt:disabled { cursor: default; }
@keyframes pop { 50% { transform: scale(1.03); } }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
.fb { display: flex; gap: 12px; margin-top: 18px; padding: 14px 16px; border-radius: 16px; animation: rise .3s ease both; }
.fb.ok { background: var(--ok-bg); } .fb.bad { background: var(--bad-bg); }
.fb.ok > div > b { color: var(--ok); } .fb.bad > div > b { color: var(--bad); }
.fb-ic { font-size: 1.6rem; line-height: 1.2; }
.exp { margin-top: 6px; line-height: 1.8; }
.review { margin-bottom: 12px; } .review p { margin: .4em 0; }
.tag { display: inline-block; padding: 0 8px; border-radius: 6px; font-size: .78rem; font-weight: 800; }
.tag.ok { background: var(--ok-bg); color: var(--ok); } .tag.bad { background: var(--bad-bg); color: var(--bad); }

/* ---------- kết quả ---------- */
.result { padding: 26px 20px; border-radius: 24px; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow-up); text-align: center; animation: rise .4s ease both; }
.result .msg { font-size: 1.05rem; }
.stars { display: flex; justify-content: center; gap: 8px; font-size: 2.6rem; line-height: 1; margin-bottom: 6px; }
.stars span { color: var(--line); }
.stars span.on { color: #ffc93c; text-shadow: 0 4px 14px rgba(255, 180, 0, .45); animation: star .5s cubic-bezier(.3, 1.6, .5, 1) both; animation-delay: var(--d); }
@keyframes star { from { transform: scale(0) rotate(-40deg); opacity: 0; } to { transform: none; opacity: 1; } }
.ring { --c: var(--accent); width: 128px; height: 128px; margin: 8px auto 10px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--soft) 0); }
.ring.good { --c: var(--ok); } .ring.mid { --c: var(--mid); } .ring.low { --c: var(--bad); }
.ring span { width: 98px; height: 98px; border-radius: 50%; background: var(--card); display: grid; place-items: center; font-size: 1.6rem; font-weight: 800; }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 20; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(var(--r)); } }

/* ---------- tiến bộ ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 12px 0; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; box-shadow: var(--shadow); }
.tile b { display: block; font-size: 1.6rem; color: var(--accent); }
.tile span { color: var(--muted); font-size: .86rem; }
.prow { display: grid; grid-template-columns: minmax(0, 1.6fr) 1fr auto auto; align-items: center; gap: 10px; padding: 11px 16px; border-top: 1px solid var(--line); }
.prow:first-child { border-top: 0; } .pnum { font-weight: 800; min-width: 3.2em; text-align: right; }
@media (max-width: 520px) { .prow { grid-template-columns: 1fr auto; } .prow .bar { grid-column: 1 / -1; grid-row: 2; } .prow .small { display: none; } }
.sess { border-top: 1px solid var(--line); padding: 0 16px; } .sess:first-child { border-top: 0; }
.sess summary { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; padding: 11px 0; cursor: pointer; }
.sess ul { margin: 0 0 12px; padding-left: 18px; font-size: .92rem; } .sess li { margin: 6px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 4px; }
.chip { padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); color: var(--ink); text-decoration: none; font-weight: 700; font-size: .9rem; }
.chip.on { background: var(--grad); color: #fff; border-color: transparent; }
.warn-box { background: var(--warn-bg); margin: 12px 0; } .bad-box { background: var(--bad-bg); }

/* ---------- màn hình đăng nhập ---------- */
.login { display: grid; grid-template-columns: 1.1fr 1fr; max-width: 860px; margin: 10px auto; border-radius: 24px; overflow: hidden;
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow-up); animation: rise .4s ease both; }
.login-art { position: relative; padding: 30px 26px; background: var(--ocean); color: #fff; display: flex; flex-direction: column; justify-content: flex-end; min-height: 320px; }
.login-art .hero-art { position: absolute; top: 18px; right: 14px; width: 200px; opacity: .9; }
.login-art h1 { position: relative; margin: 0 0 6px; font-size: 1.7rem; }
.login-art p { position: relative; margin: 0; opacity: .9; max-width: 32ch; }
.login-box { padding: 28px 26px; }
.login-box h2 { margin: 0 0 6px; font-size: 1.35rem; }
@media (max-width: 680px) { .login { grid-template-columns: 1fr; } .login-art { min-height: 190px; padding: 22px 20px; } .login-art .hero-art { width: 130px; } }

/* ---------- biểu mẫu ---------- */
.narrow { max-width: 460px; margin: 0 auto; }
.form { display: grid; gap: 12px; }
.form.two { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form label { display: grid; gap: 4px; font-weight: 700; font-size: .9rem; }
.form input, .form select { min-height: 44px; padding: 8px 12px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--ink); font: 1rem var(--font); }
.form input:focus, .form select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--tint); }
.form label.check { display: flex; align-items: center; gap: 8px; }
.form label.check input { min-height: 0; width: 18px; height: 18px; }
.tbl { overflow-x: auto; margin-top: 14px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: .8rem; } .acts { white-space: nowrap; } .acts .btn { margin: 2px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 30; max-width: calc(100% - 32px);
  padding: 11px 20px; border-radius: 12px; background: var(--ink); color: var(--bg); font-weight: 700; box-shadow: var(--shadow-up); animation: rise .25s ease both; }
.toast.bad { background: var(--bad); color: #fff; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- hình vẽ SVG (svg.js) ---------- */
.fig { display: block; max-width: 100%; height: auto; margin: 0 auto; }
.fig .tx { font: 14px var(--font); fill: var(--ink); } .fig .sm { font-size: 12.5px; } .fig .xs { font-size: 11px; fill: var(--muted); }
.fig .it { font-family: var(--math); font-style: italic; font-size: 16px; } .fig .b { font-weight: 700; }
.fig .al { font-size: 12.5px; fill: var(--orange); font-weight: 700; } .fig .c2t { fill: var(--orange); font-weight: 600; }
.fig .ln { stroke: var(--ink); stroke-width: 2; fill: none; stroke-linejoin: round; }
.fig .sh { stroke: var(--ink); stroke-width: 2; fill: var(--tint); stroke-linejoin: round; }
.fig .ax { stroke: var(--muted); stroke-width: 1.4; } .fig .gr { stroke: var(--line); stroke-width: 1; }
.fig .ds { stroke: var(--muted); stroke-width: 1.2; stroke-dasharray: 4 3; fill: none; }
.fig .c1 { stroke: var(--accent); stroke-width: 2.6; fill: none; } .fig .c2 { stroke: var(--orange); stroke-width: 2.4; fill: none; }
.fig .am { stroke: var(--orange); stroke-width: 1.6; fill: none; }
.fig .ahx { fill: var(--muted); } .fig .ah2 { fill: var(--orange); }
.fig .dt { fill: var(--accent); } .fig .col { fill: var(--accent); opacity: .85; }
.fig .col2 { fill: var(--orange); opacity: .85; }
.fig .pc0 { fill: #1e88e5; } .fig .pc1 { fill: #26a69a; } .fig .pc2 { fill: #ffa726; } .fig .pc3 { fill: #ef5350; } .fig .pc4 { fill: #ab47bc; } .fig .pc5 { fill: #8d6e63; }
.fig .pl { fill: #fff; }
.ftab { margin: 0 auto; border-collapse: collapse; background: var(--card); border-radius: 10px; overflow: hidden; font-size: .95rem; }
.ftab th, .ftab td { border: 1px solid var(--line); padding: 6px 12px; text-align: center; }
.ftab th { background: var(--tint); color: var(--ink); font-weight: 700; }
.ftitle { text-align: center; font-weight: 700; margin: 0 0 8px; font-size: .92rem; }
.figbox .fig .gr { stroke: color-mix(in srgb, var(--muted) 22%, transparent); }

/* ---------- công thức (math.js) ---------- */
.m { font-family: var(--math); font-size: 1.08em; white-space: nowrap; }
.otx .m, .stem .m { white-space: normal; }
.m i { font-style: italic; padding-right: .04em; }
.m-op { margin: 0 .28em; } .m-bin { margin: 0 .2em; }
.m-fn { font-style: normal; margin-right: .15em; } .m-tx { font-family: var(--font); font-size: .93em; }
.m sup { font-size: .72em; vertical-align: .55em; line-height: 0; margin-left: .03em; } .m sub { font-size: .72em; vertical-align: -.2em; line-height: 0; }
.m-frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; font-size: .92em; margin: 0 .12em; line-height: 1.2; }
.m-frac > span:first-child { border-bottom: .08em solid currentColor; padding: 0 .2em .05em; }
.m-frac > span:last-child { padding: .05em .2em 0; }
.m-sqrt { display: inline-flex; align-items: stretch; vertical-align: baseline; }
.m-rad { font-size: 1.05em; line-height: 1; }
.m-rc { border-top: .07em solid currentColor; padding: .05em .12em 0 .08em; margin-left: -.02em; }
.m-ov { border-top: .07em solid currentColor; padding-top: .05em; }
.m-idx { font-size: .55em; vertical-align: .9em; margin-right: -.25em; }
.m-hat { position: relative; display: inline-block; }
.m-hat::before { content: "^"; position: absolute; left: 0; right: 0; top: -.62em; text-align: center; font-family: var(--font); font-size: .95em; transform: scaleX(1.6); }
.m-sys { display: inline-flex; align-items: center; vertical-align: middle; margin: .2em 0; }
.m-br { font-size: 2.3em; line-height: 1; font-weight: 300; margin-right: .1em; }
.m-rows { display: flex; flex-direction: column; line-height: 1.5; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media print { .top, .foot, .row, .back { display: none; } body { background: #fff; } .card, .qcard { box-shadow: none; } }

/* hẹn giờ học (đầu trang) */
.timer-chip { display: inline-flex; align-items: center; gap: 4px; min-height: 36px; padding: 4px 12px; border-radius: 99px; border: 1.5px solid rgba(255, 255, 255, .45);
  background: rgba(255, 255, 255, .12); color: #fff; font: inherit; font-weight: 800; font-size: .9rem; white-space: nowrap; cursor: pointer; font-variant-numeric: tabular-nums; }
.timer-chip:hover { background: rgba(255, 255, 255, .24); }
.timer-chip.on { background: #e8fff1; border-color: #34d399; color: #047857; }
.timer-chip.warn { background: #fff1f0; border-color: #f87171; color: #b91c1c; animation: tpulse 1s ease-in-out infinite; }
@keyframes tpulse { 50% { transform: scale(1.06); } }
@media (max-width: 679px) { .timer-chip { min-height: 34px; padding: 4px 10px; font-size: .84rem; } }
@media (max-width: 420px) { .timer-chip:not(.on) #timerTxt { display: none; } }
.timer-opts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.timer-opts .btn { justify-content: center; }
/* hộp thoại */
.dlg { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(8, 22, 43, .55); backdrop-filter: blur(3px); animation: rise .2s ease both; }
.dlg-card { width: min(440px, 100%); padding: 22px; border-radius: 20px; background: var(--card); color: var(--ink); border: 1px solid var(--line); box-shadow: 0 24px 60px rgba(0, 0, 0, .35); }
.dlg-card h2 { margin: 0 0 6px; }
.dlg-ic { font-size: 3.4rem; line-height: 1.1; }
/* làm bài: đồng hồ + bảng số câu */
.clock { padding: 4px 12px; border-radius: 99px; background: var(--card); border: 1px solid var(--line); font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.qdots { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 14px; }
.qdots span { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; border: 1.5px solid var(--line); background: var(--card);
  font-weight: 800; font-size: .85rem; color: var(--muted); }
.qdots span.cur { border: 2px solid var(--accent); color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.qdots span.ok { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.qdots span.bad { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
@media (max-width: 679px) { .qdots { gap: 5px; } .qdots span { width: 29px; height: 29px; font-size: .8rem; border-radius: 8px; } .qtop { gap: 8px; } .clock, .score { padding: 3px 9px; font-size: .9rem; } }

/* nút Thoát khi làm bài: dạng nút rõ ràng */
.qtop .back#quit { flex: none; gap: 6px; padding: 7px 14px 7px 10px; border-radius: 99px; background: var(--card); border: 1.5px solid color-mix(in srgb, var(--bad) 35%, var(--line));
  color: var(--bad); font-weight: 800; box-shadow: var(--shadow); transition: background .15s, transform .15s; }
.qtop .back#quit:hover { background: var(--bad-bg); transform: translateY(-1px); }
@media (max-width: 679px) { .qtop .back#quit { padding: 6px 11px 6px 8px; } }

/* ---------- duyệt mẫu (Quản trị) ---------- */
.rv-bar { margin-bottom: 16px; } .rv-bar .grades { margin-top: 0; }
.rv-lb { align-self: center; font-size: .9rem; margin-right: 2px; }
.rv-sum { margin: 12px 0 0; }
.rv-sk { margin-bottom: 16px; } .rv-sk h2 { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 0; }
.rv-sk h2 small { font-size: .8rem; font-weight: 600; width: 100%; }
.rv-lv { border: 1px solid var(--line); border-left: 5px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-top: 12px; }
.rv-lv.ok { border-left-color: var(--ok); background: color-mix(in srgb, var(--ok-bg) 45%, transparent); }
.rv-lv.bad { border-left-color: var(--bad); background: color-mix(in srgb, var(--bad-bg) 45%, transparent); }
.rv-lvh { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.rv-lvh .btn { margin-left: auto; }
.rv-ck { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: .9rem; cursor: pointer; }
.rv-ck input { width: 18px; height: 18px; }
.rv-q { padding: 12px 0; border-bottom: 1px dashed var(--line); } .rv-q:last-child { border-bottom: 0; }
.rv-q .stem { font-size: 1.02rem; }
.rv-opts { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 6px; }
@media (min-width: 640px) { .rv-opts { grid-template-columns: 1fr 1fr; } }
.rv-opts li { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 10px; border: 1.5px solid var(--line); }
.rv-opts li.ok { border-color: var(--ok); background: var(--ok-bg); font-weight: 700; }
.rv-opts .key { flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; background: var(--tint); color: var(--accent); font-weight: 800; font-size: .85rem; }
.rv-opts li.ok .key { background: var(--ok); color: #fff; }
.rv-note { display: grid; gap: 4px; margin-top: 6px; font-weight: 700; font-size: .88rem; color: var(--bad); }
.rv-note textarea, .rv-out { width: 100%; box-sizing: border-box; padding: 8px 10px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); font: .95rem var(--font); resize: vertical; }

/* ---------- In đề kiểm tra ---------- */
.prch { margin: 6px 0 10px; }
.prch-h { border: 0; background: none; padding: 4px 0; font: 800 .95rem var(--font); color: var(--accent); cursor: pointer; text-align: left; }
.prch-h:hover { text-decoration: underline; }
.prgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 6px; }
.prsk { display: flex; gap: 8px; align-items: flex-start; padding: 7px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); cursor: pointer; font-size: .92rem; }
.prsk input { width: 18px; height: 18px; margin-top: 2px; flex: none; accent-color: var(--accent); }
.prsk small { color: var(--accent); font-weight: 800; margin-right: 2px; }
.prsk:has(input:checked) { border-color: var(--accent); background: var(--tint); }
label.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; font-weight: 600; }
label.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.prprev { overflow-x: auto; background: #e9edf3; }
.paper { --ink: #000; --muted: #333; --accent: #111; --accent2: #444; --orange: #000; --tint: #eee; --line: #bbb; --soft: #fff; --card: #fff;
  background: #fff; color: #000; max-width: 210mm; margin: 0 auto; padding: 14mm 14mm; font: 12.5pt/1.5 "Times New Roman", Times, serif; box-shadow: 0 2px 14px rgba(0,0,0,.15); }
.paper .m { font-size: 1.02em; }
.paper .ph { display: flex; justify-content: space-between; gap: 16px; text-align: center; }
.paper .ph > div:first-child { min-width: 34%; }
.paper .ph-r b { font-size: 14pt; }
.paper .pmuted { color: #333; font-size: 11pt; }
.paper .pname { margin: 10px 0 4px; } .paper .pname span { display: inline-block; width: 46%; border-bottom: 1px dotted #000; } .paper .pname span.sm { width: 14%; }
.paper .psec { font: 700 13pt "Times New Roman", serif; margin: 14px 0 2px; }
.paper .pnote { margin: 0 0 6px; font-style: italic; }
.paper .pq { margin: 7px 0; break-inside: avoid; page-break-inside: avoid; }
.paper .popts { display: grid; gap: 2px 14px; margin: 3px 0 0 18px; } .paper .popts.c4 { grid-template-columns: repeat(4, 1fr); }
.paper .popts.c2 { grid-template-columns: 1fr 1fr; } .paper .popts.c1 { grid-template-columns: 1fr; }
.paper .pfig { margin: 4px 0; text-align: center; } .paper .pfig .fig { max-width: 62%; max-height: 50mm; width: auto; height: auto; } .paper .pfig .ftab { font-size: 11pt; }
.paper .pitem { margin: 4px 0 4px 18px; }
.paper .plines div { border-bottom: 1px dotted #777; height: 8mm; }
.paper .pans { border-collapse: collapse; margin: 4px 0 8px; } .paper .pans th, .paper .pans td { border: 1px solid #000; min-width: 9mm; height: 7mm; padding: 1px 4px; text-align: center; font-size: 11pt; }
.paper .pend { text-align: center; font-weight: 700; margin-top: 12px; }
.paper .pkey { break-before: page; page-break-before: always; margin-top: 18px; padding-top: 10px; border-top: 2px dashed #999; }
.paper .pkey h2 { text-align: center; margin: 0; font: 700 15pt "Times New Roman", serif; } .paper .pcenter { text-align: center; margin: 2px 0 8px; }
.paper .pexp summary { font-weight: 700; cursor: pointer; margin: 4px 0; } .paper .pexp p { margin: 3px 0; font-size: 11.5pt; }
.paper .fig .tx { fill: #000; } .paper .fig .rg { fill: #888; fill-opacity: .22; }
#printArea { display: none; }
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff !important; padding: 0 !important; }
  body.printing > *:not(#printArea), body:has(#printArea:not(:empty)) > *:not(#printArea) { display: none !important; }
  #printArea { display: block; }
  body::before, body::after { display: none !important; }
  #printArea .paper { box-shadow: none; padding: 0; max-width: none; }
  #printArea .pkey { border-top: 0; margin-top: 0; padding-top: 0; }
  #printArea .pexp summary { list-style: none; }
}
