/* =========================================================
   拯救灭建国样式
   - 页面整体：深紫背景 + 16:9 舞台居中
   - 舞台内部：canvas 画游戏世界，DOM 画 HUD 与弹窗
   - 单位尽量用「相对舞台的百分比 / 容器查询单位」，
     这样手机横屏、电脑全屏都能等比缩放
   ========================================================= */

:root {
  --ink: #2c1c3d;
  --cream: #fff3d6;
  --gold: #ffcf5c;
  --pink: #ff9db5;
  --green: #7ed957;
  --shadow: 0 8px 24px rgba(40, 20, 60, .28);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #171321;
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  touch-action: none;
}

.game-shell {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 12px;
}

/* 舞台：永远保持 16:9，宽度取「视口宽」和「视口高换算出的宽」里较小的那个 */
.stage {
  position: relative;
  width: min(100vw - 24px, (100svh - 24px) * 16 / 9);
  aspect-ratio: 16 / 9;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow), 0 0 0 4px #2b2038;
  container-type: size; /* 让内部可以用 cqw / cqh 单位 */
  user-select: none;
  background: #1d1526;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ================= HUD ================= */
.hud {
  position: absolute;
  inset: 0;
  pointer-events: none; /* 默认不挡操作，只有按钮单独开启 */
  padding: 2.2cqw;
  display: flex;
  flex-direction: column;
}

.top {
  display: flex;
  align-items: center;
  gap: 1.4cqw;
}

.hpbar {
  position: relative;
  flex: 1 1 auto;
  height: 3.4cqw;
  min-height: 20px;
  max-height: 34px;
  border-radius: 999px;
  background: #2b2038cc;
  box-shadow: inset 0 0 0 2px #ffffff33;
  overflow: hidden;
}

.hpfill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff7a9c, #ffb36b);
  transition: width .12s linear;
}

.hpbar span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font: 700 1.35cqw/1 "PingFang SC", system-ui, sans-serif;
  color: #fff;
  text-shadow: 0 1px 2px #00000088;
  letter-spacing: .04em;
  font-size: max(11px, 1.35cqw);
}

.chapter {
  font: 700 1.5cqw/1.4 "PingFang SC", system-ui, sans-serif;
  font-size: max(12px, 1.5cqw);
  color: #5b3a6b;
  background: #fff6e0d9;
  padding: .5cqw 1.2cqw;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 2px 0 #d9c39a;
}

/* 技能按钮 */
.skills {
  margin-top: auto;
  display: flex;
  justify-content: flex-end;
  gap: 1.2cqw;
  pointer-events: none;
}

.skill {
  position: relative;
  pointer-events: auto;
  border: 0;
  cursor: pointer;
  overflow: hidden;
  min-width: 9cqw;
  padding: 1cqw 1.2cqw;
  border-radius: 1.2cqw;
  background: linear-gradient(180deg, #fff8e6, #ffdca8);
  box-shadow: 0 4px 0 #c99a5e, 0 8px 18px #0004;
  color: #4a2f1a;
  font: 800 1.25cqw/1.15 "PingFang SC", system-ui, sans-serif;
  font-size: max(12px, 1.25cqw);
  display: grid;
  gap: .25cqw;
  transition: transform .06s;
}

.skill:active { transform: translateY(2px); box-shadow: 0 2px 0 #c99a5e; }

.skill .key {
  font: 600 .9cqw/1 system-ui, sans-serif;
  font-size: max(10px, .9cqw);
  color: #8a6440;
  letter-spacing: .08em;
}

/* 第一个技能名字比较长，单独缩小一点，保证一行放得下 */
.skill b { white-space: nowrap; }
#skDash b { font-size: max(9px, .95cqw); letter-spacing: -.01em; }

/* 冷却遮罩：从下往上退
   别用不透明的深色填满，否则一个 100px 的大圆盘糊在战场上非常挡视野，
   只用很淡的一层 + 一条上边缘，能看出"还在冷却"就够了 */
.skill .cd {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 0%;
  background: linear-gradient(180deg, #2b203815, #2b203870);
  border-top: 1px solid #2b203880;
  pointer-events: none;
}

/* ================= 弹窗 ================= */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  gap: 2cqw;
  padding: 4cqw;
  background: radial-gradient(120% 120% at 50% 0%, #3b2450d9, #170f1fe8);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
  z-index: 10;
}

.overlay.show { opacity: 1; pointer-events: auto; }

.panel {
  width: min(78cqw, 620px);
  padding: 3.4cqw 3.6cqw;
  border-radius: 2.4cqw;
  background: linear-gradient(180deg, #fffaf0, #ffe9c9);
  box-shadow: 0 1.6cqw 0 #b98a55, 0 3cqw 6cqw #0006;
  text-align: center;
}

.eyebrow {
  margin: 0 0 1cqw;
  font: 700 1.1cqw/1 system-ui, sans-serif;
  font-size: max(11px, 1.1cqw);
  letter-spacing: .18em;
  color: #9a7a52;
}

.title-panel h1 {
  margin: 0 0 1.4cqw;
  font: 900 6cqw/1.05 "Songti SC", "SimSun", serif;
  font-size: max(30px, 6cqw);
  color: #4b2c5e;
  text-shadow: 0 .35cqw 0 #ffd98a;
  letter-spacing: .06em;
}

.subtitle {
  margin: 0 0 2.6cqw;
  font: 700 1.9cqw/1.65 "PingFang SC", system-ui, sans-serif;
  font-size: max(14px, 1.9cqw);
  color: #6b4a58;
}

.subtitle b { color: #b63f6d; }

.primary-btn {
  border: 0;
  cursor: pointer;
  padding: 1.5cqw 3.4cqw;
  border-radius: 999px;
  background: linear-gradient(180deg, #7ad35b, #43a832);
  color: #fff;
  font: 900 1.7cqw/1 "PingFang SC", system-ui, sans-serif;
  font-size: max(15px, 1.7cqw);
  letter-spacing: .1em;
  box-shadow: 0 .8cqw 0 #2e7a22, 0 1.4cqw 3cqw #0005;
  transition: transform .07s;
}

.primary-btn:active { transform: translateY(.4cqw); box-shadow: 0 .4cqw 0 #2e7a22; }

.keys {
  margin: 2.4cqw 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: .7cqw;
  font: 600 1.15cqw/1.5 system-ui, sans-serif;
  font-size: max(11px, 1.15cqw);
  color: #7a5c46;
}

kbd {
  display: inline-block;
  padding: .1em .45em;
  border-radius: .35em;
  background: #fff;
  box-shadow: 0 2px 0 #cbb79a;
  font: 700 .95em/1.3 ui-monospace, monospace;
  color: #5c4230;
}

/* ================= 升级选卡 ================= */
#levelUp {
  background: radial-gradient(120% 120% at 50% 100%, #5a2f6ed9, #170f1fee);
  align-content: center;
}

.levelup-head { text-align: center; }

.levelup-head h2 {
  margin: 0 0 .6cqw;
  font: 900 3.4cqw/1.1 "Songti SC", serif;
  font-size: max(22px, 3.4cqw);
  color: #ffe9a8;
  text-shadow: 0 .3cqw 0 #b4406d;
  letter-spacing: .1em;
}

.levelup-head p {
  margin: 0 0 2.6cqw;
  font: 600 1.3cqw/1.4 system-ui, sans-serif;
  font-size: max(12px, 1.3cqw);
  color: #e6d3ffcc;
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2cqw;  width: min(88cqw, 900px);
}

.card {
  cursor: pointer;
  text-align: left;
  border: 0;
  padding: 2.2cqw 2cqw 2.4cqw;
  border-radius: 1.8cqw;
  background: linear-gradient(180deg, #fffdf6, #ffe7bf);
  box-shadow: 0 1cqw 0 #a97b4b, 0 2cqw 4cqw #0006;
  transition: transform .12s ease, box-shadow .12s ease;
  display: grid;
  gap: 1cqw;
  align-content: start;
}

.card:hover { transform: translateY(-.8cqw); box-shadow: 0 1.6cqw 0 #a97b4b, 0 2.6cqw 5cqw #0007; }
.card:active { transform: translateY(.2cqw); }

.card .tag {
  font: 800 .95cqw/1 ui-monospace, monospace;
  font-size: max(10px, .95cqw);
  color: #fff;
  background: #6b4a9a;
  padding: .45cqw .8cqw;
  border-radius: .5cqw;
  justify-self: start;
  letter-spacing: .08em;
}

.card .name {
  font: 900 2.1cqw/1.2 "PingFang SC", system-ui, sans-serif;
  font-size: max(16px, 2.1cqw);
  color: #452a5c;
}

.card .desc {
  font: 600 1.15cqw/1.55 system-ui, sans-serif;
  font-size: max(11px, 1.15cqw);
  color: #6d5540;
}

.card .stack {
  font: 700 1cqw/1 ui-monospace, monospace;
  font-size: max(10px, 1cqw);
  color: #9b7c5c;
}

/* ================= 移动端摇杆 ================= */
.joy {
  position: absolute;
  left: 3.5cqw;
  bottom: 3.5cqw;
  width: 15cqw;
  height: 15cqw;
  min-width: 92px;
  min-height: 92px;
  border-radius: 50%;
  background: #ffffff1f;
  box-shadow: inset 0 0 0 2px #ffffff44;
  display: none;
  place-items: center;
  z-index: 5;
  touch-action: none;
}

.joy .knob {
  width: 42%;
  height: 42%;
  border-radius: 50%;
  background: #ffffffdd;
  box-shadow: 0 .3cqw 1cqw #0005;
  transform: translate(0, 0);
}

/* 触屏设备才显示摇杆 */
@media (hover: none) and (pointer: coarse) {
  .joy { display: grid; }
}

/* ================= 飘字提示 ================= */
.toast {
  position: absolute;
  left: 50%;
  top: 16%;
  transform: translate(-50%, 0);
  padding: .9cqw 2cqw;
  border-radius: 999px;
  background: #2b2038e0;
  color: #ffe9a8;
  font: 800 1.35cqw/1.2 "PingFang SC", system-ui, sans-serif;
  font-size: max(12px, 1.35cqw);
  opacity: 0;
  transition: opacity .25s, transform .25s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 8;
}

.toast.show { opacity: 1; transform: translate(-50%, -1cqw); }

/* =========================================================
   手机适配（pointer: coarse = 触屏设备）
   ========================================================= */

.icon-btn {
  pointer-events: auto;
  flex: 0 0 auto;
  width: 3.4cqw;
  height: 3.4cqw;
  min-width: 30px;
  min-height: 30px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid #ffffff44;
  background: #2b2038b3;
  color: #ffe9a8;
  font-size: max(12px, 1.4cqw);
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.touch-tip {
  display: none;
  margin: 1.4cqw 0 0;
  font: 600 1.2cqw/1.5 "PingFang SC", system-ui, sans-serif;
  font-size: max(12px, 1.2cqw);
  color: #7a5c46;
}

/* 竖屏时的"请横屏"提示 */
.rotate-hint {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: none;
  place-items: center;
  background: radial-gradient(120% 120% at 50% 40%, #2a1c3a, #120c1b);
  color: #ffe9a8;
  text-align: center;
  padding: 6vw;
}

.rotate-hint .phone-ico {
  font-size: 14vmin;
  line-height: 1;
  animation: tilt 1.8s ease-in-out infinite;
}

.rotate-hint p {
  margin: 4vmin 0 1.5vmin;
  font: 800 5.4vmin/1.3 "Songti SC", serif;
  letter-spacing: .08em;
}

.rotate-hint small {
  font: 600 3vmin/1.4 system-ui, sans-serif;
  color: #c9b2e0;
}

@keyframes tilt {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-90deg); }
}

.rotate-hint .hint-btn {
  margin-top: 6vmin;
  padding: 2.6vmin 5vmin;
  font-size: 3.4vmin;
  letter-spacing: .04em;
}

@media (orientation: portrait) and (pointer: coarse) {
  .rotate-hint { display: grid; }
}

/* ---------------------------------------------------------
   竖屏兜底模式：手机转不过来（方向锁定 / 微信内置浏览器）时，
   点「竖屏也能玩」→ body 加 .play-portrait。
   舞台铺满整屏，canvas 用 object-fit: contain 保持 16:9，
   上下多出来的黑边正好留给拇指放摇杆和技能键。
   --------------------------------------------------------- */
@media (orientation: portrait) {
  body.play-portrait .rotate-hint { display: none; }
}

@media (orientation: portrait) and (pointer: coarse) {
  body.play-portrait .stage {
    width: 100vw;
    height: 100svh;
    aspect-ratio: auto;
    border-radius: 0;
    box-shadow: none;
  }

  body.play-portrait canvas {
    object-fit: contain;
  }

  body.play-portrait .hud {
    /* 竖屏也要避开刘海和底部横条 */
    padding: max(3vmin, env(safe-area-inset-top))
             max(4vmin, env(safe-area-inset-right))
             max(3vmin, env(safe-area-inset-bottom))
             max(4vmin, env(safe-area-inset-left));
  }

  body.play-portrait .joy {
    width: 26vmin;
    height: 26vmin;
    min-width: 88px;
    min-height: 88px;
    bottom: max(5vmin, env(safe-area-inset-bottom));
    left: max(5vmin, env(safe-area-inset-left));
  }

  body.play-portrait .skills {
    gap: 4vmin;
    padding: 0;
  }

  body.play-portrait .skill {
    min-width: 20vmin;
    min-height: 20vmin;
    font-size: max(14px, 3.6vmin);
  }

  /* 竖屏时章节标签太占地方，藏掉 */
  body.play-portrait .chapter { display: none; }
}

@media (pointer: coarse) {
  html, body {
    height: 100%;
    overscroll-behavior: none;
    -webkit-touch-callout: none;
  }

  /* 手机上不要留白，舞台尽量铺满，多出来的用同色黑边 */
  .game-shell {
    padding: 0;
    background: #120c1b;
  }

  .stage {
    width: min(100vw, 100svh * 16 / 9);
    border-radius: 0;
    box-shadow: none;
  }

  /* 键盘提示对手机没意义 */
  .keys { display: none; }
  .touch-tip { display: block; }

  /* 技能键做成圆钮，拇指够得着即可，别做太大挡战场 */
  .skills { gap: 3cqw; padding: 0 1cqw; }
  .skill {
    min-width: 13cqw;
    min-height: 13cqw;
    border-radius: 50%;
    place-content: center;
    font-size: max(13px, 2.6cqw);
  }
  .skill .key { display: none; }

  .hud {
    padding-top: max(2.2cqw, env(safe-area-inset-top));
    padding-bottom: max(2.2cqw, env(safe-area-inset-bottom));
    padding-left: max(2.2cqw, env(safe-area-inset-left));
    padding-right: max(2.2cqw, env(safe-area-inset-right));
  }

  .joy { display: grid; }
}

/* =========================================================
   无限宝石选卡
   每张卡顶上一颗发光宝石，颜色由 JS 写在 --gem 里
   ========================================================= */
.card.gem {
  justify-items: start;
  padding-top: 1.6cqw;
}

.card .gem-orb {
  width: 3.6cqw;
  height: 3.6cqw;
  min-width: 26px;
  min-height: 26px;
  border-radius: 50%;
  background: var(--gem, #999); /* 老浏览器没有 color-mix 时的兜底 */
  background:
    radial-gradient(circle at 34% 28%, #ffffffcc 0%, #ffffff33 22%, transparent 45%),
    radial-gradient(circle at 50% 50%, var(--gem, #999) 0%, color-mix(in srgb, var(--gem, #999) 60%, #000) 100%);
  box-shadow:
    0 0 1.6cqw var(--gem, transparent),
    inset 0 -0.4cqw 0.8cqw #0004;
  margin-bottom: .6cqw;
}

.card.gem .name {
  color: var(--gem, #452a5c);
  text-shadow: 0 1px 0 #ffffffaa;
}

.card.gem.owned {
  cursor: default;
  opacity: .42;
  filter: grayscale(.7);
  box-shadow: 0 .6cqw 0 #a97b4b, 0 1cqw 2cqw #0003;
}
