:root {
  --bg: #0f141c;
  --panel: rgba(18, 24, 34, 0.94);
  --panel2: #1a2230;
  --line: rgba(255, 255, 255, 0.1);
  --text: #eef2f7;
  --dim: #94a0b3;
  --accent: #ff7a2f;
  --accent2: #ffd166;
  --mint: #4dffb5;
  --bad: #ff5a6a;
  --font: -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", "Segoe UI", sans-serif;
  --num: "Segoe UI", "SF Pro Display", Roboto, var(--font);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; overscroll-behavior: none; }
body { touch-action: none; user-select: none; -webkit-user-select: none; }
button { font-family: inherit; color: inherit; cursor: pointer; }
input, select { font-family: inherit; }
.hidden { display: none !important; }
#app { position: fixed; inset: 0; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- 加载 ---------- */
#loading { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--bg); z-index: 50; gap: 14px; color: var(--dim); }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid rgba(255,255,255,0.1); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 通用浮层 ---------- */
.overlay { position: absolute; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); background: radial-gradient(ellipse at 30% 20%, rgba(255,122,47,0.12), transparent 55%), rgba(8, 11, 16, 0.78); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.panel { background: var(--panel); border: 1px solid var(--line); clip-path: polygon(0 0, calc(100% - 18px) 0, 100% 18px, 100% 100%, 18px 100%, 0 calc(100% - 18px)); padding: 20px 22px; width: min(520px, 100%); max-height: 100%; display: flex; flex-direction: column; gap: 12px; }
.panel.wide { width: min(880px, 100%); height: min(640px, 100%); }
.panel.small { width: min(340px, 100%); }
.panel h2 { margin: 0; font-size: 20px; letter-spacing: 1px; }
.panelHead { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.close { background: var(--accent); border: 0; color: #1a0e05; font-weight: 700; padding: 8px 18px; clip-path: polygon(8px 0, 100% 0, calc(100% - 8px) 100%, 0 100%); }
.btn { background: var(--panel2); border: 1px solid var(--line); padding: 11px 18px; font-size: 15px; font-weight: 600; letter-spacing: 1px; clip-path: polygon(8px 0, 100% 0, calc(100% - 8px) 100%, 0 100%); transition: background .15s; }
.btn:hover { background: #253046; }
.btn.primary { background: var(--accent); color: #1a0e05; border-color: transparent; }
.btn.primary:hover { background: #ff9150; }
.btn.ghost { background: transparent; }
.fine { color: var(--dim); font-size: 12px; line-height: 1.6; margin: 0; }

/* ---------- 开始界面 ---------- */
#menu { overflow-y: auto; align-items: flex-start; }
.menuInner { width: min(980px, 100%); margin: auto; display: flex; flex-direction: column; gap: 22px; padding: 10px 0; }
.brand { display: flex; align-items: center; gap: 16px; }
.brand h1 { margin: 0; font-size: clamp(24px, 4vw, 40px); letter-spacing: 3px; }
.brand p { margin: 6px 0 0; color: var(--dim); font-size: 14px; }
.logo { width: 58px; height: 58px; flex: none; background: var(--accent); clip-path: polygon(20% 0, 100% 0, 100% 80%, 80% 100%, 0 100%, 0 20%); position: relative; }
.logo span { position: absolute; inset: 14px; border-radius: 50%; background: #1a0e05; box-shadow: inset 0 0 0 6px var(--accent2); }
.modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.modeCard { text-align: left; background: linear-gradient(160deg, #1d2636, #131a25); border: 1px solid var(--line); padding: 18px 16px 20px; min-height: 170px; position: relative; clip-path: polygon(0 0, calc(100% - 16px) 0, 100% 16px, 100% 100%, 0 100%); transition: transform .15s, border-color .15s; }
.modeCard:hover { transform: translateY(-3px); border-color: var(--accent); }
.modeCard i { font-style: normal; font-family: var(--num); font-weight: 800; color: var(--accent); font-size: 14px; letter-spacing: 2px; }
.modeCard h2 { margin: 8px 0 8px; font-size: 20px; }
.modeCard p { margin: 0; color: var(--dim); font-size: 13px; line-height: 1.6; }
.modeCard::after { content: ""; position: absolute; left: 16px; bottom: 0; width: 40px; height: 3px; background: var(--accent); }
.menuRow { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 13; }
#modeTag { position: absolute; top: max(12px, env(safe-area-inset-top)); left: max(14px, env(safe-area-inset-left)); display: flex; align-items: baseline; gap: 10px; background: rgba(10,14,20,0.6); padding: 6px 12px; border-left: 3px solid var(--accent); font-weight: 700; font-size: 14px; }
#modeSub { color: var(--dim); font-weight: 500; font-size: 12px; }
#fps { position: absolute; top: max(12px, env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right)); font-family: var(--num); font-size: 12px; color: var(--dim); background: rgba(10,14,20,0.5); padding: 4px 8px; }
#crosshair { position: absolute; left: 50%; top: 50%; width: 160px; height: 160px; transform: translate(-50%, -50%); image-rendering: pixelated; }
#hitmarker { position: absolute; left: 50%; top: 50%; width: 26px; height: 26px; transform: translate(-50%, -50%) rotate(45deg); opacity: 0; }
#hitmarker::before, #hitmarker::after { content: ""; position: absolute; background: #fff; }
#hitmarker::before { left: 12px; top: 0; width: 2px; height: 26px; clip-path: polygon(0 0, 100% 0, 100% 35%, 0 35%, 0 65%, 100% 65%, 100% 100%, 0 100%); }
#hitmarker::after { top: 12px; left: 0; height: 2px; width: 26px; clip-path: polygon(0 0, 35% 0, 35% 100%, 0 100%, 0 0, 65% 0, 100% 0, 100% 100%, 65% 100%); }
#hitmarker.show { animation: hm .25s ease-out; }
#hitmarker.head::before, #hitmarker.head::after { background: var(--bad); }
@keyframes hm { 0% { opacity: 1; transform: translate(-50%, -50%) rotate(45deg) scale(1.3); } 100% { opacity: 0; transform: translate(-50%, -50%) rotate(45deg) scale(1); } }
#toast { position: absolute; left: 50%; top: 62%; transform: translateX(-50%); background: rgba(10,14,20,0.75); padding: 8px 16px; font-size: 15px; font-weight: 600; opacity: 0; transition: opacity .2s; white-space: nowrap; border-bottom: 2px solid var(--accent); }
#toast.on { opacity: 1; }
#toast.good { border-color: var(--mint); }
#toast.bad { border-color: var(--bad); }
#statBar { position: absolute; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; gap: 4px; }
.stat { background: rgba(10,14,20,0.62); padding: 6px 12px 5px; min-width: 76px; text-align: center; display: flex; flex-direction: column; }
.stat b { font-family: var(--num); font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat small { color: var(--dim); font-size: 11px; }
.pips { justify-content: flex-end; }
#satchelPips { display: flex; gap: 5px; justify-content: center; height: 24px; align-items: center; }
#satchelPips i { width: 14px; height: 14px; background: var(--accent); clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
#satchelPips i.used { background: rgba(255,255,255,0.18); }
#satchelPips i.live { background: var(--accent2); animation: blink .5s infinite alternate; }
@keyframes blink { to { opacity: 0.45; } }
#weaponBox { position: absolute; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); background: rgba(10,14,20,0.62); padding: 8px 14px; display: flex; gap: 12px; align-items: baseline; border-right: 3px solid var(--accent); }
#weaponBox b { font-size: 15px; }
#wpAmmo { font-family: var(--num); font-size: 22px; font-weight: 700; }
#trainPanel { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); background: rgba(10,14,20,0.72); padding: 10px 14px; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: auto; max-width: min(640px, 70vw); border-top: 2px solid var(--accent); }
#trainPanel .tpTitle { font-weight: 700; font-size: 14px; text-align: center; }
#trainPanel .tpTip { color: var(--dim); font-size: 12px; text-align: center; }
.predRow { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.predRow button { background: var(--panel2); border: 1px solid var(--line); padding: 6px 10px; font-size: 13px; min-width: 64px; }
.predRow button.on { background: var(--accent); color: #1a0e05; border-color: transparent; font-weight: 700; }
.predRow button kbd { font-family: var(--num); font-size: 10px; opacity: 0.7; margin-left: 4px; }
.tpRow { display: flex; gap: 8px; align-items: center; }
.tpRow button { background: var(--panel2); border: 1px solid var(--line); padding: 5px 10px; font-size: 12px; }
#resultCard { position: absolute; right: max(16px, env(safe-area-inset-right)); top: 70px; width: 230px; background: var(--panel); border: 1px solid var(--line); padding: 12px 14px; clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 0 100%); }
#resultCard h3 { margin: 0 0 8px; font-size: 14px; color: var(--accent2); }
#resultCard .row { display: flex; justify-content: space-between; font-size: 13px; padding: 3px 0; border-bottom: 1px dashed rgba(255,255,255,0.06); }
#resultCard .row b { font-family: var(--num); }
#resultCard .tip { margin-top: 8px; font-size: 12px; color: var(--dim); line-height: 1.55; }
#resultCard .ok { color: var(--mint); }
#resultCard .no { color: var(--bad); }
#observerWrap { position: absolute; left: max(14px, env(safe-area-inset-left)); bottom: 84px; width: 230px; background: var(--panel); border: 1px solid var(--line); padding: 8px; }
.obsHead { font-size: 12px; font-weight: 700; margin-bottom: 6px; }
.obsHead small { color: var(--dim); font-weight: 400; }
#observer { width: 214px; height: 214px; display: block; background: #0b1017; }
#obsInfo { font-size: 11px; color: var(--dim); margin-top: 6px; line-height: 1.6; font-family: var(--num); }
#replayBar { position: absolute; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line); padding: 8px 10px; display: flex; gap: 6px; align-items: center; pointer-events: auto; flex-wrap: wrap; justify-content: center; width: min(640px, 94vw); }
.rpTitle { font-weight: 700; font-size: 13px; color: var(--accent2); margin-right: 4px; }
#replayBar button { background: var(--panel2); border: 1px solid var(--line); padding: 6px 10px; font-size: 13px; min-width: 40px; }
#rpSeek { flex: 1; min-width: 120px; accent-color: var(--accent); }
#rpInfo { width: 100%; text-align: center; font-size: 11px; color: var(--dim); }
#pointerHint { position: absolute; left: 50%; top: 40%; transform: translateX(-50%); background: rgba(10,14,20,0.8); padding: 10px 18px; font-size: 14px; }

/* ---------- 触屏按钮 ---------- */
#touch { position: absolute; inset: 0; z-index: 12; pointer-events: none; }
.tb { position: absolute; transform: translate(-50%, -50%); border-radius: 50%; background: rgba(20, 28, 40, 0.55); border: 2px solid rgba(255,255,255,0.35); color: #fff; font-size: 14px; font-weight: 700; display: flex; align-items: center; justify-content: center; pointer-events: auto; touch-action: none; text-shadow: 0 1px 2px #000; }
.tb.on { background: rgba(255,122,47,0.75); border-color: var(--accent2); }
.tb.big { font-size: 17px; }
.tb.fire { background: rgba(255,90,60,0.4); }
.tb.satchel { background: rgba(255,122,47,0.45); }
.tb.small { font-size: 12px; }
.tb.stick { background: rgba(255,255,255,0.06); border: 2px dashed rgba(255,255,255,0.2); }
.tb.stick .knob { position: absolute; left: 50%; top: 50%; width: 40%; height: 40%; transform: translate(-50%, -50%); border-radius: 50%; background: rgba(255,255,255,0.45); border: 2px solid rgba(255,255,255,0.7); }
.tb.stick .ring { position: absolute; inset: 18%; border-radius: 50%; border: 1px solid rgba(255,255,255,0.15); }
.tb.stick.run .knob { background: rgba(255,122,47,0.85); }
#touch.editing .tb { border-style: dashed; border-color: var(--accent2); }
#touch.editing .tb.sel { box-shadow: 0 0 0 3px var(--mint); }

#layoutEditor { position: absolute; left: 0; right: 0; top: 0; z-index: 40; display: flex; justify-content: center; pointer-events: none; }
#leBar { pointer-events: auto; margin-top: max(8px, env(safe-area-inset-top)); background: var(--panel); border: 1px solid var(--line); padding: 8px 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; font-size: 13px; max-width: 96vw; }
#leBar .btn { padding: 6px 12px; font-size: 13px; }
#leSize { accent-color: var(--accent); }

#rotateHint { position: absolute; inset: 0; z-index: 60; background: rgba(8,11,16,0.92); display: flex; align-items: center; justify-content: center; text-align: center; font-size: 18px; line-height: 1.8; }
#rotateHint small { color: var(--dim); font-size: 13px; }

/* ---------- 设置 ---------- */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.tabs button { background: transparent; border: 0; padding: 8px 14px; font-size: 14px; color: var(--dim); font-weight: 600; }
.tabs button.on { color: var(--text); box-shadow: inset 0 -3px 0 var(--accent); }
.tabBody { overflow-y: auto; flex: 1; padding-right: 6px; }
.tabBody::-webkit-scrollbar, .helpBody::-webkit-scrollbar { width: 6px; }
.tabBody::-webkit-scrollbar-thumb, .helpBody::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); }
.field { display: grid; grid-template-columns: 150px 1fr 70px; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.05); font-size: 14px; }
.field.two { grid-template-columns: 150px 1fr; }
.field input[type=range] { width: 100%; accent-color: var(--accent); }
.field input[type=number], .field input[type=text], .field select { background: #0d131c; border: 1px solid var(--line); color: var(--text); padding: 6px 8px; width: 100%; font-size: 13px; }
.field .val { font-family: var(--num); font-variant-numeric: tabular-nums; text-align: right; color: var(--accent2); }
.field small { color: var(--dim); font-size: 12px; }
.seg { display: flex; gap: 4px; flex-wrap: wrap; }
.seg button { background: #0d131c; border: 1px solid var(--line); padding: 6px 12px; font-size: 13px; }
.seg button.on { background: var(--accent); color: #1a0e05; border-color: transparent; font-weight: 700; }
.switch { width: 44px; height: 24px; border-radius: 12px; background: #2b3444; border: 0; position: relative; }
.switch::after { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: #c8d0dc; transition: left .15s; }
.switch.on { background: var(--accent); }
.switch.on::after { left: 23px; background: #fff; }
.secTitle { font-size: 13px; color: var(--accent2); margin: 16px 0 4px; letter-spacing: 1px; }
.note { color: var(--dim); font-size: 12px; line-height: 1.6; margin: 6px 0; }
.bindTable { width: 100%; border-collapse: collapse; font-size: 14px; }
.bindTable td { padding: 5px 4px; border-bottom: 1px solid rgba(255,255,255,0.05); }
.bindTable td:first-child { color: var(--text); }
.bindBtn { width: 100%; background: #0d131c; border: 1px solid var(--line); padding: 7px 8px; font-size: 13px; min-height: 32px; }
.bindBtn.wait { border-color: var(--accent); color: var(--accent2); animation: blink .5s infinite alternate; }
.bindBtn.conflict { border-color: var(--bad); }
.xhWrap { display: grid; grid-template-columns: 220px 1fr; gap: 16px; }
.xhPreview { background: linear-gradient(135deg, #3a4b5e, #84909c 50%, #c9b79c); height: 160px; display: flex; align-items: center; justify-content: center; position: sticky; top: 0; }
.xhPreview canvas { width: 160px; height: 160px; image-rendering: pixelated; }
.codeRow { display: flex; gap: 6px; margin-top: 8px; }
.codeRow input { flex: 1; background: #0d131c; border: 1px solid var(--line); color: var(--text); padding: 6px 8px; font-size: 12px; min-width: 0; }
.codeRow button { background: var(--panel2); border: 1px solid var(--line); padding: 6px 10px; font-size: 12px; }
.confirm { position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.5); }
.confirm .panel { width: min(380px, 92vw); }
.confirm .btns { display: flex; gap: 8px; justify-content: flex-end; }
.helpBody { overflow-y: auto; font-size: 14px; line-height: 1.7; color: #d9e0ea; }
.helpBody h3 { font-size: 14px; color: var(--accent2); margin: 14px 0 6px; }
.helpBody table { border-collapse: collapse; width: 100%; }
.helpBody td { padding: 4px 6px; border-bottom: 1px solid rgba(255,255,255,0.05); }
.helpBody kbd { background: #0d131c; border: 1px solid var(--line); padding: 1px 6px; font-family: var(--num); font-size: 12px; }

@media (max-width: 820px) {
  .modes { grid-template-columns: repeat(2, 1fr); }
  .modeCard { min-height: 120px; padding: 14px 12px; }
  .modeCard h2 { font-size: 17px; }
  .field { grid-template-columns: 110px 1fr 56px; font-size: 13px; }
  .field.two { grid-template-columns: 110px 1fr; }
  .xhWrap { grid-template-columns: 1fr; }
  .xhPreview { position: static; height: 120px; }
}
@media (max-height: 500px) {
  .menuInner { gap: 12px; }
  .brand p { display: none; }
  .modeCard { min-height: 96px; }
  .modeCard p { font-size: 12px; line-height: 1.45; }
  .panel.wide { height: 100%; }
  .stat { min-width: 60px; padding: 3px 8px; }
  .stat b { font-size: 16px; }
  #observerWrap { width: 160px; bottom: auto; top: 52px; }
  #observer { width: 144px; height: 144px; }
  #resultCard { top: 52px; width: 200px; font-size: 12px; }
  #replayBar { bottom: 60px; }
}
body.touchMode #statBar { bottom: max(4px, env(safe-area-inset-bottom)); }
body.touchMode #weaponBox { display: none; }

body.touchMode #fps { right: 80px; }
body.touchMode #modeSub { display: none; }
body.touchMode #trainPanel { top: 58px; padding: 6px 10px; gap: 5px; }
body.touchMode #trainPanel .tpTitle { font-size: 12px; }
body.touchMode #trainPanel .tpTip { display: none; }
body.touchMode #observerWrap { top: 58px; bottom: auto; width: 160px; }
body.touchMode #observer { width: 144px; height: 144px; }
body.touchMode #resultCard { top: auto; bottom: 62px; left: 50%; right: auto; transform: translateX(-50%); width: min(46vw, 360px); display: grid; grid-template-columns: 1fr 1fr; column-gap: 14px; padding: 7px 10px; clip-path: none; opacity: 0.94; }
body.touchMode #resultCard h3 { grid-column: 1 / -1; margin: 0 0 3px; font-size: 12px; }
body.touchMode #resultCard .row { font-size: 11px; padding: 2px 0; }
body.touchMode #resultCard .tip { display: none; }
body.touchMode #replayBar { bottom: 12px; }
@media (max-height: 500px) {
  .modes { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .modeCard { min-height: 0; padding: 10px 10px 14px; }
  .modeCard h2 { font-size: 15px; margin: 4px 0; }
  .modeCard p { font-size: 11px; }
  .brand h1 { font-size: 22px; }
  .logo { width: 40px; height: 40px; }
  .logo span { inset: 10px; box-shadow: inset 0 0 0 4px var(--accent2); }
  .menuRow .btn { padding: 8px 14px; font-size: 13px; }
}
/* 面板里允许手指上下滑动 */
#menu, .tabBody, .helpBody, .panel { touch-action: pan-y; }
input[type=range] { touch-action: pan-x; }
body.touchMode .predRow kbd { display: none; }
