:root {
  --wood-dark: #3a2110;
  --wood: #6b3f1d;
  --cream: #ffe9b8;
  --cheese: #ffc93c;
  --green: #7ec850;
  --danger: #e2452e;
  --ink: #1b1208;
  --font: "Trebuchet MS", "Segoe UI", "HYQiHei", sans-serif;
  /* 底部工具栏预留高度：画面整体上移，蟑螂永远不会跑到按钮底下 */
  --bar-h: 104px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: #120c06 radial-gradient(circle at 50% 0%, #3a2614 0%, #120c06 70%);
  font-family: var(--font);
  color: #fff;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
}

#stage {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: var(--bar-h);
  margin: auto;
  width: min(100vw, calc((100vh - var(--bar-h)) * 16 / 9));
  height: min(calc(100vh - var(--bar-h)), calc(100vw * 9 / 16));
  /* 折叠屏/移动浏览器收起地址栏时 100vh 会比可视区大，优先用动态视口高度 */
  width: min(100vw, calc((100dvh - var(--bar-h)) * 16 / 9));
  height: min(calc(100dvh - var(--bar-h)), calc(100vw * 9 / 16));
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .65), 0 0 0 1px rgba(255, 220, 150, .12);
}

body { position: relative; }

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

/* ===== HUD ===== */
#hud {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 14px 16px;
  pointer-events: none;
  z-index: 5;
}

.hud-group { display: flex; align-items: center; gap: 10px; pointer-events: none; }
.hud-group > button, .hud-group > .pill { pointer-events: auto; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px;
  border-radius: 12px;
  background: rgba(28, 18, 9, .72);
  border: 1px solid rgba(255, 214, 130, .28);
  font-size: 14px;
  letter-spacing: .8px;
  backdrop-filter: blur(6px);
}
.wave-pill b { color: var(--cheese); font-size: 19px; }

.cheese-meter {
  position: relative;
  width: 190px;
  height: 40px;
  border-radius: 12px;
  background: rgba(28, 18, 9, .72);
  border: 1px solid rgba(255, 214, 130, .28);
  overflow: hidden;
  backdrop-filter: blur(6px);
}
.cheese-meter-fill {
  position: absolute;
  inset: 3px auto 3px 3px;
  width: calc(100% - 6px);
  border-radius: 9px;
  background: linear-gradient(180deg, #ffd766, var(--cheese));
  box-shadow: 0 0 14px rgba(255, 201, 60, .45);
  transition: width .18s ease, background .3s;
}
.cheese-meter-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 700;
  color: #3a2208;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .35);
}
.cheese-meter.low .cheese-meter-fill { background: linear-gradient(180deg, #ff8a6e, var(--danger)); animation: pulse .8s infinite; }

.coin-pill b { font-size: 20px; color: var(--cheese); min-width: 34px; }

.coin {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff0b8, #f5b91b 55%, #a9760b);
  box-shadow: inset 0 0 0 1.5px rgba(120, 76, 0, .5);
  display: inline-block;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(28, 18, 9, .72);
  border: 1px solid rgba(255, 214, 130, .28);
  color: #ffe9b8;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: .15s;
}
.icon-btn:hover { background: rgba(70, 45, 20, .9); }
.icon-btn svg { width: 21px; height: 21px; fill: currentColor; stroke: currentColor; stroke-width: 1.8; fill-rule: evenodd; }
.icon-btn svg .wave { fill: none; }
#btnMute.muted { opacity: .45; }

/* ===== HINT / BANNER ===== */
.hint {
  position: absolute;
  left: 50%;
  top: 74px;
  transform: translateX(-50%);
  font-size: 15px;
  color: rgba(255, 233, 184, .8);
  text-shadow: 0 2px 6px #000;
  z-index: 4;
  transition: opacity .5s;
  pointer-events: none;
}
.hint.gone { opacity: 0; }

.banner {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%) scale(.8);
  /* 绝对定位 + left:50% 时默认按「剩余宽度」收缩，长文案会在半屏处换行；
     用 max-content + max-width 让它先按一行排，超宽才折行。 */
  width: max-content;
  max-width: 94%;
  /* 留 3px 上内边距：动画里元素会被合成到单独图层，
     字顶和 6px 立体阴影贴着盒子边缘时容易被图层边界削掉一点。 */
  padding: 3px 0 8px;
  font-size: 46px;
  font-weight: 800;
  letter-spacing: 3px;
  line-height: 1.18;
  color: #fff3cf;
  text-shadow: 0 6px 0 #6b3f1d, 0 10px 28px #000;
  opacity: 0;
  z-index: 6;
  pointer-events: none;
  text-align: center;
  white-space: normal;
  overflow-wrap: break-word;
}
.banner.show { animation: bannerPop 1.7s ease forwards; }
.banner small { display: block; font-size: 18px; letter-spacing: 2px; opacity: .85; margin-top: 6px; }

@keyframes bannerPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.7); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
  30% { transform: translate(-50%, -50%) scale(1); }
  78% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -55%) scale(1); }
}

/* 升级横幅：从大到小“砸”下来 + 两下回弹 + 金色外发光，配合画面定格 */
.banner.punch {
  color: #fff6d4;
  text-shadow: 0 6px 0 #6b3f1d, 0 0 24px rgba(255, 201, 60, .9), 0 0 60px rgba(255, 150, 20, .55), 0 12px 34px #000;
  animation: bannerSlam 1.9s cubic-bezier(.16, .84, .28, 1) forwards;
}
@keyframes bannerSlam {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.42) rotate(-5deg); }
  14% { opacity: 1; transform: translate(-50%, -50%) scale(1.22) rotate(2deg); }
  22% { transform: translate(-50%, -50%) scale(.95) rotate(-1.2deg); }
  30% { transform: translate(-50%, -50%) scale(1.08) rotate(.6deg); }
  38% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(1.06); }
}
@keyframes pulse { 50% { opacity: .55; } }

/* ===== 窄舞台（折叠屏 / 竖屏手机）=====
   HUD 和横幅要按「舞台宽度」排，而折叠屏往往视口很宽、舞台只有 360~420px，
   按视口写的媒体查询管不到，所以由 ui.js 读舞台实际宽度挂 .compact / .narrow。 */
#stage.compact #hud { padding: 10px 10px; }
#stage.compact .hud-group { gap: 6px; }
#stage.compact .pill { height: 34px; padding: 0 9px; font-size: 11px; letter-spacing: .4px; gap: 4px; }
#stage.compact .wave-pill b { font-size: 15px; }
#stage.compact .cheese-meter { width: 96px; height: 34px; }
#stage.compact .cheese-meter-label { font-size: 11px; }
#stage.compact .coin { width: 12px; height: 12px; }
#stage.compact .coin-pill b { font-size: 15px; min-width: 20px; }
#stage.compact .icon-btn { width: 34px; height: 34px; border-radius: 10px; }
#stage.compact .icon-btn svg { width: 17px; height: 17px; }
#stage.compact .banner { font-size: 30px; letter-spacing: 2px; }
#stage.compact .banner small { font-size: 13px; letter-spacing: 1px; margin-top: 4px; }
#stage.compact .hint { top: 58px; font-size: 12px; }

#stage.narrow #hud { padding: 8px 8px; }
#stage.narrow .hud-group { gap: 5px; }
#stage.narrow .pill { padding: 0 7px; }
#stage.narrow .cheese-meter { width: 66px; }
#stage.narrow .banner { font-size: 24px; }
#stage.narrow .banner small { font-size: 11px; }

/* ===== TOOLBAR ===== */
#toolbar {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  z-index: 5;
}

.tool {
  position: relative;
  width: 96px;
  padding: 8px 6px 7px;
  border-radius: 14px;
  border: 1px solid rgba(255, 214, 130, .3);
  background: linear-gradient(180deg, rgba(52, 34, 16, .92), rgba(26, 17, 8, .95));
  color: #ffe9b8;
  font-family: var(--font);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  transition: transform .12s, box-shadow .15s, opacity .2s;
}
.tool:hover { transform: translateY(-3px); box-shadow: 0 8px 18px rgba(0, 0, 0, .5); }
.tool:active { transform: translateY(0) scale(.97); }
.tool.locked { opacity: .45; filter: saturate(.4); }
.tool.ready { box-shadow: 0 0 0 2px rgba(255, 201, 60, .55), 0 8px 20px rgba(255, 170, 0, .22); }
.tool-icon { width: 26px; height: 26px; fill: #ffd15c; stroke: #ffd15c; stroke-width: 1.4; }
.tool.ad-tool .tool-icon { fill: #8be07a; stroke: #8be07a; }
.tool-name { letter-spacing: .4px; opacity: .95; }
.tool-cost { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; font-size: 12px; color: #ffd15c; }
.tool-cost .coin { width: 11px; height: 11px; }
.tool-cost.reward { color: #8be07a; }

/* ===== OVERLAYS ===== */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  /* flex + 面板 margin:auto：面板比屏幕矮时居中，比屏幕高时从顶部开始并可滚动，
     不会像 place-items:center 那样把上下两端一起裁掉（折叠屏就栽在这）。 */
  display: flex;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: rgba(12, 7, 3, .72);
  backdrop-filter: blur(4px);
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}
.overlay.hidden { display: none; }

.panel {
  flex: 0 0 auto;
  margin: auto;
  width: min(520px, 100%);
  padding: 30px 30px 26px;
  border-radius: 20px;
  background: linear-gradient(180deg, #3a2614, #211408);
  border: 1px solid rgba(255, 214, 130, .35);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .7), inset 0 1px 0 rgba(255, 230, 170, .18);
  text-align: center;
}
.panel.small { width: min(420px, 100%); }

/* ===== DIFFICULTY PILLS ===== */
.diff-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 10px 0 14px;
}
.diff-pill {
  flex: 1 1 0;
  max-width: 150px;
  padding: 8px 6px;
  border-radius: 12px;
  border: 1px solid rgba(255, 214, 130, .22);
  background: rgba(20, 12, 6, .7);
  color: #c9ab7d;
  font-family: var(--font);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  transition: border-color .15s, background .15s, color .15s, transform .12s;
}
.diff-pill b { font-size: 12px; letter-spacing: 1.2px; }
.diff-pill span { font-size: 9px; line-height: 1.25; opacity: .8; }
.diff-pill:hover { transform: translateY(-2px); }
.diff-pill.on {
  border-color: rgba(255, 201, 60, .85);
  background: linear-gradient(180deg, rgba(255, 201, 60, .22), rgba(120, 70, 10, .35));
  color: #ffe9b8;
  box-shadow: 0 0 0 1px rgba(255, 201, 60, .3), 0 8px 20px rgba(255, 170, 0, .18);
}

.panel h1 {
  margin: 0 0 6px;
  font-size: 44px;
  letter-spacing: 4px;
  color: #fff3cf;
  text-shadow: 0 5px 0 #8a4f12, 0 10px 24px #000;
  line-height: 1.05;
}
.panel h1 span { display: block; color: var(--cheese); font-size: 40px; }
.panel h2 { margin: 0 0 16px; font-size: 26px; letter-spacing: 2px; color: #fff3cf; }
.panel h2.danger { color: #ff8f74; }
.sub { margin: 10px 0 16px; color: #e8cfa2; font-size: 14px; line-height: 1.5; }

.rules {
  margin: 0 0 20px;
  padding: 14px 16px 14px 32px;
  text-align: left;
  background: rgba(0, 0, 0, .28);
  border-radius: 12px;
  color: #e8cfa2;
  font-size: 13px;
  line-height: 1.75;
}
.rules b { color: var(--cheese); }

.btn {
  width: 100%;
  height: 50px;
  border-radius: 13px;
  border: none;
  font-family: var(--font);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 2px;
  cursor: pointer;
  margin-top: 10px;
  transition: transform .12s, filter .15s;
}
.btn:active { transform: scale(.98); }
.btn.primary {
  color: #3a2208;
  background: linear-gradient(180deg, #ffdf85, #f3b41c);
  box-shadow: 0 5px 0 #a9760b, 0 10px 24px rgba(255, 180, 40, .3);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost {
  color: #e8cfa2;
  background: rgba(255, 233, 184, .08);
  border: 1px solid rgba(255, 214, 130, .28);
}
.best { margin: 14px 0 0; font-size: 12px; color: #b99a6c; letter-spacing: 1px; }
.best b { color: var(--cheese); }

.stats { display: grid; gap: 8px; margin: 0 0 8px; }
.stats > div {
  display: flex;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(0, 0, 0, .28);
  font-size: 14px;
  color: #e8cfa2;
}
.stats b { color: var(--cheese); font-size: 16px; }

/* ===== AD LAYER ===== */
.panel.ad { width: min(440px, 100%); padding: 24px; }
.ad-tag {
  display: inline-block;
  font-size: 11px;
  letter-spacing: 2px;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(255, 201, 60, .18);
  color: #ffd15c;
  margin-bottom: 16px;
}
.ad-body {
  height: 180px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: repeating-linear-gradient(45deg, #1a1108, #1a1108 12px, #221708 12px, #221708 24px);
  color: #8a7554;
  font-size: 14px;
  letter-spacing: 1px;
}
.ad-progress { height: 8px; border-radius: 4px; background: rgba(255, 255, 255, .1); margin-top: 16px; overflow: hidden; }
.ad-progress > div { height: 100%; width: 0%; background: linear-gradient(90deg, #ffd15c, #f3b41c); transition: width .2s linear; }
.panel.ad .btn { margin-top: 14px; }

.panel.ad .btn.hidden, .hidden { display: none; }

.tool.free::after {
  content: "FREE";
  position: absolute;
  top: -8px;
  right: -6px;
  padding: 2px 7px;
  border-radius: 7px;
  background: var(--green);
  color: #12280a;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .6px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .45);
  animation: pulse 1.1s infinite;
}

.panel.rev .sub { margin: 12px 0 18px; }
.panel.rev .sub b { color: var(--cheese); }

/* ===== DAILY CHALLENGE BUTTON ===== */
.btn.daily {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 12.5px;
  letter-spacing: 1.2px;
  background: linear-gradient(180deg, rgba(255, 150, 60, .22), rgba(255, 110, 30, .12));
  border: 1px solid rgba(255, 160, 70, .5);
  color: #ffd9a8;
  box-shadow: inset 0 1px 0 rgba(255, 220, 170, .25);
}
.btn.daily b { font-size: 11px; color: #ffb457; letter-spacing: .6px; font-weight: 800; }
.btn.daily.done { background: rgba(126, 200, 80, .16); border-color: rgba(126, 200, 80, .45); color: #b6ef8f; }
.btn.daily.done b { color: #8be07a; }

/* ===== ACHIEVEMENTS ===== */
.ach-btn { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 13px; letter-spacing: 1.5px; }
.ach-btn b { color: var(--cheese); font-size: 13px; }

.panel.ach { width: min(560px, 100%); padding: 24px 22px 20px; text-align: left; }
.panel.ach h2 { text-align: center; margin-bottom: 4px; }
.ach-progress { margin: 0 0 14px; text-align: center; font-size: 12px; color: #b99a6c; letter-spacing: 1px; }

.ach-list {
  max-height: min(52vh, 380px);
  overflow-y: auto;
  padding-right: 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.ach-list::-webkit-scrollbar { width: 6px; }
.ach-list::-webkit-scrollbar-thumb { background: rgba(255, 201, 60, .3); border-radius: 3px; }

.ach-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 11px;
  background: rgba(0, 0, 0, .3);
  border: 1px solid rgba(255, 214, 130, .12);
}
.ach-row.done { background: rgba(126, 200, 80, .12); border-color: rgba(126, 200, 80, .4); }

.ach-badge {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 214, 130, .2);
  color: #12280a;
  font-weight: 800;
  font-size: 15px;
}
.ach-row.done .ach-badge { background: var(--green); border-color: var(--green); }

.ach-main { flex: 1 1 auto; min-width: 0; }
.ach-name { font-size: 14px; font-weight: 700; color: #fff3cf; letter-spacing: .4px; }
.ach-row.done .ach-name { color: #b6ef8f; }
.ach-desc { font-size: 11.5px; color: #a98f6b; margin: 1px 0 6px; }
.ach-bar { height: 5px; border-radius: 3px; background: rgba(255, 255, 255, .09); overflow: hidden; }
.ach-bar > i { display: block; height: 100%; background: linear-gradient(90deg, #ffd15c, #f3b41c); }
.ach-row.done .ach-bar > i { background: var(--green); }

.ach-num { flex: 0 0 auto; font-size: 12px; font-weight: 700; color: var(--cheese); }
.ach-row.done .ach-num { color: #b6ef8f; }

/* ===== MENU ROW / MINI BUTTONS ===== */
.menu-row { display: flex; gap: 10px; margin-top: 10px; }
.btn.mini {
  flex: 1 1 0;
  height: 42px;
  margin-top: 0;
  font-size: 12px;
  letter-spacing: 1.2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn.mini b { color: var(--cheese); font-size: 12px; font-weight: 800; }

/* ===== LEADERBOARD ===== */
.panel.board { width: min(540px, 100%); padding: 24px 22px 20px; text-align: left; }
.panel.board h2, .panel.board .ach-progress { text-align: center; }

.board-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: min(56vh, 360px);
  overflow-y: auto;
  padding-right: 4px;
  margin-bottom: 16px;
}
.board-list::-webkit-scrollbar { width: 6px; }
.board-list::-webkit-scrollbar-thumb { background: rgba(255, 201, 60, .3); border-radius: 3px; }

.board-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, .3);
  border: 1px solid rgba(255, 214, 130, .1);
  font-size: 13px;
  color: #e8cfa2;
}
.board-row:first-child { background: rgba(255, 201, 60, .13); border-color: rgba(255, 201, 60, .45); }
.board-pos { width: 22px; text-align: center; font-weight: 800; color: var(--cheese); }
.board-wave { flex: 0 0 auto; font-size: 11.5px; letter-spacing: 1px; color: #b99a6c; }
.board-wave b { color: #fff3cf; font-size: 16px; margin-left: 2px; }
.board-kills { flex: 1 1 auto; }
.board-combo { color: #8be07a; font-weight: 700; }
.board-date { font-size: 11px; color: #8a7554; }
.board-empty {
  padding: 26px 20px;
  margin-bottom: 16px;
  text-align: center;
  font-size: 13px;
  color: #a98f6b;
  background: rgba(0, 0, 0, .25);
  border-radius: 10px;
}

/* ===== SKINS ===== */
.panel.skins { width: min(540px, 100%); padding: 24px 22px 20px; }
.skin-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.skin-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px 12px;
  border-radius: 14px;
  background: rgba(0, 0, 0, .3);
  border: 1px solid rgba(255, 214, 130, .16);
  color: #e8cfa2;
  font-family: var(--font);
  cursor: pointer;
  transition: transform .14s, box-shadow .16s, opacity .2s;
}
.skin-card:hover { transform: translateY(-2px); }
.skin-card.active {
  background: rgba(255, 201, 60, .1);
  border-color: var(--cheese);
  box-shadow: 0 0 0 2px rgba(255, 201, 60, .32);
}
.skin-card.locked { opacity: .42; cursor: not-allowed; }
.skin-card.locked:hover { transform: none; }
.skin-swatch {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, .35);
  box-shadow: inset -4px -6px 10px rgba(0, 0, 0, .45), inset 3px 4px 8px rgba(255, 255, 255, .22);
}
.skin-name { font-size: 12px; font-weight: 800; letter-spacing: .5px; color: #fff3cf; }
.skin-desc { font-size: 10px; line-height: 1.3; color: #a98f6b; }
.skin-card.active .skin-desc { color: #8be07a; }

/* ===== SHARE CARD ===== */
.btn.share-btn {
  color: #d9f3ff;
  background: linear-gradient(180deg, rgba(92, 180, 220, .26), rgba(40, 120, 170, .14));
  border: 1px solid rgba(120, 200, 240, .45);
}
.panel.share { width: min(620px, 100%); padding: 22px 22px 18px; }
.share-preview {
  margin: 2px 0 10px;
  border-radius: 12px;
  overflow: hidden;
  background: #0c0804;
  border: 1px solid rgba(255, 214, 130, .25);
}
.share-preview img { display: block; width: 100%; height: auto; }
.share-hint { margin: 0 0 4px; font-size: 12px; line-height: 1.45; color: #b99a6c; text-align: center; }
.btn:disabled { opacity: .45; cursor: default; }
#overRank.hot { color: #8be07a; }

/* ===== PORTRAIT PHONE HINT ===== */
#rotateHint {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: #120c06;
  text-align: center;
  padding: 30px;
}
#rotateHint p { margin: 0; font-size: 20px; letter-spacing: 3px; color: #ffe9b8; }
#rotateHint span { font-size: 13px; color: #b99a6c; letter-spacing: 1px; }
.rotate-icon {
  width: 62px;
  height: 100px;
  border: 3px solid #ffc93c;
  border-radius: 12px;
  animation: rotateHint 2.4s ease-in-out infinite;
}
@keyframes rotateHint {
  0%, 30% { transform: rotate(0deg); }
  60%, 100% { transform: rotate(-90deg); }
}
/* ===== PORTRAIT PHONE ===== */
/* 竖屏是一套 648×1152 的竖版逻辑画布（见 config.js layout()），
   所以这里只要让舞台铺满工具栏上方的空间、按 9:16 完整显示即可，不裁边也不缩成小窗。 */
@media (orientation: portrait) {
  #stage {
    width: min(100vw, calc((100vh - var(--bar-h)) * 9 / 16));
    height: min(calc(100vh - var(--bar-h)), calc(100vw * 16 / 9));
    width: min(100vw, calc((100dvh - var(--bar-h)) * 9 / 16));
    height: min(calc(100dvh - var(--bar-h)), calc(100vw * 16 / 9));
    border-radius: 0;
  }
  /* 菜单在竖屏下用整屏显示，避免被舞台高度裁掉；高度跟动态视口走，
     否则折叠屏上浏览器工具栏会把菜单底部（开始按钮）挡在屏幕外 */
  .overlay { position: fixed; inset: 0; height: 100dvh; max-height: 100dvh; }
  #rotateHint { display: none !important; }
}

/* 折叠屏、矮一点的手机：把开场面板整体压扁，尽量一屏放下 START 按钮 */
@media (max-height: 820px) {
  .panel { padding: 16px 18px 14px; }
  .panel h1 { font-size: 30px; letter-spacing: 3px; }
  .panel h1 span { font-size: 26px; }
  .panel h2 { font-size: 21px; margin-bottom: 10px; }
  .panel .sub { font-size: 12px; margin: 6px 0 10px; }
  .rules { font-size: 11px; line-height: 1.55; padding: 10px 12px 10px 26px; margin: 0 0 10px; }
  .diff-row { margin: 6px 0 8px; }
  .diff-pill { padding: 5px 4px; }
  .diff-pill b { font-size: 11px; }
  .diff-pill span { font-size: 8px; }
  .btn { height: 42px; font-size: 14px; margin-top: 7px; }
  .btn.mini { height: 36px; font-size: 11px; }
  .best { margin: 8px 0 0; font-size: 11px; }
}

@media (max-width: 560px) {
  .cheese-meter { width: 120px; }
  #toolbar { gap: 6px; bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
  .tool { width: 76px; font-size: 10px; }
  .panel h1 { font-size: 34px; }
  .panel h1 span { font-size: 30px; }
  .banner { font-size: 32px; }
  .rules { font-size: 12px; line-height: 1.6; }
}

/* 横屏手机等矮屏：工具栏压扁，少占画面高度 */
@media (max-height: 560px) {
  :root { --bar-h: 74px; }
  #toolbar { gap: 7px; bottom: calc(6px + env(safe-area-inset-bottom, 0px)); }
  .tool { width: 78px; padding: 5px 4px 4px; gap: 1px; font-size: 9px; border-radius: 11px; }
  .tool-icon { width: 18px; height: 18px; }
  .tool-cost { font-size: 9px; gap: 3px; }
  .tool-cost .coin { width: 9px; height: 9px; }
  /* 舞台变矮后，菜单面板要能被压缩，否则按钮会被裁掉；
     同时让 overlay 脱离 #stage、撑满整个视口——否则 #stage 只有约 338px 高，
     面板底部的 START 按钮会被 #stage 的 overflow:hidden 直接裁掉（横屏手机实测）。
     竖屏媒体查询里已是同样做法，这里补齐横屏矮屏。 */
  .overlay { padding: 8px; position: fixed; inset: 0; height: 100vh; height: 100dvh; max-height: 100vh; max-height: 100dvh; }
  .panel { padding: 16px 18px 14px; max-height: 100%; overflow-y: auto; }
  .panel h1 { font-size: 28px; }
  .panel h1 span { font-size: 24px; }
  .panel .sub { font-size: 12px; margin: 4px 0 8px; }
  .rules { font-size: 11px; line-height: 1.5; margin: 6px 0 10px; }
  .btn { padding: 9px 20px; }
}

/* 极矮屏（横屏手机）：菜单只剩按钮，规则文字让位给可点区域 */
@media (max-height: 430px) {
  .rules { display: none; }
  .panel h1 { font-size: 24px; }
  .panel h1 span { font-size: 21px; }
  .panel .sub { font-size: 11px; margin: 2px 0 8px; }
}
