/* ============================================================
   XOAY VÒNG – Rotate & Merge
   ============================================================ */
:root {
  --navy: #22307a;
  --navy-2: #2c43a8;
  --ink: #24335f;
  --muted: #5a6a92;
  --r0: #3b82f6;   /* vùng 1 - xanh dương */
  --r1: #ec4899;   /* vùng 2 - hồng */
  --r2: #22c55e;   /* vùng 3 - xanh lá */
  --r3: #f59e0b;   /* vùng 4 - cam */
  --display: 'Baloo 2', 'Nunito', system-ui, sans-serif;
  --body: 'Nunito', system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--body);
  color: var(--ink);
  background: #bfe3ff linear-gradient(180deg, #86c6ff 0%, #b9e0ff 32%, #e2f3ff 68%, #f1faff 100%) fixed;
  min-height: 100svh;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Phông nền ---------- */
.scenery { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.cloud {
  position: absolute; left: 0; width: 150px; height: 44px; background: #fff; border-radius: 999px;
  opacity: .92; filter: drop-shadow(0 8px 10px rgba(70, 130, 210, .14));
  animation: drift 90s linear infinite;
}
.cloud::before, .cloud::after { content: ""; position: absolute; background: #fff; border-radius: 50%; }
.cloud::before { width: 66px; height: 66px; left: 24px; top: -34px; }
.cloud::after  { width: 50px; height: 50px; left: 76px; top: -22px; }
.c1 { top: 7%;  animation-duration: 110s; animation-delay: -20s; transform: scale(1.15); }
.c2 { top: 22%; animation-duration: 140s; animation-delay: -95s; transform: scale(.8); opacity: .8; }
.c3 { top: 46%; animation-duration: 120s; animation-delay: -60s; transform: scale(1.3); opacity: .7; }
.c4 { top: 68%; animation-duration: 160s; animation-delay: -130s; transform: scale(.9); opacity: .75; }
@keyframes drift { from { translate: -220px 0; } to { translate: calc(100vw + 60px) 0; } }

.sparkle { position: absolute; width: 22px; height: 22px; fill: #fff; filter: drop-shadow(0 0 6px rgba(255,255,255,.9)); animation: twinkle 3s ease-in-out infinite; }
.s1 { top: 4%;  left: 8%; }
.s2 { top: 15%; right: 7%; width: 16px; animation-delay: -1s; fill: #ffe9a6; }
.s3 { top: 52%; left: 4%; width: 14px; animation-delay: -2s; }
.s4 { top: 40%; right: 5%; width: 18px; animation-delay: -1.6s; fill: #ffd6f0; }
@keyframes twinkle { 0%,100% { opacity: .3; transform: scale(.6) rotate(0); } 50% { opacity: 1; transform: scale(1.1) rotate(45deg); } }

.bushes { position: absolute; left: 0; bottom: 0; width: 100%; height: 150px; }

/* ---------- Khung ứng dụng ---------- */
.app {
  position: relative; z-index: 1;
  max-width: 520px; margin: 0 auto;
  padding-block: max(14px, env(safe-area-inset-top)) max(28px, env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  min-height: 100svh;
}
.screen { display: none; flex-direction: column; align-items: center; }
.screen.active { display: flex; animation: screenIn .45s cubic-bezier(.2,.9,.3,1.15) both; }
@keyframes screenIn { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- Tiêu đề viền đậm ---------- */
.outline-title {
  font-family: var(--display); font-weight: 800; color: #fff; margin: 0; line-height: .95; letter-spacing: .3px;
  --o: var(--navy);
  text-shadow:
    4px 0 0 var(--o), 3.7px 1.5px 0 var(--o), 2.8px 2.8px 0 var(--o), 1.5px 3.7px 0 var(--o),
    0 4px 0 var(--o), -1.5px 3.7px 0 var(--o), -2.8px 2.8px 0 var(--o), -3.7px 1.5px 0 var(--o),
    -4px 0 0 var(--o), -3.7px -1.5px 0 var(--o), -2.8px -2.8px 0 var(--o), -1.5px -3.7px 0 var(--o),
    0 -4px 0 var(--o), 1.5px -3.7px 0 var(--o), 2.8px -2.8px 0 var(--o), 3.7px -1.5px 0 var(--o),
    0 8px 0 var(--o), 3px 7px 0 var(--o), -3px 7px 0 var(--o),
    0 12px 14px rgba(20, 40, 120, .35);
}

/* ---------- Logo ---------- */
.logo { display: flex; align-items: center; }
.logo .rot { flex: none; filter: drop-shadow(0 4px 0 rgba(34, 48, 122, .3)); animation: wobble 5s ease-in-out infinite; }
@keyframes wobble { 0%,100% { transform: rotate(-8deg); } 50% { transform: rotate(14deg); } }
.logo.big { gap: 4px; margin-top: 6px; }
.logo.big .rot { width: clamp(78px, 22vw, 112px); height: clamp(78px, 22vw, 112px); }
.logo.big h1 { font-size: clamp(46px, 13.5vw, 72px); }
.logo-text { display: flex; flex-direction: column; align-items: center; }
.plank {
  position: relative; margin-top: 2px; padding: 3px 20px 4px;
  font-family: var(--display); font-weight: 800; font-size: clamp(18px, 5.4vw, 27px); color: #5b2c0a;
  background:
    repeating-linear-gradient(176deg, rgba(150, 80, 20, .0) 0 7px, rgba(150, 80, 20, .1) 7px 9px),
    linear-gradient(180deg, #ffdf96 0%, #f4b553 55%, #dc8d2e 100%);
  border: 3px solid #7a3e10; border-radius: 12px 18px 12px 18px;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.6), 0 4px 0 #7a3e10, 0 9px 12px rgba(90, 45, 0, .25);
  transform: rotate(-2.5deg); text-shadow: 0 1px 0 rgba(255,255,255,.55); white-space: nowrap;
}

.logo.small { gap: 2px; }
.logo.small .rot { width: 44px; height: 44px; }
.logo.small .outline-title { font-size: 30px; --o: var(--navy); text-shadow:
    2.5px 0 0 var(--o), -2.5px 0 0 var(--o), 0 2.5px 0 var(--o), 0 -2.5px 0 var(--o),
    1.8px 1.8px 0 var(--o), -1.8px 1.8px 0 var(--o), 1.8px -1.8px 0 var(--o), -1.8px -1.8px 0 var(--o),
    0 5px 0 var(--o), 0 8px 8px rgba(20,40,120,.3); }

/* ---------- Bong bóng khẩu hiệu ---------- */
.bubble {
  position: relative; display: flex; flex-direction: column; align-items: center;
  margin: 22px 0 6px; padding: 12px 30px 14px;
  background: radial-gradient(120% 90% at 30% 20%, #5b8cf0 0%, #3a63d6 55%, #2b4cb8 100%);
  color: #fff; border-radius: 46px 70px 52px 76px / 52px 44px 64px 46px;
  transform: rotate(-4deg);
  font-family: var(--display); font-weight: 700; font-style: italic; font-size: clamp(17px, 4.8vw, 22px); line-height: 1.15;
  box-shadow: inset 0 3px 0 rgba(255,255,255,.25), 0 10px 22px rgba(40, 70, 180, .3);
  text-shadow: 0 2px 0 rgba(20, 30, 100, .35);
}
.bubble .hl { color: #ffe14d; }
.bubble::after { content: ""; position: absolute; left: 22%; bottom: 8px; width: 56%; height: 3px; border-radius: 3px; background: #ffe14d; opacity: .8; transform: rotate(-1deg); }

/* ---------- Bảng demo trang chủ ---------- */
.demo-wrap { position: relative; width: min(72vw, 300px); margin: 24px 0 18px; animation: bob 4s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.board.demo { width: 100%; padding: 0; box-shadow: 0 0 0 4px #fff, 0 0 0 6px #c8dbff, 0 16px 30px rgba(40, 80, 160, .22); }
.hand {
  position: absolute; font-size: 44px; left: 0; top: 0; pointer-events: none; z-index: 5;
  transition: left .6s cubic-bezier(.4,0,.2,1), top .6s cubic-bezier(.4,0,.2,1);
  filter: drop-shadow(0 4px 4px rgba(0,0,0,.25));
}
.hand.tap { animation: tap .3s ease; }
@keyframes tap { 50% { transform: scale(.82) translateY(4px); } }

.home-actions { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-top: 10px; }
.home-best { margin-top: 18px; font-weight: 800; color: var(--navy); background: rgba(255,255,255,.75); padding: 6px 16px; border-radius: 999px; box-shadow: 0 0 0 2px #fff, 0 4px 10px rgba(40,80,160,.15); }

/* ---------- Nút bấm ---------- */
.btn-yellow, .btn-blue, .btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--display); font-weight: 800; border-radius: 999px;
  transition: transform .1s ease, box-shadow .1s ease, filter .15s;
}
.btn-yellow {
  font-size: clamp(24px, 7vw, 32px); color: #5b2c0a; padding: 12px 46px 8px; min-width: 240px;
  background: linear-gradient(180deg, #fff48a 0%, #ffd626 45%, #ffb300 100%);
  border: 3px solid #fff8d0;
  box-shadow: 0 0 0 3px #f29a00, inset 0 -6px 0 rgba(210, 110, 0, .28), inset 0 4px 0 rgba(255,255,255,.75),
              0 8px 0 #c47500, 0 15px 22px rgba(150, 80, 0, .32);
  text-shadow: 0 2px 0 rgba(255,255,255,.6);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.04); } }
.btn-yellow:active { animation: none; transform: translateY(6px); box-shadow: 0 0 0 3px #f29a00, inset 0 -6px 0 rgba(210,110,0,.28), inset 0 4px 0 rgba(255,255,255,.75), 0 2px 0 #c47500, 0 5px 10px rgba(150,80,0,.3); }
.btn-blue {
  font-size: 22px; color: #fff; padding: 9px 30px 6px; min-width: 200px;
  background: linear-gradient(180deg, #7aa8ff 0%, #4a7cf0 50%, #2f5ad0 100%);
  border: 3px solid #d8e5ff;
  box-shadow: 0 0 0 2.5px #2a4bb5, inset 0 3px 0 rgba(255,255,255,.4), 0 6px 0 #1e3c98, 0 11px 16px rgba(30, 60, 160, .3);
  text-shadow: 0 2px 0 rgba(20, 30, 100, .4);
}
.btn-blue:active { transform: translateY(5px); box-shadow: 0 0 0 2.5px #2a4bb5, inset 0 3px 0 rgba(255,255,255,.4), 0 1px 0 #1e3c98; }
.btn-ghost {
  font-size: 19px; color: var(--navy); padding: 8px 24px 5px;
  background: rgba(255,255,255,.88); border: 2.5px solid #fff;
  box-shadow: 0 0 0 2px #b9cdf5, 0 5px 0 #b9cdf5, 0 9px 14px rgba(40, 80, 160, .16);
}
.btn-ghost:active { transform: translateY(4px); box-shadow: 0 0 0 2px #b9cdf5, 0 1px 0 #b9cdf5; }
.center { align-self: center; }

/* ---------- Màn chơi ---------- */
.topbar { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.icon-btn {
  width: 46px; height: 46px; display: grid; place-items: center; border-radius: 16px; color: var(--navy);
  background: rgba(255,255,255,.9); border: 2.5px solid #fff;
  box-shadow: 0 0 0 2px #b9cdf5, 0 4px 0 #b9cdf5, 0 8px 12px rgba(40,80,160,.15);
  transition: transform .1s;
}
.icon-btn:active { transform: translateY(3px); }
.icon-btn .snd-off { display: none; }
.icon-btn.muted .snd-on { display: none; }
.icon-btn.muted .snd-off { display: block; }

.stats { width: 100%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 16px 0 14px; }
.stat {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  padding: 6px 4px 7px; min-height: 64px; border-radius: 18px;
  background: rgba(255,255,255,.82); border: 2.5px solid #fff;
  box-shadow: 0 0 0 2px #c8dbff, 0 6px 14px rgba(40, 80, 160, .14);
}
.stat small { font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; white-space: nowrap; }
.stat b { font-family: var(--display); font-weight: 800; font-size: 25px; line-height: 1.05; color: var(--navy-2); }
.stat b.bump { animation: bump .35s ease; }
@keyframes bump { 40% { transform: scale(1.25); color: #f08a00; } }

.board-card {
  width: min(100%, calc(100svh - 300px)); min-width: 280px;
  padding: 12px; border-radius: 32px;
  background: rgba(255,255,255,.78); border: 3px solid #fff;
  box-shadow: 0 0 0 2.5px #c3d7ff, 0 16px 34px rgba(40, 80, 160, .22);
  backdrop-filter: blur(6px);
}
.board {
  position: relative; width: 100%; aspect-ratio: 1; container-type: inline-size;
  border-radius: 24px;
  background: linear-gradient(180deg, #f2f7ff, #e1ebfc);
  box-shadow: inset 0 3px 10px rgba(40, 80, 160, .13);
}
.regions, .tiles, .fx { position: absolute; inset: 0; }
.tiles, .fx { pointer-events: none; }
.fx { z-index: 6; }

/* Vùng xoay */
.region {
  position: absolute; width: 48%; height: 48%;
  border-radius: 5.2cqw; border: 1cqw solid var(--rc);
  background: linear-gradient(180deg, color-mix(in srgb, var(--rc) 12%, #fff), color-mix(in srgb, var(--rc) 22%, #fff));
  box-shadow: inset 0 0 0 .5cqw rgba(255,255,255,.75), 0 .8cqw 0 color-mix(in srgb, var(--rc) 45%, #fff);
  transition: transform .12s ease, box-shadow .2s ease, filter .2s;
  cursor: pointer;
}
.region.r0 { --rc: var(--r0); left: 1%;  top: 1%; }
.region.r1 { --rc: var(--r1); left: 51%; top: 1%; }
.region.r2 { --rc: var(--r2); left: 1%;  top: 51%; }
.region.r3 { --rc: var(--r3); left: 51%; top: 51%; }
@media (hover: hover) {
  #board .region:hover { filter: brightness(1.04) saturate(1.15); box-shadow: inset 0 0 0 .5cqw rgba(255,255,255,.75), 0 .8cqw 0 color-mix(in srgb, var(--rc) 45%, #fff), 0 0 0 1.4cqw color-mix(in srgb, var(--rc) 25%, transparent); }
}
.region:focus-visible { outline: 1cqw solid var(--navy); outline-offset: .6cqw; }
.region.twist { animation: twist .32s ease; }
@keyframes twist { 0% { transform: rotate(0) scale(1); } 45% { transform: rotate(5deg) scale(.97); } 100% { transform: rotate(0) scale(1); } }
.region.hinted { animation: hintGlow 1s ease-in-out infinite; }
@keyframes hintGlow { 50% { box-shadow: inset 0 0 0 .5cqw rgba(255,255,255,.8), 0 0 0 2cqw color-mix(in srgb, var(--rc) 40%, transparent); } }

/* Ô số */
.tile {
  position: absolute; width: 20.75%; height: 20.75%; z-index: 2;
  transition: left .26s cubic-bezier(.45,.05,.35,1), top .26s cubic-bezier(.45,.05,.35,1);
}
.tile.absorb { z-index: 1; transition-duration: .2s; transition-timing-function: ease-in; }
.tile-in {
  position: relative; width: 100%; height: 100%;
  display: grid; place-items: center;
  border-radius: 3.8cqw;
  background: linear-gradient(180deg, var(--t1) 0%, var(--t2) 100%);
  border: .55cqw solid var(--te);
  box-shadow: inset 0 -1.1cqw 0 rgba(0,0,0,.07), inset 0 .5cqw 0 rgba(255,255,255,.7),
              0 1cqw 0 var(--te), 0 1.8cqw 2.4cqw rgba(30, 60, 130, .2);
  font-family: var(--display); font-weight: 800; font-size: 12cqw; line-height: 1; color: var(--tn);
}
.tile[data-digits="2"] .tile-in { font-size: 9.5cqw; }
.tile[data-digits="3"] .tile-in { font-size: 7.5cqw; }
.tile-in::before {
  content: ""; position: absolute; left: 9%; right: 9%; top: 6%; height: 40%;
  border-radius: 2.6cqw 2.6cqw 50% 50% / 2.6cqw 2.6cqw 35% 35%;
  background: linear-gradient(180deg, rgba(255,255,255,.85), rgba(255,255,255,0));
  pointer-events: none;
}
.tile-in span { position: relative; transform: translateY(.5cqw); text-shadow: 0 .55cqw 0 var(--ts, rgba(255,255,255,.7)); }
.tile.moving { animation: squash .26s ease; }
@keyframes squash { 50% { transform: scale(.9); } }
.tile-in.spawn { animation: spawn .34s cubic-bezier(.3,1.6,.5,1) both; }
@keyframes spawn { from { transform: scale(0); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.tile-in.pop { animation: pop .36s cubic-bezier(.3,1.6,.5,1); }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.22); } 100% { transform: scale(1); } }
.tile.absorb .tile-in { transform: scale(.7); opacity: 0; transition: transform .2s ease-in, opacity .12s ease-in .08s; }
.over-shake { animation: shake .45s ease; }
@keyframes shake { 20%,60% { transform: translateX(-1.5cqw); } 40%,80% { transform: translateX(1.5cqw); } }

/* Bảng màu theo cấp */
[data-lv="1"]  { --t1: #f4f7ff; --t2: #d1ddf8; --te: #a3b6e4; --tn: #26336e; }
[data-lv="2"]  { --t1: #e7f2ff; --t2: #a9cefb; --te: #6fa2e6; --tn: #1d58cf; }
[data-lv="3"]  { --t1: #e2fcee; --t2: #a3e8c5; --te: #5ec297; --tn: #0b7656; }
[data-lv="4"]  { --t1: #fff6d8; --t2: #ffd685; --te: #ecab44; --tn: #d55c08; }
[data-lv="5"]  { --t1: #ffebf4; --t2: #ffb8d7; --te: #e985b2; --tn: #be1659; }
[data-lv="6"]  { --t1: #f3ebff; --t2: #d2baff; --te: #a587e6; --tn: #682dd3; }
[data-lv="7"]  { --t1: #82bbff; --t2: #3577ea; --te: #1f4db5; --tn: #fff; --ts: rgba(10, 30, 100, .35); }
[data-lv="8"]  { --t1: #74eab3; --t2: #17a96b; --te: #0b7146; --tn: #fff; --ts: rgba(0, 60, 30, .35); }
[data-lv="9"]  { --t1: #ffc874; --t2: #ff7b1c; --te: #bf4d08; --tn: #fff; --ts: rgba(110, 40, 0, .35); }
[data-lv="10"] { --t1: #ff9fc8; --t2: #e43a88; --te: #a01b58; --tn: #fff; --ts: rgba(100, 10, 50, .35); }
[data-lv="11"] { --t1: #bba4ff; --t2: #6b3bef; --te: #4320aa; --tn: #fff; --ts: rgba(40, 10, 100, .4); }
[data-lv="12"] { --t1: #fff27e; --t2: #ffb800; --te: #be7c00; --tn: #7a3f00; --ts: rgba(255,255,255,.7); }
[data-lv="max"]{ --t1: #3a3f7a; --t2: #171a45; --te: #ffcc1a; --tn: #ffe14d; --ts: rgba(0,0,0,.5); }
.tile[data-lv="12"] .tile-in, .tile[data-lv="max"] .tile-in { overflow: hidden; }
.tile[data-lv="12"] .tile-in::after, .tile[data-lv="max"] .tile-in::after {
  content: ""; position: absolute; inset: -20%; background: linear-gradient(110deg, transparent 35%, rgba(255,255,255,.65) 50%, transparent 65%);
  animation: shine 2.6s ease-in-out infinite;
}
@keyframes shine { 0% { transform: translateX(-80%); } 60%,100% { transform: translateX(80%); } }

/* Ô tĩnh (mini) */
.mtile {
  --s: 44px;
  position: relative; width: var(--s); height: var(--s); flex: none;
  display: grid; place-items: center;
  border-radius: calc(var(--s) * .2);
  background: linear-gradient(180deg, var(--t1), var(--t2));
  border: 2px solid var(--te);
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.07), inset 0 2px 0 rgba(255,255,255,.7), 0 3px 0 var(--te), 0 5px 8px rgba(30, 60, 130, .16);
  font-family: var(--display); font-weight: 800; font-size: calc(var(--s) * .6); line-height: 1; color: var(--tn);
  padding-top: calc(var(--s) * .06);
  text-shadow: 0 2px 0 var(--ts, rgba(255,255,255,.7));
}
.mtile::before { content: ""; position: absolute; left: 10%; right: 10%; top: 6%; height: 38%; border-radius: 8px 8px 50% 50% / 8px 8px 35% 35%; background: linear-gradient(180deg, rgba(255,255,255,.8), rgba(255,255,255,0)); }
.mtile.sm { --s: 32px; }
.mtile.lg { --s: 58px; }
.mtile.empty { background: rgba(255,255,255,.5); border: 2.5px dashed #a9bde6; box-shadow: none; }
.mtile.empty::before { display: none; }
.stat.max .mtile { margin-top: 2px; }

/* Hiệu ứng */
.float {
  position: absolute; transform: translate(-50%, -50%); z-index: 10; white-space: nowrap;
  font-family: var(--display); font-weight: 800; font-size: 6.5cqw; color: #fff;
  --o: var(--navy);
  text-shadow: 2px 0 0 var(--o), -2px 0 0 var(--o), 0 2px 0 var(--o), 0 -2px 0 var(--o), 1.5px 1.5px 0 var(--o), -1.5px 1.5px 0 var(--o), 1.5px -1.5px 0 var(--o), -1.5px -1.5px 0 var(--o), 0 4px 0 var(--o);
  animation: floatUp 1s ease-out forwards;
}
@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(.6); }
  20% { opacity: 1; transform: translate(-50%, -70%) scale(1.12); }
  100% { opacity: 0; transform: translate(-50%, -190%) scale(1); }
}
.particle { position: absolute; width: 2.6cqw; height: 2.6cqw; margin: -1.3cqw 0 0 -1.3cqw; clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%); }
.hint-badge {
  position: absolute; transform: translate(-50%, -50%); z-index: 9;
  display: flex; align-items: center; gap: .6cqw;
  padding: .6cqw 2.2cqw .6cqw 1.2cqw; border-radius: 999px;
  background: var(--rc); color: #fff; border: .7cqw solid #fff;
  font-family: var(--display); font-weight: 800; font-size: 5.2cqw; line-height: 1.1;
  box-shadow: 0 1cqw 2cqw rgba(0,0,0,.25);
  animation: badgeIn .35s cubic-bezier(.3,1.6,.5,1), badgeBob 1s ease-in-out .35s infinite;
}
.hint-badge svg { width: 6cqw; height: 6cqw; }
@keyframes badgeIn { from { transform: translate(-50%, -50%) scale(0); } }
@keyframes badgeBob { 50% { transform: translate(-50%, -50%) scale(1.1); } }

.combo {
  position: absolute; left: 50%; top: 50%; z-index: 12; pointer-events: none; opacity: 0;
  transform: translate(-50%, -50%); white-space: nowrap;
  font-family: var(--display); font-weight: 800; font-size: 13cqw; color: #ffe14d;
  --o: #8a3b00;
  text-shadow: 4px 0 0 var(--o), -4px 0 0 var(--o), 0 4px 0 var(--o), 0 -4px 0 var(--o), 3px 3px 0 var(--o), -3px 3px 0 var(--o), 3px -3px 0 var(--o), -3px -3px 0 var(--o), 0 8px 0 var(--o), 0 12px 16px rgba(0,0,0,.3);
}
.combo.show { animation: comboIn 1.1s cubic-bezier(.2,1.4,.4,1) forwards; }
@keyframes comboIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.3) rotate(-10deg); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1.1) rotate(-4deg); }
  70% { opacity: 1; transform: translate(-50%, -55%) scale(1) rotate(-4deg); }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(.9) rotate(-4deg); }
}

.controls { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; justify-content: center; }
.btn-small {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px 8px; border-radius: 999px;
  font-family: var(--display); font-weight: 800; font-size: 17px; color: var(--navy);
  background: rgba(255,255,255,.92); border: 2.5px solid #fff;
  box-shadow: 0 0 0 2px #b9cdf5, 0 5px 0 #b9cdf5, 0 9px 14px rgba(40,80,160,.16);
  transition: transform .1s, box-shadow .1s;
}
.btn-small .ico { width: 20px; height: 20px; }
.btn-small:active { transform: translateY(4px); box-shadow: 0 0 0 2px #b9cdf5, 0 1px 0 #b9cdf5; }
.btn-small.hint { color: #8a4b00; background: linear-gradient(180deg, #fff8c4, #ffe27a); box-shadow: 0 0 0 2px #f2b200, 0 5px 0 #d99a00, 0 9px 14px rgba(150,90,0,.2); }
.btn-small.hint:active { box-shadow: 0 0 0 2px #f2b200, 0 1px 0 #d99a00; }
.btn-small.hint:disabled { filter: grayscale(.8); opacity: .7; }
.badge { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; display: inline-grid; place-items: center; background: #ef4444; color: #fff; font-size: 14px; border: 2px solid #fff; line-height: 1; }
.keys-tip { margin: 16px 0 0; font-size: 13.5px; font-weight: 700; color: var(--muted); text-align: center; }
kbd { display: inline-block; min-width: 20px; padding: 0 5px; margin: 0 2px; border-radius: 6px; background: #fff; border: 1.5px solid #b9cdf5; border-bottom-width: 3px; font-family: var(--body); font-weight: 800; font-size: 12px; color: var(--navy); }
@media (hover: none) { .keys-tip kbd, .keys-tip .kb { display: none; } }

/* ---------- Hộp thoại ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50; display: none; align-items: center; justify-content: center;
  padding: 16px; background: rgba(28, 46, 110, .38); backdrop-filter: blur(5px);
}
.modal.open { display: flex; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; } }
.modal-card {
  position: relative; width: min(620px, 100%); max-height: calc(100svh - 32px); overflow: auto;
  padding: 22px 18px 24px; border-radius: 30px;
  background: linear-gradient(180deg, #f8fbff, #e8f2ff);
  border: 4px solid #fff;
  box-shadow: 0 0 0 3px #b5ccff, 0 24px 60px rgba(20, 40, 120, .4);
  animation: cardIn .4s cubic-bezier(.3,1.4,.5,1);
  display: flex; flex-direction: column; gap: 14px;
}
@keyframes cardIn { from { transform: scale(.85) translateY(20px); opacity: 0; } }
.close-btn {
  position: absolute; top: 12px; right: 12px; width: 38px; height: 38px; border-radius: 50%;
  background: #fff; color: var(--navy); font-weight: 900; font-size: 18px;
  box-shadow: 0 0 0 2px #b9cdf5, 0 3px 0 #b9cdf5; z-index: 2;
}
.how-head { display: flex; align-items: center; justify-content: center; gap: 4px; margin-bottom: 4px; }
.how-head .rot { width: 56px; height: 56px; }
.how-head h2 { font-size: 40px; }

.how-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hcard {
  padding: 14px 14px 16px; border-radius: 22px; background: rgba(255,255,255,.92);
  border: 2px solid #fff; box-shadow: 0 0 0 2px #d4e2ff, 0 6px 14px rgba(40, 80, 160, .1);
  display: flex; flex-direction: column; gap: 10px;
}
.hcard.wide { grid-column: 1 / -1; }
.hcard h3 { margin: 0; display: flex; align-items: center; gap: 8px; font-family: var(--display); font-weight: 800; font-size: 20px; color: var(--navy); line-height: 1.1; }
.hnum {
  flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; padding-top: 3px;
  background: linear-gradient(180deg, #5b84f0, #2a4dbf); color: #fff; font-size: 21px;
  border: 3px solid #fff; box-shadow: 0 0 0 2px #2a4dbf, 0 3px 0 #1c3690;
}
.hcard p { margin: 0; font-size: 15px; font-weight: 700; line-height: 1.4; color: #34436f; }
.hcard .note { font-size: 13.5px; color: var(--muted); font-style: italic; text-align: center; }
.mini-regions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; align-self: center; }
.mreg { display: grid; grid-template-columns: repeat(2, auto); gap: 5px; padding: 5px; border-radius: 14px; border: 3px solid var(--rc, #9db4e8); background: color-mix(in srgb, var(--rc, #9db4e8) 12%, #fff); }
.mreg .mtile { --s: 34px; }
.mreg.r0 { --rc: var(--r0); } .mreg.r1 { --rc: var(--r1); } .mreg.r2 { --rc: var(--r2); } .mreg.r3 { --rc: var(--r3); }
.mreg.plain { --rc: #8aa6dc; }
.mreg.plain .mtile { --s: 40px; }
.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 10px; font-weight: 800; font-size: 13px; color: var(--navy); }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: -6px; vertical-align: -1px; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.1); }
.d0 { background: var(--r0); } .d1 { background: var(--r1); } .d2 { background: var(--r2); } .d3 { background: var(--r3); }
.before-after { display: flex; align-items: center; justify-content: center; gap: 8px; }
.ba-label { text-align: center; margin-bottom: 6px; padding: 2px 10px; border-radius: 10px; background: #64748b; color: #fff; font-size: 12px; font-weight: 800; white-space: nowrap; }
.arrow { font-size: 26px; color: #f59e0b; text-shadow: 0 2px 0 #b45f06; font-weight: 900; }
.merge-demo, .spawn-demo { display: flex; align-items: center; justify-content: center; gap: 8px; }
.formula { text-align: center; font-family: var(--display); font-size: 22px !important; color: var(--navy) !important; }
.steps { margin: 0; padding-left: 22px; font-size: 14.5px; font-weight: 700; line-height: 1.4; color: #34436f; display: flex; flex-direction: column; gap: 4px; }
.steps li::marker { color: var(--navy-2); font-weight: 900; }
.purple-banner {
  padding: 12px 16px; border-radius: 20px; text-align: center;
  background: linear-gradient(180deg, #a77bff, #7444e6); color: #fff;
  font-weight: 800; font-size: 15.5px; line-height: 1.35;
  border: 3px solid #e7dcff; box-shadow: 0 0 0 2px #5b2fc4, 0 5px 0 #4a24a6, 0 10px 16px rgba(80, 40, 180, .25);
  text-shadow: 0 1px 0 rgba(40, 10, 100, .35);
}
.tips { position: relative; margin-top: 14px; padding: 26px 12px 12px; border-radius: 22px; background: #fff8ec; border: 2px solid #fff; box-shadow: 0 0 0 2px #f4d9a8; }
.ribbon {
  position: absolute; top: -16px; left: 14px; padding: 4px 16px 2px;
  font-family: var(--display); font-weight: 800; font-size: 19px; color: #fff;
  background: linear-gradient(180deg, #ffa53d, #e7760c); border-radius: 12px 18px 12px 18px;
  border: 2.5px solid #fff1d6; box-shadow: 0 3px 0 #b75400; transform: rotate(-3deg);
  text-shadow: 0 2px 0 rgba(120, 50, 0, .4);
}
.tips-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tips-row > div { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; font-size: 13px; font-weight: 700; color: #4a3a22; line-height: 1.3; }
.tips-row span { font-size: 28px; }

/* Kết thúc */
.over-card { width: min(400px, 100%); align-items: center; text-align: center; }
.crown { width: 130px; height: auto; margin-top: -4px; animation: bob 2.5s ease-in-out infinite; }
.over-card h2 { font-size: 42px; margin-top: -4px; }
.record { padding: 4px 16px; border-radius: 999px; background: linear-gradient(180deg, #ff7eb6, #e63a89); color: #fff; font-weight: 900; font-size: 16px; box-shadow: 0 3px 0 #a51d5c; animation: pulse 1s ease-in-out infinite; }
.over-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; }
.over-stats > div { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 10px 4px; border-radius: 18px; background: #fff; box-shadow: 0 0 0 2px #d4e2ff; }
.over-stats small { font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; }
.over-stats b { font-family: var(--display); font-weight: 800; font-size: 30px; line-height: 1; color: var(--navy-2); }
.over-stats .mtile { --s: 40px; }
.over-card .btn-yellow { margin-top: 6px; }

.confirm-card { width: min(340px, 100%); text-align: center; align-items: center; }
.confirm-card h3 { margin: 0; font-family: var(--display); font-size: 26px; color: var(--navy); }
.confirm-card p { margin: 0; font-weight: 700; color: var(--muted); }
.confirm-card .row { display: flex; gap: 12px; margin-top: 6px; }
.confirm-card .btn-blue { min-width: 0; font-size: 19px; padding: 8px 22px 5px; }

.toast {
  position: fixed; left: 50%; bottom: 40px; z-index: 60; transform: translate(-50%, 20px); opacity: 0;
  padding: 10px 20px; border-radius: 999px; background: var(--navy); color: #fff; font-weight: 800;
  box-shadow: 0 8px 20px rgba(20, 40, 120, .35); transition: opacity .25s, transform .25s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Màn hình nhỏ ---------- */
@media (max-width: 560px) {
  .how-grid { grid-template-columns: 1fr; }
  .tips-row { grid-template-columns: 1fr 1fr; gap: 12px 8px; }
  .how-head h2 { font-size: 34px; }
}
@media (max-width: 380px) {
  .stat small { font-size: 10px; }
  .stat b { font-size: 21px; }
  .btn-small { font-size: 15px; padding: 8px 12px 7px; }
  .logo.small .outline-title { font-size: 25px; }
}
@media (max-height: 700px) {
  .demo-wrap { width: min(60vw, 230px); margin: 16px 0 12px; }
  .bubble { margin-top: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
  .cloud { display: none; }
}
