* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0f141a;
  overscroll-behavior: none;
}

body {
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", system-ui,
    sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#game {
  display: block;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  touch-action: none;
  outline: none;
}

/* ------------------------------------------------------------ 手机触控层 */

.touch-ui {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  pointer-events: none;
}

.touch-ui.visible {
  display: block;
}

.touch-pause {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  right: calc(8px + env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid #1e2430;
  border-radius: 14px;
  background: rgba(255, 246, 229, 0.88);
  color: #1e2430;
  font: 900 15px/1 "Segoe UI", "Microsoft YaHei", "PingFang SC",
    system-ui, sans-serif;
  box-shadow: 0 4px 0 rgba(30, 36, 48, 0.22);
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.touch-pause:active {
  transform: translateY(2px);
  background: #ffd23f;
  box-shadow: 0 2px 0 rgba(30, 36, 48, 0.22);
}

.touch-stick {
  position: absolute;
  left: calc(16px + env(safe-area-inset-left));
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: 140px;
  height: 140px;
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;
  transition: opacity 0.15s ease;
}

.touch-stick.is-disabled {
  opacity: 0.3;
}

.stick-base {
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  border: 2px solid rgba(30, 36, 48, 0.45);
  background: rgba(30, 36, 48, 0.18);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.22);
}

.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border: 2px solid #1e2430;
  border-radius: 50%;
  background: rgba(255, 246, 229, 0.92);
  box-shadow: 0 4px 0 rgba(30, 36, 48, 0.22);
  will-change: transform;
}

.touch-stick.is-active .stick-knob {
  background: #ffd23f;
}

.touch-pad {
  position: absolute;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: 174px;
  height: 174px;
  pointer-events: none;
  touch-action: none;
}

.touch-pad .pad {
  position: absolute;
  width: 58px;
  height: 58px;
  padding: 0;
  border: 2px solid #1e2430;
  border-radius: 16px;
  background: rgba(255, 246, 229, 0.88);
  color: #1e2430;
  font: 900 22px/1 "Segoe UI", "Microsoft YaHei", "PingFang SC",
    system-ui, sans-serif;
  box-shadow: 0 4px 0 rgba(30, 36, 48, 0.22);
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  transition: opacity 0.12s ease, background 0.08s ease;
}

.touch-pad .pad.up {
  left: 58px;
  top: 0;
}

.touch-pad .pad.left {
  left: 0;
  top: 58px;
}

.touch-pad .pad.down {
  left: 58px;
  top: 116px;
}

.touch-pad .pad.right {
  left: 116px;
  top: 58px;
}

.touch-pad .pad:disabled {
  opacity: 0.26;
  box-shadow: none;
}

.touch-pad .pad.pressed {
  transform: translateY(2px);
  background: #ffd23f;
  box-shadow: 0 2px 0 rgba(30, 36, 48, 0.22);
}

.touch-ui.mode-gesture .touch-stick,
.touch-ui.mode-gesture .touch-pad {
  display: none;
}

/* 操控方式选择：标题页 / 暂停页显示 */
.control-mode {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 35;
  display: none;
  align-items: center;
  gap: 4px;
  padding: 4px 5px 4px 10px;
  border: 2px solid #1e2430;
  border-radius: 999px;
  background: rgba(255, 246, 229, 0.94);
  box-shadow: 0 4px 0 rgba(30, 36, 48, 0.22);
  pointer-events: auto;
  white-space: nowrap;
  transform: translateX(-50%);
}

.control-mode.visible {
  display: flex;
}

.control-mode .cm-label {
  margin-right: 2px;
  color: #6b7280;
  font-size: 10px;
  font-weight: 800;
}

.control-mode button {
  padding: 4px 10px;
  border: 2px solid #1e2430;
  border-radius: 999px;
  background: transparent;
  color: #1e2430;
  font-size: 11px;
  font-weight: 800;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.control-mode button.active {
  background: #1e2430;
  color: #fff6e5;
}

/* ------------------------------------------------------------ 调参面板 */

.debug-panel {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 50;
  display: none;
  width: min(348px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  overflow-y: auto;
  padding: 14px 16px 12px;
  border: 2px solid #05080c;
  border-radius: 16px;
  background: rgba(18, 24, 32, 0.95);
  box-shadow: 0 22px 56px rgba(0, 0, 0, 0.55);
  color: #eee8dc;
  font-size: 12px;
  backdrop-filter: blur(10px);
}

.debug-panel.open {
  display: block;
}

.debug-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.debug-title {
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.debug-hint {
  margin-left: auto;
  color: #8d97a3;
  font-size: 11px;
}

.debug-close {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid #05080c;
  border-radius: 8px;
  background: #2a3442;
  color: #eee8dc;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.debug-close:hover {
  background: #39475a;
}

.debug-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
}

.debug-actions button {
  padding: 7px 6px;
  border: 1px solid #05080c;
  border-radius: 8px;
  background: #2a3442;
  color: #f4eee2;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.debug-actions button:hover {
  background: #39475a;
}

.debug-groups {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.debug-group h3 {
  margin: 0 0 6px;
  padding-bottom: 5px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: #9aa4b0;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.debug-row {
  margin-bottom: 8px;
}

.debug-row label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 3px;
  color: #d9d3c7;
  font-size: 11.5px;
}

.debug-value {
  color: #ffd23f;
  font-family: Consolas, "Courier New", monospace;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.debug-row input[type="range"] {
  width: 100%;
  height: 16px;
  margin: 0;
  accent-color: #ffd23f;
  cursor: pointer;
}

.debug-footer {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  color: #8d97a3;
  font-size: 10.5px;
  line-height: 1.55;
}

.debug-footer code {
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  color: #d9d3c7;
  font-size: 10px;
}

.debug-panel::-webkit-scrollbar {
  width: 8px;
}

.debug-panel::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}

.debug-toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  z-index: 60;
  padding: 9px 18px;
  border: 2px solid #1e2430;
  border-radius: 999px;
  background: #ffd23f;
  color: #1e2430;
  font-size: 12.5px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.debug-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ------------------------------------------------------------ 全球排行榜 */

.lb-root {
  font-family: inherit;
}

.lb-open {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top, 0px));
  right: calc(16px + env(safe-area-inset-right, 0px));
  z-index: 36;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 9px 16px;
  border: 2px solid #1e2430;
  border-radius: 999px;
  background: #fff6e5;
  box-shadow: 0 4px 0 rgba(30, 36, 48, 0.28);
  color: #1e2430;
  font: inherit;
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.lb-open.visible {
  display: inline-flex;
}

.lb-open.pending {
  background: #ffd23f;
}

.lb-open:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(30, 36, 48, 0.28);
}

.lb-modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: none;
  align-items: center;
  justify-content: center;
  padding: calc(12px + env(safe-area-inset-top, 0px))
    calc(12px + env(safe-area-inset-right, 0px))
    calc(12px + env(safe-area-inset-bottom, 0px))
    calc(12px + env(safe-area-inset-left, 0px));
  font-family: inherit;
}

.lb-modal.open {
  display: flex;
}

.lb-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 16, 22, 0.62);
  backdrop-filter: blur(4px);
}

.lb-card {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(430px, 100%);
  max-height: min(82vh, 720px);
  max-height: min(82dvh, 720px);
  overflow: hidden;
  border: 3px solid #1e2430;
  border-radius: 22px;
  background: #fff6e5;
  box-shadow: 0 16px 0 rgba(30, 36, 48, 0.2),
    0 24px 48px rgba(0, 0, 0, 0.35);
  color: #1e2430;
}

.lb-stripe {
  flex: 0 0 auto;
  height: 7px;
  background: linear-gradient(
    90deg,
    #ff6a3d 0 25%,
    #ffd23f 25% 50%,
    #4f9fd9 50% 75%,
    #43aa8b 75% 100%
  );
}

.lb-head {
  display: flex;
  flex: 0 0 auto;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 8px;
}

.lb-heading h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: -0.01em;
}

.lb-sub {
  margin: 4px 0 0;
  font-size: 11px;
  font-weight: 700;
  color: #6b7280;
}

.lb-close {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 2px solid #1e2430;
  border-radius: 50%;
  background: #fff6e5;
  color: #1e2430;
  font: inherit;
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.lb-tabs {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
  padding: 2px 16px 10px;
}

.lb-tabs button {
  padding: 6px 14px;
  border: 2px solid #1e2430;
  border-radius: 999px;
  background: transparent;
  color: #6b7280;
  font: inherit;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
}

.lb-tabs button.active {
  background: #1e2430;
  color: #fff6e5;
}

.lb-list {
  flex: 1 1 auto;
  min-height: 120px;
  padding: 0 16px 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.lb-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 9px 2px;
  border-bottom: 1px dashed rgba(30, 36, 48, 0.14);
}

.lb-row:last-child {
  border-bottom: 0;
}

.lb-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(30, 36, 48, 0.08);
  color: #6b7280;
  font-size: 11px;
  font-weight: 900;
}

.lb-rank.top1 {
  background: #ffd23f;
  color: #1e2430;
}

.lb-rank.top2 {
  background: #d7dde3;
  color: #1e2430;
}

.lb-rank.top3 {
  background: #e5b083;
  color: #1e2430;
}

.lb-name-cell {
  min-width: 0;
  overflow: hidden;
  font-size: 13.5px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-score {
  font-size: 14px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.lb-empty {
  padding: 26px 8px;
  color: #6b7280;
  font-size: 12.5px;
  font-weight: 700;
  text-align: center;
}

.lb-error {
  color: #b4312a;
}

.lb-retry {
  margin-top: 10px;
  padding: 6px 16px;
  border: 2px solid #1e2430;
  border-radius: 999px;
  background: #ffd23f;
  color: #1e2430;
  font: inherit;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}

.lb-submit {
  flex: 0 0 auto;
  padding: 11px 16px 12px;
  border-top: 1px solid rgba(30, 36, 48, 0.12);
  background: #f7edd7;
}

.lb-run {
  margin-bottom: 8px;
  color: #6b7280;
  font-size: 11.5px;
  font-weight: 800;
}

.lb-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lb-name-label {
  color: #6b7280;
  font-size: 11.5px;
  font-weight: 900;
}

.lb-name {
  flex: 1;
  min-width: 0;
  height: 34px;
  padding: 0 10px;
  border: 2px solid #1e2430;
  border-radius: 10px;
  outline: none;
  background: #fffdf7;
  color: #1e2430;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
}

.lb-name:focus {
  box-shadow: 0 0 0 3px rgba(255, 106, 61, 0.22);
}

.lb-save-name {
  flex: 0 0 auto;
  height: 34px;
  padding: 0 12px;
  border: 2px solid #1e2430;
  border-radius: 10px;
  background: #fff6e5;
  color: #1e2430;
  font: inherit;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
}

.lb-auto {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  color: #6b7280;
  font-size: 10.5px;
  font-weight: 700;
  cursor: pointer;
}

.lb-auto input {
  width: 14px;
  height: 14px;
  accent-color: #ff6a3d;
}

.lb-submit-btn {
  width: 100%;
  height: 38px;
  margin-top: 9px;
  border: 2px solid #1e2430;
  border-radius: 11px;
  background: #ff6a3d;
  color: #fff6e5;
  font: inherit;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
}

.lb-submit-btn:disabled {
  background: #d7cdbd;
  color: #8c8578;
  cursor: default;
}

.lb-status {
  min-height: 15px;
  margin: 7px 0 0;
  color: #6b7280;
  font-size: 11px;
  font-weight: 800;
}

.lb-status[data-tone='ok'] {
  color: #2b7a5f;
}

.lb-status[data-tone='error'] {
  color: #b4312a;
}

.lb-status[data-tone='info'] {
  color: #8a6a1f;
}

.lb-foot {
  flex: 0 0 auto;
  margin: 0;
  padding: 0 16px 12px;
  color: #9aa1a9;
  font-size: 9.5px;
  font-weight: 600;
  line-height: 1.45;
}

.lb-toast {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top, 0px));
  left: 50%;
  z-index: 80;
  padding: 9px 18px;
  border: 2px solid #1e2430;
  border-radius: 999px;
  background: #ffd23f;
  color: #1e2430;
  font-size: 12.5px;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.lb-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 760px), (pointer: coarse) {
  .lb-open {
    top: auto;
    right: calc(12px + env(safe-area-inset-right, 0px));
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    padding: 8px 13px;
    font-size: 12px;
    box-shadow: 0 3px 0 rgba(30, 36, 48, 0.25);
  }

  .lb-modal {
    padding: calc(8px + env(safe-area-inset-top, 0px))
      calc(8px + env(safe-area-inset-right, 0px))
      calc(8px + env(safe-area-inset-bottom, 0px))
      calc(8px + env(safe-area-inset-left, 0px));
  }

  .lb-card {
    max-height: 90vh;
    max-height: 90dvh;
    border-radius: 18px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .lb-head {
    padding: 12px 13px 6px;
  }

  .lb-heading h2 {
    font-size: 18px;
  }

  .lb-sub {
    font-size: 10.5px;
  }

  .lb-tabs {
    padding: 2px 13px 8px;
  }

  .lb-list {
    flex: 0 0 auto;
    padding: 0 13px 4px;
    overflow: visible;
  }

  .lb-submit {
    padding: 9px 13px 10px;
  }

  .lb-name {
    height: 40px;
    font-size: 16px;
  }

  .lb-save-name {
    height: 40px;
  }

  .lb-foot {
    padding: 0 13px 10px;
    font-size: 9px;
  }

  .lb-toast {
    top: calc(8px + env(safe-area-inset-top, 0px));
    font-size: 11.5px;
  }
}
