/* ── SIZE TOKENS ─────────────────────────────────────────────────
   The board keeps its square shape at any width: the cell size is
   derived from the space available and from how many columns the
   chosen difficulty uses (--tg-n, set on the board by the script). */
#tgBoard {
  --tg-gap:   10px;
  --tg-avail: min(calc(100vw - 80px), 420px);
  --tg-cell:  clamp(38px, calc((var(--tg-avail) - (var(--tg-n) - 1) * var(--tg-gap)) / var(--tg-n)), 110px);

  position: relative;
  width: fit-content;
  margin: 0 auto;
  padding: var(--tg-gap);
  border-radius: 14px;
  background: var(--border-light);
  border: 2px solid var(--btn-border);
  touch-action: none;          /* swipes belong to the game, not the page */
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: filter .25s, background .25s;
}

#tgBoard.blurred { filter: blur(8px); pointer-events: none; }

/* ── EMPTY GRID BEHIND THE TILES ─────────────────────────────── */
.tg-bg {
  display: grid;
  gap: var(--tg-gap);
}

.tg-bg-cell {
  width: var(--tg-cell);
  height: var(--tg-cell);
  border-radius: 8px;
  background: rgba(100, 120, 160, .09);
}

[data-theme="dark"] .tg-bg-cell { background: rgba(150, 170, 220, .06); }

/* ── TILES ───────────────────────────────────────────────────── */
.tg-tiles {
  position: absolute;
  inset: var(--tg-gap);
  pointer-events: none;
}

.tg-tile {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--tg-cell);
  height: var(--tg-cell);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-weight: 800;
  font-size: calc(var(--tg-cell) * .46);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  transition: transform 110ms ease-in-out;
  will-change: transform;
}

.tg-tile.tg-long { font-size: calc(var(--tg-cell) * .3); }

/* ── TILE COLOURS — light ────────────────────────────────────── */
.tg-v2    { background: #eee4da; color: #6a6054; }
.tg-v4    { background: #ece0c8; color: #6a6054; }
.tg-v8    { background: #f2b179; color: #fff; }
.tg-v16   { background: #f59563; color: #fff; }
.tg-v32   { background: #f67c5f; color: #fff; }
.tg-v64   { background: #f65e3b; color: #fff; }
.tg-v128  { background: #edcf72; color: #fff; }
.tg-v256  { background: #edcc61; color: #fff; }
.tg-v512  { background: #edc850; color: #fff; }
.tg-v1024 { background: #edc53f; color: #fff; }
.tg-v2048 { background: #edc22e; color: #fff; box-shadow: 0 0 22px rgba(237, 194, 46, .55); }
.tg-vsuper{ background: #3c3a32; color: #fff; box-shadow: 0 0 22px rgba(60, 58, 50, .5); }

/* ── TILE COLOURS — dark ─────────────────────────────────────── */
[data-theme="dark"] .tg-v2  { background: #27405c; color: #cfe2f5; }
[data-theme="dark"] .tg-v4  { background: #2f5176; color: #e0edfb; }
[data-theme="dark"] .tg-v8  { background: #d98b4a; color: #fff; }
[data-theme="dark"] .tg-v16 { background: #d97339; color: #fff; }
[data-theme="dark"] .tg-v32 { background: #d85c34; color: #fff; }
[data-theme="dark"] .tg-v64 { background: #d1442a; color: #fff; }
[data-theme="dark"] .tg-v128  { background: #cfae4a; color: #fff; }
[data-theme="dark"] .tg-v256  { background: #d0a93c; color: #fff; }
[data-theme="dark"] .tg-v512  { background: #d1a52e; color: #fff; }
[data-theme="dark"] .tg-v1024 { background: #d2a222; color: #fff; }
[data-theme="dark"] .tg-v2048 { background: #d6a111; color: #fff; }
[data-theme="dark"] .tg-vsuper{ background: #101d2e; color: #ffd978; box-shadow: 0 0 22px rgba(255, 217, 120, .35); }

/* ── TILE ANIMATIONS ─────────────────────────────────────────── */
@keyframes tg-appear {
  from { scale: 0; opacity: 0; }
  to   { scale: 1; opacity: 1; }
}
@keyframes tg-pop {
  0%   { scale: 1; }
  55%  { scale: 1.17; }
  100% { scale: 1; }
}

/* scale is animated separately from transform so the slide is untouched */
.tg-tile.tg-new    { animation: tg-appear 140ms ease-out; }
.tg-tile.tg-merged { animation: tg-pop 180ms ease-in-out; }

/* ── SCORE READOUTS ──────────────────────────────────────────── */
.best-info {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.best-info b {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
}

.tg-score {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
  color: var(--muted);
}
.tg-score b {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
}

@keyframes tg-score-pop {
  0%   { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -26px); }
}

.tg-score-pop {
  position: absolute;
  left: 50%;
  top: -4px;
  font-size: 16px;
  font-weight: 800;
  color: #16a34a;
  pointer-events: none;
  animation: tg-score-pop .7s ease-out forwards;
}
[data-theme="dark"] .tg-score-pop { color: #4ade80; }

/* ── HELPER LINE + ACTIONS ───────────────────────────────────── */
#tgHelp {
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 12px;
}

.tg-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.act-btn.tg-btn-off { opacity: .45; cursor: not-allowed; }
.act-btn.tg-btn-off:hover { border-color: var(--btn-border); color: var(--btn-text); background: var(--card-bg); }

/* second button inside the win card */
.keep-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 10px 28px;
  border: 2px solid var(--btn-border);
  border-radius: 30px;
  background: transparent;
  color: var(--btn-text);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: .18s;
}
.keep-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ── HINT AD MODAL ───────────────────────────────────────────── */
#hintModal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(5, 15, 45, .72);
  backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
#hintModal.show { display: flex; }

.hint-card {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 32px 28px;
  text-align: center;
  box-shadow: 0 24px 72px rgba(0, 0, 40, .32);
  animation: pop .38s cubic-bezier(.34, 1.56, .64, 1);
  width: 360px;
  max-width: 90vw;
  position: relative;
}

#hintPhase1, #hintPhase2, #hintPhase3 { display: none; }
#hintPhase1.active, #hintPhase2.active, #hintPhase3.active { display: block; }

.hint-icon  { font-size: 50px; line-height: 1.15; }
.hint-title { font-size: 1.25em; font-weight: 800; color: var(--primary); margin: 10px 0 6px; }
.hint-sub   { font-size: 14px; color: var(--muted); line-height: 1.55; }

.hint-btns { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }

.hint-btn-primary {
  padding: 11px 24px; border: none; border-radius: 26px;
  background: var(--primary); color: white;
  font-size: 14px; font-weight: 700; cursor: pointer; transition: .16s;
}
.hint-btn-primary:hover { background: var(--primary-dk); transform: translateY(-1px); }

.hint-btn-ghost {
  padding: 9px 24px; border: 2px solid var(--btn-border); border-radius: 26px;
  background: transparent; color: var(--btn-text);
  font-size: 14px; font-weight: 600; cursor: pointer; transition: .16s;
}
.hint-btn-ghost:hover { border-color: var(--primary); color: var(--primary); }

#hintPhase2 { position: relative; }
.hint-close-btn {
  position: absolute; top: -8px; right: -8px;
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid var(--btn-border); background: var(--card-bg);
  cursor: pointer; font-size: 13px;
  display: flex; align-items: center; justify-content: center; transition: .14s;
}
.hint-close-btn:hover { border-color: var(--err-color); color: var(--err-color); }

#hintAdSlot { margin: 0 auto; }

.hint-progress-label { font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.hint-progress-wrap  { height: 8px; background: var(--border-light); border-radius: 4px; overflow: hidden; }
.hint-progress-bar   { height: 100%; width: 0%; background: var(--primary); border-radius: 4px; transition: width 1s linear; }

/* ── SIDE PANEL ADS (hidden by default) ─────────────────────── */
.side-panel-ad     { display: none; }
.side-panel-mid-ad { display: none; }
.game-mid-ad       { display: none; margin: 0 auto 14px; }

@media (max-width: 775px) {
  .hdr-nav .ad-leaderboard { display: none; }
  .game-mid-ad { display: flex; }
}
@media (max-width: 1100px) {
  .content-row { grid-template-columns: 1fr; }
}
@media (min-width: 775px) and (max-width: 1100px) {
  .right-sidebar { display: none; }
  .side-panel-ad { display: flex; }
}
@media (max-width: 650px) {
  .side-panel-mid-ad { display: flex; margin: 0 auto; }
}
