:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #454863;
  background: #e9efff;
  font-synthesis: none;
  -webkit-tap-highlight-color: transparent;
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    radial-gradient(ellipse at 12% 4%, rgba(255, 255, 255, 0.94), transparent 34%),
    radial-gradient(ellipse at 92% 24%, rgba(219, 207, 255, 0.68), transparent 38%),
    radial-gradient(ellipse at 8% 86%, rgba(205, 232, 255, 0.72), transparent 38%),
    linear-gradient(180deg, #e8f1ff 0%, #f0ebfb 48%, #fff0e7 100%);
}

body::before,
body::after {
  content: "";
  position: fixed;
  z-index: 0;
  width: 310px;
  height: 310px;
  border-radius: 50%;
  pointer-events: none;
  filter: blur(70px);
  opacity: 0.5;
}

body::before {
  top: 22%;
  left: -190px;
  background: #b7d8ff;
}

body::after {
  right: -190px;
  bottom: 4%;
  background: #ffd4c9;
}

button {
  font: inherit;
}

button:focus-visible,
canvas:focus-visible {
  outline: 3px solid rgba(105, 126, 226, 0.42);
  outline-offset: 3px;
}

.game {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  isolation: isolate;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}

#gameCanvas.dragging {
  cursor: grabbing;
}

.game-hud {
  position: absolute;
  z-index: 3;
  top: max(18px, env(safe-area-inset-top));
  left: max(20px, env(safe-area-inset-left));
  right: max(20px, env(safe-area-inset-right));
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  pointer-events: none;
}

.level-info {
  filter: drop-shadow(0 2px 5px rgba(255, 255, 255, 0.45));
}

.level-info p {
  margin: 0 0 4px;
  color: #9296b6;
  font-size: 8px;
  line-height: 1;
  letter-spacing: 2.2px;
  font-weight: 800;
}

.level-info h1 {
  margin: 0;
  color: #515473;
  font-size: 17px;
  line-height: 1.3;
  letter-spacing: 0.2px;
  font-weight: 800;
}

.level-track {
  width: 82px;
  height: 4px;
  margin-top: 9px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.72);
  border-radius: 999px;
  box-shadow: inset 0 1px 2px rgba(91, 94, 140, 0.09);
}

.level-track span {
  display: block;
  width: 20%;
  height: 100%;
  background: linear-gradient(90deg, #86c3ff, #8d8ae8);
  border-radius: inherit;
  box-shadow: 0 0 8px rgba(123, 148, 237, 0.38);
  transition: width 400ms cubic-bezier(0.2, 0.9, 0.25, 1.15);
}

.hud-button {
  width: 43px;
  height: 43px;
  padding: 11px;
  display: grid;
  place-items: center;
  color: #7d819e;
  background: rgba(255, 255, 255, 0.64);
  border: 1px solid rgba(255, 255, 255, 0.88);
  border-radius: 15px;
  box-shadow: 0 8px 24px rgba(97, 94, 139, 0.1), inset 0 1px 1px rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(16px);
  cursor: pointer;
  pointer-events: auto;
  transition: transform 150ms ease, background 150ms ease;
}

.hud-button:hover {
  background: rgba(255, 255, 255, 0.9);
  transform: translateY(-1px);
}

.hud-button:active {
  transform: scale(0.92);
}

.hud-button svg,
.hint-gesture svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.score-hud {
  position: absolute;
  z-index: 3;
  top: max(79px, calc(env(safe-area-inset-top) + 61px));
  left: 50%;
  min-width: 210px;
  height: 51px;
  padding: 7px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid rgba(255, 255, 255, 0.84);
  border-radius: 19px;
  box-shadow: 0 10px 30px rgba(95, 94, 137, 0.09), inset 0 1px 1px rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(18px);
  transform: translateX(-50%);
  pointer-events: none;
}

.score-item {
  display: flex;
  align-items: center;
  gap: 7px;
}

.score-item > div,
.score-territory {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
}

.score-item strong {
  color: #565975;
  font-size: 16px;
  line-height: 1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.score-item span {
  color: #9b9eb5;
  font-size: 8px;
  line-height: 1;
  font-weight: 600;
}

.score-territory {
  align-items: center;
}

.score-territory strong {
  color: #7778a6;
  font-size: 15px;
}

.score-divider {
  width: 1px;
  height: 23px;
  background: rgba(130, 130, 164, 0.11);
}

.team-orb {
  width: 23px;
  height: 23px;
  display: block;
  border-radius: 50%;
  box-shadow: 0 4px 8px rgba(91, 98, 160, 0.17), inset -1px -2px 3px rgba(75, 68, 145, 0.13);
}

.team-player {
  background: radial-gradient(circle at 30% 22%, #f5fcff 0 7%, #b5ddff 22%, #7eacfa 60%, #7277d5 100%);
}

.team-enemy {
  background: radial-gradient(circle at 30% 22%, #fff9ee 0 7%, #ffd2bf 22%, #ff9ca6 60%, #e77996 100%);
}

.status-pill {
  position: absolute;
  z-index: 2;
  top: max(139px, calc(env(safe-area-inset-top) + 121px));
  left: 50%;
  padding: 5px 11px;
  color: rgba(104, 105, 140, 0.74);
  background: rgba(255, 255, 255, 0.38);
  border-radius: 999px;
  font-size: 9px;
  line-height: 1.4;
  font-weight: 650;
  white-space: nowrap;
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  position: absolute;
  z-index: 6;
  top: max(176px, calc(env(safe-area-inset-top) + 158px));
  left: 50%;
  max-width: calc(100% - 40px);
  padding: 10px 17px;
  color: #6c6d9c;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.96);
  border-radius: 999px;
  box-shadow: 0 12px 30px rgba(96, 90, 136, 0.13);
  backdrop-filter: blur(16px);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, -8px) scale(0.96);
  pointer-events: none;
  transition: opacity 180ms ease, transform 240ms cubic-bezier(0.2, 0.9, 0.25, 1.15);
}

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

.drag-hint {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: max(22px, calc(env(safe-area-inset-bottom) + 12px));
  padding: 10px 16px 10px 11px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #696d92;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 18px;
  box-shadow: 0 12px 32px rgba(92, 91, 137, 0.12), inset 0 1px 1px rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(18px);
  font-size: 11px;
  line-height: 1.35;
  font-weight: 700;
  white-space: nowrap;
  transform: translateX(-50%);
  pointer-events: none;
  transition: opacity 250ms ease, transform 250ms ease;
  animation: hint-float 2.6s ease-in-out infinite;
}

.drag-hint small {
  display: block;
  margin-top: 2px;
  color: #a0a2b8;
  font-size: 9px;
  font-weight: 500;
}

.hint-gesture {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: #7d8ed3;
  background: linear-gradient(145deg, #edf6ff, #efedff);
  border-radius: 12px;
}

.drag-hint.hidden {
  opacity: 0;
  transform: translate(-50%, 12px);
}

.result-modal {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(229, 229, 245, 0.42);
  backdrop-filter: blur(16px) saturate(0.85);
}

.result-modal[hidden] {
  display: none;
}

.result-card {
  width: min(100%, 326px);
  padding: 35px 29px 27px;
  text-align: center;
  background: rgba(255, 255, 255, 0.91);
  border: 1px solid rgba(255, 255, 255, 0.98);
  border-radius: 34px;
  box-shadow: 0 28px 80px rgba(83, 77, 125, 0.2), inset 0 1px 1px #fff;
  animation: result-in 420ms cubic-bezier(0.18, 0.9, 0.25, 1.18);
}

.result-orb {
  position: relative;
  width: 102px;
  height: 102px;
  margin: 0 auto 25px;
  border-radius: 50%;
  background: radial-gradient(circle at 29% 20%, #fff 0 4%, #e0f2ff 13%, #95c4ff 46%, #7c9cf0 72%, #6f73d2 100%);
  box-shadow: 0 18px 30px rgba(102, 113, 199, 0.25), inset -6px -8px 14px rgba(74, 68, 155, 0.13), inset 4px 5px 10px rgba(255, 255, 255, 0.65);
  animation: result-orb-float 2.4s ease-in-out infinite;
}

.result-orb::before {
  content: "";
  position: absolute;
  width: 26px;
  height: 12px;
  left: 18px;
  top: 15px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.72);
  transform: rotate(-35deg);
}

.result-orb::after {
  content: "";
  position: absolute;
  left: 42px;
  top: 58px;
  width: 18px;
  height: 10px;
  border: solid #4d568e;
  border-width: 0 0 3px;
  border-radius: 0 0 18px 18px;
}

.result-orb i::before,
.result-orb i::after {
  content: "";
  position: absolute;
  top: 43px;
  width: 7px;
  height: 10px;
  background: #4d568e;
  border-radius: 50%;
  box-shadow: inset 1px 1px 1px rgba(255, 255, 255, 0.35);
}

.result-orb i::before { left: 29px; }
.result-orb i::after { right: 29px; }

.result-orb b::before,
.result-orb b::after {
  content: "";
  position: absolute;
  top: 58px;
  width: 13px;
  height: 6px;
  background: rgba(238, 126, 157, 0.18);
  border-radius: 50%;
}

.result-orb b::before { left: 17px; }
.result-orb b::after { right: 17px; }

.result-orb.loss {
  filter: grayscale(0.55);
  background: radial-gradient(circle at 29% 20%, #fff 0 4%, #e7e8f1 13%, #bec1d4 48%, #9296b1 100%);
}

.result-eyebrow {
  margin: 0;
  color: #9b9db7;
  font-size: 9px;
  letter-spacing: 2.4px;
  font-weight: 800;
}

.result-card h2 {
  margin: 11px 0 9px;
  color: #50536f;
  font-size: 24px;
  line-height: 1.35;
  letter-spacing: -0.5px;
}

.result-card > p:not(.result-eyebrow) {
  margin: 0 0 25px;
  color: #9597ac;
  font-size: 12px;
  line-height: 1.7;
}

.primary-button {
  width: 100%;
  padding: 15px 22px;
  color: #fff;
  background: linear-gradient(135deg, #83bff8, #8f8be8);
  border: 0;
  border-radius: 17px;
  box-shadow: 0 10px 24px rgba(119, 129, 218, 0.28), inset 0 1px 1px rgba(255, 255, 255, 0.42);
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.primary-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 28px rgba(119, 129, 218, 0.34), inset 0 1px 1px rgba(255, 255, 255, 0.42);
}

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

@keyframes hint-float {
  0%, 100% { transform: translate(-50%, 0); }
  50% { transform: translate(-50%, -5px); }
}

@keyframes result-in {
  from { opacity: 0; transform: translateY(20px) scale(0.92); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes result-orb-float {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-7px) rotate(2deg); }
}

@media (max-height: 700px) {
  .game-hud {
    top: max(12px, env(safe-area-inset-top));
  }

  .score-hud {
    top: max(66px, calc(env(safe-area-inset-top) + 54px));
  }

  .status-pill {
    display: none;
  }

  .toast {
    top: max(126px, calc(env(safe-area-inset-top) + 114px));
  }

  .drag-hint {
    bottom: max(12px, env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  .drag-hint,
  .result-card,
  .result-orb {
    animation: none;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}
