/* Tro choi tu choi o nha — Keo co, Doan tau tri thuc, Lat manh ghep */

/* ══════════════ KEO CO ══════════════ */
.tn-kc-muc { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.tn-kc-muc-nut { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 16px; min-width: 96px; }
.tn-kc-muc-nut small { font-size: .72rem; font-weight: 700; color: var(--fg-text-muted); }
.tn-kc-muc-nut[aria-pressed="true"] { background: var(--tn-vang); color: #4a2c08; box-shadow: 0 4px 0 var(--tn-vang-dam); }
.tn-kc-muc-nut[aria-pressed="true"] small { color: #6b4405; }

.tn-kc-dau { display: flex; flex-direction: column; gap: 6px; }
.tn-kc-nhan { display: flex; justify-content: space-between; align-items: center; font-weight: 800; font-size: .9rem; }
.tn-kc-nhan-em, .tn-kc-nhan-may { display: inline-flex; align-items: center; gap: 4px; }
.tn-kc-nhan-em { color: var(--tn-b); }
.tn-kc-nhan-may { color: var(--tn-a); }
.tn-kc-nhan-ic { height: 1.9em; width: auto; }
.tn-kc-muc-nho { font-size: .75rem; color: var(--fg-text-muted); background: var(--color-gray-100); border-radius: 999px; padding: 1px 10px; }
/* San keo co: troi, doi, co. Sprite ban nho va ro-bot dung tren co, tay o ngang day.
   Ty le theo viewBox sprite: cao san = 172 don vi, ban nho 140, ro-bot 156, chan cach day 4,
   tay cach chan 60.5 -> day o 62.5% chieu cao san. */
.tn-kc-bai {
  --h: clamp(128px, 32vw, 184px);
  position: relative; height: var(--h); border-radius: 20px; overflow: hidden;
  border: 3px solid #2b1d3a;
  background:
    linear-gradient(90deg, rgba(47, 124, 246, .13) 0 50%, rgba(229, 72, 77, .13) 50% 100%),
    linear-gradient(180deg, transparent 0 64%, #8bc34a 64% 84%, #689f38 84%),
    radial-gradient(ellipse 34% 30% at 16% 66%, #a5d6a7 0 98%, transparent 100%),
    radial-gradient(ellipse 42% 36% at 84% 68%, #9ccc65 0 98%, transparent 100%),
    radial-gradient(ellipse 9% 8% at 34% 20%, rgba(255, 255, 255, .92) 0 96%, transparent 100%),
    radial-gradient(ellipse 6% 6% at 39% 16%, rgba(255, 255, 255, .92) 0 96%, transparent 100%),
    radial-gradient(ellipse 8% 7% at 70% 26%, rgba(255, 255, 255, .85) 0 96%, transparent 100%),
    linear-gradient(180deg, #7fccff 0%, #d9f2ff 64%);
}
/* Bui tung len truoc chan ban nho (trai) va ro-bot (phai) */
.tn-kc-bai::before, .tn-kc-bai::after {
  content: ''; position: absolute; z-index: 3; bottom: 0; width: calc(var(--h) * .2); aspect-ratio: 48 / 30; pointer-events: none;
  background: url(/images/game/tug-dust.svg) center / contain no-repeat; opacity: .9;
}
.tn-kc-bai::before { left: calc(1% + var(--h) * .5); }
.tn-kc-bai::after { right: calc(1% + var(--h) * .52); transform: scaleX(-1); }
/* Vach phan san tren co (vach giua + vach dich hai ben) */
.tn-kc-vach { position: absolute; top: 72%; height: 10%; width: 3px; margin-left: -1.5px; background: rgba(255, 255, 255, .7); border-radius: 2px; }
.tn-kc-vach.giua { top: 48%; height: 50%; width: 4px; margin-left: -2px; background: #fff8ec; opacity: .9; }
.tn-kc-vach.dich-em, .tn-kc-vach.dich-may { top: 52%; height: 46%; width: 0; margin-left: -2px; background: none; border-left: 4px dashed var(--tn-b); }
.tn-kc-vach.dich-may { border-left-color: var(--tn-a); }
.tn-kc-day {
  position: absolute; z-index: 1; left: -50%; width: 200%; top: 62.5%; height: 13px; margin-top: -6.5px;
  background: url(/images/game/tug-rope.svg) 0 0 / 22px 100% repeat-x;
  filter: drop-shadow(0 3px 0 rgba(43, 29, 58, .18));
  transition: transform .45s cubic-bezier(.3, 1.35, .5, 1);
}
/* No ruy bang giua day: vang khi can bang, xanh khi nghieng ve Em, do khi nghieng ve May */
.tn-kc-nut {
  position: absolute; left: 50%; top: 50%; width: 38px; height: 41px; margin: -9px 0 0 -19px;
  background: url(/images/game/tug-flag.svg) center / contain no-repeat;
}
.tn-kc-dau.nghieng-em .tn-kc-nut { background-image: url(/images/game/tug-flag-blue.svg); }
.tn-kc-dau.nghieng-may .tn-kc-nut { background-image: url(/images/game/tug-flag-red.svg); }
.tn-kc-nguoi {
  position: absolute; z-index: 2; bottom: 2.3%; width: auto; max-width: none;
  transform-origin: 50% 100%; transition: transform .35s ease; user-select: none; -webkit-user-select: none;
}
.tn-kc-em { left: 1%; height: 81.4%; }
.tn-kc-may { right: 1%; height: 90.7%; }
/* Ben dang thang nga nguoi ra sau, ben dang thua chui ve phia truoc */
.tn-kc-dau.nghieng-em .tn-kc-em { transform: rotate(-5deg); }
.tn-kc-dau.nghieng-em .tn-kc-may { transform: rotate(-6deg); }
.tn-kc-dau.nghieng-may .tn-kc-may { transform: rotate(5deg); }
.tn-kc-dau.nghieng-may .tn-kc-em { transform: rotate(6deg); }
.tn-kc-em.keo { animation: tnKcKeoTrai .4s ease; }
.tn-kc-may.keo { animation: tnKcKeoPhai .4s ease; }
.tn-kc-dau.thang .tn-kc-em, .tn-kc-dau.thua .tn-kc-may { animation: tnKcNhay .5s ease 3; }
.tn-kc-dau.thang .tn-kc-may, .tn-kc-dau.thua .tn-kc-em { opacity: .55; }
@keyframes tnKcKeoTrai { 50% { transform: translateX(-8px) rotate(-12deg); } }
@keyframes tnKcKeoPhai { 50% { transform: translateX(8px) rotate(12deg); } }
@keyframes tnKcNhay { 50% { transform: translateY(-16%); } }
/* Man gioi thieu: ban nho va ro-bot dung doi dien */
.tn-kc-moi { display: inline-flex; align-items: flex-end; gap: 10px; }
.tn-kc-moi img { height: clamp(78px, 20vw, 104px); width: auto; }
.tn-kc-moi img + img { height: clamp(87px, 22.3vw, 116px); }
.tn-kc-dem { display: flex; align-items: center; gap: 8px; font-size: .78rem; font-weight: 800; color: var(--fg-text-muted); }
.tn-kc-dem i { flex: 1; height: 8px; border-radius: 999px; background: var(--color-gray-100); overflow: hidden; }
.tn-kc-dem b { display: block; height: 100%; width: 0; border-radius: 999px; background: #ffb35c; }
.tn-kc-dem b.gap { background: var(--tn-a); }
.tn-kc-hoi { display: flex; flex-direction: column; }

/* ══════════════ DOAN TAU TRI THUC ══════════════ */
.tn-dt-ray {
  position: relative; border-radius: 20px; padding: 10px 10px 8px; overflow: hidden;
  border: 3px solid #2b1d3a;
  background:
    linear-gradient(180deg, transparent 0 calc(100% - 10px), #6d4c41 calc(100% - 10px)),
    radial-gradient(ellipse 30% 34% at 12% 100%, #81c784 0 98%, transparent 100%),
    radial-gradient(ellipse 38% 40% at 62% 100%, #a5d6a7 0 98%, transparent 100%),
    radial-gradient(ellipse 30% 30% at 96% 100%, #81c784 0 98%, transparent 100%),
    radial-gradient(ellipse 7% 13% at 72% 22%, rgba(255, 255, 255, .92) 0 96%, transparent 100%),
    radial-gradient(ellipse 5% 10% at 76% 15%, rgba(255, 255, 255, .92) 0 96%, transparent 100%),
    radial-gradient(ellipse 6% 11% at 42% 30%, rgba(255, 255, 255, .8) 0 96%, transparent 100%),
    radial-gradient(circle at 92% 18%, #fff59d 0 18px, rgba(255, 245, 157, .35) 19px 28px, transparent 29px),
    linear-gradient(180deg, #6ec6ff 0%, #c9ecff 100%);
}
.tn-dt-dem {
  position: relative; z-index: 2;
  display: inline-flex; align-items: center; gap: 6px; font-weight: 800; font-size: .9rem; color: #2b1d3a;
  background: #fff8ec; border: 2px solid #2b1d3a; border-radius: 999px; padding: 2px 12px 2px 6px; box-shadow: 0 3px 0 rgba(43, 29, 58, .25);
}
.tn-dt-dem-ic { height: 22px; width: auto; }
.tn-dt-dem b { font-size: 1.15rem; color: #c62828; font-variant-numeric: tabular-nums; }
.tn-dt-tau { position: relative; z-index: 1; display: flex; align-items: flex-end; gap: 4px; margin-top: 10px; min-height: 66px; }
.tn-dt-dau { flex: none; position: relative; z-index: 1; display: block; line-height: 0; }
.tn-dt-dau img { display: block; height: clamp(54px, 15vw, 64px); width: auto; }
.tn-dt-dau.hu { animation: tnDtHu .4s ease; }
/* Khoi tu ong khoi (ong khoi o khoang 28% chieu ngang dau tau) */
.tn-dt-khoi {
  position: absolute; left: 20%; top: -12px; width: 26px; height: 20px; opacity: 0; pointer-events: none;
  background: url(/images/game/train-smoke.svg) center / contain no-repeat;
}
.tn-dt-ray.chay .tn-dt-khoi { animation: tnDtKhoi 1.8s ease-out infinite; }
.tn-dt-ray.chay .tn-dt-khoi.k2 { animation-delay: .6s; }
.tn-dt-ray.chay .tn-dt-khoi.k3 { animation-delay: 1.2s; }
.tn-dt-toas { flex: 1; min-width: 0; display: flex; align-items: flex-end; gap: 4px; overflow: hidden; padding-top: 4px; }
/* Toa: sprite thung mau + bang chu kem; chu Han nam tren bang */
.tn-dt-toa {
  position: relative; flex: none; width: 56px; height: auto; aspect-ratio: 56 / 59; margin-bottom: 1px;
  background: url(/images/game/train-wagon-red.svg) 0 0 / 100% 100% no-repeat;
}
.tn-dt-toa.m1 { background-image: url(/images/game/train-wagon-blue.svg); }
.tn-dt-toa.m2 { background-image: url(/images/game/train-wagon-yellow.svg); }
.tn-dt-toa.m3 { background-image: url(/images/game/train-wagon-green.svg); }
.tn-dt-zh {
  position: absolute; left: 9%; right: 9%; top: 6%; height: 46%; display: grid; place-items: center;
  font-family: var(--font-hanzi); font-weight: 700; font-size: 1.3rem; line-height: 1; white-space: nowrap; color: #c62828;
}
.tn-dt-toa.m1 .tn-dt-zh { color: #1554c0; }
.tn-dt-toa.m2 .tn-dt-zh { color: #a15c00; }
.tn-dt-toa.m3 .tn-dt-zh { color: #157a40; }
.tn-dt-toa.dai .tn-dt-zh { font-size: 1rem; }
.tn-dt-toa.rat-dai .tn-dt-zh { font-size: .78rem; }
.tn-dt-toa.moi { animation: tnDtVao .45s cubic-bezier(.3, 1.4, .5, 1); }
.tn-dt-toa.roi { animation: tnDtRoi .45s ease-in forwards; }
.tn-dt-an {
  flex: none; align-self: center; margin-bottom: 8px; font-weight: 900; font-size: .85rem; color: #2b1d3a;
  background: #fff8ec; border: 2px solid #2b1d3a; border-radius: 999px; padding: 2px 8px;
}
/* Duong ray: sprite ray + ta vet lap ngang */
.tn-dt-duong {
  height: 16px; margin: -2px -10px 0;
  background: url(/images/game/train-track.svg) 0 0 / 22px 16px repeat-x, linear-gradient(180deg, transparent 0 6px, #a1887f 6px);
}
.tn-dt-ray.chay .tn-dt-duong { animation: tnDtRay .6s linear infinite; }
.tn-dt-ray.chay .tn-dt-dau { animation: tnDtLac 1.2s ease-in-out infinite; }
.tn-dt-ray.chay .tn-dt-dau.hu { animation: tnDtHu .4s ease; }
.tn-dt-hoi { display: flex; flex-direction: column; }
@keyframes tnDtRay { to { background-position: 22px 0, 0 0; } }
@keyframes tnDtKhoi { 0% { opacity: 0; transform: translate(0, 0) scale(.5); } 15% { opacity: .95; } 100% { opacity: 0; transform: translate(26px, -30px) scale(1.5); } }
@keyframes tnDtLac { 50% { transform: translateY(-2px); } }
@keyframes tnDtHu { 40% { transform: scale(1.15) rotate(-6deg); } }
@keyframes tnDtVao { from { opacity: 0; transform: translateX(40px) scale(.7); } }
@keyframes tnDtRoi { to { opacity: 0; transform: translate(20px, 50px) rotate(25deg); } }

/* ══════════════ LAT MANH GHEP ══════════════ */
.tn-mg-so { font-size: .85rem; font-weight: 800; color: var(--fg-text-muted); background: var(--color-gray-100); border-radius: 999px; padding: 2px 10px; }
.tn-mg-goi { font-size: 1rem; font-weight: 700; color: var(--fg-gray-800); }
.tn-mg-luu {
  margin: 0; font-size: .88rem; line-height: 1.5; color: var(--fg-gray-800);
  background: var(--color-gray-100); border-radius: 12px; padding: 8px 12px;
}
.tn-mg-khu { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; justify-content: center; }
.tn-mg-tranh {
  position: relative; flex: none; width: min(calc(100% - 20px), 340px); aspect-ratio: 1 / 1; border-radius: 22px; overflow: hidden;
  container-type: inline-size; box-sizing: border-box; margin: 10px;
  border: 4px solid #2b1d3a;
  box-shadow: 0 0 0 7px #fff8ec, 0 0 0 10px #2b1d3a, 0 14px 0 6px rgba(43, 29, 58, .18);
}
.tn-mg-hinh {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center; line-height: 1;
  font-size: 9rem; font-size: 62cqi;
}
.tn-mg-hinh.la-chu {
  font-family: var(--font-hanzi); font-weight: 700; color: #fff; text-shadow: 0 4px 0 rgba(0, 0, 0, .25);
  font-size: 7rem; font-size: 56cqi; white-space: nowrap;
}
.tn-mg-hinh.la-chu.c2 { font-size: 4.6rem; font-size: 40cqi; }
.tn-mg-hinh.la-chu.c3 { font-size: 3.2rem; font-size: 28cqi; }
.tn-mg-hinh.la-chu.c4 { font-size: 2.4rem; font-size: 21cqi; }
.tn-mg-tranh.lo .tn-mg-hinh { animation: tnMgLo .6s cubic-bezier(.3, 1.4, .5, 1); }
.tn-mg-luoi { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 0; }
.tn-mg-o {
  font: inherit; border: none; margin: 0; padding: 0; cursor: pointer; color: #fff; border-radius: 0;
  display: grid; place-items: center; font-weight: 900; font-size: clamp(1.4rem, 7vw, 2.2rem);
  background: url(/images/game/puzzle-tile-red.svg) 0 0 / 100% 100% no-repeat;
  transition: opacity .35s ease, transform .35s ease, visibility 0s linear .35s;
}
.tn-mg-o span { position: relative; top: -3%; text-shadow: 0 3px 0 rgba(43, 29, 58, .45), 0 0 6px rgba(43, 29, 58, .25); }
.tn-mg-o.m1 { background-image: url(/images/game/puzzle-tile-blue.svg); }
.tn-mg-o.m2 { background-image: url(/images/game/puzzle-tile-yellow.svg); }
.tn-mg-o.m3 { background-image: url(/images/game/puzzle-tile-green.svg); }
.tn-mg-o:hover:not(:disabled) { filter: brightness(1.08); }
.tn-mg-o:active:not(:disabled) { transform: scale(.95); }
.tn-mg-o:focus-visible { outline: 4px solid var(--color-gold-500); outline-offset: -6px; }
.tn-mg-o.dang-chon { outline: 4px solid #fff8ec; outline-offset: -9px; animation: tnMgNhap .9s ease-in-out infinite; }
.tn-mg-o.mo { opacity: 0; transform: scale(.6) rotate(8deg); visibility: hidden; pointer-events: none; }
/* Lo tranh: ngoi sao nho bung ra o hai goc */
.tn-mg-tranh::before, .tn-mg-tranh::after {
  content: ''; position: absolute; z-index: 3; width: 18%; aspect-ratio: 1; pointer-events: none; opacity: 0;
  background: url(/images/game/puzzle-star.svg) center / contain no-repeat;
}
.tn-mg-tranh::before { left: 5%; top: 5%; }
.tn-mg-tranh::after { right: 5%; bottom: 5%; width: 14%; }
.tn-mg-tranh.lo::before, .tn-mg-tranh.lo::after { opacity: 1; animation: tnMgSao .7s cubic-bezier(.3, 1.5, .5, 1) both; }
.tn-mg-tranh.lo::after { animation-delay: .15s; }
.tn-mg-ben { flex: 1 1 260px; min-width: 0; max-width: 520px; display: flex; flex-direction: column; gap: 10px; }
.tn-mg-nhac { margin: 0; color: var(--fg-gray-800); font-weight: 600; line-height: 1.5; }
.tn-mg-thuong {
  margin: 0; align-self: flex-start; font-weight: 800; color: #4a2c08; background: var(--tn-vang);
  border-radius: 999px; padding: 4px 14px; box-shadow: 0 3px 0 var(--tn-vang-dam);
}
.tn-mg-lzh { display: block; font-family: var(--font-hanzi); }
.tn-mg-lpy { display: block; font-family: var(--font-latin, inherit); font-size: .9rem; font-weight: 600; opacity: .9; }
.tn-mg-lui { align-self: flex-start; padding: 8px 14px; font-size: .9rem; }
.tn-mg-dapan {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  background: var(--color-gray-100); border-radius: 18px; padding: 14px;
}
.tn-mg-dem { font-size: 2.6rem; line-height: 1; }
.tn-mg-dzh { font-family: var(--font-hanzi); font-size: clamp(2.2rem, 8vw, 3rem); font-weight: 700; color: var(--fg-gray-900); line-height: 1.1; }
.tn-mg-dpy { font-size: 1.1rem; font-weight: 600; color: var(--fg-pinyin); }
.tn-mg-dvn { font-size: 1.2rem; font-weight: 800; color: var(--fg-gray-900); }
.tn-mg-hang { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
@keyframes tnMgLo { from { transform: scale(.7); } }
@keyframes tnMgNhap { 50% { filter: brightness(1.18); } }
@keyframes tnMgSao { from { transform: scale(0) rotate(-60deg); } }

@media (max-width: 520px) {
  .tn-mg-tranh { width: min(calc(100% - 20px), 300px); }
  .tn-mg-khu { gap: 12px; }
  .tn-mg-ben { flex-basis: 100%; }
  .tn-dt-toa { width: 52px; }
  .tn-kc-nhan-ic { height: 1.6em; }
}

@media (prefers-reduced-motion: reduce) {
  .tn-kc-day, .tn-mg-o { transition: none; }
  .tn-kc-nguoi { transition: none; }
  .tn-kc-nguoi, .tn-kc-dau.thang .tn-kc-em, .tn-kc-dau.thua .tn-kc-may,
  .tn-dt-dau, .tn-dt-toa, .tn-dt-duong, .tn-mg-o.dang-chon, .tn-mg-tranh.lo .tn-mg-hinh,
  .tn-mg-tranh.lo::before, .tn-mg-tranh.lo::after { animation: none !important; }
  .tn-dt-khoi { display: none; }
}
