/* ghep.css — GHÉP THẺ TÍNH NHẨM (js/ghep.js). Bảng ô lật ngửa: ô phép tính màu kem, ô kết quả màu xanh nhạt.
   --c / --r = số cột / số hàng khi cầm dọc (js đặt theo level); cầm ngang thì đổi chiều cho bảng nằm ngang. */

/* ===== chọn level + tốc độ (màn 'match') ===== */
.screen--match { gap: var(--space-2); }
.glvgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); flex: none; }
.glv {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 7px;
  border-radius: var(--radius-lg); background: var(--color-surface); color: var(--color-ink);
  border: var(--bw-2) solid var(--color-outline); box-shadow: 0 4px 0 var(--color-outline); transition: transform var(--dur-fast);
}
.glv b { font-family: var(--font-num); font-weight: 800; font-size: 30px; line-height: 1; min-height: 30px; display: grid; place-items: center; }
.glv b .ico { width: 24px; height: 24px; color: var(--color-lock); }
.glv small { font-size: 11.5px; color: var(--color-text-muted); }
.glv__stars { display: flex; gap: 2px; }
.glv__stars i { width: 16px; height: 16px; color: #D8D3E6; display: block; }
.glv__stars i.is-on { color: var(--color-gold); }
.glv__stars .ico { width: 100%; height: 100%; display: block; }
.glv.is-selected { transform: translateY(-3px); border-color: var(--color-primary); box-shadow: 0 6px 0 var(--color-primary-dark), 0 0 0 3px var(--color-primary-soft); }
.glv.is-locked { opacity: .55; }
.glvnote { align-self: center; text-align: center; font-size: var(--fs-sm); font-weight: 700; color: var(--color-ink); background: rgba(255,255,255,.86); padding: 4px 14px; border-radius: var(--radius-lg); }
.gspeeds { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); flex: none; }
.gspeed {
  display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 8px 4px; border-radius: var(--radius-lg);
  background: var(--color-surface); color: var(--color-ink); border: var(--bw-2) solid var(--color-outline); box-shadow: 0 4px 0 var(--color-outline);
}
.gspeed b { font-family: var(--font-head); font-size: var(--fs-md); line-height: 1.1; }
.gspeed small { font-size: 11.5px; color: var(--color-text-muted); }
.gspeed.is-selected { transform: translateY(-3px); border-color: var(--color-info); box-shadow: 0 6px 0 var(--color-info), 0 0 0 3px rgba(120, 200, 255, .45); }

/* ===== bàn ghép (màn 'ghep') ===== */
.ghep { --sw: min(100vw, 560px); --cols: var(--c); --rows: var(--r); }
.screen--ghep { height: 100%; gap: var(--space-2); overflow: hidden; }
.glevel {
  font-family: var(--font-head); font-weight: 800; font-size: var(--fs-md); letter-spacing: .04em; color: #fff; padding: 6px 16px; border-radius: 999px;
  background: linear-gradient(180deg, #FF8DB5, #F0508A); border: var(--bw-2) solid #fff; box-shadow: 0 4px 0 #C2386B; text-shadow: 0 2px 0 #C2386B;
}
.glevel b { font-family: var(--font-num); font-size: 1.25em; color: #FFF27A; }
.gbar { display: flex; align-items: center; gap: var(--space-2); flex: none; }
.gtime {
  position: relative; flex: 1; height: 28px; border-radius: 999px; overflow: hidden; border: var(--bw-2) solid #fff; box-shadow: 0 0 0 2px var(--color-ink), 0 4px 0 rgba(0,0,0,.14);
  background: linear-gradient(90deg, #FF5B6E 0%, #FFC531 36%, #C8F03C 62%, #4ED36B 100%);
}
.gtime__fill { position: absolute; top: 0; bottom: 0; right: 0; width: 0; background: #ECE8F5; transition: width .12s linear; }       /* tấm che: giờ đã trôi */
.gtime__num { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--font-num); font-weight: 800; font-size: 14px; color: var(--color-ink); text-shadow: 0 1px 0 rgba(255,255,255,.85), 0 0 4px rgba(255,255,255,.9); }
.gscore { flex: none; font-size: 12px; font-weight: 700; color: var(--color-ink); background: rgba(255,255,255,.9); padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.gscore b { font-family: var(--font-num); font-size: 18px; }
.gbar__reset { width: 40px; height: 40px; }
.gbar__reset .ico { width: 20px; height: 20px; }

.gboard {
  flex: 1 1 0; min-height: 0; display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); grid-auto-rows: minmax(0, 1fr); gap: 6px; padding: 8px;
  max-height: calc((var(--sw) - 48px) / var(--cols) * var(--rows) * 1.02 + 46px);
  border-radius: var(--radius-xl); background: rgba(255,255,255,.5); border: var(--bw-2) solid #fff; box-shadow: 0 5px 0 rgba(0,0,0,.12), inset 0 0 0 2px rgba(255,255,255,.4);
}
.gtile {
  position: relative; min-width: 0; min-height: 0; padding: 0; display: grid; place-items: center; border-radius: var(--radius-md);
  background: linear-gradient(180deg, #FFFEF6, #FFF0C9); color: var(--color-ink); border: var(--bw-2) solid #E9C782; box-shadow: 0 3px 0 #D6AE62;
  font-family: var(--font-num); font-weight: 800; line-height: 1; white-space: nowrap; letter-spacing: -.01em;
  font-size: clamp(12px, calc((var(--sw) - 48px) / var(--cols) * .27), 28px);
  transition: transform var(--dur-fast), box-shadow var(--dur-fast); -webkit-tap-highlight-color: transparent;
}
.gtile[data-kind="a"] {
  background: linear-gradient(180deg, #F4FBFF, #D2EEFF); color: #12407A; border-color: #8DCBF0; box-shadow: 0 3px 0 #6CB2DD;
  font-size: clamp(15px, calc((var(--sw) - 48px) / var(--cols) * .36), 36px);
}
.gtile:active { transform: translateY(2px); }
.gtile.is-sel { transform: translateY(-3px) scale(1.07); z-index: 2; border-color: #fff; box-shadow: 0 0 0 3px var(--color-gold), 0 7px 0 #E08A00, 0 0 14px rgba(255, 200, 40, .8); }
.gtile.is-no { animation: g-no .5s; }
.gtile.is-hint { z-index: 2; border-color: #fff; box-shadow: 0 0 0 3px var(--color-success), 0 0 14px rgba(60, 210, 120, .9); animation: g-hint .5s 3; }
.gtile.is-done { animation: g-eat .42s var(--ease-bounce) forwards; pointer-events: none; }
.gtile.is-target { border-color: #fff; box-shadow: 0 0 0 3px var(--color-gold), 0 0 18px rgba(255, 220, 90, .95); animation: g-hint .45s infinite; }
@keyframes g-no { 0%, 100% { transform: none; } 20% { transform: translateX(-5px) rotate(-3deg); } 40% { transform: translateX(5px) rotate(3deg); } 60% { transform: translateX(-4px) rotate(-2deg); } 80% { transform: translateX(3px); } }
@keyframes g-hint { 50% { transform: scale(1.1); } }
@keyframes g-eat { 0% { transform: scale(1); opacity: 1; } 35% { transform: scale(1.24); opacity: 1; filter: brightness(1.25); } 100% { transform: scale(.2) rotate(14deg); opacity: 0; visibility: hidden; } }

.gfoot { display: flex; align-items: center; gap: var(--space-3); flex: none; background: rgba(255,255,255,.88); border-radius: var(--radius-lg); padding: 5px 14px 5px 6px; }
.ghero { position: relative; flex: none; width: 58px; }
.ghero .art { width: 58px; display: block; }
.gcombo { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.gcombo small { font-size: 11.5px; font-weight: 700; color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gpips { display: flex; gap: 6px; }
.gpips i { flex: 1; max-width: 34px; height: 12px; border-radius: 999px; background: #E4E0EF; box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px var(--color-outline); transition: background .15s, transform .15s; }
.gpips i.is-on { background: linear-gradient(180deg, #FFE680, #FFB21F); transform: scale(1.1); box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px #E08A00, 0 0 9px rgba(255, 190, 40, .85); }
.gleft { flex: none; font-size: var(--fs-sm); font-weight: 700; color: var(--color-ink); white-space: nowrap; }
.gleft b { font-family: var(--font-num); font-size: 22px; }

/* chữ bật giữa màn hình (COMBO, phép vừa bị chiêu bắn tan, lời nhắn hết giờ) */
.gbanner { position: fixed; left: 0; right: 0; top: 30%; z-index: 18; display: grid; place-items: center; pointer-events: none; text-align: center; padding: 0 16px; }
.gbanner .comic { font-size: clamp(36px, 12vw, 68px); animation: banner-in .45s var(--ease-bounce) both; }
.gnote { display: inline-block; background: rgba(24, 14, 66, .88); color: #fff; padding: 8px 18px; border-radius: 999px; font-weight: 800; font-size: var(--fs-md); animation: banner-in .4s var(--ease-bounce) both; }
.gnote--eq { font-family: var(--font-num); font-size: clamp(26px, 9vw, 44px); background: #fff; color: var(--color-ink); border: 3px solid var(--color-gold); box-shadow: 0 5px 0 #E08A00; }

/* lúc ra chiêu: nền tối lại, nhân vật và hai ô bị nhắm nổi lên trên lớp tối */
.ghep[data-dim="1"] .vfxdim { opacity: 1; }
.ghep[data-dim="1"] .gtile.is-target, .ghep[data-dim="1"] .ghero { z-index: 16; }

/* xong level */
.gdone { position: fixed; inset: 0; z-index: 30; display: flex; padding: 20px; background: rgba(24, 14, 66, .58); overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; }   /* màn thấp thì cuộn được tới hàng nút cuối */
.gdone__conf { position: fixed; inset: 0; overflow: hidden; pointer-events: none; }                 /* pháo giấy rơi ở lớp riêng, không làm khung cuộn dài ra */
.gdone[hidden] { display: none; }
.gdone__card {
  position: relative; z-index: 1; margin: auto; flex: none; width: min(100%, 380px); display: flex; flex-direction: column; gap: var(--space-3); align-items: stretch; text-align: center;
  background: var(--color-surface); border-radius: var(--radius-xl); border: var(--bw-4) solid #fff; box-shadow: 0 10px 0 rgba(0,0,0,.22); padding: 18px 16px 16px;
  animation: banner-in .5s var(--ease-bounce) both;
}
.gdone__stars { display: flex; justify-content: center; gap: 8px; }
.gdone__stars i { width: 56px; height: 56px; color: #DAD6E6; display: block; }
.gdone__stars i .ico { width: 100%; height: 100%; display: block; }
.gdone__stars i.is-on { color: var(--color-gold); filter: drop-shadow(0 3px 0 #E08A00); animation: pair-pop .5s var(--ease-bounce) calc(var(--i) * .16s) both; }
.gdone__title { margin: 0; font-size: 34px; line-height: 1.1; }
.gdone .chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }

/* ===== màn rộng và cầm ngang: bảng nằm ngang (nhiều cột, ít hàng) ===== */
@media (min-width: 768px) { .ghep { --sw: min(100vw, 660px); } }
@media (min-width: 1024px) { .ghep { --sw: min(100vw, 700px); } }
@media (orientation: landscape) {
  .ghep { --cols: var(--cw); --rows: var(--rw); }
}
@media (orientation: landscape) and (max-height: 540px) {
  .screen--ghep { max-width: 1000px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); gap: 6px 10px; }
  .screen--ghep .topbar { grid-column: 1 / -1; }
  .gbar { grid-column: 1; grid-row: 2; }
  .gfoot { grid-column: 2; grid-row: 2; }            /* thanh giờ và thanh liên tiếp nằm chung một hàng, nhường chiều cao cho bảng ô */
  .gboard { grid-column: 1 / -1; grid-row: 3; }
  .ghep { --sw: min(100vw, 1000px); }
  .screen--ghep .topbar { min-height: 44px; }
  .gboard { gap: 4px; padding: 5px; max-height: none; }
  .gtile { font-size: clamp(11px, calc((100vh - 140px) / var(--rows) * .44), 22px); border-radius: var(--radius-sm); }
  .gtile[data-kind="a"] { font-size: clamp(12px, calc((100vh - 140px) / var(--rows) * .52), 26px); }
  .ghero, .ghero .art { width: 40px; }
  .gfoot { padding: 3px 12px 3px 5px; }
  .gbanner { top: 22%; }
  .gdone { padding: 10px; }
  .gdone__card { width: min(100%, 560px); gap: 8px; padding: 12px 14px; }
  .gdone__stars i { width: 38px; height: 38px; }
  .gdone__title { font-size: 26px; }
  .gdone .btn--cta { min-height: 52px; font-size: var(--fs-lg); }
}
@media (max-height: 640px) and (orientation: portrait) {
  .ghero, .ghero .art { width: 44px; }
  .gboard { gap: 5px; padding: 6px; }
}
