/* HUD、選單、觸控 UI。深色底、明亮強調色、圓角卡片。 */
:root {
  --ui-bg: #10151a;
  --ui-panel: #1b242d;
  --ui-panel-2: #26323d;
  --ui-line: #34444f;
  --ui-text: #e8eef2;
  --ui-dim: #93a4b0;
  --ui-accent: #ffd23f;
  --ui-hp: #ff5d6c;
  --ui-xp: #4de0b0;
  --ui-boss: #c06bff;
  --ui-dash: #5cc8ff;
  --ui-gap: clamp(6px, 1.4vmin, 14px);
  --ui-font: clamp(12px, 1.9vmin, 18px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

/* ---------- 觸控 UI ---------- */
.touch-ui { position: absolute; inset: 0; pointer-events: none; }
.touch-ui[hidden] { display: none; }

.touch-joy-base {
  position: absolute;
  width: 112px; height: 112px;
  margin: -56px 0 0 -56px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.28);
  pointer-events: none;
}
.touch-joy-base[hidden] { display: none; }
.touch-joy-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 52px; height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.7);
}

.touch-dash-btn {
  position: absolute;
  right: calc(var(--safe-r) + clamp(16px, 4vmin, 40px));
  bottom: calc(var(--safe-b) + clamp(16px, 4vmin, 40px));
  width: clamp(72px, 16vmin, 112px);
  height: clamp(72px, 16vmin, 112px);
  border-radius: 50%;
  border: 3px solid var(--ui-dash);
  background: rgba(92, 200, 255, 0.22);
  color: var(--ui-text);
  font: 700 clamp(15px, 3.2vmin, 22px) system-ui, "Microsoft JhengHei", sans-serif;
  pointer-events: auto;
  touch-action: none;
  padding: 0;
}
.touch-dash-btn.is-down { background: rgba(92, 200, 255, 0.55); transform: scale(0.94); }

/* ---------- HUD ---------- */
.hud {
  position: absolute; inset: 0;
  padding: calc(var(--safe-t) + var(--ui-gap)) calc(var(--safe-r) + var(--ui-gap)) var(--ui-gap) calc(var(--safe-l) + var(--ui-gap));
  font-size: var(--ui-font);
  color: var(--ui-text);
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}
.hud[hidden] { display: none; }

.hud-left {
  position: absolute;
  top: calc(var(--safe-t) + var(--ui-gap));
  left: calc(var(--safe-l) + var(--ui-gap));
  width: clamp(120px, 30vw, 300px);
  display: flex; flex-direction: column; gap: 5px;
}
.hud-bar {
  position: relative;
  height: clamp(14px, 2.6vmin, 24px);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--ui-line);
  overflow: hidden;
}
.hud-fill { height: 100%; width: 0; border-radius: inherit; }
.hud-bar-hp .hud-fill { background: var(--ui-hp); }
.hud-bar-hp.is-low .hud-fill { background: #ff2f45; animation: hud-pulse 0.7s infinite alternate; }
.hud-bar-text {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8em; font-weight: 700;
}
.hud-xp-row { display: flex; align-items: center; gap: 6px; }
.hud-level { font-weight: 800; color: var(--ui-accent); min-width: 3.2em; }
.hud-bar-xp { flex: 1; height: clamp(8px, 1.5vmin, 14px); }
.hud-bar-xp .hud-fill { background: var(--ui-xp); }
@keyframes hud-pulse { from { opacity: 1; } to { opacity: 0.55; } }

.hud-center {
  position: absolute;
  top: calc(var(--safe-t) + var(--ui-gap));
  left: 50%; transform: translateX(-50%);
  text-align: center; line-height: 1.25;
  white-space: nowrap;
}
.hud-stage { color: var(--ui-dim); font-size: 0.85em; }
.hud-wave { font-weight: 800; }
.hud-wave.is-boss { color: var(--ui-boss); }
.hud-time { font-variant-numeric: tabular-nums; font-weight: 700; }

.hud-right {
  position: absolute;
  top: calc(var(--safe-t) + var(--ui-gap));
  right: calc(var(--safe-r) + var(--ui-gap));
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
}
.hud-pause {
  pointer-events: auto;
  min-width: 64px; min-height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--ui-line);
  background: rgba(27, 36, 45, 0.85);
  color: var(--ui-text);
  font: 700 var(--ui-font) system-ui, "Microsoft JhengHei", sans-serif;
  cursor: pointer;
}
.hud-pause:hover { background: var(--ui-panel-2); }
.hud-stats { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-weight: 700; }
.hud-gold { color: var(--ui-accent); }

.hud-boss {
  position: absolute;
  top: calc(var(--safe-t) + var(--ui-gap) + clamp(56px, 9vmin, 80px));
  left: 50%; transform: translateX(-50%);
  width: clamp(180px, 50vw, 520px);
  text-align: center;
}
.hud-boss[hidden] { display: none; }
.hud-boss-name { font-weight: 800; color: var(--ui-boss); margin-bottom: 3px; }
.hud-bar-boss .hud-fill { background: var(--ui-boss); }

.hud-dash {
  position: absolute;
  left: calc(var(--safe-l) + var(--ui-gap));
  top: calc(var(--safe-t) + var(--ui-gap) + clamp(56px, 9vmin, 84px));
  width: clamp(72px, 12vw, 120px);
  height: clamp(16px, 2.8vmin, 24px);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--ui-line);
  overflow: hidden;
}
.hud-dash-fill { height: 100%; width: 0; background: rgba(92, 200, 255, 0.5); }
.hud-dash.is-ready .hud-dash-fill { background: var(--ui-dash); }
.hud-dash-label {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75em; font-weight: 700;
}

/* ---------- 選單 ---------- */
.menu-overlay {
  position: absolute; inset: 0;
  display: flex;
  align-items: safe center;
  justify-content: center;
  padding: calc(var(--safe-t) + 16px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 16px) calc(var(--safe-l) + 16px);
  background: rgba(8, 11, 14, 0.78);
  pointer-events: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  font-size: clamp(14px, 2.2vmin, 20px);
  color: var(--ui-text);
}
.menu-overlay[hidden] { display: none; }
.menu-panel {
  width: min(100%, 560px);
  margin: auto;
  padding: clamp(16px, 3.5vmin, 32px);
  background: var(--ui-panel);
  border: 1px solid var(--ui-line);
  border-radius: 20px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  display: flex; flex-direction: column; gap: 12px;
}
.menu-levelup .menu-panel { width: min(100%, 760px); }

.menu-h1 {
  margin: 0; text-align: center;
  font-size: clamp(30px, 7vmin, 56px);
  letter-spacing: 0.04em;
  color: var(--ui-accent);
}
.menu-h1-sm { font-size: clamp(24px, 5vmin, 38px); }
.menu-h1-clear { color: var(--ui-xp); }
.menu-h1-gameover { color: var(--ui-hp); }
.menu-sub { margin: 0; text-align: center; color: var(--ui-dim); }
.menu-heading { margin: 4px 0 0; font-size: 1em; color: var(--ui-dim); }
.menu-gold { text-align: center; color: var(--ui-accent); font-weight: 800; }

.menu-btn {
  min-height: 52px;
  padding: 10px 18px;
  border-radius: 14px;
  border: 1px solid var(--ui-line);
  background: var(--ui-panel-2);
  color: var(--ui-text);
  font: 700 1em system-ui, "Microsoft JhengHei", sans-serif;
  cursor: pointer;
  touch-action: manipulation;
}
.menu-btn:hover:not(:disabled) { border-color: var(--ui-accent); }
.menu-btn:active:not(:disabled) { transform: scale(0.98); }
.menu-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.menu-btn-primary { background: var(--ui-accent); color: #1a1500; border-color: var(--ui-accent); }
.menu-btn-secondary { background: var(--ui-panel-2); }

.menu-stage-list { display: flex; flex-direction: column; gap: 8px; }
.menu-stage { display: flex; align-items: center; gap: 12px; text-align: left; }
.menu-stage-no {
  width: 32px; height: 32px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%; background: var(--ui-bg); color: var(--ui-accent);
}
.menu-stage-name { flex: 1; }
.menu-stage-state { color: var(--ui-dim); font-size: 0.85em; }
.menu-stage:not(:disabled) .menu-stage-state { color: var(--ui-xp); }

.menu-help { color: var(--ui-dim); font-size: 0.85em; line-height: 1.5; }
.menu-help p { margin: 2px 0; }

.menu-shop-list { display: flex; flex-direction: column; gap: 8px; }
.menu-shop-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  background: var(--ui-bg);
  border: 1px solid var(--ui-line);
  border-radius: 14px;
}
.menu-shop-info { flex: 1; min-width: 0; }
.menu-shop-name { font-weight: 800; }
.menu-shop-desc { color: var(--ui-dim); font-size: 0.85em; }
.menu-shop-level { color: var(--ui-xp); font-size: 0.8em; }
.menu-shop-buy { min-width: 96px; flex: none; }

.menu-choices { display: flex; gap: 12px; }
.menu-card {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 16px 12px;
  border-radius: 16px;
  border: 2px solid var(--ui-line);
  background: var(--ui-panel-2);
  color: var(--ui-text);
  font: inherit;
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
}
.menu-card:hover { border-color: var(--ui-accent); transform: translateY(-2px); }
.menu-card-key {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 8px; background: var(--ui-bg); color: var(--ui-dim);
  font-size: 0.85em; font-weight: 800;
}
.menu-card-name { font-size: 1.15em; font-weight: 800; color: var(--ui-accent); }
.menu-card-tag { font-size: 0.8em; color: var(--ui-xp); font-weight: 700; }
.menu-card-desc { color: var(--ui-dim); font-size: 0.9em; line-height: 1.4; }

.menu-stats { display: flex; flex-direction: column; gap: 6px; padding: 8px 4px; }
.menu-stat { display: flex; justify-content: space-between; gap: 12px; }
.menu-stat-label { color: var(--ui-dim); }
.menu-stat-value { font-weight: 800; font-variant-numeric: tabular-nums; }
.menu-actions { display: flex; flex-direction: column; gap: 10px; }

/* 窄螢幕（手機直式）：升級卡片改為直排 */
@media (max-width: 600px) {
  .menu-choices { flex-direction: column; }
  .menu-card { flex-direction: row; flex-wrap: wrap; justify-content: flex-start; text-align: left; padding: 12px; }
  .menu-card-desc { flex-basis: 100%; }
}

/* 矮螢幕（手機橫式）：縮小間距 */
@media (max-height: 480px) {
  .menu-panel { padding: 12px 16px; gap: 8px; }
  .menu-h1 { font-size: 28px; }
  .menu-btn { min-height: 44px; }
  .hud-dash { top: calc(var(--safe-t) + var(--ui-gap) + 46px); }
  .hud-boss { top: calc(var(--safe-t) + var(--ui-gap) + 48px); }
}
