/* Fifteen Puzzle — 十五拼图 · static iframe game.
 * Tokens verbatim from ~/workspace/ts-spaces/shi-wu-pin-tu-you-xi/index.html (v3).
 * No prototype shell here: the game fills its iframe and centres one
 * card (max-width 640px). Board frame max-width 330px, centred.
 */
:root {
  --ink: #3d3663;
  --ink-soft: #7a74a3;
  --blank: #d9d2f2;
  --blank-line: #c3b8ec;
  --you-bg: #f3edff;
  --you-border: #b7a6f2;
  --pill-border: #e6e1f5;
  --shadow: 0 10px 30px rgba(80, 60, 140, 0.18);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  /* Transparent (v2.0.1): the portal page shows through the iframe;
   * only the white game card itself carries a background. The blue-
   * purple page wash is removed (same precedent as minesweeper
   * v1.0.2). */
  background: transparent;
  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;
  /* v2.0.1: card flush to the iframe's top/left/right edges — no
   * top/left/right padding (bottom 12px kept), flex-start so the
   * card sits at the top even if the frame is taller than the card. */
  justify-content: flex-start;
  padding: 0 0 12px;
}
.game-card {
  position: relative;
  background: #fff;
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 16px;
  overflow: hidden;
  width: 100%;
  max-width: 640px;
  color: var(--ink);
}
.rank-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ---------- 游玩页头 ---------- */
.play-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.play-title { font-size: 18px; font-weight: 800; margin: 0; flex: none; }
.level-name { font-size: 13px; font-weight: 700; color: var(--ink-soft); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  flex: none; width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid #f0d48a; background: #fff7dd;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.icon-btn:active { background: #ffedb8; }

/* ---------- HUD ---------- */
.hud { display: flex; gap: 6px; margin-bottom: 12px; }
.hud-pill {
  flex: 1; background: #f6f3ff; border: 1px solid var(--pill-border);
  border-radius: 12px; padding: 6px 4px 7px; text-align: center; min-width: 0;
}
.hud-label { display: block; font-size: 11px; font-weight: 600; letter-spacing: 0.1em; color: var(--ink-soft); line-height: 1.3; }
.hud-num { display: block; font-size: 19px; font-weight: 800; line-height: 1.2; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- 棋盘 ---------- */
.board-frame {
  background: #fff; border: 1px solid var(--pill-border); border-radius: 16px;
  padding: 6px; box-shadow: 0 4px 14px rgba(80, 60, 140, 0.10);
  width: 100%; max-width: 330px; margin: 0 auto;
}
.board {
  display: grid; gap: 1.5px; width: 100%; aspect-ratio: 16 / 9;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.tile {
  position: relative; overflow: hidden; border-radius: 7px;
  min-width: 0; min-height: 0; border: none; padding: 0; background: #eee;
}
button.tile { cursor: pointer; }
button.tile:active { filter: brightness(0.94); }
.tile .scene { position: absolute; pointer-events: none; }
.tile .scene svg { display: block; width: 100%; height: 100%; }
.tile.blank {
  background:
    radial-gradient(circle at 50% 50%, #e6defa 0 26%, transparent 27%),
    var(--blank);
  box-shadow: inset 0 0 0 1.5px var(--blank-line);
  cursor: default;
}
.tile.moved { animation: tileIn 0.14s ease-out; }
@keyframes tileIn { 0% { transform: scale(0.96); } 100% { transform: scale(1); } }

/* ---------- 参考图 ---------- */
.ref-row {
  display: flex; align-items: center; gap: 12px;
  max-width: 330px; margin: 12px auto 0;
  background: #f6f3ff; border: 1px solid var(--pill-border); border-radius: 14px; padding: 8px 12px 8px 8px;
}
.ref-thumb { position: relative; width: 96px; height: 54px; border-radius: 10px; overflow: hidden; flex: none; box-shadow: inset 0 0 0 1px rgba(61,54,99,0.12); background-color: #eee; }
.ref-blank { position: absolute; background: #eee; border-radius: 2px; pointer-events: none; }
.ref-thumb svg { display: block; width: 100%; height: 100%; }
.ref-label { font-size: 13px; font-weight: 700; color: var(--ink); }
.ref-sub { font-size: 12px; color: var(--ink-soft); line-height: 1.5; margin-top: 2px; }

/* ---------- 按钮 ---------- */
.play-actions { display: flex; gap: 10px; max-width: 330px; margin: 14px auto 2px; }
.btn {
  appearance: none; border: none; cursor: pointer; font-size: 15px; font-weight: 700;
  border-radius: 999px; padding: 10px 18px; min-height: 44px; line-height: 1.2;
  transition: filter 0.15s ease, transform 0.05s ease; white-space: nowrap; color: #fff; flex: 1;
}
.btn:active { transform: scale(0.97); }
.btn-pink { background: linear-gradient(90deg, #ffa5ae, #fec6e1); color: #7c2d4e; }
.btn-cyan { background: linear-gradient(90deg, #3fb9fe, #0ee5fe); color: #075985; }
.btn-green { background: linear-gradient(90deg, #34d399, #2dd4bf); color: #064e3b; }
.btn-light { background: #fff; color: var(--ink); border: 1px solid var(--pill-border); }
.btn-levels {
  flex: none; font-size: 14px; padding: 8px 16px; min-height: 44px;
  background: #f6f3ff; color: var(--ink); border: 1px solid var(--pill-border);
}

/* ---------- 弹框（过关 / 重新开始确认 / 选关） ---------- */
.overlay {
  position: absolute; inset: 0; background: rgba(250, 248, 255, 0.92);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 5;
  overflow-y: auto;
}
.overlay-box { text-align: center; max-width: 300px; width: 100%; position: relative; z-index: 2; margin: auto; }
.overlay-title { margin: 0 0 6px; font-size: 30px; font-weight: 800; color: var(--ink); }
.overlay-sub { margin: 0 0 18px; font-size: 14px; color: var(--ink-soft); line-height: 1.6; }
.record-badge {
  display: inline-block; background: #fff3c4; border: 1.5px solid #edcf72; color: #8a6d1a;
  font-size: 13px; font-weight: 800; border-radius: 999px; padding: 4px 14px; margin-bottom: 14px;
}
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 20px; }
.stat { background: #fff; border: 1px solid var(--pill-border); border-radius: 12px; padding: 9px 2px 7px; }
.stat-label { display: block; font-size: 11px; color: var(--ink-soft); letter-spacing: 0.06em; margin-bottom: 2px; }
.stat-num { display: block; font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.overlay-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.overlay-btns .btn { flex: none; padding: 11px 24px; }
.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); }
}

/* ---------- 选关弹框（11 关，两列排布，超高可滚） ---------- */
.level-modal-box { max-width: 340px; max-height: 100%; overflow-y: auto; }
.level-modal-title { margin: 0 0 6px; font-size: 22px; font-weight: 800; color: var(--ink); }
.level-modal-sub { margin: 0 0 14px; font-size: 13px; color: var(--ink-soft); line-height: 1.6; }
.max-level { font-weight: 800; color: var(--ink); }
.level-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.level-item {
  width: 100%; text-align: center; padding: 12px 4px; min-height: 44px;
  border: 1.5px solid var(--pill-border); border-radius: 12px;
  background: #fff; color: var(--ink); font-size: 14px; font-weight: 700; white-space: nowrap;
}
.level-item.current { border-color: #715bb8; background: #f6f3ff; }
.level-item.done { border-color: #34d399; }
.level-item.locked { background: #f4f1fa; color: #a49cb8; cursor: not-allowed; }
.level-tip { font-size: 13px; color: #b45309; margin: 0 0 12px; }

/* ---------- 排行榜 ---------- */
.rank-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.back-btn {
  appearance: none; background: #fff; border: 1px solid var(--pill-border); color: var(--ink);
  font: inherit; font-size: 14px; font-weight: 700; border-radius: 999px;
  min-width: 44px; height: 44px; padding: 0 14px; cursor: pointer; flex: none;
  display: flex; align-items: center; justify-content: center;
}
.rank-title { margin: 0; font-size: 22px; font-weight: 800; }
.demo-tag {
  margin-left: auto; flex: none; background: #fff3c4; border: 1px solid #edcf72; color: #8a6d1a;
  font-size: 12px; font-weight: 700; border-radius: 999px; padding: 4px 10px; white-space: nowrap;
}
.rank-note { font-size: 12px; color: var(--ink-soft); margin: 0 0 12px; line-height: 1.5; }
.rank-list {
  flex: 1;
  min-height: 300px;
  overflow-y: auto; border: 1px solid #eee9fa; border-radius: 16px; background: #fff;
}
.rank-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 14px;
  border-bottom: 1px solid #f4f1fc; font-size: 14px; color: var(--ink);
}
.rank-row:last-child { border-bottom: none; }
.rank-head-row { background: #f6f3ff; font-size: 11px; font-weight: 700; letter-spacing: 0.08em; color: var(--ink-soft); padding: 8px 14px; }
.rank-head-row .rank-no { background: transparent; width: 28px; }
.rank-no {
  width: 28px; height: 28px; border-radius: 50%; background: #f1edfb; color: var(--ink-soft);
  font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center;
  flex: none; font-variant-numeric: tabular-nums;
}
.rank-row.top .rank-no { color: #fff; }
.rank-row.top .rank-name { font-weight: 800; }
.rank-row.r1 .rank-no { background: #edc22e; }
.rank-row.r2 .rank-no { background: #b9b3a8; }
.rank-row.r3 .rank-no { background: #d99a5b; }
.rank-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-moves { width: 64px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; flex: none; }
.rank-time { width: 56px; text-align: right; color: var(--ink-soft); font-variant-numeric: tabular-nums; flex: none; }
.rank-note-row { justify-content: center; color: var(--ink-soft); font-size: 13px; padding: 18px 14px; }
.rank-note-row .rank-name { text-align: center; }
.rank-row.you { background: var(--you-bg); box-shadow: inset 0 0 0 1.5px var(--you-border); }
.rank-row.you .rank-no { background: #715bb8; color: #fff; }
.rank-row.you .rank-name { font-weight: 800; }
.rank-footer {
  flex: none; display: flex; align-items: center; gap: 10px;
  background: var(--you-bg); border: 1.5px solid var(--you-border);
  border-radius: 16px; padding: 10px 14px; margin-top: 10px; font-size: 14px; color: var(--ink);
}

@media (prefers-reduced-motion: reduce) {
  .tile.moved, .confetti i { animation: none; }
  .confetti { display: none; }
}
