:root {
  --ui-bg: #ffffff;
  --ui-text: #2b2b3a;
  --ui-muted: #6b6b80;
  --ui-line: #ece8f5;
  --accent: #6741d9;
  --accent-soft: #efe9ff;
  --danger: #e03131;
  --stage-bg: #fffdf7;
  --grid: #eee6d3;
  --radius: 14px;
  --font: "Segoe UI", Tahoma, Arial, sans-serif;
  --emoji: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; font-family: var(--font); color: var(--ui-text); background: var(--ui-bg); user-select: none; }
button { font-family: inherit; color: inherit; }
i { font-style: normal; font-family: var(--emoji); }

/* ---------- Thanh công cụ ---------- */
#topbar { position: fixed; inset: 0 0 auto 0; height: 76px; display: flex; align-items: center; gap: 12px; padding: 0 12px; background: var(--ui-bg); border-bottom: 2px solid var(--ui-line); z-index: 20; }
.brand { display: flex; align-items: center; gap: 8px; min-width: 140px; flex: 0 1 220px; }
.logo { width: 40px; height: 40px; }
#docTitle { flex: 1; min-width: 0; font: 700 18px var(--font); border: 2px solid transparent; border-radius: 10px; padding: 6px 8px; background: transparent; color: var(--ui-text); user-select: text; }
#docTitle:hover { border-color: var(--ui-line); }
#docTitle:focus { outline: none; border-color: var(--accent); background: #fff; }
.tools { display: flex; align-items: center; gap: 4px; flex: 1; min-width: 0; overflow: hidden; }
.tools.compact button span { display: none; }
.tools.compact button { min-width: 46px; }
.tools button.ovf, .tools .group.empty { display: none; }
.tools button.drop span::after { content: ' ▾'; font-size: 10px; }
.tools .more-btn i { font-size: 24px; font-weight: 900; letter-spacing: 1px; }
.top-right { display: flex; align-items: center; gap: 8px; flex: none; margin-left: auto; }
.top-right button { border: 0; cursor: pointer; font-family: var(--font); transition: background .15s, transform .1s, box-shadow .15s; }
.top-right button:active { transform: scale(.95); }
.top-right .share-btn { display: flex; align-items: center; gap: 7px; height: 42px; padding: 0 18px 0 14px; border-radius: 99px; background: var(--accent); color: #fff; font-weight: 800; font-size: 14.5px; box-shadow: 0 3px 10px rgba(103, 65, 217, .28); }
.top-right .share-btn i { font-style: normal; font-size: 18px; }
.top-right .share-btn:hover { box-shadow: 0 5px 16px rgba(103, 65, 217, .38); filter: brightness(1.06); }
.top-right .share-btn.on { box-shadow: 0 0 0 3px var(--accent-soft); }
.top-right .acc-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 56px; height: 56px; padding: 4px; border-radius: 12px; background: transparent; }
.top-right .acc-btn i { font-style: normal; font-size: 24px; line-height: 1; }
.top-right .acc-btn span { font-size: 11.5px; font-weight: 700; color: var(--ui-muted); max-width: 72px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-right .acc-btn:hover, .top-right .acc-btn.on { background: var(--accent-soft); }
.top-right .acc-btn.is-pro { box-shadow: inset 0 0 0 2px #fcc419; background: #fff9db; }
@media (max-width: 960px) { .top-right .share-btn span { display: none; } .top-right .share-btn { padding: 0 13px; } }
.menu-h { font-size: 11.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--ui-muted); padding: 6px 12px 2px; }
.group { display: flex; gap: 2px; padding: 0 4px; border-right: 2px solid var(--ui-line); }
.group:last-child { border-right: 0; }
.tools button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 60px; height: 62px; padding: 4px 6px; border: 0; border-radius: 12px; background: transparent; cursor: pointer; transition: background .15s, transform .1s; }
.tools button i { font-size: 24px; line-height: 1; }
.tools button span { font-size: 12px; font-weight: 600; white-space: nowrap; color: var(--ui-muted); }
.tools button:hover { background: var(--accent-soft); }
.tools button:hover span { color: var(--accent); }
.tools button:active { transform: scale(.94); }
.tools button.hot { background: #e6fcf5; }
.tools button.hot:hover { background: #c3fae8; }
.tools button:disabled { opacity: .35; cursor: default; background: transparent; }
.tools button.on { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }

@media (max-width: 1180px) { .tools button { height: 54px; } .tools button i { font-size: 22px; } .tools button span { font-size: 11px; } #topbar { height: 66px; } #stage { top: 66px !important; } }

/* ---------- Vùng vẽ ---------- */
#stage { position: fixed; inset: 76px 0 0 0; overflow: hidden; background-color: var(--stage-bg); background-image: radial-gradient(var(--grid) 1.6px, transparent 1.6px); background-size: 28px 28px; cursor: grab; touch-action: none; outline: none; }
#stage.panning { cursor: grabbing; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#links { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
#nodes { position: absolute; left: 0; top: 0; }

.mnode { position: absolute; cursor: pointer; transition: box-shadow .15s, filter .15s; }
.mnode > * { position: absolute; pointer-events: none; }
.mnode.lv0 { box-shadow: 0 6px 18px rgba(0, 0, 0, .18); }
.mnode.lv1 { box-shadow: 0 4px 10px rgba(0, 0, 0, .13); }
.mnode:hover { filter: brightness(1.04); box-shadow: 0 0 0 4px rgba(103, 65, 217, .15), 0 4px 12px rgba(0, 0, 0, .12); }
.mnode.sel { box-shadow: 0 0 0 3px #fff, 0 0 0 6px #4dabf7, 0 6px 16px rgba(0, 0, 0, .2); z-index: 2; }
.mnode.shape-underline.sel, .mnode.shape-underline:hover { box-shadow: none; outline: 3px dashed #4dabf7; outline-offset: 3px; }
.mtext { white-space: pre; text-align: center; }
.memo { font-family: var(--emoji); white-space: nowrap; }
.mnote { font-family: var(--emoji); }
.mimg { border-radius: 8px; object-fit: cover; }
.mnode.dragging { opacity: .9; z-index: 10; box-shadow: 0 12px 28px rgba(0, 0, 0, .3); cursor: grabbing; transition: none; }
.mnode.ghost { opacity: .35; }
#links .drop-link { stroke-width: 3.5; stroke-dasharray: 9 7; stroke-linecap: round; opacity: .9; animation: dropdash .6s linear infinite; }
#links .snap-guide { stroke: #e64980; stroke-width: 1.5; stroke-dasharray: 4 4; }
@keyframes dropdash { to { stroke-dashoffset: -16; } }
@media (prefers-reduced-motion: reduce) { #links .drop-link { animation: none; } }
.mnode.drop-child { box-shadow: 0 0 0 4px #fff, 0 0 0 8px #40c057 !important; }
.mnode.drop-before::before, .mnode.drop-after::after { content: ""; position: absolute; left: -6px; right: -6px; height: 6px; border-radius: 3px; background: #40c057; }
.mnode.drop-before::before { top: -12px; }
.mnode.drop-after::after { bottom: -12px; }
.mnode.drop-before.horiz::before, .mnode.drop-after.horiz::after { top: -6px; bottom: -6px; left: auto; right: auto; width: 6px; height: auto; }
.mnode.drop-before.horiz::before { left: -12px; }
.mnode.drop-after.horiz::after { right: -12px; }

/* đang sửa chữ */
.mnode.editing { width: max-content !important; height: auto !important; display: flex; align-items: center; justify-content: center; gap: 8px; cursor: text; z-index: 5; box-shadow: 0 0 0 3px #fff, 0 0 0 6px #fab005 !important; }
.mnode.editing > * { position: static !important; }
.mnode.editing .mimg { display: none; }
.mnode.editing .mtext { pointer-events: auto; white-space: pre-wrap; word-break: break-word; min-width: 30px; outline: none; user-select: text; caret-color: currentColor; width: auto !important; }

.mtoggle { position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%; background: #fff; border: 2px solid; font: 700 11px/18px var(--font); text-align: center; cursor: pointer; z-index: 3; opacity: 0; transition: opacity .15s, transform .1s; }
.mtoggle.closed, .mtoggle.vis { opacity: 1; }
#nodes:hover .mtoggle { opacity: .9; }
.mtoggle { transform: scale(var(--inv, 1)); }
.mtoggle:hover { transform: scale(calc(var(--inv, 1) * 1.2)); }
.madd { position: absolute; width: 34px; height: 34px; margin: -17px 0 0 -17px; transform: scale(var(--inv, 1)); border-radius: 50%; background: #40c057; color: #fff; font: 700 24px/32px var(--font); text-align: center; cursor: pointer; box-shadow: 0 3px 8px rgba(0, 0, 0, .25); z-index: 4; animation: pop .2s ease-out; }
.madd:hover { background: #2f9e44; transform: scale(calc(var(--inv, 1) * 1.12)); }
@keyframes pop { from { transform: scale(.3); opacity: 0; } }

/* ---------- Thanh phóng to, gợi ý ---------- */
#zoombar { position: fixed; right: 16px; bottom: 16px; display: flex; align-items: center; gap: 4px; padding: 6px; background: var(--ui-bg); border-radius: 999px; box-shadow: 0 4px 16px rgba(0, 0, 0, .15); z-index: 15; }
#zoombar button { border: 0; background: var(--accent-soft); border-radius: 999px; height: 36px; min-width: 36px; padding: 0 12px; cursor: pointer; font: 600 14px var(--font); font-family: var(--font), var(--emoji); }
#zoombar button:hover { background: #ddd1ff; }
#zoomLabel { min-width: 52px; text-align: center; font-weight: 700; font-size: 14px; }
#hint { position: fixed; left: 16px; bottom: 16px; max-width: calc(100% - 420px); padding: 8px 14px; background: rgba(255, 255, 255, .92); border-radius: 999px; box-shadow: 0 3px 12px rgba(0, 0, 0, .1); font-size: 13.5px; color: var(--ui-muted); z-index: 15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#hint b { color: var(--accent); background: var(--accent-soft); padding: 1px 7px; border-radius: 6px; font-weight: 700; }
#status { position: fixed; right: 16px; bottom: 70px; font-size: 12px; color: var(--ui-muted); background: rgba(255, 255, 255, .85); padding: 3px 10px; border-radius: 999px; z-index: 15; }
#status:empty { display: none; }

/* ---------- Popover ---------- */
#popover { position: fixed; z-index: 40; background: var(--ui-bg); border-radius: 16px; box-shadow: 0 10px 40px rgba(30, 20, 60, .25); padding: 14px; max-width: min(440px, calc(100vw - 20px)); max-height: calc(100vh - 100px); overflow: auto; animation: pop .15s ease-out; user-select: none; }
.pop-title { font-weight: 800; font-size: 14px; margin: 2px 2px 8px; color: var(--ui-muted); }
.pop-title:not(:first-child) { margin-top: 14px; }
.swatches { display: grid; grid-template-columns: repeat(9, 34px); gap: 7px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1.5px #d0d0de; cursor: pointer; transition: transform .1s; }
.swatch:hover { transform: scale(1.15); }
.swatch.on { box-shadow: 0 0 0 3px var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 2px solid var(--ui-line); background: #fff; border-radius: 12px; padding: 7px 12px; font: 600 14px var(--font); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.chip:hover { border-color: #c5b6f6; background: var(--accent-soft); }
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.chip i { font-size: 18px; }
.shape-demo { display: inline-block; width: 30px; height: 18px; border: 2.5px solid currentColor; }
.emoji-tabs { display: flex; gap: 4px; margin-bottom: 8px; flex-wrap: wrap; }
.emoji-tabs button { border: 0; background: transparent; font-size: 22px; padding: 4px 6px; border-radius: 10px; cursor: pointer; font-family: var(--emoji); }
.emoji-tabs button.on { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 44px); gap: 4px; }
.emoji-grid button { width: 44px; height: 44px; border: 0; border-radius: 10px; background: transparent; font-size: 28px; cursor: pointer; font-family: var(--emoji); transition: transform .1s; }
.emoji-grid button:hover { background: #fff3bf; transform: scale(1.2); }
.menu { display: flex; flex-direction: column; min-width: 230px; }
.menu button { display: flex; align-items: center; gap: 10px; border: 0; background: transparent; padding: 9px 12px; border-radius: 10px; font: 600 14.5px var(--font); text-align: left; cursor: pointer; }
.menu button i { font-size: 18px; width: 24px; text-align: center; }
.menu button:hover { background: var(--accent-soft); color: var(--accent); }
.menu button.danger:hover { background: #fff0f0; color: var(--danger); }
.menu kbd { margin-left: auto; font: 12px var(--font); color: var(--ui-muted); background: #f3f1f8; padding: 1px 6px; border-radius: 5px; }
.menu hr { border: 0; border-top: 1.5px solid var(--ui-line); margin: 5px 4px; }
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.card-opt { border: 2px solid var(--ui-line); background: #fff; border-radius: 14px; padding: 10px 6px; cursor: pointer; text-align: center; font: 600 13px var(--font); }
.card-opt:hover { border-color: #c5b6f6; background: var(--accent-soft); }
.card-opt.on { border-color: var(--accent); background: var(--accent-soft); }
.card-opt svg { display: block; margin: 0 auto 6px; }
.theme-dot { width: 100%; height: 44px; border-radius: 10px; margin-bottom: 6px; display: flex; align-items: center; justify-content: center; gap: 4px; }
.theme-dot span { width: 12px; height: 12px; border-radius: 50%; }

/* ---------- Hộp thoại ---------- */
#modal { position: fixed; inset: 0; z-index: 50; background: rgba(35, 25, 70, .45); display: flex; align-items: center; justify-content: center; padding: 20px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal-card { background: var(--ui-bg); border-radius: 24px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); width: min(980px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column; overflow: hidden; animation: pop .2s ease-out; }
.modal-card.small { width: min(520px, 100%); }
.m-head { display: flex; align-items: center; gap: 12px; padding: 18px 22px 10px; }
.m-head h2 { margin: 0; font-size: 22px; flex: 1; }
.m-close { border: 0; background: #f3f1f8; width: 38px; height: 38px; border-radius: 50%; font-size: 18px; cursor: pointer; }
.m-close:hover { background: #ffe3e3; }
.m-body { padding: 8px 22px 18px; overflow: auto; }
.m-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 12px 22px 18px; border-top: 1.5px solid var(--ui-line); flex-wrap: wrap; }
.btn { border: 0; border-radius: 12px; padding: 10px 18px; font: 700 15px var(--font); cursor: pointer; background: #f1eef8; display: inline-flex; align-items: center; gap: 8px; }
.btn:hover { background: #e5def7; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: #5530c2; }
.btn.danger { background: #fff0f0; color: var(--danger); }
.btn i { font-size: 18px; }
textarea.field, input.field { width: 100%; border: 2px solid var(--ui-line); border-radius: 12px; padding: 10px 12px; font: 16px var(--font); resize: vertical; user-select: text; }
textarea.field:focus, input.field:focus { outline: none; border-color: var(--accent); }

.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 12px; }
.tpl { border: 0; border-radius: 18px; padding: 16px 12px 14px; cursor: pointer; text-align: center; transition: transform .12s, box-shadow .12s; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.tpl:hover { transform: translateY(-4px) scale(1.02); box-shadow: 0 10px 22px rgba(0, 0, 0, .14); }
.tpl i { font-size: 42px; line-height: 1.1; }
.tpl b { font-size: 15px; }
.tpl small { font-size: 12px; color: #555; }
.start-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.start-actions .btn { padding: 12px 18px; }
.btn.continue { background: #fff3bf; }
.btn.continue:hover { background: #ffec99; }
.recent { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 16px; }
.recent .chip { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.section-title { font-weight: 800; color: var(--ui-muted); font-size: 14px; margin: 8px 0 10px; }

.hist-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.hist-item { border: 2px solid var(--ui-line); border-radius: 16px; overflow: hidden; display: flex; flex-direction: column; background: #fff; }
.hist-item img, .hist-item .noimg { width: 100%; height: 120px; object-fit: contain; background: #faf8ff; display: flex; align-items: center; justify-content: center; font-size: 40px; border-bottom: 1.5px solid var(--ui-line); }
.hist-item .meta { padding: 8px 10px 4px; }
.hist-item .meta b { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-item .meta small { color: var(--ui-muted); font-size: 12px; }
.hist-item .acts { display: flex; gap: 6px; padding: 6px 10px 10px; }
.hist-item .acts .btn { padding: 6px 10px; font-size: 13px; flex: 1; justify-content: center; }
.empty { text-align: center; color: var(--ui-muted); padding: 30px; font-size: 15px; }

.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 26px; }
.help-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--ui-line); font-size: 14.5px; }
.help-row kbd { min-width: 92px; text-align: center; font: 700 12.5px var(--font); background: var(--accent-soft); color: var(--accent); padding: 4px 8px; border-radius: 8px; }
.tips { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tip { background: #f8f6ff; border-radius: 14px; padding: 12px 14px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
.tip i { font-size: 28px; }

#toast { position: fixed; left: 50%; top: 92px; transform: translateX(-50%) translateY(-20px); background: #2b2b3a; color: #fff; padding: 10px 20px; border-radius: 999px; font-weight: 600; font-size: 14.5px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 60; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); }
#dropzone { position: fixed; inset: 0; z-index: 70; background: rgba(103, 65, 217, .2); display: flex; align-items: center; justify-content: center; pointer-events: none; }
#dropzone div { background: #fff; padding: 26px 40px; border-radius: 24px; font-size: 22px; font-weight: 800; border: 4px dashed var(--accent); }
[hidden] { display: none !important; }

/* ======================================================================
   Điện thoại & máy tính bảng nhỏ (PWA): bố cục gọn, thanh công cụ dưới cùng
   ====================================================================== */
#mobilebar, .m-only { display: none; }
.lang-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; min-width: 260px; }
.lang-list .chip { justify-content: center; padding: 12px; font-size: 15px; }

@media (max-width: 760px) {
  #topbar { height: calc(56px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 10px 0; gap: 8px; }
  .tools, .top-right { display: none; }
  .brand { flex: 1; min-width: 0; }
  .logo { width: 32px; height: 32px; }
  #docTitle { font-size: 16px; padding: 6px; }
  .m-only { display: flex; }
  .top-btn { border: 0; background: var(--accent-soft); width: 42px; height: 42px; border-radius: 12px; align-items: center; justify-content: center; font-size: 20px; cursor: pointer; }
  #stage, #stage[style] { top: calc(56px + env(safe-area-inset-top)) !important; bottom: calc(64px + env(safe-area-inset-bottom)); }

  #mobilebar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; height: calc(64px + env(safe-area-inset-bottom)); padding: 4px 4px env(safe-area-inset-bottom); background: var(--ui-bg); border-top: 2px solid var(--ui-line); box-shadow: 0 -4px 14px rgba(0, 0, 0, .06); }
  #mobilebar button { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 0; background: transparent; border-radius: 12px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
  #mobilebar button i { font-size: 22px; line-height: 1; flex: none; }
  #mobilebar button span { font-size: 10.5px; line-height: 1.15; font-weight: 700; color: var(--ui-muted); text-align: center; max-width: 100%; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
  #mobilebar button:active { background: var(--accent-soft); }
  #mobilebar button.hot i { background: #40c057; color: #fff; border-radius: 50%; width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; font-size: 18px; }
  #mobilebar button:disabled { opacity: .35; }

  #hint, #status { display: none; }
  #zoombar { right: 10px; bottom: calc(74px + env(safe-area-inset-bottom)); padding: 4px; }
  #zoombar button { height: 34px; min-width: 34px; padding: 0 8px; }
  #zoombar button[data-cmd="fit"] span { display: none; }
  #zoomLabel { min-width: 44px; font-size: 13px; }
  #toast { top: calc(66px + env(safe-area-inset-top)); max-width: calc(100% - 24px); white-space: normal; text-align: center; border-radius: 16px; }

  /* bảng chọn trượt lên từ dưới */
  #popover.sheet { left: 0 !important; right: 0; top: auto !important; bottom: 0; max-width: none; width: 100%; max-height: 72vh; border-radius: 22px 22px 0 0; padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); animation: sheet-up .2s ease-out; }
  #popover.sheet::before { content: ""; display: block; width: 44px; height: 5px; border-radius: 3px; background: #d9d4e8; margin: 0 auto 10px; }
  @keyframes sheet-up { from { transform: translateY(40%); opacity: .4; } }
  #popover.sheet .swatches { grid-template-columns: repeat(auto-fill, 38px); justify-content: space-between; }
  #popover.sheet .swatch { width: 38px; height: 38px; }
  #popover.sheet .emoji-grid { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); }
  #popover.sheet .menu { min-width: 0; }
  #popover.sheet .menu button { padding: 12px; font-size: 15.5px; }
  #popover.sheet .menu kbd { display: none; }
  #popover.sheet .lang-list { min-width: 0; }

  /* hộp thoại toàn màn hình */
  #modal { padding: 0; align-items: flex-end; }
  .modal-card, .modal-card.small { width: 100%; max-height: calc(100% - 24px - env(safe-area-inset-top)); border-radius: 22px 22px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .m-head { padding: 14px 16px 6px; }
  .m-head h2 { font-size: 18px; }
  .m-head .btn { padding: 8px 10px; font-size: 13px; }
  .m-body { padding: 6px 16px 16px; }
  .tpl-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tpl { padding: 12px 8px; border-radius: 16px; }
  .tpl i { font-size: 34px; }
  .tpl b { font-size: 14px; }
  .hist-list { grid-template-columns: 1fr 1fr; gap: 8px; }
  .hist-item img, .hist-item .noimg { height: 90px; }
  .hist-item .acts .btn { font-size: 12px; padding: 6px; }
  .help-grid { grid-template-columns: 1fr; }
  .desktop-only { display: none !important; }
  .tips { grid-template-columns: 1fr; }
}

/* ---------- Trạng thái hệ thống do quản trị viên đặt ---------- */
#sysbanner { position: fixed; left: 50%; top: 88px; transform: translateX(-50%); z-index: 38; max-width: min(720px, calc(100% - 24px)); display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 18px; border-radius: 14px; font-weight: 600; font-size: 14.5px; box-shadow: 0 8px 24px rgba(0, 0, 0, .15); background: #6741d9; color: #fff; }
#sysbanner.lv-success { background: #2b8a3e; }
#sysbanner.lv-warning { background: #ffe066; color: #5c3c00; }
#sysbanner button { border: 0; background: rgba(255, 255, 255, .25); color: inherit; width: 28px; height: 28px; border-radius: 50%; cursor: pointer; flex: none; }
#sysblock { position: fixed; inset: 0; z-index: 100; background: rgba(255, 253, 247, .97); display: grid; place-items: center; padding: 24px; }
.sysblock-card { max-width: 440px; text-align: center; font-size: 18px; font-weight: 600; color: var(--ui-text); }
.sysblock-ic { font-size: 64px; font-family: var(--emoji); margin-bottom: 10px; }
@media (max-width: 760px) { #sysbanner { top: calc(64px + env(safe-area-inset-top)); font-size: 13.5px; } }

/* ======================================================================
   Hộp thoại xuất tệp
   ====================================================================== */
.x-body { display: grid; grid-template-columns: 250px 1fr; gap: 20px; }
.x-formats { display: flex; flex-direction: column; gap: 8px; }
.x-fmt { display: grid; grid-template-columns: 40px 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center; text-align: left; border: 2px solid var(--ui-line); background: #fff; border-radius: 14px; padding: 10px 12px; cursor: pointer; font-family: var(--font); }
.x-fmt i { grid-row: span 2; font-size: 28px; }
.x-fmt b { font-size: 15px; }
.x-fmt small { color: var(--ui-muted); font-size: 12.5px; }
.x-fmt:hover { border-color: #c5b6f6; background: var(--accent-soft); }
.x-fmt.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 3px #e5dbff; }
.x-formats .chips .chip { font-size: 13px; padding: 6px 10px; }
.x-main { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.x-preview { display: flex; flex-direction: column; align-items: center; gap: 6px; background: #f3f1f8; border-radius: 16px; padding: 16px; }
.x-page { width: 100%; max-height: 300px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.x-page img { max-width: 100%; max-height: 300px; object-fit: contain; display: block; }
.x-page.paper, .x-page.slide { width: auto; height: 300px; max-width: 100%; padding: 4%; box-shadow: 0 6px 20px rgba(40, 30, 80, .18); border-radius: 4px; }
.x-page.paper img, .x-page.slide img { max-height: 100%; }
.x-page.slide { padding: 3%; border-radius: 8px; }
.x-page.checker { background-color: #fff !important; background-image: linear-gradient(45deg, #e9e6f0 25%, transparent 25%), linear-gradient(-45deg, #e9e6f0 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #e9e6f0 75%), linear-gradient(-45deg, transparent 75%, #e9e6f0 75%); background-size: 16px 16px; background-position: 0 0, 0 8px, 8px -8px, -8px 0; border-radius: 8px; }
.x-info { color: var(--ui-muted); font-weight: 600; }
.x-opts .pop-title:first-child { margin-top: 0; }
.x-check { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-weight: 600; font-size: 14px; cursor: pointer; }
.x-check input { width: 18px; height: 18px; accent-color: var(--accent); }
.x-sheet { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0 26px; }
.x-sheet .chips { display: contents; }

/* ======================================================================
   Chế độ học thuộc lòng
   ====================================================================== */
body.quiz-on .tools button:is([data-cmd="save"], [data-cmd="undo"], [data-cmd="redo"], [data-need], [data-cmd="layout"]) { opacity: .3; pointer-events: none; }
#quizbar { position: fixed; top: 86px; left: 50%; transform: translateX(-50%); z-index: 30; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center; max-width: calc(100% - 24px); background: #fff; border-radius: 18px; padding: 8px 12px; box-shadow: 0 8px 26px rgba(60, 40, 120, .2); border: 2px solid #e5dbff; }
.qb-title { font-size: 15px; white-space: nowrap; }
.qb-levels { display: flex; gap: 4px; flex-wrap: wrap; }
.qb-levels .chip { padding: 5px 10px; font-size: 13px; }
.qb-hint { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.qb-hint input { accent-color: var(--accent); }
.qb-progress { font-weight: 800; font-size: 14px; background: #f8f6ff; padding: 5px 12px; border-radius: 999px; white-space: nowrap; }
.qb-acts { display: flex; gap: 6px; }
.qb-acts .btn { padding: 7px 12px; font-size: 13.5px; }

.mnode.quiz-hidden { cursor: pointer; background-image: repeating-linear-gradient(-45deg, rgba(255, 255, 255, .28) 0 7px, transparent 7px 14px) !important; animation: q-wiggle 2.8s ease-in-out infinite; }
.mnode.quiz-hidden:nth-child(3n) { animation-delay: .7s; }
.mnode.quiz-hidden:nth-child(3n+1) { animation-delay: 1.4s; }
.mnode.quiz-hidden > * { visibility: hidden; }
.mnode.quiz-hidden.q-hint > .memo { visibility: visible; }
.mnode.quiz-hidden:not(.q-hint)::after { content: "❓"; position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--emoji); font-size: min(26px, 70%); }
.mnode.quiz-hidden:hover { filter: brightness(1.08); transform: scale(1.05); }
@keyframes q-wiggle { 0%, 88%, 100% { transform: rotate(0); } 92% { transform: rotate(-2deg); } 96% { transform: rotate(2deg); } }
.mnode.q-ok { box-shadow: 0 0 0 3px #fff, 0 0 0 6px #40c057 !important; }
.mnode.q-bad { box-shadow: 0 0 0 3px #fff, 0 0 0 6px #fd7e14 !important; }
.mnode.q-ok::after, .mnode.q-bad::after { position: absolute; right: -12px; top: -12px; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: #fff; font-size: 13px; font-family: var(--emoji); box-shadow: 0 2px 6px rgba(0, 0, 0, .2); }
.mnode.q-ok::after { content: "✅"; }
.mnode.q-bad::after { content: "🔁"; }
.mnode.q-seen { box-shadow: 0 0 0 3px #fff, 0 0 0 6px #74c0fc !important; }
.mnode.q-flip { animation: q-flip .55s ease-out; }
@keyframes q-flip { 0% { transform: perspective(600px) rotateY(90deg); } 100% { transform: perspective(600px) rotateY(0); } }

.q-card { width: 300px; max-width: 100%; display: flex; flex-direction: column; gap: 10px; }
.q-row { display: flex; gap: 8px; }
.q-row .field { flex: 1; min-width: 0; padding: 9px 12px; }
.q-flipbtn { justify-content: center; }
.q-out { display: flex; flex-direction: column; gap: 8px; }
.q-out .q-row .btn { flex: 1; justify-content: center; }
.q-verdict { font-weight: 800; font-size: 16px; color: #e8590c; }
.q-verdict.ok { color: #2b8a3e; font-size: 20px; text-align: center; }
.q-answer { display: flex; align-items: center; gap: 10px; background: #fff9db; border: 2px dashed #fcc419; border-radius: 14px; padding: 10px 14px; font-size: 17px; font-weight: 700; white-space: pre-wrap; }
.q-answer i { font-size: 26px; }
.q-yes.primary { background: #2f9e44; }
.q-result { text-align: center; padding: 26px 22px 22px; }
.q-result h2 { margin: 6px 0; font-size: 26px; }
.q-stars { font-size: 46px; font-family: var(--emoji); letter-spacing: 6px; }
.q-stars span { display: inline-block; filter: grayscale(1); opacity: .3; }
.q-stars span.on { filter: none; opacity: 1; animation: q-star .5s cubic-bezier(.3, 1.8, .5, 1) both; }
@keyframes q-star { from { transform: scale(0) rotate(-40deg); } }
.q-score { font-size: 20px; font-weight: 800; margin: 4px 0; }
.q-result-acts { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.q-result-acts .btn { justify-content: center; padding: 12px; }

@media (max-width: 760px) {
  .x-body { grid-template-columns: 1fr; }
  .x-formats { display: grid; grid-template-columns: 1fr 1fr; }
  .x-formats .pop-title, .x-formats .chips { grid-column: 1 / -1; }
  .x-fmt { grid-template-columns: 1fr; text-align: center; justify-items: center; padding: 10px 6px; }
  .x-fmt i { grid-row: auto; }
  .x-page.paper, .x-page.slide { height: 200px; }
  .x-page img { max-height: 200px; }
  #quizbar { top: calc(62px + env(safe-area-inset-top)); left: 8px; right: 8px; transform: none; max-width: none; gap: 6px; padding: 8px; border-radius: 14px; }
  .qb-acts { width: 100%; }
  .qb-acts .btn { flex: 1; justify-content: center; }
  .qb-title, .qb-hint { display: none; }
  .qb-levels .chip { padding: 4px 8px; font-size: 12px; }
  .qb-acts .btn { padding: 6px 9px; font-size: 12.5px; }
  .q-card { width: 100%; }
}

/* ================= Thư viện mind map ================= */
.tools button.lib-btn { background: #fff4e6; }
.tools button.lib-btn:hover { background: #ffe8cc; }
.btn.lib-start { background: #fff4e6; }
.btn.lib-start:hover { background: #ffe8cc; }
.modal-card.lib-modal { width: min(1180px, 100%); height: min(860px, calc(100vh - 40px)); }
.lib-modal .lib-body { flex: 1; min-height: 0; padding-bottom: 22px; }
.lib-head { flex-wrap: wrap; border-bottom: 1.5px solid var(--ui-line); padding-bottom: 12px; }
.lib-head h2 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-account { display: flex; align-items: center; gap: 8px; }
.lib-me { font-weight: 700; color: var(--accent); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-modal .btn.small { padding: 6px 12px; font-size: 13.5px; border-radius: 10px; }
.lib-modal .btn.ghost { background: transparent; box-shadow: inset 0 0 0 2px var(--ui-line); }
.lib-modal .btn.ghost:hover { background: #f8f6fd; }
.lib-modal .btn.on { background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
.lib-modal .btn:disabled { opacity: .5; cursor: default; }
.lib-tabs { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 4px 0 14px; position: sticky; top: -8px; background: var(--ui-bg); padding: 8px 0; z-index: 1; }
.lib-tabs .chip { font-size: 15px; padding: 9px 16px; }
.lib-spacer { flex: 1; }
.lib-filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.lib-filters input { flex: 1 1 260px; }
.lib-modal .field { border: 2px solid var(--ui-line); border-radius: 12px; padding: 9px 12px; font: 15px var(--font); background: #fff; color: var(--ui-text); user-select: text; min-width: 0; }
.lib-modal .field:focus { outline: none; border-color: var(--accent); }
.lib-cats { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.lib-cats .chip { padding: 5px 11px; font-size: 13px; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.lib-grid > .empty { grid-column: 1 / -1; }
.lib-card { border: 2px solid var(--ui-line); background: #fff; border-radius: 18px; padding: 0; overflow: hidden; cursor: pointer; text-align: left; display: flex; flex-direction: column; transition: transform .12s, box-shadow .12s, border-color .12s; font-family: inherit; }
.lib-card:hover { transform: translateY(-3px); box-shadow: 0 10px 22px rgba(0, 0, 0, .1); border-color: #d6ccf6; }
.lib-thumb { position: relative; display: flex; align-items: center; justify-content: center; aspect-ratio: 16 / 10; background: var(--stage-bg); border-bottom: 1.5px solid var(--ui-line); }
.lib-thumb { overflow: hidden; }
.lib-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.lib-thumb i { font-size: 44px; }
.lib-badge { position: absolute; top: 8px; left: 8px; background: #fff3bf; color: #8a5a00; font-size: 12px; font-weight: 800; padding: 3px 9px; border-radius: 999px; }
.lib-lock { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 40px; background: rgba(255, 255, 255, .55); font-family: var(--emoji); }
.lib-card.locked img { filter: blur(2px) grayscale(.4); }
.lib-info { display: grid; gap: 3px; padding: 10px 12px 12px; min-width: 0; }
.lib-info b { font-size: 15.5px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lib-info small { color: var(--ui-muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-stats { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; font-size: 13px; color: var(--ui-muted); font-weight: 600; }
.lib-stats.big { font-size: 15px; gap: 18px; }
.lib-tag { display: inline-block; font-size: 12px; font-weight: 800; padding: 3px 9px; border-radius: 999px; background: #f1eef8; color: var(--ui-muted); margin: 0; }
.lib-tag.st-pending, .lib-tag.or-pending { background: #fff3bf; color: #8a5a00; }
.lib-tag.st-hidden, .lib-tag.or-cancelled { background: #fff0f0; color: var(--danger); }
.lib-tag.or-paid { background: #ebfbee; color: #2b8a3e; }
.lib-more { text-align: center; margin-top: 16px; }
.lib-loading { padding: 40px; text-align: center; color: var(--ui-muted); grid-column: 1 / -1; }
.lib-detail { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(280px, 1fr); gap: 22px; align-items: start; }
.lib-preview { background: var(--stage-bg); border: 2px solid var(--ui-line); border-radius: 18px; display: flex; align-items: center; justify-content: center; min-height: 260px; overflow: hidden; }
.lib-preview img { width: 100%; max-height: 560px; object-fit: contain; display: block; }
.lib-preview i { font-size: 64px; }
.lib-preview.small { min-height: 180px; }
.lib-side h3 { margin: 0 0 6px; font-size: 22px; line-height: 1.25; }
.lib-meta { color: var(--ui-muted); margin: 0 0 10px; font-size: 14px; }
.lib-desc { white-space: pre-line; margin: 0 0 12px; line-height: 1.5; user-select: text; }
.lib-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; }
.lib-note { font-size: 13px; color: var(--ui-muted); margin: 4px 0; }
.lib-warn { background: #fff9db; border-radius: 12px; padding: 10px 12px; font-size: 14px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.lib-ok { background: #ebfbee; color: #2b8a3e; border-radius: 12px; padding: 10px 12px; font-weight: 600; }
.lib-form { display: grid; gap: 12px; }
.lib-form.narrow { max-width: 440px; margin: 0 auto; }
.lib-form label { display: grid; gap: 6px; font-weight: 700; font-size: 14px; }
.lib-form label.lib-check { display: flex; gap: 8px; align-items: flex-start; font-weight: 600; }
.lib-form label.lib-check input { margin-top: 3px; width: 18px; height: 18px; flex: none; }
.lib-share-form { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 22px; align-items: start; }
.lib-share-form > div { display: grid; gap: 12px; }
.lib-radios { display: grid; gap: 6px; }
.lib-radios label { display: flex; gap: 8px; font-weight: 600; align-items: center; }
.lib-rules { background: #f8f6fd; border-radius: 12px; padding: 8px 12px; font-size: 13.5px; }
.lib-rules summary { font-weight: 700; cursor: pointer; }
.lib-rules p { margin: 6px 0 0; color: var(--ui-muted); line-height: 1.5; }
.lib-link { background: none; border: 0; color: var(--accent); font: 600 14px var(--font); cursor: pointer; padding: 4px; justify-self: center; }
.lib-intro { display: flex; gap: 14px; align-items: center; justify-content: space-between; flex-wrap: wrap; background: #f8f6fd; border-radius: 16px; padding: 12px 16px; margin-bottom: 16px; }
.lib-intro p { margin: 0; flex: 1 1 320px; color: var(--ui-muted); }
.lib-grid.libs { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.lib-lib { border: 2px solid var(--ui-line); border-radius: 18px; background: #fff; overflow: hidden; cursor: pointer; text-align: left; display: flex; flex-direction: column; padding: 0; font-family: inherit; transition: transform .12s, box-shadow .12s; }
.lib-lib:hover { transform: translateY(-3px); box-shadow: 0 10px 22px rgba(0, 0, 0, .1); }
.lib-cover { display: flex; align-items: center; justify-content: center; height: 96px; background: color-mix(in srgb, var(--c, #6741d9) 16%, #fff); }
.lib-cover i { font-size: 48px; }
.lib-desc2 { font-size: 13px; color: var(--ui-muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lib-price { font-weight: 800; color: var(--accent); margin-top: 4px; }
.lib-price.free { color: #2b8a3e; }
.lib-libhead { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 18px; margin-bottom: 18px; align-items: start; }
.lib-libhead .lib-cover { height: 120px; border-radius: 22px; }
.lib-libhead h3 { margin: 0 0 6px; font-size: 22px; }
.lib-pay { display: grid; grid-template-columns: minmax(0, 300px) minmax(0, 1fr); gap: 24px; align-items: start; }
.pay-qr { width: 100%; border-radius: 16px; border: 2px solid var(--ui-line); background: #fff; }
.pay-info { display: grid; gap: 8px; }
.pay-info p { margin: 0; }
.pay-row { display: grid; grid-template-columns: 150px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 12px; background: #f8f6fd; border-radius: 12px; }
.pay-row span { color: var(--ui-muted); font-size: 14px; }
.pay-row b { overflow-wrap: anywhere; user-select: text; }
.pay-row:not(:has(button)) { grid-template-columns: 150px minmax(0, 1fr); }
.mono { font-family: Consolas, "Courier New", monospace; letter-spacing: .03em; }
.code-input { font: 700 22px Consolas, monospace !important; text-align: center; letter-spacing: .12em; text-transform: uppercase; }
.lib-orders { display: grid; gap: 8px; }
.order-row { display: grid; grid-template-columns: 110px minmax(0, 1fr) 100px auto auto; gap: 12px; align-items: center; padding: 10px 12px; border: 2px solid var(--ui-line); border-radius: 14px; }
@media (max-width: 760px) {
  .modal-card.lib-modal { height: 100%; max-height: none; border-radius: 0; }
  .lib-head { padding: 12px 14px 10px; gap: 8px; }
  .lib-head h2 { font-size: 18px; flex: 1 1 calc(100% - 64px); order: -2; }
  .lib-head .m-close { order: -1; }
  .lib-account { flex: 1 1 220px; justify-content: flex-end; min-width: 0; }
  .lib-account .btn.small { padding: 5px 9px; font-size: 12.5px; white-space: nowrap; }
  .lib-me { max-width: 110px; }
  .lib-modal .m-body { padding: 8px 14px 18px; }
  .lib-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .lib-grid.libs { grid-template-columns: 1fr; }
  .lib-tabs .lib-share { width: 100%; justify-content: center; }
  .lib-tabs .lib-spacer { display: none; }
  .lib-detail, .lib-share-form, .lib-pay { grid-template-columns: 1fr; }
  .lib-libhead { grid-template-columns: 72px minmax(0, 1fr); }
  .lib-libhead .lib-cover { height: 72px; }
  .lib-libhead .lib-cover i { font-size: 34px; }
  .pay-row { grid-template-columns: 1fr auto; }
  .pay-row span { grid-column: 1 / -1; }
  .pay-row:not(:has(button)) { grid-template-columns: 1fr; }
  .order-row { grid-template-columns: 1fr auto; }
  .lib-info b { font-size: 14px; }
}

/* ======================================================================
   Tài khoản · Các gói · Sơ đồ của tôi · Thẻ ghi nhớ
   ====================================================================== */
.acc-btn i { display: grid; place-items: center; }
.acc-avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; display: block; }
.acc-avatar.big, .acc-initial.big { width: 48px; height: 48px; font-size: 22px; }
.acc-initial { width: 26px; height: 26px; border-radius: 50%; background: linear-gradient(135deg, #845ef7, #e64980); color: #fff; display: grid; place-items: center; font: 800 14px var(--font); flex: none; }
.tools .acc-btn.is-pro { box-shadow: inset 0 0 0 2px #fcc419; background: #fff9db; }
.acc-login, .acc-onb { display: flex; flex-direction: column; gap: 12px; }
.acc-reason { background: #fff3bf; border-radius: 12px; padding: 10px 14px; font-weight: 700; margin: 0; }
.acc-ok { background: #ebfbee; color: #2b8a3e; border-radius: 12px; padding: 14px; font-weight: 700; font-size: 16px; }
.acc-google { display: flex; flex-direction: column; align-items: center; gap: 6px; min-height: 44px; }
.acc-gbtn { width: 100%; max-width: 320px; justify-content: center; border: 2px solid #dadce0; background: #fff; font-size: 15px; padding: 11px; }
.acc-gbtn:hover { background: #f8f9fa; }
.g-logo { font: 900 18px Arial, sans-serif; background: conic-gradient(from -45deg, #ea4335 0 25%, #4285f4 0 50%, #34a853 0 75%, #fbbc05 0); -webkit-background-clip: text; background-clip: text; color: transparent; }
.acc-wait { font-weight: 700; color: var(--accent); animation: pulse-t 1.4s ease-in-out infinite; }
@keyframes pulse-t { 50% { opacity: .45; } }
.acc-or { display: flex; align-items: center; gap: 10px; color: var(--ui-muted); font-size: 13px; }
.acc-or::before, .acc-or::after { content: ""; flex: 1; height: 1px; background: var(--ui-line); }
.acc-email { display: flex; flex-direction: column; gap: 8px; }
.acc-email .field { padding: 10px 12px; }
.acc-seg { align-self: center; display: inline-flex; background: #f3f1f8; border-radius: 10px; padding: 3px; }
.acc-seg button { border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; font: 600 13.5px var(--font); cursor: pointer; color: var(--ui-muted); }
.acc-seg button.on { background: #fff; color: var(--accent); box-shadow: 0 1px 4px rgba(0, 0, 0, .1); }
.acc-guest { text-align: center; margin: 0; }
.acc-roles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.acc-roles .chip { justify-content: center; padding: 12px; font-size: 15px; }
.acc-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.acc-fields .field:last-child { grid-column: 1 / -1; }
.m-foot.flat { border: 0; padding: 4px 0 0; }
.acc-menu { width: 300px; max-width: 100%; display: flex; flex-direction: column; gap: 10px; }
.acc-head { display: flex; gap: 12px; align-items: center; }
.acc-head div { display: flex; flex-direction: column; min-width: 0; }
.acc-head small { color: var(--ui-muted); overflow: hidden; text-overflow: ellipsis; }
.acc-plan { align-self: flex-start; margin-top: 4px; font-size: 12px; font-weight: 800; padding: 2px 10px; border-radius: 999px; background: #f1eef8; color: var(--ui-muted); }
.acc-plan.pro { background: linear-gradient(135deg, #fff3bf, #ffe066); color: #8a5a00; }
.acc-plan.free { background: #e7f5ff; color: #1864ab; }
.acc-usage { font-size: 13px; font-weight: 600; color: var(--ui-muted); }
.acc-bar { height: 7px; border-radius: 4px; background: #f1eef8; margin-top: 4px; overflow: hidden; }
.acc-bar b { display: block; height: 100%; background: linear-gradient(90deg, #845ef7, #6741d9); border-radius: 4px; }
.up-body { display: flex; flex-direction: column; gap: 14px; }
.up-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.up-table th, .up-table td { padding: 10px; text-align: center; border-bottom: 1px solid var(--ui-line); }
.up-table td:first-child { text-align: left; font-weight: 700; color: var(--ui-muted); }
.up-table th { font-size: 16px; }
.up-table th small { display: block; font-size: 11px; color: var(--accent); }
.up-table .cur { background: #f8f6ff; }
.up-table th:last-child { color: #b07d00; }
.up-benefits { margin: 0; padding-left: 4px; list-style: none; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.up-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.up-actions .btn { padding: 12px 18px; }
.up-save { background: #ffe066; color: #5c3c00; border-radius: 999px; padding: 1px 8px; font-size: 11.5px; margin-left: 4px; }
.up-redeem { display: flex; gap: 8px; }
.up-redeem .field { flex: 1; text-transform: uppercase; letter-spacing: .05em; }
.up-pay { border: 2px dashed #c5b6f6; border-radius: 16px; padding: 14px; }
.up-pay h3 { margin: 0 0 10px; }
.up-pay-grid { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.up-qr { width: 180px; border-radius: 12px; background: #fff; }
.up-pay dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; font-size: 14px; }
.up-pay dt { color: var(--ui-muted); }
.up-pay dd { margin: 0; }
.up-pay .mono { font-family: Consolas, monospace; }
.up-pay .chip { padding: 2px 8px; font-size: 12px; margin-left: 4px; }
.tpl.locked { position: relative; filter: grayscale(.55); opacity: .75; }
.tpl.locked:hover { filter: none; opacity: 1; }
.tpl-lock { position: absolute; top: 8px; right: 10px; font-size: 16px; font-family: var(--emoji); }
.x-fmt.locked { opacity: .6; }
.x-check.locked { opacity: .6; }
.mm-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.mm-where { font-weight: 800; }
.mm-usage { color: var(--ui-muted); font-weight: 600; font-size: 14px; flex: 1; }
.primary-chip { background: var(--accent); color: #fff; border-color: var(--accent); }
.primary-chip:hover { background: #5530c2; color: #fff; }
.mm-current { border-color: var(--accent); box-shadow: 0 0 0 3px #e5dbff; }

/* chọn cách ôn */
.fc-choose { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fc-choose .x-fmt { grid-template-columns: 1fr; text-align: center; justify-items: center; gap: 6px; padding: 18px 12px; }
.fc-choose .x-fmt i { font-size: 40px; grid-row: auto; }
.fc-choose .x-fmt b { font-size: 16px; }
.fc-start { display: flex; flex-direction: column; gap: 10px; }
.fc-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.fc-stats div { background: #f8f6ff; border-radius: 14px; padding: 12px; text-align: center; display: flex; flex-direction: column; }
.fc-stats b { font-size: 26px; color: var(--accent); }
.fc-stats span { font-size: 12.5px; color: var(--ui-muted); font-weight: 600; }
.fc-ok { text-align: center; font-weight: 700; color: #2b8a3e; margin: 4px 0; }

/* màn hình ôn thẻ */
#fcview { position: fixed; inset: 0; z-index: 80; background: radial-gradient(circle at 20% 10%, #efe9ff, transparent 55%), radial-gradient(circle at 90% 90%, #ffe3ec, transparent 50%), #fbfaff; display: flex; flex-direction: column; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
.fc-top { display: flex; align-items: center; gap: 14px; max-width: 760px; width: 100%; margin: 0 auto; }
.fc-top > b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40%; }
.fc-bar { flex: 1; height: 10px; border-radius: 6px; background: #e9e4f7; overflow: hidden; }
.fc-bar b { display: block; height: 100%; background: linear-gradient(90deg, #40c057, #82c91e); border-radius: 6px; transition: width .3s; }
.fc-top > span { font-weight: 700; color: var(--ui-muted); font-size: 14px; white-space: nowrap; }
.fc-stage { flex: 1; display: grid; place-items: center; perspective: 1400px; padding: 16px 0; min-height: 0; }
.fc-card { position: relative; width: min(560px, 100%); height: min(380px, 100%); transform-style: preserve-3d; transition: transform .5s cubic-bezier(.3, 1.3, .5, 1); cursor: pointer; outline: none; }
.fc-card.flipped { transform: rotateY(180deg); }
.fc-face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 26px; background: #fff; box-shadow: 0 18px 50px rgba(60, 40, 120, .18); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 28px; text-align: center; overflow: auto; }
.fc-front { border: 3px solid #e5dbff; }
.fc-back { transform: rotateY(180deg); border: 3px solid #b2f2bb; justify-content: flex-start; }
.fc-path { font-size: 13px; color: var(--ui-muted); font-weight: 600; }
.fc-word { font-size: clamp(24px, 5vw, 34px); font-weight: 800; line-height: 1.25; }
.fc-word.small { font-size: 18px; color: var(--ui-muted); }
.fc-q { font-size: 17px; font-weight: 700; color: var(--accent); }
.fc-count { background: var(--accent-soft); border-radius: 999px; padding: 2px 10px; font-size: 13px; margin-left: 4px; }
.fc-hint { font-size: 13px; color: var(--ui-muted); margin-top: 8px; }
.fc-list { list-style: none; margin: 0; padding: 0; width: 100%; display: flex; flex-direction: column; gap: 8px; text-align: left; }
.fc-list li { background: #f4fce3; border-radius: 12px; padding: 10px 14px; font-size: 17px; }
.fc-list small { display: block; color: var(--ui-muted); font-size: 13px; margin-top: 2px; }
.fc-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; min-height: 54px; }
.fc-actions .btn { padding: 13px 20px; font-size: 16px; min-width: 130px; justify-content: center; }
.fc-actions kbd { font: 600 11px var(--font); background: rgba(0, 0, 0, .08); border-radius: 5px; padding: 1px 6px; margin-left: 6px; }
.fc-again { background: #fff0f0; color: #c92a2a; }
.fc-hard { background: #fff9db; color: #8a5a00; }
.fc-good { background: #ebfbee; color: #2b8a3e; }
.fc-keys { text-align: center; color: var(--ui-muted); font-size: 12.5px; margin: 8px 0 0; }
.fc-done { background: #fff; border-radius: 26px; box-shadow: 0 18px 50px rgba(60, 40, 120, .18); width: min(460px, 100%); }
@media (max-width: 760px) {
  .acc-fields, .fc-choose { grid-template-columns: 1fr; }
  .fc-actions .btn { min-width: 0; flex: 1; padding: 12px 8px; font-size: 14px; }
  .fc-actions kbd, .fc-keys { display: none; }
  .fc-top > b { display: none; }
  .up-table { font-size: 12.5px; }
  .up-table th, .up-table td { padding: 7px 4px; }
}
@media (prefers-reduced-motion: reduce) { .fc-card { transition: none; } }

/* ---------- Lớp học ---------- */
#classview { position: fixed; inset: 0; z-index: 45; display: grid; grid-template-columns: 260px 1fr; background: #fbfaff; }
#classview[hidden] { display: none; }
.cv-side { background: #fff; border-right: 2px solid var(--ui-line); display: flex; flex-direction: column; padding: 14px 12px; gap: 10px; overflow-y: auto; }
.cv-brand { display: flex; align-items: center; justify-content: space-between; font-size: 18px; padding: 0 4px; }
.cv-side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.cv-side nav button { display: flex; align-items: center; gap: 6px; text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 10px; cursor: pointer; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cv-side nav button:hover { background: #f6f3ff; }
.cv-side nav button.on { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.cv-side nav button.archived { opacity: .55; }
.cv-sec { font-size: 12px; font-weight: 700; color: var(--ui-muted); text-transform: uppercase; letter-spacing: .04em; padding: 12px 10px 4px; }
.cv-badge { margin-left: auto; background: #ff6b6b; color: #fff; border-radius: 999px; font-size: 11.5px; font-weight: 700; padding: 1px 7px; }
.cv-side-acts { display: grid; gap: 6px; }
.cv-main { overflow-y: auto; padding: 24px 32px 48px; }
.cv-main > * { max-width: 1100px; }
.cv-loading { padding: 40px; text-align: center; font-size: 28px; color: var(--ui-muted); }
.cv-h1 { font-size: 24px; margin: 0 0 18px; }
.cv-h2 { font-size: 17px; margin: 24px 0 10px; color: var(--ui-muted); }
.cv-hero { text-align: center; padding: 48px 12px; margin: 0 auto; max-width: 640px; }
.cv-hero h1 { font-size: 28px; margin: 0 0 8px; }
.cv-choose { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 28px; }
.cv-choose .x-fmt { padding: 18px; }
.cv-choose .x-fmt i { font-size: 38px; }
.muted { color: var(--ui-muted); }
.small { font-size: 13px; }
.block { display: block; }
.cv-section { margin-bottom: 28px; }
.cv-sec-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.cv-sec-head h2 { font-size: 18px; margin: 0; }
.cv-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.cv-card { display: flex; flex-direction: column; gap: 4px; text-align: left; border: 2px solid var(--ui-line); background: #fff; border-radius: 16px; padding: 14px; cursor: pointer; position: relative; }
.cv-card:hover { border-color: #c5b6f6; box-shadow: 0 6px 18px rgba(103, 65, 217, .1); }
.cv-card.archived { opacity: .6; }
.cv-card b { font-size: 16px; padding-right: 70px; }
.cv-card small { color: var(--ui-muted); min-height: 1.2em; }
.cv-card code { position: absolute; top: 12px; right: 12px; font: 700 12px Consolas, monospace; background: var(--accent-soft); color: var(--accent); padding: 2px 6px; border-radius: 6px; }
.cv-card-stats { display: flex; gap: 12px; margin-top: 6px; font-size: 13.5px; }
.cv-card-stats .hot { color: #e8590c; font-weight: 700; }
.cv-pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; background: #f1eff7; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.cv-pill.warn { background: #fff4e6; color: #d9480f; }
.cv-pill.ok { background: #ebfbee; color: #2b8a3e; }
.cv-ok { background: #ebfbee; color: #2b8a3e; padding: 14px; border-radius: 14px; font-weight: 600; }
.cv-list { display: flex; flex-direction: column; gap: 8px; }
.cv-row { display: flex; align-items: center; gap: 12px; text-align: left; border: 2px solid var(--ui-line); background: #fff; border-radius: 14px; padding: 10px 14px; cursor: pointer; }
.cv-row:hover { border-color: #c5b6f6; }
.cv-row > i { font-size: 24px; }
.cv-row > div { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.cv-row > div b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cv-row small { color: var(--ui-muted); }
.cv-st { display: inline-flex; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; background: #f1eff7; }
.cv-st.st-draft { background: #fff9db; color: #946200; }
.cv-st.st-submitted { background: #e7f5ff; color: #1864ab; }
.cv-st.st-returned { background: #ebfbee; color: #2b8a3e; }
.cv-class-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.cv-class-head h1 { margin: 0 0 4px; font-size: 24px; }
.cv-class-head p { margin: 0; }
.cv-head-acts { display: flex; gap: 6px; flex-wrap: wrap; }
.cv-instr { background: #fff; border-left: 4px solid var(--accent); padding: 8px 12px; border-radius: 8px; white-space: pre-wrap; margin-top: 10px !important; }
.cv-code { background: #fff; border: 2px dashed #c5b6f6; border-radius: 16px; padding: 8px 14px; text-align: center; }
.cv-code small { display: block; color: var(--ui-muted); font-size: 12px; }
.cv-code b { font: 800 26px Consolas, monospace; letter-spacing: .12em; color: var(--accent); }
.cv-code div { display: flex; gap: 4px; justify-content: center; margin-top: 4px; }
.cv-tabs.seg { display: flex; gap: 4px; background: #f1eff7; padding: 4px; border-radius: 14px; margin-bottom: 16px; overflow-x: auto; }
.cv-tabs.seg button { border: 0; background: none; padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 14px; white-space: nowrap; }
.cv-tabs.seg button.on { background: #fff; color: var(--accent); box-shadow: 0 2px 6px rgba(0, 0, 0, .08); }
.cv-toolbar { display: flex; gap: 8px; justify-content: flex-end; margin-bottom: 12px; }
.cv-back { margin-bottom: 10px; }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 2px var(--ui-line); }
.cv-form { display: flex; flex-direction: column; gap: 12px; max-width: 760px; }
.cv-form label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 14px; }
.cv-form label.x-check { flex-direction: row; align-items: center; font-weight: 500; }
.cv-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cv-modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cv-modes .x-fmt.on { border-color: var(--accent); background: var(--accent-soft); }
.cv-modes .x-fmt:disabled { opacity: .45; cursor: not-allowed; }
.cv-preview img { display: block; max-width: 100%; border: 2px solid var(--ui-line); border-radius: 14px; margin: 8px 0 4px; }
.cv-preview .chips { align-items: center; }
.cv-code-input { font: 800 28px Consolas, monospace !important; letter-spacing: .3em; text-align: center; text-transform: uppercase; }
.cv-join-card { display: flex; align-items: center; gap: 18px; background: #fff; border: 2px solid var(--ui-line); border-radius: 16px; padding: 14px 18px; margin-bottom: 16px; }
.cv-join-code { font: 800 34px Consolas, monospace; letter-spacing: .14em; color: var(--accent); background: var(--accent-soft); padding: 6px 14px; border-radius: 12px; }
.cv-join-card p { margin: 4px 0 0; }
.cv-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 14px; overflow: hidden; }
.cv-table th, .cv-table td { padding: 9px 12px; border-bottom: 1.5px solid var(--ui-line); text-align: left; font-size: 14px; }
.cv-table th { background: #f8f6fd; font-size: 12.5px; color: var(--ui-muted); }
.cv-mini-bar { display: inline-block; width: 70px; height: 7px; background: #eee; border-radius: 9px; overflow: hidden; margin-right: 6px; vertical-align: middle; }
.cv-mini-bar b { display: block; height: 100%; background: #40c057; }
.cv-matrix-wrap { overflow: auto; border: 2px solid var(--ui-line); border-radius: 14px; background: #fff; }
.cv-matrix { border-collapse: collapse; font-size: 14px; }
.cv-matrix th, .cv-matrix td { border: 1px solid var(--ui-line); padding: 8px 10px; text-align: center; min-width: 64px; }
.cv-matrix th:first-child, .cv-matrix td:first-child { text-align: left; position: sticky; left: 0; background: #fff; min-width: 140px; }
.cv-matrix th span { display: block; max-width: 130px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12.5px; }
.cv-matrix td[data-sub] { cursor: pointer; }
.cv-matrix td[data-sub]:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
.cv-matrix .c-none { color: #ccc; }
.cv-matrix .c-draft { background: #fff9db; }
.cv-matrix .c-submitted { background: #e7f5ff; }
.cv-matrix .c-returned { background: #ebfbee; font-weight: 700; color: #2b8a3e; }
.cv-matrix td.late, .late-dot { box-shadow: inset 0 -3px 0 #fa5252; }
.late-dot { display: inline-block; width: 14px; height: 10px; }
.cv-matrix tfoot td { background: #f8f6fd; font-weight: 700; font-size: 12.5px; }
.cv-legend { color: var(--ui-muted); font-size: 13px; }
.cv-danger { display: flex; gap: 8px; margin-top: 32px; padding-top: 16px; border-top: 2px dashed var(--ui-line); }
.cv-roster { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)) !important; }
.cv-sub { cursor: pointer; text-align: left; padding: 0; font: inherit; }
.cv-sub:disabled { cursor: default; opacity: .6; }
.cv-sub:not(:disabled):hover { border-color: #c5b6f6; }
.cv-sub .meta small { display: block; color: var(--ui-muted); }
.cv-sub .acts { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px 10px 10px; }

/* làm bài / chấm bài */
body.cr-on #stage { right: 360px; }
body.cr-on #zoombar { right: 376px; }
#crpanel { position: fixed; top: 76px; right: 0; bottom: 0; width: 360px; z-index: 18; background: #fff; border-left: 2px solid var(--ui-line); display: flex; flex-direction: column; }
.crp-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 2px solid var(--ui-line); }
.crp-nav { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 13.5px; }
.crp-body { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.crp-title { display: flex; flex-direction: column; gap: 4px; }
.crp-title b { font-size: 16px; }
.crp-box { background: #f8f6fd; border-radius: 14px; padding: 10px 12px; }
.crp-box p { margin: 6px 0 0; white-space: pre-wrap; font-size: 14px; }
.crp-box.result { background: #ebfbee; }
.crp-fill { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 220px; overflow-y: auto; }
.crp-fill li { display: flex; gap: 8px; align-items: flex-start; padding: 6px 8px; border-radius: 10px; background: #fff; cursor: pointer; }
.crp-fill li.bad { background: #fff5f5; }
.crp-fill li div { display: flex; flex-direction: column; min-width: 0; }
.crp-fill small { color: var(--ui-muted); }
.crp-grade { display: flex; flex-direction: column; gap: 8px; }
.crp-score { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.crp-score .field { width: 90px; font-size: 18px; font-weight: 700; text-align: center; }
.crp-acts { display: flex; gap: 6px; justify-content: flex-end; }
.crp-comments { display: flex; flex-direction: column; gap: 10px; }
.crp-thread { border: 1.5px solid var(--ui-line); border-radius: 12px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.crp-node { border: 0; background: var(--accent-soft); color: var(--accent); font-weight: 700; border-radius: 8px; padding: 4px 8px; text-align: left; cursor: pointer; font-size: 13px; }
.crp-c { background: #f1f3f5; border-radius: 10px; padding: 6px 9px; margin-right: 24px; }
.crp-c.teacher { background: #fff4e6; margin: 0 0 0 24px; }
.crp-c small { color: var(--ui-muted); font-size: 11.5px; display: flex; gap: 4px; align-items: center; }
.crp-c p { margin: 2px 0 0; font-size: 14px; white-space: pre-wrap; user-select: text; }
.crp-del { margin-left: auto; border: 0; background: none; cursor: pointer; color: #aaa; font-size: 11px; }
.crp-del:hover { color: var(--danger); }
.crp-compose { border-top: 2px solid var(--ui-line); padding: 8px 12px; display: flex; flex-direction: column; gap: 4px; }
.crp-compose small { color: var(--accent); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crp-row { display: flex; gap: 6px; align-items: flex-end; }
.crp-row textarea { flex: 1; resize: none; }
.crp-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 2px solid var(--ui-line); background: #fbfaff; }
.crp-foot small { font-size: 12px; }
.mnode .cr-badge { position: absolute; top: -12px; right: -10px; background: #ffd43b; border-radius: 999px; padding: 1px 6px; font-size: 12px; font-weight: 700; box-shadow: 0 2px 6px rgba(0, 0, 0, .2); pointer-events: none; z-index: 2; }
.mnode.cr-blank { outline: 3px dashed #845ef7; outline-offset: 4px; border-radius: 14px; }
.mnode.cr-right { outline: 4px solid #69db7c; outline-offset: 3px; border-radius: 14px; }
.mnode.cr-wrong { outline: 4px solid #ff8787; outline-offset: 3px; border-radius: 14px; }
@media (max-width: 1180px) { #crpanel { top: 66px; } }
@media (max-width: 760px) {
  #classview { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .cv-side { border-right: 0; border-bottom: 2px solid var(--ui-line); padding: calc(10px + env(safe-area-inset-top)) 10px 10px; max-height: 42vh; }
  .cv-side nav { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; }
  .cv-sec { display: none; }
  .cv-side-acts { grid-template-columns: 1fr 1fr; }
  .cv-main { padding: 16px 14px 40px; }
  .cv-choose, .cv-grid2, .cv-modes { grid-template-columns: 1fr; }
  .cv-table th:nth-child(2), .cv-table td:nth-child(2) { display: none; }
  .cv-row { flex-wrap: wrap; row-gap: 6px; }
  .cv-row > div { flex-basis: calc(100% - 40px); }
  .cv-row > span:first-of-type { margin-left: 36px; }
  body.cr-on #stage { right: 0; bottom: 46vh; }
  body.cr-on #zoombar { display: none; }
  #crpanel { top: auto; height: 46vh; width: 100%; border-left: 0; border-top: 2px solid var(--ui-line); border-radius: 18px 18px 0 0; z-index: 25; }
}

/* ---------- Thử thách tuần ---------- */
#chview { position: fixed; inset: 0; z-index: 45; overflow-y: auto; background: radial-gradient(circle at 15% 0%, #fff3bf, transparent 45%), radial-gradient(circle at 100% 100%, #e5dbff, transparent 50%), #fbfaff; }
#chview[hidden] { display: none; }
.ch-wrap { max-width: 920px; margin: 0 auto; padding: 18px 18px calc(40px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 16px; }
.ch-head { display: flex; align-items: center; justify-content: space-between; padding-top: env(safe-area-inset-top); }
.ch-head h1 { margin: 0; font-size: 24px; }
.ch-hero { background: linear-gradient(135deg, #6741d9, #9c36b5 60%, #e64980); color: #fff; border-radius: 24px; padding: 22px 24px; box-shadow: 0 14px 34px rgba(103, 65, 217, .28); }
.ch-hero h2 { margin: 10px 0 4px; font-size: 28px; }
.ch-hero p { margin: 0 0 10px; opacity: .92; }
.ch-hero-top, .ch-hero-meta { display: flex; flex-wrap: wrap; gap: 8px; }
.ch-hero-meta span { background: rgba(255, 255, 255, .16); padding: 4px 10px; border-radius: 999px; font-size: 13.5px; font-weight: 600; }
.ch-chip { background: rgba(255, 255, 255, .22); padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.ch-chip.warm { background: #ffd43b; color: #5c3c00; }
.ch-hero-foot { display: flex; align-items: center; gap: 18px; margin-top: 16px; flex-wrap: wrap; }
.ch-play { background: #fff !important; color: #6741d9 !important; font-size: 18px; padding: 12px 26px; border-radius: 999px; box-shadow: 0 6px 18px rgba(0, 0, 0, .2); }
.ch-play:hover { transform: translateY(-1px); }
.ch-mybest { display: flex; flex-direction: column; line-height: 1.2; }
.ch-mybest b { font-size: 26px; }
.ch-mybest small { opacity: .85; font-size: 12.5px; }
.ch-how { font-size: 13px; opacity: .85; margin: 14px 0 0 !important; }
.ch-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.ch-stats > div { background: #fff; border: 2px solid var(--ui-line); border-radius: 18px; padding: 12px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.ch-stats i { font-size: 24px; }
.ch-stats b { font-size: 20px; }
.ch-stats small { color: var(--ui-muted); font-size: 12px; }
.ch-login { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: #fff; border: 2px dashed #c5b6f6; border-radius: 18px; padding: 12px 16px; font-weight: 600; }
.ch-board, .ch-past, .ch-own { background: #fff; border: 2px solid var(--ui-line); border-radius: 20px; padding: 14px 16px; }
.ch-board h3, .ch-past h3 { margin: 0 0 10px; font-size: 17px; }
.ch-sec-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.ch-sec-head h3 { margin: 0; }
.ch-seg { display: flex; gap: 4px; background: #f1eff7; padding: 3px; border-radius: 12px; }
.ch-seg button { border: 0; background: none; padding: 6px 12px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 13px; }
.ch-seg button.on { background: #fff; color: var(--accent); box-shadow: 0 2px 6px rgba(0, 0, 0, .08); }
.ch-rank { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.ch-rank li { display: grid; grid-template-columns: 36px 1fr auto auto; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 12px; }
.ch-rank li:nth-child(-n+3) { background: #fff9db; }
.ch-rank li.me { background: var(--accent-soft); box-shadow: inset 0 0 0 2px #c5b6f6; }
.ch-rank li.gap { display: block; text-align: center; color: var(--ui-muted); padding: 0; background: none; }
.ch-rank .rk { font-weight: 800; text-align: center; font-size: 16px; }
.ch-rank small { color: var(--ui-muted); font-size: 12.5px; }
.ch-rank em { font-style: normal; font-weight: 800; color: var(--accent); min-width: 54px; text-align: right; }
.ch-own { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.ch-own > div:first-child { display: flex; flex-direction: column; }
.ch-own small { color: var(--ui-muted); }
.ch-past .cv-row { cursor: default; }

/* trò chơi */
.ch-game { display: flex; flex-direction: column; min-height: 100%; max-width: 1100px; margin: 0 auto; padding: env(safe-area-inset-top) 0 0; }
.ch-ghead { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.ch-gtitle { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ch-gtitle b { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-gtitle small { color: var(--ui-muted); }
.ch-timer { font: 800 20px Consolas, monospace; background: #fff; border: 2px solid var(--ui-line); border-radius: 12px; padding: 4px 12px; min-width: 96px; text-align: center; }
.ch-progress { height: 8px; margin: 0 16px; background: #ece8f5; border-radius: 9px; overflow: hidden; }
.ch-progress b { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #845ef7, #e64980); transition: width .25s; }
.ch-gbody { flex: 1; padding: 14px 16px; }
.ch-gfoot { position: sticky; bottom: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: rgba(251, 250, 255, .94); backdrop-filter: blur(6px); border-top: 2px solid var(--ui-line); }
.ch-gfoot .btn.pulse { animation: chPulse 1.2s infinite; }
@keyframes chPulse { 50% { box-shadow: 0 0 0 8px rgba(103, 65, 217, .18); } }
.ch-bins { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.ch-bin, .ch-fgroup { background: #fff; border: 3px solid var(--c); border-radius: 18px; overflow: hidden; display: flex; flex-direction: column; min-height: 120px; transition: transform .12s, box-shadow .12s; }
.ch-bin-h { background: var(--c); color: #fff; font-weight: 800; padding: 8px 12px; font-size: 15.5px; }
.ch-bin-items { flex: 1; display: flex; flex-wrap: wrap; align-content: flex-start; gap: 6px; padding: 10px; }
.ch-bin.over, .ch-picking .ch-bin:hover { transform: scale(1.02); box-shadow: 0 0 0 4px rgba(103, 65, 217, .25); }
.ch-picking .ch-bin { cursor: pointer; }
.ch-tray { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 8px; padding: 14px; min-height: 70px; border: 2px dashed #c5b6f6; border-radius: 18px; background: rgba(255, 255, 255, .7); }
.ch-tray.empty { border-color: #8ce99a; background: #ebfbee; }
.ch-tray.over { background: var(--accent-soft); }
.ch-card { border: 2px solid var(--ui-line); background: #fff; border-radius: 12px; padding: 8px 12px; font: 600 15px var(--font); font-family: var(--font), var(--emoji); cursor: grab; touch-action: none; user-select: none; box-shadow: 0 2px 6px rgba(0, 0, 0, .06); display: inline-flex; flex-direction: column; align-items: flex-start; }
.ch-card:hover { border-color: #b197fc; }
.ch-card.sel { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 3px rgba(103, 65, 217, .25); }
.ch-card.dragging { opacity: .35; }
.ch-card.ghost { position: fixed; z-index: 70; pointer-events: none; transform: translate(-50%, -50%) rotate(-3deg); box-shadow: 0 10px 24px rgba(0, 0, 0, .25); }
.ch-card.pop { animation: chPop .25s; }
@keyframes chPop { 50% { transform: scale(1.12); } }
.ch-card.ok { border-color: #40c057; background: #ebfbee; }
.ch-card.bad { border-color: #fa5252; background: #fff5f5; }
.ch-card.ok::before { content: '✅ '; } .ch-card.bad::before { content: '❌ '; }
.ch-card small { font-size: 11.5px; color: #c92a2a; font-weight: 600; }
.ch-fill { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.ch-fgroup { padding-bottom: 8px; }
.ch-fitem { margin: 6px 10px 0; padding: 7px 10px; border-radius: 10px; background: #f8f6fd; font-weight: 600; font-family: var(--font), var(--emoji); }
.ch-fitem.blank { background: none; padding: 0; display: flex; flex-direction: column; position: relative; }
.ch-fitem input { width: 100%; border: 2px dashed #b197fc; border-radius: 10px; padding: 8px 10px; font: 600 15px var(--font); background: #fff; }
.ch-fitem input:focus { outline: none; border-style: solid; border-color: var(--accent); }
.ch-fitem input::placeholder { color: #b8b0d0; letter-spacing: .04em; }
.ch-hint { display: none; }
.ch-fitem.ok input { border: 2px solid #40c057; background: #ebfbee; }
.ch-fitem.bad input { border: 2px solid #fa5252; background: #fff5f5; }
.ch-ans { color: #2b8a3e; font-weight: 700; padding: 2px 4px; }
.ch-result { position: fixed; inset: 0; z-index: 48; background: rgba(35, 25, 70, .45); display: flex; align-items: center; justify-content: center; padding: 16px; overflow: hidden; animation: fade .15s; }
.ch-result-card { background: #fff; border-radius: 26px; padding: 24px 22px; width: min(440px, 100%); text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); animation: pop .25s ease-out; position: relative; z-index: 1; }
.ch-big { font-size: 56px; line-height: 1; }
.ch-score b { display: block; font-size: 52px; font-weight: 900; background: linear-gradient(90deg, #6741d9, #e64980); -webkit-background-clip: text; background-clip: text; color: transparent; }
.ch-score small { color: var(--ui-muted); font-weight: 700; }
.ch-line { margin: 8px 0; font-weight: 600; }
.btn-row.center { justify-content: center; margin-top: 14px; }
.ch-confetti { position: absolute; top: -40px; animation: chFall 2.2s ease-in forwards; font-style: normal; }
@keyframes chFall { to { transform: translateY(110vh) rotate(540deg); opacity: .6; } }
@media (max-width: 760px) {
  .ch-wrap { padding: 12px 12px 32px; }
  .ch-hero { padding: 18px; border-radius: 20px; }
  .ch-hero h2 { font-size: 23px; }
  .ch-stats { grid-template-columns: repeat(2, 1fr); }
  .ch-bins { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .ch-bin { min-height: 96px; }
  .ch-bin-h { font-size: 13.5px; padding: 6px 8px; }
  .ch-card { font-size: 14px; padding: 7px 10px; }
  .ch-gfoot small { display: none; }
  .ch-gfoot .btn { flex: 1; }
  .ch-rank li { grid-template-columns: 30px 1fr auto; }
  .ch-rank li small { display: none; }
  .ch-past .cv-row { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) { .ch-confetti, .ch-card.pop, .ch-gfoot .btn.pulse { animation: none; } }

/* ---------- Pháp lý & dữ liệu cá nhân ---------- */
.acc-agree { font-size: 12.5px; color: var(--ui-muted); background: #f8f6fd; border-radius: 12px; padding: 8px 10px; margin: 0 0 10px; line-height: 1.5; }
.acc-agree a, .acc-onb a, .acc-data a { color: var(--accent); font-weight: 600; }
.acc-agree span { display: inline-block; margin-top: 3px; }
.acc-data section { border: 2px solid var(--ui-line); border-radius: 16px; padding: 12px 14px; margin-top: 12px; }
.acc-data h3 { margin: 0 0 4px; font-size: 16px; }
.acc-data label { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; font-weight: 600; }
.acc-data .danger-zone { border-color: #ffc9c9; background: #fff8f8; }
.btn.danger:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Hình dạng ô (SVG) ---------- */
.mnode > .mshape { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.mnode.svgshape { box-shadow: none !important; }
.mnode.svgshape.lv0 > .mshape { filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .18)); }
.mnode.svgshape.lv1 > .mshape { filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .13)); }
.mnode.svgshape:hover > .mshape { filter: drop-shadow(0 0 4px rgba(103, 65, 217, .45)); }
.mnode.svgshape.sel > .mshape { filter: drop-shadow(0 0 0 #4dabf7) drop-shadow(0 0 3px #4dabf7) drop-shadow(0 0 3px #4dabf7); }
.mnode.svgshape.sel { outline: 3px dashed #4dabf7; outline-offset: 4px; border-radius: 10px; }
.mnode.svgshape.editing > .mshape { display: none; }
.mnode.svgshape.drop-child { outline: 4px solid #40c057; outline-offset: 4px; }
.shape-chips .chip { display: inline-flex; align-items: center; gap: 6px; }
.shape-chips .chip svg { flex: none; }
.shape-scope { display: flex; gap: 3px; background: #f1eff7; padding: 3px; border-radius: 11px; margin-bottom: 8px; }
.shape-scope button { flex: 1; border: 0; background: none; padding: 6px 8px; border-radius: 8px; cursor: pointer; font: 600 13px var(--font); }
.shape-scope button.on { background: #fff; color: var(--accent); box-shadow: 0 1px 4px rgba(0, 0, 0, .08); }
.subj-shape { margin-top: 8px; border-color: #c5b6f6; }

/* ---------- 7 bố cục ---------- */
.lay-cards { grid-template-columns: repeat(3, 1fr); width: min(400px, calc(100vw - 48px)); }
.lay-cards .card-opt { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 6px 8px; }
.lay-cards .card-opt b { font-size: 13.5px; }
.lay-cards .card-opt small { font-weight: 500; font-size: 11.5px; color: var(--ui-muted); line-height: 1.25; }
.lay-star { position: absolute; top: 4px; right: 6px; font-size: 13px; font-family: var(--emoji); }
.lay-sug { margin: -4px 0 8px; font-size: 12.5px; color: #946200; background: #fff9db; padding: 5px 10px; border-radius: 10px; }

/* ---------- Môn học ở màn hình bắt đầu ---------- */
.subj-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.subj-chip { display: inline-flex; align-items: center; gap: 6px; }
.subj-chip i { font-size: 16px; }
.subj-chip.on { border-color: var(--sc); background: color-mix(in srgb, var(--sc) 14%, #fff); color: #1f1f2e; }

/* ---------- Thư viện icon ---------- */
.ic-panel { width: min(456px, calc(100vw - 48px)); display: flex; flex-direction: column; gap: 8px; }
#popover:has(.ic-panel) { max-width: min(484px, calc(100vw - 20px)); }
.ic-level { background: #fff9db; border-radius: 12px; padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; }
.ic-subjects { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
.ic-subj { flex: none; display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 58px; border: 2px solid transparent; background: #f8f6fd; border-radius: 12px; padding: 5px 4px; cursor: pointer; font: 600 11px var(--font); color: var(--ui-text); }
.ic-subj i { font-size: 20px; }
.ic-subj span { max-width: 70px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ic-subj.on { border-color: var(--sc); background: color-mix(in srgb, var(--sc) 14%, #fff); }
.ic-subj.ic-lv { margin-left: auto; background: #fff; border: 2px dashed var(--ui-line); }
.ic-search .field { width: 100%; }
.ic-tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: thin; padding-bottom: 2px; }
.ic-tabs[hidden] { display: none; }
.ic-tabs button { flex: none; border: 0; background: #f1eff7; border-radius: 999px; padding: 5px 11px; cursor: pointer; font: 600 12.5px var(--font); white-space: nowrap; }
.ic-tabs button.on { background: var(--accent); color: #fff; }
.ic-tabs i { font-family: var(--emoji); }
.ic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 4px; max-height: 300px; overflow-y: auto; align-content: start; padding: 2px; }
.ic-cell { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 2px solid transparent; background: #fff; border-radius: 12px; padding: 6px 2px 4px; cursor: pointer; min-height: 62px; }
.ic-cell:hover { border-color: #c5b6f6; background: var(--accent-soft); }
.ic-cell i { font-family: var(--emoji); line-height: 1; }
.ic-cell img { object-fit: contain; border-radius: 6px; }
.ic-cell small { font-size: 10.5px; line-height: 1.15; color: var(--ui-muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
.ic-upload { border: 2px dashed #c5b6f6; background: #faf8ff; }
.ic-del { position: absolute; top: 2px; right: 4px; font-size: 11px; color: #c92a2a; display: none; }
.ic-cell:hover .ic-del { display: block; }
.ic-empty, .ic-note { grid-column: 1 / -1; margin: 6px 4px; }
.ic-foot { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; border-top: 1.5px solid var(--ui-line); padding-top: 8px; font-size: 12.5px; }
.ic-foot .x-check { font-size: 12.5px; }
.ic-suggest { position: absolute; z-index: 8; display: flex; align-items: center; gap: 2px; background: #fff; border-radius: 14px; padding: 4px 6px; box-shadow: 0 6px 18px rgba(0, 0, 0, .18); animation: pop .15s ease-out; transform-origin: top left; transform: scale(var(--inv, 1)); }
.ic-suggest span { font-size: 11.5px; font-weight: 700; color: var(--ui-muted); padding: 0 4px; white-space: nowrap; }
.ic-suggest button { border: 0; background: none; border-radius: 10px; padding: 3px; cursor: pointer; display: grid; place-items: center; }
.ic-suggest button:hover { background: var(--accent-soft); }
.ic-suggest i { font-family: var(--emoji); }
@media (max-width: 760px) {
  .ic-panel { width: 100%; }
  .ic-grid { max-height: 34vh; grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); }
  .lay-cards { grid-template-columns: repeat(2, 1fr); width: 100%; }
}

/* ---------- Chia sẻ sơ đồ ---------- */
.modal-card.sh-modal { width: min(560px, 100%); }
.sh-body { display: flex; flex-direction: column; gap: 10px; }
.sh-add { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; }
.sh-add .field { min-width: 0; }
.sh-people { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 260px; overflow-y: auto; }
.sh-people li { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 6px 4px; border-radius: 12px; }
.sh-people li:hover { background: #f8f6fd; }
.sh-av { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 800; overflow: hidden; }
.sh-av img { width: 100%; height: 100%; object-fit: cover; }
.sh-who { display: flex; flex-direction: column; min-width: 0; }
.sh-who b, .sh-who small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sh-who small { color: var(--ui-muted); font-size: 12.5px; }
.sh-owner { font-size: 13px; color: var(--ui-muted); padding-right: 8px; }
.sh-role, .sh-lrole { width: auto; padding: 6px 8px; font-size: 13px; }
.sh-link { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto auto; gap: 10px; align-items: center; background: #f8f6fd; border-radius: 14px; padding: 10px; }
.sh-gi { width: 40px; height: 40px; border-radius: 50%; background: #fff; display: grid; place-items: center; font-size: 20px; font-family: var(--emoji); }
.sh-gl { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.sh-gl select { width: auto; max-width: 100%; font-weight: 700; padding: 5px 8px; }
.sh-gl small { color: var(--ui-muted); font-size: 12.5px; }
.sh-note { margin: 2px 0 0; }
.sh-pill { display: inline-block; margin-top: 4px; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #f1eff7; color: var(--ui-muted); }
.sh-pill.edit { background: var(--accent-soft); color: var(--accent); }
.mm-tabs { display: flex; gap: 3px; background: #f1eff7; padding: 3px; border-radius: 12px; margin-bottom: 10px; }
.mm-tabs button { flex: 1; border: 0; background: none; padding: 8px 10px; border-radius: 9px; cursor: pointer; font: 600 14px var(--font); }
.mm-tabs button.on { background: #fff; color: var(--accent); box-shadow: 0 1px 4px rgba(0, 0, 0, .08); }
@media (max-width: 760px) {
  .sh-add { grid-template-columns: minmax(0, 1fr) auto; }
  .sh-add .btn { grid-column: 1 / -1; }
  .sh-link { grid-template-columns: 40px minmax(0, 1fr); }
  .sh-lrole, .sh-reset { grid-column: 2; justify-self: start; }
}
.sh-badge { flex: none; border: 0; border-radius: 999px; padding: 5px 12px; font: 700 12.5px var(--font); font-family: var(--font), var(--emoji); cursor: pointer; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; background: #f1eff7; color: var(--ui-muted); }
.sh-badge.edit { background: var(--accent-soft); color: var(--accent); }
.sh-badge i { font-style: normal; margin-right: 4px; }
@media (max-width: 1180px) { .sh-badge { padding: 5px 9px; } .sh-badge span { display: none; } .sh-badge i { margin: 0; } }

/* ---------- Giới thiệu bạn bè ---------- */
.modal-card.ref-modal, .modal-card.so-modal { width: min(620px, 100%); }
.ref-body { display: flex; flex-direction: column; gap: 12px; }
.ref-hero { background: linear-gradient(135deg, #6741d9, #9c36b5); color: #fff; border-radius: 16px; padding: 14px 16px; }
.ref-hero b { font-size: 17px; }
.ref-hero p { margin: 6px 0 0; font-size: 14px; opacity: .95; }
.ref-linkbox { display: flex; flex-direction: column; gap: 4px; font-weight: 700; font-size: 13.5px; }
.ref-row { display: flex; gap: 8px; }
.ref-row .field { flex: 1; min-width: 0; font-weight: 600; }
.ref-share { display: flex; flex-wrap: wrap; gap: 6px; }
.ref-steps { margin: 0; padding-left: 20px; font-size: 13.5px; color: var(--ui-muted); display: grid; gap: 2px; }
.ref-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ref-stats div { background: #f8f6fd; border-radius: 12px; padding: 8px 10px; display: flex; flex-direction: column; }
.ref-stats b { font-size: 17px; font-variant-numeric: tabular-nums; }
.ref-stats small { color: var(--ui-muted); font-size: 12px; }
.ref-stats .hi { background: var(--accent-soft); }
.ref-stats .hi b { color: var(--accent); }
.ref-sec { border: 1.5px solid var(--ui-line); border-radius: 14px; padding: 8px 12px; }
.ref-sec summary { cursor: pointer; font-weight: 700; font-size: 14px; }
.ref-bank { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.ref-bank .btn { grid-column: 1 / -1; justify-self: start; }
.ref-pay { margin: 4px 0 6px; }
.ref-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; max-height: 200px; overflow-y: auto; }
.ref-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; font-size: 13.5px; padding: 4px 0; border-bottom: 1px solid var(--ui-line); }
.ref-list small { color: var(--ui-muted); }
.ref-list b { font-variant-numeric: tabular-nums; }

/* ---------- Đăng lên mạng xã hội ---------- */
.so-body { display: flex; flex-direction: column; gap: 10px; }
.so-preview { border-radius: 14px; overflow: hidden; border: 1.5px solid var(--ui-line); aspect-ratio: 1200 / 630; background: #faf8ff; display: grid; place-items: center; }
.so-preview img { width: 100%; height: 100%; display: block; }
.so-field { display: flex; flex-direction: column; gap: 4px; font-weight: 700; font-size: 13.5px; }
.so-field textarea { resize: vertical; }
.so-step { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.so-step p { flex-basis: 100%; margin: 0; }
.so-step[hidden] { display: none; }
.so-step .so-field { flex-basis: 100%; }
.so-net { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; flex-basis: 100%; }
.so-btn { display: flex; align-items: center; gap: 8px; border: 0; border-radius: 12px; padding: 9px 10px; cursor: pointer; font: 700 13.5px var(--font); color: #fff; }
.so-btn b { width: 24px; height: 24px; border-radius: 6px; background: rgba(255, 255, 255, .22); display: grid; place-items: center; font-size: 14px; }
.so-btn.fb { background: #1877f2; } .so-btn.zl { background: #0068ff; } .so-btn.ms { background: #a033ff; }
.so-btn.x { background: #111; } .so-btn.li { background: #0a66c2; } .so-btn.tg { background: #229ed9; } .so-btn.more { background: #6b6b80; }
.so-btn:hover { filter: brightness(1.08); }
@media (max-width: 760px) { .ref-stats { grid-template-columns: repeat(2, 1fr); } .ref-bank { grid-template-columns: 1fr; } }

/* hộp thanh toán: chờ xác nhận & đã nhận tiền */
.up-qrbox { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.up-qrbox .chip { text-decoration: none; font-size: 12.5px; }
.up-wait { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 10px 0 4px; }
.up-wait [data-status] { flex: 1; min-width: 200px; }
.up-done { text-align: center; padding: 18px 8px 8px; }
.up-done b { font-size: 19px; color: #2b8a3e; }
.up-done p { margin: 8px 0 14px; }

/* link mở ô nhập mã kích hoạt (ẩn mặc định để không hiểu lầm là bắt buộc) */
.up-codelink { display: block; margin: 12px auto 0; background: none; border: 0; padding: 4px 8px; color: var(--muted, #6b6b80); font: inherit; font-size: 14px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.up-codelink:hover { color: var(--accent, #6741d9); }
.up-codelink[hidden], .up-redeem[hidden] { display: none; }
