/* ================= Xếp Gạch — MonBlock ================= */
:root {
  --bg: #0d1117;
  --panel: #151c26;
  --panel-2: #1b2431;
  --line: #2b3646;
  --txt: #e8eef6;
  --muted: #93a3b8;
  --accent: #ffcf5a;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--txt);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--accent); }
.wrap { max-width: 640px; margin: 0 auto; padding: 8px 14px 28px; }
.screen { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
h2 { font-size: 17px; margin: 18px 0 10px; }
.note { color: var(--muted); font-size: 13px; line-height: 1.5; }
body.touch .no-touch { display: none; }

/* ---------- trang chủ ---------- */
.me-card { display: flex; align-items: center; gap: 14px; padding: 12px 16px 12px 12px; margin: 6px 0 14px; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); }
.me-tile { position: relative; width: 60px; height: 60px; flex: none; border-radius: 12px; overflow: hidden; background: #0d1230; }
.me-tile canvas { display: block; width: 100%; height: 100%; }
.me-tile .me-avemo { position: absolute; inset: 0; display: grid; place-items: center; font-size: 34px; line-height: 1; background: rgba(255, 255, 255, .92); }
.me-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.me-info b { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-info span { color: var(--muted); font-size: 13px; font-weight: 600; }
.xpbar { height: 6px; border-radius: 9px; background: var(--panel-2); overflow: hidden; }
.xpbar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #4f86ff, #46e6f0); border-radius: 9px; }
.me-chips { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; font-size: 14px; font-weight: 700; white-space: nowrap; }

.big { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; margin: 0 0 10px; padding: 15px 18px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); font-size: 17px; font-weight: 800; text-align: left; }
.big small { color: var(--muted); font-size: 13px; font-weight: 600; }
.big-daily.done small { color: #00a862; }
.homegrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 6px; }
.small { padding: 12px 6px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); font-size: 14px; font-weight: 700; }
.small:disabled { opacity: .4; cursor: default; }

/* ---------- chọn kiểu chơi ---------- */
.variants { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; margin-top: 6px; }
.variant { display: flex; align-items: flex-start; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); text-align: left; }
.variant.on { border-color: var(--pri, var(--accent)); box-shadow: inset 0 0 0 1px var(--pri, var(--accent)); }
.variant > i { font-size: 32px; font-style: normal; line-height: 1; }
.variant > i .mbi { display: block; width: 36px; height: 36px; }
#btnSound .mbi { display: block; width: 24px; height: 24px; }
.variant span { display: flex; flex-direction: column; gap: 3px; }
.variant b { font-size: 16px; }
.variant small { color: var(--muted); font-size: 13px; line-height: 1.4; }
.variant em { color: var(--pri, var(--accent)); font-size: 12px; font-style: normal; font-weight: 800; }

/* ---------- đang chơi: toàn màn hình (design system "Đang chơi", 17/11/2026) — thanh trên riêng, giếng nới theo màn, nút dính đáy ---------- */
#scPlay { animation: none; }
#scPlay.screen { position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column; align-items: stretch;
  padding: var(--sat, env(safe-area-inset-top)) var(--sar, env(safe-area-inset-right)) var(--sab, env(safe-area-inset-bottom)) var(--sal, env(safe-area-inset-left));
  /* Home painting behind the well (owner 19/11/2026: play screen matches the home screen), veil = --ds-scene-veil */
  background: linear-gradient(rgba(242, 244, 245, .66), rgba(242, 244, 245, .66)), url(/xepgach/img/home-bg.webp) center / cover no-repeat, #efd9b8; color: #191b1d; overflow: hidden; }
#scPlay.screen.hidden { display: none !important; }
/* What the browser bars uncover while playing takes the scene colour, not the light page grey. */
html.xg-playing, html.xg-playing body { background: #efd9b8 !important; }
.xg-top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: 6px 10px 4px; }
.xg-right { display: flex; justify-content: flex-end; gap: 8px; }
.xg-ib { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 1px solid #e3e5e8; border-radius: 12px; background: #ffffff; color: #191b1d; }
.xg-ib svg { width: 24px; height: 24px; fill: currentColor; }
.xg-ib svg .ln { fill: none; stroke: currentColor; stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
.xg-ib:active { background: #f2f4f5; }
.xg-mode { display: flex; align-items: center; gap: 6px; max-width: 58vw; padding: 6px 12px; border-radius: 999px; border: 1px solid #e3e5e8; background: #ffffff; font-size: 15px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xg-mode .mbi { width: 20px; height: 20px; flex: none; }
.stage { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; touch-action: none; -webkit-user-select: none; user-select: none; }
.stage canvas { display: block; touch-action: none; }
.pad { display: flex; justify-content: space-between; align-items: flex-end; gap: 14px; width: 100%; max-width: 520px; margin: 0 auto; padding: 6px 10px 8px; box-sizing: border-box; touch-action: none; -webkit-user-select: none; user-select: none; }
.pad > div { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pad > .pad-move { flex: 1.25; grid-template-columns: 1fr 1fr 1fr; grid-template-areas: "left soft right"; align-self: end; }
.pad-act { grid-template-areas: "hold hard" "cw cw"; }
.pad [data-act="left"] { grid-area: left; } .pad [data-act="right"] { grid-area: right; } .pad [data-act="soft"] { grid-area: soft; }
.pad [data-act="hold"] { grid-area: hold; } .pad [data-act="hard"] { grid-area: hard; } .pad [data-act="cw"] { grid-area: cw; }
.pad button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: 52px; padding: 0; border: 0; border-radius: 14px;
  border: 1px solid #e3e5e8; background: #ffffff; color: #191b1d; touch-action: none; -webkit-user-select: none; user-select: none; }
.pad button svg { width: 28px; height: 28px; fill: currentColor; }
.pad button svg .ln { fill: none; stroke: currentColor; stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; }
.pad button svg .th { stroke-width: 3.5; }
.pad button small { font-size: 12px; font-weight: 800; }
.pad .b-hold { background: #ffffff; }
.pad .b-drop { border-color: #e5374f; background: #e5374f; color: #ffffff; }
.pad-move button { height: 66px; }
.pad .b-rot { height: 66px; border-color: #335fff; background: #335fff; color: #ffffff; }
.pad-move button svg { width: 32px; height: 32px; }
.pad .b-rot svg { width: 34px; height: 34px; }
.pad button.on, .pad button:active { transform: scale(.96); filter: brightness(.94); }
.keys { margin: 0 0 8px; text-align: center; color: #606368 !important; }
/* Màn ngang thấp: cụm nút di chuyển bên trái, cụm nút hành động bên phải, giếng ở giữa. */
@media (orientation: landscape) and (max-height: 560px) {
  #scPlay.screen { display: grid; grid-template-columns: minmax(210px, 1fr) auto minmax(150px, 1fr); grid-template-rows: auto 1fr; }
  .xg-top { grid-column: 1 / 4; grid-row: 1; padding-top: 4px; }
  .stage { grid-column: 2; grid-row: 2; min-width: 0; padding-bottom: 6px; }
  .pad { display: contents; }
  .pad > div { grid-row: 2; align-self: end; flex: none; width: 150px; padding: 0 12px 12px; }
  .pad > .pad-move { grid-column: 1; justify-self: start; width: 210px; }
  .pad-act { grid-column: 3; justify-self: end; }
  .keys { display: none; }
}

/* ---------- cửa hàng ---------- */
.shop-top { display: flex; justify-content: flex-end; gap: 16px; margin: 4px 0; font-size: 17px; font-weight: 800; }
.gem-chip b { color: #7fd8ff; }
.shop { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.item { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 8px 12px; border: 2px solid var(--line); border-radius: 16px; background: var(--panel); text-align: center; }
.item.locked { opacity: .55; }
.item b { font-size: 14px; }
.item .rar { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; }
.item .act { padding: 2px 8px; border-radius: 6px; font-size: 13px; font-weight: 800; color: var(--muted); }
.item .act.buy { color: var(--accent); }
.gem { color: #7fd8ff; }
canvas.prev { display: block; width: 100%; max-width: 120px; aspect-ratio: 1; border-radius: 10px; }
.buyprev { display: flex; justify-content: center; margin: 4px 0 8px; }
.buyprev canvas.prev { max-width: 180px; }

/* ---------- xếp hạng ---------- */
.tabs { display: flex; gap: 6px; margin: 6px 0 10px; }
.tabs button { flex: 1; padding: 10px 6px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); font-weight: 800; font-size: 14px; }
.tabs button.on { border-color: var(--accent); color: var(--accent); }
.rank .row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.rank .row.me { border-radius: 10px; }
.rank .no { width: 28px; color: var(--muted); font-weight: 800; text-align: center; }
.rank .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.rank .nm small { color: var(--muted); font-weight: 600; }
.rank .sc { font-weight: 900; color: var(--pri, var(--accent)); }

.help { line-height: 1.6; }
.help ul { padding-left: 20px; }

/* ---------- hộp thoại ---------- */
.modal { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 16px; background: rgba(5, 8, 12, .72); }
.dialog { width: min(420px, 100%); max-height: calc(100dvh - 32px); overflow: auto; padding: 18px; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); box-shadow: 0 20px 60px rgba(0, 0, 0, .6); }
.dialog h3 { margin: 0 0 8px; font-size: 20px; }
.dialog p { line-height: 1.5; }
.dialog .score { margin: 4px 0; font-size: 40px; font-weight: 900; text-align: center; color: var(--pri, var(--accent)); }
.dialog .rw { padding-left: 18px; line-height: 1.8; font-weight: 700; }
.dlg-btns { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.dlg-btns button { padding: 10px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); font-weight: 800; }
.dlg-btns button.pri { border-color: var(--accent); background: var(--accent); color: #1c1608; }
.toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 90; transform: translateX(-50%); padding: 10px 16px; border-radius: 12px; background: #222c3a; font-weight: 700; box-shadow: 0 8px 24px rgba(0, 0, 0, .5); }
.updatebar { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 45; display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel-2); }
.updatebar button { padding: 8px 12px; border: 0; border-radius: 10px; background: var(--accent); color: #1c1608; font-weight: 800; }

/* Limited event item tag (sdk/events.js) */
.evtag { display: inline-block; margin: 2px 0; padding: 1px 8px; border-radius: 999px; background: linear-gradient(90deg, #4fa8ff, #7a6bff); color: #fff; font-size: 11px; font-style: normal; font-weight: 800; }

/* ===== Trang chủ tranh vẽ (design system 17/11/2026 — bố cục chuẩn: ‹ trên trái, loa + sách trên phải, logo + CHƠI, 4 ô đáy) ===== */
#scHome { position: fixed; inset: 0; z-index: 5; overflow: hidden; padding: 0; max-width: none; background: #efd9b8; animation: none; container-type: size; }
#scHome .hm-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center top; }
body:has(#scHome:not(.hidden)) .mb-nav { display: none !important; }
#scHome button { -webkit-appearance: none; appearance: none; font-family: inherit; }
.hm-back, .hm-gear { position: absolute; top: max(10px, env(safe-area-inset-top)); width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; padding: 0; box-shadow: 0 3px 6px rgba(0, 0, 0, .35); }
.hm-back { left: max(10px, env(safe-area-inset-left)); background: #fff; border: 3px solid #e3e5e8; color: #191b1d; font: 700 28px/1 system-ui; padding-bottom: 4px; }
.hm-gear { right: max(10px, env(safe-area-inset-right)); border-radius: 12px; background: linear-gradient(#5ab4ff, #2a6fd8); border: 3px solid #e8f7ff; color: #fff; }
.hm-gear svg { width: 26px; height: 26px; display: block; }
.hm-mute { display: none; position: absolute; left: 7px; right: 7px; top: 50%; height: 3px; background: #ff4d4d; border-radius: 2px; transform: rotate(-45deg); }
.hm-gear.off .hm-mute { display: block; }
.hm-book { top: calc(max(10px, env(safe-area-inset-top)) + 54px); border-radius: 50%; }
.hm-top { position: absolute; left: calc(max(10px, env(safe-area-inset-left)) + 52px); top: max(10px, env(safe-area-inset-top)); display: flex; align-items: center; gap: 8px; }
.hm-av { position: relative; flex: none; width: 52px; height: 52px; padding: 0; border-radius: 50%; border: 3px solid #d8a13a; background: #fff3d6; display: grid; place-items: center; box-shadow: 0 3px 6px rgba(0, 0, 0, .35); cursor: pointer; }
.hm-av .me-avemo { position: absolute; inset: 0; display: grid; place-items: center; font-size: 28px; line-height: 1; border-radius: 50%; overflow: hidden; color: var(--px, #e5484d); font-weight: 900; }
.hm-lv { position: absolute; left: 50%; bottom: -9px; transform: translateX(-50%); padding: 1px 8px; border-radius: 8px; background: #7a4a1c; border: 2px solid #d8a13a; color: #fff; font: 900 12px/1.2 system-ui, sans-serif; white-space: nowrap; }
.hm-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.hm-xp, .hm-pts { display: none; }
.hm-bar { display: flex; align-items: center; gap: 4px; min-width: 84px; height: 32px; padding: 0 10px 0 4px; border-radius: 16px; background: rgba(20, 60, 90, .78); border: 2px solid rgba(255, 255, 255, .55); }
.hm-bar img { width: 24px; height: auto; flex: none; }
.hm-bar b { flex: 1; color: #fff !important; font: 900 14px/1 system-ui, sans-serif; text-align: center; }
.hm-stack { position: absolute; left: 0; right: 0; top: calc(max(10px, env(safe-area-inset-top)) + 64px); bottom: 150px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.6cqh; padding: 0 5cqw; }
.hm-logo { flex: 0 1 auto; min-height: 0; max-height: 16cqh; max-width: 84cqw; width: auto; height: auto; filter: drop-shadow(0 5px 6px rgba(0, 0, 0, .3)); pointer-events: none; }
.hm-hero { flex: 0 1 auto; min-height: 0; max-height: 28cqh; max-width: 72cqw; width: auto; height: auto; filter: drop-shadow(0 6px 6px rgba(0, 0, 0, .25)); pointer-events: none; }
.hm-play { flex: none; width: min(70cqw, 330px); padding: 1.2cqh 3cqw 1.4cqh; border-radius: 999px; text-align: center; color: #fff; background: linear-gradient(#8aea5a, #2fae2a 60%, #238a22); border: 4px solid #fff5cf; box-shadow: 0 5px 0 #1b6b1a, 0 9px 12px rgba(0, 0, 0, .35); }
.hm-play b { display: block; font: 900 clamp(26px, 5.2cqh, 44px)/1.05 "Arial Rounded MT Bold", system-ui, sans-serif; -webkit-text-stroke: .12em #1d6a1d; paint-order: stroke fill; letter-spacing: 2px; }
.hm-play small { display: block; font: 900 clamp(12px, 1.8cqh, 15px)/1.2 system-ui, sans-serif; -webkit-text-stroke: .2em #1d6a1d; paint-order: stroke fill; }
.hm-play:active, .hm-ic:active { transform: scale(.96); }
.hm-row { position: absolute; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; gap: 2cqw; }
.hm-ic { position: relative; width: min(21cqw, 96px); padding: 0; background: none; border: 0; box-shadow: none; color: #fff; }
.hm-ic img { width: 100%; height: auto; aspect-ratio: 1; object-fit: contain; display: block; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .4)); }
.hm-ic span { display: block; margin-top: -2px; text-align: center; font: 900 clamp(12px, 1.7cqh, 14px)/1.1 system-ui, sans-serif; -webkit-text-stroke: .22em #4a2a14; paint-order: stroke fill; white-space: nowrap; }
.hm-dot { position: absolute; top: 2px; right: 2px; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px; background: #e5374f; border: 2px solid #fff; color: #fff; font: 900 12px/18px system-ui; font-style: normal; }
.hm-dot.hidden { display: none; }
#scHome .hm-seo { position: absolute !important; width: 1px !important; height: 1px !important; margin: 0 !important; padding: 0 !important; overflow: hidden !important; clip: rect(0 0 0 0) !important; white-space: nowrap !important; }
#scBook a.bk-link { display: flex; align-items: center; min-height: 44px; padding: 8px 16px; border: 1px solid var(--skin-card-line, #e3e5e8); border-radius: 12px; background: var(--skin-card, #f7f8f9); color: var(--skin-ink, #191b1d); font-size: 15px; font-weight: 700; text-decoration: none; }
#scBook .bk-list, #scModes { display: flex; flex-direction: column; gap: 8px; }
#scModes .big { margin: 0; }
#scHelp .help ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; font-size: 15px; line-height: 1.4; }
/* Xếp Gạch: guest avatar = the home hero block stack; Nhiệm vụ = today's challenge card */
.hm-av .hm-avimg { position: absolute; inset: 6px; width: calc(100% - 12px); height: calc(100% - 12px); object-fit: contain; }
.hm-av:has(.me-avemo:not(.hidden)) .hm-avimg { display: none; }
#questDot { min-width: 16px; width: 16px; height: 16px; padding: 0; top: 6px; right: 10px; }
#scQuest { display: flex; flex-direction: column; gap: 10px; }
#scQuest .big { margin: 0; }
#scQuest .note { margin: 0; font-size: 14px; }
.qd-card { display: flex; flex-direction: column; gap: 4px; padding: 12px 16px; border: 1px solid #e3e5e8; border-radius: 12px; background: #f7f8f9; }
.qd-card b { font-size: 16px; }
.qd-card small { color: #606368; font-size: 14px; line-height: 1.4; }
.qd-done { margin: 4px 0 0; color: #00a862; font-size: 14px; font-weight: 800; }
/* Khung ngang thấp (điện thoại cầm ngang 844×390): logo + hình chính to hơn, gọn giữa thanh trên và 4 ô (như Người Que) */
@container (orientation: landscape) {
  .hm-stack { top: calc(max(10px, env(safe-area-inset-top)) + 58px); bottom: calc(max(10px, env(safe-area-inset-bottom)) + min(11cqw, 22cqh) + 22px); gap: 1.2cqh; }
  .hm-logo { max-height: 19cqh; max-width: 46cqw; }
  .hm-hero { max-height: 25cqh; max-width: 40cqw; }
  .hm-play { width: min(46cqw, 340px); padding: 0.8cqh 3cqw 1cqh; }
  .hm-play small { white-space: nowrap; font-size: clamp(12px, 3.2cqh, 15px); }
  .hm-play b { font-size: clamp(24px, 7cqh, 40px); }
  .hm-row { bottom: max(10px, env(safe-area-inset-bottom)); gap: 1.6cqw; }
  .hm-ic { width: min(11cqw, 22cqh, 96px); }
  .hm-ic span { font-size: clamp(12px, 3.2cqh, 14px); }
}
/* Home painting behind every other screen too (shop, leaderboard…), shared rule in sdk/game-light.css */
body.mb-light { --mb-scene: url(/xepgach/img/home-bg.webp); --mb-scene-on: ''; --muted: #4c4f54; }
.item.locked { opacity: .6; }
.small:disabled { opacity: .6; }

/* Sheet skin "wood": small sheets take the colours of the painted home (owner 30/11/2026). */
body.mb-light { --skin-frame: #6b3d17; --skin-head: linear-gradient(#93592a, #6b3d17); --skin-head-ink: #fff3d6; --skin-line: #d8a13a;
  --skin-paper: #f4e6c6; --skin-card: #fffaf0; --skin-card-line: #d6b886; --skin-ink: #3a1d0c; --skin-muted: #765536; --skin-hover: #fff3dc; }
