/* Block Puzzle — 方块拼图 · static iframe game.
 * Tokens verbatim from ~/workspace/ts-spaces/fang-kuai-pin-tu-you-xi/index.html
 * (original dark + high-saturation art, not Block Blast / Woodoku /
 * Blockudoku colours). No prototype shell here: the game fills its
 * iframe and centres one card (max-width 640px).
 */
:root {
  --card: #1a2231;
  --card-soft: #232e42;
  --board-bg: #10151f;
  --cell-empty: #28303f;
  --ink: #eef3fa;
  --ink-soft: #9fb0c6;
  --ink-dim: #6d7f99;
  --gold: #eaa93c;
  --blue: #3a86ff;
  --teal: #2ec4b6;
  --danger: #ef476f;
  --you-bg: #3a2f14;
  --you-border: #eaa93c;
  --overlay-bg: rgba(13, 18, 28, 0.9);
  --shadow: 0 10px 30px rgba(10, 15, 25, 0.35);
  --c0: #ef476f; --c1: #f4841f; --c2: #ffd23f; --c3: #3fbf72;
  --c4: #2ec4b6; --c5: #3a86ff; --c6: #9b5de5;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: #141a26;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- 游戏根：填满 iframe，卡片居中 ---------- */
.game-root {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.game-card {
  position: relative;
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 14px;
  overflow: hidden;
  width: 100%;
  max-width: 640px;
  container-type: inline-size;
  color: var(--ink);
}
.rank-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ---------- HUD ---------- */
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 10px; }
.scores { display: flex; gap: 8px; }
.pill {
  position: relative; background: var(--card-soft); border-radius: 10px;
  padding: 5px 12px 7px; min-width: 76px; text-align: center;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}
.pill-label { display: block; font-size: 11px; font-weight: 600; letter-spacing: 0.12em; color: var(--ink-soft); line-height: 1.3; }
.pill-num { display: block; font-size: 22px; font-weight: 800; color: #fff; line-height: 1.15; font-variant-numeric: tabular-nums; }
.gain {
  position: absolute; left: 50%; top: 2px; transform: translateX(-50%);
  font-size: 15px; font-weight: 800; color: var(--gold); opacity: 0; pointer-events: none; white-space: nowrap;
}
.gain.show { animation: gainFloat 0.8s ease-out; }
@keyframes gainFloat {
  0% { opacity: 0; transform: translate(-50%, 6px); }
  25% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -16px); }
}
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--card-soft); color: var(--gold);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  padding: 0; flex: none;
}
.icon-btn svg { width: 21px; height: 21px; }
.icon-btn .icon-label { font-size: 9px; color: var(--ink-soft); line-height: 1.1; }
.icon-btn:active { transform: scale(0.95); }

/* ---------- 模式行 ---------- */
.mode-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.segmented {
  display: flex; background: var(--board-bg); border-radius: 999px; padding: 3px; flex: none;
}
.segmented button {
  border: none; background: transparent; color: var(--ink-soft);
  font-size: 13px; font-weight: 700; padding: 7px 14px; border-radius: 999px; min-height: 34px;
}
.segmented button.active { background: var(--blue); color: #fff; }
.mode-info { flex: 1; min-width: 0; font-size: 12px; color: var(--ink-soft); line-height: 1.45; }
.mode-info b { color: var(--gold); font-variant-numeric: tabular-nums; }
.daily-progress { height: 6px; background: var(--board-bg); border-radius: 999px; margin-top: 4px; overflow: hidden; }
.daily-progress i { display: block; height: 100%; background: var(--gold); border-radius: 999px; transition: width 0.3s ease; }
.combo-chip {
  flex: none; font-size: 12px; font-weight: 800; color: #141a26; background: var(--gold);
  border-radius: 999px; padding: 5px 10px; font-variant-numeric: tabular-nums;
}
.combo-chip.off { background: var(--card-soft); color: var(--ink-dim); }

/* ---------- 棋盘 ---------- */
.board-wrap { position: relative; }
.board {
  background: var(--board-bg); border-radius: 14px; padding: 6px;
  display: grid; grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr)); gap: 4px;
  width: 100%; aspect-ratio: 1 / 1; touch-action: none;
  user-select: none; -webkit-user-select: none;
}
.board.shake { animation: boardShake 0.28s ease; }
@keyframes boardShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  60% { transform: translateX(4px); }
}
.cell {
  background: var(--cell-empty); border-radius: 5px; aspect-ratio: 1 / 1;
  min-width: 0; min-height: 0; position: relative;
}
.cell.filled { box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.35), inset 0 -3px 0 rgba(0, 0, 0, 0.25); }
.cell.f0 { background: var(--c0); } .cell.f1 { background: var(--c1); }
.cell.f2 { background: var(--c2); } .cell.f3 { background: var(--c3); }
.cell.f4 { background: var(--c4); } .cell.f5 { background: var(--c5); }
.cell.f6 { background: var(--c6); }
.cell.ghost { box-shadow: inset 0 0 0 2px #ffffff, inset 0 3px 0 rgba(255, 255, 255, 0.35), inset 0 -3px 0 rgba(0, 0, 0, 0.25); filter: brightness(1.25); }
.cell.ghost-clear { box-shadow: inset 0 0 0 2px var(--gold), inset 0 3px 0 rgba(255, 255, 255, 0.35), inset 0 -3px 0 rgba(0, 0, 0, 0.25); animation: clearFlash 0.45s ease infinite alternate; }
.cell.line-hint { box-shadow: inset 0 0 0 2px rgba(234, 169, 60, 0.85); animation: clearFlash 0.45s ease infinite alternate; }
@keyframes clearFlash { from { filter: brightness(1.05); } to { filter: brightness(1.45); } }
.cell.bad { background: #5a2730 !important; box-shadow: inset 0 0 0 2px #ff5c7a; }
.cell.clearing { animation: cellPop 0.24s ease forwards; }
@keyframes cellPop {
  0% { transform: scale(1); }
  45% { transform: scale(1.18); filter: brightness(1.6); }
  100% { transform: scale(0.2); opacity: 0; }
}
.cell.placed { animation: cellLand 0.16s ease; }
@keyframes cellLand { 0% { transform: scale(1.22); } 100% { transform: scale(1); } }
.particle {
  position: absolute; width: 7px; height: 7px; border-radius: 2px;
  pointer-events: none; z-index: 6; animation: particleFly 0.55s ease-out forwards;
}
@keyframes particleFly {
  0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(200deg) scale(0.4); }
}
.big-text {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  pointer-events: none; z-index: 7; opacity: 0;
}
.big-text span {
  font-size: 40px; font-weight: 900; letter-spacing: 0.02em; color: #fff;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35), 0 0 26px rgba(234, 169, 60, 0.65);
  transform: scale(0.6);
}
.big-text.gold span { color: var(--gold); }
.big-text.show { animation: bigPop 1.15s ease forwards; }
.big-text.show span { animation: bigPopSpan 1.15s ease forwards; }
@keyframes bigPop { 0% { opacity: 0; } 15% { opacity: 1; } 75% { opacity: 1; } 100% { opacity: 0; } }
@keyframes bigPopSpan {
  0% { transform: scale(0.5) rotate(-4deg); }
  18% { transform: scale(1.12) rotate(1deg); }
  30% { transform: scale(1); }
  100% { transform: scale(1.04); }
}

/* ---------- 托盘 ---------- */
.tray { display: flex; gap: 8px; margin-top: 12px; }
.tray-slot {
  flex: 1; height: 98px; background: var(--board-bg); border-radius: 14px;
  display: flex; align-items: center; justify-content: center; position: relative;
}
.tray-piece { display: grid; gap: 2px; touch-action: none; cursor: grab; padding: 6px; border-radius: 10px; }
.tray-piece:active { cursor: grabbing; }
.tray-piece.selected { box-shadow: 0 0 0 2px var(--gold); background: rgba(234, 169, 60, 0.12); }
.tray-piece.stuck { opacity: 0.32; filter: grayscale(0.7); }
.tray-piece .pcell { width: 15px; height: 15px; border-radius: 3px; }
.tray-piece .pcell.on { box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.35), inset 0 -2px 0 rgba(0, 0, 0, 0.25); }
.pcell.f0 { background: var(--c0); } .pcell.f1 { background: var(--c1); }
.pcell.f2 { background: var(--c2); } .pcell.f3 { background: var(--c3); }
.pcell.f4 { background: var(--c4); } .pcell.f5 { background: var(--c5); }
.pcell.f6 { background: var(--c6); }
.drag-float {
  position: fixed; z-index: 200; pointer-events: none; display: grid; gap: 3px;
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.45));
}
.drag-float .pcell { border-radius: 5px; box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.35), inset 0 -3px 0 rgba(0, 0, 0, 0.25); }

/* ---------- 游玩页底部行 ---------- */
.play-foot { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.toggle-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.14); background: var(--card-soft); color: var(--ink-soft);
  border-radius: 999px; padding: 7px 13px; font-size: 13px; font-weight: 700;
}
.toggle-btn svg { width: 17px; height: 17px; }
.toggle-btn.on { color: var(--gold); border-color: rgba(234, 169, 60, 0.55); }
.toggle-btn:active { transform: scale(0.97); }
.restart-btn {
  margin-left: auto; min-height: 44px; border: none; border-radius: 999px;
  background: var(--card-soft); color: var(--ink); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
  padding: 8px 18px; font-size: 13px; font-weight: 700;
}
.restart-btn:active { transform: scale(0.97); }
.drag-tip { margin: 10px 2px 0; font-size: 12px; color: var(--ink-dim); line-height: 1.5; }

/* ---------- 按钮（遮罩内） ---------- */
.btn {
  appearance: none; border: none; cursor: pointer; font-size: 15px; font-weight: 700;
  border-radius: 999px; padding: 11px 22px; min-height: 46px; line-height: 1.2;
  transition: transform 0.05s ease; white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-main { background: var(--blue); color: #fff; }
.btn-gold { background: var(--gold); color: #23180a; }
.btn-light { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.3); }

/* ---------- 遮罩（失败 / 广告占位） ---------- */
.overlay {
  position: absolute; inset: 0; background: var(--overlay-bg);
  display: flex; align-items: center; justify-content: center;
  padding: 22px; z-index: 8;
}
.overlay-box { text-align: center; max-width: 420px; width: 100%; position: relative; z-index: 2; }
.overlay-title { margin: 0 0 6px; font-size: 34px; font-weight: 900; color: #fff; letter-spacing: 0.02em; }
.overlay-sub { margin: 0 0 20px; font-size: 14px; color: var(--ink-soft); line-height: 1.65; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 22px; }
.stat { background: var(--card-soft); border-radius: 12px; padding: 10px 4px 8px; }
.stat-label { display: block; font-size: 11px; color: var(--ink-dim); letter-spacing: 0.08em; margin-bottom: 2px; }
.stat-num { display: block; font-size: 20px; font-weight: 800; color: #fff; font-variant-numeric: tabular-nums; }
.overlay-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.ad-note {
  margin: 16px auto 0; max-width: 300px; font-size: 12px; color: var(--ink-dim); line-height: 1.6;
  border: 1px dashed rgba(255, 255, 255, 0.22); border-radius: 10px; padding: 8px 10px;
}
.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 1; }
.confetti i {
  position: absolute; top: -14px; width: 9px; height: 14px; border-radius: 2px;
  opacity: 0; animation: fall linear forwards;
}
@keyframes fall {
  0% { opacity: 1; transform: translateY(0) rotate(0deg); }
  90% { opacity: 1; }
  100% { opacity: 0; transform: translateY(560px) rotate(560deg); }
}
.ad-progress { height: 8px; background: var(--board-bg); border-radius: 999px; overflow: hidden; margin: 18px 0 8px; }
.ad-progress i { display: block; height: 100%; width: 0; background: var(--gold); border-radius: 999px; }

/* ---------- 排行榜 ---------- */
.rank-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.back-btn {
  appearance: none; background: var(--card-soft); border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--ink); font-size: 14px; font-weight: 700; border-radius: 999px;
  padding: 8px 18px; min-height: 44px; cursor: pointer;
}
.rank-title { margin: 0; font-size: 24px; font-weight: 800; color: #fff; }
.demo-tag {
  margin-left: auto; font-size: 12px; font-weight: 700; color: #23180a;
  background: var(--gold); border-radius: 999px; padding: 4px 12px; white-space: nowrap;
}
.rank-footer {
  flex: none; display: flex; align-items: center; gap: 12px;
  background: var(--you-bg); border: 1.5px solid var(--you-border);
  border-radius: 16px; padding: 12px 18px; margin-top: 12px; color: var(--ink);
}
.rank-list {
  flex: 1;
  /* Floor for the empty board: with no rows the list is only the
     "nobody yet" message, so without this the card collapses to a
     short strip. The JS height pin (play-card height) normally
     stretches it further; this is the minimum when the pin cannot
     apply. */
  min-height: 300px;
  overflow-y: auto; border-radius: 16px;
  background: var(--board-bg); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}
.rank-colhead, .rank-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  font-size: 15px; color: var(--ink);
}
.rank-colhead {
  font-size: 12px; color: var(--ink-soft); letter-spacing: 0.06em;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  position: sticky; top: 0; z-index: 1; background: var(--board-bg);
}
.rank-colhead .rank-no { background: transparent; height: auto; }
.rank-row { border-bottom: 1px solid rgba(255, 255, 255, 0.05); }
.rank-row:last-child { border-bottom: none; }
.rank-no {
  width: 30px; height: 30px; border-radius: 50%; background: var(--card-soft); color: var(--ink-soft);
  font-size: 13px; font-weight: 700; display: flex; align-items: center; justify-content: center;
  flex: none; font-variant-numeric: tabular-nums;
}
.rank-row.top .rank-no { color: #14181f; }
.rank-row.top .rank-name, .rank-row.top .rank-score { font-weight: 800; }
.rank-row.r1 .rank-no { background: #ffd23f; }
.rank-row.r2 .rank-no { background: #cfd8e3; }
.rank-row.r3 .rank-no { background: #e59a5f; }
.rank-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-score { font-weight: 700; font-variant-numeric: tabular-nums; }
.rank-row.you { background: var(--you-bg); box-shadow: inset 0 0 0 1.5px var(--you-border); }
.rank-row.you .rank-no { background: var(--gold); color: #23180a; }
.rank-row.you .rank-name, .rank-row.you .rank-score { font-weight: 800; }
.rank-empty {
  padding: 28px 16px; text-align: center; font-size: 14px; color: var(--ink-soft);
}
.banner-slot {
  flex: none; margin-top: 12px; border: 1px dashed rgba(255, 255, 255, 0.22); border-radius: 12px;
  padding: 9px 12px; font-size: 12px; color: var(--ink-dim); text-align: center; line-height: 1.5;
}

@media (max-width: 460px) {
  .game-card { padding: 12px; }
  .pill { min-width: 64px; padding: 5px 8px 7px; }
  .pill-num { font-size: 19px; }
  .btn { padding: 10px 18px; font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .gain.show, .big-text.show, .big-text.show span, .cell.clearing, .cell.placed,
  .cell.ghost-clear, .cell.line-hint, .board.shake { animation: none; }
  .confetti, .particle { display: none; }
}
