/* ============================================================
 * 《回声·声呐潜行》- 游戏化 UI（声呐雷达 HUD 风）
 * 设计语言：切角面板 / 发光描边 / 扫描线 / 雷达盘
 * ============================================================ */
:root {
  --bg: #03070d;
  --panel: rgba(7, 18, 30, 0.92);
  --line: rgba(46, 230, 200, 0.28);
  --teal: #2ee6c8;
  --cyan: #3fd8ff;
  --gold: #f0c060;
  --red: #e05656;
  --text: #cfe6f2;
  --dim: #7e9cb2;
  --cut: 14px;                       /* 切角尺寸 */
}

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

html, body {
  width: 100%; height: 100%;
  background: #01040a;
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  user-select: none;
}

#stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: #02060b;
  overflow: hidden;
}

/* 画布全屏铺满：世界内容在 canvas 内部做居中缩放 */
#cv-wrap { position: absolute; inset: 0; }
#game { display: block; width: 100%; height: 100%; }

.layer { position: absolute; inset: 0; pointer-events: none; }
.hidden { display: none !important; }

/* ---------------- 全局氛围 ---------------- */
#fx-scan {
  position: absolute; inset: 0; z-index: 60; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(180, 255, 240, 0.022) 0 1px, transparent 1px 3px);
  mix-blend-mode: screen;
}
#fx-vignette {
  position: absolute; inset: 0; z-index: 59; pointer-events: none;
  background: radial-gradient(ellipse at 50% 42%, transparent 58%, rgba(1, 4, 9, 0.55) 100%);
}

/* ---------------- HUD ---------------- */
#hud { z-index: 5; }
#hud::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 64px;
  background: linear-gradient(180deg, rgba(2, 8, 15, 0.88), rgba(2, 8, 15, 0));
}

.hud-left {
  position: absolute; top: calc(10px + env(safe-area-inset-top, 0px)); left: 10px;
  display: flex; align-items: center; gap: 8px;
}
.ship-badge {
  width: 42px; height: 42px; padding: 6px;
  background: rgba(5, 16, 26, 0.85);
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
  filter: drop-shadow(0 0 6px rgba(63, 216, 255, 0.35));
}
.ship-badge img { width: 100%; height: 100%; object-fit: contain; }
.ship-badge img.danger { animation: hpblink 0.6s steps(2) infinite; }
@keyframes hpblink { 50% { opacity: 0.35; } }

.hp-pips { display: flex; flex-direction: column; gap: 4px; }
.hp-pips i {
  width: 34px; height: 8px;
  clip-path: polygon(4px 0, 100% 0, calc(100% - 4px) 100%, 0 100%);
  background: rgba(46, 230, 200, 0.85);
  box-shadow: 0 0 8px rgba(46, 230, 200, 0.6);
  transition: background 0.25s, box-shadow 0.25s;
}
.hp-pips i.off { background: rgba(70, 96, 110, 0.35); box-shadow: none; }

.hud-mid {
  position: absolute; top: calc(12px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%);
}
.plaque {
  padding: 5px 18px;
  background: linear-gradient(90deg, rgba(8, 26, 38, 0.4), rgba(10, 34, 46, 0.85) 30%, rgba(10, 34, 46, 0.85) 70%, rgba(8, 26, 38, 0.4));
  clip-path: polygon(10px 0, calc(100% - 10px) 0, 100% 100%, 0 100%);
  border-bottom: 1px solid rgba(46, 230, 200, 0.4);
  font-size: 12px; letter-spacing: 1.5px; color: var(--teal);
  text-shadow: 0 0 10px rgba(46, 230, 200, 0.5);
  white-space: nowrap;
}

.hud-right {
  position: absolute; top: calc(10px + env(safe-area-inset-top, 0px)); right: 10px;
  display: flex; flex-direction: column; gap: 6px; align-items: flex-end;
}
.chip {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 12px 4px 9px;
  background: rgba(5, 16, 26, 0.85);
  clip-path: polygon(7px 0, 100% 0, 100% 100%, 0 100%, 0 7px);
  font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.chip.gold { color: var(--gold); text-shadow: 0 0 8px rgba(240, 192, 96, 0.6); }
.chip.cyan { color: var(--cyan); text-shadow: 0 0 8px rgba(63, 216, 255, 0.6); }

.ico { width: 10px; height: 10px; transform: rotate(45deg); display: inline-block; }
.ico.shard { background: var(--gold); box-shadow: 0 0 8px var(--gold); }
.ico.sonar { border-radius: 50%; background: var(--cyan); box-shadow: 0 0 8px var(--cyan); transform: none; }

/* ---------------- 操作台（悬浮叠加在游戏画面内） ---------------- */
#controls {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: 0 14px calc(14px + env(safe-area-inset-bottom, 0px));
  pointer-events: none;
}
#controls > * { pointer-events: auto; }
.ctl-left { display: flex; flex-direction: column; gap: 10px; }

/* 功能键：悬浮切角按键（半透明 + 毛玻璃，融入画面） */
.keybtn {
  width: 48px; height: 48px;
  position: relative; border: none; cursor: pointer;
  background: rgba(10, 26, 40, 0.66);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  transition: filter 0.15s;
}
.keybtn::before {
  content: ""; position: absolute; inset: 1px;
  background: rgba(12, 33, 48, 0.5);
  clip-path: polygon(9px 0, 100% 0, 100% calc(100% - 9px), calc(100% - 9px) 100%, 0 100%, 0 9px);
}
.keybtn .k { position: relative; font-size: 16px; color: var(--teal); text-shadow: 0 0 10px rgba(46, 230, 200, 0.7); line-height: 1; }
.keybtn .t { position: relative; font-size: 8px; letter-spacing: 2px; color: var(--dim); }
.keybtn:active { filter: drop-shadow(0 0 10px rgba(46, 230, 200, 0.6)) brightness(1.3); }

/* 声呐雷达盘 */
#sonar-wrap { position: relative; width: 104px; height: 104px; }
#sonar-wrap .sweep {
  position: absolute; inset: -6px; border-radius: 50%;
  background: conic-gradient(from 0deg, rgba(46, 230, 200, 0.35), rgba(46, 230, 200, 0) 22%);
  animation: sweep 3.2s linear infinite;
  pointer-events: none;
}
#btn-sonar.holding ~ .sweep, #sonar-wrap.holding .sweep { animation-duration: 1.1s; }

#btn-sonar {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid rgba(46, 230, 200, 0.55);
  background:
    radial-gradient(circle at 50% 42%, rgba(22, 74, 92, 0.95), rgba(6, 20, 32, 0.97) 72%);
  box-shadow: 0 0 28px rgba(46, 230, 200, 0.35), inset 0 0 24px rgba(46, 230, 200, 0.18);
  color: var(--teal);
  pointer-events: auto; cursor: pointer; touch-action: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  transition: box-shadow 0.15s, border-color 0.15s, transform 0.08s;
}
#btn-sonar .ring {
  position: absolute; border-radius: 50%;
  border: 1px solid rgba(46, 230, 200, 0.4);
}
#btn-sonar .ring.r1 { inset: 12px; }
#btn-sonar .ring.r2 { inset: 24px; border-style: dashed; opacity: 0.7; }
#btn-sonar .ring.r3 { inset: 36px; border-color: rgba(46, 230, 200, 0.6); }
#btn-sonar .core {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 16px var(--teal), 0 0 4px #fff;
  animation: corepulse 2.2s ease-in-out infinite;
}
@keyframes corepulse { 50% { transform: scale(1.35); opacity: 0.8; } }
#btn-sonar .lbl { font-size: 11px; letter-spacing: 4px; margin-top: 5px; text-indent: 4px; opacity: 0.9; }

#btn-sonar.holding {
  border-color: var(--cyan);
  box-shadow: 0 0 44px rgba(63, 216, 255, 0.6), inset 0 0 30px rgba(63, 216, 255, 0.3);
  transform: scale(1.05);
}
#btn-sonar.holding .core { background: var(--cyan); box-shadow: 0 0 20px var(--cyan); }
#btn-sonar.holding .ring { animation: ringout 1s ease-out infinite; }
@keyframes ringout { from { transform: scale(1); opacity: 0.8; } to { transform: scale(1.28); opacity: 0; } }
#btn-sonar.low { border-color: rgba(224, 86, 86, 0.75); box-shadow: 0 0 30px rgba(224, 86, 86, 0.45), inset 0 0 24px rgba(224, 86, 86, 0.2); }
#btn-sonar.low .core { background: var(--red); box-shadow: 0 0 16px var(--red); animation: none; }
#btn-sonar.low .ring { border-color: rgba(224, 86, 86, 0.5); }
#btn-sonar.alarm { animation: shake 0.4s; }
@keyframes sweep { to { transform: rotate(360deg); } }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

#sonar-dir {
  position: absolute; left: 50%; top: 50%;
  width: 12px; height: 12px; margin: -6px 0 0 -6px;
  border-radius: 50%; background: var(--cyan);
  box-shadow: 0 0 14px var(--cyan);
  opacity: 0; transition: opacity 0.12s; pointer-events: none; z-index: 7;
}

.ctrl-hint {
  position: absolute; left: 0; right: 0; bottom: calc(3px + env(safe-area-inset-bottom, 0px));
  text-align: center; font-size: 9px; letter-spacing: 1px; color: rgba(126, 156, 178, 0.5);
  pointer-events: none;
}
.ctrl-hint em { font-style: normal; color: rgba(46, 230, 200, 0.4); margin: 0 6px; }

/* 窄屏（手机竖屏）：HUD 缩小防重叠 */
@media (max-width: 480px) {
  .ship-badge { width: 34px; height: 34px; padding: 4px; }
  .hp-pips i { width: 24px; height: 6px; }
  .plaque { font-size: 10px; padding: 4px 12px; letter-spacing: 0.5px; }
  .chip { font-size: 12px; padding: 3px 9px 3px 7px; }
  #sonar-wrap { width: 92px; height: 92px; }
  #btn-sonar .lbl { font-size: 10px; letter-spacing: 3px; }
}

/* ---------------- 提示 ---------------- */
#tip {
  z-index: 8; pointer-events: none;
  position: absolute; left: 0; right: 0; top: 0;
  padding: 104px 24px 20px;
  text-align: center; font-size: 13px; line-height: 1.7;
  color: var(--teal);
  background: linear-gradient(180deg, rgba(4, 12, 20, 0.9), rgba(4, 12, 20, 0));
  opacity: 0; transition: opacity 0.3s;
  text-shadow: 0 0 14px rgba(46, 230, 200, 0.5);
}
#tip.show { opacity: 1; }

/* ---------------- 面板（切角游戏框） ---------------- */
.panel {
  position: absolute; inset: 0; z-index: 20;
  background: linear-gradient(180deg, rgba(2, 7, 13, 0.94), rgba(2, 7, 13, 0.99));
  display: flex; flex-direction: column; align-items: center;
  padding: 20px; overflow-y: auto;
}
.panel::-webkit-scrollbar { width: 0; }

.panel-box {
  position: relative;
  width: 100%; max-width: 360px;
  margin: auto;
  padding: 20px 16px 18px;
  background: #061420;
  clip-path: polygon(20px 0, 100% 0, 100% calc(100% - 20px), calc(100% - 20px) 100%, 0 100%, 0 20px);
  filter: drop-shadow(0 0 24px rgba(46, 230, 200, 0.12));
}
.panel-box::before {
  content: ""; position: absolute; inset: 1px;
  background: linear-gradient(170deg, rgba(10, 28, 42, 0.96), rgba(5, 14, 24, 0.98));
  clip-path: polygon(19px 0, 100% 0, 100% calc(100% - 19px), calc(100% - 19px) 100%, 0 100%, 0 19px);
  z-index: -1;
}
.panel-box::after {
  content: ""; position: absolute; top: 0; left: 0; width: 46px; height: 3px;
  background: linear-gradient(90deg, var(--teal), transparent);
  box-shadow: 0 0 10px var(--teal);
}
.panel-box.result { text-align: center; max-width: 330px; }

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; position: relative;
}
.panel-head h2 { font-size: 16px; letter-spacing: 3px; color: var(--teal); text-shadow: 0 0 12px rgba(46, 230, 200, 0.5); }
#upg-shards { font-size: 12px; color: var(--dim); }
#upg-shards b { color: var(--gold); font-size: 14px; }

/* 主菜单 */
#panel-menu { justify-content: flex-start; padding-top: 0; }
.brand { text-align: center; margin-top: 7vh; margin-bottom: 10px; position: relative; }
.brand h1 {
  font-size: 44px; font-weight: 800; letter-spacing: 14px; text-indent: 14px; color: #dffff8;
  text-shadow: 0 0 18px rgba(46, 230, 200, 0.85), 0 0 60px rgba(46, 230, 200, 0.4);
}
.brand .en { margin-top: 10px; font-size: 11px; letter-spacing: 5px; color: var(--dim); }
.brand .slogan { margin-top: 18px; font-size: 12px; color: var(--dim); line-height: 2; letter-spacing: 2px; }

.radar {
  width: 130px; height: 130px; margin: 0 auto 22px;
  border-radius: 50%; border: 1px solid rgba(46, 230, 200, 0.45);
  position: relative;
  box-shadow: 0 0 34px rgba(46, 230, 200, 0.2), inset 0 0 34px rgba(46, 230, 200, 0.14);
  animation: radarGlow 3s ease-in-out infinite;
}
@keyframes radarGlow { 50% { box-shadow: 0 0 50px rgba(46, 230, 200, 0.34), inset 0 0 44px rgba(46, 230, 200, 0.2); } }
.radar::before, .radar::after {
  content: ""; position: absolute; inset: 22px; border-radius: 50%;
  border: 1px solid rgba(46, 230, 200, 0.25);
}
.radar::after { inset: 46px; }
.radar i {
  position: absolute; left: 50%; top: 50%; width: 50%; height: 50%;
  transform-origin: 0 0; border-radius: 0 100% 0 0;
  background: conic-gradient(from 0deg, rgba(46, 230, 200, 0.5), rgba(46, 230, 200, 0));
  animation: sweep 2.6s linear infinite;
}
.radar.small { width: 96px; height: 96px; margin-bottom: 16px; }

.menu-info { display: flex; gap: 26px; font-size: 12px; color: var(--dim); margin: 8px 0 20px; letter-spacing: 1px; }
.menu-info b { color: var(--gold); font-size: 15px; text-shadow: 0 0 10px rgba(240, 192, 96, 0.5); }
.menu-btns { width: 100%; max-width: 300px; display: flex; flex-direction: column; gap: 12px; margin-top: auto; padding-bottom: 8px; }
.menu-ver { font-size: 9px; letter-spacing: 3px; color: rgba(126, 156, 178, 0.4); padding: 12px 0 10px; }

/* ---------------- 按钮（切角 + 扫光） ---------------- */
.btn {
  position: relative;
  padding: 14px 18px; border: none;
  font-size: 14px; letter-spacing: 2px; font-family: inherit;
  color: var(--text);
  background: transparent;
  clip-path: polygon(14px 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%, 0 14px);
  cursor: pointer; transition: filter 0.16s, transform 0.1s;
  overflow: hidden;
}
.btn::before {
  content: ""; position: absolute; inset: 1px;
  background: linear-gradient(135deg, #0e2739, #081523);
  clip-path: polygon(13px 0, 100% 0, 100% calc(100% - 13px), calc(100% - 13px) 100%, 0 100%, 0 13px);
  z-index: -1;
}
.btn::after {                          /* 扫光 */
  content: ""; position: absolute; top: 0; bottom: 0; width: 40%;
  left: -60%;
  background: linear-gradient(100deg, transparent, rgba(180, 255, 240, 0.14), transparent);
  transition: left 0.4s;
}
.btn:hover::after { left: 120%; }
.btn:active { transform: scale(0.985); }
.btn > * { position: relative; z-index: 1; }

.btn.primary { color: #032420; font-weight: 700; }
.btn.primary::before { background: linear-gradient(135deg, #2ee6c8, #23b8d6); }
.btn.ghost { color: var(--dim); }
.btn.ghost::before { background: rgba(10, 24, 36, 0.5); }
.btn.small { padding: 9px 14px; font-size: 12px; }
.btn.dis { opacity: 0.4; pointer-events: none; }

/* 结算 */
#panel-result { justify-content: center; }
.result-glow {
  position: absolute; top: -40px; left: 50%; transform: translateX(-50%);
  width: 200px; height: 90px; border-radius: 50%;
  background: radial-gradient(ellipse, rgba(46, 230, 200, 0.16), transparent 70%);
  pointer-events: none;
}
#result-title { font-size: 26px; font-weight: 700; letter-spacing: 8px; text-indent: 8px; margin-bottom: 12px; }
#result-title.win { color: var(--teal); text-shadow: 0 0 26px rgba(46, 230, 200, 0.7); }
#result-title.lose { color: var(--red); text-shadow: 0 0 26px rgba(224, 86, 86, 0.7); }
#result-stars { font-size: 32px; letter-spacing: 10px; text-indent: 10px; color: var(--gold); text-shadow: 0 0 22px rgba(240, 192, 96, 0.65); margin-bottom: 20px; }
#result-rows { width: 100%; margin-bottom: 22px; }
.rr {
  display: flex; justify-content: space-between; padding: 9px 4px;
  font-size: 13px; color: var(--dim);
  border-bottom: 1px dashed rgba(46, 230, 200, 0.16);
}
.rr b { color: var(--text); }
#result-btns { width: 100%; display: flex; flex-direction: column; gap: 10px; }

/* 升级 */
#upg-list { width: 100%; display: flex; flex-direction: column; gap: 12px; position: relative; }
.upg-card {
  position: relative;
  background: linear-gradient(160deg, #0a2130, #071626);
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
  padding: 13px;
  box-shadow: inset 0 0 0 1px rgba(46, 230, 200, 0.22);
}
.upg-card.maxed { box-shadow: inset 0 0 0 1px rgba(240, 192, 96, 0.45); }
.upg-head { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.upg-icon { color: var(--cyan); font-size: 15px; text-shadow: 0 0 8px rgba(63, 216, 255, 0.6); }
.upg-lv { margin-left: auto; font-size: 11px; color: var(--dim); }
.upg-body { display: flex; align-items: center; justify-content: space-between; margin: 11px 0 9px; font-size: 12px; color: var(--dim); }
.upg-next b { color: var(--teal); }
.upg-max { color: var(--gold); }
.upg-bar { display: flex; gap: 5px; }
.upg-bar i { flex: 1; height: 4px; background: rgba(46, 230, 200, 0.14); clip-path: polygon(2px 0, 100% 0, calc(100% - 2px) 100%, 0 100%); }
.upg-bar i.on { background: var(--teal); box-shadow: 0 0 8px rgba(46, 230, 200, 0.7); }
.panel-foot { width: 100%; margin-top: 18px; position: relative; }

/* 选关 */
#level-grid { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 11px; position: relative; }
.lv-card {
  position: relative;
  background: linear-gradient(160deg, #0a2130, #071626);
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
  box-shadow: inset 0 0 0 1px rgba(46, 230, 200, 0.22);
  padding: 12px 10px; text-align: left; cursor: pointer; color: var(--text); font-family: inherit;
  transition: filter 0.15s;
}
.lv-card:not(.locked):active { filter: brightness(1.35); }
.lv-card.locked { opacity: 0.4; }
.lv-no { font-size: 18px; font-weight: 700; color: var(--teal); text-shadow: 0 0 10px rgba(46, 230, 200, 0.5); }
.lv-name { font-size: 12px; margin: 4px 0 7px; }
.lv-mech { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
.tag { font-style: normal; font-size: 10px; padding: 1px 6px; box-shadow: inset 0 0 0 1px var(--line); color: var(--dim); clip-path: polygon(4px 0, 100% 0, 100% 100%, 0 100%, 0 4px); }
.tag.door { box-shadow: inset 0 0 0 1px rgba(240, 192, 96, 0.6); color: var(--gold); }
.tag.guard { box-shadow: inset 0 0 0 1px rgba(224, 86, 86, 0.6); color: var(--red); }
.tag.base { box-shadow: inset 0 0 0 1px rgba(46, 230, 200, 0.45); color: var(--teal); }
.lv-stars { font-size: 12px; color: var(--gold); letter-spacing: 2px; }

/* 回响三选一 */
#boon-cards { width: 100%; display: flex; flex-direction: column; gap: 11px; position: relative; }
#boon-sub { font-size: 11px; color: var(--dim); }
.boon-card {
  position: relative;
  background: linear-gradient(160deg, #0a2130, #071626);
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
  box-shadow: inset 0 0 0 1px rgba(46, 230, 200, 0.22);
  padding: 13px 14px; text-align: left; cursor: pointer; color: var(--text); font-family: inherit;
  display: flex; align-items: center; gap: 12px;
  transition: filter 0.15s;
}
.boon-card:hover { box-shadow: inset 0 0 0 1px rgba(46, 230, 200, 0.55); }
.boon-card:active { filter: brightness(1.4); }
.boon-icon {
  width: 40px; height: 40px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; color: var(--teal); text-shadow: 0 0 10px rgba(46, 230, 200, 0.7);
  background: rgba(46, 230, 200, 0.08);
  clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
}
.boon-info { flex: 1; }
.boon-name { font-size: 14px; font-weight: 700; }
.boon-name .pips { margin-left: 8px; font-size: 10px; color: var(--gold); letter-spacing: 2px; }
.boon-desc { font-size: 12px; color: var(--dim); margin-top: 4px; }
.boon-lv { font-size: 10px; color: var(--dim); flex: none; }

/* 加载 */
#loading { z-index: 40; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #03070d; gap: 18px; }
#loading .brand { margin-top: 0; }
#loading .brand h1 { font-size: 30px; }
.load-track { width: 200px; height: 3px; background: rgba(46, 230, 200, 0.16); overflow: hidden; }
#load-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--teal), var(--cyan)); box-shadow: 0 0 12px var(--teal); transition: width 0.2s; }
#load-pct { font-size: 11px; color: var(--dim); letter-spacing: 3px; }
