/* =========================================================
   2048 — Giao diện (CSS)
   Màu sắc theo SPEC. Bảng co giãn theo bề rộng màn hình.
   ========================================================= */

:root {
  --bg-page: #faf8ef;     /* nền trang */
  --bg-board: #bbada0;    /* nền bảng */
  --cell-empty: #cdc1b4;  /* ô trống */
  --text-dark: #776e65;
  --text-light: #f9f6f2;

  /* Toán vị trí ô (theo % bề rộng bảng):
     có 4 ô + 5 khoảng hở => kích thước ô = (100% - 5*gap) / 4 */
  --gap: 2.5%;
  --tile-size: 21.875%;   /* (100 - 5*2.5) / 4 */
  --step: 24.375%;        /* tile-size + gap (khoảng cách tâm-tới-tâm) */

  --radius: 6px;
  --anim: 120ms;          /* thời lượng hiệu ứng trượt (~0.1s như SPEC) */
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { height: 100%; }
body {
  min-height: 100%;
  background: var(--bg-page);
  color: var(--text-dark);
  font-family: "Clear Sans", "Helvetica Neue", Arial, sans-serif;
  -webkit-user-select: none; user-select: none;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px 0;   /* trên: tránh "tai thỏ" */
}

/* ===== Đầu trang ===== */
.header { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.title { font-size: 48px; font-weight: 800; color: var(--text-dark); letter-spacing: -2px; }
.scores { display: flex; gap: 8px; }
.score-box {
  background: var(--bg-board); color: var(--text-light);
  border-radius: var(--radius); padding: 6px 14px; min-width: 64px; text-align: center;
}
.score-label { font-size: 11px; font-weight: 700; letter-spacing: 1px; color: #eee4da; }
.score-value { font-size: 22px; font-weight: 800; }

.subheader { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 14px 0; }
.intro { font-size: 14px; color: var(--text-dark); }
.btn-new {
  background: #8f7a66; color: #f9f6f2; border: none; border-radius: var(--radius);
  padding: 10px 16px; font-size: 15px; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.btn-new:active { background: #7c6a58; }

/* ===== Bảng chơi ===== */
.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;        /* luôn vuông, tự co giãn theo bề rộng */
  background: var(--bg-board);
  border-radius: 10px;
  touch-action: none;          /* tự xử lý vuốt, không cho trình duyệt cuộn */
}
.grid-bg, .tile-container { position: absolute; inset: 0; }

.cell {
  position: absolute;
  width: var(--tile-size); height: var(--tile-size);
  background: var(--cell-empty);
  border-radius: var(--radius);
}

/* ===== Ô số ===== */
.tile {
  position: absolute;
  width: var(--tile-size); height: var(--tile-size);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: clamp(20px, 8.5vw, 40px);
  background: #eee4da; color: var(--text-dark);
  /* hiệu ứng trượt: chỉ chuyển left/top cho mượt */
  transition: left var(--anim) ease-in-out, top var(--anim) ease-in-out;
}

/* Số càng nhiều chữ thì chữ càng nhỏ (theo SPEC) */
.tile.d3 { font-size: clamp(16px, 6.6vw, 32px); }
.tile.d4 { font-size: clamp(13px, 5.2vw, 26px); }
.tile.d5 { font-size: clamp(10px, 4.2vw, 21px); }

/* Màu nền + chữ theo giá trị (bảng màu trong SPEC) */
.tile.v2    { background:#eee4da; color:#776e65; }
.tile.v4    { background:#ede0c8; color:#776e65; }
.tile.v8    { background:#f2b179; color:#f9f6f2; }
.tile.v16   { background:#f59563; color:#f9f6f2; }
.tile.v32   { background:#f67c5f; color:#f9f6f2; }
.tile.v64   { background:#f65e3b; color:#f9f6f2; }
.tile.v128  { background:#edcf72; color:#f9f6f2; }
.tile.v256  { background:#edcc61; color:#f9f6f2; }
.tile.v512  { background:#edc850; color:#f9f6f2; }
.tile.v1024 { background:#edc53f; color:#f9f6f2; }
.tile.v2048 { background:#edc22e; color:#f9f6f2; }
.tile.vbig  { background:#3c3a32; color:#f9f6f2; }   /* > 2048 */

/* Hiệu ứng ô mới xuất hiện */
.tile.new { animation: pop var(--anim) ease-in-out; }
@keyframes pop { 0% { transform: scale(0); } 100% { transform: scale(1); } }

/* Hiệu ứng khi gộp ô (nảy nhẹ) */
.tile.merged { animation: bump 160ms ease-in-out; z-index: 2; }
@keyframes bump { 0% { transform: scale(1); } 50% { transform: scale(1.18); } 100% { transform: scale(1); } }

/* ===== Popup ===== */
.overlay {
  position: absolute; inset: 0; z-index: 10;
  background: rgba(238, 228, 218, 0.80);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  animation: fade 300ms ease;
}
.overlay[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.overlay-content { text-align: center; padding: 20px; }
.overlay-title { font-size: 40px; font-weight: 800; color: #776e65; margin-bottom: 8px; }
.overlay-msg { font-size: 16px; color: #776e65; margin-bottom: 18px; }
.overlay-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.overlay-buttons button {
  background: #8f7a66; color: #f9f6f2; border: none; border-radius: var(--radius);
  padding: 12px 18px; font-size: 15px; font-weight: 700; cursor: pointer;
}
.overlay-buttons button.secondary { background: #bbada0; }

.hint { text-align: center; font-size: 12px; color: #a89c8f; margin: 16px 0; }

/* ===== Chỗ đặt quảng cáo (rỗng cho tới khi gắn AdSense) ===== */
.ad-zone { max-width: 480px; margin: 8px auto 0; padding: 0 16px; text-align: center; }

/* ===== Nội dung SEO bên dưới game ===== */
.content {
  max-width: 600px;
  margin: 8px auto 0;
  padding: 0 18px;
  line-height: 1.65;
  -webkit-user-select: text; user-select: text;   /* cho phép bôi đen để đọc */
}
.content .lead { font-size: 16px; color: #6f655b; margin-bottom: 4px; }
.content h2 { font-size: 22px; margin: 26px 0 8px; color: #6f655b; }
.content h3 { font-size: 16px; margin: 16px 0 2px; color: #776e65; }
.content p { font-size: 15px; color: #6f655b; margin: 6px 0; }
.content ol, .content ul { padding-left: 22px; margin: 6px 0; }
.content li { font-size: 15px; color: #6f655b; margin: 5px 0; }

/* ===== Chân trang ===== */
.footer {
  max-width: 600px;
  margin: 30px auto;
  padding: 0 18px;
  text-align: center;
  font-size: 13px;
  color: #a89c8f;
  display: flex; gap: 8px; justify-content: center; align-items: center;
}
.footer a { color: #8f7a66; text-decoration: none; }
.footer a:hover { text-decoration: underline; }
