/* ── SIZE TOKENS ─────────────────────────────────────────────────
   Both grids scale with the viewport so the board never needs an
   inner scrollbar: 93px covers the page, card and board padding plus
   the 7 gaps between cells; 120px does the same for the 3-slot tray.
   The tray row is exactly tall enough for the tallest piece (5 cells),
   so its height never jumps when a new set appears.                  */
:root {
  --bf-cell:   clamp(26px, calc((100vw - 96px)  / 8),  44px);
  --bf-tcell:  clamp(11px, calc((100vw - 120px) / 18), 19px);
  --bf-slot-h: calc(5 * var(--bf-tcell) + 24px);
}

/* ── BOARD ───────────────────────────────────────────────────── */
.bf-scroll {
  overflow-x: auto;
  overflow-y: visible;
  margin: 0 -4px;
  padding: 0 4px 6px;
}

#bfBoard {
  display: grid;
  grid-template-columns: repeat(8, var(--bf-cell));
  gap: 3px;
  background: var(--border-light);
  border: 2px solid var(--btn-border);
  border-radius: 12px;
  padding: 6px;
  width: fit-content;
  margin: 0 auto;
  transition: filter .25s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

/* while a piece is in hand, sliding on the board must not scroll the page */
#bfBoard.bf-armed { touch-action: none; }

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

/* ── CELL ────────────────────────────────────────────────────── */
.bf-cell {
  width: var(--bf-cell);
  height: var(--bf-cell);
  border-radius: 7px;
  background: rgba(100, 120, 160, .07);
  border: 1px solid rgba(100, 120, 160, .16);
  position: relative;
  transition: background .12s, box-shadow .12s;
}

[data-theme="dark"] .bf-cell {
  background: rgba(150, 170, 220, .05);
  border-color: rgba(150, 170, 220, .12);
}

/* ── BLOCK COLOURS ───────────────────────────────────────────── */
.bf-fill[data-col="1"], .bf-cell[data-prev="1"] { --b: #60a5fa; --b2: #2563eb; }
.bf-fill[data-col="2"], .bf-cell[data-prev="2"] { --b: #34d399; --b2: #059669; }
.bf-fill[data-col="3"], .bf-cell[data-prev="3"] { --b: #fbbf24; --b2: #d97706; }
.bf-fill[data-col="4"], .bf-cell[data-prev="4"] { --b: #a78bfa; --b2: #7c3aed; }
.bf-fill[data-col="5"], .bf-cell[data-prev="5"] { --b: #fb7185; --b2: #e11d48; }
.bf-fill[data-col="6"], .bf-cell[data-prev="6"] { --b: #22d3ee; --b2: #0891b2; }
.bf-fill[data-col="7"], .bf-cell[data-prev="7"] { --b: #fb923c; --b2: #ea580c; }
.bf-fill[data-col="8"], .bf-cell[data-prev="8"] { --b: #f472b6; --b2: #db2777; }

/* .bf-cell.bf-fill is needed so a placed block outranks the dark-theme
   empty-cell rule, which is also two classes deep */
.bf-fill,
.bf-cell.bf-fill {
  background: linear-gradient(155deg, var(--b), var(--b2));
  border-color: transparent;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .34),
              inset 0 -2px 0 rgba(0, 0, 0, .18);
}

/* ── PLACEMENT PREVIEW ───────────────────────────────────────── */
/* a ghost must read as "not placed yet" in both themes: translucent fill,
   bright ring */
.bf-cell.bf-prev {
  background: linear-gradient(155deg, var(--b), var(--b2));
  opacity: .62;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .8);
}

.bf-cell.bf-bad {
  background: rgba(208, 48, 48, .3);
  box-shadow: 0 0 0 2px var(--err-color) inset;
}

/* rows and columns the current drop would complete */
.bf-cell.bf-will-clear {
  box-shadow: inset 0 0 0 2px #f59e0b, 0 0 12px rgba(245, 158, 11, .5);
  z-index: 1;
}

/* ── BOARD SHAKE ON AN ILLEGAL DROP ──────────────────────────── */
@keyframes bf-shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-5px); }
  40%      { transform: translateX(5px); }
  60%      { transform: translateX(-3px); }
  80%      { transform: translateX(3px); }
}
#bfBoard.bf-shake { animation: bf-shake .3s ease-in-out; }

/* ── LINE CLEAR FLASH ────────────────────────────────────────── */
@keyframes bf-clear {
  0%   { transform: scale(1);    filter: brightness(1); }
  45%  { transform: scale(1.14); filter: brightness(2.1); }
  100% { transform: scale(.25);  opacity: 0; }
}
.bf-cell.bf-clearing {
  animation: bf-clear .26s ease-in forwards;
  z-index: 2;
}

/* ── HINT PULSE ──────────────────────────────────────────────── */
@keyframes bf-hint-pulse {
  0%, 100% { box-shadow: 0 0 0 3px #f59e0b, 0 0 8px rgba(245, 158, 11, .35); }
  50%      { box-shadow: 0 0 0 3px #f59e0b, 0 0 20px rgba(245, 158, 11, .7); }
}
.bf-cell.bf-hint {
  z-index: 3;
  animation: bf-hint-pulse .6s ease-in-out 3;
}

/* ── PIECE TRAY ──────────────────────────────────────────────── */
#bfTray {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 440px;
  margin: 14px auto 0;
  transition: filter .25s;
  /* a touch starting here is a drag, never a page scroll — without this the
     browser claims the gesture and the piece never leaves the tray */
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

.bf-slot {
  min-height: var(--bf-slot-h);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border: 2px solid var(--btn-border);
  border-radius: 12px;
  background: var(--best-bg);
  cursor: pointer;
  user-select: none;
  transition: border-color .15s, transform .15s, box-shadow .15s, opacity .2s;
}
.bf-slot:hover { border-color: var(--primary); }

.bf-slot.bf-sel {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(42, 111, 189, .25);
  transform: translateY(-3px);
}

.bf-slot.bf-used {
  border-style: dashed;
  background: transparent;
  cursor: default;
}
.bf-slot.bf-used:hover { border-color: var(--btn-border); }

.bf-piece { display: grid; gap: 2px; }

.bf-tc {
  width: var(--bf-tcell);
  height: var(--bf-tcell);
  border-radius: 4px;
}
.bf-tc.bf-fill { border-radius: 4px; }

.bf-tc[data-col="1"] { --b: #60a5fa; --b2: #2563eb; }
.bf-tc[data-col="2"] { --b: #34d399; --b2: #059669; }
.bf-tc[data-col="3"] { --b: #fbbf24; --b2: #d97706; }
.bf-tc[data-col="4"] { --b: #a78bfa; --b2: #7c3aed; }
.bf-tc[data-col="5"] { --b: #fb7185; --b2: #e11d48; }
.bf-tc[data-col="6"] { --b: #22d3ee; --b2: #0891b2; }
.bf-tc[data-col="7"] { --b: #fb923c; --b2: #ea580c; }
.bf-tc[data-col="8"] { --b: #f472b6; --b2: #db2777; }

/* ── PIECE IN HAND ───────────────────────────────────────────────
   A floating copy of the held piece. pointer-events:none is required —
   elementFromPoint has to see the board cell underneath it.          */
.bf-drag {
  position: fixed;
  left: 0;
  top: 0;
  display: none;
  gap: 3px;
  pointer-events: none;
  z-index: 500;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 50, .4));
}
.bf-drag.show { display: grid; }

.bf-dc {
  width: var(--bf-cell);
  height: var(--bf-cell);
  border-radius: 7px;
  transition: transform .12s;
}

/* over an illegal spot the piece shrinks so the red ghost shows through */
.bf-drag.bad .bf-dc {
  transform: scale(.74);
  filter: saturate(.4) brightness(.9);
}

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

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

/* ── HELPER LINE + COMBO TOAST ───────────────────────────────── */
#bfHelp {
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 10px;
}

#comboMsg {
  display: none;
  background: #e0f2fe;
  color: #075985;
  border: 1px solid #7dd3fc;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  margin: 10px auto 0;
  width: fit-content;
  max-width: 100%;
}
#comboMsg.show { display: block; animation: pop .3s cubic-bezier(.34, 1.56, .64, 1); }

[data-theme="dark"] #comboMsg {
  background: #082f49;
  color: #7dd3fc;
  border-color: #075985;
}

/* ── ACTION BUTTONS ──────────────────────────────────────────── */
.bf-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}

/* ── 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; }
}
