/* Voxel Destroyer — dark UI theme */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  color-scheme: dark;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --focus-ring: #7bc8ff;
}

html, body {
  width: 100%; height: 100%;
  min-height: 100%;
  overflow: hidden;
  background: #0b0e14;
  font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  color: #dfe6f0;
  user-select: none;
  -webkit-user-select: none;
}

@supports (height: 100dvh) {
  html, body { height: 100dvh; min-height: 100dvh; }
}

#app, #app canvas { position: absolute; inset: 0; }
#app canvas { display: block; cursor: crosshair; }

/* Screenshot / clean mode: hide all UI chrome (via #clean=1 deep-link param) */
body.clean #top-center, body.clean #panel, body.clean #usage-hint,
body.clean #float-layer, body.clean #toasts,
body.clean #angle-indicator, body.clean #main-menu,
body.clean #level-select, body.clean #level-result,
body.clean #siege-hud, body.clean #siege-handoff,
body.clean #siege-result { display: none; }

/* ---------- Top center stack: toolbar + level HUD + score ---------- */
/* Children flow vertically, so the score/HUD can never overlap the toolbar
   no matter how many weapon buttons are added. */
#top-center {
  position: absolute;
  top: calc(14px + var(--safe-top)); left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  z-index: 20;
  pointer-events: none; /* never blocks camera drags; toolbar re-enables */
  max-width: 96vw;
}

/* ---------- Top toolbar ---------- */
#toolbar {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
  max-width: min(700px, 94vw); /* ~7 buttons per row */
  pointer-events: auto;
  background: rgba(16, 20, 30, 0.82);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 8px;
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 24px rgba(0,0,0,0.45);
}
.tool-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 64px;
  padding: 8px 10px 6px;
  font-size: 24px;
  background: rgba(255,255,255,0.04);
  color: #cfd8e6;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.tool-btn span { font-size: 12px; }

/* Tool facing angle indicator (subtle, top-right) */
#angle-indicator {
  position: absolute;
  top: calc(14px + var(--safe-top)); right: calc(16px + var(--safe-right));
  z-index: 20;
  min-width: 46px;
  text-align: center;
  font-size: 13px;
  color: #9fb0c8;
  background: rgba(16, 20, 30, 0.7);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 5px 10px;
  pointer-events: none;
}
.tool-btn kbd {
  font-size: 10px; color: #8a94a8;
  background: rgba(255,255,255,0.06);
  border-radius: 4px; padding: 0 5px;
  font-family: inherit;
}
.tool-btn:hover { background: rgba(255,255,255,0.10); transform: translateY(-1px); }
.tool-btn.active {
  background: rgba(255, 122, 61, 0.22);
  border-color: #ff7a3d;
  box-shadow: 0 0 14px rgba(255,122,61,0.35);
}
.tool-btn.pulsing { animation: pulse 0.5s ease infinite alternate; }
@keyframes pulse { from { filter: brightness(1); } to { filter: brightness(1.6); } }

/* A visible keyboard focus ring is deliberately stronger than hover/active. */
:where(button, select, input, .level-card):focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 3px;
}
.tool-btn:focus-visible {
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 3px rgba(123, 200, 255, 0.28);
}

/* ---------- Left panel ---------- */
#panel {
  position: absolute;
  top: calc(14px + var(--safe-top)); left: calc(14px + var(--safe-left));
  width: 230px;
  max-height: calc(100vh - 28px - var(--safe-top) - var(--safe-bottom)); /* never taller than the viewport */
  overflow-y: auto;                /* scroll when content overflows */
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.18) transparent;
  z-index: 20;
  background: rgba(16, 20, 30, 0.85);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 14px;
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 24px rgba(0,0,0,0.45);
}
@supports (max-height: 100dvh) {
  #panel { max-height: calc(100dvh - 28px - var(--safe-top) - var(--safe-bottom)); }
}
#panel::-webkit-scrollbar { width: 6px; }
#panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 3px; }
#panel::-webkit-scrollbar-track { background: transparent; }
#panel h1 { font-size: 17px; margin-bottom: 10px; letter-spacing: 1px; }
.group { margin-bottom: 14px; }
.group-title {
  font-size: 12px; color: #8a94a8;
  margin-bottom: 6px; letter-spacing: 2px;
}
.ui-btn {
  display: block; width: 100%;
  margin-bottom: 6px;
  padding: 8px 10px;
  font-size: 13px;
  text-align: left;
  color: #dfe6f0;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.ui-btn:hover { background: rgba(255,122,61,0.20); border-color: rgba(255,122,61,0.5); }
.hint-small { font-size: 11px; color: #7b8496; line-height: 1.5; }
.row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; margin-bottom: 8px;
}
.row select {
  background: #1a2030; color: #dfe6f0;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px; padding: 4px 6px;
  font-size: 12px;
}
.stat {
  display: flex; justify-content: space-between;
  font-size: 13px; padding: 3px 0;
  color: #aab4c6;
}
.stat b { color: #ffd166; font-variant-numeric: tabular-nums; }

/* ---------- Bottom hint ---------- */
#usage-hint {
  position: absolute;
  bottom: calc(14px + var(--safe-bottom)); left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  font-size: 12px;
  color: #9aa5b8;
  background: rgba(16, 20, 30, 0.75);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 999px;
  padding: 8px 18px;
  white-space: nowrap;
  backdrop-filter: blur(8px);
}

/* ---------- Toasts ---------- */
#toasts {
  position: absolute;
  top: calc(14px + var(--safe-top)); right: calc(14px + var(--safe-right));
  z-index: 40;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 320px;
}
.toast {
  background: rgba(30, 36, 52, 0.95);
  border: 1px solid rgba(255,122,61,0.5);
  border-left: 4px solid #ff7a3d;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  animation: toast-in 0.25s ease;
}
.toast.info { border-color: rgba(92,184,255,0.5); border-left-color: #5cb8ff; }
.toast.ok { border-color: rgba(98,210,130,0.5); border-left-color: #62d282; }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
.toast.out { opacity: 0; transform: translateX(20px); transition: all 0.3s ease; }

/* ---------- Score display ---------- */
#score-display {
  text-align: center;
}

/* ---------- Rescue mode HUD ---------- */
#rescue-hud {
  display: flex; gap: 18px;
  font-size: 26px; font-weight: 800;
  text-shadow: 0 2px 8px rgba(0,0,0,0.7);
  font-variant-numeric: tabular-nums;
}
#rescue-enemies { color: #ff6b5e; }
#rescue-allies { color: #7ce88a; }
#score-value {
  font-size: 42px;
  font-weight: 800;
  color: #ffd166;
  text-shadow: 0 2px 12px rgba(255, 209, 102, 0.35), 0 2px 4px rgba(0,0,0,0.6);
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
  line-height: 1.1;
}
#combo-mult {
  display: inline-block;
  font-size: 22px;
  font-weight: 700;
  color: #8a94a8;
  margin-top: 2px;
  transition: color 0.25s ease;
  font-variant-numeric: tabular-nums;
}
#combo-mult.hot { color: #ff7a3d; text-shadow: 0 0 14px rgba(255,122,61,0.6); }
#combo-mult.ending { color: #6b7385; text-shadow: none; } /* combo about to break */
#combo-mult.pulse { animation: combo-pulse 0.22s ease; }
@keyframes combo-pulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

/* ---------- Milestone popup ---------- */
#milestone {
  position: absolute;
  top: 38%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 35;
  font-size: 44px;
  font-weight: 900;
  color: #ffd166;
  text-shadow: 0 0 24px rgba(255,122,61,0.8), 0 3px 6px rgba(0,0,0,0.7);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
#milestone.show { animation: milestone-pop 1.4s ease forwards; }
@keyframes milestone-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  30% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(1.05); }
}

/* ---------- Floating "+N" texts ---------- */
#float-layer {
  position: absolute; inset: 0;
  z-index: 32;
  pointer-events: none;
  overflow: hidden;
}
.float-point {
  position: absolute;
  font-size: 22px;
  font-weight: 800;
  color: #7dffa8;
  text-shadow: 0 0 10px rgba(125,255,168,0.6), 0 2px 3px rgba(0,0,0,0.7);
  animation: float-up 1.1s ease-out forwards;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
@keyframes float-up {
  0% { opacity: 0; transform: translateY(6px) scale(0.7); }
  15% { opacity: 1; transform: translateY(0) scale(1.1); }
  100% { opacity: 0; transform: translateY(-64px) scale(1); }
}

/* ---------- Celebration overlay ---------- */
#celebrate {
  position: absolute; inset: 0;
  z-index: 46;
  display: none;
  align-items: center; justify-content: center;
  background: rgba(8, 10, 16, 0.72);
  backdrop-filter: blur(4px);
}
#celebrate.show { display: flex; }
.celebrate-box {
  text-align: center;
  background: rgba(22, 27, 40, 0.95);
  border: 1px solid rgba(255,122,61,0.5);
  border-radius: 18px;
  padding: 36px 56px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.6), 0 0 60px rgba(255,122,61,0.25);
  animation: celebrate-in 0.5s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes celebrate-in {
  from { opacity: 0; transform: scale(0.6); }
  to { opacity: 1; transform: scale(1); }
}
.celebrate-title { font-size: 34px; font-weight: 900; margin-bottom: 8px; }
.celebrate-sub { font-size: 14px; color: #8a94a8; letter-spacing: 4px; }
#celebrate-score {
  font-size: 56px;
  font-weight: 900;
  color: #ffd166;
  text-shadow: 0 0 24px rgba(255,209,102,0.5);
  margin: 6px 0 20px;
  font-variant-numeric: tabular-nums;
}
.celebrate-box .ui-btn { text-align: center; font-size: 15px; padding: 12px 18px; }

/* ---------- Flash ---------- */
#flash {
  position: absolute; inset: 0;
  background: #fff7e0;
  opacity: 0;
  pointer-events: none;
  z-index: 30;
}

/* ---------- Loading ---------- */
#loading {
  position: absolute; inset: 0;
  z-index: 50;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  background: rgba(8, 10, 16, 0.85);
  backdrop-filter: blur(4px);
}
#loading.hidden { display: none; }
.spinner {
  width: 46px; height: 46px;
  border: 4px solid rgba(255,255,255,0.12);
  border-top-color: #ff7a3d;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-text { font-size: 14px; color: #aab4c6; letter-spacing: 2px; }

/* Keep centered overlays inside notches and home-indicator areas. */
#main-menu, #level-select, #level-result, #celebrate, #loading,
#siege-handoff, #siege-result {
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

/* ---------- Drop overlay ---------- */
#drop-overlay {
  position: absolute; inset: 0;
  z-index: 45;
  display: none;
  align-items: center; justify-content: center;
  background: rgba(20, 30, 50, 0.7);
  border: 3px dashed #5cb8ff;
  font-size: 22px;
  pointer-events: none;
}
#drop-overlay.show { display: flex; }

/* ================= 关卡模式 ================= */

.hidden { display: none !important; }

/* ---------- 关卡 HUD：关名 + 倒计时 + 进度条 ---------- */
#level-hud {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
#level-hud-name {
  font-size: 15px; font-weight: 600; color: #ffd28a;
  text-shadow: 0 2px 8px rgba(0,0,0,0.7);
  letter-spacing: 1px;
}
#level-timer {
  font-size: 44px; font-weight: 800; line-height: 1;
  color: #eef4ff;
  text-shadow: 0 3px 12px rgba(0,0,0,0.8);
  font-variant-numeric: tabular-nums;
}
#level-timer.urgent {
  color: #ff5a4e;
  animation: timer-blink 0.5s ease-in-out infinite alternate;
}
@keyframes timer-blink {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: 0.55; transform: scale(1.08); }
}
#level-progress {
  position: relative;
  width: 300px; height: 22px;
  background: rgba(10, 14, 22, 0.78);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 11px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,0.45);
}
#level-progress-fill {
  position: absolute; inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, #ff8a3d, #ffc44d);
  transition: width 0.2s ease;
}
#level-progress-fill.goal-met { background: linear-gradient(90deg, #3ddc78, #9ff05a); }
#level-progress-goal {
  position: absolute; top: 0; bottom: 0;
  width: 2px;
  background: rgba(255,255,255,0.85);
  box-shadow: 0 0 6px rgba(255,255,255,0.6);
}
#level-progress-text {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
}

/* ================= 本地双人攻防对决 ================= */

#siege-hud {
  position: absolute;
  left: 50%;
  bottom: calc(14px + var(--safe-bottom));
  z-index: 36;
  width: min(920px, calc(100vw - 32px - var(--safe-left) - var(--safe-right)));
  padding: 10px 12px 9px;
  transform: translateX(-50%);
  border: 1px solid rgba(255, 145, 72, .42);
  border-radius: 16px;
  background: linear-gradient(145deg, rgba(18, 23, 34, .96), rgba(10, 14, 22, .94));
  box-shadow: 0 18px 50px rgba(0, 0, 0, .58), 0 0 32px rgba(255, 105, 47, .09);
  backdrop-filter: blur(10px);
}
.siege-hud-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.siege-match-state { display: flex; align-items: center; min-width: 0; gap: 9px; }
.siege-phase {
  flex: 0 0 auto;
  padding: 4px 8px;
  border-radius: 7px;
  background: rgba(255, 122, 61, .18);
  color: #ffb173;
  font-size: 12px;
  font-weight: 850;
  letter-spacing: .05em;
}
#siege-hud[data-phase="attack"] .siege-phase {
  background: rgba(255, 78, 58, .18);
  color: #ff9388;
}
.siege-round { flex: 0 0 auto; color: #8290a5; font-size: 12px; }
.siege-player {
  min-width: 0;
  overflow: hidden;
  color: #eef4ff;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.siege-clock, .siege-resource {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  min-width: 86px;
  color: #8390a4;
  font-size: 11px;
  white-space: nowrap;
}
#siege-timer {
  color: #ffd166;
  font-size: 30px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
#siege-timer.urgent { color: #ff6659; text-shadow: 0 0 14px rgba(255, 82, 67, .48); }
.siege-resource {
  min-width: 110px;
  padding: 6px 10px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 9px;
  background: rgba(255,255,255,.035);
}
#siege-resource-value {
  color: #91dcff;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}
.siege-hud-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding-top: 8px;
}
.siege-objective { display: flex; align-items: center; min-width: 0; gap: 10px; }
.siege-objective-label {
  flex: 0 0 auto;
  color: #aeb8c8;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .08em;
}
.siege-cores {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  flex: 1 1 auto;
  gap: 6px;
  min-width: 0;
  list-style: none;
}
.siege-core {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 7px;
  align-items: center;
  min-width: 0;
  padding: 5px 8px;
  border: 1px solid rgba(85, 223, 170, .26);
  border-radius: 9px;
  background: rgba(49, 181, 126, .08);
  color: #70e3b4;
}
.siege-core > span { grid-row: 1 / 3; font-size: 19px; text-shadow: 0 0 12px currentColor; }
.siege-core b { overflow: hidden; color: #dce8e4; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.siege-core small { color: #72b59a; font-size: 10px; }
.siege-core.is-damaged, .siege-core.damaged {
  border-color: rgba(255, 187, 82, .34);
  background: rgba(255, 164, 48, .09);
  color: #ffbf58;
}
.siege-core.is-damaged small, .siege-core.damaged small { color: #d7a24f; }
.siege-core.is-destroyed, .siege-core.destroyed {
  border-color: rgba(255, 102, 89, .28);
  background: rgba(170, 48, 42, .10);
  color: #6e7787;
  filter: saturate(.55);
}
.siege-core.is-destroyed small, .siege-core.destroyed small { color: #ff776c; }
.siege-primary {
  min-width: 138px;
  min-height: 44px;
  padding: 9px 16px;
  border: 1px solid #ffb36b;
  border-radius: 10px;
  background: linear-gradient(135deg, #ff9a45, #ef552d);
  box-shadow: 0 8px 22px rgba(255, 91, 39, .25);
  color: #190b05;
  font: inherit;
  font-size: 14px;
  font-weight: 850;
  cursor: pointer;
}
.siege-primary:hover { background: linear-gradient(135deg, #ffb05f, #ff6936); transform: translateY(-1px); }
.siege-primary:disabled { opacity: .42; cursor: default; transform: none; }
.siege-defense-palette {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}
.siege-defense-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  min-height: 44px;
  padding: 6px 8px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 9px;
  background: rgba(255,255,255,.04);
  color: #aeb9c9;
  font: inherit;
  cursor: pointer;
}
.siege-defense-btn span { flex: 0 0 auto; font-size: 17px; }
.siege-defense-btn b { min-width: 0; overflow: hidden; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.siege-defense-btn small { flex: 0 0 auto; color: #8290a4; font-size: 10px; white-space: nowrap; }
.siege-defense-btn:hover { border-color: rgba(255, 168, 96, .55); background: rgba(255, 122, 61, .10); color: #f0f4fa; }
.siege-defense-btn.active,
.siege-defense-btn[aria-pressed="true"] {
  border-color: #ff9a55;
  background: rgba(255, 122, 61, .18);
  color: #ffd3b2;
  box-shadow: inset 0 0 0 1px rgba(255, 163, 93, .13);
}
.siege-help {
  margin: 7px 2px 0;
  color: #78869a;
  font-size: 10px;
  line-height: 1.25;
  text-align: center;
}

body.siege-mode #panel,
body.siege-mode #panel-toggle,
body.siege-mode #usage-hint,
body.siege-mode #score-display,
body.siege-mode #level-hud,
body.siege-mode #rescue-hud,
body.siege-mode #privacy-banner { display: none; }

/* The defender builds directly on the arena; weapons belong to the attack phase only. */
body.siege-mode:not(.siege-attack) #toolbar { display: none; }
body.siege-attack .tool-btn.locked { display: none; }
body.siege-attack #toolbar { justify-content: center; }
body.siege-mode #btn-pause {
  display: block;
  top: calc(14px + var(--safe-top));
  right: auto;
  bottom: auto;
  left: calc(14px + var(--safe-left));
  z-index: 38;
}
body.siege-mode #toasts { top: calc(72px + var(--safe-top)); }
body.siege-attack #toasts { top: calc(128px + var(--safe-top)); }

/* Handoff and match result intentionally cover the battlefield. */
#siege-handoff, #siege-result {
  position: absolute;
  inset: 0;
  z-index: 72;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 8, 13, .9);
  backdrop-filter: blur(12px);
}
.siege-overlay-box {
  width: min(680px, calc(100vw - 32px - var(--safe-left) - var(--safe-right)));
  max-height: calc(100vh - 40px - var(--safe-top) - var(--safe-bottom));
  overflow-y: auto;
  padding: 30px;
  border: 1px solid rgba(255, 146, 75, .30);
  border-radius: 20px;
  background: linear-gradient(150deg, rgba(20, 25, 37, .99), rgba(12, 16, 25, .99));
  box-shadow: 0 24px 80px rgba(0,0,0,.7), 0 0 52px rgba(255, 111, 52, .08);
}
.siege-handoff-box { display: flex; flex-direction: column; align-items: center; text-align: center; }
.siege-handoff-icon { font-size: 48px; line-height: 1; }
.siege-handoff-box h2, .siege-result-box h2 {
  margin-top: 13px;
  color: #f4f7fc;
  font-size: 28px;
  line-height: 1.2;
}
.siege-handoff-box > p {
  max-width: 520px;
  margin: 10px 0 16px;
  color: #9eacbe;
  font-size: 14px;
  line-height: 1.6;
}
.siege-handoff-summary {
  width: 100%;
  margin-bottom: 20px;
  padding: 12px 14px;
  border: 1px solid rgba(102, 192, 255, .20);
  border-radius: 10px;
  background: rgba(68, 143, 205, .08);
  color: #a8d6f7;
  font-size: 13px;
}
.siege-loadout {
  width: 100%;
  margin: -6px 0 18px;
  padding: 13px;
  border: 1px solid rgba(255, 166, 94, .22);
  border-radius: 13px;
  background: rgba(255, 121, 51, .055);
  text-align: left;
}
.siege-loadout-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 11px;
}
.siege-loadout-head h3 { color: #f0f4fa; font-size: 14px; }
.siege-loadout-head p { margin-top: 3px; color: #8491a4; font-size: 11px; line-height: 1.4; }
#siege-loadout-budget {
  flex: 0 0 auto;
  padding: 6px 9px;
  border-radius: 8px;
  background: rgba(255, 155, 75, .14);
  color: #ffc084;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#siege-loadout-budget.over-budget { background: rgba(255, 77, 65, .16); color: #ff8c82; }
.siege-loadout-options { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.siege-loadout-btn {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 6px;
  min-width: 0;
  min-height: 48px;
  padding: 6px 8px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 9px;
  background: rgba(255,255,255,.035);
  color: #9ba7b8;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.siege-loadout-btn > span { grid-row: 1 / 3; font-size: 20px; }
.siege-loadout-btn b { min-width: 0; overflow: hidden; color: #dfe6f0; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.siege-loadout-btn small { color: #7f8b9d; font-size: 9px; }
.siege-loadout-btn:hover { border-color: rgba(255, 169, 100, .56); background: rgba(255, 122, 61, .10); }
.siege-loadout-btn.active,
.siege-loadout-btn.selected,
.siege-loadout-btn[aria-pressed="true"] {
  border-color: #ff9a55;
  background: rgba(255, 122, 61, .17);
  box-shadow: inset 0 0 0 1px rgba(255, 177, 113, .11);
}
.siege-loadout-btn.active b,
.siege-loadout-btn.selected b,
.siege-loadout-btn[aria-pressed="true"] b { color: #ffd3b2; }
.siege-result-box { text-align: center; }
.siege-result-winner {
  margin: 7px 0 20px;
  color: #ffd166;
  font-size: 24px;
  font-weight: 900;
  text-shadow: 0 0 22px rgba(255, 209, 102, .24);
}
.siege-round-results { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; text-align: left; }
.siege-round-card {
  padding: 14px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 13px;
  background: rgba(255,255,255,.035);
}
.siege-round-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.siege-round-card h3 { color: #f0f4fa; font-size: 15px; }
.siege-round-card-head strong { color: #ffad70; font-size: 11px; }
.siege-round-card dl { display: grid; gap: 7px; }
.siege-round-card dl > div { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.siege-round-card dt { color: #8390a3; font-size: 12px; }
.siege-round-card dd { margin: 0; color: #e4ebf5; font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; }
.siege-result-actions { display: flex; justify-content: center; gap: 10px; margin-top: 20px; }
.siege-result-actions .menu-btn { min-width: 200px; font-size: 14px; }

/* ---------- 全屏菜单/选关/结算 通用 ---------- */
#main-menu, #level-select, #level-result, #wechat-share, #account-dialog {
  position: absolute; inset: 0;
  z-index: 40;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 10, 16, 0.72);
  backdrop-filter: blur(6px);
}
.menu-box, .result-box, .select-box {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  background: rgba(16, 20, 30, 0.92);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 20px;
  padding: 36px 48px;
  box-shadow: 0 18px 60px rgba(0,0,0,0.6);
}
.menu-title { font-size: 42px; font-weight: 800; letter-spacing: 2px; }
.menu-hook { font-size: 21px; font-weight: 800; color: #fff2d7; text-align: center; }
.menu-sub { font-size: 13px; color: #8fa0b8; letter-spacing: 4px; margin-top: -8px; }
.menu-foot { font-size: 12px; color: #66748a; margin-top: 6px; }
.site-footer {
  width: 100%;
  margin-top: 2px;
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
  white-space: nowrap;
}
.site-footer a {
  padding: 4px 6px;
  color: #9eacc0;
  text-decoration: none;
  text-underline-offset: 3px;
}
.site-footer a:hover { color: #dbe7f6; text-decoration: underline; }
.site-footer a:focus-visible {
  color: #dbe7f6;
  outline: 3px solid var(--focus-ring);
  outline-offset: 3px;
  border-radius: 2px;
  text-decoration: underline;
}
.menu-btn {
  min-width: 240px;
  padding: 13px 26px;
  font-size: 18px; font-weight: 700;
  color: #eef4ff;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.menu-btn:hover { background: rgba(255,138,61,0.22); border-color: #ff8a3d; transform: translateY(-1px); }
.menu-btn:disabled { opacity: 0.35; cursor: default; transform: none; }
.menu-primary {
  background: linear-gradient(135deg, #ff9a45, #ef552d);
  border-color: #ffb76b;
  color: #170b06;
  box-shadow: 0 10px 28px rgba(255, 103, 48, 0.32);
}
.menu-primary:hover { background: linear-gradient(135deg, #ffb05f, #ff6936); }
#btn-result-share {
  background: linear-gradient(135deg, #34d675, #07c160);
  border-color: #70e49a;
  color: #052412;
  box-shadow: 0 10px 28px rgba(7, 193, 96, .26);
}
#btn-result-share:hover { background: linear-gradient(135deg, #5ee28e, #13cc6b); border-color: #9af0b8; }
.menu-link {
  padding: 6px 10px;
  border: 0;
  background: transparent;
  color: #9fc8ff;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.account-menu-row {
  width: min(360px, 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin-top: -2px;
}
.account-entry {
  flex: 0 0 auto;
  padding: 7px 12px;
  border: 1px solid rgba(142, 195, 255, .28);
  border-radius: 9px;
  background: rgba(70, 128, 196, .13);
  color: #b9d9ff;
  font: inherit;
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
}
.account-entry:hover { border-color: #8ec3ff; background: rgba(70, 128, 196, .24); }
#account-menu-status { color: #718098; font-size: 11px; line-height: 1.3; }

/* ---------- Account dialog ---------- */
#account-dialog { z-index: 58; }
.account-box {
  position: relative;
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 40px - var(--safe-top) - var(--safe-bottom));
  overflow-y: auto;
  box-sizing: border-box;
  padding: 30px 34px 28px;
  border: 1px solid rgba(142, 195, 255, .22);
  border-radius: 20px;
  background: rgba(16, 22, 34, .98);
  box-shadow: 0 22px 72px rgba(0, 0, 0, .68), 0 0 50px rgba(60, 133, 220, .08);
}
.account-close {
  position: absolute;
  top: 12px;
  right: 14px;
  min-width: 52px;
  min-height: 36px;
  padding: 0 11px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 18px;
  background: rgba(255,255,255,.035);
  color: #9aa9bd;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.account-close:hover { color: #fff; background: rgba(255,255,255,.08); }
.account-close:focus-visible { outline: 3px solid rgba(117, 184, 255, .35); outline-offset: 2px; }
.account-title { padding-right: 64px; font-size: 27px; font-weight: 850; }
#account-dialog[data-account-context="trial-ended"] .account-box {
  border-color: rgba(255, 183, 107, .42);
  box-shadow: 0 22px 72px rgba(0, 0, 0, .68), 0 0 56px rgba(255, 123, 55, .11);
}
.account-privacy { margin: 9px 0 20px; color: #9eacc0; font-size: 13px; line-height: 1.55; }
.account-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 18px; padding: 4px; border-radius: 11px; background: rgba(255,255,255,.05); }
.account-tab {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #8492a6;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
}
.account-tab.active { background: #253349; color: #eef5ff; box-shadow: 0 4px 14px rgba(0,0,0,.24); }
.account-form { display: flex; flex-direction: column; }
.account-form label { margin: 0 0 6px; color: #dbe7f6; font-size: 13px; font-weight: 700; }
.account-form input {
  width: 100%;
  height: 44px;
  box-sizing: border-box;
  margin: 0 0 14px;
  padding: 0 12px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 9px;
  outline: 0;
  background: rgba(5, 9, 16, .68);
  color: #f4f7fb;
  font: inherit;
}
.account-form input:focus { border-color: #75b8ff; box-shadow: 0 0 0 3px rgba(82, 164, 255, .18); }
.account-form .menu-btn { width: 100%; min-width: 0; margin-top: 3px; }
.account-field-hint { margin: -9px 0 13px; color: #77869b; font-size: 11px; }
.account-merge {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 15px 0 8px;
  padding: 11px 12px;
  border: 1px solid rgba(112, 215, 153, .18);
  border-radius: 10px;
  background: rgba(30, 126, 75, .08);
  cursor: pointer;
}
.account-merge input { flex: 0 0 auto; width: 17px; height: 17px; margin-top: 2px; accent-color: #3ddc78; }
.account-merge span { display: flex; flex-direction: column; gap: 3px; color: #d9e7dd; font-size: 13px; }
.account-merge small { color: #82978a; font-size: 11px; line-height: 1.45; }
.account-status { min-height: 20px; margin-top: 8px; color: #8fa5bf; font-size: 12px; text-align: center; line-height: 1.45; }
.account-status.is-error { color: #ff938a; }
.account-note { margin: 12px 4px 0; color: #6f7d90; font-size: 11px; line-height: 1.5; text-align: center; }
.account-profile { display: flex; align-items: center; gap: 13px; margin: 10px 0 17px; padding: 15px; border-radius: 13px; background: rgba(255,255,255,.045); }
.account-avatar { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 13px; background: linear-gradient(145deg, #30415d, #1d293d); font-size: 26px; }
.account-profile span { display: block; margin-bottom: 3px; color: #8291a7; font-size: 11px; }
.account-profile strong { display: block; color: #f1f6ff; font-size: 20px; overflow-wrap: anywhere; }
.account-sync-state { margin-bottom: 15px; padding: 10px 12px; border-radius: 9px; background: rgba(61, 220, 120, .09); color: #82e4a5; font-size: 13px; text-align: center; }
.account-sync-state.offline { background: rgba(255, 184, 84, .09); color: #f4bc6d; }
.account-sync-state.is-error { background: rgba(255, 92, 82, .09); color: #ff938a; }
.account-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.account-actions .menu-btn { min-width: 0; padding: 11px 8px; font-size: 14px; }
.result-best { color: #ffd166; font-weight: 700; text-align: center; }

/* Guided first run, pause, and direct mobile controls */
#tutorial-card {
  position: absolute;
  left: 50%; bottom: calc(26px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 38;
  width: min(620px, calc(100vw - 32px));
  padding: 18px 20px;
  border: 1px solid rgba(255,177,101,.5);
  border-radius: 16px;
  background: rgba(12,17,27,.94);
  box-shadow: 0 16px 50px rgba(0,0,0,.55), 0 0 40px rgba(255,122,61,.14);
  text-align: center;
}
.tutorial-step { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 19px; }
#tutorial-count { padding: 4px 8px; border-radius: 999px; background: #ff7a3d; color: #1c0b05; font-size: 12px; font-weight: 900; }
#tutorial-copy { margin: 8px 0 10px; color: #aebbd0; line-height: 1.5; }
.tutorial-actions { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
.tutorial-actions .menu-btn { min-width: 150px; padding: 9px 15px; font-size: 14px; }
.mobile-action {
  display: none;
  position: absolute;
  z-index: 28;
  min-width: 76px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 11px;
  background: rgba(14,19,29,.88);
  color: #eaf1ff;
  font-weight: 700;
}
#btn-pause { display: block; right: calc(14px + var(--safe-right)); bottom: calc(14px + var(--safe-bottom)); }
#pause-overlay, #webgl-fallback {
  position: absolute; inset: 0; z-index: 65;
  display: flex; align-items: center; justify-content: center;
  background: rgba(5,8,13,.82); backdrop-filter: blur(7px);
}
.pause-box { min-width: min(360px, 90vw); padding: 30px; border-radius: 18px; background: #111827; text-align: center; }
.pause-box p, #webgl-fallback p { margin: 10px 0 20px; color: #aebbd0; line-height: 1.6; }
#privacy-banner {
  position: fixed;
  left: calc(16px + var(--safe-left)); right: calc(16px + var(--safe-right)); bottom: calc(16px + var(--safe-bottom));
  z-index: 80;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid rgba(123,200,255,.4);
  border-radius: 14px;
  background: rgba(12,18,29,.98);
  box-shadow: 0 12px 40px rgba(0,0,0,.55);
}
#privacy-banner div { display: flex; flex-direction: column; gap: 3px; }
#privacy-banner span { font-size: 12px; color: #9dacbf; }
#privacy-banner .ui-btn { width: auto; min-width: 78px; margin: 0; text-align: center; }

/* ---------- 关卡选择 ---------- */
.select-box { max-width: 860px; }
.select-head {
  width: 100%;
  display: flex; align-items: baseline; justify-content: space-between;
}
.select-title { font-size: 26px; font-weight: 800; }
.select-stars { font-size: 15px; color: #ffd28a; }
#level-cards {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin: 8px 0 4px;
}
.level-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  width: 140px;
  padding: 14px 8px 10px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.level-card:hover { background: rgba(255,138,61,0.18); border-color: #ff8a3d; transform: translateY(-2px); }
.level-card .lc-no { font-size: 11px; color: #8fa0b8; letter-spacing: 2px; }
.level-card .lc-emoji { font-size: 34px; line-height: 1.2; }
.level-card .lc-name { font-size: 14px; font-weight: 700; }
.level-card .lc-goal { font-size: 11px; color: #8fa0b8; }
.level-card .lc-stars { font-size: 14px; letter-spacing: 2px; min-height: 18px; color: #ffd28a; }
.level-card.locked { opacity: 0.42; cursor: default; filter: grayscale(0.8); }
.level-card.locked:hover { background: rgba(255,255,255,0.05); border-color: rgba(255,255,255,0.10); transform: none; }

/* ---------- 结算 ---------- */
.result-title { font-size: 36px; font-weight: 800; }
.result-title.lose { color: #ff7a6e; }
.result-stars { font-size: 34px; letter-spacing: 6px; min-height: 42px; color: #ffd28a; text-shadow: 0 0 18px rgba(255,210,138,0.5); }
.result-unlock {
  font-size: 20px; font-weight: 800; color: #2b1a05;
  background: linear-gradient(90deg, #ffc44d, #ff9a3d);
  border-radius: 12px;
  padding: 10px 22px;
  animation: unlock-pop 0.6s ease;
}
@keyframes unlock-pop {
  0% { transform: scale(0.4); opacity: 0; }
  60% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); }
}
.result-stats { display: flex; gap: 26px; margin: 4px 0; }
.result-stats .stat { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.result-stats .stat span { font-size: 12px; color: #8fa0b8; }
.result-stats .stat b { font-size: 22px; }
.result-btns { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.result-btns .menu-btn { min-width: 150px; font-size: 15px; padding: 11px 16px; }

/* ---------- 微信成绩分享 ---------- */
#wechat-share {
  z-index: 90;
  background: rgba(5, 8, 13, 0.88);
  backdrop-filter: blur(10px);
}
.wechat-share-box {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 32px - var(--safe-top) - var(--safe-bottom));
  padding: 26px;
  overflow-y: auto;
  border: 1px solid rgba(101, 220, 125, 0.35);
  border-radius: 22px;
  background: linear-gradient(145deg, rgba(15, 27, 24, 0.98), rgba(16, 20, 30, 0.98));
  box-shadow: 0 24px 80px rgba(0,0,0,.7), 0 0 55px rgba(7, 193, 96, .09);
}
.wechat-share-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,.07);
  color: #dce8e1;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}
.wechat-share-kicker { color: #62d985; font-size: 11px; font-weight: 900; letter-spacing: 4px; }
.wechat-share-title { color: #f3fff7; font-size: 30px; font-weight: 900; }
.wechat-share-copy { max-width: 600px; color: #b6c8bc; line-height: 1.55; text-align: center; }
.wechat-poster-wrap {
  position: relative;
  display: grid;
  place-items: center;
  width: min(390px, 70vw);
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 18px;
  background: #090d14;
  border: 1px solid rgba(255,255,255,.12);
  box-shadow: 0 14px 38px rgba(0,0,0,.48);
}
#wechat-share-poster {
  width: 100%; height: 100%; object-fit: cover;
  user-select: auto;
  -webkit-user-select: auto;
  -webkit-touch-callout: default;
}
.wechat-share-loading { position: absolute; inset: 0; display: grid; place-items: center; color: #9fb2a4; background: #0c1316; }
.wechat-share-status { min-height: 20px; color: #72e594; font-size: 13px; text-align: center; }
.wechat-share-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.wechat-share-actions .menu-btn { min-width: 210px; font-size: 15px; }
.wechat-share-tip { color: #7e9084; font-size: 12px; text-align: center; }

/* ---------- 工具锁定（关卡中未解锁） ---------- */
.tool-btn.locked { opacity: 0.38; filter: grayscale(0.9); cursor: not-allowed; position: relative; }
.tool-btn.locked::after {
  content: '🔒';
  position: absolute; top: 2px; right: 4px;
  font-size: 12px;
}

/* 关卡进行/结算时隐藏沙盒侧栏与底部说明，保持战场干净 */
body.level-mode #panel, body.level-mode #usage-hint, body.level-mode #panel-toggle { display: none; }

/* ---------- Touch / mobile ---------- */
html, body { overscroll-behavior: none; }
#app, #app canvas { touch-action: none; }

#panel-toggle {
  display: none;
  position: absolute;
  top: calc(8px + var(--safe-top)); left: calc(8px + var(--safe-left));
  z-index: 30;
  width: 48px; height: 48px;
  align-items: center; justify-content: center;
  font-size: 20px;
  background: rgba(16, 20, 30, 0.85);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  color: #cfd8e6;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

@media (max-width: 768px),
       (max-width: 932px) and (max-height: 500px) and (orientation: landscape) {
  /*
   * Compact weapon rail: existing buttons remain immediately usable, but a
   * single-row horizontal tray replaces the 4–5 row mobile wall of controls.
   * It works without JavaScript and is naturally swipe-scrollable.
   */
  #top-center {
    top: calc(8px + var(--safe-top));
    width: 100%;
    max-width: 100%;
    gap: 6px;
  }
  #toolbar {
    width: calc(100% - 72px - var(--safe-left) - var(--safe-right));
    max-width: none;
    margin-left: calc(56px + var(--safe-left));
    padding: 5px;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 5px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    scroll-padding-inline: 5px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    border-radius: 12px;
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 8px, #000 calc(100% - 12px), transparent 100%);
    mask-image: linear-gradient(to right, transparent 0, #000 8px, #000 calc(100% - 12px), transparent 100%);
  }
  #toolbar::-webkit-scrollbar { display: none; }
  .tool-btn {
    flex: 0 0 50px;
    min-width: 50px;
    min-height: 52px;
    padding: 4px 4px 3px;
    font-size: 19px;
    gap: 0;
    border-radius: 8px;
    scroll-snap-align: center;
  }
  .tool-btn span { font-size: 10px; }
  .tool-btn kbd { display: none; }

  /* Score + HUDs smaller */
  #score-display {
    padding: 3px 10px;
    border-radius: 10px;
    background: rgba(11, 14, 20, 0.52);
    backdrop-filter: blur(5px);
  }
  #score-value { font-size: clamp(22px, 7vw, 28px); }
  #combo-mult { font-size: 14px; }
  #level-timer { font-size: 22px; }
  #level-hud-name {
    max-width: calc(100vw - 24px - var(--safe-left) - var(--safe-right));
    overflow: hidden;
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #level-progress { width: min(300px, calc(100vw - 32px - var(--safe-left) - var(--safe-right))); }
  #rescue-hud { font-size: 20px; }

  #milestone {
    top: 43%;
    width: calc(100vw - 32px - var(--safe-left) - var(--safe-right));
    max-width: 560px;
    font-size: clamp(28px, 10vw, 40px);
    line-height: 1.1;
    text-align: center;
    white-space: normal;
    text-wrap: balance;
  }

  /* Sidebar hidden behind the ☰ toggle */
  #panel {
    display: none;
    top: calc(92px + var(--safe-top));
    left: calc(8px + var(--safe-left));
    width: min(260px, calc(100vw - 16px - var(--safe-left) - var(--safe-right)));
    max-height: calc(100vh - 108px - var(--safe-top) - var(--safe-bottom));
    padding: 12px;
  }
  @supports (max-height: 100dvh) {
    #panel { max-height: calc(100dvh - 108px - var(--safe-top) - var(--safe-bottom)); }
  }
  body.panel-open #panel { display: block; }
  #panel-toggle { display: flex; }

  #toasts {
    top: calc(92px + var(--safe-top));
    right: calc(8px + var(--safe-right));
    left: calc(8px + var(--safe-left));
    max-width: none;
    align-items: flex-end;
  }
  .toast { max-width: min(320px, 100%); }

  /* Mouse hint is irrelevant on touch */
  #usage-hint { display: none; }

  /* Angle indicator out of the way */
  #angle-indicator {
    top: auto;
    bottom: calc(8px + var(--safe-bottom));
    right: calc(8px + var(--safe-right));
  }

  /* Overlays fit the viewport */
  .menu-box, .select-box, .result-box, .celebrate-box, .wechat-share-box, .account-box {
    width: calc(100vw - 32px - var(--safe-left) - var(--safe-right));
    max-width: 92vw;
    max-height: calc(100vh - 32px - var(--safe-top) - var(--safe-bottom));
    padding: 16px;
    box-sizing: border-box; /* padding counts inside the 92vw */
    overflow-y: auto;
  }
  @supports (max-height: 100dvh) {
    .menu-box, .select-box, .result-box, .celebrate-box, .wechat-share-box, .account-box {
      max-height: calc(100dvh - 32px - var(--safe-top) - var(--safe-bottom));
    }
  }
  .menu-title { font-size: 24px; }
  .menu-hook { font-size: 17px; }
  .menu-sub { font-size: 11px; letter-spacing: 2px; margin-top: -4px; text-align: center; }
  .menu-foot { font-size: 11px; text-align: center; }
  .menu-btn { font-size: 16px; padding: 10px 18px; min-width: 200px; }
  .account-box { padding: 24px 18px 20px; }
  .account-title { font-size: 23px; }
  .account-menu-row { flex-direction: column; gap: 4px; }
  .result-btns { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .result-btns .menu-btn { min-width: 0; width: 100%; font-size: 14px; }
  .wechat-share-box { gap: 8px; padding: 18px 14px; }
  .wechat-share-title { font-size: 24px; }
  .wechat-share-copy { padding: 0 18px; font-size: 13px; }
  .wechat-poster-wrap { width: min(330px, 72vw, 48vh); }
  .wechat-share-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .wechat-share-actions .menu-btn { min-width: 0; width: 100%; padding: 10px 8px; font-size: 13px; }
  #siege-hud {
    bottom: calc(8px + var(--safe-bottom));
    width: calc(100vw - 16px - var(--safe-left) - var(--safe-right));
    padding: 8px;
    border-radius: 12px;
  }
  body.siege-attack #toolbar {
    width: calc(100% - 108px - var(--safe-left) - var(--safe-right));
    margin-left: calc(92px + var(--safe-left));
    justify-content: center;
  }
  .siege-hud-summary { grid-template-columns: minmax(0, 1fr) auto auto; gap: 6px; padding-bottom: 6px; }
  .siege-match-state { flex-wrap: wrap; gap: 3px 6px; }
  .siege-phase { padding: 3px 6px; font-size: 10px; }
  .siege-round { font-size: 10px; }
  .siege-player { flex-basis: 100%; font-size: 11px; }
  .siege-clock { min-width: 58px; gap: 2px; }
  .siege-clock > span:first-child { display: none; }
  #siege-timer { font-size: 24px; }
  .siege-resource { min-width: 74px; padding: 5px 6px; flex-direction: column; align-items: center; gap: 0; }
  #siege-resource-label { font-size: 9px; }
  #siege-resource-value { font-size: 17px; line-height: 1; }
  .siege-hud-controls { gap: 7px; padding-top: 6px; }
  .siege-objective { gap: 0; }
  .siege-objective-label { display: none; }
  .siege-cores { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
  .siege-core { column-gap: 4px; padding: 4px 5px; }
  .siege-core > span { font-size: 15px; }
  .siege-core b { font-size: 10px; }
  .siege-core small { font-size: 10px; }
  .siege-primary { min-width: 96px; min-height: 48px; padding: 8px; font-size: 12px; }
  .siege-defense-palette { gap: 4px; }
  .siege-defense-btn { flex-direction: column; gap: 1px; min-height: 56px; padding: 4px 2px; }
  .siege-defense-btn span { font-size: 15px; line-height: 1; }
  .siege-defense-btn b { max-width: 100%; font-size: 10px; }
  .siege-defense-btn small { font-size: 10px; line-height: 1; }
  .siege-help { margin-top: 5px; font-size: 11px; line-height: 1.35; }
  body.siege-mode #btn-mobile-rotate,
  body.siege-mode #btn-mobile-tool-rotate { display: none; }
  body.siege-setup #btn-mobile-rotate,
  body.siege-setup #btn-mobile-tool-rotate,
  body.siege-attack #btn-mobile-rotate,
  body.siege-attack #btn-mobile-tool-rotate {
    display: block;
    bottom: auto;
    min-width: 0;
    min-height: 44px;
    padding: 6px;
    font-size: 11px;
  }
  body.siege-setup #btn-mobile-rotate {
    top: calc(8px + var(--safe-top));
    left: calc(92px + var(--safe-left));
    width: 82px;
  }
  body.siege-setup #btn-mobile-tool-rotate {
    top: calc(8px + var(--safe-top));
    left: calc(182px + var(--safe-left));
    width: 72px;
  }
  body.siege-attack #btn-mobile-rotate {
    top: calc(78px + var(--safe-top));
    left: calc(8px + var(--safe-left));
    width: 82px;
  }
  body.siege-attack #btn-mobile-tool-rotate {
    top: calc(78px + var(--safe-top));
    left: calc(98px + var(--safe-left));
    width: 72px;
  }
  body.siege-setup #angle-indicator,
  body.siege-attack #angle-indicator { bottom: auto; }
  body.siege-setup #angle-indicator { top: calc(60px + var(--safe-top)); }
  body.siege-attack #angle-indicator { top: calc(78px + var(--safe-top)); }
  body.siege-mode #btn-pause {
    top: calc(8px + var(--safe-top));
    right: auto;
    bottom: auto;
    left: calc(8px + var(--safe-left));
  }
  .siege-overlay-box {
    width: calc(100vw - 32px - var(--safe-left) - var(--safe-right));
    max-height: calc(100vh - 32px - var(--safe-top) - var(--safe-bottom));
    padding: 22px 16px;
  }
  .siege-handoff-box h2, .siege-result-box h2 { font-size: 23px; }
  .siege-handoff-box > p { font-size: 13px; }
  .siege-loadout { margin-bottom: 14px; padding: 10px; }
  .siege-loadout-head { gap: 8px; margin-bottom: 8px; }
  .siege-loadout-head h3 { font-size: 12px; }
  .siege-loadout-head p { font-size: 11px; }
  #siege-loadout-budget { padding: 5px 7px; font-size: 11px; }
  .siege-loadout-options { gap: 4px; }
  .siege-loadout-btn {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 1px;
    min-height: 56px;
    padding: 4px 2px;
    text-align: center;
  }
  .siege-loadout-btn > span { font-size: 17px; line-height: 1; }
  .siege-loadout-btn b { max-width: 100%; font-size: 10px; }
  .siege-loadout-btn small { font-size: 10px; }
  .siege-result-winner { margin-bottom: 14px; font-size: 20px; }
  .siege-round-results { grid-template-columns: 1fr; gap: 8px; }
  .siege-round-card { padding: 10px 12px; }
  .siege-result-actions { display: grid; grid-template-columns: 1fr; gap: 8px; }
  .siege-result-actions .menu-btn { width: 100%; min-width: 0; }
  .siege-overlay-box .menu-btn { min-height: 44px; }
  #level-cards { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .level-card { width: auto; padding: 10px 6px 8px; }
  .level-card .lc-emoji { font-size: 26px; }
  .select-title { font-size: 20px; }
  #tutorial-card { bottom: calc(72px + var(--safe-bottom)); padding: 14px; }
  .tutorial-step { font-size: 16px; }
  #tutorial-copy { font-size: 13px; }
  .mobile-action { display: block; }
  #btn-mobile-rotate { left: calc(8px + var(--safe-left)); bottom: calc(8px + var(--safe-bottom)); }
  #btn-mobile-tool-rotate { left: calc(92px + var(--safe-left)); bottom: calc(8px + var(--safe-bottom)); }
  #btn-pause { right: calc(8px + var(--safe-right)); bottom: calc(8px + var(--safe-bottom)); }
  #privacy-banner { grid-template-columns: 1fr 1fr; }
  #privacy-banner div { grid-column: 1 / -1; }
  #privacy-banner .ui-btn { width: 100%; }
}

/* Short landscape phones need an even quieter HUD and a two-row level grid. */
@media (max-width: 932px) and (max-height: 500px) and (orientation: landscape) {
  #account-dialog { align-items: stretch; overflow-y: auto; }
  .account-box {
    width: min(720px, calc(100vw - 32px - var(--safe-left) - var(--safe-right)));
    max-width: none;
    min-height: max-content;
    max-height: none;
    margin: 16px auto;
    overflow: visible;
  }
  #toolbar {
    width: calc(100% - 128px - var(--safe-left) - var(--safe-right));
  }
  .tool-btn { flex-basis: 46px; min-width: 46px; min-height: 44px; }
  .tool-btn span { display: none; }
  #panel {
    top: calc(68px + var(--safe-top));
    max-height: calc(100vh - 84px - var(--safe-top) - var(--safe-bottom));
  }
  @supports (max-height: 100dvh) {
    #panel { max-height: calc(100dvh - 84px - var(--safe-top) - var(--safe-bottom)); }
  }
  #score-display { display: flex; align-items: baseline; gap: 8px; }
  #siege-hud {
    width: calc(100vw - 16px - var(--safe-left) - var(--safe-right));
    padding: 6px 8px;
  }
  .siege-hud-summary { padding-bottom: 4px; }
  .siege-hud-controls { padding-top: 4px; }
  .siege-help { display: block; margin-top: 3px; font-size: 10px; }
  .siege-core small { display: block; font-size: 10px; }
  .siege-defense-btn { min-height: 44px; flex-direction: row; }
  body.siege-attack #btn-mobile-rotate,
  body.siege-attack #btn-mobile-tool-rotate,
  body.siege-attack #angle-indicator { top: calc(68px + var(--safe-top)); }
  .siege-handoff-icon { display: none; }
  .siege-handoff-box h2 { margin-top: 0; }
  .siege-handoff-box > p { margin: 6px 0 10px; }
  .siege-handoff-summary { margin-bottom: 10px; padding: 8px 10px; }
  .siege-loadout { margin: 0 0 10px; padding: 8px; }
  .siege-loadout-head { margin-bottom: 6px; }
  .siege-loadout-btn { min-height: 44px; flex-direction: row; }
  .siege-loadout-btn small { display: inline; font-size: 10px; }
  .siege-overlay-box { max-height: calc(100vh - 24px - var(--safe-top) - var(--safe-bottom)); padding: 18px 22px; }
  .siege-round-results { grid-template-columns: 1fr 1fr; }
  #milestone { top: 55%; font-size: clamp(24px, 7vw, 34px); }
  #level-cards { grid-template-columns: repeat(5, 1fr); }
  .level-card .lc-goal, .level-card .lc-stars { display: none; }
}

/* Respect vestibular and photosensitivity preferences without hiding state. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation: none !important;
    transition: none !important;
  }
  /* JS removes these states on its normal timers; keep their information
     visible while the class/node exists, but remove translation and scaling. */
  #milestone.show, .float-point { opacity: 1; transform: none; }
  #level-timer.urgent { opacity: 1; transform: none; }
  .tool-btn.pulsing { filter: brightness(1.35); }
  #flash { display: none !important; }
  .tool-btn:hover, .menu-btn:hover, .level-card:hover, .siege-primary:hover { transform: none; }
  #toolbar { scroll-snap-type: none; }
}

@media (hover: none) {
  .tool-btn:hover, .ui-btn:hover, .menu-btn:hover, .level-card:hover {
    transform: none;
  }
}

@media (prefers-contrast: more) {
  :root { --focus-ring: #bce4ff; }
  #toolbar, #panel, .menu-box, .select-box, .result-box, .celebrate-box,
  #siege-hud, .siege-overlay-box, .siege-loadout {
    background: #10141e;
    border-color: rgba(255,255,255,0.38);
  }
  .tool-btn, .ui-btn, .menu-btn, .level-card, .siege-defense-btn,
  .siege-loadout-btn { border-color: rgba(255,255,255,0.35); }
}
