:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #f2f4ff;
  background: #11162e;
  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 82% 12%, rgba(113, 83, 190, 0.34), transparent 40%),
    radial-gradient(ellipse at 5% 54%, rgba(40, 155, 199, 0.2), transparent 42%),
    radial-gradient(ellipse at 85% 92%, rgba(190, 87, 143, 0.2), transparent 40%),
    linear-gradient(175deg, #10182f 0%, #1b2040 47%, #302342 100%);
}

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

body::before {
  top: 18%;
  left: -210px;
  background: #38b6d9;
}

body::after {
  right: -210px;
  bottom: 2%;
  background: #bd668f;
}

button {
  font: inherit;
}

button:focus-visible,
canvas:focus-visible {
  outline: 3px solid rgba(120, 225, 255, 0.5);
  outline-offset: 3px;
}

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

.game::after {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(5, 8, 26, 0.24) 100%);
  pointer-events: none;
}

#gameCanvas {
  position: absolute;
  z-index: 0;
  inset: 0;
  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(20px, env(safe-area-inset-top));
  left: max(21px, env(safe-area-inset-left));
  right: max(21px, env(safe-area-inset-right));
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  pointer-events: none;
}

.level-info p {
  margin: 0 0 5px;
  color: #8994ba;
  font-size: 8px;
  line-height: 1;
  letter-spacing: 2.5px;
  font-weight: 800;
}

.level-info h1 {
  margin: 0;
  color: #f2f4ff;
  font-size: 18px;
  line-height: 1.3;
  letter-spacing: 0.5px;
  font-weight: 750;
  text-shadow: 0 2px 16px rgba(112, 189, 255, 0.16);
}

.level-track {
  width: 86px;
  height: 4px;
  margin-top: 10px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
}

.level-track span {
  display: block;
  width: 20%;
  height: 100%;
  background: linear-gradient(90deg, #6ee7f4, #8d8cf5);
  border-radius: inherit;
  box-shadow: 0 0 10px rgba(100, 220, 255, 0.55);
  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: #d4dbf5;
  background: rgba(27, 33, 65, 0.58);
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 15px;
  box-shadow: 0 10px 28px rgba(4, 7, 24, 0.24), inset 0 1px 1px rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(18px);
  cursor: pointer;
  pointer-events: auto;
  transition: transform 150ms ease, background 150ms ease;
}

.hud-button:hover {
  background: rgba(49, 58, 98, 0.78);
  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(82px, calc(env(safe-area-inset-top) + 62px));
  left: 50%;
  min-width: 216px;
  height: 53px;
  padding: 7px 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 13px;
  background: rgba(24, 29, 60, 0.66);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  box-shadow: 0 14px 38px rgba(4, 7, 24, 0.24), inset 0 1px 1px rgba(255, 255, 255, 0.065);
  backdrop-filter: blur(22px);
  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: 2px;
}

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

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

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

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

.score-divider {
  width: 1px;
  height: 24px;
  background: rgba(255, 255, 255, 0.09);
}

.team-orb {
  width: 23px;
  height: 23px;
  display: block;
  border-radius: 50%;
}

.team-player {
  background: radial-gradient(circle at 30% 22%, #f4feff 0 6%, #a5f3ff 22%, #54c6ed 58%, #5b6ed7 100%);
  box-shadow: 0 0 13px rgba(84, 213, 249, 0.35), inset -1px -2px 3px rgba(53, 69, 158, 0.2);
}

.team-enemy {
  background: radial-gradient(circle at 30% 22%, #fff7ed 0 6%, #ffd0ba 22%, #ff91a6 58%, #d35d94 100%);
  box-shadow: 0 0 13px rgba(255, 127, 161, 0.28), inset -1px -2px 3px rgba(141, 57, 111, 0.18);
}

.status-pill {
  position: absolute;
  z-index: 2;
  top: max(143px, calc(env(safe-area-inset-top) + 123px));
  left: 50%;
  padding: 5px 11px;
  color: #9da7cc;
  background: rgba(19, 24, 53, 0.32);
  border: 1px solid rgba(255, 255, 255, 0.045);
  border-radius: 999px;
  font-size: 9px;
  line-height: 1.4;
  font-weight: 600;
  white-space: nowrap;
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  position: absolute;
  z-index: 6;
  top: max(179px, calc(env(safe-area-inset-top) + 159px));
  left: 50%;
  max-width: calc(100% - 40px);
  padding: 10px 17px;
  color: #e5eaff;
  background: rgba(37, 44, 82, 0.92);
  border: 1px solid rgba(174, 211, 255, 0.18);
  border-radius: 999px;
  box-shadow: 0 14px 34px rgba(3, 6, 23, 0.32);
  backdrop-filter: blur(18px);
  font-size: 11px;
  font-weight: 650;
  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(23px, calc(env(safe-area-inset-bottom) + 12px));
  padding: 10px 16px 10px 11px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #e0e8ff;
  background: rgba(28, 35, 69, 0.74);
  border: 1px solid rgba(145, 218, 255, 0.15);
  border-radius: 19px;
  box-shadow: 0 14px 38px rgba(3, 6, 22, 0.32), inset 0 1px 1px rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(20px);
  font-size: 11px;
  line-height: 1.35;
  font-weight: 650;
  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: 3px;
  color: #8f9cc2;
  font-size: 9px;
  font-weight: 500;
}

.hint-gesture {
  width: 35px;
  height: 35px;
  display: grid;
  place-items: center;
  color: #91eaff;
  background: linear-gradient(145deg, rgba(90, 200, 238, 0.17), rgba(132, 116, 224, 0.18));
  border: 1px solid rgba(157, 229, 255, 0.08);
  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(7, 10, 28, 0.5);
  backdrop-filter: blur(18px) saturate(0.8);
}

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

.result-card {
  width: min(100%, 326px);
  padding: 35px 29px 27px;
  text-align: center;
  background: linear-gradient(155deg, rgba(45, 52, 94, 0.97), rgba(30, 34, 70, 0.97));
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 34px;
  box-shadow: 0 30px 90px rgba(2, 4, 18, 0.48), inset 0 1px 1px rgba(255, 255, 255, 0.09);
  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%, #dcfaff 13%, #8deaff 43%, #5ab9e9 70%, #6267cf 100%);
  box-shadow: 0 0 36px rgba(92, 216, 255, 0.3), 0 18px 30px rgba(5, 9, 32, 0.28), inset -6px -8px 14px rgba(57, 60, 153, 0.16), inset 4px 5px 10px rgba(255, 255, 255, 0.62);
  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.74);
  transform: rotate(-35deg);
}

.result-orb::after {
  content: "";
  position: absolute;
  left: 42px;
  top: 58px;
  width: 18px;
  height: 10px;
  border: solid #36477d;
  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: #36477d;
  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.2);
  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%, #aeb4ce 48%, #727b9e 100%);
}

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

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

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

.primary-button {
  width: 100%;
  padding: 15px 22px;
  color: #fff;
  background: linear-gradient(135deg, #54cce9, #8279e5);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 17px;
  box-shadow: 0 12px 28px rgba(61, 172, 221, 0.24), inset 0 1px 1px rgba(255, 255, 255, 0.28);
  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 15px 32px rgba(74, 181, 229, 0.3), inset 0 1px 1px rgba(255, 255, 255, 0.28);
}

.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;
  }
}
