/* TANK BATTLE · 坦克大战 —— 深色军事风 + 红白机手柄
 *
 * 设计约束（沿用项目约定）：
 *   - 纯 CSS、零依赖、零素材、零构建；封面是 HTML 里的内联 SVG
 *   - 移动优先：整页**不滚动**，游戏区吃掉剩下的全部高度（画布尺寸由 game.mjs 的 layout() 算）
 *   - 三区版面铁律：顶栏（细）→ 游戏区（flex:1）→ 手柄（flex:0 0 auto，先占位）
 *   - 像素感靠「等宽字体 + 硬阴影 + image-rendering: pixelated」，不用图片
 *
 * 配色：近黑底 + 砖橙 #c1622b + 军绿 #5f9e3f + 钢灰
 */

/*
 * 🔴 这一条必须是样式表的第一条，不能删：
 *   下面 .scores / .menu / .save-row / .overlay / .title 都写了 display:flex，
 *   作者样式会盖掉浏览器给 [hidden] 的 display:none —— 面板就再也关不掉了
 *   （这个项目真踩过两次：面板一进页面就浮在那儿，点「关闭」没反应）。
 */
[hidden] { display: none !important; }

/* 🔴 三级 z-index（模板第四节 4.3，数字别改）：
 *   5   主界面 / 覆盖层
 *   8   高分榜 / 菜单 —— 必须高于 5，否则榜开了却看不见 =「打不开」
 *   12  Toast         —— 提示永远最上面
 */
.title, .overlay { z-index: 5; }
.scores, .menu   { z-index: 8; }
.toast           { z-index: 12; }

*, *::before, *::after { box-sizing: border-box; }

:root {
  /* ---- 军事风配色 ---- */
  --bg: #0a0b09;          /* 近黑，带一点军绿的脏 */
  --panel: #161a14;       /* 面板底 */
  --panel-2: #0b0d0a;     /* 更深的一块（输入框 / 画布底） */
  --line: #35402f;        /* 钢灰绿描边 */
  --ink: #e7ecdf;
  --ink-dim: #8b9684;     /* 钢灰字 */
  --accent: #c1622b;      /* 砖橙：主按钮 / 强调 */
  --accent-2: #e08a4c;    /* 砖橙的亮档（渐变上沿 / 标题） */
  --green: #5f9e3f;       /* 军绿：分数 / 成功 */
  --danger: #d8452f;
  --shadow: #040503;

  /* ---- 手柄配色：偏暗的「酒红」机身，才压得住深色底，不刺眼（数值来自模板，别动） ---- */
  --pad-base: #6d2328;
  --pad-base-2: #3f1215;
  --pad-edge: #24090b;
  --pad-gold: #d9bd7c;
  --pad-cream: #f2e4c4;
  --key-face: #d8d4c9;
  --key-face-2: #a9a498;

  /* ---- 手柄按键尺寸：随屏宽/屏高自适应，短屏（横屏）自动变小。
     这几个数是按「360px 宽的手机也放得下 十字键 + 两颗胶钮 + A/B」倒推出来的（模板原值） ---- */
  --key: min(56px, 15vw);          /* 十字键一格的宽度 */
  --keyh: calc(var(--key) * 0.9);  /* 高度略矮一点，别做成正方形 */
  --ab: min(62px, 16.5vw);
  --pill-w: 40px;
  --pill-h: 22px;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #000;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  /* 游戏页不滚动：一切尺寸都由视口反推，战场小了就小一点，不要出现滚动条 */
  overflow: hidden;
  overscroll-behavior: none;
}

/* 背景上压一层很淡的「军用坐标纸」，别抢战场 */
body {
  background-image:
    linear-gradient(rgba(95, 158, 63, .05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(95, 158, 63, .05) 1px, transparent 1px);
  background-size: 24px 24px;
}

/* ---------- 页面骨架（三区：顶栏 / 游戏区 / 手柄） ---------- */

.battle-app {
  height: 100vh;
  height: 100dvh;                                   /* 手机上 dvh 才准，vh 会被地址栏骗 */
  max-width: 480px;
  margin: 0 auto;
  padding:
    calc(6px + env(safe-area-inset-top))
    calc(10px + env(safe-area-inset-right))
    calc(24px + env(safe-area-inset-bottom))
    calc(10px + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ---------- 顶栏（细，不抢空间） ---------- */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  border-bottom: 1px solid rgba(53, 64, 47, .75);
}

.back-link {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--ink-dim);
  text-decoration: none;
  border-bottom: 1px dashed currentColor;
}

.back-link:active { color: var(--accent-2); }

.stat {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 3px;
  font-size: 11px;
  color: var(--ink-dim);
  white-space: nowrap;
  overflow: hidden;
}

.stat__label {
  font-size: 10px;
  letter-spacing: .5px;
  color: var(--ink-dim);
}

.stat__value {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
}

.stat__value--level { color: var(--accent-2); }
.stat__sep { opacity: .45; }

/* 过一关时闪一下（JS 加 .is-up，动画完自己摘掉） */
.stat__value.is-up { animation: stage-up .9s ease-out; }

@keyframes stage-up {
  0%   { color: #fff; text-shadow: 0 0 12px var(--accent); transform: scale(1.3); }
  100% { color: var(--accent-2); text-shadow: none; transform: scale(1); }
}

/* 右上角一排图标工具（只放图标，中文都在 aria-label / title 里） */

.tools {
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
}

.icon-btn {
  position: relative;        /* 声音关掉时那条「斜杠」用伪元素画 */
  width: 29px;
  height: 29px;
  padding: 0;
  font-family: inherit;
  font-size: 14px;
  line-height: 1;
  color: var(--ink);
  background: linear-gradient(180deg, #1e241b, #131711);
  border: 1px solid var(--line);
  border-radius: 5px;
  box-shadow: 0 1px 0 var(--shadow);
  cursor: pointer;
}

.icon-btn:active { transform: translate(1px, 1px); box-shadow: none; }

/* 声音关掉：红底 + 一道斜杠（「静音」那种观感）。
   JS 用的是 .icon-btn--off；.is-off 是模板里的旧名，两个都认，改名不会掉样式。 */
.icon-btn--off,
.icon-btn.is-off {
  color: #ffb6a8;
  background: rgba(216, 69, 47, .22);
  border-color: #8d2a1c;
}

.icon-btn--off::after,
.icon-btn.is-off::after {
  content: '';
  position: absolute;
  left: 3px;
  right: 3px;
  top: 50%;
  height: 2px;
  margin-top: -1px;
  background: #ff8f7a;
  border-radius: 1px;
  transform: rotate(-24deg);
  pointer-events: none;
}

/* ---------- 游戏区：吃掉顶栏与手柄之外的全部高度 ---------- */

.stage {
  position: relative;        /* 覆盖界面按它定位 */
  flex: 1 1 auto;            /* ★ 吃满剩下的高度 */
  min-height: 0;             /* ★ 不写这行，flex 子项不会真的收缩 */
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

/* 画布外框：宽高由 JS 在 layout() 里写成内联 px（256×224 的 NES 比例），CSS 不写死 */
.board-wrap {
  position: relative;
  display: flex;
  /* 兜底尺寸：layout() 跑起来就会用内联 px 覆写掉这两个值。
     留着它只是为了「JS 还没跑完」的那一瞬间不是 0×0（真踩过别的站整块空白）。 */
  width: 256px;
  height: 224px;
  background: #000;
  border: 3px solid var(--line);
  box-shadow: 3px 3px 0 var(--shadow);
}

.board-wrap--over { border-color: var(--danger); }

.board {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;             /* 别让 canvas 的固有宽度（256）把外框撑出去 */
  min-height: 0;
  /* ⚠️ 这条不能删：战场放大好几倍，没有它像素块会糊成一团，硬边没了 */
  image-rendering: pixelated;
  background: #000;
  touch-action: none;
}

/* ---------- Toast（一行短提示，永远在最上面，见顶部 z-index 那一块） ---------- */

.toast {
  position: absolute;
  left: 50%;
  top: 8px;
  transform: translateX(-50%);
  margin: 0;
  padding: 4px 10px;
  font-size: 11px;
  letter-spacing: .5px;
  white-space: nowrap;
  color: #f4f8ee;
  background: rgba(11, 13, 10, .92);
  border: 1px solid var(--accent);
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .5);
  opacity: 0;
  transition: opacity .2s ease-out;
  pointer-events: none;
}

.toast--show { opacity: 1; }

/* ---------- 主界面（封面 + 两个入口） ---------- */

.title {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;   /* 按钮沉到底部，上面让 canvas 的标题画面透出来 */
  gap: 10px;
  padding: 12px;
  text-align: center;
  overflow: hidden;          /* 矮屏时宁可裁掉一点，也绝不撑出滚动条 */
  /* 只有底部压一层暗色，按钮才看得清；上面完全透明，露出 canvas 画的标题画面 */
  background: linear-gradient(180deg, transparent 46%, rgba(4, 5, 4, .78) 74%, rgba(4, 5, 4, .92));
}

/* 主界面底部那条窄条：不透明底，所以它后面的东西是被盖住的（用户提过「没遮住后面」） */
.title__bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: calc(100% + 24px);
  margin: 0 -12px -12px;
  padding: 5px 10px calc(5px + env(safe-area-inset-bottom));
  background: #0a0b0c;
  border-top: 1px solid #23252a;
  font-size: 10px;
  color: #9aa0a6;
}

.title__link {
  padding: 2px 4px;
  font: inherit;
  color: #c9cdd4;
  background: transparent;
  border: 0;
  cursor: pointer;
}

.title__sep { opacity: .45; }
.title__hint2 { color: #7f858d; }

.title__card {
  position: relative;
  flex: 0 1 auto;            /* 矮屏允许它（连同封面）一起缩，不跟按钮抢高度 */
  min-height: 0;
  width: 100%;
  max-width: 320px;
  aspect-ratio: 208 / 116;   /* 和内联 SVG 的 viewBox 一致 */
  overflow: hidden;
  background: #0a0a0c;
  border: 2px solid var(--line);
  border-radius: 6px;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, .85),
    0 6px 16px rgba(0, 0, 0, .55);
}

.title__art {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.title__name {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 6px;
  text-indent: 6px;          /* 抵消最后一个字多出来的字距，视觉才居中 */
  color: var(--ink);
  text-shadow: 0 2px 0 #000, 0 0 14px rgba(193, 98, 43, .55);
}

.title__sub {
  margin: 0;
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--green);
}

/* 主界面底部的版本号：小、不抢眼，但能一眼看出手机跑的是哪一版 */
.build {
  margin: 2px 0 0;
  font-size: 9px;
  letter-spacing: .5px;
  color: #6f7480;
}

/* 真标题图：宽度跟着卡片走，别撑破版面 */
.title__pic {
  display: block;
  width: 100%;
  max-width: 260px;
  height: auto;
  margin: 0 auto 4px;
  border: 1px solid #2a2a33;
  border-radius: 6px;
}

/* 主界面上的操作提示：第一次玩的人（和小孩）不用猜手柄哪颗键是开炮 */
.title__hint {
  margin: 2px 0 0;
  font-size: 10px;
  line-height: 1.5;
  letter-spacing: .5px;
  color: #9aa0a6;
}

.title__btn {
  flex: 0 0 auto;
  width: 168px;
}

/* 封面上的小动画：**只动分组里的子元素**。
   ⚠️ 不能给 .title__tank / .title__foe / .title__eagle 这几个分组写 transform：
      它们身上已经有 transform="translate(x y)" 属性，CSS 的 transform 会把它整个顶掉
       —— 坦克会瞬间跑到画布左上角去。
   ⚠️ 只改 opacity / filter / 子元素零点几像素的位移：不参与布局，也绝不会跑出卡片
       （SVG 根元素默认 overflow:hidden，卡片自己也 overflow:hidden）。 */

/* 履带：两条履带原地轻轻抖一下 */
.title__tank rect:nth-of-type(1),
.title__tank rect:nth-of-type(2) {
  animation: tank-track .7s steps(2, end) infinite alternate;
}

/* 炮口火光：一梭子闪一下，其余时间压暗 */
.title__tank rect:last-of-type {
  animation: tank-fire 1.8s ease-out infinite;
}

/* 敌方坦克：明明灭灭地压过来 */
.title__foe { animation: foe-prowl 2.2s ease-in-out infinite; }

/* 老鹰基地：慢慢「呼吸」，别抢标题 */
.title__eagle { animation: eagle-guard 2.6s ease-in-out infinite; }

@keyframes tank-track {
  0%   { transform: translateY(0); }
  100% { transform: translateY(0.5px); }
}

@keyframes tank-fire {
  0%, 60%, 100% { opacity: .22; }
  66%, 74%      { opacity: 1; }
  70%           { opacity: .55; }
  86%           { opacity: 0; }
}

@keyframes foe-prowl {
  0%, 100% { opacity: 1; }
  50%      { opacity: .72; }
}

@keyframes eagle-guard {
  0%, 100% { opacity: 1; }
  50%      { opacity: .74; }
}

/* 关掉系统动效就一点都不动（前庭敏感的人看着晃会难受） */
@media (prefers-reduced-motion: reduce) {
  .title__tank rect:nth-of-type(1),
  .title__tank rect:nth-of-type(2),
  .title__tank rect:last-of-type,
  .title__foe,
  .title__eagle,
  .stat__value.is-up { animation: none; }
}

/* ---------- 高分榜 / 菜单面板（盖住游戏区的小面板） ---------- */

.scores,
.menu {
  position: absolute;
  inset: 0;
  /* z-index: 8（必须高于 .title / .overlay 的 5，见顶部那一块） */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  text-align: center;
  overflow: hidden;
  background: rgba(5, 7, 5, .94);
  border: 1px solid rgba(193, 98, 43, .30);
}

.scores__title,
.menu__title {
  margin: 0;
  font-size: 15px;
  letter-spacing: 2px;
  color: var(--accent-2);
}

.scores__list {
  width: 100%;
  max-width: 320px;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* 榜单条目由 JS 生成：名字已转义后进 innerHTML */
.score-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 5px 8px;
  font-size: 12px;
  text-align: left;
  background:
    linear-gradient(90deg, rgba(95, 158, 63, .12), rgba(95, 158, 63, 0) 72%),
    var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--green);
  border-radius: 3px;
}

.score-row__rank {
  flex: 0 0 auto;
  width: 16px;
  color: var(--pad-gold);
  font-weight: 700;
}

.score-row__name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;   /* 名字不限长度，太长就省略号 */
}

.score-row__value {
  flex: 0 0 auto;
  font-weight: 700;
  color: var(--accent-2);
}

.score-row__meta {
  flex: 0 0 auto;
  font-size: 9px;
  color: var(--ink-dim);
}

.score-row--empty {
  justify-content: center;
  border-left-color: var(--line);
  color: var(--ink-dim);
}

/* 菜单里的按钮排一列，宽度一致 */
.menu .btn { width: 132px; }

/* ---------- 覆盖层（PAUSED / GAME OVER / STAGE CLEAR） ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;       /* 平时居中 */
  gap: 10px;
  padding: 18px 16px;
  text-align: center;
  overflow: hidden;
  background: rgba(5, 7, 5, .92);
  border: 1px solid rgba(193, 98, 43, .30);
}

/* 正在录名字（手机键盘弹起来）时才改成靠上，不然会被键盘顶掉。
   ⚠️ 不能用 :focus-within —— 按钮被点过之后也一直算「有焦点」，
   下次打开界面就莫名其妙地跑到上面去了（真踩过）。 */
.overlay--typing { justify-content: flex-start; }

.overlay__title {
  margin: 0;
  font-size: 26px;
  letter-spacing: 4px;
  color: var(--accent-2);
  text-shadow: 0 0 12px rgba(193, 98, 43, .55);
}

.overlay--over .overlay__title {
  color: #ff8f7a;
  text-shadow: 0 0 12px rgba(216, 69, 47, .55);
}

.overlay__stats {
  margin: 0;
  font-size: 13px;
  letter-spacing: 1px;
  color: var(--ink);
}

.overlay__tip {
  margin: 0;
  font-size: 12px;
  line-height: 1.7;
  color: var(--ink-dim);
}

/* 上榜录名字 */

.save-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
}

.save-row__input {
  width: 120px;
  min-height: 36px;
  padding: 4px 8px;
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--panel-2);
  border: 2px solid var(--line);
  border-radius: 4px;
  outline: none;
}

.save-row__input::placeholder { color: #6d7866; }

.save-row__input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(193, 98, 43, .22);
}

/* ---------- 按钮 ---------- */

.btn {
  padding: 10px 16px;
  min-height: 42px;
  font-family: inherit;
  font-size: 13px;
  letter-spacing: 1px;
  color: var(--ink);
  background: linear-gradient(180deg, #1e241b, #12160f);
  border: 2px solid var(--line);
  border-radius: 5px;
  box-shadow: 2px 2px 0 var(--shadow);
  cursor: pointer;
}

.btn--small {
  padding: 6px 10px;
  min-height: 34px;
  font-size: 12px;
}

.btn:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--shadow); }
.btn:disabled { opacity: .45; }

.btn--primary {
  color: #1a0f07;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border-color: #8f4519;
  font-weight: 700;
}

.btn--ghost {
  color: var(--ink-dim);
  background: transparent;
  box-shadow: none;
}

/* ---------- 状态修饰 ---------- */

/* 模板里 JS 有时用 class 而不是 hidden 属性收面板；放这里（面板规则之后）才压得住 display:flex */
.is-hidden { display: none; }

/* ---------- 手柄（红白机造型，往「实物」上做） ---------- */

.pad {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 10px 18px;
  border-radius: 14px;
  /* 机身：暗酒红塑料 + 上面的高光/下面的暗部，做出曲面感 */
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .12), rgba(0, 0, 0, .26)),
    linear-gradient(180deg, var(--pad-base), var(--pad-base-2));
  border: 1px solid var(--pad-edge);
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, .30),          /* 内圈暗线 */
    inset 0 0 0 6px rgba(217, 189, 124, .10),    /* 红白机那块金面板的意思，压得很淡 */
    inset 0 1px 0 rgba(255, 255, 255, .22),      /* 顶部高光 */
    inset 0 -3px 6px rgba(0, 0, 0, .35),         /* 底部暗部 */
    0 5px 12px rgba(0, 0, 0, .45);               /* 落在页面上的影子 */
}

/* 十字键：用一整块内联 SVG 画「十」字（两根长条同一填充叠在一起，交接处没有缝）。
   早先用两根各带描边的 div 拼，交接处会露出彼此的边框 —— 看着就是「穿模」 */

.dpad {
  position: relative;
  flex: 0 0 auto;
  width: calc(var(--key) * 3);
  height: calc(var(--keyh) * 3);
  /* 按下时的位移加在这一层，见下面 .dpad.is-* —— 整块一起动，箭头和中心圆点才不会掉队 */
  transition: transform .06s ease-out;
}

.dpad__cross {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* drop-shadow 跟着「两块的并集」走，描边不会跑到十字中间去 */
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .45));
  transition: filter .06s ease-out;
}

/* 按下时整块十字往那个方向「压」一点、并亮一档 —— 真十字键是按下去会翘的。
   ⚠️ 位移挂在 .dpad 这一层，不是挂在 .dpad__cross 上：
      四个小三角（.dpad__btn）和中间的圆点（.dpad__hub）都是它的兄弟节点，
      只动 SVG 的话，箭头和圆点会留在原地不动 —— 看着就是「十字跑了、字没跟上」。
   ⚠️ 不能给按钮本身加背景：那会在十字上盖出一块方角，看着就像穿模。 */
.dpad.is-press .dpad__cross { filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .45)) brightness(1.3); }
.dpad.is-up { transform: translateY(-2%); }
.dpad.is-down { transform: translateY(2%); }
.dpad.is-left { transform: translateX(-2%); }
.dpad.is-right { transform: translateX(2%); }

.dpad__btn {
  position: absolute;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--key);
  height: var(--keyh);
  padding: 0;
  font-family: inherit;
  font-size: calc(var(--keyh) * 0.3);
  line-height: 1;
  color: #9a9aa4;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .6);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  touch-action: none;          /* 按住连发时别触发页面滚动 */
  user-select: none;
  -webkit-user-select: none;
}

.dpad__btn--up { left: var(--key); top: 0; }
.dpad__btn--left { left: 0; top: var(--keyh); }
.dpad__btn--right { left: calc(var(--key) * 2); top: var(--keyh); }
.dpad__btn--down { left: var(--key); top: calc(var(--keyh) * 2); }

.dpad__btn:active { color: #f0f0f4; }

.dpad__hub {
  position: absolute;
  z-index: 2;
  left: var(--key);
  top: var(--keyh);
  width: var(--key);
  height: var(--keyh);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.dpad__hub::before {
  content: '';
  width: 34%;
  height: 34%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #3c3c42, #0c0c0e 75%);
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, .18);
}

/* 中间两颗小胶钮：横着并排，红白机上印的是 SELECT / START */

.pills {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 5px;
}

.pill {
  width: var(--pill-w);
  height: var(--pill-h);
  padding: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 7px;
  letter-spacing: .2px;
  line-height: 1;
  color: #cfcfd6;
  background: linear-gradient(180deg, #3c3c43, #1b1b1f);
  border: 1px solid #0b0b0d;
  border-radius: 11px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .18),
    0 1px 0 #170607;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.pill:active {
  transform: translateY(1px);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, .6);
  background: linear-gradient(180deg, #2b2b31, #141417);
}

.pill:disabled {
  opacity: .55;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, .6);
  background: linear-gradient(180deg, #2b2b31, #141417);
}

/* A / B：两颗暗红圆钮，带一点球面感 */

.abtn {
  flex: 0 0 auto;
  align-self: center;      /* 和十字键的中间对齐，不再吊在顶上 */
  display: flex;
  align-items: center;
  gap: 9px;
}

.abtn__btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  width: var(--ab);
  height: var(--ab);
  padding: 0;
  font-family: inherit;
  color: var(--pad-cream);
  background: radial-gradient(circle at 34% 26%, #e0605f, #94202a 72%);
  border: 1px solid #4d0d13;
  border-radius: 50%;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .28),
    inset 0 -3px 5px rgba(0, 0, 0, .35),
    0 3px 0 #26080b;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.abtn__btn--a { transform: translateY(-7px); }
.abtn__btn--b { transform: translateY(7px); }

.abtn__btn:active {
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, .5);
  background: radial-gradient(circle at 34% 26%, #b6555a, #6d151c 72%);
}

/* 两颗都是「按下去 = 往下沉」，别再一颗往上跑 */
.abtn__btn--a:active { transform: translateY(-2px) scale(.96); }
.abtn__btn--b:active { transform: translateY(12px) scale(.96); }

.abtn__letter {
  font-size: calc(var(--ab) * 0.34);
  font-weight: 700;
  line-height: 1;
}

.abtn__icon {
  font-size: calc(var(--ab) * 0.19);
  line-height: 1;
  opacity: .75;
}

/* ---------- 状态修饰 ---------- */

.is-hidden { display: none; }

/* ---------- 短屏 / 横屏：把按键缩小，别把场地挤没了 ---------- */

@media (max-height: 620px) {
  :root {
    --key: min(46px, 12vw);
    --ab: min(50px, 13vw);
    --pill-w: 34px;
    --pill-h: 19px;
  }
  .pad { padding: 8px 8px 10px; }
  .pill { font-size: 6px; }
}

/* 很窄的手机：再收一档，保证 十字键 + 两个胶钮 + A/B 能并排放下 */
@media (max-width: 350px) {
  :root {
    --key: min(50px, 13.5vw);
    --ab: min(54px, 15vw);
    --pill-w: 36px;
  }
}

@media (min-width: 620px) {
  :root {
    --key: 64px;
    --ab: 70px;
    --pill-w: 46px;
    --pill-h: 24px;
  }
  .battle-app { max-width: 520px; }
  .pill { font-size: 8px; }
}

/* ---------- 坦克大战自己的矮屏 / 窄屏 / 平板微调 ----------
   ⚠️ 上面手柄那三档媒体查询里的 --key / --ab / --pill-* 是调出来的，别动；
      这里只调「坦克大战自己的东西」（封面、按钮、顶栏）。 */

@media (max-height: 620px) {              /* 矮屏 / 横屏：封面与按钮一起收，别把战场挤没 */
  .topbar { min-height: 26px; }
  .icon-btn { width: 26px; height: 26px; font-size: 13px; }
  .title { gap: 6px; padding: 8px; }
  .title__card { max-width: 216px; }
  .title__name { font-size: 18px; letter-spacing: 4px; text-indent: 4px; }
  .title__sub { font-size: 10px; letter-spacing: 1px; }
  .title__btn { width: 148px; }
  .title .btn { min-height: 36px; padding: 7px 12px; font-size: 12px; }
  .overlay { gap: 8px; padding: 12px 14px; }
  .overlay__title { font-size: 22px; letter-spacing: 3px; }
  .scores, .menu { gap: 6px; padding: 10px; }
}

@media (max-width: 350px) {               /* 很窄的手机：顶栏图标再小一点，给状态文字让位 */
  .icon-btn { width: 25px; height: 25px; font-size: 12px; }
  .stat { font-size: 10px; }
  .stat__value { font-size: 14px; }
  .title__card { max-width: 100%; }
  .title__btn { width: 148px; }
}

@media (min-width: 620px) {               /* 平板 / 桌面：封面与榜单放大一档 */
  .title__card { max-width: 380px; }
  .title__name { font-size: 30px; letter-spacing: 8px; text-indent: 8px; }
  .title__sub { font-size: 12px; }
  .title__btn { width: 200px; }
  .scores__list { max-width: 380px; }
  .score-row { font-size: 13px; }
}

/* 横屏矮到家（≤430px 高）：手柄那 190px 一定要留，
   游戏区只剩不到 100px —— 封面这时候必须让位，只留标题 + 两颗按钮，
   否则「开始游戏」会被挤出可视区（flex 列溢出是上下两头一起裁，按钮就点不到了）。 */
@media (max-height: 430px) {
  .title { gap: 3px; padding: 5px; }
  .title__card { display: none; }
  .title__sub { display: none; }
  .title__name { font-size: 16px; line-height: 1.1; letter-spacing: 3px; text-indent: 3px; }
  .title .btn { min-height: 32px; padding: 5px 10px; font-size: 12px; }
  .title__btn { width: 132px; }
  .overlay { gap: 6px; padding: 8px 12px; }
  .overlay__title { font-size: 18px; letter-spacing: 2px; }
  .overlay__stats { font-size: 11px; }
  .overlay__tip { font-size: 11px; line-height: 1.4; }
  .save-row__input { min-height: 30px; }
  .scores__title, .menu__title { font-size: 13px; }
  .score-row { font-size: 11px; padding: 3px 6px; }
}
