:root {
  color-scheme: dark;
  --ink: #eef6ff;
  --muted: #91a5c7;
  --cyan: #55e6ff;
  --violet: #9a74ff;
  --coral: #ff765f;
  --panel: rgba(7, 12, 35, 0.78);
  --panel-strong: rgba(8, 13, 38, 0.94);
  --line: rgba(123, 173, 255, 0.28);
}

html,
body {
  background: #050817;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  position: relative;
  isolation: isolate;
}

body::before {
  content: "";
  position: fixed;
  inset: -5%;
  z-index: -2;
  background:
    radial-gradient(circle at 50% 115%, rgba(80, 59, 219, 0.34), transparent 42%),
    linear-gradient(180deg, rgba(3, 6, 20, 0.30), rgba(3, 5, 16, 0.92)),
    url("assets/arena-backdrop.png") center / cover no-repeat;
  filter: blur(22px) saturate(0.85);
  transform: scale(1.08);
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 50%, transparent 36%, rgba(1, 3, 14, 0.68) 100%),
    linear-gradient(90deg, rgba(56, 211, 255, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(56, 211, 255, 0.025) 1px, transparent 1px);
  background-size: auto, 48px 48px, 48px 48px;
}

#appShell {
  position: relative;
  padding: 18px;
  gap: 14px;
}

#gameCanvas {
  border: 1px solid rgba(126, 171, 255, 0.34);
  border-radius: 20px;
  background: #070b1f;
  box-shadow:
    0 0 0 1px rgba(1, 4, 18, 0.9),
    0 26px 80px rgba(0, 0, 14, 0.66),
    0 0 54px rgba(78, 95, 255, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.13);
  outline: none;
}

#gameCanvas:focus-visible {
  border-color: rgba(89, 230, 255, 0.86);
  box-shadow:
    0 0 0 3px rgba(57, 214, 255, 0.22),
    0 26px 80px rgba(0, 0, 14, 0.66),
    0 0 64px rgba(78, 95, 255, 0.24);
}

#utilityBar {
  position: fixed;
  z-index: 4;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  display: flex;
  gap: 7px;
  padding: 6px;
  border: 1px solid rgba(121, 166, 255, 0.18);
  border-radius: 12px;
  background: rgba(4, 8, 25, 0.58);
  box-shadow: 0 12px 32px rgba(0, 0, 12, 0.30);
  backdrop-filter: blur(16px) saturate(1.25);
}

.utilityBtn {
  min-height: 30px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #9db0d2;
  background: transparent;
  font: 700 10px/1 Inter, ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.09em;
  cursor: pointer;
  transition: color 160ms ease, background 160ms ease, border-color 160ms ease, transform 120ms ease;
}

.utilityBtn:hover {
  color: #f4f9ff;
  border-color: rgba(104, 217, 255, 0.28);
  background: rgba(62, 98, 180, 0.24);
}

.utilityBtn:active {
  transform: translateY(1px);
}

.utilityBtn:focus-visible,
.touchBtn:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

#touchControls {
  border-radius: 16px;
  padding: 7px;
  border: 1px solid rgba(122, 164, 242, 0.21);
  background: rgba(5, 9, 28, 0.68);
  box-shadow: 0 18px 44px rgba(0, 0, 15, 0.38), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(18px) saturate(1.35);
}

.touchPanel {
  gap: 8px;
}

.touchBtn {
  min-height: 46px;
  border: 1px solid rgba(107, 157, 255, 0.32);
  border-radius: 11px;
  color: #dbe7ff;
  background:
    linear-gradient(180deg, rgba(54, 72, 142, 0.72), rgba(14, 23, 66, 0.88));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.15),
    inset 0 -8px 18px rgba(0, 0, 18, 0.18),
    0 4px 12px rgba(0, 0, 16, 0.22);
  font: 800 11px/1 Inter, ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.055em;
  transition: transform 100ms ease, filter 120ms ease, border-color 120ms ease;
}

.touchBtn:hover {
  filter: brightness(1.12);
  border-color: rgba(111, 225, 255, 0.54);
}

.touchBtn:active,
.touchBtn.is-down {
  transform: translateY(2px) scale(0.985);
  border-color: #69eaff;
  color: #fff;
  background: linear-gradient(180deg, rgba(60, 100, 184, 0.88), rgba(21, 34, 94, 0.94));
}

.touchBtn.primary {
  border-color: rgba(87, 229, 255, 0.64);
  color: #ecfcff;
  background: linear-gradient(135deg, rgba(37, 175, 228, 0.84), rgba(98, 82, 226, 0.88));
}

.touchBtn.danger {
  border-color: rgba(255, 118, 95, 0.56);
  color: #ffe7e2;
  background: linear-gradient(180deg, rgba(130, 54, 78, 0.78), rgba(54, 19, 47, 0.9));
}

@media (max-width: 900px) {
  body.mobile-input #utilityBar,
  body.device-selecting #utilityBar {
    display: none;
  }
}

@media (min-width: 901px) {
  #appShell {
    grid-template-rows: minmax(0, auto) auto;
  }

  #gameCanvas {
    width: min(calc(100vw - 20px), calc(100dvh - 76px), 700px);
  }

  #utilityBar {
    position: static;
    justify-self: center;
    margin-top: -7px;
  }
}

@media (max-width: 440px) {
  #appShell {
    padding-top: max(7px, env(safe-area-inset-top));
    padding-bottom: max(7px, env(safe-area-inset-bottom));
  }

  #gameCanvas {
    border-radius: 15px;
  }

  #fullscreenToggle {
    display: none;
  }

  .utilityBtn {
    min-height: 28px;
    padding: 0 9px;
    font-size: 9px;
  }

  #touchControls {
    padding: 6px;
    border-radius: 13px;
  }

  .touchBtn {
    min-height: 41px;
    border-radius: 9px;
    font-size: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
