/* Giao diện ưu tiên máy tính và iPad; vẫn dùng được trên điện thoại. */
:root {
  --bg: #e8f2ff;
  --card: #ffffff;
  --ink: #1d2b53;
  --muted: #5b6990;
  --line: #d5e1f5;
  --toan: #5a4fe8;
  --hoa: #06896b;
  --ly: #dc4c0b;
  --anh: #d42f7c;
  --accent: var(--toan);
  --accent-soft: #e9e7ff;
  --grad: linear-gradient(135deg, #5a4fe8, #8f5cf7);
  --accent-dark: color-mix(in srgb, var(--accent) 70%, #000);
  --sun: #ffd43b;
  --sun-dark: #e0a800;
  --ok: #12813f;
  --ok-soft: #dcf7e5;
  --bad: #c92a2a;
  --bad-soft: #ffe5e5;
  --hint: #8a5a00;
  --hint-soft: #fff3c9;
  --radius: 18px;
  --font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Baloo 2", "Be Vietnam Pro", system-ui, sans-serif;
}
[data-subject="toan"] { --accent: var(--toan); --accent-soft: #e9e7ff; --grad: linear-gradient(135deg, #5a4fe8, #8f5cf7); }
[data-subject="hoa"] { --accent: var(--hoa); --accent-soft: #d8f6ec; --grad: linear-gradient(135deg, #06896b, #19b88f); }
[data-subject="ly"] { --accent: var(--ly); --accent-soft: #ffe8d9; --grad: linear-gradient(135deg, #dc4c0b, #f7861d); }
[data-subject="anh"] { --accent: var(--anh); --accent-soft: #ffe2ef; --grad: linear-gradient(135deg, #d42f7c, #f2669f); }
[data-subject] { --accent-dark: color-mix(in srgb, var(--accent) 70%, #000); }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 17px; line-height: 1.65;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-family: var(--serif); font-size: 2rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.08rem; }
p { margin: 0 0 .9em; }
a { color: var(--accent); }
button { font: inherit; color: inherit; cursor: pointer; }
sub, sup { font-size: .72em; line-height: 0; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 28px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30; min-height: 57px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); text-decoration: none; white-space: nowrap; }
.brand-mark {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 9px;
  background: var(--ink); color: #fff; font-family: var(--serif); font-size: 1.1rem;
}
.brand-mark.big { width: 56px; height: 56px; font-size: 1.9rem; border-radius: 16px; }
.grade {
  font: inherit; font-weight: 600; font-size: .92rem; padding: 6px 10px; min-height: 36px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink);
}
.search { position: relative; flex: 1; max-width: 440px; margin-left: auto; }
.search input {
  width: 100%; font: inherit; font-size: .92rem; padding: 7px 14px; min-height: 36px;
  border: 1px solid var(--line); border-radius: 99px; background: var(--bg);
}
.search input:focus, .menu input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.search-results, .menu {
  position: absolute; top: calc(100% + 8px); background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 12px 32px rgba(0, 0, 0, .14); z-index: 50;
}
.search-results { left: 0; right: 0; padding: 6px; max-height: 70vh; overflow-y: auto; }
.result { display: block; padding: 8px 12px; border-radius: 8px; text-decoration: none; color: var(--ink); font-size: .92rem; line-height: 1.35; }
.result b { display: block; font-weight: 600; }
.result small { color: var(--muted); }
a.result:hover, a.result:focus { background: var(--accent-soft); }
.result.off { color: var(--muted); }
.topnav { display: flex; gap: 8px; align-items: center; }
.account { position: relative; }
.account > .btn { white-space: nowrap; }
.menu { right: 0; width: 270px; padding: 14px; display: grid; gap: 8px; font-size: .92rem; }
.menu form { display: grid; gap: 8px; }
.menu small { color: var(--muted); line-height: 1.35; }
.menu p { margin: 0; }
.menu input { font: inherit; padding: 8px 10px; border: 1.5px solid var(--line); border-radius: 8px; width: 100%; }

.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px;
  padding: 10px 18px; font-weight: 600; min-height: 44px;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: .9rem; }
.btn.ghost { background: transparent; }

/* ---------- Trang chủ ---------- */
.home { max-width: 1180px; margin: 0 auto; padding: 36px 28px 80px; }
.home-hero { margin-bottom: 28px; }
.home-hero p { color: var(--muted); max-width: 60ch; }
.home.narrow { max-width: 820px; }
.home .back { display: inline-block; margin-bottom: 14px; text-decoration: none; font-size: .95rem; }
.parent-note { --accent: #6d4bb5; --accent-soft: #eee8fa; }
.subject-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px; }
.subject-card {
  display: flex; flex-direction: column; gap: 6px; padding: 24px 22px; min-height: 250px;
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  color: var(--ink); text-decoration: none; transition: transform .15s, box-shadow .15s, border-color .15s;
}
a.subject-card:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: 0 14px 30px rgba(0, 0, 0, .08); }
.subject-card.soon { opacity: .62; }
.subject-icon {
  width: 54px; height: 54px; border-radius: 14px; display: grid; place-items: center; margin-bottom: 8px;
  background: var(--accent-soft); color: var(--accent); font-family: var(--serif); font-size: 1.5rem; font-weight: 600;
}
.subject-card h2 { font-family: var(--serif); font-size: 1.5rem; color: var(--accent); margin: 0; }
.subject-card p { color: var(--muted); font-size: .93rem; margin: 0; }
.subject-progress, .subject-card .pill { margin-top: auto; }
.subject-progress .meter { background: var(--accent-soft); margin: 0 0 6px; }
.subject-progress small { color: var(--muted); font-size: .8rem; }
.pill { align-self: flex-start; font-size: .78rem; font-weight: 600; padding: 3px 12px; border-radius: 99px; background: var(--line); color: var(--muted); }
.subject {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
}
.subject-head { padding: 22px 24px 18px; background: var(--accent-soft); border-bottom: 1px solid var(--line); }
.subject-head h2 { font-family: var(--serif); font-size: 1.6rem; color: var(--accent); margin-bottom: 2px; }
.subject-head small { color: var(--muted); }
.meter { height: 8px; background: #fff; border-radius: 99px; margin-top: 14px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.chapter { padding: 16px 24px 8px; }
.chapter h3 { font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.lesson-row {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 11px 12px; margin: 0 -12px; border: 0; background: none; border-radius: 10px;
  text-decoration: none; color: var(--ink);
}
a.lesson-row:hover { background: var(--accent-soft); }
.lesson-row .num {
  flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  border: 2px solid var(--accent); color: var(--accent); font-weight: 700; font-size: .9rem;
}
.lesson-row.done .num { background: var(--accent); color: #fff; }
.lesson-row.locked, .lesson-row.soon { color: var(--muted); }
.lesson-row.locked .num, .lesson-row.soon .num { border-color: var(--line); color: var(--muted); }
.lesson-row .tag { margin-left: auto; font-size: .78rem; color: var(--muted); white-space: nowrap; }
.lesson-row.done .tag { color: var(--ok); font-weight: 600; }
.home-foot { margin-top: 20px; color: var(--muted); font-size: .9rem; }

.muted { color: var(--muted); font-size: .92rem; }
.row-wrap { display: flex; align-items: center; gap: 10px; }
.row-wrap > .lesson-row { flex: 1; min-width: 0; margin-right: 0; }
.row-wrap .lesson-row .tag { display: none; }
.row-state { color: var(--muted); white-space: nowrap; }
.reset-all { margin-top: 14px; }

/* ---------- Bài kiểm tra ---------- */
.tests { margin-top: 36px; }
.tests-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.tests-head h2, .maker + div h2 { font-family: var(--serif); margin: 0; }
.test-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; margin-top: 8px;
}
.test-row small { display: block; color: var(--muted); font-size: .84rem; }
.test-actions { display: flex; gap: 6px; }
.test-actions .btn { text-decoration: none; display: inline-flex; align-items: center; }
.tests-head .btn, .print-bar .btn { text-decoration: none; display: inline-flex; align-items: center; }
.maker { display: grid; gap: 16px; }
.maker + div { margin-top: 28px; }
.field { display: grid; gap: 6px; }
.field select, .field input[type="text"] { font: inherit; padding: 9px 12px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; max-width: 420px; }
.check-grid { display: grid; gap: 4px; }
.check { display: flex; gap: 8px; align-items: baseline; padding: 4px 0; }
.check small { color: var(--muted); }
.home.narrow h2 { margin-top: 28px; font-size: 1.15rem; }
.tq .option.pick { display: flex; gap: 10px; align-items: baseline; cursor: pointer; }
.tq .option.pick:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.tq .option.pick.right { border-color: var(--ok); background: var(--ok-soft); }
.tq .option.pick.wrong { border-color: var(--bad); background: var(--bad-soft); }
.ds-table { width: 100%; border-collapse: collapse; }
.ds-table td { border-top: 1px solid var(--line); padding: 9px 6px; vertical-align: top; }
.ds-table td:nth-child(2) { white-space: nowrap; width: 150px; }
.ds-pick { margin-right: 12px; cursor: pointer; }
.ds-table tr.right .ds-key { color: var(--ok); font-weight: 700; }
.ds-table tr.wrong .ds-key { color: var(--bad); font-weight: 700; white-space: nowrap; }
.essay { width: 100%; font: inherit; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px; resize: vertical; }
.tl-grade { margin-top: 12px; }
.tl-grade input { width: 90px; }
.test-clock { position: sticky; top: 65px; z-index: 5; }

/* ---------- Bản in đề ---------- */
.print-wrap { padding: 24px 16px 60px; }
.print-bar { max-width: 210mm; margin: 0 auto 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.paper {
  max-width: 210mm; margin: 0 auto 24px; background: #fff; color: #000; padding: 18mm 16mm;
  border: 1px solid var(--line); font-family: "Times New Roman", Times, serif; font-size: 13pt; line-height: 1.45;
}
.paper h3 { font-size: 13pt; margin: 14pt 0 4pt; }
.p-head { display: flex; justify-content: space-between; gap: 20px; line-height: 2; }
.p-score { border: 1px solid #000; width: 34mm; height: 22mm; text-align: center; font-style: italic; line-height: 1.4; padding-top: 2mm; }
.p-title { text-align: center; font-size: 15pt; margin: 12pt 0 2pt; font-family: inherit; }
.p-sub { text-align: center; font-style: italic; margin: 0 0 8pt; }
.p-note { font-style: italic; margin: 0 0 6pt; }
.p-q { margin: 0 0 9pt; break-inside: avoid; }
.p-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 1pt 18pt; margin-top: 2pt; padding-left: 12pt; }
.p-ds, .p-key { border-collapse: collapse; width: 100%; margin-top: 4pt; }
.p-ds th, .p-ds td, .p-key th, .p-key td { border: 1px solid #000; padding: 3pt 6pt; }
.p-ds th:nth-child(n+2), .p-ds td:nth-child(n+2) { width: 16mm; text-align: center; }
.p-key td, .p-key th { text-align: center; }
.p-lines > div { border-bottom: 1px dotted #555; height: 9mm; }
.p-end { text-align: center; margin-top: 14pt; font-weight: bold; }
.answer-page { break-before: page; }
@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; }
  .topbar, .no-print { display: none !important; }
  .print-wrap { padding: 0; }
  .paper { border: 0; padding: 0; margin: 0; max-width: none; }
}

/* ---------- Trang bài học ---------- */
.lesson { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: calc(100vh - 57px); }
.lesson.with-tutor { grid-template-columns: 250px minmax(0, 1fr) 370px; }
.stepper { padding: 24px 16px; border-right: 1px solid var(--line); background: var(--card); }
.stepper .back { font-size: .9rem; text-decoration: none; }
.stepper h2 { font-size: 1.05rem; margin: 14px 0 4px; }
.stepper .sub { color: var(--muted); font-size: .85rem; margin-bottom: 16px; }
.step-list { list-style: none; margin: 0; padding: 0; }
.step-list button {
  display: flex; gap: 10px; align-items: center; width: 100%; text-align: left;
  border: 0; background: none; padding: 8px 10px; border-radius: 9px; font-size: .92rem;
}
.step-list button:disabled { color: var(--muted); cursor: default; }
.step-list .dot {
  flex: none; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line);
  display: grid; place-items: center; font-size: .7rem; font-weight: 700;
}
.step-list .passed .dot { background: var(--accent); border-color: var(--accent); color: #fff; }
.step-list .current button { background: var(--accent-soft); font-weight: 600; }
.step-list .current .dot { border-color: var(--accent); }

.stage { padding: 32px 40px 110px; }
.stage-inner { max-width: 780px; margin: 0 auto; }
.kind { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); font-weight: 700; }
.stage h1 { font-size: 1.75rem; margin-top: 4px; }
.goals { background: var(--accent-soft); border-radius: var(--radius); padding: 16px 20px; margin-bottom: 20px; }
.goals ul, .prose ul, .prose ol { margin: 0 0 .9em; padding-left: 1.3em; }
.prose li { margin-bottom: .3em; }
.prose strong { color: var(--accent); }
.note {
  border-left: 4px solid var(--accent); background: var(--accent-soft);
  padding: 12px 16px; border-radius: 0 10px 10px 0; margin: 0 0 1em;
}
.formula {
  font-family: var(--serif); font-size: 1.35rem; text-align: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin: 0 0 1em;
}
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; line-height: 1.2; }
.frac > span:first-child { border-bottom: 2px solid currentColor; padding: 0 6px; }
.prose table { border-collapse: collapse; width: 100%; margin: 0 0 1em; font-size: .95rem; }
.prose th, .prose td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; }
.prose th { background: var(--accent-soft); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; margin: 0 0 18px; }
.q-title { font-weight: 600; margin-bottom: 12px; }
.options { display: grid; gap: 8px; }
.option {
  text-align: left; border: 1.5px solid var(--line); background: #fff; border-radius: 10px;
  padding: 11px 14px; min-height: 46px;
}
.option:hover:not(:disabled) { border-color: var(--accent); }
.option.right { border-color: var(--ok); background: var(--ok-soft); }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.option:disabled { cursor: default; }
.num-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.num-row input {
  font: inherit; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px; width: 160px; min-height: 46px;
}
.feedback { margin-top: 12px; padding: 10px 14px; border-radius: 10px; font-size: .95rem; }
.feedback.ok { background: var(--ok-soft); color: #14532d; }
.feedback.bad { background: var(--bad-soft); color: #7f1d1d; }
.feedback.hint { background: var(--hint-soft); color: var(--hint); }
.ex-step { border-left: 3px solid var(--accent); padding: 4px 0 4px 14px; margin: 12px 0; }
.ex-step b { color: var(--accent); }
.score { text-align: center; }
.score .big { font-family: var(--serif); font-size: 2.6rem; color: var(--accent); }

.stage-nav {
  position: fixed; bottom: 0; left: 250px; right: 0; display: flex; justify-content: space-between; gap: 12px;
  padding: 14px 40px; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px); border-top: 1px solid var(--line); z-index: 10;
}
.lesson.with-tutor .stage-nav { right: 370px; }
.stage-nav .why { align-self: center; color: var(--muted); font-size: .88rem; margin-left: auto; }

/* ---------- Gia sư AI ---------- */
.tutor {
  display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--card);
  position: sticky; top: 57px; height: calc(100vh - 57px);
}
.tutor-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.tutor-head .avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700;
}
.tutor-head small { display: block; color: var(--muted); font-size: .78rem; line-height: 1.3; }
.tutor-head .btn { margin-left: auto; }
.tutor-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 92%; padding: 10px 13px; border-radius: 14px; font-size: .93rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.bot { background: var(--accent-soft); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.me { background: var(--ink); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.err { background: var(--bad-soft); color: #7f1d1d; align-self: flex-start; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 10px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 5px 12px; font-size: .82rem; }
.chip:hover { border-color: var(--accent); }
.tutor-form { display: flex; gap: 8px; padding: 12px 16px 16px; border-top: 1px solid var(--line); }
.tutor-form textarea {
  flex: 1; font: inherit; font-size: .95rem; resize: none; border: 1.5px solid var(--line);
  border-radius: 10px; padding: 9px 11px; height: 46px; max-height: 120px;
}
.tutor-form textarea:focus, .num-row input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- Mô hình tương tác ---------- */
.widget { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin: 0 0 18px; }
.widget-title { font-weight: 600; margin-bottom: 8px; }
.widget svg { display: block; max-width: 100%; height: auto; margin: 0 auto; }
.widget .controls { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; margin-top: 10px; font-size: .92rem; }
.widget input[type="range"] { width: 200px; accent-color: var(--accent); }
.widget select { font: inherit; padding: 6px 10px; border-radius: 8px; border: 1.5px solid var(--line); }
.widget .readout { color: var(--muted); font-size: .92rem; margin-top: 8px; }
.ptable { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 5px; }
.ptable button {
  border: 1.5px solid transparent; border-radius: 8px; padding: 5px 2px; text-align: center; line-height: 1.2; min-height: 54px;
}
.ptable button b { display: block; font-size: 1.05rem; }
.ptable button small { font-size: .68rem; }
.ptable .metal { background: #dbeafe; }
.ptable .nonmetal { background: #fde9c8; }
.ptable .noble { background: #e9defa; }
.ptable button.sel { border-color: var(--ink); }
.ptable .head { font-size: .75rem; color: var(--muted); text-align: center; font-weight: 600; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .82rem; margin-top: 10px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- Đăng nhập ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 36px 32px;
  width: min(400px, 100%); text-align: center; display: grid; gap: 12px; justify-items: center;
}
.login-card input { font: inherit; width: 100%; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 10px; text-align: center; }
.login-card .btn { width: 100%; }
.login-error { color: var(--bad); min-height: 1.5em; margin: 0; }

/* ---------- iPad dọc và màn hình hẹp ---------- */
@media (max-width: 1100px) {
  .subject-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .subject-card { min-height: 210px; }
  .lesson.with-tutor { grid-template-columns: 250px minmax(0, 1fr); }
  .tutor {
    position: fixed; top: 0; right: 0; bottom: 0; height: auto; width: min(400px, 100%); z-index: 40;
    box-shadow: -12px 0 40px rgba(0, 0, 0, .18);
  }
  .lesson.with-tutor .stage-nav { right: 0; }
}
@media (max-width: 820px) {
  .brand-name { display: none; }
  .topbar { gap: 8px; }
  .lesson, .lesson.with-tutor { grid-template-columns: 1fr; }
  .stepper { border-right: 0; border-bottom: 1px solid var(--line); padding: 12px 16px; }
  .stepper h2, .stepper .sub { display: none; }
  .step-list { display: flex; gap: 4px; overflow-x: auto; margin-top: 8px; }
  .step-list button span:last-child { display: none; }
  .step-list .current button span:last-child { display: inline; white-space: nowrap; }
  .stage { padding: 22px 16px 110px; }
  .stage-nav { left: 0; padding: 12px 16px; }
  .topbar { padding: 8px 12px; }
  .topnav .btn, .account > .btn { padding: 6px 9px; }
  .home { padding: 24px 16px 60px; }
}

/* ================= Giao diện tươi trẻ cho học sinh cấp 2 ================= */
body {
  background-color: var(--bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260' fill='none' stroke-width='3' stroke-linecap='round' stroke-linejoin='round' opacity='.55'%3E%3Cpath d='M30 28l6 12 13 2-9 9 2 13-12-6-12 6 2-13-9-9 13-2z' stroke='%23ffc94d'/%3E%3Ccircle cx='200' cy='50' r='12' stroke='%2385c8ff'/%3E%3Cpath d='M120 110h24M132 98v24' stroke='%23ff9ec4'/%3E%3Cpath d='M40 196l16-28 16 28z' stroke='%2376dbb2'/%3E%3Cpath d='M168 200q10-16 20 0t20 0' stroke='%23b9a2ff'/%3E%3Crect x='100' y='200' width='18' height='18' rx='4' transform='rotate(20 109 209)' stroke='%2385c8ff'/%3E%3Ccircle cx='95' cy='40' r='4' fill='%23ff9ec4' stroke='none'/%3E%3Ccircle cx='232' cy='140' r='5' fill='%23ffc94d' stroke='none'/%3E%3Ccircle cx='20' cy='120' r='4' fill='%2376dbb2' stroke='none'/%3E%3C/svg%3E"), linear-gradient(180deg, #dff0ff 0%, #efe9ff 55%, #fff1dd 100%);
  background-size: 260px 260px, cover;
  background-attachment: fixed;
}
h1 { font-weight: 800; letter-spacing: -.01em; }
h2 { font-weight: 700; }

/* Nút bấm kiểu "nhấn được" */
.btn {
  border: 2px solid var(--line); border-radius: 14px; font-weight: 700;
  box-shadow: 0 4px 0 var(--line); transition: transform .08s, box-shadow .08s, filter .15s;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.btn.primary { border-color: var(--accent-dark); box-shadow: 0 4px 0 var(--accent-dark); }
.btn.primary:active:not(:disabled) { box-shadow: 0 1px 0 var(--accent-dark); }
.btn.ghost { box-shadow: none; }
.btn.sun { background: var(--sun); border-color: var(--sun-dark); box-shadow: 0 4px 0 var(--sun-dark); color: #4a3500; }
.btn.small { border-radius: 12px; box-shadow: 0 3px 0 var(--line); }
.btn.small.primary { box-shadow: 0 3px 0 var(--accent-dark); }
.btn.small.sun { box-shadow: 0 3px 0 var(--sun-dark); }
.btn.small.ghost { box-shadow: none; }

/* Thanh trên cùng */
.topbar { border-bottom: 3px solid var(--line); background: rgba(255, 255, 255, .94); backdrop-filter: blur(8px); }
.brand { font-family: var(--serif); font-size: 1.3rem; font-weight: 800; }
.brand-mark { background: linear-gradient(135deg, #5a4fe8, #f2669f 60%, #ffb21d); border-radius: 12px; font-weight: 800; }
.grade { border-width: 2px; border-radius: 12px; background: #fff7d6; border-color: var(--sun-dark); color: #4a3500; }
.search input { border-width: 2px; background: #f2f7ff; }
.menu, .search-results { border-width: 2px; border-radius: 16px; }

/* Trang chủ */
.home-hero h1 { font-size: 2.5rem; margin-bottom: .2em; }
.home-hero p { font-size: 1.05rem; }
.subject-card {
  background: var(--grad); color: #fff; border: 0; border-radius: 24px;
  box-shadow: 0 8px 0 var(--accent-dark), 0 18px 28px rgba(29, 43, 83, .16);
}
a.subject-card:hover { transform: translateY(-5px) rotate(-1deg); box-shadow: 0 13px 0 var(--accent-dark), 0 24px 32px rgba(29, 43, 83, .2); }
a.subject-card:active { transform: translateY(4px); box-shadow: 0 3px 0 var(--accent-dark); }
.subject-card h2 { color: #fff; font-size: 1.8rem; font-weight: 800; }
.subject-card p { color: #fff; opacity: .95; font-weight: 500; }
.subject-icon { background: #fff; font-size: 1.8rem; width: 62px; height: 62px; border-radius: 18px; box-shadow: 0 4px 0 rgba(0, 0, 0, .12); }
.subject-progress .meter { background: rgba(255, 255, 255, .35); height: 10px; }
.subject-progress .meter > i { background: #fff; }
.subject-progress small { color: #fff; font-weight: 600; }
.subject-card.soon { opacity: 1; filter: saturate(.35); }
.pill { background: rgba(255, 255, 255, .9); color: var(--ink); }

/* Trang một môn */
.home .back, .stepper .back { font-weight: 700; }
.subject { border: 2px solid var(--line); border-radius: 24px; box-shadow: 0 6px 0 rgba(29, 43, 83, .07); }
.subject-head { background: var(--grad); color: #fff; border-bottom: 0; }
.subject-head h2 { color: #fff; font-size: 1.9rem; font-weight: 800; }
.subject-head small { color: #fff; opacity: .95; font-weight: 500; }
.subject-head .meter { background: rgba(255, 255, 255, .35); height: 10px; }
.subject-head .meter > i { background: #fff; }
.chapter h3 { color: var(--accent); font-weight: 700; }
.lesson-row { border-radius: 14px; font-weight: 500; }
.lesson-row .num { width: 38px; height: 38px; background: var(--accent-soft); border-width: 0; font-weight: 800; }
.lesson-row.done .num { background: var(--accent); }
.lesson-row.locked .num, .lesson-row.soon .num { background: #eef2f9; }
a.lesson-row .tag { background: var(--accent-soft); color: var(--accent); font-weight: 700; padding: 3px 12px; border-radius: 99px; }
.lesson-row.done .tag { background: var(--ok-soft); color: var(--ok); }
.tests { border-top: 2px dashed var(--line); margin-top: 8px; padding-bottom: 20px; }
.tests .tests-head h3 { margin: 0; }
.test-row { border-width: 2px; border-radius: 16px; }

/* Trang bài học */
.stepper { background: rgba(255, 255, 255, .9); border-right: 3px solid var(--line); }
.step-list button { border-radius: 12px; font-weight: 500; }
.step-list .dot { width: 26px; height: 26px; font-size: .78rem; }
.step-list .current button { background: var(--accent); color: #fff; }
.step-list .current .dot { background: #fff; color: var(--accent); border-color: #fff; }
.stage-inner {
  background: #fff; border: 2px solid var(--line); border-radius: 26px; padding: 30px 36px 34px;
  box-shadow: 0 8px 0 rgba(29, 43, 83, .07);
}
.kind { display: inline-block; background: var(--accent); color: #fff; padding: 3px 14px; border-radius: 99px; letter-spacing: .04em; }
.stage h1 { font-size: 2rem; margin-top: 10px; }
.goals { border: 2px dashed var(--accent); }
.note { border-left-width: 6px; border-radius: 6px 14px 14px 6px; }
.formula { background: var(--accent-soft); border: 2px dashed var(--accent); font-weight: 700; border-radius: 16px; }
.prose th { color: var(--accent-dark); }
.card { border-width: 2px; }
.stage-inner .card { background: #f8fbff; }
.option { border-width: 2px; border-radius: 14px; box-shadow: 0 3px 0 var(--line); font-weight: 500; transition: transform .08s, box-shadow .08s; }
.option:hover:not(:disabled) { background: var(--accent-soft); }
.option:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.option.right { box-shadow: 0 3px 0 var(--ok); }
.option.wrong { box-shadow: 0 3px 0 var(--bad); }
.num-row input, .essay, .field select, .field input[type="text"] { border-width: 2px; border-radius: 12px; }
.feedback { border-radius: 14px; border: 2px solid transparent; }
.feedback.ok { border-color: #9be0b3; }
.feedback.bad { border-color: #ffb3b3; }
.feedback.hint { border-color: #ffdf80; }
.ex-step { border-left-width: 5px; background: var(--accent-soft); border-radius: 0 12px 12px 0; padding: 8px 14px; }
.score .big { font-size: 3.2rem; font-weight: 800; }
.stage-nav { background: rgba(255, 255, 255, .92); border-top: 3px solid var(--line); }
.widget { border-width: 2px; background: #fff; }

/* Gia sư */
.tutor { border-left: 3px solid var(--line); }
.tutor-head { background: var(--grad); color: #fff; border-bottom: 0; }
.tutor-head small { color: #fff; opacity: .92; }
.tutor-head .avatar { background: #fff; color: var(--accent); font-family: var(--serif); font-weight: 800; }
.tutor-head .btn { background: rgba(255, 255, 255, .2); color: #fff; border-color: transparent; }
.msg { border-radius: 18px; }
.msg.me { background: var(--accent); }
.chip { border-width: 2px; font-weight: 600; color: var(--accent); border-color: var(--accent-soft); }
.chip:hover { background: var(--accent-soft); }
.tutor-form textarea { border-width: 2px; border-radius: 14px; }

/* Đăng nhập */
.login-card { border: 2px solid var(--line); border-radius: 28px; box-shadow: 0 10px 0 rgba(29, 43, 83, .08); }
.login-card h1 { font-family: var(--serif); }
.login-card input { border-width: 2px; border-radius: 14px; }

@media (max-width: 820px) {
  .stage-inner { padding: 20px 18px 24px; border-radius: 20px; }
  .home-hero h1 { font-size: 2rem; }
  .stepper { border-right: 0; border-bottom: 3px solid var(--line); }
}
@media (prefers-reduced-motion: reduce) {
  .btn, .option, .subject-card { transition: none; }
  a.subject-card:hover { transform: none; }
}
@media print {
  body { background: #fff !important; }
}

/* Chỉnh sau khi xem thực tế */
.subject-head .btn { color: var(--ink); }
.home.narrow .subject-head h2 { font-size: 1.9rem; margin-top: 0; }
.subject-card.soon { filter: saturate(.55); opacity: .78; }

.ch-book { color: var(--muted); font-weight: 500; text-transform: none; letter-spacing: 0; }

/* Kí hiệu toán */
.sqrt { white-space: nowrap; }
.sqrt > span { border-top: 1.5px solid currentColor; padding: 0 2px 0 1px; }
.frac { font-size: .92em; margin: 0 2px; }
.option .frac, .q-title .frac { vertical-align: middle; }
.hat { position: relative; display: inline-block; padding-top: .12em; }
.hat::before { content: "^"; position: absolute; left: 0; right: 0; top: -.36em; text-align: center; font-size: .85em; font-weight: 700; line-height: 1; }

/* ================= Sửa hiển thị trên điện thoại ================= */
body { overflow-x: clip; }
.lesson > *, .stage, .stage-inner, .stepper { min-width: 0; }
.topbar .btn { white-space: nowrap; }
@media (max-width: 820px) {
  .lesson, .lesson.with-tutor { grid-template-columns: minmax(0, 1fr); }
  /* Header hai hàng: hàng trên là logo, lớp, nút; hàng dưới là ô tìm kiếm */
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .topbar .account { margin-left: auto; }
  .topbar .topnav { margin-left: auto; }
  .topbar .topnav:not(:empty) + .account { margin-left: 0; }
  .search { order: 5; flex: 1 1 100%; max-width: none; margin-left: 0; }
  .search input { min-height: 40px; font-size: 16px; }
  .grade { font-size: .88rem; padding: 6px 8px; min-height: 38px; }
  .topnav .btn, .account > .btn { font-size: .84rem; padding: 6px 10px; min-height: 38px; }
  .menu { width: min(270px, calc(100vw - 24px)); }
  .stage-nav { left: 0; right: 0; padding: 10px 12px; }
  .stage-nav .why { display: none; }
  .stage h1 { font-size: 1.5rem; }
  .prose table { display: block; overflow-x: auto; max-width: 100%; }
  .formula { font-size: 1.1rem; padding: 12px 8px; overflow-x: auto; }
  .test-clock { position: static; }
  .row-wrap { flex-wrap: wrap; row-gap: 2px; padding-bottom: 8px; border-bottom: 1px dashed var(--line); }
  .row-wrap > .lesson-row { flex: 1 1 100%; margin: 0; }
  .row-wrap .row-state { margin-left: 52px; white-space: normal; flex: 1; }
  .lesson-row { align-items: flex-start; }
  .lesson-row .tag { white-space: nowrap; font-size: .72rem; }
  .chapter { padding: 14px 16px 6px; }
  .subject-head { padding: 18px 16px 16px; }
  .tests-head { flex-wrap: wrap; }
  .test-row { padding: 12px; }
  .test-actions { flex-wrap: wrap; }
  .ds-table td:nth-child(2) { width: auto; }
  .ds-pick { display: block; margin: 0 0 4px; }
  .print-bar { padding: 0 4px; }
  .paper { padding: 10mm 6mm; font-size: 12pt; }
  .p-opts { grid-template-columns: 1fr; }
  .tutor { width: 100%; }
  .widget input[type="range"] { width: 150px; }
  .ptable { gap: 3px; }
  .ptable button { min-height: 46px; padding: 3px 1px; }
  .ptable button b { font-size: .92rem; }
}
@media (max-width: 560px) {
  .subject-grid { grid-template-columns: 1fr; gap: 16px; }
  .subject-card { min-height: 0; padding: 18px; display: grid; grid-template-columns: auto 1fr; column-gap: 14px; align-items: center; }
  .subject-card .subject-icon { grid-row: span 2; margin: 0; }
  .subject-card h2 { font-size: 1.5rem; }
  .subject-card .subject-progress, .subject-card .pill { grid-column: 1 / -1; margin-top: 10px; }
  .home-hero h1 { font-size: 1.6rem; }
  .brand-mark { width: 30px; height: 30px; }
}
@media (max-width: 380px) {
  .topnav .btn, .account > .btn { font-size: .78rem; padding: 6px 8px; }
  .grade { font-size: .82rem; }
}
@media (max-width: 560px) {
  /* Ở trang bài học, ẩn ô chọn lớp để nút "Hỏi cô Mai" và tài khoản nằm gọn một hàng */
  .topbar:has(.topnav:not(:empty)) .grade { display: none; }
}
