/* 钢幕：零号站 — theme tokens 与共享界面组件（按钮 / 面板 / HUD 牌 / 触屏圆钮）。
   外壳美术到位后只在「组件外壳绑定」一节替换，布局与文字层不动。 */
:root {
  --c-bg: #0b0f14;
  --c-steel: #232b34;
  --c-steel-2: #2f3944;
  --c-steel-hi: #5a6673;
  --c-line: #3c4855;
  --c-text: #e8eef4;
  --c-muted: #93a1b0;
  --c-amber: #ffb020;
  --c-amber-dim: #a8700d;
  --c-red: #ff4438;
  --c-ok: #5bd88c;
  --chamfer: 12px;
  --gap: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .55);
  --t-fast: 120ms;
  --t-mid: 220ms;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --u: clamp(12px, 1.9vmin, 20px); /* 界面基准单位 */
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: #000; color: var(--c-text); }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
canvas#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
[hidden] { display: none !important; }

#ui { position: fixed; inset: 0; pointer-events: none; font-size: var(--u); line-height: 1.35; }
.screen { position: absolute; inset: 0; }
#ui button, #ui .panel, #ui .scrim, #title .title-col { pointer-events: auto; }

/* ---------- 共享组件：按钮 ---------- */
/* 外壳：assets/ui_btn_primary.webp（1512×470）九宫格。切片 150/190（含警示端条与切角），
   绘制宽度 18px/23px 不占布局；border-width 给端条与边框留位，文字落在实测内框里。 */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 11em; min-height: 56px; padding: 0 .5em;
  color: var(--c-text); cursor: pointer;
  font-size: 1.1em; letter-spacing: .12em;
  background: none;
  border-style: solid; border-color: transparent; border-width: 11px 28px;
  border-image-source: url("assets/ui_btn_primary.webp");
  border-image-slice: 150 190 150 190 fill;
  border-image-width: 18px 23px;
  border-image-repeat: stretch;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, .5));
  transition: transform var(--t-fast), filter var(--t-fast);
}
.btn > span { display: block; white-space: nowrap; text-shadow: 0 1px 2px rgba(0, 0, 0, .8); }
.btn:hover { filter: drop-shadow(0 3px 5px rgba(0, 0, 0, .5)) brightness(1.22); }
.btn:active, .btn.is-press { transform: translateY(2px) scale(.985); filter: brightness(.85); }
.btn:focus-visible { outline: 2px solid var(--c-amber); outline-offset: 3px; }
.btn[disabled] { filter: grayscale(.9) brightness(.6); cursor: default; }
.btn-ghost { color: var(--c-muted); filter: saturate(.3) brightness(.86); }
.btn-ghost:hover { filter: saturate(.45) brightness(1.08); }
.btn-ghost:active { filter: saturate(.3) brightness(.75); }

/* ---------- 共享组件：面板 / 弹窗 ---------- */
.scrim { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: calc(12px + var(--safe-t)) calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) calc(12px + var(--safe-l));
  background: rgba(4, 7, 10, .72); }
/* 外壳：assets/ui_panel_main.webp（1500×947）九宫格。切片 200/340（角件 + 散热格栅），
   --pk 为绘制比例；border-width = 边框厚度（源图约 103px）× 比例，内容再留白。 */
.panel {
  --pk: .32;
  position: relative; display: flex; flex-direction: column;
  width: min(720px, 100%); max-height: 100%;
  padding: 8px 14px 6px;
  background: none;
  border-style: solid; border-color: transparent; border-width: calc(110px * var(--pk));
  border-image-source: url("assets/ui_panel_main.webp");
  border-image-slice: 200 340 200 340 fill;
  border-image-width: calc(200px * var(--pk)) calc(340px * var(--pk));
  border-image-repeat: stretch;
  filter: drop-shadow(0 12px 22px rgba(0, 0, 0, .6));
}
.panel-title { margin: 0 46px 12px; font-size: 1.7em; letter-spacing: .08em; color: var(--c-text); text-align: center; }
.panel-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; color: var(--c-text); }
.panel-actions { flex: 0 0 auto; display: flex; flex-wrap: wrap; gap: var(--gap); justify-content: center; padding-top: 16px; }
.panel-actions .btn { flex: 1 1 0; min-width: 10em; }
.panel-actions:has(.btn:nth-child(4)) .btn { flex-basis: 40%; }   /* 四个操作排成 2×2，保持等宽 */
.panel-actions:empty { display: none; }
.panel-x { position: absolute; top: 0; right: 6px; width: 44px; height: 44px; border: 0; cursor: pointer;
  background: transparent; color: var(--c-muted); font-size: 28px; line-height: 44px; }
.panel-x:hover { color: var(--c-amber); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 18px; align-items: center; margin: 0; }
.kv dt { color: var(--c-amber); white-space: nowrap; }
.kv dd { margin: 0; color: var(--c-text); }

/* ---------- 共享组件：HUD 牌 ---------- */
.hud-plate {
  position: absolute; display: flex; align-items: center; gap: .6em;
  min-height: 48px; padding: 0 .2em;
  /* 外壳：assets/ui_hud_plate.webp（1490×442）九宫格，切片 190/270/190/280，绘制 19px/27px/19px/28px */
  background: none;
  border-style: solid; border-color: transparent; border-width: 8px 24px 8px 22px;
  border-image-source: url("assets/ui_hud_plate.webp");
  border-image-slice: 190 270 190 280 fill;
  border-image-width: 19px 27px 19px 28px;
  border-image-repeat: stretch;
  font-variant-numeric: tabular-nums;
}
.hud-label { color: var(--c-muted); font-size: .8em; letter-spacing: .1em; white-space: nowrap; }
.hud-val { color: var(--c-text); font-size: 1.1em; min-width: 1.6em; white-space: nowrap; }
.hud-val.big { font-size: 1.5em; line-height: 1.45; min-width: 1.5em; text-align: right; }
.hud-val.dim { color: var(--c-muted); }
.hud-sep { width: 1px; height: 1.2em; background: var(--c-line); margin: 0 .2em; }
.hud-topcol { position: absolute; top: calc(10px + var(--safe-t)); left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px; max-width: 96%; }
.hud-topcol .hud-plate { position: relative; }
.hud-boss .hud-label { color: var(--c-red); }
.bar-boss { width: 14em; }
.bar-boss > i { background: linear-gradient(90deg, var(--c-red), #ff8a6a); }
.hud-combo { min-height: 1.4em; color: var(--c-amber); letter-spacing: .14em; font-size: 1.05em; white-space: nowrap;
  text-shadow: 0 2px 3px rgba(0, 0, 0, .8); font-variant-numeric: tabular-nums; }
.reload-bar { position: absolute; left: 50%; top: calc(50% + 34px); width: 96px; height: 6px; transform: translateX(-50%); }
.reload-bar > i { background: var(--c-amber); transition: none; }
.hud-bl { left: calc(14px + var(--safe-l)); bottom: calc(14px + var(--safe-b)); }
.hud-br { right: calc(14px + var(--safe-r)); bottom: calc(14px + var(--safe-b)); }
/* 武器栏：纯代码切角小牌，当前武器琥珀高亮（键鼠可见；触屏改用切枪键） */
.hud-guns { position: absolute; right: calc(16px + var(--safe-r)); bottom: calc(86px + var(--safe-b)); display: flex; gap: 6px; }
.gun-chip { display: flex; align-items: center; gap: .45em; padding: .22em .7em .22em .3em; font-size: .82em; white-space: nowrap;
  color: var(--c-muted); background: rgba(12, 17, 22, .72); border-left: 3px solid var(--c-line);
  clip-path: polygon(0 0, calc(100% - 7px) 0, 100% 7px, 100% 100%, 0 100%); transition: color var(--t-fast), background var(--t-fast); }
.gun-chip i { font-style: normal; min-width: 1.5em; text-align: center; color: var(--c-text); background: rgba(255, 255, 255, .08); font-variant-numeric: tabular-nums; }
.gun-chip.on { color: var(--c-text); background: rgba(40, 30, 8, .82); border-left-color: var(--c-amber); }
.gun-chip.on i { color: #14100a; background: var(--c-amber); }
body.is-touch .hud-guns { display: none; }
.bar { position: relative; width: 9em; height: .7em; background: rgba(0, 0, 0, .55); border: 1px solid var(--c-line); overflow: hidden; }
.bar > i { position: absolute; inset: 0; transform-origin: left center; background: linear-gradient(90deg, var(--c-ok), #b8f0a0); transition: transform var(--t-mid); }
.bar.low > i { background: linear-gradient(90deg, var(--c-red), #ff8a6a); }
.hud-tip { position: absolute; left: 50%; top: 36%; transform: translateX(-50%); max-width: 86%; text-align: center;
  padding: .4em 1em; color: var(--c-text); background: rgba(8, 12, 16, .6); border-left: 3px solid var(--c-amber);
  opacity: 0; transition: opacity var(--t-mid); }
.hud-tip.show { opacity: 1; }

/* 准星与受击暗角：纯代码 */
#crosshair { position: absolute; left: 50%; top: 50%; width: 0; height: 0; --spread: 7px; }
#crosshair i { position: absolute; background: var(--c-text); box-shadow: 0 0 2px #000; }
#crosshair i:nth-child(1) { width: 2px; height: 9px; left: -1px; top: calc(-9px - var(--spread)); }
#crosshair i:nth-child(2) { width: 2px; height: 9px; left: -1px; top: var(--spread); }
#crosshair i:nth-child(3) { height: 2px; width: 9px; top: -1px; left: calc(-9px - var(--spread)); }
#crosshair i:nth-child(4) { height: 2px; width: 9px; top: -1px; left: var(--spread); }
#crosshair b { position: absolute; left: -1.5px; top: -1.5px; width: 3px; height: 3px; background: var(--c-amber); }
#crosshair u { position: absolute; left: -12px; top: -12px; width: 24px; height: 24px; opacity: 0; transition: opacity 90ms; }
#crosshair u::before, #crosshair u::after { content: ''; position: absolute; left: 11px; top: -2px; width: 2px; height: 28px;
  background: var(--c-text); box-shadow: 0 0 2px #000; transform: rotate(45deg); }
#crosshair u::after { transform: rotate(-45deg); }
#crosshair.hit u { opacity: 1; }
#crosshair.kill u::before, #crosshair.kill u::after { background: var(--c-red); }
.scrim-fx { position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(255, 40, 30, .55) 100%); transition: opacity 260ms; }

/* ---------- 共享组件：触屏圆钮与摇杆 ---------- */
.tbtn { position: absolute; width: 60px; height: 60px; border-radius: 50%; border: 0;
  background: url("assets/ui_touch_round.webp") center / contain no-repeat;   /* 外壳按 contain 摆放，图标在中心圆盘 */
  color: var(--c-text); display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; touch-action: none;
  opacity: .92; transition: transform var(--t-fast), filter var(--t-fast); }
.tbtn svg { width: 40%; height: 40%; display: block; }
.tbtn:hover { filter: brightness(1.2); }
.tbtn:active, .tbtn.is-held { color: var(--c-amber); transform: scale(.93); filter: brightness(1.3); opacity: 1; }
.tbtn-fire { width: 84px; height: 84px; right: calc(26px + var(--safe-r)); bottom: calc(92px + var(--safe-b)); color: var(--c-amber); }
.tbtn-jump { right: calc(124px + var(--safe-r)); bottom: calc(72px + var(--safe-b)); }
.tbtn-reload { right: calc(104px + var(--safe-r)); bottom: calc(150px + var(--safe-b)); }
.tbtn-swap { width: 56px; height: 56px; right: calc(40px + var(--safe-r)); bottom: calc(186px + var(--safe-b)); }
.tbtn-sprint { left: calc(170px + var(--safe-l)); bottom: calc(96px + var(--safe-b)); }
.tbtn-pause { width: 46px; height: 46px; right: calc(12px + var(--safe-r)); top: calc(10px + var(--safe-t)); }
#stick { position: absolute; left: calc(24px + var(--safe-l)); bottom: calc(72px + var(--safe-b)); width: 132px; height: 132px; border-radius: 50%;
  border: 2px solid rgba(140, 155, 170, .55); background: rgba(14, 20, 26, .35); pointer-events: auto; touch-action: none; }
#stick-knob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #6c7a88, #2a333d); border: 2px solid var(--c-amber-dim); }
/* 触屏时 HUD 牌上移，给摇杆与按钮留位 */
body.is-touch .hud-bl { bottom: auto; top: calc(10px + var(--safe-t)); left: calc(14px + var(--safe-l)); }
body.is-touch .hud-br { bottom: auto; top: calc(64px + var(--safe-t)); right: calc(12px + var(--safe-r)); }
body.is-touch .hud-top { font-size: .9em; }
body.is-touch .hud-bl .bar { width: 6em; }

/* ---------- 弹窗内容：强化卡、结算数据 ---------- */
#ui button { font-family: inherit; }
.lead { margin: 0 0 12px; color: var(--c-muted); text-align: center; }
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--gap); }
/* 强化卡：面板外壳的小尺寸实例（同一张图，绘制比例 .15） */
.card { --pk: .15; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center;
  min-height: 124px; padding: 6px 4px; cursor: pointer; font-size: 1em; color: var(--c-text);
  background: none;
  border-style: solid; border-color: transparent; border-width: calc(125px * var(--pk));
  border-image-source: url("assets/ui_panel_main.webp");
  border-image-slice: 200 340 200 340 fill;
  border-image-width: calc(200px * var(--pk)) calc(340px * var(--pk));
  border-image-repeat: stretch;
  filter: brightness(1.35);
  transition: transform var(--t-fast), filter var(--t-fast); }
.card b { font-weight: inherit; font-size: 1.2em; color: var(--c-amber); letter-spacing: .06em; }
.card span { color: var(--c-text); }
.card:hover { filter: brightness(1.7); }
.card:active { transform: translateY(2px) scale(.985); filter: brightness(1.1); }
.card:focus-visible { outline: 2px solid var(--c-amber); outline-offset: 2px; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 14px; }
.stat { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: .45em .8em;
  background: rgba(0, 0, 0, .28); border-left: 3px solid var(--c-line); font-variant-numeric: tabular-nums; }
.stat span { color: var(--c-muted); }
.stat b { font-weight: inherit; font-size: 1.15em; white-space: nowrap; }
.stat.hi { border-left-color: var(--c-amber); }
.stat.hi b { color: var(--c-amber); }
.note { margin: 10px 0 0; color: var(--c-red); }
.note:empty { display: none; }

/* ---------- 标题页：左侧菜单列（约 38% 宽），右侧留给主视觉 ---------- */
#title { background:
    linear-gradient(90deg, rgba(6, 9, 12, .94) 0%, rgba(6, 9, 12, .72) 38%, rgba(6, 9, 12, .12) 70%, rgba(6, 9, 12, 0) 100%); }
.title-col { position: absolute; left: calc(5vw + var(--safe-l)); top: 50%; transform: translateY(-50%);
  width: min(38vw, 520px); min-width: 260px; display: flex; flex-direction: column; gap: 14px; }
.title-kicker { color: var(--c-amber); letter-spacing: .3em; font-size: .85em; }
.title-name { margin: 0; font-size: clamp(34px, 7vmin, 76px); line-height: 1.3; letter-spacing: .04em; text-shadow: 0 4px 0 rgba(0, 0, 0, .5); }
.title-brief { margin: 0; color: var(--c-muted); }
.title-actions { display: flex; flex-direction: column; align-items: flex-start; gap: var(--gap); margin-top: 8px; }
.title-best { color: var(--c-muted); font-size: .9em; }
.title-best b { color: var(--c-amber); font-weight: inherit; font-variant-numeric: tabular-nums; }

/* ---------- 加载 ---------- */
.boot { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: var(--c-bg); pointer-events: auto; }
.boot-name { font-size: clamp(28px, 6vmin, 56px); letter-spacing: .06em; }
.boot-msg { color: var(--c-muted); }
.boot-bar { width: min(60vw, 320px); }
.boot-bar > i { background: linear-gradient(90deg, var(--c-amber-dim), var(--c-amber)); transform: scaleX(0); }

/* ---------- 窄屏 / 竖屏 ---------- */
@media (max-aspect-ratio: 1/1) {
  #title { background: linear-gradient(0deg, rgba(6, 9, 12, .95) 0%, rgba(6, 9, 12, .7) 46%, rgba(6, 9, 12, .1) 80%); }
  .title-col { left: 50%; top: auto; bottom: calc(8vh + var(--safe-b)); transform: translateX(-50%); width: min(86vw, 420px); }
  .title-actions { align-items: stretch; }
  .hud-top { font-size: .82em; gap: .4em; padding: .4em .7em; }
  body.is-touch .hud-topcol { top: calc(64px + var(--safe-t)); }
  body.is-touch .hud-br { top: calc(118px + var(--safe-t)); }
  .bar-boss { width: 6em; }
  .cards { grid-template-columns: 1fr; }
  .card { min-height: 72px; flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
  .stats { grid-template-columns: 1fr; }
  .panel-actions { flex-direction: column; flex-wrap: nowrap; }
  .panel-actions .btn { flex: none; width: 100%; }
}
@media (max-width: 520px), (max-height: 420px) {
  .panel { --pk: .22; padding: 4px 8px 4px; }
  .panel-title { font-size: 1.35em; margin-bottom: 6px; }
  .panel-actions { padding-top: 10px; gap: 8px; }
}
@media (max-height: 420px) {
  .btn { min-height: 46px; border-width: 8px 26px; border-image-width: 15px 19px; }
  .title-col { gap: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .btn, .card, .tbtn { transition: none; }
}

/* 自检面板（仅自检入口使用） */
#selftest { position: fixed; left: 6px; top: 6px; z-index: 50; max-width: min(430px, 96vw); padding: 6px 8px; pointer-events: none;
  font: 11px/1.35 var(--yoroll-font-body), ui-monospace, Menlo, Consolas, monospace; color: #dfe; background: rgba(0, 0, 0, .78); border-left: 3px solid var(--c-amber); white-space: pre-wrap; }
#selftest .bad { color: #ff7a6e; }
#selftest .pend { color: #ffcf6a; }
