:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0c0618;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background:
    radial-gradient(circle at 50% 40%, rgba(91, 45, 139, 0.34), transparent 52%),
    #0c0618;
}

body {
  display: grid;
  place-items: center;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

#game-shell {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  min-width: 1px;
  min-height: 1px;
  overflow: hidden;
  background: #130824;
  box-shadow: 0 32px 100px rgba(0, 0, 0, 0.5);
  isolation: isolate;
}

#canvas {
  position: absolute;
  inset: 0;
  display: none;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  object-fit: fill;
  touch-action: none;
}

#player-name-input {
  position: absolute;
  left: 34.6875%;
  top: 50.3333%;
  z-index: 4;
  display: none;
  width: 30.625%;
  height: max(6.4444%, 38px);
  margin: 0;
  padding: 0 1.1875%;
  border: 2px solid rgba(185, 143, 245, 0.95);
  border-radius: 12px;
  outline: 0;
  color: rgba(255, 255, 255, 0.96);
  background: #150b31;
  box-shadow: inset 0 0 18px rgba(72, 36, 128, 0.24);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: clamp(16px, 1.4375vw, 23px);
  font-weight: 500;
  line-height: 1;
  transform: translateY(-50%);
  appearance: none;
  touch-action: manipulation;
}

#player-name-input.is-active {
  display: block;
}

#player-name-input::placeholder {
  color: rgba(180, 168, 201, 0.55);
}

#player-name-input:focus {
  border-color: #c7a2ff;
  box-shadow:
    0 0 0 3px rgba(175, 124, 239, 0.2),
    inset 0 0 18px rgba(72, 36, 128, 0.24);
}

#spinner {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  place-items: center;
  overflow: hidden;
  color: rgba(255, 255, 255, 0.92);
  background:
    radial-gradient(circle at 50% 44%, rgba(65, 176, 169, 0.2), transparent 34%),
    radial-gradient(circle at 14% 8%, rgba(80, 92, 174, 0.22), transparent 34%),
    radial-gradient(circle at 86% 92%, rgba(218, 172, 72, 0.11), transparent 30%),
    linear-gradient(145deg, #07131f 0%, #102735 54%, #0a1825 100%);
  letter-spacing: 0.02em;
}

#spinner::before {
  position: absolute;
  inset: -25%;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 52px 52px;
  content: "";
  opacity: 0.28;
  pointer-events: none;
  transform: rotate(-8deg);
}

#spinner::after {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, transparent 24%, rgba(2, 8, 15, 0.34) 100%);
  content: "";
  pointer-events: none;
}

#spinner.pending,
#spinner.loading,
#spinner.error {
  display: grid;
}

.loader-content {
  position: relative;
  z-index: 1;
  display: grid;
  width: 100%;
  place-items: center;
  gap: clamp(8px, 1.5vh, 18px);
  padding: 18px;
  text-align: center;
}

.loader-logo {
  display: block;
  width: clamp(160px, 44%, 400px);
  max-height: 38vh;
  margin-bottom: clamp(2px, 1vh, 10px);
  object-fit: contain;
  filter:
    drop-shadow(0 12px 18px rgba(0, 0, 0, 0.34))
    drop-shadow(0 0 22px rgba(255, 240, 173, 0.12));
  animation: logo-arrive 700ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

#spinner strong {
  font-size: clamp(15px, 1.5vw, 22px);
  font-weight: 620;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.36);
}

#spinner small {
  color: rgba(230, 238, 241, 0.46);
  font-size: clamp(9px, 0.75vw, 11px);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.spinner-ring {
  position: relative;
  display: block;
  width: clamp(42px, 4vw, 58px);
  height: clamp(42px, 4vw, 58px);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.09);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.06),
    0 10px 28px rgba(0, 0, 0, 0.25),
    0 0 30px rgba(77, 193, 179, 0.12);
}

.spinner-ring::before,
.spinner-ring::after {
  position: absolute;
  border-radius: inherit;
  content: "";
}

.spinner-ring::before {
  inset: 0;
  background: conic-gradient(
    from 20deg,
    transparent 0deg,
    rgba(91, 198, 151, 0.2) 76deg,
    #5bc697 154deg,
    #55b9dc 238deg,
    #f1cd70 324deg,
    transparent 360deg
  );
  animation: spin 1.05s cubic-bezier(0.55, 0.18, 0.45, 0.82) infinite;
}

.spinner-ring::after {
  inset: 4px;
  display: grid;
  place-items: center;
  color: #ff8796;
  background: radial-gradient(circle at 42% 36%, #153448, #0b1c2a 72%);
  box-shadow: inset 0 0 12px rgba(255, 255, 255, 0.04);
  font-size: 22px;
  font-weight: 750;
}

#spinner.error .spinner-ring::before {
  background: conic-gradient(from 20deg, #ff8796, rgba(255, 109, 126, 0.18));
  animation: none;
}

#spinner.error .spinner-ring::after {
  content: "!";
}

.loading-message-error {
  display: none;
}

#spinner.error .loading-message-default {
  display: none;
}

#spinner.error .loading-message-error {
  display: inline;
  color: #ffd8dd;
}

#fullscreen {
  position: absolute;
  right: max(12px, env(safe-area-inset-right));
  top: max(12px, env(safe-area-inset-top));
  z-index: 4;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  color: rgba(255, 255, 255, 0.78);
  background: rgba(18, 8, 36, 0.62);
  backdrop-filter: blur(12px);
  cursor: pointer;
  opacity: 0;
  transition: opacity 150ms ease, color 150ms ease, background 150ms ease;
}

#game-shell:hover #fullscreen,
#fullscreen:focus-visible {
  opacity: 1;
}

#fullscreen:hover {
  color: #fff;
  background: rgba(52, 143, 210, 0.75);
}

#fullscreen:focus-visible {
  outline: 2px solid #55c873;
  outline-offset: 2px;
}

noscript {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  color: #fff;
  background: #130824;
  text-align: center;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes logo-arrive {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (pointer: coarse) {
  #fullscreen {
    opacity: 0.72;
  }

  #player-name-input {
    height: max(6.4444%, 44px);
    font-size: 16px;
  }
}

@media (pointer: coarse) and (orientation: portrait) {
  #player-name-input {
    left: 8%;
    width: 84%;
    height: 48px;
  }
}

@media (max-width: 420px) {
  #spinner small {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .loader-logo {
    animation: none;
  }

  .spinner-ring::before {
    animation-duration: 2.2s;
  }
}
