:root {
  --bg: #0e1015;
  --panel: #161922;
  --panel-2: #1d212c;
  --line: #2a2f3d;
  --text: #e8eaf1;
  --muted: #8d94a8;
  --brand: #6d5bff;
  --brand-2: #8878ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#appbar { flex: none; height: 56px; }
.editorbar { flex: none; height: 52px; background: var(--bg); }
.editor { flex: 1; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.page { flex: 1; min-height: 0; overflow-y: auto; }

.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav button { background: transparent; border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer; color: var(--muted); font-weight: 600; }
.nav button:hover { color: var(--text); }
.nav button.on { background: var(--panel-2); color: var(--text); }

button, select, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.brand { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: -.2px; white-space: nowrap; }
.spacer { flex: 1; }
.namefield { flex: none; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; white-space: nowrap; margin: 0; }
.name { width: 400px; flex: none; background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 6px 8px; }
.name:hover, .name:focus { border-color: var(--line); background: var(--panel-2); outline: none; }

.btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #3a4156; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--brand-2); }
.btn.ghost { background: transparent; }

select, textarea, input[type=text] {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%;
}
.topbar select { width: auto; max-width: 240px; }
select:focus, textarea:focus, input:focus-visible, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
textarea { resize: vertical; }

.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg button { background: transparent; border: 0; padding: 5px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.seg button.on { background: var(--brand); color: #fff; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 290px 1fr 396px; min-height: 0; }
.panel { background: var(--panel); overflow-y: auto; padding: 14px; min-height: 0; }
.panel.left { border-right: 1px solid var(--line); padding: 0; }
.panel.right { border-left: 1px solid var(--line); }
.panel h3 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.panel label, .panel .field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; color: var(--muted); font-size: 12.5px; }
.panel .seg { align-self: flex-start; }
.panel input[type=range] { width: 100%; accent-color: var(--brand); }
.panel input[type=color] { width: 100%; height: 34px; padding: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.colors { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.hint { color: var(--muted); font-size: 12px; margin: 10px 0 0; }

.tabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.tabs button { background: transparent; border: 0; padding: 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 600; }
.tabs button.on { color: var(--text); border-bottom-color: var(--brand); }
.tabpane { padding: 14px; }

.tpl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tpl { background: var(--panel-2); border: 2px solid transparent; border-radius: 10px; padding: 6px; cursor: pointer; text-align: center; color: var(--muted); font-size: 12px; }
.tpl canvas { width: 100%; height: auto; border-radius: 6px; display: block; margin-bottom: 6px; }
.tpl:hover { border-color: #3a4156; }
.tpl.on { border-color: var(--brand); color: var(--text); }

/* ---------- Stage ---------- */
.center { display: grid; grid-template-rows: minmax(0, 1fr) auto; min-width: 0; min-height: 0; }
.stage { position: relative; display: grid; place-items: center; min-height: 0; padding: 20px;
  background: radial-gradient(circle at 50% 40%, #181b25, var(--bg)); }
.stage { container-type: size; }
.stage canvas { max-width: 100cqw; max-height: 100cqh; width: auto; height: auto; border-radius: 6px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.stage.drag { outline: 2px dashed var(--brand); outline-offset: -10px; }
.drop-hint { position: absolute; inset: 0; display: none; place-items: center; background: rgba(14,16,21,.7); font-size: 18px; font-weight: 600; pointer-events: none; }
.stage.drag .drop-hint { display: grid; }

.film { display: flex; gap: 10px; padding: 12px 14px; overflow-x: auto; background: var(--panel); border-top: 1px solid var(--line); align-items: flex-start; }
.thumb { position: relative; flex: 0 0 auto; width: 70px; border: 2px solid transparent; border-radius: 8px; cursor: pointer; background: var(--panel-2); padding: 3px; }
.thumb canvas { display: block; width: 100%; height: auto; border-radius: 5px; }
.thumb.on { border-color: var(--brand); }
.thumb.over { border-color: #fff; }
.thumb .no { position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; border-radius: 4px; padding: 0 5px; }
.thumb .acts { position: absolute; right: 4px; top: 4px; display: none; gap: 3px; }
.thumb:hover .acts, .thumb:focus-within .acts { display: flex; }
.thumb .acts button { width: 22px; height: 22px; border: 0; border-radius: 5px; background: rgba(0,0,0,.7); color: #fff; cursor: pointer; font-size: 12px; line-height: 1; }
.thumb .acts button:hover { background: var(--brand); }
.add-tile { flex: 0 0 auto; width: 70px; min-height: 120px; align-self: stretch; display: grid; place-items: center; text-align: center; border: 2px dashed var(--line); border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; padding: 4px; }
.add-tile:hover { border-color: var(--brand); color: var(--text); }
.add-tile b { display: block; font-size: 22px; line-height: 1; }

.imgbox { display: flex; gap: 10px; align-items: center; margin-bottom: 4px; }
.imgbox img { width: 56px; height: 100px; object-fit: cover; object-position: top; border-radius: 8px; border: 1px solid var(--line); }
.imgbtns { display: flex; flex-direction: column; gap: 8px; }

/* ---------- Dialogs ---------- */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(480px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.6); }
.dlg { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.dlg h2 { margin: 0; font-size: 18px; }
.dlg label, .dlg .field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 12.5px; }
.dlg-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.plist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }
.plist li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; }
.plist li.cur { border-color: var(--brand); }
.plist .info { flex: 1; min-width: 0; }
.plist .info b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plist .info small { color: var(--muted); }
.checks { display: flex; flex-direction: column; gap: 8px; }
.check-head { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-top: 6px; }
.checks label { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-size: 14px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #000; color: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; z-index: 50; max-width: calc(100vw - 32px); }

/* ---------- Trang dự án ---------- */
.page-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 22px; margin: 0; }
.page-head .hint { margin: 0; flex-basis: 100%; }
.page-head input[type=search] { width: 240px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
.page-body { max-width: 1680px; margin: 0 auto; padding: 24px 16px 60px; }
.pgrid.tgrid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 450px), 1fr)); gap: 20px; }
.tgrid .pthumb { min-height: 0; padding: 12px 8px; }
.tgrid .pthumb canvas { max-height: none; }
.tcard { cursor: default; }
.tcard .pthumb { cursor: pointer; }
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; }
.pcard { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.pcard.cur { border-color: var(--brand); }
.pthumb { border: 0; padding: 0; background: var(--panel-2); border-radius: 10px; cursor: pointer; overflow: hidden; display: grid; place-items: center; min-height: 160px; }
.pthumb canvas { display: block; width: 100%; height: auto; max-height: 360px; object-fit: contain; }
.pinfo b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pinfo small { color: var(--muted); font-size: 12px; }
.pacts { display: flex; gap: 8px; }
.pacts { align-items: center; }
.pacts > .btn.primary { flex: 1; height: 36px; padding: 0 14px; font-size: 14px; font-weight: 700; }
.kebab { background: transparent; border-color: transparent; width: 36px; height: 36px; padding: 0; display: grid; place-items: center; font-size: 22px; line-height: 1; color: var(--muted); }
.kebab:hover, .kebab[aria-expanded="true"] { background: transparent; border-color: transparent; color: var(--text); }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 5; min-width: 170px; padding: 4px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px rgba(0,0,0,.5); }
.menu button { display: block; width: 100%; text-align: left; background: transparent; border: 0; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover, .menu button:focus-visible { background: var(--line); }
.menu .danger { color: #ff8585; }
.empty { background: var(--panel); border: 1px dashed var(--line); border-radius: 14px; padding: 28px; max-width: 640px; }
.empty p { margin: 0 0 16px; color: var(--muted); }
.empty b { color: var(--text); }
.quick { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .editor { display: block; overflow-y: auto; }
  .topbar { flex-wrap: wrap; padding: 10px 14px; }
  #appbar, .editorbar { height: auto; min-height: 52px; }
  .layout { grid-template-columns: 1fr; }
  .center { order: -1; }
  .stage { height: 70vh; }
  .panel.left, .panel.right { border: 0; border-top: 1px solid var(--line); }
  .panel.left { padding: 0; }
}

/* ---------- Bộ lọc category ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; flex-basis: 100%; margin-top: 4px; }
.chip { background: var(--panel); border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 6px 14px; cursor: pointer; font-size: 13px; }
.chip:hover { color: var(--text); border-color: #3a4156; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }

/* Ô chọn dạng checkbox trong panel */
.panel label.check { flex-direction: row; align-items: flex-start; gap: 10px; color: var(--text); font-size: 13px; cursor: pointer; }
.panel label.check input { margin-top: 2px; width: 16px; height: 16px; accent-color: var(--brand); flex: none; }

/* ---------- Editor: tab 3 cột, lớp phủ kéo thả, panel layout ---------- */
.tabs.three { grid-template-columns: repeat(3, 1fr); }
.stage canvas#overlay { position: absolute; max-width: none; max-height: none; background: transparent; box-shadow: none; border-radius: 0; touch-action: none; }
.panel hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.subhead { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 10px; }
.hint.tight { margin: 0 0 12px; }
.hint.tight b { color: var(--text); }
.btn.block { width: 100%; }
.btnrow { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.btnrow .btn { padding: 5px 9px; font-size: 12.5px; }
.btnrow .btn:disabled { opacity: .4; cursor: default; }
.chips.tiny { gap: 6px; flex-basis: auto; margin: 0; }
.chips.tiny .chip { min-width: 34px; padding: 5px 10px; text-align: center; }
.colors.two { grid-template-columns: repeat(2, 1fr); }

/* ---------- Trang chủ ---------- */
.home { max-width: 1180px; margin: 0 auto; padding: 40px 20px 80px; }
.hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 40px; align-items: center; }
.eyebrow { display: inline-block; padding: 5px 12px; border-radius: 999px; background: rgba(109,91,255,.16); color: #b3a9ff; font-size: 13px; font-weight: 600; margin-bottom: 18px; }
.hero h1 { font-size: clamp(32px, 4.4vw, 52px); line-height: 1.08; letter-spacing: -1px; margin: 0 0 16px; }
.lead { color: var(--muted); font-size: 17px; line-height: 1.6; margin: 0 0 24px; max-width: 520px; }
.cta-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 22px; }
.btn.big { padding: 12px 20px; font-size: 15px; font-weight: 600; border-radius: 10px; }
.ticks { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 22px; color: var(--muted); font-size: 14px; }
.ticks li::before { content: '✓'; color: #5fe0a4; margin-right: 7px; font-weight: 800; }
.hero-art { min-width: 0; padding: 14px; border-radius: 20px; background: radial-gradient(circle at 50% 30%, #1d2130, var(--panel)); border: 1px solid var(--line); }
.hero-art canvas { display: block; width: 100%; height: auto; border-radius: 10px; }
.section-title { font-size: 26px; letter-spacing: -.4px; margin: 72px 0 24px; }
.features { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.feature { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; }
.feature svg { width: 30px; height: 30px; fill: none; stroke: #9b8cff; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; margin-bottom: 14px; }
.feature h3 { margin: 0 0 6px; font-size: 17px; }
.feature p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.55; }
.steps { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.steps li { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; display: flex; flex-direction: column; gap: 6px; }
.steps b { font-size: 17px; }
.steps span { color: var(--muted); font-size: 14px; line-height: 1.55; }
.final-cta { margin-top: 72px; padding: 40px 20px; text-align: center; border-radius: 20px; background: linear-gradient(135deg, rgba(109,91,255,.28), rgba(42,167,255,.16)); border: 1px solid var(--line); }
.final-cta h2 { margin: 0 0 18px; font-size: 26px; letter-spacing: -.4px; }
@media (max-width: 900px) { .hero { grid-template-columns: 1fr; } }

/* Nhóm style riêng của slide */
.ovr { border: 1px solid var(--line); border-radius: 10px; padding: 10px 10px 2px; margin-bottom: 10px; }
.ovr.on { border-color: rgba(109,91,255,.55); background: rgba(109,91,255,.06); }
.ovr > label.check { margin-bottom: 10px; }
.ovr input[type=color] { width: 100%; height: 32px; padding: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; }
.ovr .imgbox img { width: 44px; height: 64px; }
.chips.tiny .chip { white-space: nowrap; }
.seg button:disabled { opacity: .55; cursor: default; }

/* ---------- Panel cài đặt (trái: dự án, phải: màn hình) ---------- */
.panel.left { padding: 14px; }
.panel-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 12px; }
.psec { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.psec:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.psec h4 { margin: 0 0 10px; font-size: 13px; color: var(--text); }
.panel .field > .seg { align-self: stretch; }
.panel .field > .seg button { flex: 1; }
.tgroup { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 10px 0; margin-bottom: 10px; }
.tgroup-title { font-size: 12px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.focusbox { background: rgba(109,91,255,.07); border: 1px solid rgba(109,91,255,.45); border-radius: 10px; padding: 10px 10px 0; margin-bottom: 10px; }
.film .thumb .nm { display: block; font-size: 10.5px; color: var(--muted); text-align: center; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.film .thumb.on .nm { color: var(--text); }

/* Gradient nhiều điểm */
.gwrap { position: relative; height: 34px; margin: 4px 8px 6px; }
.gbar { position: absolute; inset: 6px 0; border-radius: 6px; border: 1px solid var(--line); cursor: copy; }
.gmarks { position: absolute; inset: 0; pointer-events: none; }
.gmark { position: absolute; top: 0; width: 16px; height: 34px; margin-left: -8px; border-radius: 6px; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.5); cursor: ew-resize; pointer-events: auto; padding: 0; }
.gmark.on { outline: 2px solid var(--brand); outline-offset: 2px; }
.gstop { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; margin-bottom: 2px; }
.gstop .btn { margin-bottom: 14px; }
.delstop { width: 34px; height: 34px; }
.delstop:disabled { opacity: .35; cursor: default; }

/* Ô màu khung máy */
.swatches { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin-bottom: 12px; }
.swatch { display: flex; align-items: center; gap: 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; cursor: pointer; color: var(--text); font-size: 12.5px; }
.swatch i { width: 18px; height: 18px; border-radius: 50%; border: 1px solid rgba(255,255,255,.35); flex: none; }
.swatch.on { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }

/* Lưới layout */
.lgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; }
.lgroup { grid-column: 1 / -1; font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.ltile { background: var(--panel-2); border: 2px solid transparent; border-radius: 8px; padding: 3px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--muted); font-size: 10.5px; }
.ltile canvas { width: 100%; height: auto; border-radius: 4px; display: block; }
.ltile:hover { border-color: #3a4156; }
.ltile.on { border-color: var(--brand); color: var(--text); }

/* ---------- Card cài đặt dự án (mở / thu gọn) ---------- */
.pcard-set { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; overflow: hidden; }
.pcard-set > summary { list-style: none; cursor: pointer; padding: 11px 12px; font-size: 13px; font-weight: 700; color: var(--text); display: flex; align-items: center; justify-content: space-between; user-select: none; }
.pcard-set > summary::-webkit-details-marker { display: none; }
.pcard-set > summary::after { content: ''; width: 7px; height: 7px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .15s; margin-right: 4px; }
.pcard-set:not([open]) > summary::after { transform: rotate(-45deg); }
.pcard-set > summary:hover { background: rgba(255,255,255,.03); }
.pcard-set[open] > summary { border-bottom: 1px solid var(--line); }
.pcard-body { padding: 12px; }
.pcard-body .tgroup { background: var(--panel); }
.pcard-body .swatch, .pcard-body select, .pcard-body textarea, .pcard-body input[type=text], .pcard-body .seg { background: var(--panel); }

/* Ô bàn cờ phía sau canvas: chỉ lộ ra ở chỗ nền trong suốt (vd. nền ảnh chưa chọn ảnh) */
#preview, .thumb canvas {
  background-color: #fff;
  background-image: linear-gradient(45deg, #d7dbe3 25%, transparent 25%), linear-gradient(-45deg, #d7dbe3 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d7dbe3 75%), linear-gradient(-45deg, transparent 75%, #d7dbe3 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

/* Ảnh nền xem trước: ô vuông (ảnh nền có thể ngang hoặc dọc) */
.bgedit .imgbox img, .ovr .bgedit .imgbox img, .frimg img { width: 64px; height: 64px; object-fit: cover; object-position: center; }

/* Ô chọn screen size trên thanh editor */
.sizepick { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.sizepick select { max-width: 300px; }
.dlg .checks { max-height: 50vh; overflow-y: auto; }
.bgedit .imgph, .frimg .imgph { width: 64px; height: 64px; flex: none; border: 2px dashed var(--line); border-radius: 8px; background: transparent; cursor: pointer; position: relative; }
.bgedit .imgph::after, .frimg .imgph::after { content: '+'; position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 22px; }
.bgedit .imgph:hover, .frimg .imgph:hover { border-color: var(--brand); }

/* Nút tròn "+" thêm khung, nằm cạnh các khung */
.chips.tiny { align-items: center; }
.addframe { width: 30px; height: 30px; border-radius: 50%; border: 1px dashed var(--brand); background: rgba(109,91,255,.12); color: #c9c1ff; font-size: 18px; line-height: 1; cursor: pointer; display: grid; place-items: center; padding: 0; }
.addframe:hover { background: var(--brand); color: #fff; border-style: solid; }
.addframe:disabled { opacity: .35; cursor: default; }

/* ---------- Ô nhập chữ có định dạng ---------- */
.rtebox { margin-bottom: 14px; }
.rtebox-label { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.rtebox-frame { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); overflow: hidden; }
.rtebox-frame:focus-within { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.rtebar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px; background: var(--panel-2); border-bottom: 1px solid var(--line); }
.rtebar select { width: auto; flex: 1 1 80px; min-width: 0; padding: 5px 7px; font-size: 12.5px; }
.rbtn { width: 30px; height: 30px; padding: 0; display: grid; place-items: center; font-size: 14px; }
.rbtn.on { border-color: var(--brand); background: rgba(109,91,255,.18); }
.panel .rcolor { position: relative; flex-direction: row; justify-content: center; gap: 0; width: 30px; height: 30px; flex: none; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); display: grid; place-items: center; cursor: pointer; margin: 0 !important; }
.rcolor span { position: relative; font-weight: 800; color: var(--text); line-height: 1; font-size: 14px; pointer-events: none; }
.rcolor span::after { content: ''; position: absolute; left: -2px; right: -2px; bottom: -4px; height: 3px; border-radius: 2px; background: var(--c, #ff4d6d); }
.rcolor input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100% !important; height: 100% !important; }
.rte { min-height: calc(1.45em + 16px); padding: 8px 10px; color: var(--text); font-size: 14px; line-height: 1.45; outline: none; white-space: pre-wrap; word-break: break-word; }
.rte.empty::before { content: attr(data-ph); color: var(--muted); font-weight: 400; pointer-events: none; }

/* Dropdown tự vẽ cho font / độ đậm */
.ssel { position: relative; flex: 1 1 80px; min-width: 0; }
.ssel-btn { width: 100%; text-align: left; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 24px 6px 8px; font-size: 12.5px; color: var(--text); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative; }
.ssel-btn::after { content: ''; position: absolute; right: 9px; top: 50%; width: 6px; height: 6px; margin-top: -5px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); }
.pcard-body .ssel-btn { background: var(--panel); padding: 7px 28px 7px 9px; font-size: 13px; }
.ssel-list { position: fixed; z-index: 1000; max-height: 260px; overflow-y: auto; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.5); padding: 4px; display: flex; flex-direction: column; }
.ssel-item { background: transparent; border: 0; border-radius: 6px; padding: 7px 10px; text-align: left; color: var(--text); font-size: 15px; cursor: pointer; white-space: nowrap; }
.ssel-item:hover { background: rgba(255,255,255,.07); }
.ssel-item.on { background: rgba(109,91,255,.25); }
.field > .ssel { flex: none; }
/* Ô ảnh màn hình: nút xoá (chỉ ảnh riêng) nằm trong ảnh; ảnh kế thừa nằm trên nền ô cờ trắng đen, mờ 80% */
.thumbwrap { position: relative; flex: none; line-height: 0; }
.thumbwrap.inherited { background: conic-gradient(#000 25%, #fff 0 50%, #000 0 75%, #fff 0) 0 0 / 12px 12px; border-radius: 8px; }
.thumbwrap.inherited img { opacity: .8; }
.thumbdel { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; padding: 0; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; display: grid; place-items: center; cursor: pointer; }
.thumbdel:hover { background: #e5484d; }
/* Ảnh màn hình của device: khung 3:4, các nút (tải / xoá / cách đặt ảnh) nằm bên phải */
.imgbox.frimg img, .imgbox.frimg .imgph { width: 72px; height: 96px; }
.imgbox.frimg .imgbtns { flex: 1; min-width: 0; }
#frFitField .seg { display: flex; width: 100%; align-self: stretch; }
#frFitField .seg button { flex: 1; padding-left: 4px; padding-right: 4px; }

/* Chế độ thử nghiệm (Beta) */
.beta { font-size: 10px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; color: #fff; background: var(--brand); border-radius: 999px; padding: 2px 7px; }
.beta-note { margin: 0 0 18px; padding: 8px 12px; border: 1px dashed var(--brand); border-radius: 10px; color: var(--muted); font-size: 13px; background: rgba(109,91,255,.08); }

/* Khách (chưa đăng nhập) / đã đăng nhập */
body:not(.authed) [data-auth], body.authed [data-guest] { display: none !important; }

/* Nhãn Free / Pro trên thẻ bản mẫu */
.tbadge { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px; font-size: 10px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; vertical-align: middle; }
.tbadge.free { background: rgba(34,197,94,.18); color: #4ade80; }
.tbadge.pro { background: rgba(109,91,255,.22); color: #b3a8ff; }

/* Tên project chỉ đọc (demo) */
.name[readonly], .name[readonly]:hover, .name[readonly]:focus { border-color: transparent; background: transparent; cursor: default; color: var(--text); }
.dlg label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.dlg label.check input { width: 16px; height: 16px; accent-color: var(--brand); flex: none; }

/* Ảnh mẫu của bản mẫu trong hộp thoại chọn: thanh cuộn nằm trong khung ảnh, cả hộp thoại không cuộn */
#dlgNew, #dlgTemplate { overflow: hidden; width: min(780px, calc(100vw - 32px)); }
#dlgNew .dlg, #dlgTemplate .dlg { max-height: calc(100vh - 48px); }
#dlgNew .dlg .field { flex: 1 1 auto; min-height: 0; }
#dlgNew .dlg .checks { flex: 1 1 auto; min-height: 90px; max-height: none; overflow-y: auto; }
.tplscroll { flex: none; overflow-x: auto; overflow-y: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.tplprev { display: block; width: 100%; min-width: 480px; height: auto; } /* đủ 5 màn hình theo bề ngang hộp thoại; màn hình hẹp thì cuộn ngang */

/* Thư viện ảnh */
#dlgLibrary { width: min(640px, calc(100vw - 32px)); }
.libgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; max-height: 55vh; overflow-y: auto; padding: 2px; }
.libitem { position: relative; line-height: 0; }
.libpick { width: 100%; padding: 0; border: 2px solid transparent; border-radius: 10px; background: var(--panel-2); cursor: pointer; overflow: hidden; }
.libpick:hover { border-color: var(--brand); }
.libpick img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; display: block; }
.libcap { display: flex; flex-direction: column; gap: 1px; margin-top: 4px; line-height: 1.25; font-size: 11px; min-width: 0; }
.libname { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.libdim { color: var(--muted); }

body.in-editor #btnDemo { display: none; }

/* Biểu tượng Pro (vương miện) */
.crown { width: 14px; height: 14px; fill: #fbbf24; flex: none; }
.btn.proable { display: inline-flex; align-items: center; gap: 6px; }
.probadge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; background: rgba(251,191,36,.14); color: #fbbf24; font-size: 11px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; white-space: nowrap; flex: none; }
.pcard { position: relative; }
.card-crown { position: absolute; top: 18px; right: 18px; width: 28px; height: 28px; border-radius: 50%; background: rgba(15,17,21,.78); display: grid; place-items: center; pointer-events: none; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.card-crown .crown { width: 16px; height: 16px; }
.tplwrap { position: relative; flex: none; }
.card-crown.prevcrown { top: 8px; right: 8px; }
.ssel-item .crown, .ssel-btn .crown { margin-left: 6px; vertical-align: -2px; }
#dlgNew .ssel-btn, #dlgTemplate .ssel-btn { font-size: 14px; padding: 8px 28px 8px 10px; }

/* Hộp thoại demo: hai thẻ lựa chọn ở đầu hộp thoại */
.newfields { display: flex; flex-direction: column; gap: 14px; min-height: 0; flex: 1 1 auto; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { display: flex; flex-direction: column; gap: 4px; text-align: left; padding: 12px 14px 12px 40px; position: relative; background: var(--panel-2); border: 2px solid var(--line); border-radius: 12px; color: var(--text); cursor: pointer; font-size: 14px; }
.choice span { color: var(--muted); font-size: 12px; font-weight: 400; }
.choice::before { content: ''; position: absolute; left: 14px; top: 16px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); box-sizing: border-box; }
.choice:hover { border-color: #3a4156; }
.choice.on { border-color: var(--brand); background: rgba(109,91,255,.12); }
.choice.on::before { border-color: var(--brand); background: radial-gradient(circle, var(--brand) 45%, transparent 50%); }
@media (max-width: 560px) { .choices { grid-template-columns: 1fr; } }

/* Nội dung SEO trên trang chủ */
.seo-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px 36px; }
.seo-cols p, .seo-lead { margin: 0; color: var(--muted); font-size: 15.5px; line-height: 1.7; max-width: 70ch; }
.seo-lead { margin-bottom: 22px; }
.size-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.size-group { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; }
.size-group h3 { margin: 0 0 12px; font-size: 16px; }
.size-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.size-list li { font-size: 12.5px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px; }
.cat-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.faq { display: grid; gap: 10px; max-width: 860px; }
.faq-item { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 0 18px; }
.faq-item summary { cursor: pointer; padding: 15px 0; font-weight: 600; font-size: 15.5px; list-style: none; display: flex; justify-content: space-between; gap: 12px; }
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after { content: '+'; color: var(--muted); font-size: 20px; line-height: 1; }
.faq-item[open] summary::after { content: '–'; }
.faq-item p { margin: 0 0 16px; color: var(--muted); font-size: 14.5px; line-height: 1.65; }

/* Trong editor mặc định ẩn header của trang; nút ☰ trên thanh editor để hiện lại */
body.in-editor:not(.show-appbar) #appbar { display: none; }

/* Thông báo Pro miễn phí ở bản beta trong hộp thoại xuất */
.proinfo { display: flex; align-items: flex-start; gap: 10px; margin: 0; padding: 10px 12px; border: 1px dashed rgba(251,191,36,.6); border-radius: 10px; background: rgba(251,191,36,.08); color: var(--text); font-size: 13px; line-height: 1.5; }
.proinfo .crown { margin-top: 2px; }
