/* Cùng bảng màu/khuôn với public/games/ghep-cap-so/style.css và
   public/games/luyen-tu-vung-anh/style.css (theme trang host khai lại bằng
   hex — bundle chạy độc lập trong iframe, không có Tailwind/CSS variables
   của trang host). */
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family:
    'Be Vietnam Pro',
    system-ui,
    -apple-system,
    'Segoe UI',
    sans-serif;
  background: #fff8ed;
  color: #4a3b5c;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  /* Vuốt nối các ô chữ cái là thao tác chính — tắt bôi đen văn bản/con trỏ hệ
     thống khi rê chuột/ngón tay (cùng lý do với luyen-tu-vung-anh/style.css). */
  user-select: none;
  touch-action: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  border-radius: 16px;
  border: 2px solid #ffe1c2;
  background: #ffffff;
  box-shadow: 0 4px 0 #e7dcc7;
  flex-shrink: 0;
}

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

.stat {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.play-area {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

/* Bảng gỗ (asset người dùng cung cấp, cắt từ bộ GUI .eps) làm nền cho khu vực
   sơ đồ ô chữ — kéo giãn khít nguyên khung `.grid-area` (không theo tỉ lệ ô
   chữ, vốn đổi theo từng cấp độ) nên hình luôn giữ đúng dáng bảng gỗ, không
   méo theo số hàng/cột. `layoutGrid()` (game.js) chừa lề `GRID_INSET` quanh
   lưới chữ để không đè lên viền vân gỗ trang trí của tấm bảng. */
.grid-area {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background-image: url('wood-board.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
}

/* Kích thước/số cột-hàng thật đặt bởi `layoutGrid()` trong game.js (mỗi cấp
   độ 1 lưới khác nhau, xem `buildCrossword()`) — CSS chỉ định khoảng cách ô
   và bo góc. */
.xgrid {
  display: grid;
  gap: 3px;
}

.xcell {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: #ffffff;
  border: 2px solid #ffe1c2;
  color: #4a3b5c;
  font-size: calc(var(--cell-size, 32px) * 0.5);
  font-weight: 800;
  line-height: 1;
  /* Đổ bóng nhẹ — ô chữ trông như miếng giấy/gỗ nổi trên nền bảng gỗ
     `.grid-area`, thay vì dán phẳng. */
  box-shadow: 0 2px 0 rgba(74, 33, 15, 0.25);
}

/* Ô không thuộc từ nào (khoảng đệm giữ đúng hình chữ nhật của lưới, giống ô
   đen trên 1 tờ ô chữ thật) — vô hình nhưng vẫn chiếm chỗ trong CSS Grid. */
.xcell.xcell-empty {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

.xcell.filled {
  animation: pop-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  border-color: #7bd8b0;
  background: #eafff5;
}

@keyframes pop-in {
  0% {
    transform: scale(0.55);
    opacity: 0;
  }
  70% {
    transform: scale(1.12);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Nút gợi ý CHỈ có icon (không chữ) trong topbar — bấm mới mở dialog
   (`.dialog#hint-dialog`) lộ nghĩa của 1 từ CHƯA tìm ra (xoay vòng qua các từ
   còn thiếu mỗi lần bấm, xem `onHintClick()` trong game.js), giữ độ khó của
   trò "đoán từ" thay vì hiện hết ngay từ đầu. */
.hint-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 2px solid #ffc93c;
  border-radius: 50%;
  color: #4a3b5c;
  background: #fff3c4;
  cursor: pointer;
  transition:
    transform 0.12s ease,
    opacity 0.12s ease;
}

.hint-btn:hover {
  transform: translateY(-1px);
  opacity: 0.92;
}

.hint-btn:active {
  transform: translateY(0);
}

.wheel-area {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 4px 0 2px;
}

.current-word {
  min-height: 20px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 4px;
  color: #4a3b5c;
}

.wheel {
  position: relative;
  width: min(32vh, 190px);
  height: min(32vh, 190px);
  flex-shrink: 0;
}

.wheel-line {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Miếng gỗ tròn (cùng asset .eps với `.grid-area`) thay cho hình tròn CSS
   thuần trước đây — 2 file ảnh ứng với 2 trạng thái: `wood-circle.png` (mặt
   thường) và `wood-circle-active.png` (mặt có vòng khắc, dùng khi đang được
   kéo vào đường ghép chữ). Vì hình dáng viền/vân gỗ đã có sẵn trong ảnh, bỏ
   hẳn `border`/`background` màu CSS — chỉ còn kích thước + vị trí (đặt bởi
   `layoutWheel()` trong game.js) và màu chữ. */
.letter-tile {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  background-image: url('wood-circle.png');
  background-size: contain;
  background-repeat: no-repeat;
  color: #fff8ed;
  text-shadow: 0 1px 2px rgba(59, 26, 10, 0.6);
  font-size: 19px;
  font-weight: 800;
  cursor: pointer;
  touch-action: none;
  transition: transform 0.1s ease;
}

.letter-tile.active {
  transform: scale(1.14);
  background-image: url('wood-circle-active.png');
}

/* `drop-shadow` (không phải `box-shadow`) — bám theo đúng biên dạng trong
   suốt của ảnh tròn (hình vuông của box thật ra có góc trong suốt), tạo hào
   quang tròn quanh miếng gỗ thay vì 1 khối vuông màu sau lưng nó. */
.letter-tile.correct {
  filter: drop-shadow(0 0 8px #7bd8b0) drop-shadow(0 0 3px #7bd8b0);
}

.letter-tile.wrong {
  filter: drop-shadow(0 0 8px #e0554a) drop-shadow(0 0 3px #e0554a);
  animation: shake 0.3s ease;
}

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

/* `.dialog` dùng chung cho cả 2 hộp thoại (kết quả cấp/game và gợi ý) — cùng
   1 kiểu overlay + thẻ trắng bo tròn, tránh lặp CSS. */
.dialog {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(74, 59, 92, 0.45);
}

.dialog[hidden] {
  display: none;
}

.dialog-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 22px 30px;
  max-width: 80%;
  border-radius: 26px;
  border: 2px solid #ffe1c2;
  background: #ffffff;
  box-shadow: 0 6px 0 #e7dcc7;
}

.dialog-card p {
  margin: 0;
  text-align: center;
}

#game-over-text {
  font-size: 18px;
  font-weight: 800;
}

#game-over-detail {
  font-size: 13px;
  font-weight: 600;
  color: #7a6a8c;
}

#hint-dialog-text {
  font-size: 16px;
  font-weight: 800;
}

.dialog-card button {
  border: none;
  border-radius: 999px;
  padding: 9px 22px;
  font-size: 14px;
  font-weight: 700;
  color: #4a3b5c;
  background: #ff8e6c;
  cursor: pointer;
  transition:
    transform 0.12s ease,
    opacity 0.12s ease;
}

.dialog-card button:hover {
  transform: translateY(-1px);
  opacity: 0.92;
}
