:root {
  --cream: #fdf3d6;
  --cream-2: #f7e2a8;
  --brown: #6b4a2b;
  --ink: #3a2a1a;
  --font: "Nunito", Arial, sans-serif;
  --title: "Lilita One", "Nunito", sans-serif;
  /* mặt sau thẻ — đổi theo thế giới */
  --back: #efe7da;
  --back-edge: #cbbca6;
  --back-mark: #c9b8a0;
  --face: #f3eee6;
  --face-edge: #fffdf8;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1a120c;
  font-family: var(--font);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
[hidden] {
  display: none !important;
}
button {
  font-family: var(--font);
  cursor: pointer;
}

.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  /* clip: không cho trình duyệt tự cuộn khung khi focus vào thẻ */
  overflow: clip;
}

/* ---------- Khung cảnh từng thế giới ---------- */
.bg {
  position: absolute;
  inset: 0;
  transition: background 0.6s;
}
.bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(0, 0, 0, 0.45));
  pointer-events: none;
}
.deco {
  position: absolute;
  line-height: 1;
  filter: saturate(0.9) drop-shadow(0 8px 14px rgba(0, 0, 0, 0.35));
  pointer-events: none;
}
.deco.soft {
  filter: blur(1.5px) saturate(0.8) opacity(0.75);
}
.deco.flicker {
  animation: flicker 1.6s ease-in-out infinite alternate;
}
@keyframes flicker {
  to {
    transform: scale(1.06) translateY(-3px);
    filter: brightness(1.2) drop-shadow(0 0 30px rgba(255, 170, 40, 0.9));
  }
}
.deco.sway {
  animation: sway 5s ease-in-out infinite alternate;
  transform-origin: bottom center;
}
@keyframes sway {
  to {
    transform: rotate(4deg);
  }
}
.deco.float {
  animation: floaty 6s ease-in-out infinite alternate;
}
@keyframes floaty {
  to {
    transform: translate(18px, -14px);
  }
}

.world-temple {
  --back: #efe7da;
  --back-edge: #cbbca6;
  --back-mark: #c4b29a;
}
.world-jungle {
  --back: #f4b52a;
  --back-edge: #c98410;
  --back-mark: #a65e0e;
}
.world-ocean {
  --back: #5fcad8;
  --back-edge: #2b8ea0;
  --back-mark: #1d6c7e;
}
.world-desert {
  --back: #f39257;
  --back-edge: #c45d2c;
  --back-mark: #8c3a17;
}

/* ---------- Thanh trên ---------- */
.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(14px, env(safe-area-inset-top)) 18px 0;
  z-index: 4;
  pointer-events: none;
}
.hud > * {
  pointer-events: auto;
}
.sq {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(#fff4d6, #f3dca6);
  box-shadow:
    0 3px 0 #b8925a,
    0 6px 12px rgba(0, 0, 0, 0.3);
  color: var(--brown);
  font: 900 20px var(--font);
  text-decoration: none;
}
.sq svg {
  width: 22px;
  fill: #8a6a42;
}
.sq:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #b8925a;
}
.pill {
  height: 46px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-radius: 12px;
  background: rgba(30, 18, 10, 0.55);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  color: #fff3d8;
  font: 900 18px var(--font);
}
.stars i {
  font-style: normal;
  font-size: 24px;
  color: #ffc23a;
  text-shadow:
    0 2px 0 #b06b0a,
    0 0 6px rgba(255, 190, 60, 0.6);
  transition:
    color 0.3s,
    transform 0.3s;
}
.stars i.off {
  color: #6d5a45;
  text-shadow: none;
  transform: scale(0.85);
}
.limit {
  gap: 6px;
}
.limit.warn {
  color: #ff8a6b;
  animation: pulse 0.6s ease-in-out infinite alternate;
}
@keyframes pulse {
  to {
    transform: scale(1.06);
  }
}
.lvl {
  margin-left: auto;
}
.next-btn {
  position: absolute;
  left: 50%;
  top: max(14px, env(safe-area-inset-top));
  transform: translateX(-50%);
  height: 46px;
  padding: 0 20px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(#fff6db, #f5df9f);
  box-shadow:
    0 3px 0 #b8925a,
    0 8px 18px rgba(0, 0, 0, 0.35);
  color: var(--brown);
  font: 900 17px var(--font);
  animation: nextIn 0.4s cubic-bezier(0.3, 1.5, 0.5, 1);
}
.next-btn span {
  margin-left: 6px;
}
@keyframes nextIn {
  from {
    transform: translate(-50%, -30px);
    opacity: 0;
  }
}

/* ---------- Bàn thẻ ---------- */
.board {
  position: absolute;
  display: grid;
  gap: var(--gap, 12px);
  grid-template-columns: repeat(var(--cols), var(--card));
  grid-auto-rows: var(--card);
  z-index: 2;
}
.card {
  position: relative;
  padding: 0;
  border: 0;
  background: none;
  perspective: 900px;
}
.card.empty {
  visibility: hidden;
  pointer-events: none;
}
.card .inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.36s cubic-bezier(0.4, 0.2, 0.2, 1);
}
.card.flipped .inner {
  transform: rotateY(180deg);
}
.card .back,
.card .face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 14%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.card .back {
  background:
    repeating-conic-gradient(from 0deg, rgba(255, 255, 255, 0.22) 0 7deg, transparent 7deg 18deg),
    var(--back);
  box-shadow:
    inset 0 0 0 calc(var(--card) * 0.045) var(--back-edge),
    inset 0 0 0 calc(var(--card) * 0.065) rgba(255, 255, 255, 0.35),
    0 calc(var(--card) * 0.035) 0 rgba(0, 0, 0, 0.18),
    0 6px 14px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}
.card .back::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.55), transparent 62%);
}
.card .back span {
  position: relative;
  font: calc(var(--card) * 0.5) / 1 var(--title);
  color: var(--back-mark);
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.35);
}
.card:hover:not(.flipped) .back {
  filter: brightness(1.08);
}
.card .face {
  transform: rotateY(180deg);
  background: radial-gradient(circle at 50% 40%, #fffaf0, var(--face) 70%);
  box-shadow:
    inset 0 0 0 calc(var(--card) * 0.05) var(--face-edge),
    inset 0 0 0 calc(var(--card) * 0.058) #e2d6c2,
    0 calc(var(--card) * 0.035) 0 rgba(0, 0, 0, 0.15),
    0 6px 14px rgba(0, 0, 0, 0.3);
}
.card .face span,
.fx .face span {
  font-size: calc(var(--card) * 0.56);
  line-height: 1;
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.25));
}
.card.gone {
  visibility: hidden;
}
.card.reveal {
  animation: revealPop 0.45s cubic-bezier(0.3, 1.6, 0.5, 1) both;
}
@keyframes revealPop {
  from {
    transform: scale(0.4);
    opacity: 0;
  }
}
.card.shake .inner {
  animation: shake 0.35s;
}
@keyframes shake {
  25% {
    transform: rotateY(180deg) translateX(-5px);
  }
  75% {
    transform: rotateY(180deg) translateX(5px);
  }
}
.app.peek .card:not(.gone) .inner {
  transform: rotateY(180deg);
}

/* ---------- Hiệu ứng ghép đúng ---------- */
.fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
}
.fx .face {
  position: absolute;
  display: grid;
  place-items: center;
  border-radius: 14%;
  background: radial-gradient(circle at 50% 40%, #fffaf0, var(--face) 70%);
  box-shadow:
    inset 0 0 0 calc(var(--card) * 0.05) var(--face-edge),
    0 14px 30px rgba(0, 0, 0, 0.4);
}
.rays {
  position: absolute;
  border-radius: 50%;
  background: repeating-conic-gradient(rgba(255, 244, 190, 0.75) 0 9deg, transparent 9deg 22deg);
  -webkit-mask: radial-gradient(circle, #000 18%, transparent 68%);
  mask: radial-gradient(circle, #000 18%, transparent 68%);
}

/* ---------- Đèn pin ---------- */
.booster {
  position: absolute;
  right: 18px;
  top: 50%;
  z-index: 4;
  width: 72px;
  height: 72px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(#fff6dc, #f3dca6);
  box-shadow:
    0 4px 0 #b8925a,
    0 10px 18px rgba(0, 0, 0, 0.35);
  transform: translateY(-50%);
}
.booster .ico {
  display: block;
  font-size: 32px;
  line-height: 1;
  transform: rotate(-35deg);
}
.booster b {
  display: block;
  margin-top: 2px;
  font: 900 20px var(--font);
  color: #5a4632;
}
.booster:disabled {
  filter: grayscale(0.8) opacity(0.6);
  cursor: default;
}
.booster:active:not(:disabled) {
  transform: translateY(calc(-50% + 3px));
}
.tip {
  position: absolute;
  right: 102px;
  top: 50%;
  z-index: 5;
  width: min(290px, 60vw);
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--cream);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
  transform: translateY(-50%);
  animation: fadeIn 0.3s;
}
.tip::after {
  content: "";
  position: absolute;
  right: -8px;
  top: 50%;
  border: 9px solid transparent;
  border-right: 0;
  border-left-color: var(--cream);
  transform: translateY(-50%);
}
.tip b {
  font-size: 17px;
}
.tip p {
  margin: 6px 0 0;
  font-size: 14px;
  font-weight: 700;
  color: #5b4a3a;
  line-height: 1.35;
}
@keyframes fadeIn {
  from {
    opacity: 0;
  }
}

/* ---------- Hướng dẫn ---------- */
.tutorial {
  position: absolute;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: min(780px, 94vw);
  padding: 22px 26px 18px;
  border-radius: 14px;
  background: var(--cream);
  box-shadow:
    0 0 0 2px #e9cf8f,
    0 12px 26px rgba(0, 0, 0, 0.4);
  transform: translateX(-50%);
  animation: fadeIn 0.3s;
}
.tutorial .tag {
  position: absolute;
  left: 50%;
  top: -15px;
  padding: 4px 12px;
  border-radius: 8px;
  background: linear-gradient(#ffc04a, #e98a14);
  color: #fff;
  font: 900 14px var(--font);
  box-shadow: 0 2px 0 #a95d07;
  transform: translateX(-50%);
  white-space: nowrap;
}
.tutorial p {
  margin: 0;
  font: 800 16px var(--font);
  color: #4a3a2a;
  text-align: center;
}
.hand {
  position: absolute;
  z-index: 7;
  font-size: 54px;
  line-height: 1;
  pointer-events: none;
  filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.35));
  animation: tap 0.9s ease-in-out infinite;
}
@keyframes tap {
  50% {
    transform: translate(-6px, -10px) scale(0.92);
  }
}

/* ---------- Nút kem ---------- */
.cream {
  min-height: 46px;
  padding: 0 22px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(#fff8e2, #f8e2a6);
  box-shadow:
    0 3px 0 #c39a5c,
    0 6px 12px rgba(0, 0, 0, 0.2);
  color: #6b5232;
  font: 900 17px var(--font);
  white-space: nowrap;
}
.cream:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #c39a5c;
}
.cream.big {
  min-height: 52px;
  font-size: 19px;
}
.link {
  border: 0;
  background: none;
  color: #fff;
  font: 900 16px var(--font);
}

/* ---------- Hộp thoại ---------- */
.modal {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(20, 12, 6, 0.45);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  animation: fadeIn 0.25s;
}
.modal .panel {
  position: relative;
  display: grid;
  gap: 14px;
  width: min(340px, 100%);
  padding: 26px 30px 18px;
  border-radius: 26px;
  background: #4a93c4;
  box-shadow:
    inset 0 0 0 4px #5aa6d6,
    0 6px 0 #2f6f9c,
    0 20px 40px rgba(0, 0, 0, 0.45);
  text-align: center;
  animation: popIn 0.35s cubic-bezier(0.3, 1.5, 0.5, 1);
}
@keyframes popIn {
  from {
    transform: scale(0.7);
    opacity: 0;
  }
}
#intro .panel {
  padding-top: 112px;
  margin-top: 70px;
}
.modal h2 {
  margin: 0;
  font: 400 34px var(--title);
  color: #fff;
  text-shadow: 0 3px 0 #1f4f75;
}
.badge {
  position: absolute;
  left: 50%;
  top: -64px;
  width: 250px;
  height: 160px;
  display: grid;
  place-items: center;
  align-content: center;
  border-radius: 34px 34px 46px 46px;
  background: linear-gradient(160deg, #6a66f0, #3a2fb2 70%);
  box-shadow:
    inset 0 0 0 5px #ffd25a,
    inset 0 0 0 9px #f39a1e,
    0 8px 0 #2a1f80,
    0 14px 26px rgba(0, 0, 0, 0.4);
  transform: translateX(-50%) perspective(400px) rotateX(8deg);
}
.badge .num {
  margin-top: -56px;
  font: 400 86px/1 var(--title);
  color: #fff;
  -webkit-text-stroke: 7px #10237a;
  paint-order: stroke fill;
}
.badge .word {
  margin-top: -6px;
  font: 400 48px/1 var(--title);
  color: #fff;
  -webkit-text-stroke: 7px #10237a;
  paint-order: stroke fill;
}
.badge .diff {
  position: absolute;
  bottom: -16px;
  padding: 4px 12px;
  border-radius: 10px;
  background: linear-gradient(#ffcf48, #f19016);
  box-shadow: 0 3px 0 #a75807;
  font: 400 19px var(--title);
  color: #fff;
  -webkit-text-stroke: 3px #b4570c;
  paint-order: stroke fill;
}
.badge .diff.easy {
  background: linear-gradient(#8fe36a, #3fae2c);
  box-shadow: 0 3px 0 #23741a;
  -webkit-text-stroke-color: #2b7a1e;
}
.badge .diff.hard {
  background: linear-gradient(#ff7a6b, #d8352a);
  box-shadow: 0 3px 0 #8d1a12;
  -webkit-text-stroke-color: #9a2116;
}
.info {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 16px;
  border-radius: 12px;
  background: #1f6390;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  color: #fff;
}
.info-ico {
  font: 900 28px/1 var(--font);
  color: #5be36b;
}
.info b {
  font-size: 19px;
}
.info p {
  margin: 0;
  font-weight: 800;
  font-size: 15px;
  line-height: 1.35;
}
.fail-ico {
  font-size: 54px;
  line-height: 1;
}
.fail-text {
  margin: 0;
  color: #eaf5ff;
  font-weight: 800;
}

/* ---------- Danh sách màn ---------- */
.map {
  position: absolute;
  inset: 0;
  z-index: 9;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(20, 12, 6, 0.35);
}
.map-panel {
  width: min(640px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 18px 20px 22px;
  border-radius: 24px;
  background: #4a93c4;
  box-shadow:
    inset 0 0 0 4px #5aa6d6,
    0 6px 0 #2f6f9c,
    0 20px 40px rgba(0, 0, 0, 0.45);
}
.map header {
  display: flex;
  align-items: center;
  gap: 12px;
}
.map h1 {
  flex: 1;
  margin: 0;
  text-align: center;
  font: 400 36px var(--title);
  color: #fff;
  -webkit-text-stroke: 5px #10237a;
  paint-order: stroke fill;
}
.map-sub {
  margin: 8px 0 16px;
  text-align: center;
  color: #e6f3ff;
  font-weight: 800;
}
.levels {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 12px;
}
.lv {
  position: relative;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(#fff6dc, #f3d996);
  box-shadow:
    0 4px 0 #b8925a,
    0 8px 14px rgba(0, 0, 0, 0.25);
  color: #6b4a2b;
}
.lv b {
  font: 400 32px/1 var(--title);
}
.lv small {
  font-size: 13px;
  letter-spacing: -1px;
  color: #ffb21e;
  text-shadow: 0 1px 0 #a96b0b;
}
.lv small .off {
  color: #c9b48e;
  text-shadow: none;
}
.lv.locked {
  background: linear-gradient(#9fb5c6, #7f97ab);
  box-shadow: 0 4px 0 #566d80;
  color: #e8eef4;
  cursor: default;
}
.lv.current {
  outline: 4px solid #ffd25a;
  outline-offset: 2px;
}
.lv:active:not(.locked) {
  transform: translateY(3px);
}

@media (max-width: 600px) {
  .hud {
    gap: 6px;
    padding: max(10px, env(safe-area-inset-top)) 10px 0;
  }
  .sq,
  .pill,
  .next-btn {
    height: 40px;
  }
  .sq {
    width: 40px;
  }
  .pill {
    padding: 0 10px;
    font-size: 15px;
  }
  .stars i {
    font-size: 19px;
  }
  .next-btn {
    top: 58px;
    font-size: 15px;
  }
  .booster {
    top: auto;
    bottom: 14px;
    right: 12px;
    width: 62px;
    height: 62px;
    transform: none;
  }
  .booster:active:not(:disabled) {
    transform: translateY(3px);
  }
  .tip {
    top: auto;
    bottom: 22px;
    right: 86px;
    transform: none;
  }
  .tutorial {
    flex-direction: column;
    gap: 10px;
    padding: 20px 16px 14px;
  }
  .tutorial p {
    font-size: 14px;
  }
}
