/* Huarong Dao — 华容道 · static iframe game.
 * Tokens from ~/workspace/prototypes/huarongdao-prototype.html
 * (warm wood board + vermilion Cao Cao, cream paper card).
 * No prototype shell here: the game fills its iframe and centres one
 * card (max-width 640px).
 */
:root {
  --card: #fdf6e9;
  --board: #8a5a2b;
  --board-frame: #6b4423;
  --ink: #4a3220;
  --ink-soft: #8a6d4b;
  --btn-main: #a8322a;
  --btn-main-hover: #8c2a23;
  --pill-border: #e3d5b8;
  --you-bg: #fff3cf;
  --you-border: #f2d06b;
  --overlay-bg: rgba(253, 246, 233, 0.92);
  --shadow: 0 12px 32px rgba(74, 50, 32, 0.18);
  --cao: #b03a2e;
  --cao-ink: #fff6ec;
  --guanyu: #2e6e46;
  --gen1: #2f5f8f;
  --gen2: #7a4f86;
  --gen3: #8a5a2b;
  --gen4: #3f7f7f;
  --dajiang: #4d7a3a;
  --pianjiang: #6b6b3f;
  --soldier: #e8d5a8;
  --soldier-ink: #5d4a26;
  --gold: #f2d06b;
  --win: #7fb069;
  --win-ink: #3d8a4a;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: #efe9dc;
  color: #33302a;
  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: 28px;
  box-shadow: var(--shadow);
  padding: 16px;
  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（4 个 pill + 右侧奖杯图标） ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  margin-bottom: 12px;
}
.scores { display: flex; gap: 5px; flex-wrap: nowrap; flex: 1; min-width: 0; }
.pill {
  background: var(--board);
  border-radius: 14px;
  padding: 5px 4px 6px;
  flex: 1;
  min-width: 0;
  text-align: center;
}
.pill-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #f3e2c2;
  line-height: 1.3;
  white-space: nowrap;
}
.pill-num {
  display: block;
  font-size: 19px;
  font-weight: 800;
  color: #fff;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.trophy-btn {
  appearance: none;
  flex: none;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1.5px solid var(--gold);
  background: #fff8dc;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  box-shadow: 0 3px 10px rgba(180, 150, 40, 0.18);
  transition: transform 0.08s ease, background 0.15s ease;
}
.trophy-btn:hover { background: #fff3bd; }
.trophy-btn:active { transform: scale(0.94); }
.trophy-btn svg { width: 22px; height: 22px; display: block; }
.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
  border-radius: 999px;
  padding: 9px 22px;
  min-height: 44px;
  line-height: 1.2;
  transition: background 0.15s ease, transform 0.05s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-light {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--pill-border);
}
.btn-light:hover { background: #f6f1e7; }
.btn-main {
  background: var(--btn-main);
  color: #fff;
}
.btn-main:hover { background: var(--btn-main-hover); }

/* ---------- 关卡行 ---------- */
.level-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.level-name { font-size: 17px; font-weight: 800; color: var(--ink); }
.level-opt { font-size: 13px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

/* ---------- 棋盘：4 列 × 5 行，木质 ---------- */
.board-wrap { position: relative; width: 100%; max-width: 340px; margin: 0 auto; }
.board {
  position: relative;
  background: var(--board);
  border: 6px solid var(--board-frame);
  border-radius: 14px;
  width: 100%;
  aspect-ratio: 4 / 5;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
.board-grid {
  position: absolute; inset: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(5, 1fr);
}
.board-grid i {
  border: 1px solid rgba(255, 235, 200, 0.16);
  display: block;
}
.exit-mark {
  position: absolute;
  left: 25%; width: 50%;
  bottom: 0; height: 8px;
  background: #f6e3b8;
  border-radius: 4px 4px 0 0;
  z-index: 2;
  pointer-events: none;
}
.exit-mark::after {
  content: "出 口 ↓";
  position: absolute;
  left: 50%; bottom: 12px;
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 800;
  color: #f6e3b8;
  letter-spacing: 0.2em;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}
.piece {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 800;
  color: #fff;
  border-radius: 8px;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.35), inset 0 -3px 0 rgba(0, 0, 0, 0.22), 0 2px 5px rgba(0, 0, 0, 0.25);
  cursor: grab;
  z-index: 3;
  line-height: 1.15;
  transition: left 0.12s ease, top 0.12s ease;
  padding: 2px;
}
.piece:active { cursor: grabbing; }
.piece.selected { outline: 3px solid #ffd54a; outline-offset: 1px; z-index: 4; }
.piece.cao { background: linear-gradient(180deg, #c04538, var(--cao)); color: var(--cao-ink); font-size: 22px; letter-spacing: 0.06em; }
.piece.guanyu { background: linear-gradient(180deg, #3a7d55, var(--guanyu)); font-size: 17px; }
.piece.gen1 { background: linear-gradient(180deg, #3a6d9e, var(--gen1)); font-size: 15px; }
.piece.gen2 { background: linear-gradient(180deg, #8a5c94, var(--gen2)); font-size: 15px; }
.piece.gen3 { background: linear-gradient(180deg, #9a6834, var(--gen3)); font-size: 15px; }
.piece.gen4 { background: linear-gradient(180deg, #4a8d8d, var(--gen4)); font-size: 15px; }
.piece.dajiang { background: linear-gradient(180deg, #5a8a44, var(--dajiang)); font-size: 15px; }
.piece.pianjiang { background: linear-gradient(180deg, #7a7a48, var(--pianjiang)); font-size: 15px; }
.piece.soldier { background: linear-gradient(180deg, #f0e0b4, var(--soldier)); color: var(--soldier-ink); font-size: 16px; }
.piece.dragging { transition: none; z-index: 5; box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35), inset 0 2px 0 rgba(255, 255, 255, 0.35); }

/* ---------- 棋盘下方操作行 ---------- */
.controls-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.controls-row .btn { padding: 8px 18px; font-size: 14px; min-height: 44px; }
.play-hint { font-size: 13px; color: var(--ink-soft); line-height: 1.5; flex: 1; min-width: 120px; }
.toast {
  margin-top: 10px;
  background: #fff8dc;
  border: 1px solid var(--gold);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  color: #7a5b12;
  line-height: 1.5;
}

/* ---------- 选关弹框（v1.0.4：关卡不再常驻显示） ---------- */
.level-modal-box { max-width: 560px; text-align: center; }
.level-modal-title { margin: 0 0 6px; font-size: 24px; font-weight: 800; color: var(--ink); }
.level-modal-sub { margin: 0 0 14px; font-size: 13px; color: var(--ink-soft); line-height: 1.6; }
.level-modal-sub .max-level { vertical-align: 1px; }
.level-modal-box .overlay-btns { margin-top: 16px; }
.level-tip { margin: 12px 0 0; font-size: 13px; font-weight: 700; color: #7a5b12; line-height: 1.5; }
.max-level {
  flex: none;
  font-size: 12px;
  font-weight: 800;
  color: var(--win-ink);
  background: #eef6e9;
  border: 1px solid #cfe3c2;
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
}
.level-row {
  /* Two rows, no horizontal scroll: 17 buttons at 44px cannot fit one
     row (11 fit the 560px modal box), and a horizontal scrollbar
     inside the game area hides levels 14-17. */
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.level-btn {
  appearance: none;
  position: relative;
  flex: none;
  min-width: 44px; height: 44px;
  border-radius: 12px;
  border: 1.5px solid var(--pill-border);
  background: #fff;
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.level-btn.active { background: var(--btn-main); border-color: var(--btn-main); color: #fff; }
.level-btn.done { border-color: var(--win); color: var(--win-ink); }
.level-btn.done.active { background: var(--win); border-color: var(--win); color: #fff; }
/* Locked (v1.0.4 sequential unlock): greyed with a lock badge, not
   clickable — the click only shows the unlock hint. */
.level-btn.locked {
  background: #f0ede4;
  color: #b3a98f;
  border-color: #ddd5c2;
  cursor: not-allowed;
}
.level-btn.locked::after {
  content: "🔒";
  position: absolute;
  top: 1px; right: 3px;
  font-size: 10px;
  line-height: 1;
}

/* ---------- 胜利横幅（唯一的结束遮罩） ---------- */
.overlay {
  position: absolute;
  inset: 0;
  background: var(--overlay-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 5;
}
.overlay-box { text-align: center; max-width: 420px; width: 100%; position: relative; z-index: 2; }
.banner-badge {
  display: inline-block;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: #fff;
  background: var(--win);
  border-radius: 999px;
  padding: 10px 38px 11px;
  margin-bottom: 14px;
  box-shadow: 0 8px 20px rgba(95, 130, 85, 0.22);
}
.record-tag {
  display: inline-block;
  font-size: 13px;
  font-weight: 800;
  color: #7a5b12;
  background: var(--gold);
  border-radius: 999px;
  padding: 4px 14px;
  margin-bottom: 12px;
  margin-left: 8px;
  vertical-align: 6px;
}
.overlay-sub {
  margin: 0 0 22px;
  font-size: 15px;
  color: var(--ink-soft);
  line-height: 1.6;
}
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 24px;
}
.stat {
  background: #fff;
  border: 1px solid var(--pill-border);
  border-radius: 12px;
  padding: 10px 4px 8px;
}
.stat-label { display: block; font-size: 11px; color: #a2937d; letter-spacing: 0.08em; margin-bottom: 2px; }
.stat-num { display: block; font-size: 20px; font-weight: 800; color: var(--ink); font-variant-numeric: tabular-nums; }
.overlay-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.overlay-btns .btn { padding: 12px 26px; font-size: 16px; }
.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); }
}

/* ---------- 排行榜 ---------- */
.rank-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.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;
  padding: 8px 18px;
  min-height: 44px;
  cursor: pointer;
}
.back-btn:hover { background: #f6f1e7; }
.rank-title { margin: 0; font-size: 24px; font-weight: 800; color: var(--ink); }
.demo-tag {
  margin-left: auto;
  font-size: 12px;
  font-weight: 700;
  color: #7a5b12;
  background: var(--gold);
  border-radius: 999px;
  padding: 4px 12px;
  white-space: nowrap;
}
.rank-sub { font-size: 13px; color: var(--ink-soft); margin: -8px 0 12px; }
.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;
}
.rank-tag {
  flex: none;
  background: #fff;
  border: 1px solid var(--you-border);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
}
.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: 1px solid #eee7d8;
  border-radius: 16px;
  background: #fff;
}
.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 #f3eee1;
  background: #fbf8f0;
  position: sticky;
  top: 0;
  z-index: 1;
}
.rank-row { border-bottom: 1px solid #f3eee1; }
.rank-row:last-child { border-bottom: none; }
.rank-no {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: #f3eee1;
  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-colhead .rank-no { background: transparent; height: auto; }
.rank-row.top .rank-no { color: #fff; }
.rank-row.top .rank-name { font-weight: 800; }
.rank-row.top .rank-level, .rank-row.top .rank-time { 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-level, .rank-time { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.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(--btn-main); color: #fff; }
.rank-row.you .rank-name { font-weight: 800; }
.rank-row.you .rank-level, .rank-row.you .rank-time { font-weight: 800; }
.rank-empty {
  padding: 28px 16px;
  text-align: center;
  font-size: 14px;
  color: var(--ink-soft);
}

@media (max-width: 460px) {
  .game-card { padding: 14px; }
  .pill-num { font-size: 18px; }
  .btn { padding: 8px 16px; font-size: 14px; }
  .piece.cao { font-size: 19px; }
}
@media (prefers-reduced-motion: reduce) {
  .piece { transition: none; }
  .confetti { display: none; }
}
