/* Layout: một cuốn vở ô ly mở ra — nhãn vở ở đầu, các "tab mục lục" dán mép trên,
   nội dung là các tờ giấy/ghi chú dán lên nền ô ly. Chế độ tối = bảng đen phấn trắng. */
:root {
  --paper: #fffefa;
  --sheet: #ffffff;
  --sheet-2: #f7f5ff;
  --ink: #2c2950;          /* mực xanh đen */
  --ink-soft: #5d5a7e;
  --muted: #8a87a6;
  --violet: #5b3fa8;       /* mực tím học trò */
  --violet-soft: #ece6ff;
  --margin: #ec6f7a;       /* lề đỏ */
  --grid-major: rgba(118, 96, 196, .26);
  --grid-minor: rgba(118, 96, 196, .12);
  --hl: #fff09a;           /* bút dạ quang */
  --hl-pink: #ffd3df;
  --pink: #ff8fab;
  --mint: #7fd6b4;
  --sky: #8fc6ff;
  --peach: #ffbf86;
  --butter: #ffe27a;
  --lilac: #c9b6ff;
  --wood: #f2c48d;
  --lv1: #23905f;
  --lv2: #2f6fd0;
  --lv3: #d77812;
  --lv4: #cf3a4a;
  --ok: #1f8f5a;
  --ok-bg: #e2f7ec;
  --bad: #c93545;
  --bad-bg: #ffe6e9;
  --shadow: 0 1px 0 rgba(44, 41, 80, .06), 0 6px 18px -8px rgba(44, 41, 80, .25);
  --line: rgba(44, 41, 80, .14);
  --water-1: #0b4f8a;
  --water-2: #cfe8ff;

  --font-hand: "Mali", "Comic Sans MS", "Segoe Print", cursive;
  --font-body: "Be Vietnam Pro", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --r-sm: 6px;
  --r-md: 12px;
  --cell: 32px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1d2a26;
    --sheet: #24342f;
    --sheet-2: #2a3b35;
    --ink: #f3f1e7;
    --ink-soft: #c9cfc4;
    --muted: #93a39a;
    --violet: #c7b6ff;
    --violet-soft: #34413f;
    --margin: #ff9aa4;
    --grid-major: rgba(255, 255, 255, .10);
    --grid-minor: rgba(255, 255, 255, .045);
    --hl: rgba(240, 214, 92, .38);
    --hl-pink: rgba(255, 143, 171, .25);
    --pink: #ff9db6;
    --mint: #79d3b0;
    --sky: #8cc3ff;
    --peach: #ffc08e;
    --butter: #f2d669;
    --lilac: #c8b8ff;
    --wood: #d8ab78;
    --lv1: #6fdba5;
    --lv2: #8fb8ff;
    --lv3: #ffb867;
    --lv4: #ff8b97;
    --ok: #7fe0ae;
    --ok-bg: rgba(127, 224, 174, .14);
    --bad: #ff98a3;
    --bad-bg: rgba(255, 152, 163, .14);
    --shadow: 0 1px 0 rgba(0, 0, 0, .2), 0 8px 22px -10px rgba(0, 0, 0, .6);
    --line: rgba(255, 255, 255, .14);
    --water-1: #062b4d;
    --water-2: #9fd0ff;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #1d2a26;
  --sheet: #24342f;
  --sheet-2: #2a3b35;
  --ink: #f3f1e7;
  --ink-soft: #c9cfc4;
  --muted: #93a39a;
  --violet: #c7b6ff;
  --violet-soft: #34413f;
  --margin: #ff9aa4;
  --grid-major: rgba(255, 255, 255, .10);
  --grid-minor: rgba(255, 255, 255, .045);
  --hl: rgba(240, 214, 92, .38);
  --hl-pink: rgba(255, 143, 171, .25);
  --pink: #ff9db6;
  --mint: #79d3b0;
  --sky: #8cc3ff;
  --peach: #ffc08e;
  --butter: #f2d669;
  --lilac: #c8b8ff;
  --wood: #d8ab78;
  --lv1: #6fdba5;
  --lv2: #8fb8ff;
  --lv3: #ffb867;
  --lv4: #ff8b97;
  --ok: #7fe0ae;
  --ok-bg: rgba(127, 224, 174, .14);
  --bad: #ff98a3;
  --bad-bg: rgba(255, 152, 163, .14);
  --shadow: 0 1px 0 rgba(0, 0, 0, .2), 0 8px 22px -10px rgba(0, 0, 0, .6);
  --line: rgba(255, 255, 255, .14);
  --water-1: #062b4d;
  --water-2: #9fd0ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15.5px;
  line-height: 1.6;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid-major) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-major) 1px, transparent 1px),
    linear-gradient(var(--grid-minor) 1px, transparent 1px);
  background-size: var(--cell) var(--cell), var(--cell) var(--cell), var(--cell) calc(var(--cell) / 4);
  background-attachment: fixed;
  min-height: 100vh;
}
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px);
  z-index: 30;
  background: var(--paper);
}
/* lề đỏ của trang vở */
.margin-line {
  position: fixed;
  top: 0; bottom: 0;
  left: max(28px, calc(env(safe-area-inset-left, 0px) + 12px));
  width: 2px;
  background: var(--margin);
  opacity: .55;
  pointer-events: none;
  z-index: 0;
}
@media (max-width: 720px) { .margin-line { display: none; } }

a { color: var(--violet); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px dashed var(--violet); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3, h4 { font-family: var(--font-hand); line-height: 1.25; text-wrap: balance; margin: 0; }
p { margin: 0; }
.hand { font-family: var(--font-hand); }
.muted { color: var(--muted); }
.mark { background: linear-gradient(transparent 58%, var(--hl) 58%, var(--hl) 92%, transparent 92%); padding: 0 .1em; }
.mark-pink { background: linear-gradient(transparent 58%, var(--hl-pink) 58%, var(--hl-pink) 92%, transparent 92%); }

/* ---------- Thanh trên: nhãn vở + tab ---------- */
.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 20;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 2px dashed var(--grid-major);
}
.topbar-in {
  max-width: 1240px;
  margin: 0 auto;
  padding-block: 10px 0;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px 22px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--ink);
  padding-bottom: 8px;
}
.brand svg { width: 40px; height: 40px; flex: none; }
.brand-name { font-family: var(--font-hand); font-weight: 700; font-size: 1.35rem; line-height: 1.1; }
.brand-sub { font-size: .74rem; color: var(--muted); letter-spacing: .04em; }
.tabs {
  display: flex; gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  margin-left: auto;
  max-width: 100%;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  text-decoration: none;
  color: var(--ink);
  font-family: var(--font-hand);
  font-weight: 600;
  font-size: .98rem;
  padding: 8px 16px 10px;
  border-radius: 12px 12px 0 0;
  border: 2px solid var(--line);
  border-bottom: none;
  background: var(--sheet);
  position: relative;
  top: 2px;
  display: flex; align-items: center; gap: 6px;
}
.tab .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--lilac)); border: 1.5px solid var(--ink); }
.tab[aria-current="page"] { background: var(--c, var(--lilac)); color: #2c2950; border-color: var(--ink); }
.tab[aria-current="page"] .dot { background: var(--sheet); }
.tab:hover { transform: translateY(-2px); }
@media (max-width: 520px) {
  .tab { padding: 7px 10px 9px; font-size: .9rem; gap: 4px; }
  .tab .dot { display: none; }
  .brand-sub { display: none; }
  .brand svg { width: 32px; height: 32px; }
}

/* ---------- Khung trang ---------- */
.page {
  position: relative; z-index: 1;
  max-width: 1240px;
  margin: 0 auto;
  padding-block: 22px 60px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid;
  gap: 22px;
}
@media (min-width: 721px) { .page { padding-left: max(52px, env(safe-area-inset-left, 0px)); } }

.subnav { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.subnav .crumb { font-family: var(--font-hand); font-weight: 700; font-size: 1.05rem; margin-right: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 13px;
  border-radius: 999px;
  border: 1.5px solid var(--ink);
  background: var(--sheet);
  color: var(--ink);
  text-decoration: none;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.4;
}
.chip:hover { background: var(--violet-soft); }
.chip[aria-pressed="true"], .chip[aria-current="page"] { background: var(--ink); color: var(--paper); }
.chip svg { width: 18px; height: 18px; }

.section-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 18px; }
.section-head h1 { font-size: clamp(1.6rem, 3.2vw, 2.3rem); }
.section-head .lead { color: var(--ink-soft); max-width: 62ch; }
.section-head .grow { flex: 1 1 300px; display: grid; gap: 6px; min-width: 0; }
.section-head .doodle-pin { width: 76px; height: 76px; flex: none; }

/* tờ giấy */
.sheet {
  background: var(--sheet);
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  position: relative;
  min-width: 0;
}
.sheet.tape::before {
  content: "";
  position: absolute; top: -11px; left: 50%;
  width: 92px; height: 22px;
  transform: translateX(-50%) rotate(-2deg);
  background: repeating-linear-gradient(45deg, color-mix(in srgb, var(--tape, var(--pink)) 80%, transparent) 0 6px, color-mix(in srgb, var(--tape, var(--pink)) 60%, transparent) 6px 12px);
  border-radius: 2px;
  opacity: .9;
}
.sheet.lined {
  background-image: linear-gradient(var(--grid-minor) 1px, transparent 1px);
  background-size: 100% 28px;
  background-position: 0 14px;
}

.grid-2 { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }
.grid-3 { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px;
  border-radius: 10px;
  border: 2px solid var(--ink);
  background: var(--butter);
  color: #2c2950;
  font-weight: 700;
  font-size: .92rem;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink);
  text-decoration: none;
  line-height: 1.3;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--ink); }
.btn:active { transform: translate(1px, 1px); box-shadow: 0 0 0 var(--ink); }
.btn.ghost { background: var(--sheet); color: var(--ink); }
.btn.violet { background: var(--lilac); }
.btn.mint { background: var(--mint); }
.btn.pink { background: var(--pink); }
.btn.sm { padding: 5px 11px; font-size: .84rem; border-width: 1.5px; box-shadow: 1.5px 1.5px 0 var(--ink); }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; }
.btn svg { width: 18px; height: 18px; }

.field { display: grid; gap: 4px; }
.field label, .lbl { font-size: .82rem; font-weight: 600; color: var(--ink-soft); }
.input, select.input, textarea.input {
  width: 100%;
  padding: 8px 11px;
  border-radius: 9px;
  border: 1.5px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  min-width: 0;
}
textarea.input { resize: vertical; line-height: 1.5; }
.input:focus { border-color: var(--violet); outline: none; box-shadow: 0 0 0 3px var(--violet-soft); }

/* ---------- Trang đầu ---------- */
.cover { display: grid; gap: 22px; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); align-items: center; }
@media (max-width: 860px) { .cover { grid-template-columns: 1fr; } }
.label-card {
  position: relative;
  background: var(--sheet);
  border: 3px double var(--ink);
  border-radius: 26px;
  padding: 26px 28px 24px;
  box-shadow: var(--shadow);
  display: grid; gap: 14px;
}
.label-card::after {
  content: ""; position: absolute; inset: 7px;
  border: 1.5px dashed var(--violet);
  border-radius: 20px;
  pointer-events: none;
  opacity: .5;
}
.label-card h1 { font-size: clamp(2rem, 5vw, 3.2rem); letter-spacing: .01em; }
.label-card .kicker { font-size: .78rem; letter-spacing: .14em; text-transform: uppercase; color: var(--violet); font-weight: 700; }
.label-rows { display: grid; gap: 4px; }
.label-row { display: flex; gap: 10px; align-items: baseline; font-size: .98rem; }
.label-row b { font-family: var(--font-hand); min-width: 92px; font-weight: 600; color: var(--ink-soft); }
.label-row span { flex: 1; border-bottom: 1.5px dotted var(--muted); font-family: var(--font-hand); font-size: 1.08rem; color: var(--violet); padding-bottom: 2px; min-width: 0; }
.desk { position: relative; min-height: 280px; }
.desk svg { position: absolute; }
.desk-note {
  position: relative;
  background: var(--butter);
  color: #2c2950;
  padding: 16px 18px;
  border-radius: 4px 4px 18px 4px;
  transform: rotate(2deg);
  box-shadow: var(--shadow);
  font-family: var(--font-hand);
  max-width: 300px;
  margin: 70px auto 0;
  display: grid; gap: 6px;
}
.desk-note b { font-size: 1.05rem; }

.subject-card { display: grid; gap: 12px; align-content: start; }
.subject-card header { display: flex; gap: 12px; align-items: center; }
.subject-card header svg { width: 58px; height: 58px; flex: none; }
.subject-card h2 { font-size: 1.35rem; }
.subject-card .what { display: grid; gap: 6px; }
.subject-card .what a { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); padding: 6px 10px; border-radius: 9px; border: 1.5px dashed transparent; }
.subject-card .what a:hover { border-color: var(--line); background: var(--sheet-2); }
.subject-card .what a span.n { font-family: var(--font-hand); font-weight: 700; color: var(--violet); min-width: 2.2em; text-align: right; font-variant-numeric: tabular-nums; }

.toc { width: 100%; border-collapse: collapse; font-size: .92rem; }
.toc th, .toc td { border: 1.5px solid var(--line); padding: 7px 10px; text-align: left; vertical-align: top; }
.toc th { font-family: var(--font-hand); background: var(--sheet-2); }
.toc td.st { white-space: nowrap; }
.pill { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .78rem; font-weight: 700; border: 1.5px solid currentColor; }
.pill.on { color: var(--ok); background: var(--ok-bg); }
.pill.soon { color: var(--muted); }
.scroll-x { overflow-x: auto; max-width: 100%; }

/* ---------- Công thức ---------- */
.formula-layout { display: grid; gap: 22px; grid-template-columns: 230px minmax(0, 1fr); align-items: start; }
@media (max-width: 900px) { .formula-layout { grid-template-columns: 1fr; } }
.toc-side { position: sticky; top: 120px; display: grid; gap: 4px; }
@media (max-width: 900px) { .toc-side { position: static; display: flex; flex-wrap: wrap; gap: 6px; } }
.toc-side a { font-size: .88rem; text-decoration: none; color: var(--ink-soft); padding: 4px 10px; border-left: 3px solid var(--line); }
.toc-side a:hover { color: var(--violet); border-color: var(--violet); }
@media (max-width: 900px) { .toc-side a { border: 1.5px solid var(--line); border-radius: 999px; } }
.toc-side .ch { font-family: var(--font-hand); font-weight: 700; color: var(--ink); margin-top: 8px; font-size: .95rem; border: none; padding-left: 0; }
.chapter { display: grid; gap: 18px; }
.chapter > h2 { font-size: 1.5rem; }
.chapter > h2 small { display: block; font-family: var(--font-body); font-size: .8rem; letter-spacing: .12em; text-transform: uppercase; color: var(--violet); font-weight: 700; }
.lesson { display: grid; gap: 12px; scroll-margin-top: 130px; }
.lesson h3 { font-size: 1.15rem; display: flex; align-items: center; gap: 8px; }
.lesson h3 .num { display: inline-grid; place-items: center; min-width: 30px; height: 30px; padding: 0 6px; border-radius: 8px; background: var(--tape, var(--lilac)); border: 1.5px solid var(--ink); color: #2c2950; font-size: .85rem; }
.f-list { display: grid; gap: 0; }
.f-item { display: grid; grid-template-columns: minmax(0, 200px) minmax(0, 1fr); gap: 6px 16px; padding: 10px 0; border-top: 1.5px dashed var(--line); }
.f-item:first-child { border-top: none; }
@media (max-width: 640px) { .f-item { grid-template-columns: 1fr; } }
.f-name { font-weight: 700; font-size: .92rem; }
.f-name .tag { display: inline-block; margin-left: 4px; font-size: .68rem; font-weight: 700; color: var(--lv3); border: 1px solid currentColor; border-radius: 5px; padding: 0 4px; vertical-align: 1px; }
.f-body { min-width: 0; overflow-x: auto; overflow-y: hidden; }
.f-body .note { font-size: .86rem; color: var(--ink-soft); margin-top: 4px; }
.f-body mjx-container[display="true"] { margin: .4em 0 !important; }
.tip-box { border: 2px dashed var(--lv3); border-radius: 12px; padding: 10px 14px; background: color-mix(in srgb, var(--peach) 16%, transparent); font-size: .92rem; display: grid; gap: 4px; }
.tip-box b.t { font-family: var(--font-hand); color: var(--lv3); }

/* ---------- Bài tập ---------- */
.filters { display: grid; gap: 10px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.filter-row .lbl { min-width: 70px; }
.stat-strip { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; font-size: .9rem; }
.stat-strip b { font-family: var(--font-hand); font-size: 1.2rem; color: var(--violet); font-variant-numeric: tabular-nums; }
.ex-list { display: grid; gap: 18px; }
.ex { display: grid; gap: 12px; min-width: 0; }
.ex-list > * { min-width: 0; }
.ex-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ex-head .qn { font-family: var(--font-hand); font-weight: 700; font-size: 1.1rem; }
.stamp {
  display: inline-block;
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: .78rem;
  padding: 1px 9px;
  border: 2px solid currentColor;
  border-radius: 7px;
  transform: rotate(-3deg);
  color: var(--lvc);
  background: color-mix(in srgb, var(--lvc) 10%, transparent);
}
.stamp.l1 { --lvc: var(--lv1); }
.stamp.l2 { --lvc: var(--lv2); }
.stamp.l3 { --lvc: var(--lv3); }
.stamp.l4 { --lvc: var(--lv4); }
.tagline { font-size: .78rem; color: var(--muted); font-weight: 600; }
.tag-real { font-size: .76rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--mint); color: #173d30; border: 1.5px solid var(--ink); }
.ex-q { min-width: 0; overflow-x: auto; }
.opts { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.opt {
  display: flex; gap: 10px; align-items: flex-start;
  text-align: left;
  padding: 8px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  cursor: pointer;
  min-width: 0;
}
.opt .L { font-family: var(--font-hand); font-weight: 700; width: 26px; height: 26px; flex: none; border-radius: 50%; display: grid; place-items: center; border: 1.5px solid var(--ink); background: var(--sheet); }
.opt .T { min-width: 0; overflow-x: auto; padding-top: 1px; }
.opt:hover { border-color: var(--violet); }
.opt[aria-pressed="true"] { border-color: var(--violet); background: var(--violet-soft); }
.opt[aria-pressed="true"] .L { background: var(--violet); color: var(--sheet); border-color: var(--violet); }
.opt.right { border-color: var(--ok); background: var(--ok-bg); }
.opt.right .L { background: var(--ok); color: var(--sheet); border-color: var(--ok); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.tf-table { width: 100%; border-collapse: collapse; }
.tf-table td { border-top: 1.5px dashed var(--line); padding: 8px 6px; vertical-align: middle; }
.tf-table td.k { font-family: var(--font-hand); font-weight: 700; width: 28px; }
.tf-table td.s { min-width: 0; overflow-x: auto; }
@media (max-width: 560px) {
  .tf-table, .tf-table tbody { display: block; }
  .tf-table tr { display: grid; grid-template-columns: 26px minmax(0, 1fr); border-top: 1.5px dashed var(--line); padding: 6px 0; }
  .tf-table td { border-top: none; padding: 2px 4px; }
  .tf-table td.c { grid-column: 2; width: auto; }
}
.tf-table td.c { white-space: nowrap; width: 1%; }
.tf-btn { padding: 3px 11px; border-radius: 8px; border: 1.5px solid var(--line); background: var(--paper); cursor: pointer; font-weight: 700; font-size: .85rem; }
.tf-btn[aria-pressed="true"] { background: var(--violet); color: var(--sheet); border-color: var(--violet); }
.tf-btn.right { background: var(--ok); border-color: var(--ok); color: var(--sheet); }
.tf-btn.wrong { background: var(--bad); border-color: var(--bad); color: var(--sheet); }
.short-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.short-row .input { max-width: 180px; font-variant-numeric: tabular-nums; }
.ex-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.feedback { font-weight: 700; font-size: .92rem; padding: 6px 12px; border-radius: 9px; }
.feedback.ok { color: var(--ok); background: var(--ok-bg); }
.feedback.no { color: var(--bad); background: var(--bad-bg); }
.solution { border-left: 4px solid var(--mint); padding: 8px 14px; background: color-mix(in srgb, var(--mint) 10%, transparent); border-radius: 0 10px 10px 0; display: grid; gap: 6px; min-width: 0; overflow-x: auto; }
.solution .h { font-family: var(--font-hand); font-weight: 700; color: var(--ok); }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); display: grid; justify-items: center; gap: 8px; }
.empty svg { width: 80px; height: 80px; }

.sheet-bar {
  position: fixed;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: max(16px, env(safe-area-inset-bottom, 0px));
  z-index: 25;
  background: var(--sheet);
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: 3px 3px 0 var(--ink);
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  max-width: calc(100vw - 32px);
}
.sheet-bar b { font-family: var(--font-hand); }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(20, 18, 40, .45); z-index: 40; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--sheet); color: var(--ink); border: 2px solid var(--ink); border-radius: 16px; width: min(860px, 100%); max-height: 88vh; overflow: auto; padding: 18px 20px; display: grid; gap: 12px; box-shadow: 4px 4px 0 var(--ink); }
.modal-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.modal-head h2 { flex: 1; font-size: 1.3rem; }
.ws-preview { background: #fff; color: #1d1b33; border-radius: 6px; padding: 26px 30px; border: 1px solid #ddd; font-family: "Be Vietnam Pro", system-ui, sans-serif; font-size: 14px; display: grid; gap: 10px; }
.ws-preview h3 { font-family: "Be Vietnam Pro", system-ui, sans-serif; text-align: center; font-size: 17px; }
.ws-preview .ws-meta { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 13px; }
.ws-preview .ws-q { display: grid; gap: 4px; }
.ws-preview h4 { font-family: "Be Vietnam Pro", system-ui, sans-serif; font-size: 14px; border-bottom: 1px solid #999; padding-bottom: 2px; margin-top: 8px; }
.ws-preview table { border-collapse: collapse; }
.ws-preview td, .ws-preview th { border: 1px solid #888; padding: 3px 12px; text-align: center; }
.ws-preview .ws-key { border-top: 2px dashed #bbb; padding-top: 10px; display: grid; gap: 6px; }
.ws-preview .ws-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 2px 14px; }

/* ---------- Casio ---------- */
.casio-wrap { display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
@media (max-width: 960px) { .casio-wrap { grid-template-columns: 1fr; } }
.guide { display: grid; gap: 12px; }
.guide h3 { font-size: 1.15rem; }
.guide .ex-line { font-size: .94rem; padding: 8px 12px; border-radius: 10px; background: var(--sheet-2); min-width: 0; overflow-x: auto; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; counter-reset: st; }
.steps li { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 10px; align-items: start; counter-increment: st; }
.steps li::before { content: counter(st); width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-family: var(--font-hand); font-weight: 700; background: var(--lilac); color: #2c2950; border: 1.5px solid var(--ink); }
.steps li > div { display: grid; gap: 4px; min-width: 0; }
.keys { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; line-height: 1.2; }
.key {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 30px;
  padding: 0 8px;
  border-radius: 8px;
  background: #3a3d4a;
  color: #fff;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: .8rem;
  box-shadow: 0 3px 0 #1d1f27, inset 0 1px 0 rgba(255, 255, 255, .25);
  border: 1px solid #1d1f27;
  white-space: nowrap;
}
.key.shift { background: #c9a227; color: #231b00; box-shadow: 0 3px 0 #7a5f0d; border-color: #7a5f0d; }
.key.alpha { background: #d2455a; box-shadow: 0 3px 0 #82202f; border-color: #82202f; }
.key.num { background: #eceef4; color: #1d1f27; box-shadow: 0 3px 0 #9aa0b0; border-color: #9aa0b0; }
.key.menu { background: #6c5ce7; box-shadow: 0 3px 0 #3d2fa8; border-color: #3d2fa8; }
.keys .txt { font-size: .86rem; color: var(--ink-soft); }
.lcd {
  font-family: var(--font-mono);
  background: #c9d6b4;
  color: #1f2a17;
  border-radius: 8px;
  border: 3px solid #4b5563;
  padding: 8px 12px;
  font-size: .9rem;
  display: grid; gap: 2px;
  min-width: 0; overflow-x: auto;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, .25);
}
.lcd .r { text-align: right; font-weight: 700; font-size: 1.05rem; }
.calc-art { display: grid; justify-items: center; gap: 10px; position: sticky; top: 120px; }
@media (max-width: 960px) { .calc-art { position: static; } }
.calc-art svg { width: 220px; max-width: 100%; height: auto; }
.guide-index { display: grid; gap: 6px; }
.guide-index a { text-decoration: none; color: var(--ink); font-size: .9rem; padding: 5px 10px; border-radius: 8px; border: 1.5px dashed var(--line); background: var(--sheet); }
.guide-index a:hover { border-color: var(--violet); }

/* ---------- Vẽ hình Oxyz ---------- */
.oxyz { display: grid; gap: 18px; grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr); align-items: start; }
@media (max-width: 1000px) { .oxyz { grid-template-columns: 1fr; } }
.stage { position: relative; padding: 0; overflow: hidden; }
.stage canvas { display: block; width: 100%; height: clamp(360px, 62vh, 620px); touch-action: none; cursor: grab; }
.stage canvas:active { cursor: grabbing; }
.stage-tools { position: absolute; left: 10px; top: 10px; display: flex; flex-wrap: wrap; gap: 6px; max-width: calc(100% - 20px); }
.stage-tools .btn { background: var(--sheet); color: var(--ink); }
.stage-hint { position: absolute; right: 12px; bottom: 10px; font-size: .78rem; color: var(--muted); font-family: var(--font-hand); pointer-events: none; }
.stage-tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--paper); padding: 3px 8px; border-radius: 6px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.panel { display: grid; gap: 14px; min-width: 0; }
.panel h3 { font-size: 1.05rem; }
.cmd { font-family: var(--font-mono); font-size: .85rem; min-height: 170px; }
.obj-list { display: grid; gap: 4px; max-height: 260px; overflow: auto; }
.obj { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 5px 6px; border-radius: 8px; font-size: .86rem; }
.obj:hover { background: var(--sheet-2); }
.obj .sw { width: 12px; height: 12px; border-radius: 3px; border: 1.5px solid var(--ink); }
.obj .d { min-width: 0; overflow-x: auto; white-space: nowrap; }
.obj .d mjx-container { font-size: 95%; }
.obj input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--violet); }
.err-list { font-size: .82rem; color: var(--bad); display: grid; gap: 2px; }
.calc-out { display: grid; gap: 6px; font-size: .92rem; min-width: 0; overflow-x: auto; }
.calc-out .res { padding: 6px 10px; border-radius: 8px; background: var(--sheet-2); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row > .grow { flex: 1 1 140px; min-width: 0; }
.help-grid { display: grid; gap: 4px 12px; grid-template-columns: minmax(0, auto) minmax(0, 1fr); font-size: .84rem; }
.help-grid code { font-family: var(--font-mono); background: var(--sheet-2); padding: 1px 5px; border-radius: 5px; font-size: .8rem; overflow-wrap: anywhere; }
@media (max-width: 560px) { .help-grid { grid-template-columns: 1fr; } .help-grid > span { margin-bottom: 6px; } }
details.box { border: 1.5px dashed var(--line); border-radius: 10px; padding: 8px 12px; }
details.box summary { cursor: pointer; font-weight: 700; font-size: .9rem; }

/* ---------- Thí nghiệm ảo ---------- */
.lab-tabs { display: flex; flex-wrap: wrap; gap: 8px; }
.lab { display: grid; gap: 18px; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); align-items: start; }
@media (max-width: 1000px) { .lab { grid-template-columns: 1fr; } }
.lab-stage { padding: 0; overflow: hidden; }
.lab-stage canvas { display: block; width: 100%; height: clamp(300px, 52vh, 500px); touch-action: none; }
.lab-stage .cap { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; padding: 10px 14px; border-top: 1.5px dashed var(--line); font-size: .86rem; }
.ctrl { display: grid; gap: 4px; }
.ctrl .top { display: flex; justify-content: space-between; gap: 8px; font-size: .86rem; font-weight: 600; }
.ctrl .top output { font-family: var(--font-hand); color: var(--violet); font-weight: 700; font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--violet); }
.seg { display: inline-flex; border: 1.5px solid var(--ink); border-radius: 10px; overflow: hidden; flex-wrap: wrap; }
.seg button { border: none; background: var(--sheet); padding: 6px 12px; font-weight: 700; font-size: .85rem; cursor: pointer; }
.seg button + button { border-left: 1.5px solid var(--ink); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.readout { display: grid; gap: 6px; font-size: .92rem; }
.readout .kv { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1.5px dotted var(--line); padding: 3px 0; }
.readout .kv b { font-variant-numeric: tabular-nums; }
.verdict { padding: 8px 12px; border-radius: 10px; font-weight: 700; }
.verdict.on { background: var(--ok-bg); color: var(--ok); }
.verdict.off { background: var(--sheet-2); color: var(--ink-soft); }
.data-table { width: 100%; border-collapse: collapse; font-size: .88rem; font-variant-numeric: tabular-nums; }
.data-table th, .data-table td { border: 1.5px solid var(--line); padding: 4px 8px; text-align: center; }
.data-table th { background: var(--sheet-2); font-family: var(--font-hand); }
.task { font-size: .9rem; display: grid; gap: 4px; }
.task ol { margin: 0; padding-left: 20px; display: grid; gap: 3px; }

/* ---------- AI ---------- */
.ai-layout { display: grid; gap: 18px; grid-template-columns: minmax(300px, 0.9fr) minmax(0, 1.4fr); align-items: start; }
@media (max-width: 960px) { .ai-layout { grid-template-columns: 1fr; } }
.drop {
  border: 2.5px dashed var(--violet);
  border-radius: 14px;
  padding: 18px;
  display: grid; justify-items: center; gap: 8px;
  text-align: center;
  background: color-mix(in srgb, var(--violet-soft) 50%, transparent);
  cursor: pointer;
}
.drop.over { background: var(--violet-soft); }
.drop svg { width: 64px; height: 64px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumb { position: relative; width: 84px; height: 84px; border-radius: 10px; overflow: hidden; border: 2px solid var(--ink); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--ink); background: var(--sheet); cursor: pointer; font-weight: 700; line-height: 1; padding: 0; }
.answer { min-height: 280px; display: grid; gap: 12px; align-content: start; }
.answer .md { display: grid; gap: 10px; line-height: 1.7; min-width: 0; overflow-x: auto; }
.md h2, .md h3, .md h4 { font-size: 1.12rem; color: var(--violet); margin-top: 6px; }
.md ul, .md ol { margin: 0; padding-left: 22px; display: grid; gap: 4px; }
.md table { border-collapse: collapse; font-size: .92rem; }
.md th, .md td { border: 1.5px solid var(--line); padding: 4px 9px; }
.md code { font-family: var(--font-mono); background: var(--sheet-2); padding: 1px 5px; border-radius: 5px; font-size: .85em; }
.md hr { border: none; border-top: 2px dashed var(--line); width: 100%; }
.bubble-q { justify-self: end; max-width: 90%; background: var(--violet-soft); padding: 8px 14px; border-radius: 14px 14px 4px 14px; font-size: .94rem; }
.thinking { display: inline-flex; gap: 8px; align-items: center; font-family: var(--font-hand); color: var(--ink-soft); }
.thinking i { width: 8px; height: 8px; border-radius: 50%; background: var(--violet); animation: bob 1s infinite ease-in-out; }
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes bob { 0%, 100% { transform: translateY(0); opacity: .5; } 50% { transform: translateY(-5px); opacity: 1; } }
.notice { padding: 10px 14px; border-radius: 10px; border: 1.5px solid var(--lv3); background: color-mix(in srgb, var(--peach) 18%, transparent); font-size: .9rem; }

.footer { text-align: center; font-size: .8rem; color: var(--muted); padding: 10px 16px 30px; position: relative; z-index: 1; }

mjx-container { color: inherit; }
mjx-container[jax="SVG"] > svg { overflow: visible; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Menu thả xuống theo lớp ---------- */
button.tab { cursor: pointer; font-family: var(--font-hand); line-height: inherit; }
.tab .caret { font-size: .75em; transition: transform .15s; }
.dd-btn[aria-expanded="true"] .caret { transform: rotate(180deg); }
.dd-btn[aria-expanded="true"] { background: var(--c); color: #2c2950; border-color: var(--ink); }
.dd-menu {
  position: fixed;
  z-index: 35;
  width: 330px;
  max-width: calc(100vw - 24px);
  max-height: 72vh;
  overflow: auto;
  background: var(--sheet);
  border: 2px solid var(--ink);
  border-radius: 0 0 14px 14px;
  box-shadow: 4px 4px 0 var(--ink);
  padding: 8px;
  display: grid;
  gap: 4px;
}
@media (max-width: 640px) {
  .dd-menu { left: max(12px, env(safe-area-inset-left, 0px)) !important; right: max(12px, env(safe-area-inset-right, 0px)) !important; width: auto; }
}
.dd-grade { display: grid; gap: 2px; padding: 6px; border-radius: 10px; }
.dd-grade + .dd-grade { border-top: 1.5px dashed var(--line); border-radius: 0; }
.dd-head { font-family: var(--font-hand); font-weight: 700; font-size: 1.02rem; color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 8px; }
.dd-head:hover, .dd-head:focus-visible { background: var(--violet-soft); }
.dd-item { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 8px; padding: 6px 8px; border-radius: 8px; text-decoration: none; color: var(--ink); font-size: .9rem; }
.dd-item:hover, .dd-item:focus-visible { background: var(--violet-soft); }
.dd-ch { color: var(--violet); font-weight: 700; font-size: .78rem; padding-top: 2px; }
.brand-name { font-size: 1.12rem; letter-spacing: .02em; }
.title-caps { text-transform: uppercase; letter-spacing: .02em; }

/* ---------- Trang chủ, trang lớp ---------- */
.grade-block { display: grid; gap: 6px; padding-top: 8px; border-top: 1.5px dashed var(--line); }
.grade-head { font-family: var(--font-hand); font-weight: 700; font-size: 1.08rem; color: var(--ink); text-decoration: none; }
.grade-head:hover { color: var(--violet); }
.unit-link { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 10px; align-items: center; padding: 6px 8px; border-radius: 10px; text-decoration: none; color: var(--ink); border: 1.5px dashed transparent; }
.unit-link:hover { border-color: var(--line); background: var(--sheet-2); }
.ul-doodle svg { width: 40px; height: 40px; display: block; }
.ul-text { display: grid; gap: 1px; min-width: 0; }
.ul-text .muted { font-size: .82rem; }
.soon-line { font-size: .88rem; padding: 2px 8px; }
.plan-list { margin: 6px 0 0; padding-left: 20px; display: grid; gap: 4px; }
.crumb-link { color: inherit; text-decoration: none; }
.crumb-link:hover { color: var(--violet); }
.ghost-chip { border-style: dashed; font-weight: 500; }
.f-text { font-size: .94rem; line-height: 1.65; }
.f-text ul, .f-text ol { margin: 0; padding-left: 20px; display: grid; gap: 3px; }
.cmd-line { font-family: var(--font-mono); font-size: .9rem; }

/* ---------- Thương hiệu cô Hạnh ---------- */
.brand .avatar { width: 46px; height: 46px; border-radius: 50%; border: 2.5px solid var(--ink); background: var(--sheet); box-shadow: 2px 2px 0 var(--ink); flex: none; object-fit: cover; }
@media (max-width: 520px) { .brand .avatar { width: 38px; height: 38px; } }
.label-sub { font-size: 1.02rem; color: var(--ink-soft); margin-top: -6px; }
.hero-sticker { position: relative; display: block; width: min(250px, 70%); height: auto; margin: 30px auto 0; transform: rotate(-3deg); filter: drop-shadow(3px 4px 0 rgba(44, 41, 80, .18)); }
.desk .hero-sticker + .desk-note { margin-top: -18px; }

/* ---------- Hình minh hoạ ---------- */
.fig { margin: 8px 0 0; display: grid; gap: 6px; justify-items: center; min-width: 0; }
.figsvg { width: 100%; max-width: 680px; height: auto; display: block; }
.fig figcaption { font-size: .88rem; color: var(--ink-soft); text-align: center; max-width: 62ch; }
.fig-row { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); align-items: start; padding: 10px; border: 1.5px dashed var(--line); border-radius: 12px; background: var(--paper); }
.ex-fig .figsvg { max-width: 420px; }

/* ---------- Đề luyện tập ---------- */
.test-bar { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 74px); z-index: 15; display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; padding-block: 12px; }
@media (max-width: 720px) { .test-bar { top: calc(env(safe-area-inset-top, 0px) + 100px); } }
.test-bar .grow { flex: 1; }
.test-pick { margin: 2px 0 12px; }
.timer { font-family: var(--font-hand); font-weight: 700; font-size: 1.6rem; color: var(--violet); font-variant-numeric: tabular-nums; min-width: 4.5ch; }
.timer.low { color: var(--lv4); }
.test-part { font-size: 1.2rem; color: var(--violet); margin-top: 8px; }
.essay-note { margin: 4px 0 0; font-size: .88rem; }
.test-result { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; border: 2px solid var(--ink); box-shadow: 4px 4px 0 var(--ink); }
.test-result img { width: 150px; height: auto; flex: none; transform: rotate(-4deg); }
.test-result .score b { font-family: var(--font-hand); font-size: 2.6rem; color: var(--violet); line-height: 1; }
.test-result .score span { margin-left: 6px; color: var(--ink-soft); font-weight: 600; }
.kicker-s { font-size: .78rem; letter-spacing: .12em; text-transform: uppercase; color: var(--violet); font-weight: 700; }

/* đơn vị đi kèm công thức Vật lý */
.units { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 6px; margin: 6px 0 2px; font-size: .84rem; }
.units .u-h { font-family: var(--font-hand); font-weight: 700; color: var(--lv2); margin-right: 2px; }
.units .u { display: inline-flex; align-items: baseline; gap: 5px; padding: 1px 9px 2px; border: 1.5px solid var(--line); border-radius: 999px; background: var(--sheet-2); max-width: 100%; }
.units .u b { font-weight: 600; color: var(--ink); }
.units .u-note { flex-basis: 100%; color: var(--ink-soft); font-size: .8rem; }
.units .u-note::before { content: "Lưu ý: "; font-weight: 700; color: var(--lv3); }

/* lớp học: tài khoản học sinh, trang quản lý của cô */
.hs-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin: 0 0 12px; padding: 8px 12px; border: 1.5px dashed var(--line); border-radius: 12px; background: var(--sheet); font-size: .88rem; }
.hs-bar a { font-weight: 700; color: var(--violet); }
.mint-pill { background: var(--mint); color: #12352a; border: 1.5px solid var(--ink); border-radius: 999px; padding: 1px 8px; font-size: .78rem; font-weight: 700; }
.score-pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-weight: 700; border: 1.5px solid currentColor; }
.score-pill.good { color: var(--lv1); } .score-pill.mid { color: var(--lv3); } .score-pill.low { color: var(--lv4); }
.lop-table { font-size: .86rem; }
.lop-table td, .lop-table th { white-space: nowrap; }
.lop-table td.wrong-ids { white-space: normal; min-width: 140px; font-size: .8rem; color: var(--ink-soft); }
.lop-test { display: grid; gap: 6px; margin-bottom: 10px; }
.lop-test h4 { margin: 4px 0 0; font-size: .98rem; }
.linkish { background: none; border: 0; padding: 0; font: inherit; font-weight: 700; color: var(--violet); cursor: pointer; text-align: left; text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 3px; }
.lop-main code { font-size: .82rem; }

/* các khối trong trang không được kéo giãn lưới khi bên trong có bảng rộng (bảng tự cuộn ngang) */
.page > * { min-width: 0; }
@media (max-width: 520px) { .tab[data-top="home"] { display: none; } }
.hs-warn { border-color: var(--lv4); color: var(--ink); background: var(--sheet); }
.hs-send { border: 2px solid var(--violet); margin: 0 0 12px; }
.lop-quick { border: 2px dashed var(--violet); }

/* ---------- Mục Đề kiểm tra ---------- */
.exam-card { display: grid; gap: 10px; align-content: start; }
.exam-card h2 { margin: 0; font-size: 1.35rem; }
.exam-meta { display: grid; gap: 4px; font-size: .9rem; }
.exam-meta span { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 8px; }
.exam-meta b { font-family: var(--font-hand); color: var(--ink-soft); }
.exam-head { display: grid; grid-template-columns: 1fr 1.35fr; gap: 6px 18px; text-align: center; font-size: .92rem; margin: 6px 0 14px; position: relative; }
.exam-head > div { display: grid; gap: 2px; align-content: start; }
.exam-head b { font-weight: 800; letter-spacing: .01em; }
.exam-head i { color: var(--ink-soft); font-size: .86rem; }
.exam-head .eh-code { grid-column: 2; justify-self: end; border: 2px solid var(--ink); border-radius: 8px; padding: 2px 14px; font-weight: 800; background: var(--sheet); }
@media (max-width: 640px) { .exam-head { grid-template-columns: 1fr; } .exam-head .eh-code { grid-column: 1; justify-self: center; } }
.exam-info { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 14px; margin-bottom: 14px; }
.exam-info > .sheet { display: grid; gap: 8px; align-content: start; min-width: 0; overflow-x: auto; }
.part-note { color: var(--ink-soft); font-size: .88rem; margin: -6px 0 2px; }
.q-table { overflow-x: auto; margin: 8px 0; max-width: 100%; }
.q-grid { width: auto; min-width: 0; }
.q-grid th, .q-grid td { border: 1.5px solid var(--line); padding: 5px 10px; text-align: center; white-space: nowrap; }
.q-grid th { background: var(--sheet-2); font-weight: 700; text-align: left; }
.q-grid.bxd td { min-width: 26px; padding: 5px 6px; }
.rubric { display: grid; gap: 6px; border-left: 4px solid var(--peach); padding: 8px 12px; background: color-mix(in srgb, var(--peach) 12%, transparent); border-radius: 0 10px 10px 0; min-width: 0; overflow-x: auto; }
.rubric .h { font-family: var(--font-hand); font-weight: 700; color: var(--lv3); }
.rub { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 6px 4px; border-top: 1.5px dashed var(--line); }
div.rub { grid-template-columns: minmax(0, 1fr) auto; }
label.rub { cursor: pointer; }
.rub input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--violet); }
.rub b { font-variant-numeric: tabular-nums; white-space: nowrap; }
.home-exams { margin: 0 0 22px; display: grid; gap: 10px; }
.home-exams header svg { width: 56px; height: 56px; flex: none; }
.q-grid.bxd th, .q-grid.bxd td { border: none; background: none; }
.q-grid.bxd tr:first-child > * { border-bottom: 1.5px solid var(--ink); }
.q-grid.bxd th { border-right: 1.5px solid var(--ink); }

/* ---------- Khảo sát & vẽ đồ thị (Toán 12 – Ch. I) ---------- */
.ks-in { display: grid; gap: 10px; margin-bottom: 14px; }
.ks-mono { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: .95rem; }
.ks-tex { min-height: 2.2em; padding: 6px 12px; border-radius: 10px; background: var(--sheet-2); overflow-x: auto; font-size: 1.02rem; }
.ks-err { color: var(--lv4); font-weight: 600; font-size: .92rem; }
.ks-hint { margin: 0; font-size: .82rem; }
.ks-hint code { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: .8rem; background: var(--sheet-2); border-radius: 5px; padding: 0 4px; }
.ks-presets { gap: 6px; }
.ks-mrow { gap: 10px; align-items: center; }
.ks-stage { position: relative; display: grid; gap: 8px; margin-bottom: 16px; min-width: 0; }
.ks-tools { gap: 6px; align-items: center; }
.ks-tg { display: inline-flex; align-items: center; gap: 4px; font-size: .84rem; font-weight: 600; color: var(--ink-soft); cursor: pointer; }
.ks-plot { width: 100%; touch-action: none; cursor: crosshair; border: 1.5px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--sheet); }
.ks-plot svg { display: block; width: 100%; height: auto; }
.ks-foot { gap: 8px; align-items: center; font-size: .84rem; }
.ks-res { align-items: start; gap: 16px; }
.ks-res h3 { margin: 4px 0 2px; font-size: 1rem; }
.ks-bbt { margin-top: 8px; }
.ks-bbt svg { width: 100%; height: auto; }
.ks-tgs { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.ks-msg { margin: 0; font-size: .84rem; }
.ks-msg:empty { display: none; }
.ks-plbl { margin-bottom: -4px; }
/* máy tính: cài đặt + kết quả bên trái, đồ thị bên phải (đứng yên khi cuộn) */
.ks-wrap { display: grid; grid-template-columns: minmax(340px, 1fr) minmax(0, 1.55fr); gap: 16px; align-items: start; margin-bottom: 16px; }
.ks-side { display: grid; gap: 14px; min-width: 0; }
.ks-side .ks-in { margin-bottom: 0; }
.ks-wrap .ks-res { display: grid; gap: 14px; min-width: 0; }
.ks-main { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 78px); min-width: 0; z-index: 2; }
.ks-main .ks-stage { margin-bottom: 0; }
@media (max-width: 900px) {
  /* điện thoại, máy tính bảng dọc: ô nhập → đồ thị → kết quả */
  .ks-wrap { display: flex; flex-direction: column; gap: 14px; }
  .ks-side { display: contents; }
  .ks-side .ks-in { order: 1; }
  .ks-main { order: 2; position: static; }
  .ks-wrap .ks-res { order: 3; }
}
@media (max-width: 640px) {
  .ks-tools .ks-tg { font-size: .78rem; }
  .ks-tools .btn.sm { padding: 4px 8px; }
}

/* ---------- Vẽ hình phẳng (Toán 9 – ôn thi vào 10) ---------- */
.hp-svg { width: 100%; height: clamp(380px, 64vh, 640px); touch-action: none; cursor: move; background: var(--sheet); }
.hp-svg svg { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-select: none; }
.hp-checks { display: grid; gap: 8px; }
.hp-ck { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 8px; align-items: start; padding: 8px 10px; border-radius: 10px; background: var(--sheet-2); font-size: .9rem; line-height: 1.5; }
.hp-ck .hp-ic { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: var(--sheet); background: var(--lv1); font-size: .8rem; }
.hp-ck.no .hp-ic { background: var(--bad, #c0392b); }
.hp-hint { margin-top: 6px; font-size: .86rem; }
.hp-hint ul { margin: 4px 0 0; padding-left: 18px; display: grid; gap: 3px; }
.hp-checks code, .panel .lead code { font-family: var(--font-mono); font-size: .8rem; background: var(--sheet-2); border-radius: 5px; padding: 0 4px; }

/* ---------- Công cụ tọa độ (Toán 10: vectơ, Oxy) ---------- */
.td-wrap { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(320px, 1fr); gap: 16px; align-items: start; margin-bottom: 16px; }
.td-left { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 78px); min-width: 0; z-index: 2; }
.td-left .ks-stage { margin-bottom: 0; }
.td-right { display: grid; gap: 14px; min-width: 0; }
.td-right .ks-in { margin-bottom: 0; }
.td-right .calc-out:empty { display: none; }
.td-plot { cursor: crosshair; }
.td-tabs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; border: none; border-radius: 0; overflow: visible; justify-self: stretch; }
.td-tabs.td-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.td-tabs button, .td-tabs button + button { border: 1.5px solid var(--ink); border-radius: 9px; padding: 7px 6px; line-height: 1.25; }
.td-vrow { display: grid; gap: 8px; }
.td-vin { display: flex; align-items: center; gap: 4px; font-weight: 700; color: var(--ink); }
.td-vl { min-width: 62px; font-size: .95rem; }
.td-par { font-size: 1.15rem; color: var(--ink-soft); }
.td-n { width: 78px; padding: 6px 4px 6px 8px; text-align: center; font-size: 1rem; }
.td-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; flex: none; }
.td-ul { margin: 4px 0 0; padding-left: 20px; display: grid; gap: 3px; }
.td-ul li { line-height: 1.5; }
.td-help summary { cursor: pointer; font-size: .84rem; font-weight: 700; color: var(--ink-soft); }
.td-help .ks-hint { margin-top: 6px; }
@media (max-width: 900px) {
  .td-wrap { grid-template-columns: 1fr; }
  .td-left { position: static; }
}
@media (max-width: 560px) { .td-n { width: 66px; } .td-vl { min-width: 50px; } .td-tabs button { font-size: .8rem; padding: 6px 4px; } }

/* Vẽ hình 2D – 3D (nhúng công cụ ngoài) */
.draw-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin: 0 0 14px; }
.draw-frame { padding: 0; overflow: hidden; }
.draw-frame iframe { display: block; width: 100%; height: clamp(520px, 78vh, 900px); border: 0; background: var(--paper); }
.draw-note { font-size: .86rem; margin: 8px 2px 18px; }
.draw-links { display: grid; gap: 6px; margin-top: 8px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.draw-links a { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); padding: 6px 10px; border-radius: 9px; border: 1.5px dashed transparent; }
.draw-links a:hover { border-color: var(--line); background: var(--sheet-2); }
