/* Invite-only cinematic UFO welcome / auth gate — hard lock */

html.auth-locked,
body.auth-locked {
  overflow: hidden !important;
  height: 100% !important;
  background: #010308 !important;
}

/* Nothing except the login gate is reachable */
body.auth-locked > *:not(#auth-gate) {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
  opacity: 0 !important;
}

body.auth-locked #auth-gate {
  display: grid !important;
  visibility: visible !important;
  pointer-events: auto !important;
  opacity: 1 !important;
}

body.auth-ok #auth-gate {
  display: none !important;
}

#auth-gate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  place-items: center;
  padding: 1.25rem;
  overflow: hidden;
  background: #010308;
}

.auth-stars-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.auth-atmosphere {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.auth-nebula {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  mix-blend-mode: screen;
  opacity: 0.55;
}

.auth-nebula-a {
  width: min(70vw, 640px);
  height: min(70vw, 640px);
  top: -18%;
  left: 50%;
  transform: translateX(-50%);
  background: radial-gradient(circle, rgba(61, 255, 232, 0.35), transparent 70%);
  animation: authNebula 10s ease-in-out infinite alternate;
}

.auth-nebula-b {
  width: min(50vw, 480px);
  height: min(50vw, 480px);
  bottom: 5%;
  right: -8%;
  background: radial-gradient(circle, rgba(125, 255, 77, 0.22), transparent 70%);
  animation: authNebula 14s ease-in-out infinite alternate-reverse;
}

.auth-floor-grid {
  position: absolute;
  left: -20%;
  right: -20%;
  bottom: -5%;
  height: 55%;
  background-image:
    linear-gradient(rgba(61, 255, 232, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(125, 255, 77, 0.06) 1px, transparent 1px);
  background-size: 48px 48px;
  transform: perspective(700px) rotateX(68deg);
  transform-origin: center top;
  mask-image: linear-gradient(180deg, transparent, #000 30%, transparent 95%);
  -webkit-mask-image: linear-gradient(180deg, transparent, #000 30%, transparent 95%);
  animation: authGridPulse 6s ease-in-out infinite;
}

.auth-scan-beam {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    105deg,
    transparent 42%,
    rgba(61, 255, 232, 0.05) 49%,
    rgba(125, 255, 77, 0.08) 50%,
    rgba(61, 255, 232, 0.05) 51%,
    transparent 58%
  );
  background-size: 220% 100%;
  animation: authSweep 8s ease-in-out infinite;
}

/* ── 3D UFO stage ── */
.auth-stage {
  position: absolute;
  top: 6%;
  left: 50%;
  transform: translateX(-50%);
  width: min(420px, 88vw);
  height: min(280px, 42vh);
  z-index: 2;
  perspective: 900px;
  pointer-events: none;
}

.auth-ufo {
  --px: 0px;
  --py: 0px;
  position: absolute;
  left: 50%;
  top: 18%;
  width: 220px;
  height: 120px;
  transform: translateX(-50%) translate(var(--px), var(--py)) rotateX(18deg);
  transform-style: preserve-3d;
  animation: authUfoFloat 4.5s ease-in-out infinite;
  transition: transform 0.35s ease-out;
}

.auth-ufo-glow {
  position: absolute;
  left: 50%;
  top: 55%;
  width: 180px;
  height: 60px;
  transform: translate(-50%, -50%);
  background: radial-gradient(ellipse, rgba(61, 255, 232, 0.45), transparent 70%);
  filter: blur(12px);
  animation: authGlow 2.8s ease-in-out infinite;
}

.auth-ufo-dome {
  position: absolute;
  left: 50%;
  top: 8px;
  width: 78px;
  height: 42px;
  transform: translateX(-50%);
  border-radius: 50% 50% 40% 40%;
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.55), transparent 40%),
    linear-gradient(180deg, rgba(61, 255, 232, 0.85), rgba(8, 40, 50, 0.9));
  box-shadow:
    0 0 24px rgba(61, 255, 232, 0.55),
    inset 0 -8px 16px rgba(0, 0, 0, 0.35);
  z-index: 3;
}

.auth-ufo-saucer {
  position: absolute;
  left: 50%;
  top: 38px;
  width: 200px;
  height: 48px;
  transform: translateX(-50%);
  border-radius: 50%;
  background:
    radial-gradient(ellipse at 50% 35%, rgba(200, 255, 240, 0.25), transparent 45%),
    linear-gradient(180deg, #1a3a42 0%, #0a161c 45%, #062028 100%);
  border: 1px solid rgba(61, 255, 232, 0.45);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.55),
    0 0 30px rgba(61, 255, 232, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
  z-index: 2;
}

.auth-ufo-ring {
  position: absolute;
  left: 50%;
  top: 48px;
  border-radius: 50%;
  border: 1px solid rgba(61, 255, 232, 0.35);
  transform: translateX(-50%) rotateX(72deg);
  transform-style: preserve-3d;
  box-shadow: 0 0 12px rgba(61, 255, 232, 0.2);
}

.auth-ufo-ring-1 {
  width: 240px;
  height: 70px;
  animation: authRingSpin 10s linear infinite;
  border-top-color: var(--cyan, #3dffe8);
}

.auth-ufo-ring-2 {
  width: 280px;
  height: 82px;
  top: 44px;
  border-color: rgba(125, 255, 77, 0.25);
  border-left-color: var(--accent, #7dff4d);
  animation: authRingSpin 7s linear infinite reverse;
}

.auth-ufo-ring-3 {
  width: 160px;
  height: 48px;
  top: 52px;
  border-color: rgba(255, 179, 71, 0.3);
  animation: authRingSpin 5s linear infinite;
}

.auth-ufo-lights {
  position: absolute;
  left: 50%;
  top: 58px;
  width: 170px;
  height: 14px;
  transform: translateX(-50%);
  display: flex;
  justify-content: space-between;
  z-index: 4;
  padding: 0 18px;
}

.auth-ufo-lights i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent, #7dff4d);
  box-shadow: 0 0 10px var(--accent, #7dff4d);
  animation: authLightBlink 1.4s ease-in-out infinite;
}

.auth-ufo-lights i:nth-child(2) { animation-delay: 0.15s; background: var(--cyan, #3dffe8); box-shadow: 0 0 10px var(--cyan, #3dffe8); }
.auth-ufo-lights i:nth-child(3) { animation-delay: 0.3s; }
.auth-ufo-lights i:nth-child(4) { animation-delay: 0.45s; background: var(--cyan, #3dffe8); box-shadow: 0 0 10px var(--cyan, #3dffe8); }
.auth-ufo-lights i:nth-child(5) { animation-delay: 0.6s; }
.auth-ufo-lights i:nth-child(6) { animation-delay: 0.75s; background: #ffb347; box-shadow: 0 0 10px #ffb347; }

.auth-ufo-tractor {
  position: absolute;
  left: 50%;
  top: 78px;
  width: 90px;
  height: 160px;
  transform: translateX(-50%);
  background: linear-gradient(180deg, rgba(61, 255, 232, 0.35), rgba(125, 255, 77, 0.08), transparent);
  clip-path: polygon(32% 0, 68% 0, 100% 100%, 0 100%);
  filter: blur(0.5px);
  opacity: 0.65;
  animation: authTractor 3.2s ease-in-out infinite;
  z-index: 1;
}

.auth-holo-pad {
  position: absolute;
  left: 50%;
  bottom: 4%;
  transform: translateX(-50%);
  width: 160px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(61, 255, 232, 0.35);
  box-shadow:
    0 0 24px rgba(61, 255, 232, 0.25),
    inset 0 0 20px rgba(61, 255, 232, 0.12);
  animation: authPadPulse 2.4s ease-in-out infinite;
}

.auth-holo-pad span {
  position: absolute;
  inset: 20%;
  border-radius: 50%;
  border: 1px solid rgba(125, 255, 77, 0.25);
}

.auth-holo-pad span:nth-child(2) { inset: 35%; animation: authPadPulse 2.4s ease-in-out infinite 0.2s; }
.auth-holo-pad span:nth-child(3) { inset: 48%; }

/* Welcome lines */
.auth-welcome {
  position: absolute;
  top: min(38vh, 300px);
  left: 0;
  right: 0;
  z-index: 3;
  text-align: center;
  pointer-events: none;
  font-family: var(--font-display, Orbitron, sans-serif);
}

.auth-welcome-line {
  margin: 0.2rem 0;
  font-size: 0.68rem;
  letter-spacing: 0.28em;
  color: rgba(61, 255, 232, 0.55);
  opacity: 0;
  transform: translateY(10px);
}

.auth-welcome-hero {
  margin-top: 0.55rem;
  font-size: clamp(0.95rem, 3.5vw, 1.25rem);
  letter-spacing: 0.18em;
  color: #e7fff4;
  text-shadow: 0 0 24px rgba(61, 255, 232, 0.45);
}

body.auth-welcome-play .auth-welcome-line {
  animation: authLineIn 0.7s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

body.auth-welcome-play .auth-welcome-line[data-line="0"] { animation-delay: 0.15s; }
body.auth-welcome-play .auth-welcome-line[data-line="1"] { animation-delay: 0.55s; }
body.auth-welcome-play .auth-welcome-line[data-line="2"] { animation-delay: 1s; }

/* Login card */
.auth-gate-card {
  position: relative;
  width: min(420px, 100%);
  padding: 1.75rem 1.5rem 1.4rem;
  text-align: center;
  z-index: 5;
  margin-top: min(42vh, 340px);
  opacity: 0;
  transform: translateY(28px) scale(0.96);
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.55),
    0 0 40px rgba(61, 255, 232, 0.08);
}

body.auth-welcome-play .auth-gate-card {
  animation: authCardIn 0.85s cubic-bezier(0.22, 1, 0.36, 1) 1.35s forwards;
}

.auth-card-hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.auth-card-corner {
  position: absolute;
  width: 14px;
  height: 14px;
  border-color: var(--cyan, #3dffe8);
  border-style: solid;
  border-width: 0;
  opacity: 0.7;
}

.auth-card-corner.tl { top: 6px; left: 6px; border-top-width: 2px; border-left-width: 2px; }
.auth-card-corner.tr { top: 6px; right: 6px; border-top-width: 2px; border-right-width: 2px; }
.auth-card-corner.bl { bottom: 6px; left: 6px; border-bottom-width: 2px; border-left-width: 2px; }
.auth-card-corner.br { bottom: 6px; right: 6px; border-bottom-width: 2px; border-right-width: 2px; }

.auth-gate-sector {
  font-family: var(--font-display);
  font-size: 0.62rem;
  letter-spacing: 0.22em;
  color: var(--cyan);
  margin: 0 0 0.85rem;
}

.auth-gate-title {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 5vw, 2.1rem);
  letter-spacing: 0.1em;
  margin: 0 0 0.45rem;
  background: linear-gradient(120deg, var(--plasma), var(--cyan), var(--accent));
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: authTitleShine 5s ease infinite;
  filter: drop-shadow(0 0 18px rgba(61, 255, 232, 0.3));
}

.auth-gate-sub,
.auth-gate-hint {
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.45;
  margin: 0 0 1.1rem;
}

.auth-gate-hint {
  margin: 1rem 0 0;
  font-size: 0.75rem;
  letter-spacing: 0.02em;
}

.auth-login-form {
  display: grid;
  gap: 0.75rem;
  text-align: left;
}

.auth-field {
  display: grid;
  gap: 0.35rem;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.auth-field input {
  width: 100%;
  min-height: 46px;
  padding: 0.65rem 0.8rem;
  border-radius: 4px;
  border: 1px solid rgba(61, 255, 232, 0.28);
  background: rgba(0, 0, 0, 0.45);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
  letter-spacing: normal;
  text-transform: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.auth-field input:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(61, 255, 232, 0.12), 0 0 20px rgba(61, 255, 232, 0.12);
}

.auth-login-btn {
  width: 100%;
  margin-top: 0.25rem;
}

.auth-error {
  margin: 0;
  color: var(--error);
  font-size: 0.85rem;
  line-height: 1.4;
}

.auth-logout-btn,
.auth-logout-alien {
  position: fixed;
  top: calc(0.45rem + env(safe-area-inset-top, 0px));
  right: 0.45rem;
  left: auto;
  z-index: 100000;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.auth-logout-btn:hover,
.auth-logout-alien:hover {
  transform: scale(1.08);
}

.auth-logout-btn img,
.auth-logout-alien img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  filter: drop-shadow(0 0 8px rgba(61, 255, 232, 0.45));
}

.auth-ambience-toggle {
  margin-top: 0.85rem;
  border: 1px solid rgba(61, 255, 232, 0.25);
  background: transparent;
  color: rgba(61, 255, 232, 0.65);
  font-family: var(--font-display);
  font-size: 0.55rem;
  letter-spacing: 0.16em;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  border-radius: 2px;
}

.auth-ambience-toggle:hover,
.auth-ambience-toggle[aria-pressed="true"] {
  color: var(--cyan);
  border-color: rgba(61, 255, 232, 0.5);
}

.auth-ambience-toggle[aria-pressed="false"] {
  color: var(--text-muted);
  opacity: 0.7;
}

@keyframes authNebula {
  from { transform: translateX(-50%) scale(1); opacity: 0.4; }
  to { transform: translateX(-48%) scale(1.08); opacity: 0.65; }
}

@keyframes authGridPulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.75; }
}

@keyframes authSweep {
  0% { background-position: 120% 0; }
  100% { background-position: -120% 0; }
}

@keyframes authUfoFloat {
  0%, 100% { transform: translateX(-50%) translate(var(--px), var(--py)) rotateX(18deg); }
  50% { transform: translateX(-50%) translate(var(--px), calc(var(--py) - 12px)) rotateX(22deg); }
}

@keyframes authGlow {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

@keyframes authRingSpin {
  from { transform: translateX(-50%) rotateX(72deg) rotateZ(0deg); }
  to { transform: translateX(-50%) rotateX(72deg) rotateZ(360deg); }
}

@keyframes authLightBlink {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.75); }
}

@keyframes authTractor {
  0%, 100% { opacity: 0.4; transform: translateX(-50%) scaleX(0.92); }
  50% { opacity: 0.75; transform: translateX(-50%) scaleX(1.08); }
}

@keyframes authPadPulse {
  0%, 100% { opacity: 0.45; box-shadow: 0 0 16px rgba(61, 255, 232, 0.15); }
  50% { opacity: 1; box-shadow: 0 0 28px rgba(61, 255, 232, 0.4); }
}

@keyframes authLineIn {
  to { opacity: 1; transform: none; }
}

@keyframes authCardIn {
  to { opacity: 1; transform: none; }
}

@keyframes authTitleShine {
  0%, 100% { background-position: 0% center; }
  50% { background-position: 100% center; }
}

@media (max-width: 768px) {
  .auth-stage {
    top: 4%;
    height: min(220px, 34vh);
  }

  .auth-ufo {
    transform: translateX(-50%) scale(0.82) rotateX(18deg);
    animation-name: authUfoFloatMobile;
  }

  @keyframes authUfoFloatMobile {
    0%, 100% { transform: translateX(-50%) scale(0.82) translate(var(--px), var(--py)) rotateX(18deg); }
    50% { transform: translateX(-50%) scale(0.82) translate(var(--px), calc(var(--py) - 10px)) rotateX(22deg); }
  }

  .auth-gate-card {
    margin-top: min(36vh, 280px);
  }

  .auth-logout-btn,
  .auth-logout-alien {
    top: calc(0.4rem + env(safe-area-inset-top, 0px));
    right: 0.4rem;
    left: auto;
    bottom: auto;
    width: 38px;
    height: 38px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .auth-ufo,
  .auth-ufo-ring,
  .auth-ufo-lights i,
  .auth-ufo-tractor,
  .auth-nebula,
  .auth-scan-beam,
  .auth-floor-grid,
  .auth-holo-pad,
  .auth-gate-title {
    animation: none !important;
  }

  .auth-welcome-line,
  .auth-gate-card {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
  }
}
