:root {
  --red: #c8102e;
  --red-dark: #9b0c23;
  --gold: #d9a441;
  --ink: #2b2420;
  --muted: #7a6f68;
  --bg: #faf5ee;
  --card: #fff;
  --line: #eadfce;
  --ok: #2e8b57;
  --warn: #d98e04;
  --bad: #c8102e;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(80, 50, 20, .08);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.6; min-height: 100vh; display: flex; flex-direction: column;
}
main { flex: 1; padding-block: 24px 48px; }
.wrap { width: min(1080px, 100% - 32px); margin-inline: auto; }
a { color: var(--red); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hanzi, ruby, .prose ruby { font-family: "Noto Serif SC", "Songti SC", "SimSun", serif; }
.hanzi.big { font-size: 1.5rem; }
.pinyin { color: var(--red-dark); }
.loading, .empty { text-align: center; color: var(--muted); padding: 32px 16px; }

/* Header */
.site-header { background: #fff; border-bottom: 3px solid var(--red); position: sticky; top: 0; z-index: 10; }
.header-in { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding-block: 10px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 600; font-size: 1.2rem; }
.brand b { color: var(--red); }
.brand small { font-size: .7rem; font-weight: 500; color: var(--muted); margin-left: 4px; }
.logo { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--red); color: #fff; font: 700 1.3rem "Noto Serif SC", serif; }
nav { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
nav[hidden] { display: none; }
nav a { text-decoration: none; color: var(--ink); padding: 6px 12px; border-radius: 999px; font-size: .92rem; }
nav a:hover { background: #f4e8d8; }
nav a.active { background: var(--red); color: #fff; }
.site-footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 18px 0; border-top: 1px solid var(--line); }

/* Cards, grid */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-bottom: 16px; }
.grid.four { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid .card { margin: 0; }
.card.item { text-decoration: none; color: inherit; display: flex; flex-direction: column; gap: 6px; transition: transform .15s, box-shadow .15s; }
.card.item:hover { transform: translateY(-3px); box-shadow: 0 8px 20px rgba(80, 50, 20, .14); }
.card.item h3 { margin: 0; color: var(--ink); }
.card.item p { margin: 0; flex: 1; }
.more { color: var(--red); font-weight: 600; font-size: .9rem; }
.stat { text-decoration: none; text-align: center; color: var(--ink); }
.stat b { display: block; font-size: 2rem; color: var(--red); }
.sec { margin: 28px 0 12px; font-size: 1.25rem; }
.back { display: inline-block; margin-bottom: 12px; text-decoration: none; font-weight: 500; }

.hero { background: linear-gradient(135deg, var(--red), #e0453f); color: #fff; border-radius: 20px; padding: 36px 28px; margin-bottom: 22px; }
.hero h1 { font: 700 clamp(1.5rem, 4vw, 2.2rem) "Noto Serif SC", "Be Vietnam Pro", serif; }
.hero p { margin: 0; opacity: .92; }

/* Badges, chips */
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 10px; border-radius: 999px; background: #fbe7ea; color: var(--red-dark); }
.badge.plain { background: #eee6da; color: var(--muted); }
.badge.ok { background: #dff3e7; color: var(--ok); }
.badge.lv1 { background: #e3f4e8; color: #1f7a45; }
.badge.lv2 { background: #e0f0fa; color: #1c6f9e; }
.badge.lv3 { background: #fff1d6; color: #9a6500; }
.badge.lv4 { background: #fde3d3; color: #a84a12; }
.badge.lv5 { background: #f5dcf0; color: #8a2b7a; }
.badge.lv6 { background: #fbe0e3; color: #a3102a; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 14px; cursor: pointer; font: inherit; font-size: .9rem; }
.chip:hover { border-color: var(--red); }
.chip.active { background: var(--red); border-color: var(--red); color: #fff; }

/* Buttons & forms */
.btn { display: inline-block; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 8px 16px; border-radius: 10px; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; }
.btn:hover:not(:disabled) { border-color: var(--red); color: var(--red); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--red-dark); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 10px; font-size: .82rem; }
.btn.big { padding: 12px 32px; font-size: 1.05rem; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 18px 0; }
.bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.row { display: flex; gap: 14px; flex-wrap: wrap; align-items: end; }
.row > .field { flex: 1 1 180px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; font-weight: 500; margin-bottom: 12px; }
.field.narrow { max-width: 220px; }
input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(200, 16, 46, .35); border-color: var(--red); }
textarea { resize: vertical; }
textarea.mono, pre { font-family: ui-monospace, Consolas, monospace; font-size: .9rem; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; font-weight: 500; }
.check input, .switch input, .opt input { width: auto; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .split { grid-template-columns: 1fr; } }
.filters { display: grid; grid-template-columns: 2fr 1fr 2fr 1fr; gap: 10px; }
.filters.three { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 700px) { .filters.three { grid-template-columns: 1fr; } }
/* Thứ tự nét chữ Hán */
.stroke-btn { border: 0; background: #e9f2ff; border-radius: 50%; width: 28px; height: 28px; cursor: pointer; font-size: .85rem; vertical-align: middle; }
.stroke-btn:hover { background: #cfe2ff; }
.sv-back { position: fixed; inset: 0; background: rgba(40, 28, 20, .55); display: grid; place-items: center; z-index: 2147482000; padding: 16px; }
.sv-dialog { background: var(--card); border-radius: var(--radius); box-shadow: 0 12px 40px rgba(0, 0, 0, .3); padding: 16px 18px; width: min(420px, 100%); max-height: calc(100dvh - 32px); overflow: auto; }
.sv-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.sv-word { font-size: 1.5rem; }
.sv-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.sv-tab { border: 1px solid var(--line); background: #fff; border-radius: 10px; width: 42px; height: 42px; font-size: 1.3rem; cursor: pointer; }
.sv-tab.on { border-color: var(--red); background: #fdeef0; color: var(--red-dark); }
.sv-stage { display: grid; place-items: center; min-height: 240px; }
.sv-box { width: min(260px, 70vw); }
.sv-svg { display: block; width: 100%; height: auto; }
.sv-guide rect { fill: #fffdf9; stroke: var(--line); stroke-width: 2; }
.sv-guide line { stroke: var(--line); stroke-width: 2; stroke-dasharray: 12 12; }
.sv-filled { fill: var(--ink); opacity: 0; transition: opacity .15s; }
.sv-stroke.active .sv-draw { stroke: var(--red); }
.sv-draw { stroke: var(--ink); }
.sv-msg { text-align: center; margin: 0; padding: 0 8px; }
.sv-actions { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }
.sv-credit { text-align: center; margin: 10px 0 0; }

/* Nhạc nền trang chủ (góc dưới bên trái) */
.music-player { position: fixed; left: 14px; bottom: 14px; z-index: 40; width: min(300px, calc(100vw - 28px)); font-size: .9rem; }
.music-toggle { width: 100%; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 999px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; box-shadow: var(--shadow); }
.music-toggle:hover { border-color: var(--red); color: var(--red); }
.music-head { display: flex; gap: 6px; align-items: stretch; }
.music-head .music-toggle { flex: 1; min-width: 0; }
.music-pick { max-width: 150px; border-radius: 999px; padding: 6px 10px; font: inherit; font-size: .85rem; background: #fff; border: 1px solid var(--line); }
.music-one { align-self: center; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; color: var(--muted); }
.music-table input[type=text], .music-table input:not([type]) { min-width: 140px; }
.music-table td { vertical-align: middle; }
.music-frame { margin-top: 8px; border-radius: 12px; overflow: hidden; background: #000; box-shadow: var(--shadow); }
.music-frame[hidden] { display: none; }
.music-frame iframe { display: block; width: 100%; height: 170px; border: 0; }

/* Đồng hồ làm bài trên thanh menu */
.timer-chip { margin-left: 6px; padding: 4px 12px; border-radius: 999px; background: #fff7e6; border: 1px solid var(--gold); color: var(--red-dark); font-weight: 700; font-size: .9rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Bảng xếp hạng (admin) */
#lb-info { margin: -4px 2px 10px; }
table.lb td { white-space: nowrap; }
.lb-rank { font-weight: 700; font-size: 1.05rem; }
.lb-pct { display: flex; align-items: center; gap: 8px; min-width: 130px; }
.lb-bar { flex: 1; height: 8px; border-radius: 99px; background: #eee6da; overflow: hidden; }
.lb-bar i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
tr.top1 td { background: #fff7d6; }
tr.top2 td { background: #f3f3f3; }
tr.top3 td { background: #fbeadb; }
@media (max-width: 700px) { .filters { grid-template-columns: 1fr; } }
.login { max-width: 420px; margin: 40px auto; }
.help summary { cursor: pointer; font-weight: 600; }
.help { padding: 12px 16px; }
pre { background: #f7f0e5; border-radius: 10px; padding: 12px; overflow-x: auto; }
code { background: #f4e8d8; padding: 1px 6px; border-radius: 5px; }

/* Tables */
.table-wrap { overflow-x: auto; padding: 0; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: #f9f1e4; font-size: .85rem; color: var(--muted); }
tbody tr:last-child td { border-bottom: 0; }
.prose .table-wrap { margin: 12px 0; border: 1px solid var(--line); border-radius: 10px; }

/* Lesson */
.lesson-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.switch { font-size: .88rem; display: flex; gap: 6px; align-items: center; cursor: pointer; }
.prose { font-size: 1.05rem; }
.prose h2 { color: var(--red-dark); border-bottom: 2px solid var(--line); padding-bottom: 4px; margin-top: 1.4em; }
.prose h3 { margin-top: 1.2em; }
.prose blockquote { margin: 12px 0; padding: 10px 16px; background: #fff7e6; border-left: 4px solid var(--gold); border-radius: 0 10px 10px 0; }
.prose img { max-width: 100%; border-radius: 10px; }
.prose hr { border: 0; border-top: 1px dashed var(--line); margin: 20px 0; }
.prose ruby { font-size: 1.3em; }
.prose rt { font-size: .5em; color: var(--red-dark); font-family: "Be Vietnam Pro", sans-serif; }
.hide-pinyin rt { visibility: hidden; }
.hide-pinyin ruby:hover rt { visibility: visible; }
.say { border: 0; background: #fbe7ea; border-radius: 50%; width: 28px; height: 28px; cursor: pointer; font-size: .85rem; vertical-align: middle; }
.say:hover { background: #f5c7ce; }

/* Questions */
.q-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.q-num { flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--red); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .9rem; }
.q-prompt { flex: 1; font-size: 1.1rem; font-weight: 500; }
.q-prompt ruby { font-size: 1.3em; }
.q-pts { flex: none; font-size: .8rem; color: var(--muted); font-weight: 600; }
.options { display: grid; gap: 8px; }
.options.inline { grid-template-columns: 1fr 1fr; }
.opt { display: flex; align-items: center; gap: 10px; border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 14px; cursor: pointer; font-size: 1.05rem; }
.opt:hover { border-color: var(--red); }
.opt:has(input:checked) { border-color: var(--red); background: #fdeef0; }
.fill { font-size: 1.15rem; }
.reorder .picked, .reorder .bank { min-height: 52px; border-radius: 10px; padding: 8px; display: flex; flex-wrap: wrap; gap: 8px; }
.reorder .picked { border: 2px dashed var(--red); background: #fffafa; margin-bottom: 10px; }
.reorder .bank { background: #f7f0e5; }
.tok { border: 1px solid var(--line); background: #fff; padding: 6px 14px; border-radius: 8px; font-size: 1.2rem; cursor: pointer; box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.tok:hover { border-color: var(--red); }
.hint { font-size: .8rem; color: var(--muted); margin: 8px 0 0; }
.qe { border-left: 4px solid var(--gold); }
/* Nhiều câu trên một màn hình: lưới nhiều cột, câu dài (sắp xếp, ghi âm) chiếm cả hàng */
.qgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; align-items: start; margin-bottom: 16px; }
.qgrid > .card { margin: 0; }
.qgrid > .card.wide { grid-column: 1 / -1; }
.qgrid .card.q .q-prompt { font-size: 1.05rem; }
.qgrid .card.q .options { gap: 6px; }
.qgrid .card.q .opt { padding: 8px 12px; font-size: 1rem; }
.qgrid .card.q .fill { font-size: 1.05rem; }
/* Tổng quan & nhóm câu hỏi trong trang xem lại bài nộp */
.rv-overview { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin-bottom: 20px; }
.rv-sum { --c: var(--muted); margin: 0; padding: 12px 14px; border-top: 4px solid var(--c); }
.rv-sum.good, .rv-group-head.good { --c: var(--ok); }
.rv-sum.mid, .rv-group-head.mid { --c: var(--warn); }
.rv-sum.bad, .rv-group-head.bad { --c: var(--bad); }
.rv-sum-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.rv-name { font-size: .98rem; line-height: 1.3; }
.rv-pct { font-weight: 700; font-size: 1.15rem; color: var(--c); }
.rv-bar { height: 8px; border-radius: 99px; background: #eee6da; overflow: hidden; margin: 8px 0 6px; }
.rv-bar i { display: block; height: 100%; background: var(--c); border-radius: 99px; }
.rv-sum-meta { display: flex; justify-content: space-between; gap: 8px; font-size: .82rem; color: var(--muted); flex-wrap: wrap; }
.tiles { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.tile { min-width: 26px; height: 26px; padding: 0 4px; border: 0; border-radius: 6px; display: grid; place-items: center; font: inherit; font-size: .78rem; font-weight: 700; color: #fff; background: #bbb; cursor: pointer; transition: transform .12s, box-shadow .12s; }
.tile:hover { transform: translateY(-2px) scale(1.08); box-shadow: 0 3px 8px rgba(0, 0, 0, .25); }
.tile:focus-visible, .rv-sum:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.rv-sum[data-jump] { cursor: pointer; transition: transform .15s, box-shadow .15s; }
.rv-sum[data-jump]:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(80, 50, 20, .16); }
/* Chừa chỗ cho thanh đầu trang dính khi cuộn tới nhóm/câu; nháy nhẹ để dễ thấy */
.rv-group, .r-item { scroll-margin-top: 80px; }
.rv-flash { animation: rv-flash 1.6s ease-out; }
@keyframes rv-flash { 0%, 35% { box-shadow: 0 0 0 4px rgba(217, 164, 65, .75); } 100% { box-shadow: 0 0 0 0 rgba(217, 164, 65, 0); } }
.tile.ok { background: var(--ok); }
.tile.no { background: var(--bad); }
.rv-group { margin-bottom: 22px; }
.rv-sum-top[data-jump] { cursor: pointer; }
/* Phần nhỏ trong thẻ tổng quan (ví dụ Phần 1, Phần 2 của Nghe) */
.rv-subs { display: grid; gap: 6px; margin: 10px 0 2px; }
.rv-sub { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "n p" "m m"; gap: 0 8px; align-items: baseline; text-align: left; font: inherit; cursor: pointer; background: #fbf8f3; border: 1px solid var(--line); border-left: 4px solid var(--c, var(--muted)); border-radius: 8px; padding: 6px 10px; color: var(--ink); }
.rv-sub.good { --c: var(--ok); }
.rv-sub.mid { --c: var(--warn); }
.rv-sub.bad { --c: var(--bad); }
.rv-sub:hover { border-color: var(--red); }
.rv-sub:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.rv-sub-name { grid-area: n; font-weight: 600; font-size: .9rem; }
.rv-sub b { grid-area: p; color: var(--c, var(--muted)); }
.rv-sub small { grid-area: m; color: var(--muted); font-size: .78rem; }
/* Nhóm phần nhỏ bên trong phần lớn */
.rv-subgroup { margin: 0 0 16px; }
.rv-group-head.sub { margin-left: 14px; font-size: .95rem; border-left-width: 4px; }
.rv-group-head.sub h3 { font-size: 1rem; }
.rv-group-head { --c: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 8px 16px; flex-wrap: wrap; padding: 8px 14px; margin-bottom: 12px; background: #fff; border: 1px solid var(--line); border-left: 6px solid var(--c); border-radius: 10px; }
.rv-group-head h3 { margin: 0; font-size: 1.1rem; }
.rv-group-head span { font-size: .88rem; color: var(--muted); }
.rv-group-head b { color: var(--c); }
.qgrid .card.r-item .r-line span { min-width: 90px; }
.qgrid .card.r-item .explain { font-size: .9rem; }

/* Result */
.result-head { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; }
.ring { --c: var(--ok); width: 108px; height: 108px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--c) calc(var(--p) * 1%), #eee 0); flex: none; }
.ring.mid { --c: var(--warn); }
.ring.bad { --c: var(--bad); }
.ring span { width: 80%; height: 80%; border-radius: 50%; background: #fff; display: grid; place-items: center; font-weight: 700; font-size: 1.4rem; }
.score { margin: 0; font-size: 1.05rem; }
.r-item.ok { border-left: 5px solid var(--ok); }
.r-item.no { border-left: 5px solid var(--bad); }
.r-line { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.r-line span { color: var(--muted); min-width: 100px; }
.given-ok { color: var(--ok); }
.given-no { color: var(--bad); }
.explain { margin-top: 10px; padding: 8px 12px; background: #fff7e6; border-radius: 8px; font-size: .95rem; }

/* Toast */
#toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); width: min(92vw, 520px); display: grid; gap: 8px; z-index: 2147483000; pointer-events: none; }
.toast { pointer-events: auto; }
/* Lớp phủ/logo Netlify (Netlify Drawer) ở góc dưới phải */
#netlify-drawer, netlify-drawer, [id*="netlify" i], [class*="netlify" i], [aria-label*="netlify" i], [title*="netlify" i], [src*="netlify" i], [href*="netlify.com" i] { display: none !important; }

/* Ghi âm */
.recorder { display: grid; gap: 10px; }
.rec-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.rec-btn.recording { background: var(--bad); color: #fff; border-color: var(--bad); animation: rec-pulse 1.2s infinite; }
.rec-audio { width: 100%; max-width: 420px; }
@keyframes rec-pulse { 50% { opacity: .7; } }
.r-item.rec { border-left: 4px solid var(--bad); }
.toast { background: #333; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--bad); }

@media (max-width: 700px) {
  .qgrid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .card { padding: 14px; }
  .options.inline { grid-template-columns: 1fr; }
  .result-head { justify-content: center; text-align: center; }
}

/* Embedded HTML exercise */
.embed-frame { width: 100%; height: 80vh; min-height: 520px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; margin-bottom: 16px; }
#html-preview-out { max-height: 280px; overflow: auto; white-space: pre-wrap; }
.html-exercise-page { width: min(100vw - 24px, 1600px); margin-left: 50%; transform: translateX(-50%); }
.html-ex-head { padding-block: 12px; }
.html-exercise-page #gate { max-width: 520px; margin-inline: auto; }
.html-exercise-page #stage { display: grid; gap: 10px; }
.html-exercise-page .embed-frame { height: calc(100vh - 132px); min-height: 640px; border-radius: 8px; }
/* Đang làm bài HTML nhúng: giữ thanh đầu trang, khung bài chiếm toàn bộ phần màn hình còn lại */
body.html-playing { height: 100dvh; min-height: 0; overflow: hidden; }
body.html-playing .site-footer, body.html-playing .html-ex-head, body.html-playing .back { display: none !important; }
body.html-playing .site-header { flex: none; }
body.html-playing .header-in { padding-block: 4px; }
body.html-playing .logo { width: 30px; height: 30px; font-size: 1.05rem; }
body.html-playing main { flex: 1; min-height: 0; padding: 0; width: 100%; max-width: none; }
body.html-playing #app > div,
body.html-playing .html-exercise-page,
body.html-playing .html-exercise-page #stage,
body.html-playing .html-exercise-page #embed-box { height: 100%; }
body.html-playing .html-exercise-page { width: 100%; margin: 0; transform: none; }
body.html-playing .html-exercise-page #stage { display: block; }
body.html-playing .html-exercise-page .embed-frame { width: 100%; height: 100%; min-height: 0; border: 0; border-radius: 0; margin: 0; display: block; }
body.html-playing #embed-status { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 50; max-width: min(92vw, 620px); margin: 0; }
/* Bài học HTML nhúng: cùng kiểu toàn màn hình với bài tập, thêm một thanh mỏng ở trên */
.lesson-bar { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; padding: 6px 12px; margin-bottom: 8px; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.lesson-back { text-decoration: none; font-weight: 500; white-space: nowrap; }
.lesson-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lesson-practice { display: flex; gap: 6px; flex-wrap: wrap; }
.lesson-practice .btn { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lesson-full .embed-frame { height: calc(100vh - 150px); min-height: 520px; }
body.html-playing .lesson-full { height: 100%; display: flex; flex-direction: column; width: 100%; }
body.html-playing .lesson-bar { flex: none; margin: 0; border-width: 0 0 1px; border-radius: 0; }
body.html-playing .lesson-full #embed-box { flex: 1; min-height: 0; }
body.html-playing .lesson-full .embed-frame { width: 100%; height: 100%; min-height: 0; border: 0; border-radius: 0; margin: 0; display: block; }
@media (max-width: 700px) {
  .html-exercise-page { width: calc(100vw - 12px); }
  .html-exercise-page .embed-frame { height: calc(100vh - 116px); min-height: 520px; }
}

/* Media (ảnh, âm thanh) */
.media-img { display: block; max-width: 100%; max-height: 360px; border-radius: 12px; margin: 10px 0; box-shadow: var(--shadow); }
.media-audio { display: block; width: min(100%, 420px); margin: 10px 0; }
.media-missing { opacity: .4; min-height: 32px; }
.q .media-img, .r-item .media-img { margin: 0 0 12px; }

/* Trình soạn bài học */
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px; background: #f9f1e4; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; position: sticky; top: 64px; z-index: 5; }
.toolbar button { border: 1px solid transparent; background: #fff; border-radius: 8px; padding: 5px 11px; font: inherit; font-size: .88rem; cursor: pointer; }
.toolbar button:hover { border-color: var(--red); color: var(--red); }
.toolbar button.accent { background: var(--red); color: #fff; }
.toolbar button.accent:hover { background: var(--red-dark); color: #fff; }
.toolbar .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.toolbar #upload-status { margin-left: auto; }
.split-head { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.split > .prose { margin: 0; max-height: 520px; overflow: auto; }
@media (max-width: 800px) { .split-head { display: none; } }
textarea.drop { outline: 3px dashed var(--red); background: #fff5f6; }
.strip { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip-media { display: flex; align-items: center; gap: 8px; max-width: 220px; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 4px 10px 4px 4px; cursor: pointer; font: inherit; }
.chip-media:hover { border-color: var(--red); }
.chip-media img { width: 36px; height: 36px; object-fit: cover; border-radius: 6px; }
.chip-media span { width: 36px; height: 36px; display: grid; place-items: center; background: #fbe7ea; border-radius: 6px; }
.chip-media em { font-style: normal; font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Trình soạn câu hỏi */
.qe-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; }
.seg { display: inline-flex; background: #f4e8d8; border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg-btn { border: 0; background: transparent; padding: 5px 12px; border-radius: 8px; font: inherit; font-size: .85rem; cursor: pointer; color: var(--muted); }
.seg-btn.on { background: #fff; color: var(--red); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.pts { display: flex; align-items: center; gap: 6px; font-size: .85rem; font-weight: 500; }
.pts input { width: 64px; padding: 5px 8px; }
.qe-head .row-actions { margin-left: auto; }
.attach { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 12px; }
.attach-box { position: relative; display: flex; align-items: center; gap: 8px; }
.attach-box.wide { flex: 1 1 260px; }
.drop-btn { display: flex; align-items: center; gap: 8px; border: 2px dashed var(--line); background: #fffdf9; border-radius: 12px; padding: 10px 16px; font: inherit; font-size: .88rem; color: var(--muted); cursor: pointer; }
.drop-btn span { font-size: 1.2rem; }
.drop-btn:hover { border-color: var(--red); color: var(--red); }
.attach .thumb { width: 96px; height: 72px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.attach .media-audio { margin: 0; flex: 1; width: auto; min-width: 200px; }
.attach .x { border: 0; background: #333; color: #fff; width: 22px; height: 22px; border-radius: 50%; font-size: .7rem; cursor: pointer; }
.attach .thumb + .x { position: absolute; top: -6px; left: 84px; }

/* Tab soạn / xem trước */
.tabs2 { display: inline-flex; background: #f4e8d8; border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 14px; }
.tab2 { border: 0; background: transparent; padding: 8px 18px; border-radius: 9px; font: inherit; font-weight: 500; cursor: pointer; color: var(--muted); }
.tab2.on { background: #fff; color: var(--red); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.toolbar .switch { margin: 0 4px; }
#pv-result { margin-top: 18px; }
