/* Tự Học — giao diện sáng, dịu mắt, ưu tiên iPad. */
:root {
  --bg: #f6f3ec;
  --paper: #fffdf8;
  --ink: #1f2a33;
  --ink-2: #4a5864;
  --ink-3: #7d8a95;
  --line: #e4ddd0;
  --accent: #2f6f8f;
  --accent-ink: #ffffff;
  --accent-soft: #e3eef3;
  --good: #2e7d4f;
  --good-soft: #e3f2e8;
  --bad: #b5472f;
  --bad-soft: #f8e6e1;
  --key: #fff4cf;
  --key-line: #ecd78a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 42, 51, .06), 0 4px 14px rgba(31, 42, 51, .05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --math: "Cambria Math", "Times New Roman", Times, serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 18px/1.6 var(--font);
  padding-bottom: env(safe-area-inset-bottom);
}
button, input { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ── Thanh trên ─────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 14px;
  padding: calc(10px + env(safe-area-inset-top)) 20px 10px;
  background: rgba(246, 243, 236, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink); text-decoration: none; }
.crumbs { flex: 1; min-width: 0; color: var(--ink-3); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumbs a { color: var(--ink-2); text-decoration: none; }
.net { font-size: 13px; background: var(--key); border: 1px solid var(--key-line); padding: 2px 10px; border-radius: 99px; }

.app { max-width: 880px; margin: 0 auto; padding: 22px 20px 60px; }
h1 { font-size: 28px; line-height: 1.25; margin: 6px 0 4px; }
h2 { font-size: 22px; margin: 32px 0 10px; }
h3 { font-size: 19px; margin: 22px 0 8px; }
.muted { color: var(--ink-3); }
.small { font-size: 15px; }

/* ── Thẻ, danh sách ─────────────────────────────────────── */
.card {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px; margin: 14px 0;
}
.chapter h2 { margin: 0 0 4px; font-size: 20px; }
.chapter .strand { font-size: 13px; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); font-weight: 600; }
.lessons { list-style: none; margin: 12px 0 0; padding: 0; }
.lessons li + li { border-top: 1px solid var(--line); }
.lessons a, .lessons span.row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 4px; min-height: 52px; text-decoration: none; color: var(--ink);
}
.lessons .num { width: 84px; flex: none; font-size: 14px; color: var(--ink-3); }
.lessons .title { flex: 1; }
.lessons .pg { font-size: 14px; color: var(--ink-3); white-space: nowrap; }
.lessons .soon { opacity: .5; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--good-soft); color: var(--good); }

/* ── Tabs ───────────────────────────────────────────────── */
.tabs { display: flex; gap: 6px; margin: 18px 0 8px; background: #ece6da; padding: 4px; border-radius: 12px; }
.tabs a {
  flex: 1; text-align: center; padding: 10px 6px; border-radius: 9px;
  text-decoration: none; color: var(--ink-2); font-weight: 600; font-size: 16px; min-height: 44px;
}
.tabs a.on { background: var(--paper); color: var(--ink); box-shadow: var(--shadow); }

/* ── Nút ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 22px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--paper); cursor: pointer;
  font-weight: 600; touch-action: manipulation;
  font-family: var(--font); font-size: 17px; text-decoration: none; color: var(--ink);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .45; cursor: default; }
.btn:focus-visible, .opt:focus-visible, input:focus-visible { outline: 3px solid #9cc3d6; outline-offset: 2px; }
.row-btns { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }

/* ── Bài giảng ──────────────────────────────────────────── */
.box { background: var(--key); border: 1px solid var(--key-line); border-left: 5px solid #d9b740; border-radius: 10px; padding: 14px 18px; margin: 14px 0; }
.box .box-title { font-weight: 700; margin-bottom: 4px; }
.trap { background: var(--bad-soft); border-left: 5px solid var(--bad); border-radius: 10px; padding: 14px 18px; margin: 14px 0; }
.trap .box-title { font-weight: 700; color: var(--bad); margin-bottom: 4px; }
.tip { background: var(--accent-soft); border-radius: 10px; padding: 12px 16px; margin: 14px 0; }
.steps { counter-reset: s; margin: 10px 0; }
.step { display: flex; gap: 12px; margin: 10px 0; animation: rise .25s ease; }
.step::before {
  counter-increment: s; content: counter(s);
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 15px;
  display: grid; place-items: center; margin-top: 2px;
}
.step .body { flex: 1; }
.step .why { color: var(--ink-3); font-size: 15px; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.example { border: 1px dashed #c9bfae; border-radius: 12px; padding: 14px 18px; margin: 16px 0; background: var(--paper); }
.example .tag { display: inline-block; background: var(--accent); color: #fff; font-size: 13px; font-weight: 700; padding: 1px 10px; border-radius: 6px; margin-bottom: 6px; }
.figure { margin: 16px 0; text-align: center; }
.figure svg { max-width: 100%; height: auto; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; }
.figure figcaption { font-size: 14px; color: var(--ink-3); margin-top: 6px; }
.cases { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.cases .figure { margin: 0; }
.ref { font-size: 14px; color: var(--ink-3); }
section { scroll-margin-top: 72px; }
.pair .btn { font-size: 17px; }

/* ── Công thức ──────────────────────────────────────────── */
.m { font-family: var(--math); font-size: 1.08em; white-space: nowrap; }
.m i { font-style: italic; }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; font-size: .9em; margin: 0 2px; }
.frac > span:first-child { border-bottom: 1px solid currentColor; padding: 0 2px; }
.frac > span:last-child { padding: 0 2px; }
.sys { display: inline-flex; align-items: stretch; vertical-align: middle; margin: 4px 2px; }
.sys .brace { width: 9px; margin-right: 6px; border: 1.5px solid currentColor; border-right: 0; border-radius: 9px 0 0 9px; }
.sys .eqs { display: flex; flex-direction: column; gap: 2px; text-align: left; }
.disp { display: block; text-align: center; margin: 10px 0; }
.sqrt { white-space: nowrap; }
.sqrt .rad { border-top: 1.2px solid currentColor; padding: 0 2px; margin-left: 1px; }
.fn { font-style: normal; margin-right: 2px; }
.hat { position: relative; display: inline-block; }
.hat::before { content: "^"; position: absolute; left: 50%; top: -.55em; transform: translateX(-50%); font-size: .8em; font-style: normal; }

/* ── Thẻ nhớ ────────────────────────────────────────────── */
.flash { perspective: 1200px; margin: 18px 0; }
.flash .inner {
  min-height: 230px; border-radius: 18px; background: var(--paper); border: 1px solid var(--line);
  box-shadow: var(--shadow); padding: 28px 26px; display: flex; flex-direction: column; justify-content: center;
  text-align: center; cursor: pointer; font-size: 20px;
}
.flash .side-label { font-size: 13px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 10px; }
.flash .back { border-top: 1px dashed var(--line); margin-top: 18px; padding-top: 18px; text-align: left; font-size: 18px; }
.grade { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grade .btn { flex-direction: column; gap: 0; line-height: 1.2; }
.grade .btn small { font-weight: 400; font-size: 13px; color: var(--ink-3); }
.grade .btn.primary small { color: rgba(255, 255, 255, .85); }
.btn.primary { color: var(--accent-ink); }
.progress { height: 8px; background: #e8e1d3; border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }

/* ── Luyện tập ──────────────────────────────────────────── */
.q-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; font-size: 15px; color: var(--ink-3); }
.q-text { font-size: 20px; margin: 6px 0 14px; }
.opts { display: grid; gap: 10px; }
.opt {
  display: flex; align-items: center; gap: 12px; text-align: left;
  min-height: 56px; padding: 10px 16px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--paper); cursor: pointer; touch-action: manipulation;
}
.opt .k { flex: none; width: 30px; height: 30px; border-radius: 8px; background: #ece6da; display: grid; place-items: center; font-weight: 700; font-size: 15px; }
.opt.sel { border-color: var(--accent); background: var(--accent-soft); }
.opt.right { border-color: var(--good); background: var(--good-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.pair { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-family: var(--math); font-size: 22px; }
.pair input {
  width: 92px; min-height: 52px; text-align: center; font-size: 22px;
  border: 1.5px solid var(--line); border-radius: 10px; background: var(--paper);
}
.num-in { display: inline-flex; align-items: stretch; }
.num-in .pm {
  width: 44px; min-height: 52px; border: 1.5px solid var(--line); border-right: 0;
  border-radius: 10px 0 0 10px; background: #ece6da; font-size: 20px; cursor: pointer; touch-action: manipulation;
}
.num-in input { border-radius: 0 10px 10px 0; }
.special { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.special .opt { min-height: 48px; }
.fb { border-radius: 12px; padding: 14px 18px; margin-top: 16px; animation: rise .2s ease; }
.fb.ok { background: var(--good-soft); border: 1px solid #b9dcc6; }
.fb.no { background: var(--bad-soft); border: 1px solid #ecc3b8; }
.fb .fb-title { font-weight: 700; margin-bottom: 4px; }
.fb.ok .fb-title { color: var(--good); }
.fb.no .fb-title { color: var(--bad); }
.fb .sol { margin-top: 10px; padding-top: 10px; border-top: 1px dashed rgba(0,0,0,.12); }
.fb .sol ol { margin: 6px 0 0; padding-left: 22px; }
.score { text-align: center; padding: 24px 10px; }
.score .big { font-size: 56px; font-weight: 800; color: var(--accent); line-height: 1.1; }
.mis-list { margin: 10px 0 0; padding-left: 20px; }

@media (max-width: 560px) {
  body { font-size: 17px; }
  h1 { font-size: 24px; }
  .app { padding: 16px 16px 50px; }
  .lessons .pg { display: none; }
  .grade { grid-template-columns: 1fr; }
  .pair { font-size: 19px; gap: 6px; }
  .pair input { width: 64px; }
  .num-in .pm { width: 38px; }
}
