:root {
  color-scheme: light;
  /* Giao diện sáng, thân thiện (kiểu Poki): nền xanh nhạt, thẻ trắng bo tròn, màu tươi */
  --bg: #f2f7ff;
  --bg-2: #e8f0fb;
  --surface: #ffffff;
  --surface-2: #eef3fb;
  --border: #dde6f3;
  --text: #14213d;
  --muted: #5b6b86;
  --comment: #8a98b3;
  --primary: #2f80ed;
  --primary-ink: #ffffff;
  --accent: #2bb673;
  --pink: #ff5a5f;
  --cyan: #1a73d9;
  --orange: #f08c00;
  --yellow: #ffcc33;
  --danger: #e5484d;
  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 6px 18px rgba(20, 33, 61, .10);
  --shadow-hover: 0 14px 28px rgba(20, 33, 61, .18);
  --font: Nunito, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, Menlo, monospace;
  --bounce: cubic-bezier(.3, 1.6, .6, 1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}
a { color: var(--cyan); }
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; font-weight: 900; }
.container { width: 100%; max-width: 1280px; margin: 0 auto; padding: 0 16px; flex: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Nút ---------- */
.btn {
  font: inherit; font-weight: 800; font-size: .95rem;
  border: 0; border-radius: 999px;
  padding: .55em 1.2em; cursor: pointer; color: var(--text);
  background: var(--surface-2);
  transition: transform .12s var(--bounce), background .15s ease, opacity .15s, box-shadow .15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: #e1eaf7; transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.btn:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.btn-primary { background: var(--yellow); color: #3a2a00; box-shadow: 0 4px 0 #d9a400; }
.btn-primary:hover { background: #ffd54f; }
.btn-primary:active { box-shadow: 0 2px 0 #d9a400; transform: translateY(2px); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-icon { padding: .55em .8em; }
.btn.active { background: var(--primary); color: #fff; }

/* ---------- Header / Footer ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  box-shadow: 0 2px 10px rgba(20, 33, 61, .06);
}
.header-inner {
  max-width: 1280px; margin: 0 auto; padding: 8px 16px;
  display: flex; align-items: center; gap: 16px;
}
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); flex: none; }
.logo-icon { width: 46px; height: 46px; flex: none; display: block; transition: transform .2s var(--bounce); }
.logo:hover .logo-icon { transform: rotate(-8deg) scale(1.06); }
.logo-text { display: flex; flex-direction: column; line-height: 1.05; }
.logo-name { font-weight: 900; font-size: 1.55rem; letter-spacing: -.02em; }
.logo-name .m1 { color: #f5942e; }
.logo-name .m2 { color: #2f80ed; }
.logo-slogan { font-size: .74rem; font-weight: 800; color: var(--muted); white-space: nowrap; }
.nav { display: flex; gap: 6px; }
.nav a { color: var(--muted); text-decoration: none; font-weight: 800; font-size: .95rem; padding: .4em .8em; border-radius: 999px; }
.nav a:hover { color: var(--text); background: var(--surface-2); }
.site-search { flex: 1; max-width: 420px; margin-left: auto; position: relative; }
.site-search input {
  width: 100%; font: inherit; font-weight: 700; font-size: .95rem; color: var(--text);
  background: var(--surface-2); border: 2px solid transparent; border-radius: 999px;
  padding: .6em 1em .6em 2.6em; outline: none; transition: border-color .15s, background .15s;
}
.site-search input:focus { border-color: var(--primary); background: #fff; }
.site-search::before { content: '🔍'; position: absolute; left: .9em; top: 50%; transform: translateY(-50%); font-size: .95rem; pointer-events: none; }
.header-tools { display: flex; align-items: center; gap: 8px; }
.header-tools .btn { padding: .45em .9em; font-size: .85rem; }
.lang-picker { position: relative; }
.lang-btn {
  font: inherit; font-weight: 800; font-size: .9rem; color: var(--text);
  background: var(--surface-2); border: 0;
  border-radius: 999px; padding: .5em .9em; cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px;
  -webkit-tap-highlight-color: transparent;
}
.lang-btn:hover { background: #e1eaf7; }
.lang-btn:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.lang-caret { color: var(--muted); font-size: .75rem; }
.lang-code { display: none; font-weight: 800; }
.flag {
  display: inline-block; width: 22px; height: 15px; flex: none;
  border-radius: 3px; overflow: hidden; box-shadow: 0 0 0 1px rgba(20, 33, 61, .12);
}
.flag svg { display: block; width: 100%; height: 100%; }
.lang-menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 40;
  list-style: none; margin: 0; padding: 6px; min-width: 190px;
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-hover);
}
.lang-menu[hidden] { display: none; }
.lang-menu li {
  display: flex; align-items: center; gap: 10px; font-weight: 700;
  padding: .55em .7em; border-radius: 10px; cursor: pointer; white-space: nowrap;
}
.lang-menu li:hover, .lang-menu li:focus { background: var(--surface-2); outline: none; }
.lang-menu li[aria-selected="true"] { color: var(--primary); font-weight: 900; }
@media (max-width: 480px) {
  .lang-name { display: none; }
  .lang-code { display: inline; }
}
.site-footer { margin-top: 40px; color: var(--muted); font-size: .92rem; background: var(--surface); }
.footer-inner { max-width: 1280px; margin: 0 auto; padding: 24px 16px 30px; text-align: center; }
.footer-slogan { font-size: 1.15rem; font-weight: 900; color: var(--text); margin: 0 0 10px !important; }
.footer-slogan::before { content: '🎮 '; }
.footer-nav { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 20px; margin-bottom: 8px; font-weight: 800; }
.footer-nav a { color: var(--muted); text-decoration: none; }
.footer-nav a:hover { color: var(--primary); }
.footer-inner p { margin: 0; }

@media (max-width: 860px) {
  .nav { display: none; }
}
@media (max-width: 640px) {
  .header-inner { gap: 10px; flex-wrap: wrap; padding: 8px 12px; }
  .logo-icon { width: 40px; height: 40px; }
  .logo-name { font-size: 1.3rem; }
  .logo-slogan { font-size: .68rem; }
  .header-tools { margin-left: auto; }
  .site-search { order: 3; flex: 1 0 100%; max-width: none; }
  .site-search input { padding-top: .45em; padding-bottom: .45em; }
  /* trang chơi game: đầu trang cao 2 hàng nên không dính, tránh che bàn chơi */
  body[data-page="game"] .site-header { position: static; }
}

/* ---------- Trang chủ ---------- */
.home-hero {
  position: relative; display: flex; align-items: flex-end; overflow: hidden;
  min-height: 300px; margin: 18px 0 6px; border-radius: 26px; color: #fff; text-decoration: none;
  box-shadow: 0 10px 30px rgba(20, 33, 61, .18); background: #24324d;
}
.home-hero img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: transform .6s ease; }
.home-hero:hover img { transform: scale(1.04); }
.home-hero::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(10, 20, 45, .88), rgba(10, 20, 45, .15) 72%); }
.home-hero .hero-tx { position: relative; z-index: 1; padding: 28px; max-width: 560px; }
.home-hero h2 { margin: 8px 0 6px; font-size: clamp(1.7rem, 4vw, 2.5rem); line-height: 1.05; }
.home-hero p { margin: 0 0 16px; font-weight: 700; opacity: .92; }
.hero-tag { display: inline-block; background: var(--pink); border-radius: 999px; padding: 3px 12px; font-weight: 900; font-size: .78rem; letter-spacing: .02em; }
.hero-play { display: inline-block; background: var(--yellow); color: #3a2a00; font-weight: 900; font-size: 1.15rem; padding: 12px 30px; border-radius: 999px; box-shadow: 0 5px 0 #d9a400; transition: transform .15s var(--bounce); }
.home-hero:hover .hero-play { transform: translateY(-2px) scale(1.04); }
.home-intro { color: var(--text); font-weight: 900; margin: 12px 2px 0; font-size: 1.2rem; line-height: 1.25; }
.home-sub { color: var(--muted); font-weight: 700; margin: 4px 2px 0; font-size: .95rem; }
/* Danh sách link viết sẵn cho máy tìm kiếm (JS thay bằng thẻ game ngay khi chạy) */
.seo-links { columns: 2 220px; padding-left: 1.2em; font-weight: 700; }

/* Lọc theo loại game */
.home-chips { display: flex; gap: 10px; margin: 18px 0 4px; overflow-x: auto; padding: 4px 2px 8px; scrollbar-width: none; }
.home-chips::-webkit-scrollbar { display: none; }
.home-chips .chip {
  flex: none; display: inline-flex; align-items: center; gap: 8px;
  font: inherit; font-weight: 900; font-size: .95rem; color: var(--text);
  background: var(--surface); border: 0; border-radius: 999px;
  padding: 7px 16px 7px 7px; cursor: pointer; box-shadow: 0 3px 8px rgba(20, 33, 61, .08);
  transition: transform .15s var(--bounce), background .15s; -webkit-tap-highlight-color: transparent;
}
.home-chips .chip:hover { transform: translateY(-2px); }
.home-chips .chip i { font-style: normal; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 1.05rem; background: var(--surface-2); }
.home-chips .chip .n { font-size: .78rem; color: var(--muted); font-weight: 800; }
.home-chips .chip[aria-pressed="true"] { background: var(--primary); color: #fff; }
.home-chips .chip[aria-pressed="true"] i { background: rgba(255, 255, 255, .25); }
.home-chips .chip[aria-pressed="true"] .n { color: rgba(255, 255, 255, .85); }
.home-chips .chip:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

.home-section { margin: 14px 0 6px; }
.home-section h2, .home-all { font-size: 1.35rem; margin: 18px 0 10px; display: flex; align-items: center; gap: 8px; }
.section-sub { color: var(--muted); margin: 0 0 12px; }
.home-empty { color: var(--muted); font-weight: 800; text-align: center; padding: 30px 0; }
.row-scroll {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(200px, 1fr);
  gap: 14px; overflow-x: auto; padding: 4px 2px 14px; scroll-snap-type: x mandatory; scrollbar-width: thin;
}
.row-scroll .game-card { scroll-snap-align: start; }
@media (max-width: 560px) { .row-scroll { grid-auto-columns: 62%; } }

.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  margin: 6px 0 20px;
}
.grid-small { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
@media (max-width: 480px) {
  .grid, .grid-small { grid-template-columns: repeat(2, 1fr); gap: 12px; }
}
.game-card {
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--radius); overflow: hidden;
  text-decoration: none; color: var(--text);
  box-shadow: 0 5px 14px rgba(20, 33, 61, .08);
  transition: transform .18s var(--bounce), box-shadow .18s;
}
.game-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-hover); }
.game-card:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }
.game-card-art {
  aspect-ratio: 16 / 10; position: relative;
  display: grid; place-items: center;
  font-size: clamp(2.2rem, 8vw, 3rem);
  background: var(--bg-2);
}
.game-card-art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .3s ease; }
.game-card:hover .game-card-art img { transform: scale(1.06); }
.game-card-body { padding: 9px 12px 11px; display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; flex: 1; }
.game-card h3 { font-size: 1rem; margin: 0; font-weight: 900; flex: 1 1 auto; min-width: 0; }
.game-card p { display: none; }
.card-meta { display: flex; flex-wrap: wrap; gap: 4px; font-size: .72rem; font-weight: 800; }
.card-meta span { border-radius: 999px; padding: 1px 8px; }
.card-meta .tag-action { color: #c2410c; background: #ffe7d6; }
.card-meta .tag-board { color: #6a4fd8; background: #efe9ff; }
.card-meta .tag-puzzle { color: #15803d; background: #ddf6e5; }
.card-meta .tag-2p { color: #1a5fbf; background: #e1edff; }
.card-new { position: absolute; top: 8px; left: 8px; z-index: 1; font-size: .72rem; font-weight: 900; color: #fff; background: var(--pink); border-radius: 999px; padding: .15em .7em; }
.badge { flex-basis: 100%; font-size: .74rem; font-weight: 800; color: #b07800; }
.game-card.small h3 { font-size: .95rem; }
.game-card[hidden] { display: none; }

/* ---------- Quảng cáo ---------- */
.ad-slot { margin: 14px auto; text-align: center; max-width: 100%; overflow: hidden; }
.ad-banner { min-height: 90px; }
.ad-side { min-height: 600px; position: sticky; top: 84px; }
.ad-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--comment); margin-bottom: 4px; font-weight: 800; }
.ad-placeholder {
  display: grid; place-items: center;
  border: 2px dashed #d5e0f0; border-radius: var(--radius);
  color: var(--muted); font-size: .85rem; font-weight: 800;
  background: var(--surface);
}
.ad-banner.ad-placeholder { height: 90px; max-width: 728px; }
.ad-side.ad-placeholder { height: 600px; width: 300px; }
.interstitial {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(20, 33, 61, .7);
  display: grid; place-items: center; padding: 16px;
}
.interstitial-box {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-hover);
  padding: 18px; display: flex; flex-direction: column; align-items: center; gap: 12px;
  width: min(360px, 100%);
}
.ad-interstitial { margin: 0; min-height: 250px; width: 100%; }
.ad-interstitial.ad-placeholder { height: 250px; }

/* ---------- Trang game ---------- */
.game-page { padding-top: 0; }
.game-layout {
  display: grid; gap: 24px;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}
.game-side { display: none; }
@media (min-width: 1000px) {
  .game-layout { grid-template-columns: minmax(0, 1fr) 300px; }
  .game-side { display: block; }
}
.game-main {
  background: var(--surface); border-radius: 24px; padding: 12px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center;
}
.game-main:fullscreen { justify-content: center; border-radius: 0; background: #1d2333; overflow: auto; }
.game-head { width: 100%; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.game-head h1 { font-size: 1.45rem; margin: 0; flex: 1; min-width: 0; }
.game-actions { display: flex; gap: 6px; }
.game-actions .btn { padding: .45em 1em; font-size: .9rem; }
.game-stats { width: 100%; display: flex; justify-content: center; gap: 8px; margin: 4px 0 6px; flex-wrap: wrap; }
.stat {
  background: var(--surface-2); border-radius: 14px;
  padding: 4px 14px; min-width: 76px; text-align: center;
  display: flex; flex-direction: column;
}
.stat-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 800; }
.stat-value { font-size: 1.2rem; font-weight: 900; font-variant-numeric: tabular-nums; }

/* Khung chơi: giữ bảng màu tối như trước để các game không đổi màu (game tự vẽ nền riêng) */
.game-stage {
  --bg: #282a36; --bg-2: #21222c; --surface: #2d2f3d; --surface-2: #44475a; --border: #3c3f52;
  --text: #f8f8f2; --muted: #a9adc9; --comment: #6272a4; --primary: #bd93f9; --primary-ink: #21222c;
  --accent: #50fa7b; --pink: #ff79c6; --cyan: #8be9fd; --orange: #ffb86c; --yellow: #f1fa8c; --danger: #ff5555;
  --radius: 8px; --radius-sm: 6px; --shadow: 0 6px 18px rgba(0, 0, 0, .3);
  color-scheme: dark; color: var(--text);
  position: relative; width: 100%; max-width: 520px;
  background: #282a36; border-radius: 18px; padding: 8px;
}
@media (max-width: 560px) { .game-stage { padding: 4px; border-radius: 12px; } }
.game-main:fullscreen .game-stage { border-radius: 0; }
.game-stage .btn { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); font-weight: 700; padding: .5em 1em; box-shadow: none; }
.game-stage .btn:hover { background: #50536a; transform: none; }
.game-stage .btn-primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; box-shadow: none; }
.game-stage .btn-primary:hover { background: #caa6fa; }
.game-stage .btn-ghost { background: transparent; }
.game-stage .btn.active { background: var(--accent); color: var(--primary-ink); border-color: transparent; }
.game-root {
  width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.game-canvas {
  display: block; border-radius: var(--radius-sm);
  background: var(--bg-2);
  touch-action: none;
}
.loading { color: var(--muted); padding: 60px 0; text-align: center; font-weight: 800; }

/* Hộp menu / kết thúc trong game: thẻ trắng bo tròn, nút to vàng (dùng chung cho mọi game) */
.game-overlay {
  position: absolute; inset: 0; z-index: 5;
  display: grid; place-items: center; padding: 16px;
  background: rgba(20, 33, 61, .55);
  border-radius: var(--radius-sm);
  animation: fade-in .2s ease;
}
.game-overlay[hidden] { display: none; }
.overlay-box {
  --bg: #f2f7ff; --bg-2: #e8f0fb; --surface: #ffffff; --surface-2: #eef3fb; --border: #dde6f3;
  --text: #14213d; --muted: #5b6b86; --comment: #8a98b3; --primary: #2f80ed; --primary-ink: #ffffff;
  --accent: #2bb673; --pink: #ff5a5f; --cyan: #1a73d9; --orange: #f08c00; --yellow: #ffcc33; --danger: #e5484d;
  color-scheme: light; color: var(--text); font-family: var(--font);
  background: #fff; border-radius: 22px; box-shadow: 0 16px 40px rgba(0, 0, 0, .3);
  padding: 20px 22px; text-align: center; max-width: 340px; width: 100%;
  animation: pop-in .25s var(--bounce);
}
.overlay-box h2 { font-size: 1.55rem; font-weight: 900; }
.overlay-box p { margin: .3em 0; color: var(--muted); font-weight: 700; }
.overlay-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 16px; }
.game-stage .overlay-box .btn { border: 0; border-radius: 999px; background: var(--surface-2); color: var(--text); font-weight: 800; padding: .55em 1.2em; }
.game-stage .overlay-box .btn:hover { background: #e1eaf7; }
.game-stage .overlay-box .btn-primary { background: var(--yellow); color: #3a2a00; box-shadow: 0 4px 0 #d9a400; font-weight: 900; font-size: 1.05rem; padding: .6em 1.6em; }
.game-stage .overlay-box .btn-primary:hover { background: #ffd54f; }
.game-stage .overlay-box .btn.active { background: var(--primary); color: #fff; }
.game-stage .overlay-box .seg { background: var(--surface-2); border: 0; border-radius: 999px; padding: 3px; }
.game-stage .overlay-box .seg .btn { border-radius: 999px; padding: .35em .9em; font-size: .85rem; background: transparent; box-shadow: none; }
.game-stage .overlay-box .seg .btn.active { background: var(--primary); color: #fff; }
.game-overlay.win h2 { color: var(--accent); }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: scale(.92); } to { opacity: 1; transform: none; } }

/* Tay cầm ảo cho game hành động (trái: hướng, phải: nút bấm) */
.vpad { display: flex; justify-content: space-between; align-items: center; width: 100%; max-width: 560px; padding: 0 4px; touch-action: none; user-select: none; -webkit-user-select: none; }
.vpad-group { display: flex; gap: 10px; }
.vpad .btn { width: 66px; height: 58px; padding: 0; border-radius: 14px; font-size: 1.35rem; touch-action: none; }
.vpad .btn.on { background: var(--accent); color: var(--primary-ink); transform: scale(.95); }

/* Thanh điều khiển dùng chung cho game */
.controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; width: 100%; }
.pad { display: grid; grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(2, 56px); gap: 6px; justify-content: center; }
.pad .btn { border-radius: 12px; font-size: 1.3rem; padding: 0; touch-action: none; }
.seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; gap: 2px; }
.seg .btn { border: 0; padding: .35em .9em; font-size: .85rem; background: transparent; }
.seg .btn.active { background: var(--surface-2); color: var(--text); }

.guide, .page {
  background: var(--surface); border-radius: 24px; box-shadow: var(--shadow);
  padding: 24px 26px; margin: 24px 0;
}
.guide h2 { font-size: 1.4rem; }
.guide-desc { color: #33415c; font-weight: 700; margin-top: 0; }
.guide-body h3 { font-size: 1.1rem; margin-top: 1em; }
#game-about { margin-top: 16px; }
#game-about p { color: #33415c; }
#game-about h3 { font-size: 1.15rem; margin-top: 1.2em; }
#game-about h4 { font-size: 1rem; margin: 1em 0 .25em; }
#game-about h4 + p { margin-top: 0; }
.guide-body p, .guide-body li, .page-body p { color: #33415c; }
.guide-body strong { color: var(--text); }
.guide-body em { color: var(--orange); font-style: normal; font-weight: 800; }
.guide-body ul { padding-left: 1.2em; }
.page { max-width: 780px; margin: 32px auto; }
.page h1 { font-size: 2rem; }
.page-body h2 { font-size: 1.2rem; margin-top: 1.4em; }
.contact-email { font-size: 1.3rem; font-weight: 900; }
.more-games h2 { font-size: 1.35rem; margin-top: 8px; }

@media (max-width: 560px) {
  .game-main { padding: 10px 8px; border-radius: 16px; }
  .game-head h1 { font-size: 1.2rem; }
  .guide, .page { padding: 18px 16px; }
  .ad-banner { min-height: 50px; }
  /* Điện thoại: bỏ banner trên trang game để khung chơi nằm gọn trong màn hình */
  .game-page > .ad-slot[data-ad="top"] { display: none; }
  .ad-banner.ad-placeholder { height: 50px; }
  .home-hero { min-height: 230px; border-radius: 20px; }
  .home-hero .hero-tx { padding: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Điện thoại cầm dọc: nhắc xoay ngang ---------- */
.rotate-tip {
  position: fixed; inset: 0; z-index: 150; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 24px; text-align: center; background: linear-gradient(160deg, #2f80ed, #6a4fd8); color: #fff; font-weight: 900; font-size: 1.25rem;
}
.rotate-tip[hidden] { display: none; }
.rotate-tip p { margin: 0; max-width: 300px; }
.rotate-tip .rotate-sub { font-size: .95rem; font-weight: 700; opacity: .9; }
.rotate-phone { width: 64px; height: 108px; border: 6px solid #fff; border-radius: 14px; position: relative; animation: rot-phone 2.2s ease-in-out infinite; }
.rotate-phone::after { content: ''; position: absolute; left: 50%; bottom: 6px; width: 12px; height: 4px; margin-left: -6px; border-radius: 2px; background: #fff; }
@keyframes rot-phone { 0%, 20% { transform: rotate(0); } 50%, 80% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }
html.rotate-wait body { overflow: hidden; }

/* Số người đang online */
.online-badge { display: inline-flex; align-items: center; gap: 6px; font-weight: 800; font-size: .85rem; color: #15803d; background: #ddf6e5; border-radius: 999px; padding: .35em .8em; white-space: nowrap; }
.online-badge::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .25); }
@media (max-width: 480px) { .online-badge { font-size: .75rem; padding: .3em .6em; } }

/* ---------- Bảng xếp hạng / Facebook ---------- */
.btn-sm { padding: .3em .8em; font-size: .82rem; }
.btn-fb { background: #1877f2; color: #fff; display: inline-flex; align-items: center; gap: .5em; }
.btn-fb:hover { background: #2d86ff; }
.fb-f { font-family: Arial, sans-serif; font-weight: 900; font-size: 1.05em; background: #fff; color: #1877f2; border-radius: 50%; width: 1.25em; height: 1.25em; display: inline-grid; place-items: end center; line-height: 1; overflow: hidden; }
.btn-fb-sm { padding: .35em .75em; font-size: .82rem; }
@media (max-width: 420px) { .btn-fb-sm .fb-label { display: none; } }
.auth-user { display: inline-flex; }
.leaderboard { background: var(--surface); border-radius: 24px; box-shadow: var(--shadow); padding: 18px 20px; margin: 24px 0 0; }
.lb-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.lb-head h2 { font-size: 1.3rem; margin: 0; }
.lb-boards { margin-top: 10px; flex-wrap: wrap; }
.lb-user { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 14px 0 6px; }
.lb-user p { margin: 0; color: var(--muted); flex: 1 1 220px; }
.lb-user .lb-name { font-weight: 800; flex: 1; }
.lb-delete { color: var(--danger); }
.lb-avatar { border-radius: 50%; object-fit: cover; flex: none; background: var(--surface-2); }
.lb-avatar-text { display: inline-grid; place-items: center; font-weight: 900; font-size: .8rem; color: var(--text); }
.lb-list { list-style: none; margin: 8px 0 0; padding: 0; }
.lb-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; }
.lb-row:nth-child(odd) { background: var(--surface-2); }
.lb-row.me { background: #ddf6e5; outline: 2px solid #8fdcaa; }
.lb-rank { width: 2em; text-align: center; font-weight: 900; color: var(--muted); }
.lb-row .lb-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 900; font-variant-numeric: tabular-nums; color: var(--primary); }
.lb-msg { color: var(--muted); padding: 14px 4px; text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 120;
  transform: translate(-50%, 20px); opacity: 0;
  background: var(--text); color: #fff; font-weight: 800;
  border-radius: 999px; padding: .6em 1.3em; box-shadow: var(--shadow-hover);
  transition: opacity .25s, transform .25s; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Tối ưu theo thiết bị (lớp do core.js gắn vào <html>) ---------- */
/* Tiện ích cho game: chỉ hiện khi cảm ứng là chính / khi có chuột-bàn phím */
html:not(.touch-primary) .touch-only { display: none !important; }
html.touch-primary .pointer-only { display: none !important; }
/* Điện thoại: khung chơi sát mép, chữ hướng dẫn dễ đọc hơn */
html.device-mobile .game-page { padding: 8px 8px 0; }
html.device-mobile .game-main { padding: 8px 6px; }
html.device-mobile .guide-body { font-size: 1.02rem; }
html.device-mobile .game-card:hover { transform: none; }
/* Điện thoại xoay ngang: ẩn tiêu đề và header để dành chỗ cho khung chơi */
html.device-mobile.landscape body[data-page="game"] .site-header { position: static; }
html.device-mobile.landscape .game-head h1 { display: none; }
/* Khi mở như app (PWA): chừa vùng tai thỏ */
html.is-standalone .site-header { padding-top: env(safe-area-inset-top); }
html.is-standalone .site-footer { padding-bottom: env(safe-area-inset-bottom); }
/* Máy tính bảng: nút to hơn cho ngón tay */
html.device-tablet .btn { padding: .65em 1.2em; }
html.touch-primary .pad { grid-template-columns: repeat(3, 72px); grid-template-rows: repeat(2, 62px); }
.header-tools .btn { white-space: nowrap; }
@media (max-width: 480px) {
  #install-btn { font-size: 0; padding: .4em .65em; }
  #install-btn::before { content: '⬇'; font-size: 1rem; }
}
