:root {
  --bg: #05070f;
  --panel: rgba(12, 16, 30, 0.82);
  --line: rgba(130, 220, 255, 0.35);
  --danger: #ff4d3d;
  --accent: #43d9ff;
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#game-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  background: #070b16;
}

.loading {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 35%, #101b33 0%, #05070f 72%);
  transition: opacity 0.35s ease;
}

.loading-box {
  width: min(420px, 78vw);
  text-align: center;
}

.loading-title {
  color: #fff;
  font-size: clamp(24px, 5vw, 42px);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-shadow: 0 0 22px rgba(255, 90, 42, 0.75), 0 0 46px rgba(67, 217, 255, 0.35);
  margin-bottom: 22px;
}

.loading-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  overflow: hidden;
}

.loading-bar {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff4d3d, #ff9f3d, #43d9ff);
  transition: width 0.18s ease;
}

.loading-hint {
  margin-top: 14px;
  color: rgba(255, 255, 255, 0.65);
  font-size: 13px;
  letter-spacing: 0.2em;
}

.rotate-hint {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  background: rgba(5, 7, 15, 0.96);
  color: #fff;
  gap: 18px;
}

.rotate-icon {
  width: 72px;
  height: 72px;
  border: 3px solid var(--accent);
  border-radius: 14px;
  position: relative;
  animation: rotate-phone 1.4s ease-in-out infinite;
}

.rotate-icon::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  right: 8px;
  top: 8px;
  border-top: 3px solid var(--accent);
  border-right: 3px solid var(--accent);
}

@keyframes rotate-phone {
  0%, 100% { transform: rotate(0deg); opacity: 1; }
  55% { transform: rotate(90deg); opacity: 0.45; }
}

.rotate-text {
  font-size: 18px;
  letter-spacing: 0.3em;
  color: rgba(255, 255, 255, 0.85);
}

@media (orientation: portrait) {
  .rotate-hint { display: flex; }
  .touch-controls { display: none !important; }
}

.touch-controls {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  padding: calc(env(safe-area-inset-top) + 10px) calc(env(safe-area-inset-right) + 12px) calc(env(safe-area-inset-bottom) + 14px) calc(env(safe-area-inset-left) + 12px);
}

.controls-left,
.controls-right {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  pointer-events: none;
}

.controls-left {
  left: calc(env(safe-area-inset-left) + 16px);
  display: flex;
  gap: 14px;
  align-items: flex-end;
}

.controls-right {
  right: calc(env(safe-area-inset-right) + 16px);
  display: grid;
  grid-template-columns: repeat(5, minmax(46px, 1fr));
  grid-template-areas:
    "s0 s1 s2 ult ult"
    "guard dodge heavy jump atk";
  gap: 9px;
  width: min(420px, 72vw);
  align-items: end;
  justify-items: center;
}

#btn-skill0 { grid-area: s0; }
#btn-skill1 { grid-area: s1; }
#btn-skill2 { grid-area: s2; }
#btn-ultimate { grid-area: ult; }
#btn-guard { grid-area: guard; }
#btn-dodge { grid-area: dodge; }
#btn-heavy { grid-area: heavy; }
#btn-jump { grid-area: jump; }
#btn-attack { grid-area: atk; }

.ctl-btn {
  position: relative;
}

.ctl-btn {
  pointer-events: auto;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: linear-gradient(145deg, rgba(30, 42, 68, 0.72), rgba(10, 14, 26, 0.72));
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  transition: transform 0.05s ease, background 0.05s ease, box-shadow 0.05s ease;
}

.ctl-btn img {
  width: 58%;
  height: 58%;
  object-fit: contain;
  pointer-events: none;
}

.ctl-btn.active,
.ctl-btn:active {
  transform: translateY(3px) scale(0.96);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  background: linear-gradient(145deg, rgba(67, 217, 255, 0.42), rgba(20, 30, 52, 0.82));
}

.dpad-btn {
  width: clamp(58px, 12vw, 84px);
  height: clamp(58px, 12vw, 84px);
}

.action-btn {
  width: clamp(54px, 10.5vw, 76px);
  height: clamp(54px, 10.5vw, 76px);
}

.skill-btn {
  width: clamp(50px, 9.5vw, 70px);
  height: clamp(50px, 9.5vw, 70px);
  overflow: hidden;
}

.action-btn span,
.skill-btn span {
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  white-space: nowrap;
  line-height: 1;
  z-index: 4;
}

.cd {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0%;
  background: rgba(3, 6, 12, 0.64);
  pointer-events: none;
  transition: height 0.08s linear;
  z-index: 2;
  border-radius: 50%;
}

.cd-txt {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 900;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  z-index: 3;
  pointer-events: none;
  opacity: 0;
}

.action-btn.attack {
  border-color: rgba(255, 100, 80, 0.75);
  background: linear-gradient(145deg, rgba(120, 34, 26, 0.72), rgba(38, 10, 10, 0.78));
}

.action-btn.attack.active {
  background: linear-gradient(145deg, rgba(255, 110, 80, 0.72), rgba(120, 34, 26, 0.82));
}

.action-btn.jump {
  border-color: rgba(120, 220, 255, 0.7);
}

.action-btn.guard {
  border-color: rgba(120, 220, 255, 0.78);
  background: linear-gradient(145deg, rgba(20, 82, 112, 0.74), rgba(8, 26, 42, 0.8));
}

.action-btn.guard.active {
  background: linear-gradient(145deg, rgba(90, 200, 255, 0.72), rgba(20, 82, 112, 0.84));
}

.action-btn.dodge {
  border-color: rgba(120, 255, 205, 0.72);
  background: linear-gradient(145deg, rgba(18, 96, 84, 0.72), rgba(8, 34, 30, 0.78));
}

.action-btn.dodge.active {
  background: linear-gradient(145deg, rgba(90, 255, 200, 0.7), rgba(18, 96, 84, 0.84));
}

.action-btn.heavy {
  border-color: rgba(255, 160, 90, 0.78);
  background: linear-gradient(145deg, rgba(116, 62, 18, 0.74), rgba(38, 22, 8, 0.8));
}

.action-btn.heavy.active {
  background: linear-gradient(145deg, rgba(255, 176, 96, 0.74), rgba(116, 62, 18, 0.84));
}

.skill-btn {
  border-color: rgba(255, 200, 90, 0.7);
  background: linear-gradient(145deg, rgba(104, 74, 18, 0.72), rgba(32, 24, 8, 0.78));
}

.skill-btn.skill1 {
  border-color: rgba(255, 200, 90, 0.72);
  background: linear-gradient(145deg, rgba(110, 78, 20, 0.72), rgba(34, 26, 10, 0.78));
}

.skill-btn.skill1.active {
  background: linear-gradient(145deg, rgba(255, 214, 96, 0.72), rgba(110, 78, 20, 0.82));
}

.skill-btn.skill2 {
  border-color: rgba(255, 130, 180, 0.7);
  background: linear-gradient(145deg, rgba(112, 34, 78, 0.72), rgba(36, 10, 26, 0.78));
}

.skill-btn.skill2.active {
  background: linear-gradient(145deg, rgba(255, 130, 190, 0.72), rgba(112, 34, 78, 0.84));
}

.skill-btn.ultimate,
.action-btn.ultimate {
  border-color: rgba(160, 120, 255, 0.78);
  background: linear-gradient(145deg, rgba(72, 42, 132, 0.75), rgba(22, 12, 44, 0.8));
}

.skill-btn.ultimate.active,
.action-btn.ultimate.active {
  background: linear-gradient(145deg, rgba(178, 130, 255, 0.78), rgba(72, 42, 132, 0.85));
  box-shadow: 0 0 22px rgba(160, 120, 255, 0.75);
}

.mute-btn {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 12px);
  right: calc(env(safe-area-inset-right) + 14px);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.32);
  background: rgba(12, 16, 30, 0.72);
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.mute-btn img {
  width: 60%;
  height: 60%;
  pointer-events: none;
}

.mute-btn.muted img {
  opacity: 0.55;
}

.hidden {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.help-btn {
  position: fixed;
  left: calc(env(safe-area-inset-left) + 14px);
  top: calc(env(safe-area-inset-top) + 92px);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(160, 220, 255, 0.45);
  background: rgba(12, 16, 30, 0.78);
  color: #d8f2ff;
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
  z-index: 30;
  pointer-events: auto;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 14px rgba(67, 217, 255, 0.25);
}

.help-btn:active {
  transform: scale(0.94);
}

.keyboard-help {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 35;
  width: min(360px, 92vw);
  background: rgba(8, 12, 26, 0.96);
  border: 1px solid rgba(130, 220, 255, 0.4);
  border-radius: 14px;
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.55), 0 0 30px rgba(67, 217, 255, 0.14);
  padding: 18px 20px 16px;
  pointer-events: auto;
  user-select: none;
}

.keyboard-help.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.help-title {
  color: #fff;
  font-size: 18px;
  font-weight: 900;
  text-align: center;
  margin-bottom: 14px;
  letter-spacing: 0.12em;
}

.help-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  margin-bottom: 14px;
}

.help-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 30px;
}

.help-label {
  color: rgba(255, 255, 255, 0.82);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.help-keys {
  display: flex;
  gap: 5px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.help-keys i {
  font-style: normal;
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1px solid rgba(160, 220, 255, 0.5);
  background: rgba(30, 48, 82, 0.85);
  color: #e8f7ff;
  font-size: 13px;
  font-weight: 900;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
}

.help-close {
  width: 100%;
  height: 42px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #2b8fd6, #124b8c);
  color: #fff;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.18em;
  cursor: pointer;
  pointer-events: auto;
}

.help-close:active {
  transform: translateY(2px);
}

@media (pointer: coarse), (max-width: 760px) {
  .help-btn { display: none; }
  .keyboard-help { display: none; }
}

@media (orientation: landscape) {
  .rotate-hint { display: none; }
}

@media (max-height: 460px) {
  .action-btn span,
  .skill-btn span { display: none; }
  .controls-left,
  .controls-right { bottom: calc(env(safe-area-inset-bottom) + 10px); }
  .controls-right { gap: 6px; }
  .ctl-btn { box-shadow: 0 3px 0 rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.18); }
}
