/* ==========================================================================
   Auth screen
   ========================================================================== */

html, body { height: 100%; }

.auth-page {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--accent-strong);
  color: var(--text);
}

.auth-bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(900px 700px at 85% -10%, rgba(255, 255, 255, 0.22), transparent 55%),
    radial-gradient(800px 700px at 0% 110%, rgba(0, 0, 0, 0.22), transparent 58%),
    linear-gradient(155deg, var(--accent) 0%, var(--accent-strong) 100%);
  z-index: 0;
}

html[data-theme="dark"] .auth-bg {
  background:
    radial-gradient(900px 700px at 85% -10%, rgba(var(--accent-rgb), 0.55), transparent 55%),
    radial-gradient(800px 700px at 0% 110%, rgba(0, 0, 0, 0.75), transparent 58%),
    linear-gradient(155deg, #17131c 0%, #0a0a0c 100%);
}

/* A short warp flight replaces the plain spinner while the sign-in request
   is in flight: stars rush out of the centre and the form is hidden behind it. */
.auth-warp {
  position: fixed;
  inset: 0;
  z-index: 20;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 50%, #2a1656 0%, #120b2a 28%, #06040f 62%, #000000 100%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s ease, visibility 0.25s;
}

.auth-warp.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.auth-page.auth-launching .auth-card {
  animation: authFold 0.42s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.auth-page.auth-launching .auth-brand {
  opacity: 0;
  transform: translateY(-18px) scale(0.96);
  transition: opacity 0.22s ease, transform 0.3s ease;
}

.warp-nebula {
  position: absolute;
  inset: -18%;
  background:
    radial-gradient(ellipse at 32% 36%, rgba(124, 82, 255, 0.34), transparent 34%),
    radial-gradient(ellipse at 72% 62%, rgba(0, 214, 198, 0.23), transparent 30%),
    radial-gradient(ellipse at 53% 76%, rgba(255, 74, 155, 0.18), transparent 28%);
  filter: blur(22px);
  animation: warpDrift 6s ease-in-out infinite alternate;
}

.warp-horizon {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 120vmax;
  height: 120vmax;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(
    circle,
    transparent 0 23%,
    rgba(133, 104, 255, 0.14) 25%,
    transparent 28% 45%,
    rgba(255, 255, 255, 0.06) 46%,
    transparent 48%
  );
  animation: warpBreathe 3.6s ease-in-out infinite;
  pointer-events: none;
}

.warp-core {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.95), rgba(139, 115, 255, 0.45) 38%, transparent 70%);
  filter: blur(3px);
  animation: warpCore 1.8s ease-in-out infinite;
}

.warp-plane {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 4;
  width: 86px;
  height: 86px;
  color: #ffffff;
  opacity: 0;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 0 18px rgba(180, 210, 255, 0.8));
  pointer-events: none;
}

.warp-plane svg {
  width: 100%;
  height: 100%;
  stroke: none;
}

.auth-warp.show .warp-plane {
  opacity: 1;
  animation: warpCruise 1.6s ease-in-out infinite;
}

.auth-warp.success .warp-plane {
  animation: warpJump 0.72s cubic-bezier(0.18, 0.82, 0.24, 1) forwards;
}

.auth-warp.crash .warp-plane {
  animation: warpCrash 0.95s cubic-bezier(0.3, 0.7, 0.35, 1) forwards;
}

.warp-asteroid {
  position: absolute;
  left: calc(50% + 22vw);
  top: calc(50% - 16vh);
  z-index: 3;
  width: 74px;
  height: 74px;
  border-radius: 46% 54% 50% 42%;
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.16), transparent 18%),
    radial-gradient(circle at 68% 62%, rgba(0, 0, 0, 0.45), transparent 28%),
    radial-gradient(circle at 45% 40%, #6b647c, #2e2a3d 58%, #15131e 100%);
  box-shadow:
    inset -8px -10px 18px rgba(0, 0, 0, 0.55),
    0 0 34px rgba(133, 104, 255, 0.3);
  opacity: 0;
  transform: translate(-50%, -50%) rotate(0deg);
}

.auth-warp.crash .warp-asteroid {
  animation: warpAsteroid 0.95s ease-out forwards;
}

.warp-flash {
  position: absolute;
  left: calc(50% + 22vw);
  top: calc(50% - 16vh);
  z-index: 5;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 0 60px 28px rgba(255, 183, 120, 0.85);
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.2);
  pointer-events: none;
}

.auth-warp.crash .warp-flash {
  animation: warpFlash 0.95s ease-out forwards;
}

.warp-stars {
  position: absolute;
  inset: 0;
}

.warp-stars i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--warp-size, 2px);
  height: var(--warp-size, 2px);
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 0 7px rgba(180, 205, 255, 0.9);
  opacity: 0;
  animation: warpFly var(--warp-dur, 1.2s) linear infinite;
  animation-delay: var(--warp-delay, 0s);
}

@keyframes warpFly {
  0% {
    transform: translate(-50%, -50%) translate(0, 0) scale(0.2);
    opacity: 0;
  }
  9% { opacity: 1; }
  100% {
    transform: translate(-50%, -50%) translate(var(--warp-x), var(--warp-y)) scale(1.35);
    opacity: 0;
  }
}

@keyframes authFold {
  0% { opacity: 1; transform: translateY(0) scale(1) rotate(0); filter: blur(0); }
  55% { opacity: 0.75; transform: translateY(-14px) scale(0.32) rotate(-4deg); filter: blur(0.5px); }
  100% { opacity: 0; transform: translateY(-42px) scale(0.04) rotate(-10deg); filter: blur(2px); }
}

@keyframes warpCruise {
  0%, 100% { transform: translate(-50%, -50%) translate(-7px, 5px) rotate(-8deg) scale(0.96); }
  50% { transform: translate(-50%, -50%) translate(9px, -7px) rotate(-3deg) scale(1.04); }
}

@keyframes warpJump {
  0% { transform: translate(-50%, -50%) rotate(-8deg) scale(1); opacity: 1; }
  62% { transform: translate(-50%, -50%) translate(0, -8px) rotate(-15deg) scale(3.1); opacity: 1; }
  100% { transform: translate(-50%, -50%) translate(0, -18px) rotate(-18deg) scale(7); opacity: 0; }
}

@keyframes warpCrash {
  0% { transform: translate(-50%, -50%) rotate(-8deg) scale(1); opacity: 1; }
  68% { transform: translate(22vw, -16vh) translate(-50%, -50%) rotate(24deg) scale(0.72); opacity: 1; }
  100% { transform: translate(22vw, -16vh) translate(-50%, -50%) rotate(34deg) scale(0.1); opacity: 0; }
}

@keyframes warpAsteroid {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(-12deg) scale(0.7); }
  45% { opacity: 1; transform: translate(-50%, -50%) rotate(8deg) scale(1.04); }
  100% { opacity: 1; transform: translate(-50%, -50%) rotate(20deg) scale(1); }
}

@keyframes warpFlash {
  0%, 60% { opacity: 0; transform: translate(-50%, -50%) scale(0.2); }
  72% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(7); }
}

@keyframes warpDrift {
  from { transform: translate3d(-2%, -1%, 0) scale(1); }
  to { transform: translate3d(3%, 2%, 0) scale(1.08); }
}

@keyframes warpBreathe {
  0%, 100% { opacity: 0.55; transform: translate(-50%, -50%) scale(0.9); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
}

@keyframes warpCore {
  0%, 100% { opacity: 0.72; transform: translate(-50%, -50%) scale(0.8); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.18); }
}

@media (prefers-reduced-motion: reduce) {
  .warp-nebula,
  .warp-horizon,
  .warp-core,
  .warp-stars i {
    animation-duration: 6s;
  }
}

.auth-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(6px);
  opacity: 0.5;
  animation: floatBlob 14s ease-in-out infinite alternate;
}

.auth-blob.b1 {
  width: 260px;
  height: 260px;
  left: -90px;
  top: 12%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.28), transparent 68%);
}

.auth-blob.b2 {
  width: 340px;
  height: 340px;
  right: -140px;
  bottom: -80px;
  background: radial-gradient(circle, rgba(0, 60, 110, 0.35), transparent 68%);
  animation-delay: -5s;
}

.auth-blob.b3 {
  width: 160px;
  height: 160px;
  right: 18%;
  top: 8%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.2), transparent 70%);
  animation-delay: -9s;
}

.auth-grid {
  position: absolute;
  inset: 0;
  opacity: 0.28;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='.22' stroke-width='1.1'%3E%3Cpath d='M20 22l6 6-6 6-6-6z'/%3E%3Ccircle cx='92' cy='30' r='5'/%3E%3Cpath d='M60 84c5 0 5 8 0 8s-5-8 0-8z'/%3E%3Cpath d='M98 92l3 6 6 .8-4.6 4.2 1.3 6.5-5.7-3.2-5.7 3.2 1.3-6.5-4.6-4.2 6-.8z'/%3E%3Cpath d='M28 92h9M32.5 87.5v9'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 120px 120px;
  mask-image: linear-gradient(to bottom, black, transparent 85%);
  -webkit-mask-image: linear-gradient(to bottom, black, transparent 85%);
}

.auth-theme {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  z-index: 5;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.24);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background 0.16s, transform 0.14s;
}

.auth-theme:hover { background: rgba(255, 255, 255, 0.26); }
.auth-theme:active { transform: scale(0.92); }
.auth-theme svg { width: 21px; height: 21px; }

.auth-theme .icon-sun { display: none; }
html[data-theme="dark"] .auth-theme .icon-sun { display: block; }
html[data-theme="dark"] .auth-theme .icon-moon { display: none; }

.auth-shell {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 0;
  padding: 0;
}

.auth-brand {
  padding: 54px 26px 26px;
  text-align: center;
  color: #fff;
  animation: authRise 0.55s var(--ease) both;
}

.auth-logo {
  width: 86px;
  height: 86px;
  margin: 0 auto 16px;
  filter: drop-shadow(0 16px 30px rgba(0, 0, 0, 0.3));
}

.auth-logo svg { width: 100%; height: 100%; }

.auth-brand h1 {
  margin: 0;
  font-size: var(--fs-hero);
  font-weight: 800;
  letter-spacing: -0.045em;
  line-height: 1.1;
}

.auth-brand p {
  margin: 8px 0 0;
  font-size: var(--fs-md);
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.8);
}

.auth-card {
  width: 100%;
  max-width: 430px;
  background: var(--bg);
  border-radius: var(--r-2xl) var(--r-2xl) 0 0;
  padding: 20px 22px calc(22px + env(safe-area-inset-bottom));
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.28);
  animation: authCardRise 0.45s var(--ease) both;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg-2);
  border-radius: var(--r-lg);
  margin-bottom: 20px;
}

.auth-tab {
  flex: 1;
  height: 39px;
  border-radius: var(--r-md);
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--muted);
  transition: background 0.18s, color 0.18s, box-shadow 0.18s;
}

.auth-tab.active {
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.auth-field {
  display: block;
  margin-bottom: 14px;
}

.auth-label {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
  margin: 0 0 6px 3px;
}

.input-shell {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 50px;
  padding: 0 14px;
  background: var(--bg-2);
  border: 1.5px solid var(--line);
  border-radius: var(--r-lg);
  transition: border-color 0.18s, background 0.18s, box-shadow 0.18s;
}

.input-shell:focus-within {
  border-color: var(--accent);
  background: var(--bg);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.14);
}

.input-prefix {
  color: var(--muted);
  font-size: var(--fs-lg);
  font-weight: 500;
  padding-right: 1px;
  user-select: none;
}

.input-shell input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: var(--fs-lg);
  padding: 0 2px;
}

.input-shell input::placeholder { color: var(--muted-2); }

.eye-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  flex: none;
  margin-right: -7px;
  transition: background 0.14s, color 0.14s;
}

.eye-btn:hover { background: var(--bg-3); color: var(--text); }
.eye-btn svg { width: 20px; height: 20px; }
.eye-btn .eye-hide { display: none; }
.eye-btn.revealed .eye-show { display: none; }
.eye-btn.revealed .eye-hide { display: block; }

.auth-hint {
  display: block;
  min-height: 0;
  margin: 5px 0 0 3px;
  font-size: var(--fs-xs);
  line-height: 1.4;
  color: var(--muted);
}

.auth-hint.ok { color: var(--online); }
.auth-hint.bad { color: var(--danger); }

.auth-error {
  margin: 2px 0 13px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: var(--fs-sm);
  line-height: 1.4;
  animation: shake 0.3s ease;
}

.auth-submit {
  position: relative;
  width: 100%;
  height: 50px;
  border-radius: var(--r-lg);
  background: linear-gradient(140deg, var(--accent), var(--accent-strong));
  color: var(--on-accent);
  font-size: var(--fs-lg);
  font-weight: 600;
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 24px rgba(var(--accent-rgb), 0.32);
  transition: transform 0.15s, box-shadow 0.15s, filter 0.15s;
  margin-top: 4px;
}

.auth-submit:hover { filter: brightness(1.03); box-shadow: 0 12px 28px rgba(var(--accent-rgb), 0.38); }
.auth-submit:active { transform: scale(0.985); }
.auth-submit:disabled { filter: saturate(0.6) brightness(0.96); cursor: default; }

.spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}

.auth-switch {
  margin: 16px 0 0;
  text-align: center;
  font-size: var(--fs-sm);
  color: var(--muted);
}

.auth-switch button {
  color: var(--accent);
  font-weight: 600;
  padding: 2px 2px;
}

.auth-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 18px 0 0;
  padding-top: 15px;
  border-top: 1px solid var(--line);
  color: var(--muted-2);
  font-size: var(--fs-2xs);
  line-height: 1.4;
  text-align: center;
}

.auth-note svg { width: 15px; height: 15px; stroke-width: 1.8; flex: none; }

.auth-field[hidden] { display: none; }

@media (min-width: 720px) {
  .auth-shell {
    justify-content: center;
    padding: 40px 20px;
  }

  .auth-brand { padding: 0 20px 26px; }

  .auth-card {
    border-radius: var(--r-2xl);
    padding-bottom: 24px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.32);
  }

  .auth-logo { width: 92px; height: 92px; }
  .auth-brand h1 { font-size: var(--fs-hero); }
}

@media (max-height: 700px) {
  .auth-brand { padding-top: 26px; padding-bottom: 16px; }
  .auth-logo { width: 66px; height: 66px; margin-bottom: 10px; }
  .auth-brand h1 { font-size: var(--fs-3xl); }
  .auth-brand p { display: none; }
  .auth-card { padding-top: 16px; }
  .auth-tabs { margin-bottom: 15px; }
}

/* Keep the whole card above the fold on short desktop windows. */
@media (min-width: 720px) and (max-height: 740px) {
  .auth-shell {
    justify-content: flex-start;
    padding: 18px 20px;
  }

  .auth-brand { padding: 0 20px 14px; }
  .auth-logo { width: 58px; height: 58px; margin-bottom: 7px; }
  .auth-brand h1 { font-size: var(--fs-3xl); }

  .auth-card { padding-top: 14px; padding-bottom: 18px; }
  .auth-tabs { margin-bottom: 14px; }
  .auth-field { margin-bottom: 12px; }
  .auth-note { margin-top: 14px; padding-top: 12px; }
}

@keyframes authCardRise {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes authRise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes floatBlob {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(14px, -18px, 0) scale(1.08); }
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.auth-legal {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
  font-size: var(--fs-xs);
  color: var(--muted);
}
.auth-legal a {
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color 0.15s;
}
.auth-legal a:hover { color: var(--accent); }
.auth-passkey {
  width: 100%;
  margin-top: 10px;
  padding: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  font-weight: 600;
}
.auth-passkey:hover { border-color: var(--accent); color: var(--accent); }
.auth-passkey svg { width: 20px; height: 20px; }
.auth-passkey:disabled { opacity: 0.55; }
.passkey-hint { display: block; margin-top: 8px; }
