:root {
  --bg: #060a13;
  --surface: rgba(8, 15, 26, 0.88);
  --surface-strong: rgba(11, 20, 34, 0.94);
  --ink: #eef4ee;
  --ink-muted: #b6c8c6;
  --brine: #7fe8dc;
  --candle: #ffc070;
  --danger: #ff4d5e;
  --border: rgba(185, 207, 202, 0.28);
  --safe-top-probe: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  --safe-bottom-probe: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --safe-left-probe: var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
  --safe-right-probe: var(--safe-area-inset-right, env(safe-area-inset-right, 0px));
  --host-top: 0px;
  --host-bottom: 0px;
  --host-left: 0px;
  --host-right: 0px;
  --inset-top: var(--host-top);
  --inset-bottom: var(--host-bottom);
  --inset-left: var(--host-left);
  --inset-right: var(--host-right);
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: pan-x pan-y;
}

[hidden] {
  display: none !important;
}

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg);
  touch-action: none;
}

.game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}

/* 顶部操作按钮 */
.top-bar {
  position: absolute;
  top: calc(12px + var(--inset-top));
  right: calc(14px + var(--inset-right));
  z-index: 20;
  display: flex;
  flex-direction: row;
  align-items: center;
}

.pill-btn {
  min-width: 54px;
  min-height: 44px;
  padding: 0 14px;
  margin-left: 8px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background-color: rgba(6, 12, 22, 0.76);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.16s ease, background-color 0.16s ease, transform 0.1s ease;
}

.pill-btn:first-child {
  margin-left: 0;
}

.pill-btn:hover {
  border-color: rgba(127, 232, 220, 0.72);
  background-color: rgba(14, 28, 42, 0.88);
}

.pill-btn:active {
  transform: scale(0.95);
}

.pill-btn:focus-visible,
.primary-btn:focus-visible,
.ghost-btn:focus-visible,
.act-btn:focus-visible {
  outline: 2px solid var(--brine);
  outline-offset: 2px;
}

/* 覆盖层与面板 */
.overlay {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(18px + var(--inset-top)) calc(18px + var(--inset-right)) calc(18px + var(--inset-bottom)) calc(18px + var(--inset-left));
  background: radial-gradient(circle at 50% 42%, rgba(6, 12, 22, 0.56), rgba(4, 7, 14, 0.86));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.overlay-title {
  background: radial-gradient(circle at 50% 38%, rgba(6, 12, 22, 0.42), rgba(4, 7, 14, 0.82));
}

.panel {
  width: 100%;
  max-width: 420px;
  padding: 26px 24px 22px;
  border: 1px solid rgba(185, 207, 202, 0.34);
  border-radius: 10px;
  background-color: var(--surface);
  box-shadow: 0 20px 56px rgba(0, 0, 0, 0.65);
  text-align: center;
}

.panel-title {
  max-width: 476px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--candle);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.16em;
}

.game-title {
  margin: 0;
  font-family: "Songti SC", "Noto Serif SC", "STSong", Georgia, serif;
  font-size: 38px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-indent: 0.18em;
  color: var(--ink);
  text-shadow: 0 0 24px rgba(127, 232, 220, 0.22);
}

.panel-heading {
  margin: 0;
  font-family: "Songti SC", "Noto Serif SC", "STSong", Georgia, serif;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--ink);
}

.title-rule {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 14px auto 16px;
  width: 180px;
}

.rule-line {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, rgba(185, 207, 202, 0), rgba(185, 207, 202, 0.72), rgba(185, 207, 202, 0));
}

.rule-diamond {
  width: 7px;
  height: 7px;
  margin: 0 10px;
  background-color: var(--candle);
  transform: rotate(45deg);
}

.subtitle {
  margin: 0 0 20px;
  color: var(--ink-muted);
  font-size: 14px;
  line-height: 1.65;
}

.btn-row {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

.menu-stack {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  max-width: 240px;
  margin: 0 auto 14px;
}

.menu-stack > button {
  margin-bottom: 10px;
}

.menu-stack > button:last-child {
  margin-bottom: 0;
}

.primary-btn {
  min-width: 176px;
  min-height: 46px;
  padding: 0 26px;
  border: 1px solid rgba(127, 232, 220, 0.85);
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(24, 58, 66, 0.96), rgba(12, 32, 42, 0.98));
  color: #f4fbf9;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-indent: 0.14em;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 0 18px rgba(127, 232, 220, 0.2);
  transition: transform 0.12s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.primary-btn:hover {
  border-color: #c2fff7;
  box-shadow: 0 0 24px rgba(127, 232, 220, 0.36);
}

.primary-btn:active {
  transform: scale(0.97);
}

.ghost-btn {
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background-color: rgba(14, 24, 36, 0.72);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.08em;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.16s ease, background-color 0.16s ease;
}

.ghost-btn:hover {
  border-color: rgba(185, 207, 202, 0.65);
  background-color: rgba(20, 34, 48, 0.88);
}

.key-hints {
  list-style: none;
  margin: 0;
  padding: 14px 0 0;
  border-top: 1px solid rgba(185, 207, 202, 0.16);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  color: var(--ink-muted);
  font-size: 12px;
  line-height: 1.8;
}

.key-hints li {
  margin: 2px 8px;
}

.key-hints kbd {
  display: inline-block;
  padding: 1px 6px;
  margin: 0 2px;
  border: 1px solid rgba(185, 207, 202, 0.36);
  border-radius: 4px;
  background-color: rgba(15, 26, 38, 0.9);
  color: var(--ink);
  font-family: inherit;
  font-size: 11px;
}

.panel-note {
  margin: 0;
  color: var(--ink-muted);
  font-size: 12px;
  line-height: 1.65;
}

.stats-grid {
  display: flex;
  flex-wrap: wrap;
  margin: 0 0 20px;
  padding: 12px 14px;
  border: 1px solid rgba(185, 207, 202, 0.2);
  border-radius: 6px;
  background-color: rgba(5, 10, 18, 0.68);
  text-align: left;
}

.stats-grid dt {
  width: 52%;
  padding: 6px 0;
  color: var(--ink-muted);
  font-size: 13px;
}

.stats-grid dd {
  width: 48%;
  margin: 0;
  padding: 6px 0;
  text-align: right;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
}

/* 触屏按键层 */
.touch-layer {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 15;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 calc(16px + var(--inset-right)) calc(16px + var(--inset-bottom)) calc(16px + var(--inset-left));
  pointer-events: none;
}

.touch-stick {
  position: relative;
  width: 124px;
  height: 124px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  touch-action: none;
}

.stick-ring {
  position: relative;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  border: 1.5px solid rgba(185, 207, 202, 0.34);
  background-color: rgba(6, 12, 22, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}

.touch-stick.is-active .stick-ring {
  border-color: rgba(127, 232, 220, 0.72);
  background-color: rgba(12, 26, 36, 0.62);
}

.stick-dir {
  position: absolute;
  color: rgba(185, 207, 202, 0.32);
  font-size: 9px;
  pointer-events: none;
}

.stick-up { top: 8px; left: 50%; transform: translateX(-50%); }
.stick-down { bottom: 8px; left: 50%; transform: translateX(-50%); }
.stick-left { left: 9px; top: 50%; transform: translateY(-50%); }
.stick-right { right: 9px; top: 50%; transform: translateY(-50%); }

.stick-knob {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1.5px solid rgba(127, 232, 220, 0.75);
  background: radial-gradient(circle at 35% 35%, rgba(238, 244, 238, 0.9), rgba(47, 165, 160, 0.75));
  pointer-events: none;
}

.touch-actions {
  position: relative;
  width: 176px;
  height: 136px;
  pointer-events: none;
}

.act-btn {
  position: absolute;
  border-radius: 50%;
  border: 1.5px solid rgba(185, 207, 202, 0.44);
  background-color: rgba(8, 16, 28, 0.68);
  color: var(--ink);
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  pointer-events: auto;
  touch-action: none;
  transition: transform 0.08s ease, background-color 0.08s ease, border-color 0.08s ease;
}

.act-btn.is-pressed {
  transform: scale(0.9);
  background-color: rgba(47, 165, 160, 0.65);
  border-color: #d6fff9;
}

/* 拇指弧形排布，保证按钮边缘间距 >= 12px 且尺寸 >= 48px */
.act-attack {
  width: 62px;
  height: 62px;
  right: 76px;
  bottom: 4px;
  border-color: rgba(127, 232, 220, 0.78);
  background-color: rgba(18, 48, 56, 0.78);
}

.act-jump {
  width: 58px;
  height: 58px;
  right: 4px;
  bottom: 18px;
}

.act-dash {
  width: 52px;
  height: 52px;
  right: 54px;
  bottom: 78px;
}

.act-heal {
  width: 48px;
  height: 48px;
  right: 120px;
  bottom: 74px;
  border-color: rgba(255, 192, 112, 0.52);
  font-size: 14px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-height: 460px) {
  .panel {
    padding: 16px 18px 14px;
  }
  .game-title {
    font-size: 28px;
  }
  .title-rule {
    margin: 8px auto 10px;
  }
  .subtitle {
    margin-bottom: 12px;
    font-size: 13px;
  }
  .btn-row {
    margin-bottom: 10px;
  }
  .key-hints {
    padding-top: 8px;
    font-size: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pill-btn,
  .primary-btn,
  .ghost-btn,
  .act-btn {
    transition: none;
  }
}
