/* tính năng mở rộng — Nối số (js/game-dots.js) */
body[data-scene="noi-so"] { --sky1: #8D7CFF; --sky2: #E9E2FF; }

/* cả trò chơi nằm gọn trong phần màn hình còn lại dưới thanh trên: không phải cuộn trang (phòng tranh thì được cuộn) */
.gn { width: 100%; height: calc(var(--vh) - var(--bar) - 35px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)); min-height: 250px; }
.gn.gn-ingal { height: auto; min-height: 0; }
.gn-play[hidden], .gn-gal[hidden] { display: none; }

/* màn dọc: Gấu Con ở trên, tờ giấy ở giữa, hàng dưới là nút phòng tranh – hình bí mật – nút "tiếp" */
.gn-play { height: 100%; display: grid; gap: 10px; touch-action: none;
  grid-template: "ask ask ask" auto "board board board" minmax(0, 1fr) "gal prize next" auto / auto minmax(0, 1fr) auto; }
.gn-play > .ask { grid-area: ask; min-width: 0; }
/* tờ giấy trên cùng của một xấp giấy vẽ: mép các tờ bên dưới lộ ra ở đáy, bóng đổ mềm, mặt giấy sáng ở góc trên trái, góc dưới phải hơi cong lên */
.gn-board { grid-area: board; position: relative; min-width: 0; min-height: 0; border: 5px solid #fff; border-radius: 22px; overflow: hidden; touch-action: none;
  background: radial-gradient(120% 90% at 18% 8%, rgba(255, 255, 255, .95) 0, rgba(255, 255, 255, 0) 55%), radial-gradient(circle, rgba(122, 77, 255, .13) 1.5px, transparent 2.1px) 0 0 / 22px 22px, linear-gradient(155deg, #FFFEF8, #F4EEFF 70%, #E9E0FA);
  box-shadow: 0 2px 0 #E4DCF6, 0 4px 0 #fff, 0 6px 0 #D9CFF0, 0 8px 0 #fff, 0 10px 0 #CDC1EA, 0 12px 3px rgba(30, 42, 94, .2), 0 24px 30px rgba(30, 42, 94, .26), inset 0 0 26px rgba(122, 77, 255, .07); }
.gn-board::after { content: ""; position: absolute; right: -1px; bottom: -1px; z-index: 3; width: clamp(34px, 9%, 58px); aspect-ratio: 1; pointer-events: none; border-top-left-radius: 10px;
  background: linear-gradient(135deg, #fff 0, #F3ECFF 30%, #D9CEF2 47%, rgba(30, 42, 94, .28) 50%, #EFE8FB 51%, #E3D9F6 100%);
  box-shadow: -3px -3px 7px rgba(30, 42, 94, .16); }
.gn-svg { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; display: block; touch-action: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }

/* ----- hình thật (ảnh chụp, hoặc hình 3D đứng trên nền màu) nằm dưới nét vẽ, hiện ra khi bé nối xong ----- */
.gn-real { position: absolute; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; opacity: 0; background: #fff; }
.gn-real.gn-show { opacity: 1; transition: opacity .35s; }
.gn-photo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.gn-show > .gn-photo { animation: gn-ken 8s ease-out both; }
.gn-real.gn-3d { background: radial-gradient(70% 55% at 50% 40%, #fff 0, rgba(255, 255, 255, .5) 45%, rgba(255, 255, 255, 0) 100%), linear-gradient(rgba(255, 255, 255, .38) 0, rgba(255, 255, 255, .62) 66%, rgba(255, 255, 255, .2) 66.4%, rgba(255, 255, 255, .5) 100%), var(--tint, #9ED8FF); }
.gn-rays { position: absolute; left: 50%; top: 42%; width: 150%; aspect-ratio: 1; margin: -75% 0 0 -75%; border-radius: 50%; opacity: .5;
  background: repeating-conic-gradient(rgba(255, 255, 255, .85) 0 9deg, rgba(255, 255, 255, 0) 9deg 20deg); -webkit-mask: radial-gradient(closest-side, #000 20%, transparent 78%); mask: radial-gradient(closest-side, #000 20%, transparent 78%); }
.gn-show > .gn-rays { animation: gn-spin 40s linear infinite; }
.gn-ground { position: absolute; left: 22%; right: 22%; top: 71%; height: 9%; border-radius: 50%; background: radial-gradient(closest-side, rgba(30, 42, 94, .34), rgba(30, 42, 94, 0)); }
.gn-real > .gn-obj { position: absolute; left: 12%; top: 9%; width: 76%; height: 68%; object-fit: contain; object-position: 50% 100%; font-size: 30vmin; text-align: center;
  filter: drop-shadow(0 10px 10px rgba(30, 42, 94, .22)); }
.gn-show > .gn-obj { animation: gn-objin .8s .45s cubic-bezier(.3, 1.5, .5, 1) backwards, gn-float 3.2s ease-in-out 1.4s infinite; }
.gn-show > .gn-ground { animation: gn-ground 3.2s ease-in-out 1.4s infinite; }
/* vệt sáng lướt qua một lần lúc ảnh vừa phủ kín tờ giấy, như tấm ảnh bóng */
.gn-real::after { content: ""; position: absolute; top: -20%; bottom: -20%; left: 0; width: 34%; opacity: 0; transform: translateX(-140%) skewX(-18deg);
  background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, .7), rgba(255, 255, 255, 0)); }
.gn-real.gn-full::after { animation: gn-sheen 1s ease-out both; }
.gn-real.gn-boing { animation: gn-boing .5s; }
.gn-info { position: absolute; z-index: 4; display: grid; place-items: center; width: 28px; height: 28px; padding: 0; border-radius: 50%; border: 2px solid rgba(30, 42, 94, .3); background: rgba(255, 255, 255, .9);
  color: rgba(30, 42, 94, .7); font: italic 700 15px/1 Georgia, 'Times New Roman', serif; -webkit-tap-highlight-color: transparent; }
.gn-info[hidden] { display: none; }
.gn-info::after { content: ""; position: absolute; inset: -9px; border-radius: 50%; }
.gn-info-pic { right: 9px; top: 9px; }
.gn-info-gal { position: relative; flex: none; }
.gn-credits { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 14px; background: rgba(30, 42, 94, .5); }
.gn-credits-in { box-sizing: border-box; max-width: min(560px, 100%); max-height: 100%; overflow: auto; padding: 14px 18px; border-radius: 20px; background: #fff; color: var(--navy); font-size: 14px; line-height: 1.45; }
.gn-credits-in h3 { margin: 0 0 6px; font-size: 16px; }
.gn-credits-in ul { margin: 0; padding: 0; list-style: none; }
.gn-credits-in p { margin: 8px 0 0; opacity: .7; font-size: 12px; }
.gn-galbtn { grid-area: gal; align-self: center; width: 64px; height: 64px; }
.gn-prize { grid-area: prize; min-width: 0; min-height: 72px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px; }
/* ô bí mật: một khối "?" nổi, bóng như kẹo */
.gn-q { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 20px; border: 3px solid #fff;
  background: radial-gradient(90% 60% at 30% 16%, rgba(255, 255, 255, .85) 0, rgba(255, 255, 255, 0) 60%), linear-gradient(160deg, #B79BFF, #7A4DFF 60%, #5B34D6);
  box-shadow: 0 6px 0 #4A28B8, 0 12px 14px rgba(30, 42, 94, .3), inset 0 -6px 10px rgba(40, 16, 120, .35), inset 0 3px 4px rgba(255, 255, 255, .5);
  font: 700 40px/1 var(--font-letter); color: #fff; text-shadow: 0 2px 0 #4A28B8, 0 3px 4px rgba(30, 42, 94, .4); animation: gn-tilt 2.8s ease-in-out infinite; }
.gn-prize.gn-solo .gn-name { font-size: clamp(1.5rem, 7vw, 2.4rem); }
.gn-prize .gn-emo { font-size: 62px; animation: gn-popin .5s cubic-bezier(.3, 1.5, .5, 1) backwards, gn-tilt 2.8s ease-in-out .5s infinite; }
.gn-name { min-width: 0; font-weight: 800; font-size: clamp(1.35rem, 6vw, 2rem); line-height: 1.1; text-align: center; animation: gn-popin .5s .15s cubic-bezier(.3, 1.5, .5, 1) backwards; }
.gn-next { grid-area: next; align-self: center; display: flex; align-items: center; justify-content: center; gap: 4px; min-height: 68px; padding: 4px 14px 4px 20px; visibility: hidden; }
.gn-next.gn-show { visibility: visible; animation: gn-popin .45s cubic-bezier(.3, 1.5, .5, 1) backwards, gn-beat 1.1s ease-in-out .5s infinite; }
.gn-arrow { display: grid; place-items: center; }
.gn-arrow svg { width: 40px; height: 40px; fill: #fff; stroke: var(--navy); stroke-width: 1.6; stroke-linejoin: round; paint-order: stroke; }

/* màn ngang: Gấu Con bên trái, tờ giấy ở giữa cao hết mức, hình bí mật và nút "tiếp" bên phải */
@media (min-aspect-ratio: 11/10) {
  .gn-play { --gn-side: clamp(96px, 16vw, 184px); column-gap: 14px;
    grid-template: "ask board prize" minmax(0, 1fr) "gal board next" auto / minmax(var(--gn-side), 1fr) minmax(0, calc((var(--vh) - var(--bar) - 35px) * 1.08)) minmax(var(--gn-side), 1fr); }
  .gn-play > .ask { flex-direction: column; justify-content: flex-start; gap: 10px; }
  .gn-play > .ask > span { width: min(100%, 124px); }
  .gn-play > .ask .bubble { flex: none; width: 100%; padding: 8px 10px; font-size: 1.1rem; text-align: center; }
  .gn-play > .ask .bubble::before { left: 50%; top: -12px; margin: 0 0 0 -10px; border: 10px solid transparent; border-bottom-color: var(--yellow); border-top: 0; }
  .gn-galbtn { justify-self: center; }
  .gn-prize { flex-direction: column; align-self: center; gap: 6px; }
  .gn-q { width: clamp(72px, 11vw, 124px); height: clamp(72px, 11vw, 124px); border-radius: 28px; font-size: clamp(44px, 7vw, 80px); }
  .gn-prize .gn-emo { font-size: clamp(64px, 12vw, 132px); }
  .gn-name { font-size: clamp(1.2rem, 2.6vw, 1.9rem); }
  .gn-next { width: 100%; padding: 4px 6px 4px 12px; }
}
/* màn ngang thấp (điện thoại nằm ngang): mọi thứ nhỏ lại để tờ giấy cao hết mức */
@media (min-aspect-ratio: 11/10) and (max-height: 560px) {
  .gn-play { column-gap: 10px; }
  .gn-play > .ask { gap: 6px; }
  .gn-play > .ask > span { width: min(100%, 76px); }
  .gn-play > .ask .bubble { padding: 4px 8px; font-size: .95rem; border-radius: 16px; }
  .gn-galbtn { width: 52px; height: 52px; }
  .gn-next { min-height: 56px; padding: 2px 8px 2px 14px; }
}
@media (max-height: 700px) and (max-aspect-ratio: 11/10) {
  .gn-play { gap: 8px; }
  .gn-galbtn { width: 58px; height: 58px; }
  .gn-prize { min-height: 62px; } .gn-q { width: 56px; height: 56px; font-size: 34px; border-radius: 16px; } .gn-prize .gn-emo { font-size: 54px; }
  .gn-next { min-height: 60px; }
}

/* điện thoại dọc: nút "tiếp" chỉ còn mũi tên to, nhường chỗ cho tên hình; màn cao thì hàng dưới to hẳn lên */
@media (max-width: 480px) and (max-aspect-ratio: 11/10) {
  .gn-nexttxt { display: none; }
  .gn-next { padding: 4px 20px; }
  .gn-arrow svg { width: 48px; height: 48px; }
  .gn-name { font-size: clamp(1.05rem, 4.8vw, 1.5rem); } /* tên dài ("Con thuyền", "Vương miện") không chạm vào nút "tiếp" */
  .gn-prize { gap: 6px; }
}
@media (min-height: 760px) and (max-aspect-ratio: 3/4) {
  .gn-play { gap: 12px; }
  .gn-play > .ask > span { width: 88px; }
  .gn-board { align-self: center; height: 100%; max-height: calc((100vw - 32px) * 1.3); }
  .gn-galbtn { width: 68px; height: 68px; }
  .gn-prize { min-height: 108px; }
  .gn-q { width: 96px; height: 96px; border-radius: 26px; font-size: 60px; }
  .gn-prize .gn-emo { font-size: 96px; }
  .gn-next { min-height: 80px; }
}

/* ----- nét nối và các chấm ----- */
.gn-seg { fill: none; stroke: #7A4DFF; stroke-width: 2.8; stroke-linecap: round; pointer-events: none; }
.gn-segsh { fill: none; stroke: rgba(30, 42, 94, .2); stroke-width: 3.2; stroke-linecap: round; pointer-events: none; transform: translate(.5px, 1.3px); }
.gn-seghi { fill: none; stroke: #C9B6FF; stroke-width: .8; stroke-linecap: round; pointer-events: none; transform: translate(-.3px, -.6px); }
.gn-draw { stroke-dasharray: 1; animation: gn-draw .3s ease-out backwards; }
.gn-rubber { fill: none; stroke: #B9A2FF; stroke-width: 2.2; stroke-linecap: round; stroke-dasharray: .1 4.4; pointer-events: none; }
.gn-dot, .gn-anchor { outline: none !important; box-shadow: none !important; }
.gn-anchor { fill: none; stroke: none; pointer-events: none; } /* chỗ đặt bàn tay gợi ý: ngay dưới chấm, không che con số */
/* mỗi chấm là một cái nút nổi (màu tô nằm ngay trong thẻ svg: gradient): bóng đổ → thành nút → mặt nút bóng → con số */
.gn-disc { stroke: #7A4DFF; stroke-width: 1; }
.gn-hot { stroke: var(--orange); stroke-width: 1.4; opacity: 0; pointer-events: none; }
.gn-rim { pointer-events: none; }
.gn-rimhot { opacity: 0; }
.gn-shade { fill: rgba(30, 42, 94, .26); pointer-events: none; }
.gn-digit { font-family: var(--font-letter); font-weight: 700; fill: var(--navy); text-anchor: middle; pointer-events: none; }
.gn-star { fill: var(--yellow); stroke: var(--navy); stroke-width: .9; stroke-linejoin: round; transform: scale(0); opacity: 0; pointer-events: none; }
.gn-halo { fill: none; stroke: var(--orange); stroke-width: 1.8; opacity: 0; pointer-events: none; }
.gn-in > * { transition: transform .3s cubic-bezier(.3, 1.6, .5, 1), opacity .2s; }
.gn-on .gn-disc, .gn-on .gn-digit, .gn-on .gn-rim, .gn-on .gn-shade, .gn-on .gn-hot { transform: scale(.2); opacity: 0; }
.gn-on .gn-star { transform: scale(1); opacity: 1; }
/* chấm phải nối trước tiên, và chấm được gợi ý khi bé bí: sáng lên, có vòng lan ra */
.gn-first .gn-hot, .gn-dot.hinted .gn-hot, .gn-first .gn-rimhot, .gn-dot.hinted .gn-rimhot { opacity: 1; }
.gn-first .gn-halo, .gn-dot.hinted .gn-halo { animation: gn-halo 1.2s ease-out infinite; }
.gn-first .gn-in, .gn-dot.hinted .gn-in { animation: gn-pulse 1.2s ease-in-out infinite; }
.gn-in.gn-wob { animation: gn-wob .5s; }
.gn-in.gn-hit { animation: gn-hit .35s; }

/* ----- nối xong: hình thật hiện trong lòng nét nối rồi lớn ra phủ kín tờ giấy (js/game-dots.js: showReal); lúc đó nét nối và các ngôi sao mờ đi ----- */
.gn-gone .gn-lines, .gn-gone .gn-dots, .gn-gone .gn-rubber { opacity: 0; transition: opacity .6s .15s; }
/* bé chạm vào hình đã xong: hình nhún một cái */
.gn-prize.gn-boing { animation: gn-boing .5s; }

/* ----- phòng tranh ----- */
.gn-gal { display: flex; flex-direction: column; gap: 14px; padding-bottom: 12px; touch-action: pan-y; }
.gn-galtop { display: flex; align-items: center; gap: 12px; }
.gn-galtop .buddy { width: clamp(56px, 13vw, 88px); flex: none; }
.gn-galtop .bubble { flex: 1; min-width: 0; }
.gn-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 700px) { .gn-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; } }
.gn-card { position: relative; aspect-ratio: 1; min-width: 0; padding: 2px; display: grid; place-items: center; background: #fff; border: 4px solid #fff; border-radius: 22px;
  box-shadow: 0 5px 0 rgba(30, 42, 94, .22), 0 9px 12px rgba(30, 42, 94, .14); transition: transform .08s; -webkit-tap-highlight-color: transparent; }
.gn-card:active { transform: translateY(4px) scale(.98); }
.gn-card > * { pointer-events: none; }
.gn-thumb { width: 100%; height: 100%; display: block; }
/* hình đã xong: tấm ảnh thật phủ kín thẻ, hoặc hình 3D đứng trên nền màu */
.gn-isdone { padding: 0; background: #fff; border-color: #fff; }
.gn-tile { position: absolute; inset: 0; display: grid; place-items: center; overflow: hidden; border-radius: 17px; font-size: 3.2rem;
  background: radial-gradient(70% 55% at 50% 40%, #fff 0, rgba(255, 255, 255, .5) 45%, rgba(255, 255, 255, 0) 100%), linear-gradient(rgba(255, 255, 255, .38) 0, rgba(255, 255, 255, .62) 68%, rgba(255, 255, 255, .2) 68.4%, rgba(255, 255, 255, .5) 100%), var(--tint, #9ED8FF);
  box-shadow: inset 0 0 0 1px rgba(30, 42, 94, .08), inset 0 -10px 16px rgba(30, 42, 94, .1); }
.gn-tile-ph { background: #E9E4F5; }
.gn-tph { object-fit: cover; }
img.gn-t3d { width: 78%; height: 78%; object-fit: contain; filter: drop-shadow(0 5px 5px rgba(30, 42, 94, .25)); }
.gn-tick { position: absolute; top: -9px; right: -9px; z-index: 1; width: 34px; height: 34px; display: grid; place-items: center; font-size: 28px; filter: drop-shadow(0 2px 2px rgba(30, 42, 94, .35)); }
.gn-cloud circle { fill: #C9BFE6; }
.gn-cloud .gn-cs { fill: rgba(30, 42, 94, .16); }
.gn-cloud .gn-cg { fill: rgba(255, 255, 255, .7); }
.gn-islocked { background: linear-gradient(160deg, #F7F4FF, #E6DFF6); border-color: #F7F4FF; }
.gn-isopen { border-color: var(--yellow); background: linear-gradient(160deg, #fff, #F1EAFF); animation: gn-beat 1.3s ease-in-out infinite; }
.gn-isopen .gn-cloud circle { fill: #7A4DFF; }
.gn-isopen .gn-cloud .gn-cs { fill: rgba(30, 42, 94, .22); }
.gn-isopen .gn-cloud .gn-cg { fill: rgba(255, 255, 255, .6); }
/* thẻ ở trang chủ: hai nút số nổi + tấm ảnh thật */
.card .art > .gn-hcd { display: grid; place-items: center; width: 1.2em; height: 1.2em; flex: none; border-radius: 50%; font: 700 .7em/1 var(--font-letter); color: var(--navy);
  background: radial-gradient(circle at 36% 26%, #fff 0, #FBF9FF 45%, #CFC0FF 100%); border: 2px solid #7A4DFF; box-shadow: 0 .09em 0 #5630CF, 0 .2em .2em rgba(30, 42, 94, .3); }
.card .art > .gn-hcp { width: 1.9em; height: 1.9em; flex: none; object-fit: cover; border-radius: .3em; border: .09em solid #fff; box-shadow: 0 .09em 0 rgba(30, 42, 94, .25), 0 .2em .26em rgba(30, 42, 94, .3); }
.gn-lockq { position: absolute; font: 700 clamp(2rem, 9vw, 3.2rem)/1 var(--font-letter); color: #fff; text-shadow: var(--outline); }
.gn-isopen .gn-lockq { color: var(--yellow); }
.gn-card.gn-nope { animation: gn-nope .45s; }

@keyframes gn-draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes gn-halo { from { transform: scale(1); opacity: .95; } to { transform: scale(1.75); opacity: 0; } }
@keyframes gn-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.1); } }
@keyframes gn-wob { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(-16deg) scale(.92); } 50% { transform: rotate(13deg) scale(.92); } 80% { transform: rotate(-7deg); } }
@keyframes gn-hit { 0% { transform: scale(1); } 45% { transform: scale(1.5); } 100% { transform: scale(1); } }
@keyframes gn-popin { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes gn-ken { from { transform: scale(1.14); } to { transform: scale(1); } }
@keyframes gn-objin { from { transform: scale(.35) translateY(10%); } to { transform: scale(1) translateY(0); } }
@keyframes gn-float { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-3.5%) rotate(2deg); } }
@keyframes gn-ground { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(.86); opacity: .7; } }
@keyframes gn-sheen { 0% { opacity: 1; transform: translateX(-140%) skewX(-18deg); } 100% { opacity: 1; transform: translateX(440%) skewX(-18deg); } }
@keyframes gn-spin { to { transform: rotate(360deg); } }
@keyframes gn-boing { 0%, 100% { transform: scale(1); } 30% { transform: scale(1.06, .94); } 60% { transform: scale(.96, 1.05); } }
@keyframes gn-tilt { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg); } }
@keyframes gn-beat { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@keyframes gn-nope { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-6px) rotate(-3deg); } 50% { transform: translateX(6px) rotate(3deg); } 80% { transform: translateX(-3px); } }

@media (prefers-reduced-motion: reduce) {
  .gn *, .gn-svg * { animation: none !important; transition: none !important; }
  .gn-real::after { display: none; }
}

/* ----- công tắc "1 2 3" / "a b c" ở phòng tranh (nút to cho bé chạm) ----- */
.gn-mode { display: flex; gap: 12px; justify-content: center; }
.gn-mbtn { flex: 1 1 0; max-width: 220px; min-height: 60px; padding: 4px 10px; border-radius: 22px; border: 4px solid #fff; background: #EFE9FF; color: var(--navy); cursor: pointer;
  font: 700 clamp(1.5rem, 7vw, 2.2rem)/1.2 var(--font-letter); letter-spacing: .08em; box-shadow: 0 5px 0 rgba(30, 42, 94, .22), 0 9px 12px rgba(30, 42, 94, .14); -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.gn-mbtn.gn-mon { background: linear-gradient(160deg, #B79BFF, #7A4DFF 70%); color: #fff; border-color: var(--yellow); text-shadow: 0 2px 0 #4A28B8; }
.gn-mbtn:active { transform: translateY(4px); }
