/* "Ghép Cặp Con Số" — chủ đề đồng cỏ ngày nắng, đi theo ảnh nền
   background.jpg (trời xanh, mây trắng, cây xanh, hàng rào gỗ). Không theo
   format thẻ trắng của trang host: thanh trên là thanh rào gỗ, bàn chơi là
   tấm kính trong như bầu trời, mỗi thẻ biểu thức là 1 viên kẹo màu (trời,
   cỏ, nắng, hoa) nổi khối. Bundle chạy độc lập trong iframe nên bảng màu
   khai bằng biến CSS ở đây. */
:root {
  --ink: #23324a;
  --wood: #c98a4b;
  --wood-dark: #8a5526;
  --wood-light: #e3ab6b;
  --paper: #fffdf5;
  --sky: #3fa9f5;
  --sky-dark: #1c78c0;
  --grass: #5cc04a;
  --grass-dark: #348a28;
  --sun: #ffc93c;
  --sun-dark: #d99a00;
  --flower: #ff7aa8;
  --flower-dark: #d64477;
  --error: #e5484d;
  --error-dark: #a8262b;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family:
    'Be Vietnam Pro',
    system-ui,
    -apple-system,
    'Segoe UI',
    sans-serif;
  background: #8fd0ff;
  color: var(--ink);
  overflow: hidden;
}

body {
  /* Ảnh nền đồng cỏ; màu trời ở html là nền dự phòng lúc ảnh chưa tải.
     Canh dưới để giữ hàng rào + bãi cỏ, cắt bớt trời khi khung dẹt. */
  background: url('background.jpg') center bottom / cover no-repeat;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  user-select: none;
}

.icon {
  width: 1em;
  height: 1em;
  flex-shrink: 0;
}

/* ---- Thanh trên: thanh rào gỗ ---- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 14px;
  border: 3px solid var(--wood-dark);
  background:
    repeating-linear-gradient(
      90deg,
      rgba(0, 0, 0, 0) 0 46px,
      rgba(0, 0, 0, 0.07) 46px 48px
    ),
    linear-gradient(180deg, var(--wood-light), var(--wood));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    0 5px 0 var(--wood-dark),
    0 8px 16px rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.stats {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.stat {
  display: flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.12em 0.65em 0.12em 0.2em;
  border-radius: 999px;
  border: 3px solid var(--wood-dark);
  background: var(--paper);
  box-shadow: 0 3px 0 var(--wood-dark);
  font-size: clamp(15px, 3.8vmin, 34px);
  font-weight: 800;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.stat-icon {
  display: grid;
  place-items: center;
  width: 1.5em;
  height: 1.5em;
  border-radius: 50%;
  color: #ffffff;
  font-size: 0.8em;
}

.stat--pairs .stat-icon {
  background: var(--grass);
}

.stat--moves .stat-icon {
  background: var(--sky);
}

.stat--time .stat-icon {
  background: var(--sun-dark);
}

.stat-label {
  font-size: 0.75em;
  font-weight: 700;
  color: var(--wood-dark);
}

/* ---- Bàn chơi ---- */

.board-area {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Tấm kính trong như bầu trời bao quanh bàn — vẽ bằng box-shadow để không
   chiếm layout (layoutBoard() trong game.js đã chừa BOARD_FRAME). */
.board {
  display: grid;
  gap: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.35);
  box-shadow:
    0 0 0 12px rgba(255, 255, 255, 0.35),
    0 0 0 14px rgba(255, 255, 255, 0.75),
    0 14px 30px 14px rgba(20, 70, 120, 0.18);
}

/* Mỗi thẻ là 1 viên kẹo: mặt trắng kem, viền dày + gờ đổ màu theo sắc thái
   (`.hue-0..3` do game.js gán xoay vòng). */
.card {
  --tone: var(--grass);
  --tone-dark: var(--grass-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  border: 4px solid var(--tone);
  background: linear-gradient(180deg, #ffffff, var(--paper));
  color: var(--ink);
  box-shadow:
    inset 0 -5px 0 rgba(0, 0, 0, 0.06),
    0 6px 0 var(--tone-dark);
  /* `--cell-size` (đặt bởi `layoutBoard()` trong game.js) là kích thước ô thật
     đo được — chữ luôn scale đúng theo kích thước ô. */
  font-size: calc(var(--cell-size, 80px) * 0.22);
  font-weight: 900;
  white-space: nowrap;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  padding: 0;
  /* Thẻ bị ghép xong: mờ + thu nhỏ rồi mới ẩn (visibility trễ đúng bằng
     thời gian hiệu ứng) để thấy rõ cặp vừa biến mất. */
  transition:
    transform 0.15s ease,
    background 0.15s ease,
    box-shadow 0.15s ease,
    opacity 0.3s ease,
    visibility 0s linear 0s;
}

.card.hue-0 {
  --tone: var(--grass);
  --tone-dark: var(--grass-dark);
}

.card.hue-1 {
  --tone: var(--sky);
  --tone-dark: var(--sky-dark);
}

.card.hue-2 {
  --tone: var(--sun);
  --tone-dark: var(--sun-dark);
}

.card.hue-3 {
  --tone: var(--flower);
  --tone-dark: var(--flower-dark);
}

.card:hover:not(.removed):not(.selected):not(.wrong) {
  transform: translateY(-4px) rotate(-2deg);
}

.card:active:not(.removed) {
  transform: translateY(4px);
  box-shadow:
    inset 0 -5px 0 rgba(0, 0, 0, 0.06),
    0 2px 0 var(--tone-dark);
}

.card.selected {
  background: linear-gradient(180deg, #fff7d1, #ffe58a);
  border-color: var(--sun-dark);
  transform: translateY(-4px) scale(1.06);
  box-shadow:
    0 0 0 4px #ffffff,
    0 0 18px 6px rgba(255, 201, 60, 0.85),
    0 6px 0 var(--sun-dark);
}

.card.wrong {
  border-color: var(--error);
  background: linear-gradient(180deg, #ffe5e5, #ffc9c9);
  color: var(--error-dark);
  box-shadow: 0 6px 0 var(--error-dark);
  animation: shake 0.3s ease;
}

.card.removed {
  visibility: hidden;
  opacity: 0;
  transform: scale(0.4) rotate(12deg);
  pointer-events: none;
  transition:
    transform 0.3s ease,
    opacity 0.3s ease,
    visibility 0s linear 0.3s;
}

/* ---- Màn kết thúc: tấm biển gỗ ---- */

.game-over {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 70, 120, 0.4);
}

.game-over[hidden] {
  display: none;
}

.game-over-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 24px 36px 26px;
  border-radius: 24px;
  border: 4px solid var(--wood-dark);
  background:
    radial-gradient(circle at 25% 0%, rgba(255, 255, 255, 0.8), transparent 50%),
    linear-gradient(180deg, var(--paper), #f7e6c4);
  box-shadow:
    0 7px 0 var(--wood-dark),
    0 16px 30px rgba(0, 0, 0, 0.3);
  animation: drop-in 0.5s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.game-over-trophy {
  display: grid;
  place-items: center;
  width: 1.6em;
  height: 1.6em;
  border-radius: 50%;
  border: 4px solid var(--sun-dark);
  background: var(--sun);
  color: var(--wood-dark);
  font-size: clamp(40px, 10vmin, 88px);
  animation: sway 1.6s ease-in-out infinite;
}

.game-over p {
  margin: 0;
  font-size: clamp(16px, 3vmin, 26px);
  font-weight: 800;
  text-align: center;
}

.game-over .game-over-title {
  font-size: clamp(22px, 5vmin, 44px);
  font-weight: 900;
  color: var(--grass-dark);
}

.game-over button {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  margin-top: 4px;
  border: 3px solid var(--grass-dark);
  border-radius: 999px;
  padding: 0.45em 1.4em;
  font-family: inherit;
  font-size: clamp(15px, 2.8vmin, 24px);
  font-weight: 800;
  color: #ffffff;
  background: linear-gradient(180deg, #7fd36f, var(--grass));
  box-shadow: 0 4px 0 var(--grass-dark);
  text-shadow: 0 1px 0 var(--grass-dark);
  cursor: pointer;
  transition: transform 0.12s ease;
}

.game-over button:hover {
  transform: translateY(-2px);
}

.game-over button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--grass-dark);
}

/* ---- Hiệu ứng ---- */

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

@keyframes drop-in {
  from {
    transform: translateY(-60px) rotate(-4deg);
    opacity: 0;
  }
  to {
    transform: translateY(0) rotate(0);
    opacity: 1;
  }
}

@keyframes sway {
  0%,
  100% {
    transform: rotate(-6deg);
  }
  50% {
    transform: rotate(6deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before {
    animation: none !important;
    transition: none !important;
  }
}
