:root {
  --bg: #050506;
  --bg-elev: #0a0a0c;
  --surface: rgba(255, 255, 255, 0.028);
  --surface-hi: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.09);
  --border-hi: rgba(255, 255, 255, 0.18);
  --text: #ededef;
  --text-muted: #8a8f98;
  --text-dim: #565b64;
  --indigo: #6366f1;
  --indigo-soft: #8b8cf8;
  --purple: #a855f7;
  --danger: #f87171;
  --success: #4ade80;
  --radius-lg: 26px;
  --radius-md: 13px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --font: "Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* ---------- Ambient background ---------- */
.ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(99, 102, 241, 0.10), transparent 60%),
    linear-gradient(180deg, #050506 0%, #08080b 55%, #050506 100%);
}

.glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.5;
  will-change: transform, opacity;
}

.glow-a {
  width: 460px; height: 460px;
  top: -180px; left: -120px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.55), transparent 68%);
  animation: breathe 11s var(--ease) infinite;
}

.glow-b {
  width: 420px; height: 420px;
  bottom: -200px; right: -100px;
  background: radial-gradient(circle, rgba(168, 85, 247, 0.42), transparent 68%);
  animation: breathe 13s var(--ease) infinite 1.5s;
}

.glow-c {
  width: 320px; height: 320px;
  top: 38%; left: 52%;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.22), transparent 70%);
  animation: breathe 15s var(--ease) infinite 3s;
}

@keyframes breathe {
  0%, 100% { transform: scale(1) translateY(0); opacity: 0.42; }
  50% { transform: scale(1.14) translateY(-18px); opacity: 0.62; }
}

.grid-overlay {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  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: 56px 56px;
  mask-image: radial-gradient(80% 60% at 50% 40%, #000 0%, transparent 78%);
  -webkit-mask-image: radial-gradient(80% 60% at 50% 40%, #000 0%, transparent 78%);
}

.noise {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.028;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- Layout ---------- */
.stage {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 26px;
  padding: 48px 20px;
}

/* ---------- Card ---------- */
.auth-card {
  position: relative;
  width: 100%;
  max-width: 428px;
  padding: 38px 34px 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.012)),
    rgba(10, 10, 12, 0.72);
  backdrop-filter: blur(24px) saturate(150%);
  -webkit-backdrop-filter: blur(24px) saturate(150%);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.06) inset,
    0 40px 90px -30px rgba(0, 0, 0, 0.85),
    0 0 0 1px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  animation: card-in 0.9s var(--ease) both;
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(22px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

/* top shimmering highlight */
.card-sheen {
  position: absolute;
  top: 0;
  left: -40%;
  width: 180%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent);
  animation: sheen 6.5s var(--ease) infinite;
  pointer-events: none;
}

@keyframes sheen {
  0% { transform: translateX(-30%); opacity: 0; }
  18% { opacity: 0.9; }
  55% { transform: translateX(30%); opacity: 0; }
  100% { opacity: 0; }
}

/* ---------- Brand ---------- */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 30px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  border: 1px solid var(--border);
  background: linear-gradient(160deg, rgba(99, 102, 241, 0.22), rgba(168, 85, 247, 0.10));
  box-shadow: 0 0 24px -6px rgba(99, 102, 241, 0.55), 0 1px 0 rgba(255, 255, 255, 0.1) inset;
}

.brand-mark svg { width: 22px; height: 22px; display: block; }

.brand-text { display: flex; flex-direction: column; }

.brand-name {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text);
}

.brand-sub {
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--text-dim);
  font-weight: 500;
}

/* ---------- Headings ---------- */
.auth-head { margin-bottom: 26px; }

.auth-head h1 {
  margin: 0 0 6px;
  font-size: 27px;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--text);
}

.lead {
  margin: 0;
  font-size: 13.5px;
  color: var(--text-muted);
}

/* ---------- Form ---------- */
.form { display: flex; flex-direction: column; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 7px; }

.field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.control {
  position: relative;
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  transition: border-color 0.25s var(--ease), box-shadow 0.25s var(--ease),
    background-color 0.25s var(--ease);
}

.control:hover { border-color: var(--border-hi); }

.control:focus-within {
  border-color: rgba(139, 140, 248, 0.65);
  background: rgba(255, 255, 255, 0.045);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.14), 0 0 20px -6px rgba(99, 102, 241, 0.7);
}

.control-icon {
  flex: none;
  width: 17px;
  height: 17px;
  margin-left: 14px;
  fill: var(--text-dim);
  transition: fill 0.25s var(--ease);
}

.control:focus-within .control-icon { fill: var(--indigo-soft); }

.control input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 14.5px;
  padding: 13px 14px;
  letter-spacing: 0;
}

.control input::placeholder { color: var(--text-dim); }

/* hide native password reveal */
input::-ms-reveal, input::-ms-clear { display: none; }

.reveal {
  flex: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  margin-right: 4px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.2s var(--ease), background-color 0.2s var(--ease);
}

.reveal:hover { color: var(--text-muted); background: rgba(255, 255, 255, 0.05); }
.reveal svg { width: 18px; height: 18px; fill: currentColor; display: block; }
.reveal .eye-off { display: none; }
.reveal[aria-pressed="true"] .eye-open { display: none; }
.reveal[aria-pressed="true"] .eye-off { display: block; }

.field-error {
  margin: 0;
  min-height: 0;
  font-size: 12px;
  color: var(--danger);
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
}

.field.invalid .field-error { opacity: 1; transform: none; }

.field.invalid .control { border-color: rgba(248, 113, 113, 0.55); }
.field.invalid .control:focus-within {
  box-shadow: 0 0 0 4px rgba(248, 113, 113, 0.14);
}

/* ---------- Meta row ---------- */
.meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: -2px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.check input { position: absolute; opacity: 0; width: 0; height: 0; }

.check .box {
  display: grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border: 1px solid var(--border-hi);
  border-radius: 5px;
  background: var(--surface);
  transition: all 0.22s var(--ease);
}

.check .box svg {
  width: 11px; height: 11px;
  fill: none;
  stroke: #fff;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
  transform: scale(0.6);
  transition: all 0.22s var(--ease);
}

.check input:checked + .box {
  border-color: transparent;
  background: linear-gradient(150deg, var(--indigo), var(--purple));
  box-shadow: 0 0 14px -2px rgba(99, 102, 241, 0.75);
}

.check input:checked + .box svg { opacity: 1; transform: none; }

.check input:focus-visible + .box {
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.2);
}

/* ---------- Links ---------- */
.link {
  position: relative;
  color: var(--text-muted);
  font-size: 13px;
  text-decoration: none;
  transition: color 0.2s var(--ease);
}

.link::after {
  content: "";
  position: absolute;
  left: 0; bottom: -2px;
  width: 100%; height: 1px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s var(--ease);
}

.link:hover { color: var(--indigo-soft); }
.link:hover::after { transform: scaleX(1); }

/* ---------- Submit ---------- */
.submit {
  position: relative;
  display: grid;
  place-items: center;
  height: 48px;
  margin-top: 6px;
  border: 0;
  border-radius: var(--radius-md);
  color: #fff;
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  overflow: hidden;
  background: linear-gradient(135deg, var(--indigo) 0%, #7c5cf3 50%, var(--purple) 100%);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.25) inset,
    0 10px 30px -10px rgba(99, 102, 241, 0.9),
    0 0 40px -16px rgba(168, 85, 247, 0.8);
  transition: transform 0.25s var(--ease), box-shadow 0.3s var(--ease), filter 0.25s var(--ease);
}

.submit::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent);
  transform: translateX(-100%);
  transition: transform 0.7s var(--ease);
}

.submit:hover {
  transform: translateY(-1.5px);
  filter: saturate(1.12);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.3) inset,
    0 16px 40px -12px rgba(99, 102, 241, 1),
    0 0 54px -14px rgba(168, 85, 247, 0.95);
}

.submit:hover::before { transform: translateX(100%); }
.submit:active { transform: translateY(0) scale(0.992); }

.submit:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.35),
    0 10px 30px -10px rgba(99, 102, 241, 0.9);
}

.submit-label { grid-area: 1 / 1; transition: opacity 0.2s var(--ease); }

.submit-spinner {
  grid-area: 1 / 1;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  opacity: 0;
  animation: spin 0.7s linear infinite;
}

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

.submit.loading { pointer-events: none; }
.submit.loading .submit-label { opacity: 0; }
.submit.loading .submit-spinner { opacity: 1; }

/* ---------- Divider ---------- */
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0 2px;
  font-size: 11.5px;
  color: var(--text-dim);
}

.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}

/* ---------- OAuth ---------- */
.oauth { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.oauth-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  cursor: pointer;
  transition: all 0.25s var(--ease);
}

.oauth-btn svg { width: 17px; height: 17px; }

.oauth-btn:hover {
  transform: translateY(-1px);
  border-color: var(--border-hi);
  background: var(--surface-hi);
  box-shadow: 0 8px 24px -14px rgba(0, 0, 0, 0.9);
}

.oauth-btn:active { transform: translateY(0); }

.oauth-btn:focus-visible {
  outline: none;
  border-color: rgba(139, 140, 248, 0.6);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.16);
}

/* ---------- Footer ---------- */
.card-foot {
  margin: 22px 0 0;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

.page-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-dim);
}

.page-foot a { color: var(--text-dim); text-decoration: none; transition: color 0.2s; }
.page-foot a:hover { color: var(--text-muted); }

.page-foot .dot {
  width: 3px; height: 3px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 42px;
  z-index: 50;
  transform: translate(-50%, 20px);
  padding: 11px 20px;
  border: 1px solid var(--border-hi);
  border-radius: 999px;
  background: rgba(16, 16, 20, 0.86);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.9);
  transition: opacity 0.35s var(--ease), transform 0.35s var(--ease);
}

.toast::before {
  content: "";
  display: inline-block;
  width: 7px; height: 7px;
  margin-right: 9px;
  border-radius: 50%;
  background: var(--indigo-soft);
  box-shadow: 0 0 10px 1px rgba(99, 102, 241, 0.9);
  vertical-align: middle;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error::before { background: var(--danger); box-shadow: 0 0 10px 1px rgba(248, 113, 113, 0.9); }
.toast.success::before { background: var(--success); box-shadow: 0 0 10px 1px rgba(74, 222, 128, 0.9); }

/* ---------- Focus visibility fallback ---------- */
:focus-visible { outline: none; }

/* ---------- Responsive ---------- */
@media (max-width: 460px) {
  .auth-card { padding: 30px 22px 24px; border-radius: 22px; }
  .auth-head h1 { font-size: 24px; }
  .stage { padding: 30px 16px; gap: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}