:root {
  --paper: #f8f1e2;
  --paper-2: #efe5cf;
  --card: #fffdf6;
  --ink: #23262f;
  --ink-2: #4a4538;
  --muted: #7b6f58;
  --line: #d9cdb4;
  --accent: #b4442f;
  --navy: #1f3d5c;
  --gold: #c99a3e;
  --blue: #3b5bdb;
  --green: #2f9e44;
  --green-bg: #e6f6e3;
  --red: #c92a2a;
  --red-bg: #fde8e6;
  --yellow-bg: #fff3bf;
  --teacher: #1c5d7a;
  --teacher-bg: #e3f1f6;
  --shadow: 0 6px 24px rgba(60, 45, 20, .18);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: #e6dccb;
  color: var(--ink);
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- Sân khấu ---------- */
.stage-wrap { position: fixed; inset: 0; }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.css-layer, .css3d { position: absolute; inset: 0; pointer-events: none; }
.css3d > div { pointer-events: none; }

/* ---------- Thanh điều khiển dưới ---------- */
.bar {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 2px;
  background: rgba(255, 253, 246, .92);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(35, 38, 47, .12);
  border-radius: 999px; padding: 6px 10px;
  box-shadow: var(--shadow); z-index: 20;
  max-width: calc(100vw - 32px);
}
.icon {
  width: 36px; height: 36px; border-radius: 50%;
  display: inline-grid; place-items: center;
  border: 0; background: transparent; color: var(--ink);
  flex: none;
}
.icon:hover { background: rgba(35, 38, 47, .07); }
.icon:disabled { opacity: .3; cursor: default; background: transparent; }
.icon[aria-pressed="true"] { background: var(--teacher-bg); color: var(--teacher); }
.bar-title {
  min-width: 0; padding: 0 10px; font-family: 'Noto Serif', serif; font-weight: 600; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 340px;
}
#bar-no { color: var(--accent); margin-right: 8px; font-family: 'Be Vietnam Pro'; font-size: 13px; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 6px; flex: none; }

/* nút dạng viên thuốc */
.pill {
  border: 1.5px solid var(--ink); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: 8px 16px; font-size: 14px; font-weight: 600;
  box-shadow: 0 2px 0 var(--ink); transition: transform .08s, box-shadow .08s;
  white-space: nowrap;
}
.pill:hover { background: #fff; }
.pill:active { transform: translateY(2px); box-shadow: 0 0 0 var(--ink); }
.pill:disabled { opacity: .45; cursor: default; transform: none; }
.pill.primary { background: var(--navy); color: #fff; border-color: var(--navy); box-shadow: 0 2px 0 #0f2236; }
.pill.on { background: var(--yellow-bg); }

.stage-controls {
  position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%);
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px;
  z-index: 15; max-width: min(760px, calc(100vw - 32px));
}
.ctl-group {
  display: flex; align-items: center; gap: 8px; background: rgba(255, 253, 246, .92);
  border: 1.5px solid var(--ink); border-radius: 999px; padding: 4px 6px 4px 14px; font-size: 13px; font-weight: 600;
}
.ctl-group input[type=text] {
  width: 170px; border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px;
  font: 500 13px 'JetBrains Mono', monospace; background: #fff;
}
.ctl-group input[type=range] { width: 90px; accent-color: var(--navy); }
.ctl-group .pill { padding: 5px 12px; font-size: 13px; }

/* thanh tiến độ học (progress.js fillProgress): thẻ chương ở mục lục, ngăn mục lục, trang kết */
.prog { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12px; font-weight: 500; color: var(--muted); }
.prog.done { color: #3d7a4a; font-weight: 600; }
.prog-bar { flex: none; width: 70px; height: 6px; border-radius: 3px; background: rgba(35, 38, 47, .12); overflow: hidden; }
.prog-bar i { display: block; height: 100%; border-radius: 3px; background: #4f7cac; transition: width .4s ease; }
.prog.done .prog-bar i { background: #5b9a68; }
.prog-total { margin: 10px 0 14px; padding: 10px 12px; border-radius: 12px; background: rgba(79, 124, 172, .08); font-size: .92em; }
.prog-total .prog-bar.big { display: block; width: 100%; height: 8px; margin-top: 8px; }
/* dòng cuối phần lý thuyết: đổi thành "✓ Đã đọc xong" khi lướt tới cuối (main.js watchRead) */
.read-mark {
  margin: 22px 0 6px; padding: 8px 12px; border-radius: 10px; text-align: center;
  font-size: 13px; color: var(--muted); border: 1px dashed rgba(35, 38, 47, .22); transition: background .4s, color .4s, border-color .4s;
}
.read-mark.done { color: #2f6b3c; font-weight: 600; background: rgba(91, 154, 104, .12); border: 1px solid rgba(91, 154, 104, .45); }
.toc-pages a.seen::after { content: ' ✓'; color: #5b9a68; font-weight: 700; }

/* thẻ thông tin & trạng thái */
.side-cards {
  position: fixed; top: 16px; right: 16px; width: min(340px, calc(100vw - 32px));
  display: flex; flex-direction: column; gap: 10px; z-index: 15; pointer-events: none;
}
.side-cards > * { pointer-events: auto; }
.stage-status, .info-card {
  background: rgba(255, 253, 246, .95); border: 1.5px solid var(--ink); border-radius: 14px;
  padding: 12px 14px; box-shadow: var(--shadow); font-size: 14px; line-height: 1.5;
}
.info-card { position: relative; animation: rise .25s ease-out; }
.info-card h4 { margin: 0 26px 6px 0; font-family: 'Noto Serif', serif; font-size: 17px; }
.info-x { position: absolute; top: 6px; right: 8px; border: 0; background: none; font-size: 22px; line-height: 1; color: var(--muted); }
.st-op { font-weight: 600; }

/* thẻ thông báo thu gọn: chỉ một dòng ở góc phải trên, bấm để mở lại (stage.js collapseNotice) */
.side-cards { align-items: flex-end; }
.side-cards > * { width: 100%; box-sizing: border-box; transition: max-height .35s ease, padding .25s, width .25s; max-height: 70vh; overflow: hidden; }
.side-cards.mini > :not(.notice-toggle) {
  width: auto; max-width: 100%; max-height: 40px; padding-top: 8px; padding-bottom: 8px; cursor: pointer;
}
.side-cards.mini .stage-status > :not(:first-child),
.side-cards.mini .info-card > div,
.side-cards.mini .info-x { display: none; }
.side-cards.mini .stage-status > :first-child,
.side-cards.mini .info-card h4 {
  margin: 0; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* dấu ▸ đầu dòng = bấm để xem đầy đủ (::after của thẻ đã dùng cho đốm sáng kính) */
.side-cards.mini .stage-status > :first-child::before,
.side-cards.mini .info-card h4::before { content: '▸ '; color: var(--accent); }
/* nút Ẩn / Hiện thông báo (stage.js setupNoticeToggle): ẩn hẳn cả thẻ, lựa chọn được ghi nhớ */
.side-cards > .notice-toggle {
  width: auto; align-self: flex-end; display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; font-size: 12.5px; font-weight: 600; overflow: visible; max-height: none; position: relative;
}
.notice-toggle svg { display: block; flex: none; }
.side-cards.empty:not(.off) > .notice-toggle { display: none; }
.side-cards.off > :not(.notice-toggle) { display: none !important; }
/* chấm báo: có thông báo mới trong lúc đang ẩn */
.notice-toggle .nt-dot { display: none; width: 8px; height: 8px; border-radius: 50%; background: #c8553d; box-shadow: 0 0 0 2px rgba(255, 255, 255, .8); }
.notice-toggle.new .nt-dot { display: block; animation: nt-pulse 1.4s ease-in-out infinite; }
@keyframes nt-pulse { 50% { transform: scale(1.35); } }
.st-count { margin-top: 6px; color: var(--ink-2); font-size: 13px; }
.st-count b { font-family: 'JetBrains Mono', monospace; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 10px; margin-top: 8px; font-size: 12px; color: var(--ink-2); }
.legend i { display: inline-block; width: 12px; height: 12px; border: 1.5px solid var(--ink); border-radius: 3px; vertical-align: -2px; margin-right: 4px; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* màn mở sách */
.open-hint {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  text-align: center; z-index: 16; transition: opacity .5s;
}
.open-title { font: italic 700 34px 'Noto Serif', serif; color: var(--navy); }
.open-sub { color: var(--muted); margin: 4px 0 14px; font-size: 14px; }
body.opened .open-hint { opacity: 0; pointer-events: none; }
body:not(.opened) .bar { opacity: .0; pointer-events: none; }
.bar { transition: opacity .5s; }

/* ---------- Trang chữ (trên trang trái của sách) ---------- */
.leaf {
  padding: 26px 40px 40px;
  overflow-y: auto; overscroll-behavior: contain;
  font-family: 'Noto Serif', serif; font-size: 18px; line-height: 1.6; color: var(--ink);
  user-select: text !important;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
  /* chữ mờ dần ở mép trên/dưới khi cuộn, không đè lên tiêu đề in trên giấy */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 22px, #000 calc(100% - 22px), transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 22px, #000 calc(100% - 22px), transparent 100%);
}
body.flat .leaf { -webkit-mask-image: none; mask-image: none; }
.leaf .kicker {
  font: 600 12px 'Be Vietnam Pro', sans-serif; letter-spacing: .14em; text-transform: uppercase; color: var(--accent);
}
.leaf h2 { font-size: 31px; line-height: 1.2; margin: 6px 0 4px; }
.leaf .rule { width: 64px; height: 2px; background: var(--accent); margin: 10px 0 16px; }
.leaf h3 { font-size: 20px; margin: 22px 0 6px; }
.leaf p { margin: 0 0 12px; }
.leaf ul, .leaf ol { margin: 0 0 12px; padding-left: 22px; }
.leaf li { margin: 3px 0; }
.leaf .lead { font-style: italic; color: var(--ink-2); }
.leaf b, .leaf strong { font-weight: 700; }
.leaf .term { color: var(--navy); font-weight: 700; }
.leaf .side { font-size: 15px; color: var(--muted); font-style: italic; }
.leaf a { color: var(--navy); }
.leaf table { border-collapse: collapse; width: 100%; font-size: 15px; margin: 6px 0 14px; font-family: 'Be Vietnam Pro', sans-serif; }
.leaf th, .leaf td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.leaf th { background: var(--paper-2); font-weight: 600; }
.leaf .page-end { margin-top: 26px; font: italic 15px 'Noto Serif'; color: var(--muted); text-align: center; }

/* ---------- Công thức toán (Vật lí: js/mon/vat-li/vl-math.js) ---------- */
.m-frac {
  display: inline-flex; flex-direction: column; align-items: stretch; vertical-align: middle;
  text-align: center; margin: 0 .12em; font-size: .9em; line-height: 1.12; font-style: normal;
}
.m-frac > .m-num { padding: 0 .2em .06em; border-bottom: .075em solid currentColor; }
.m-frac > .m-den { padding: .08em .2em 0; }
.m-frac .m-frac { font-size: .92em; }
.m-sqrt { display: inline-block; position: relative; padding-left: .5em; margin: 0 .04em 0 .1em; white-space: nowrap; }
.m-sqrt > .m-rad { position: absolute; left: 0; top: 0; width: .52em; height: 100%; overflow: visible; }
.m-sqrt > .m-rad path { fill: none; stroke: currentColor; stroke-width: 1.4px; stroke-linejoin: round; stroke-linecap: round; }
.m-sqrt > .m-rc { display: inline-block; border-top: .075em solid currentColor; padding: .12em .12em .02em .06em; line-height: 1.15; }
.m-sqrt .m-frac { vertical-align: middle; margin: .08em .06em; }
.leaf p, .leaf li, .quiz { overflow-wrap: break-word; }
/* công thức in đậm có phân số/căn: không ngắt dòng giữa công thức */
.leaf b:has(.m-frac, .m-sqrt) { white-space: nowrap; }
.m-grp { white-space: nowrap; }
/* dòng công thức đứng riêng: các công thức xếp cách đều, tự xuống dòng */
.leaf .fx {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px 30px;
  margin: 10px 0 12px; font-size: 1.08em; line-height: 1.5;
}
.leaf .fx > * { white-space: nowrap; }
.leaf .fx-note { display: block; text-align: center; font-size: 15px; color: var(--muted); font-style: italic; margin: -6px 0 12px; }
/* lời giải từng bước: mỗi bước một dòng */
.leaf .sol { margin: 4px 0 14px; padding: 8px 12px 8px 14px; border-left: 2px solid var(--line); background: rgba(239, 229, 207, .35); border-radius: 0 8px 8px 0; }
.leaf .sol > .sol-h { font-weight: 700; margin-bottom: 2px; }
.leaf .sol > div:not(.sol-h) { padding: 3px 0; line-height: 1.7; }
.leaf .sol > div:not(.sol-h) + div { border-top: 1px dashed rgba(138, 124, 99, .25); }
.leaf .sol .ans { font-weight: 700; color: var(--accent); }

.keybox {
  border-left: 4px solid var(--accent); background: rgba(239, 229, 207, .7);
  padding: 10px 14px; margin: 14px 0; border-radius: 0 10px 10px 0;
}
.keybox-title { font: 700 12px 'Be Vietnam Pro'; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); margin-bottom: 4px; }
.keybox p:last-child, .keybox ul:last-child { margin-bottom: 0; }

pre.code {
  font: 14px/1.6 'JetBrains Mono', monospace; background: var(--card);
  border: 1.5px solid var(--ink); border-radius: 10px; padding: 10px 0; margin: 10px 0 14px;
  overflow-x: auto; counter-reset: ln;
}
pre.code .ln { display: block; padding: 0 14px 0 44px; position: relative; white-space: pre; transition: background .15s; }
pre.code .ln::before {
  counter-increment: ln; content: counter(ln); position: absolute; left: 0; width: 32px; text-align: right;
  color: #b3a78f; font-size: 12px;
}
pre.code .ln.active { background: var(--yellow-bg); box-shadow: inset 4px 0 0 #f59f00; }
pre.code .kw { color: #9c36b5; font-weight: 600; }
pre.code .fn { color: #1864ab; }
pre.code .cm { color: #8a7c63; font-style: italic; }
pre.code .st { color: #2b8a3e; }

/* code phải hiện đúng từng kí tự: không gộp <= thành ≤, không nối == */
pre.code, .trypy textarea, .trypy-out, code, .ctl-group input, .ctl-group select {
  /* !important vì thuộc tính rút gọn `font:` ở các luật sau sẽ đặt lại ligature */
  font-variant-ligatures: none !important;
  font-feature-settings: "liga" 0, "calt" 0, "dlig" 0 !important;
}

/* ô thử code Python */
.trypy {
  border: 1.5px solid var(--ink); border-radius: 12px; background: #fffdf6; padding: 10px 12px; margin: 14px 0;
  font-family: 'Be Vietnam Pro'; font-size: 14px; box-shadow: 3px 4px 0 rgba(35, 38, 47, .1);
}
.trypy-head { font-weight: 700; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); margin-bottom: 6px; }
.trypy-head span { background: #3776ab; color: #ffd43b; border-radius: 4px; padding: 1px 6px; letter-spacing: .04em; margin-left: 4px; }
.trypy textarea {
  width: 100%; resize: vertical; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  font: 14px/1.55 'JetBrains Mono', monospace; background: #1e2230; color: #e6edf3; tab-size: 4; outline: none;
}
.trypy textarea:focus { border-color: var(--navy); }
.trypy .trypy-in { background: #fff; color: var(--ink); }
.trypy-label { display: block; font-size: 12px; color: var(--muted); margin: 6px 0 3px; }
.trypy-bar { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.trypy-bar .pill { padding: 5px 14px; font-size: 13px; }
.trypy-status { font-size: 12.5px; color: var(--muted); }
.trypy-out {
  margin: 8px 0 0; padding: 8px 10px; border-radius: 8px; background: #11151f; color: #c8f7c5;
  font: 13.5px/1.5 'JetBrains Mono', monospace; white-space: pre-wrap; max-height: 220px; overflow: auto;
}
.trypy-out .e { color: #ff8b8b; }
.trypy-out .h { color: #ffd43b; font-family: 'Be Vietnam Pro'; }

/* ô thử HTML (chương HTML & CSS) — kết quả hiện trên laptop 3D */
.tryweb {
  border: 1.5px solid var(--ink); border-radius: 12px; background: #fffdf6; padding: 10px 12px; margin: 14px 0;
  font-family: 'Be Vietnam Pro'; font-size: 14px; box-shadow: 3px 4px 0 rgba(35, 38, 47, .1);
}
.tryweb .trypy-head span { background: #e34c26; color: #fff; }
.tryweb textarea {
  width: 100%; resize: vertical; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  font: 13.5px/1.55 'JetBrains Mono', monospace; background: #1e2230; color: #e6edf3; tab-size: 2; outline: none;
  font-variant-ligatures: none !important; font-feature-settings: "liga" 0, "calt" 0 !important; white-space: pre; overflow-x: auto;
}
.tryweb textarea:focus { border-color: var(--navy); }
.tryweb .trypy-status.warn { color: #b35c00; font-weight: 600; }
pre.code.web .ln { white-space: pre-wrap; }

/* ô thử SQL (chương Cơ sở dữ liệu) — kết quả diễn lại trên bảng 3D */
.trysql {
  border: 1.5px solid var(--ink); border-radius: 12px; background: #fffdf6; padding: 10px 12px; margin: 14px 0;
  font-family: 'Be Vietnam Pro'; font-size: 14px; box-shadow: 3px 4px 0 rgba(35, 38, 47, .1);
}
.trysql .trypy-head span { background: #4f7cac; color: #fff; }
.trysql textarea {
  width: 100%; resize: vertical; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  font: 14px/1.6 'JetBrains Mono', monospace; background: #1e2230; color: #e6edf3; outline: none; min-height: 130px;
  font-variant-ligatures: none !important; font-feature-settings: "liga" 0, "calt" 0 !important; white-space: pre-wrap;
}
.trysql textarea:focus { border-color: var(--navy); }
.sql-ex { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 8px; }
.sql-ex .pill { padding: 3px 10px; font-size: 12.5px; }
.sql-ex .pill.on { background: #f7ebcd; border-color: #b8862a; }
.sql-out { margin-top: 8px; }
.sql-err { background: #f8e3dc; color: #7c2414; border: 1px solid #c8553d; border-radius: 8px; padding: 7px 10px; font-weight: 600; }
.sql-warn { background: #f7ebcd; color: #6b4a00; border: 1px solid #d9a441; border-radius: 8px; padding: 6px 10px; margin-bottom: 6px; font-size: 13px; }
.sql-ok { background: #e6f2e3; color: #1f5a2c; border: 1px solid #5b9a68; border-radius: 8px; padding: 7px 10px; font-weight: 600; }
table.sql-table { border-collapse: collapse; font: 13px/1.4 'JetBrains Mono', monospace; margin: 0; }
table.sql-table th { background: #5d6680; color: #fbf6ea; padding: 3px 9px; font-weight: 700; }
table.sql-table td { border: 1px solid #d6cbb3; padding: 2px 9px; background: #fbf5e7; }
table.sql-table td.nul { color: #8a8272; font-style: italic; }
.sql-n { font-size: 12px; color: var(--muted); margin-top: 3px; }
pre.code.sql .ln { white-space: pre-wrap; }

/* thẻ dự đoán – như tấm phiếu dán trên trang sách */
.predict {
  position: relative; background: #fff8dc; border: 1.5px solid var(--ink);
  border-radius: 6px; padding: 14px 16px 12px; margin: 18px 4px; transform: rotate(-.6deg);
  box-shadow: 3px 4px 0 rgba(35, 38, 47, .12); font-family: 'Be Vietnam Pro'; font-size: 15px;
}
.predict::before {
  content: ''; position: absolute; top: -10px; left: 50%; width: 90px; height: 20px; transform: translateX(-50%) rotate(2deg);
  background: rgba(214, 200, 160, .75); border: 1px solid rgba(0, 0, 0, .06);
}
.predict-head { font-weight: 700; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.predict .q, .mcq .q, .tf .q { margin: 6px 0 10px; font-weight: 600; line-height: 1.5; }
.opts { display: flex; flex-direction: column; gap: 6px; }
.opt {
  text-align: left; border: 1.5px solid var(--line); background: #fff; border-radius: 8px; padding: 7px 10px;
  font-size: 14.5px; line-height: 1.45;
}
.opt:hover:not(:disabled) { border-color: var(--ink); }
.opt.chosen { border-color: var(--navy); background: #e7eefc; }
.opt.right { border-color: var(--green); background: var(--green-bg); }
.opt.wrong { border-color: var(--red); background: var(--red-bg); }
.opt:disabled { cursor: default; }
.predict .check { margin-top: 10px; }
.feedback { margin-top: 10px; font-size: 14.5px; line-height: 1.5; padding: 8px 10px; border-radius: 8px; background: rgba(255, 255, 255, .7); }
.feedback .verdict { font-weight: 700; }
.feedback .verdict.ok { color: var(--green); }
.feedback .verdict.no { color: var(--red); }

.quiz { font-family: 'Be Vietnam Pro'; font-size: 15px; }
.mcq, .tf { border: 1.5px solid var(--line); background: rgba(255, 253, 246, .8); border-radius: 10px; padding: 12px 14px; margin: 12px 0; }
.tf table { font-size: 14.5px; margin: 0; }
.tf td:last-child { white-space: nowrap; width: 1%; }
.tf .tfb { border: 1.5px solid var(--line); background: #fff; border-radius: 6px; padding: 3px 9px; font-size: 13px; font-weight: 600; margin-left: 4px; }
.tf .tfb.right { border-color: var(--green); background: var(--green-bg); }
.tf .tfb.wrong { border-color: var(--red); background: var(--red-bg); }
.score { font-weight: 700; color: var(--navy); margin-top: 8px; }

/* ghi chú giáo viên */
.teacher { display: none; }
body.teacher-mode .teacher {
  display: block; background: var(--teacher-bg); border: 1.5px solid var(--teacher); border-radius: 10px;
  padding: 10px 14px; margin: 16px 0; font: 14.5px/1.55 'Be Vietnam Pro'; color: #12394b;
}
.teacher-title { font-weight: 700; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--teacher); margin-bottom: 4px; }
.teacher ul { padding-left: 18px; margin: 4px 0; }

/* mục lục */
.toc-lessons { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.lesson-card {
  display: block; text-align: left; width: 100%; border: 1.5px solid var(--ink); border-radius: 12px;
  background: rgba(255, 253, 246, .85); padding: 12px 14px; font-family: 'Be Vietnam Pro'; box-shadow: 0 2px 0 var(--ink);
}
.lesson-card:hover { background: #fff; }
.lesson-card .no { font-size: 12px; font-weight: 700; letter-spacing: .12em; color: var(--accent); text-transform: uppercase; }
.lesson-card .t { font: 700 20px 'Noto Serif', serif; margin: 2px 0; }
.lesson-card .m { font-size: 13px; color: var(--muted); }
.lesson-card.soon { opacity: .55; box-shadow: none; border-style: dashed; cursor: default; }

/* ĐỌC THỬ: thẻ chương trong mục lục (main.js gắn .locked / .trial) */
.lesson-card { position: relative; }
.lesson-card .card-lock {
  position: absolute; top: 10px; right: 12px; font: 700 11px 'Be Vietnam Pro'; letter-spacing: .06em;
  padding: 2px 9px; border-radius: 999px; border: 1.5px solid currentColor;
}
.lesson-card.trial .card-lock { color: #3f7a4c; }
.lesson-card.locked { background: rgba(240, 234, 220, .7); }
.lesson-card.locked .card-lock { color: var(--ink-2); }
.lesson-card.locked .t, .lesson-card.locked .m { opacity: .6; }

/* trang "chương bị khoá" (js/lock-page.js) */
.lock-card .lock-badge {
  display: inline-block; font: 700 12px 'Be Vietnam Pro'; letter-spacing: .08em; text-transform: uppercase;
  padding: 4px 12px; border-radius: 999px; background: #f3e3b5; color: #6b4a12; border: 1.5px solid #c9a04a; margin-bottom: 10px;
}
.lock-card .lock-pages { margin: 4px 0 14px; padding-left: 22px; color: var(--ink-2); }
.lock-card .lock-pages li { margin: 2px 0; }
.lock-card .lock-buy {
  margin: 16px 0 18px; padding: 16px 18px; border-radius: 16px; border: 1.5px solid var(--ink);
  background: rgba(255, 253, 246, .9); box-shadow: 0 3px 0 var(--ink);
}
.lock-card .lock-price { font: 700 30px/1.3 'Noto Serif', serif; color: #1f3d5c; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.lock-card .lock-price span { font: 500 13px 'Be Vietnam Pro'; color: var(--muted); }
.lock-card .lock-btn {
  margin-top: 10px; width: 100%; height: 46px; border-radius: 999px; border: 1.5px solid #14283d; cursor: pointer;
  font: 700 13px 'Be Vietnam Pro'; letter-spacing: .1em; text-transform: uppercase; color: #fff;
  background: linear-gradient(180deg, rgba(255, 255, 255, .25), rgba(255, 255, 255, 0) 55%), #1f3d5c; box-shadow: 0 3px 0 #14283d;
  transition: transform .08s, box-shadow .08s;
}
.lock-card .lock-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #14283d; }
.lock-card .lock-btn:disabled { opacity: .7; cursor: default; }
.lock-card .lock-small { margin: 10px 0 0; font-size: 13.5px; color: var(--muted); }
.lock-card .lock-err { color: var(--accent); }
.lock-card .lock-try { display: flex; flex-direction: column; gap: 6px; }
.lock-card .lock-try a { font-weight: 600; }

.toc {
  position: fixed; top: 0; left: 0; bottom: 0; width: min(380px, 92vw); z-index: 30;
  background: var(--paper); border-right: 1.5px solid var(--ink); box-shadow: var(--shadow);
  padding: 18px; overflow-y: auto; animation: slide .25s ease-out;
}
@keyframes slide { from { transform: translateX(-100%); } to { transform: none; } }
.toc-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.toc-kicker { font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
.toc-title { font: 700 19px 'Noto Serif', serif; }
.toc-backdrop { position: fixed; inset: 0; z-index: 29; background: rgba(40, 30, 15, .18); animation: fadein .2s ease-out; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.toc-lesson { margin-bottom: 6px; border-bottom: 1px dashed rgba(0, 0, 0, .15); padding-bottom: 6px; }
.toc-chap {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; cursor: pointer;
  background: none; border: 0; padding: 8px 6px; border-radius: 8px; color: var(--ink);
}
.toc-chap:hover { background: var(--paper-2); }
.toc-chap-t { flex: 1; font: 700 16px 'Noto Serif', serif; }
.toc-chap-t .toc-no { color: var(--accent); font: 600 11px 'Be Vietnam Pro'; letter-spacing: .1em; display: block; opacity: .85; }
.toc-mark { font: 600 12px 'Be Vietnam Pro'; color: var(--muted); white-space: nowrap; }
.toc-mark.done { color: #5b9a68; font-size: 15px; }
.toc-arrow { font-size: 18px; color: var(--muted); transition: transform .2s; transform: rotate(-90deg); }
.toc-lesson.open .toc-arrow { transform: none; }
.toc-lesson.here .toc-chap-t { color: var(--navy); }
.toc-pages { display: none; padding: 2px 0 4px 8px; }
.toc-lesson.open .toc-pages { display: block; }
.toc-lesson a {
  display: block; padding: 6px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; font-size: 14px;
}
.toc-lesson a:hover { background: var(--paper-2); }
.toc-lesson a.cur { background: var(--navy); color: #fff; }

/* ---------- Giao diện kính mờ (glass) — bật bằng body.glass ---------- */
body.glass {
  --glass-bg: linear-gradient(180deg, rgba(255, 255, 255, .32) 0%, rgba(255, 255, 255, .06) 48%, rgba(255, 255, 255, 0) 52%),
    linear-gradient(135deg, rgba(255, 255, 255, .42), rgba(255, 250, 238, .18));
  --glass-edge: rgba(255, 255, 255, .65);
  --glass-shadow: 0 8px 28px rgba(50, 38, 18, .18), inset 0 1px 0 rgba(255, 255, 255, .75), inset 0 -1px 0 rgba(255, 255, 255, .15);
}
body.glass .bar,
body.glass .stage-status,
body.glass .info-card,
body.glass .ctl-group,
body.glass :is(.stage-controls, .settings-wrap, .side-cards) .pill {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(16px) saturate(1.6);
  backdrop-filter: blur(16px) saturate(1.6);
  border: 1px solid var(--glass-edge);
  box-shadow: var(--glass-shadow);
}
body.glass .stage-status, body.glass .info-card { border-radius: 18px; color: #1d2029; text-shadow: 0 1px 0 rgba(255, 255, 255, .45); }
body.glass .bar .icon:hover { background: rgba(255, 255, 255, .45); }
body.glass .bar .icon[aria-pressed="true"] { background: rgba(255, 255, 255, .55); color: var(--teacher); }
body.glass .sep { background: rgba(35, 38, 47, .15); }
body.glass :is(.stage-controls, .settings-wrap, .side-cards) .pill { color: var(--ink); transition: transform .12s, background .15s, box-shadow .15s; }
body.glass :is(.stage-controls, .settings-wrap, .side-cards) .pill:hover { background: linear-gradient(135deg, rgba(255, 255, 255, .62), rgba(255, 250, 238, .32)); }
body.glass :is(.stage-controls, .settings-wrap, .side-cards) .pill:active { transform: scale(.96); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .75), 0 3px 10px rgba(50, 38, 18, .16); }
body.glass :is(.stage-controls, .settings-wrap, .side-cards) .pill.primary {
  background: linear-gradient(135deg, rgba(31, 61, 92, .82), rgba(31, 61, 92, .62));
  color: #fff; border-color: rgba(160, 195, 230, .55);
  box-shadow: 0 8px 24px rgba(15, 34, 54, .28), inset 0 1px 0 rgba(255, 255, 255, .35);
}
body.glass :is(.stage-controls, .settings-wrap, .side-cards) .pill.on { background: linear-gradient(135deg, rgba(255, 236, 160, .7), rgba(255, 243, 191, .35)); }
body.glass .ctl-group input[type=text],
body.glass .ctl-group input[type=number],
body.glass .ctl-group input:not([type]),
body.glass .ctl-group select {
  background: rgba(255, 255, 255, .55) !important; border: 1px solid rgba(255, 255, 255, .8) !important;
  box-shadow: inset 0 1px 3px rgba(50, 38, 18, .12);
}
body.glass .ctl-group select option { background: #fbf6ea; }
body.glass .info-x { color: var(--ink-2); }

/* --- Rê chuột: kính sáng lên, nổi lên, vệt sáng lướt qua, đốm sáng theo con trỏ --- */
body.glass :is(.stage-controls, .settings-wrap, .side-cards) .pill,
body.glass .bar .icon,
body.glass .stage-status,
body.glass .info-card,
body.glass .ctl-group {
  position: relative; overflow: hidden; isolation: isolate;
  transition: transform .25s cubic-bezier(.2, .8, .3, 1.2), box-shadow .25s, background .25s, border-color .25s;
}
/* vệt sáng chéo lướt qua khi rê chuột */
body.glass :is(.stage-controls, .settings-wrap, .side-cards) .pill::before,
body.glass .bar .icon::before,
body.glass .stage-status::before,
body.glass .info-card::before {
  content: ''; position: absolute; top: -20%; bottom: -20%; left: -60%; width: 45%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .7), transparent);
  transform: skewX(-20deg) translateX(0); opacity: 0; pointer-events: none; z-index: 1;
}
body.glass :is(.stage-controls, .settings-wrap, .side-cards) .pill:hover::before,
body.glass .bar .icon:hover::before,
body.glass .stage-status:hover::before,
body.glass .info-card:hover::before {
  animation: glass-sheen .75s ease-out;
}
@keyframes glass-sheen {
  0% { transform: skewX(-20deg) translateX(0); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: skewX(-20deg) translateX(420%); opacity: 0; }
}
/* đốm sáng đi theo con trỏ (--mx, --my do main.js cập nhật) */
body.glass :is(.stage-controls, .settings-wrap, .side-cards) .pill::after,
body.glass .stage-status::after,
body.glass .info-card::after,
body.glass .ctl-group::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: -1;
  background: radial-gradient(140px circle at var(--mx, 50%) var(--my, 50%), rgba(255, 255, 255, .55), transparent 65%);
  opacity: 0; transition: opacity .25s;
}
body.glass :is(.stage-controls, .settings-wrap, .side-cards) .pill:hover::after,
body.glass .stage-status:hover::after,
body.glass .info-card:hover::after,
body.glass .ctl-group:hover::after { opacity: 1; }

body.glass :is(.stage-controls, .settings-wrap, .side-cards) .pill:hover {
  transform: translateY(-3px);
  border-color: rgba(255, 255, 255, .95);
  -webkit-backdrop-filter: blur(22px) saturate(1.9);
  backdrop-filter: blur(22px) saturate(1.9);
  box-shadow: 0 14px 34px rgba(50, 38, 18, .24), 0 0 0 4px rgba(255, 255, 255, .18),
    inset 0 1px 0 rgba(255, 255, 255, .95), inset 0 -8px 16px rgba(255, 255, 255, .12);
}
body.glass :is(.stage-controls, .settings-wrap, .side-cards) .pill.primary:hover {
  background: linear-gradient(135deg, rgba(41, 81, 120, .88), rgba(31, 61, 92, .7));
  border-color: rgba(190, 220, 250, .85);
  box-shadow: 0 14px 34px rgba(15, 34, 54, .34), 0 0 0 4px rgba(120, 170, 220, .2), inset 0 1px 0 rgba(255, 255, 255, .5);
}
body.glass :is(.stage-controls, .settings-wrap, .side-cards) .pill.primary::after {
  background: radial-gradient(120px circle at var(--mx, 50%) var(--my, 50%), rgba(170, 210, 255, .45), transparent 65%);
}
body.glass :is(.stage-controls, .settings-wrap, .side-cards) .pill:active { transform: translateY(0) scale(.96); transition-duration: .08s; }

body.glass .bar .icon:hover {
  transform: translateY(-2px) scale(1.08);
  background: linear-gradient(135deg, rgba(255, 255, 255, .75), rgba(255, 255, 255, .3));
  box-shadow: 0 6px 16px rgba(50, 38, 18, .18), inset 0 1px 0 rgba(255, 255, 255, .95), 0 0 0 1px rgba(255, 255, 255, .7);
}
body.glass .bar .icon:active { transform: scale(.94); }
body.glass .bar .icon:disabled:hover { transform: none; box-shadow: none; background: transparent; }
body.glass .bar .icon:disabled::before { display: none; }

body.glass .stage-status:hover,
body.glass .info-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, .95);
  box-shadow: 0 14px 36px rgba(50, 38, 18, .22), inset 0 1px 0 rgba(255, 255, 255, .9);
}
body.glass .bar:hover { box-shadow: 0 12px 34px rgba(50, 38, 18, .22), inset 0 1px 0 rgba(255, 255, 255, .9); }
/* --- Ấn: kính lún xuống, đặc hơn, bóng chuyển vào trong + gợn sáng lan từ điểm bấm --- */
body.glass :is(.stage-controls, .settings-wrap, .side-cards) .pill:active,
body.glass :is(.stage-controls, .settings-wrap, .side-cards) .pill.glass-press {
  transform: translateY(1px) scale(.94);
  transition-duration: .08s;
  background: linear-gradient(135deg, rgba(255, 255, 255, .7), rgba(255, 250, 238, .45));
  -webkit-backdrop-filter: blur(28px) saturate(2.1) brightness(1.06);
  backdrop-filter: blur(28px) saturate(2.1) brightness(1.06);
  box-shadow: 0 3px 10px rgba(50, 38, 18, .2), inset 0 2px 8px rgba(50, 38, 18, .14), inset 0 -1px 0 rgba(255, 255, 255, .9);
}
body.glass :is(.stage-controls, .settings-wrap, .side-cards) .pill.primary:active,
body.glass :is(.stage-controls, .settings-wrap, .side-cards) .pill.primary.glass-press {
  background: linear-gradient(135deg, rgba(25, 52, 80, .92), rgba(41, 81, 120, .8));
  box-shadow: 0 3px 10px rgba(15, 34, 54, .3), inset 0 2px 10px rgba(0, 0, 0, .28), inset 0 -1px 0 rgba(190, 220, 250, .6);
}
body.glass .bar .icon:active {
  transform: scale(.9); transition-duration: .08s;
  background: linear-gradient(135deg, rgba(255, 255, 255, .9), rgba(255, 255, 255, .5));
  box-shadow: inset 0 2px 6px rgba(50, 38, 18, .18), 0 0 0 1px rgba(255, 255, 255, .9);
}
body.glass .stage-status:active, body.glass .info-card:active { transform: scale(.985); transition-duration: .08s; }
.glass-ripple {
  position: absolute; border-radius: 50%; pointer-events: none; z-index: 2;
  width: 10px; height: 10px; margin: -5px 0 0 -5px;
  background: radial-gradient(circle, rgba(255, 255, 255, .95) 0%, rgba(255, 255, 255, .45) 40%, rgba(255, 255, 255, 0) 70%);
  animation: glass-ripple .6s cubic-bezier(.2, .7, .3, 1) forwards;
}
.pill.primary .glass-ripple {
  background: radial-gradient(circle, rgba(200, 228, 255, .85) 0%, rgba(170, 210, 255, .35) 40%, rgba(170, 210, 255, 0) 70%);
}
@keyframes glass-ripple {
  from { transform: scale(1); opacity: 1; }
  to { transform: scale(var(--rs, 30)); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .glass-ripple { display: none; }
  body.glass *::before { animation: none !important; }
  body.glass :is(.stage-controls, .settings-wrap, .side-cards) .pill:hover, body.glass .bar .icon:hover,
  body.glass .stage-status:hover, body.glass .info-card:hover { transform: none; }
}

/* ---------- Nút & bảng Tùy chỉnh (góc trái trên) ---------- */
.settings-wrap { position: fixed; top: 16px; left: 16px; z-index: 25; }
.settings-btn { display: inline-flex; align-items: center; gap: 7px; padding: 7px 14px 7px 10px; font-size: 14px; }
/* SVG mặc định xoay quanh góc trên-trái → phải đặt tâm xoay ở giữa, nếu không bánh răng văng lệch */
.settings-btn svg {
  display: block; flex: none; transform-origin: 50% 50%; transform-box: fill-box;
  transition: transform .5s cubic-bezier(.2, .8, .3, 1.2);
}
.settings-btn:hover svg, .settings-btn.on svg { transform: rotate(60deg); }
.settings-panel {
  position: fixed; top: 64px; left: 16px; z-index: 25; width: min(360px, calc(100vw - 32px));
  max-height: calc(100vh - 170px); overflow-y: auto;
  padding: 14px 16px 16px; border-radius: 20px; color: var(--ink);
  background: rgba(255, 253, 246, .95); border: 1.5px solid var(--ink); box-shadow: var(--shadow);
  animation: rise .22s ease-out;
}
body.glass .settings-panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, .5), rgba(255, 250, 238, .3));
  -webkit-backdrop-filter: blur(22px) saturate(1.5); backdrop-filter: blur(22px) saturate(1.5);
  border: 1px solid rgba(255, 255, 255, .75);
  box-shadow: 0 18px 50px rgba(50, 38, 18, .25), inset 0 1px 0 rgba(255, 255, 255, .85);
}
.set-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.set-head h3 { margin: 0; font: 700 19px 'Noto Serif', serif; }
.set-head .info-x { position: static; }
/* mục thu gọn: chỉ tiêu đề + lựa chọn hiện tại, bấm để sổ xuống (settings.js) */
.set-sec + .set-sec { border-top: 1px solid rgba(35, 38, 47, .1); }
.set-sec-head {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 11px 4px; border: 0; background: none;
  text-align: left; color: var(--ink); cursor: pointer; border-radius: 10px;
}
.set-sec-head:hover { background: rgba(255, 255, 255, .35); }
.set-sec-t { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.set-sec-sum { flex: 1; text-align: right; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.set-sec-arrow { font-size: 13px; color: var(--muted); transition: transform .25s; }
.set-sec.open .set-sec-arrow { transform: rotate(180deg); }
.set-sec-wrap { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .3s ease; }
.set-sec.open .set-sec-wrap { grid-template-rows: 1fr; }
.set-sec-wrap > .set-body { min-height: 0; overflow: hidden; }
.set-sec.open .set-sec-wrap > .set-body { padding-bottom: 12px; }
.set-options { display: grid; gap: 8px; }
.set-opt {
  display: grid; grid-template-columns: 24px 1fr; column-gap: 10px; align-items: center;
  text-align: left; padding: 9px 12px; border-radius: 12px;
  border: 1px solid rgba(35, 38, 47, .12); background: rgba(255, 255, 255, .35);
  transition: background .2s, border-color .2s, transform .15s, box-shadow .2s;
}
.set-opt:hover { background: rgba(255, 255, 255, .6); transform: translateY(-1px); box-shadow: 0 6px 16px rgba(50, 38, 18, .12); }
.set-opt:active { transform: scale(.98); }
.set-opt[aria-pressed="true"] {
  background: linear-gradient(135deg, rgba(31, 61, 92, .85), rgba(31, 61, 92, .68)); color: #fff;
  border-color: rgba(160, 195, 230, .6); box-shadow: 0 6px 18px rgba(15, 34, 54, .25), inset 0 1px 0 rgba(255, 255, 255, .3);
}
.set-opt-ic { display: flex; justify-content: center; opacity: .8; }
.set-opt[aria-pressed="true"] .set-opt-ic { opacity: 1; }
.set-opt-t { font-weight: 600; font-size: 14px; }
.set-options { gap: 6px; }
.set-vol { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 13px; font-weight: 600; }
.set-vol input { flex: 1; accent-color: #1f3d5c; }
.set-vol b { width: 38px; text-align: right; font-variant-numeric: tabular-nums; }
.set-note { margin: 8px 0 0; font-size: 12px; opacity: .75; }
.set-note.warn { opacity: 1; color: #8a4b12; font-weight: 600; }

/* đồng hồ học tập: ô tăng/giảm phút, hàng nút */
.set-step { display: flex; align-items: center; gap: 8px; padding: 6px 2px; font-size: 14px; }
.set-step > span { flex: 1; font-weight: 600; }
.set-step b { min-width: 28px; text-align: center; font-size: 17px; font-variant-numeric: tabular-nums; }
.set-step i { font-style: normal; font-size: 12px; opacity: .7; margin-left: -4px; }
.set-step-b {
  width: 30px; height: 30px; border-radius: 50%; border: 1px solid rgba(35, 38, 47, .16);
  background: rgba(255, 255, 255, .45); font-size: 17px; line-height: 1; color: var(--ink); cursor: pointer;
}
.set-step-b:hover { background: rgba(255, 255, 255, .8); }
.set-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.set-btn {
  padding: 7px 12px; border-radius: 10px; border: 1px solid rgba(35, 38, 47, .16); background: rgba(255, 255, 255, .45);
  font-size: 13px; font-weight: 600; color: var(--ink); cursor: pointer;
}
.set-btn:hover { background: rgba(255, 255, 255, .8); }
.set-btn.primary { background: rgba(31, 61, 92, .85); border-color: transparent; color: #fff; }
.set-btn.primary:hover { background: rgba(31, 61, 92, 1); }
/* tiến độ học trong bảng Tùy chỉnh */
.set-prog { display: grid; gap: 4px; }
.set-prog-row { display: grid; grid-template-columns: 1fr 70px 38px; align-items: center; gap: 8px; padding: 4px 4px; border-radius: 8px; font-size: 13px; color: var(--ink); text-decoration: none; }
.set-prog-row:hover { background: rgba(255, 255, 255, .45); }
.set-prog-row span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.set-prog-row b { text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; }
.set-prog-row.done .prog-bar i { background: #5b9a68; }

/* viên đồng hồ cạnh nút Tùy chỉnh (study-timer.js) */
.settings-wrap { display: flex; align-items: center; gap: 8px; }
.study-pill { display: inline-flex; align-items: center; gap: 7px; position: relative; font-variant-numeric: tabular-nums; }
.study-pill[hidden] { display: none; }
.study-pill .sp-dot { width: 9px; height: 9px; border-radius: 50%; background: #c8553d; }
.study-pill[data-phase="rest"] .sp-dot { background: #5b9a68; }
.study-pill:not(.paused) .sp-dot { animation: nt-pulse 2s ease-in-out infinite; }
.study-pill.paused { opacity: .8; }
.study-pill .sp-bar { position: absolute; left: 14px; right: 14px; bottom: 3px; height: 2px; border-radius: 1px; background: rgba(35, 38, 47, .1); overflow: hidden; }
.study-pill .sp-bar i { display: block; height: 100%; background: #c8553d; }
.study-pill[data-phase="rest"] .sp-bar i { background: #5b9a68; }
.study-pill.ring { animation: sp-ring .5s ease-in-out 6; }
@keyframes sp-ring { 25% { transform: rotate(-4deg) scale(1.06); } 75% { transform: rotate(4deg) scale(1.06); } }

/* chế độ máy yếu: bỏ kính mờ (backdrop-filter rất tốn), thay bằng nền giấy gần đục */
body.lite * { -webkit-backdrop-filter: none !important; backdrop-filter: none !important; }
body.lite :is(.stage-status, .info-card, .settings-panel, .bar, .ctl-group),
body.lite :is(.stage-controls, .settings-wrap, .side-cards) .pill:not(.primary) { background: rgba(255, 252, 244, .94) !important; }

/* ---------- Điện thoại: mô hình ở trên, chữ ở dưới ---------- */
.flat-page { display: none; }
@media (max-width: 820px) {
  body { overflow: visible; height: auto; }
  body.flat .stage-wrap { position: sticky; inset: auto; top: 0; height: 50vh; z-index: 3; border-bottom: 1.5px solid var(--ink); }
  body.flat .stage-status .legend { display: none; }
  body.flat .stage-status .st-op { min-height: 0; }
  body.flat .stage-controls { gap: 4px; width: calc(100vw - 16px); }
  body.flat :is(.stage-controls, .settings-wrap, .side-cards) .pill { padding: 5px 10px; font-size: 12px; }
  body.flat .ctl-group { font-size: 12px; padding: 2px 4px 2px 10px; }
  body.flat .ctl-group:has(input[type=range]) { display: none; }
  body.flat .flat-page { display: block; position: relative; z-index: 2; background: var(--paper); border-top: 1.5px solid var(--ink); min-height: 52vh; padding-bottom: 120px; }
  body.flat .leaf { overflow: visible; padding: 22px 18px 30px; font-size: 17px; }
  body.flat .leaf h2 { font-size: 26px; }
  .side-cards { position: absolute; top: 52px; left: 8px; right: 8px; width: auto; }
  .settings-wrap { top: 8px; left: 8px; }
  .settings-panel { top: 52px; left: 8px; }
  .stage-status, .info-card { font-size: 13px; padding: 9px 11px; }
  .stage-controls { position: absolute; bottom: 10px; }
  .bar { bottom: 10px; }
  .bar-title { max-width: 120px; }
  #btn-view-text { display: none; }
  .ctl-group input[type=text] { width: 120px; }
}

/* ---------- Hướng dẫn lần đầu vào trang sách (js/tour.js) ---------- */
/* lớp phủ chặn thao tác phía sau; vùng tối do bóng đổ khổng lồ của "lỗ" đèn rọi */
.tour { position: fixed; inset: 0; z-index: 3000; pointer-events: auto; animation: tour-in .35s ease-out; }
.tour.out { opacity: 0; transition: opacity .25s; }
@keyframes tour-in { from { opacity: 0; } to { opacity: 1; } }
.tour-dim {
  position: fixed; inset: 0; background: rgba(24, 20, 14, .48);
  transition: clip-path .45s cubic-bezier(.2, .8, .2, 1);
}
/* vòng sáng quanh vùng đang giới thiệu */
.tour-hole {
  position: fixed; border-radius: 14px; pointer-events: none;
  box-shadow: 0 0 0 3px rgba(255, 233, 170, .95), 0 0 26px 6px rgba(255, 220, 140, .55);
  transition: left .45s cubic-bezier(.2, .8, .2, 1), top .45s cubic-bezier(.2, .8, .2, 1), width .45s cubic-bezier(.2, .8, .2, 1), height .45s cubic-bezier(.2, .8, .2, 1);
}
.tour.center .tour-hole { box-shadow: none; }
/* thẻ hướng dẫn kiểu KÍNH (giống thẻ thông báo / nút trong sách): nền trắng trong hai lớp + viền sáng + làm mờ phía sau,
   vệt sáng chéo lướt qua mỗi khi sang bước mới, đốm sáng đi theo con trỏ (--mx/--my do tour.js ghi) */
.tour-card {
  position: fixed; padding: 16px 18px 14px; border-radius: 22px; color: #1d2029; font-family: 'Be Vietnam Pro', sans-serif;
  overflow: hidden; isolation: isolate;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .62) 0%, rgba(255, 255, 255, .38) 48%, rgba(255, 255, 255, .26) 52%, rgba(255, 252, 244, .34) 100%),
    linear-gradient(135deg, rgba(255, 250, 238, .45), rgba(255, 255, 255, .12));
  -webkit-backdrop-filter: blur(24px) saturate(1.8); backdrop-filter: blur(24px) saturate(1.8);
  border: 1px solid rgba(255, 255, 255, .8);
  box-shadow: 0 26px 60px -14px rgba(10, 6, 2, .55), 0 0 0 1px rgba(255, 255, 255, .18),
    inset 0 1px 0 rgba(255, 255, 255, .95), inset 0 -1px 0 rgba(255, 255, 255, .3);
  text-shadow: 0 1px 0 rgba(255, 255, 255, .5);
  transition: left .45s cubic-bezier(.2, .8, .2, 1), top .45s cubic-bezier(.2, .8, .2, 1);
}
.tour-card::before { /* vệt sáng chéo */
  content: ''; position: absolute; top: -20%; bottom: -20%; left: -60%; width: 45%; z-index: -1; pointer-events: none;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .8), transparent); transform: skewX(-20deg); opacity: 0;
}
.tour-card.in::before { animation: glass-sheen .9s ease-out .1s; }
.tour-card::after { /* đốm sáng theo con trỏ */
  content: ''; position: absolute; inset: 0; z-index: -1; pointer-events: none; border-radius: inherit; opacity: 0; transition: opacity .25s;
  background: radial-gradient(240px circle at var(--mx, 50%) var(--my, 30%), rgba(255, 255, 255, .55), transparent 70%);
}
.tour-card:hover::after { opacity: 1; }
.tour-card.in { animation: tour-card .45s cubic-bezier(.2, .8, .3, 1.15); }
@keyframes tour-card { from { transform: translateY(10px) scale(.96); } to { transform: none; } }
.tour-step { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.tour-title { font: 700 19px/1.3 'Noto Serif', serif; margin: 4px 0 6px; }
.tour-body { font-size: 14px; line-height: 1.55; color: #3a3428; }
.tour-list { margin: 2px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 5px; }
.tour-list li { position: relative; padding-left: 14px; }
.tour-list li::before { content: ''; position: absolute; left: 2px; top: .62em; width: 5px; height: 5px; border-radius: 50%; background: #c8553d; }
.tour-dots { display: flex; gap: 5px; margin: 12px 0 10px; }
.tour-dots i { width: 6px; height: 6px; border-radius: 50%; background: rgba(35, 38, 47, .18); transition: width .3s, background .3s; }
.tour-dots i.on { width: 18px; border-radius: 3px; background: #1f3d5c; }
.tour-acts { display: flex; align-items: center; gap: 8px; }
.tour-acts span { flex: 1; }
/* nút kính: nổi lên khi rê, lún + gợn sáng khi bấm (.glass-ripple, .glass-press do tour.js gắn) */
.tour-acts button {
  position: relative; overflow: hidden; isolation: isolate;
  height: 34px; padding: 0 14px; border-radius: 999px; font: 600 13px 'Be Vietnam Pro', sans-serif; cursor: pointer;
  border: 1px solid rgba(255, 255, 255, .9); color: #1d2029;
  background: linear-gradient(180deg, rgba(255, 255, 255, .62) 0%, rgba(255, 255, 255, .28) 48%, rgba(255, 255, 255, .16) 52%);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  box-shadow: 0 6px 16px rgba(50, 38, 18, .16), inset 0 1px 0 #fff, inset 0 -1px 0 rgba(255, 255, 255, .3);
  transition: transform .2s cubic-bezier(.2, .8, .3, 1.2), box-shadow .2s;
}
.tour-acts button:hover { transform: translateY(-2px); box-shadow: 0 10px 22px rgba(50, 38, 18, .22), 0 0 0 3px rgba(255, 255, 255, .25), inset 0 1px 0 #fff; }
.tour-acts button:active, .tour-acts button.glass-press { transform: translateY(1px) scale(.95); transition-duration: .08s;
  box-shadow: 0 2px 6px rgba(50, 38, 18, .18), inset 0 2px 6px rgba(50, 38, 18, .14); }
.tour-acts .tour-skip { background: none; border-color: transparent; box-shadow: none; color: #6b6253; padding: 0 6px; }
.tour-acts .tour-next { color: #fff; border-color: rgba(255, 255, 255, .5);
  background: linear-gradient(180deg, rgba(255, 255, 255, .28), rgba(255, 255, 255, 0) 55%), #1f3d5c;
  box-shadow: 0 8px 18px rgba(31, 61, 92, .35), inset 0 1px 0 rgba(255, 255, 255, .45); }
.tour-acts button[hidden] { display: none; }
/* máy yếu: không làm mờ phía sau (tốn GPU) nhưng vẫn giữ dáng kính: nền sáng đậm hơn, viền + vệt sáng giữ nguyên */
body.lite .tour-card { background: linear-gradient(180deg, rgba(255, 255, 255, .93), rgba(250, 246, 236, .86) 52%, rgba(255, 252, 244, .9)) !important; }
body.lite .tour-acts button:not(.tour-next):not(.tour-skip) { background: rgba(255, 255, 255, .8) !important; }
@media (prefers-reduced-motion: reduce) { .tour, .tour-card.in { animation: none; } .tour-hole, .tour-card, .tour-dim { transition: none; } }

/* ---------- Viên báo đang tải (js/busy.js) ---------- */
.busy-pill { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 1000; pointer-events: none;
  padding: 12px 22px; border-radius: 999px; background: rgba(35, 38, 47, .88); color: #fff8e8; font: 600 15px 'Be Vietnam Pro', sans-serif; white-space: nowrap; }
.busy-pill[hidden] { display: none; }
