/* Sign-in stage. Reads the same theme tokens as the app. */

#auth[hidden] { display: none; }
.auth-stage {
  position: fixed; inset: 0; z-index: 45; overflow-y: auto;
  /* Bottom room keeps the fixed demo/preview note clear of the form. */
  display: grid; place-items: center; padding: 48px 28px calc(96px + env(safe-area-inset-bottom));
  background: var(--canvas);
}
.auth-backdrop {
  position: fixed; inset: -10%; pointer-events: none;
  background:
    radial-gradient(40% 36% at 18% 12%, var(--glow-a), transparent 70%),
    radial-gradient(36% 34% at 86% 8%, var(--glow-b), transparent 70%),
    radial-gradient(46% 40% at 50% 100%, color-mix(in srgb, var(--user) 75%, transparent), transparent 70%);
  animation: auth-drift 18s ease-in-out infinite alternate;
}
@keyframes auth-drift { to { transform: translate3d(14px, -10px, 0); } }

.auth-col {
  position: relative; width: min(420px, 100%); display: flex; flex-direction: column; align-items: center; text-align: center;
  animation: auth-step 260ms var(--ease);
}
@keyframes auth-step { from { opacity: 0; transform: translateX(18px); } }

.auth-halo { position: relative; width: var(--size); height: var(--size); margin-bottom: 18px; transition: width 260ms var(--ease), height 260ms var(--ease); }
.auth-halo img { position: relative; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; box-shadow: 0 10px 28px var(--shadow); }
.auth-halo .glow {
  position: absolute; inset: -22%; border-radius: 50%; filter: blur(14px); opacity: .8;
  background: conic-gradient(from 200deg, #F7C9B5, #CFC4F3, #BFE0F7, #F7C9B5);
}
html[data-scheme="dark"] .auth-halo .glow { opacity: .35; }
.auth-halo.is-busy .glow { animation: breathe 2.2s ease-in-out infinite; }
.auth-halo .arc {
  position: absolute; inset: -10px; border-radius: 50%; border: 2px solid var(--line);
  border-top-color: var(--accent); animation: spin 1.4s linear infinite;
}

.auth-hero { margin: 4px 0 0; font-size: 28px; font-weight: 600; letter-spacing: .2px; }
.auth-title { margin: 0 0 26px; font-size: 28px; font-weight: 600; }

.auth-form { width: 100%; display: flex; flex-direction: column; gap: 14px; }
.auth-field {
  display: flex; align-items: center; gap: 10px; height: 56px; padding: 0 16px; border-radius: 18px;
  background: var(--card-solid); box-shadow: 0 0 0 .5px var(--line), 0 2px 10px color-mix(in srgb, var(--shadow) 50%, transparent);
  color: var(--muted); transition: box-shadow 160ms, color 160ms;
}
.auth-field:focus-within { color: var(--accent); box-shadow: 0 0 0 1.5px var(--accent), 0 0 0 6px color-mix(in srgb, var(--accent) 16%, transparent); }
.auth-field input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 17px; }
.auth-field input::placeholder { color: var(--faint); }

.auth-primary, .auth-secondary {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; height: 54px; border-radius: 999px; font-size: 16px; font-weight: 600;
  transition: transform 120ms, background 160ms, color 160ms;
}
.auth-primary {
  background: linear-gradient(rgba(255,255,255,.16), rgba(255,255,255,0) 60%), var(--primary); color: var(--on-primary);
  box-shadow: 0 10px 24px color-mix(in srgb, var(--shadow) 140%, transparent);
}
.auth-primary:active:not(:disabled), .auth-secondary:active:not(:disabled) { transform: scale(.98); }
.auth-primary:disabled { background: var(--control); color: var(--muted); box-shadow: none; }
.auth-primary:disabled:has(.auth-spin) { background: var(--primary); color: var(--on-primary); }
.auth-secondary { background: var(--card-solid); box-shadow: 0 0 0 .5px var(--line), 0 3px 10px var(--shadow); }
.auth-actions { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.auth-spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }

.auth-pill {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%; margin: -12px 0 22px; padding: 4px 4px 4px 14px; border-radius: 999px;
  background: color-mix(in srgb, var(--card-solid) 70%, transparent); box-shadow: 0 0 0 .5px var(--line);
}
.auth-pill-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.auth-pill button { flex: none; height: 30px; padding: 0 12px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }

.otp { position: relative; display: block; }
.otp input {
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; border: 0; font-size: 16px;
  /* Transparent but focusable and hit-testable, so paste, autofill and screen readers use the real field. */
}
.otp-cells { display: grid; grid-template-columns: repeat(6, minmax(0, 56px)); justify-content: center; gap: 8px; pointer-events: none; }
.otp-cells span {
  position: relative; height: 60px; border-radius: 16px; display: grid; place-items: center;
  background: var(--card-solid); box-shadow: 0 0 0 .5px var(--line);
  font: 600 26px/1 ui-rounded, var(--font); font-variant-numeric: tabular-nums; color: var(--ink);
  transition: box-shadow 140ms, background 140ms;
}
.otp-cells span.is-filled { animation: auth-pop 160ms var(--ease); }
@keyframes auth-pop { from { transform: scale(.86); } }
.otp-cells span.is-active { box-shadow: 0 0 0 1.5px var(--accent), 0 0 0 5px color-mix(in srgb, var(--accent) 14%, transparent); }
.otp-cells span.is-active:empty::after { content: ""; width: 2px; height: 26px; background: var(--accent); animation: blink 1s steps(2) infinite; }
.otp.is-error .otp-cells span { background: var(--danger-fill); box-shadow: 0 0 0 1.5px var(--danger); color: var(--danger); }
.otp.is-expired .otp-cells span { color: var(--faint); background: color-mix(in srgb, var(--card-solid) 60%, transparent); }
.otp.shake { animation: auth-shake 360ms ease-in-out; }
@keyframes auth-shake { 20% { transform: translateX(-8px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(2px); } }

.auth-resend { min-height: 44px; margin-top: 10px; display: flex; align-items: center; justify-content: center; font-size: 14px; }
.auth-resend button { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 10px; color: var(--accent); font-weight: 500; }
.auth-countdown { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-variant-numeric: tabular-nums; }
.auth-countdown .ring { width: 14px; height: 14px; border-radius: 50%; background: conic-gradient(var(--muted) calc(var(--p) * 360deg), var(--line) 0); }
.auth-expired { color: var(--danger); }

.auth-msg { width: 100%; min-height: 0; margin-top: 14px; }
.auth-note {
  display: flex; align-items: flex-start; gap: 8px; padding: 10px 14px; border-radius: 16px; text-align: left; font-size: 14px; line-height: 1.5;
  color: var(--ink); background: color-mix(in srgb, var(--accent) 8%, transparent); animation: fade 200ms ease-out;
}
.auth-note svg { flex: none; margin-top: 2px; color: var(--accent); }
.auth-note.is-error { background: var(--danger-fill); }
.auth-note.is-error svg { color: var(--danger); }

.auth-switch { margin: 22px 0 0; font-size: 14px; color: var(--muted); }
.auth-switch button { min-height: 44px; padding: 0 4px; color: var(--accent); font-weight: 600; }

.auth-demo {
  position: fixed; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); translate: -50% 0; margin: 0;
  padding: 6px 12px; border-radius: 999px; font-size: 12px; color: var(--muted);
  border: 1px dashed var(--faint); background: var(--card-solid);
}

.auth-preview {
  position: fixed; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); translate: -50% 0;
  display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 32px);
  padding: 6px 6px 6px 8px; border-radius: 999px; font-size: 13px;
  background: var(--card-solid); box-shadow: 0 0 0 1px color-mix(in srgb, var(--moon) 45%, transparent), 0 6px 18px var(--shadow);
}
.auth-preview-tag { flex: none; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; color: var(--moon); background: color-mix(in srgb, var(--moon) 14%, transparent); }
.auth-preview-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); font-variant-numeric: tabular-nums; }
.auth-preview button { flex: none; min-height: 30px; padding: 0 12px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
@media (max-width: 420px) { .auth-preview { flex-wrap: wrap; justify-content: center; border-radius: 18px; } .auth-preview-text { white-space: normal; text-align: center; } }

.demo-chip {
  position: fixed; left: 12px; bottom: 12px; z-index: 40; display: inline-flex; align-items: center; gap: 6px;
  min-height: 32px; padding: 0 12px; border-radius: 999px; font-size: 12px; color: var(--muted);
  background: var(--card-solid); border: 1px dashed var(--faint);
}
body.auth-open .demo-chip { display: none; }

/* ---------- Browser device authorization gate ---------- */

#device-gate[hidden] { display: none; }
.device-stage { z-index: 46; align-items: start; padding-top: 88px; }
body.device-open .demo-chip { display: none; }

.device-top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 20px 12px;
  background: color-mix(in srgb, var(--canvas) 72%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
}
.device-account { display: inline-flex; align-items: center; gap: 8px; min-width: 0; font-size: 14px; color: var(--muted); }
.device-account span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-account svg { flex: none; }
.device-signout {
  flex: none; min-height: 36px; padding: 0 14px; border-radius: 999px; font-size: 14px; font-weight: 600;
  color: var(--ink); background: var(--card-solid); box-shadow: 0 0 0 .5px var(--line), 0 2px 8px var(--shadow);
}
.device-signout:hover { background: color-mix(in srgb, var(--card-solid) 90%, var(--ink)); }

.device-col { width: min(460px, 100%); gap: 0; animation: none; }
.device-col.is-new { animation: auth-step 260ms var(--ease); }
.device-art { margin: 8px 0 18px; filter: drop-shadow(0 8px 18px var(--shadow)); }
.device-title { margin-bottom: 8px; }
.device-lede { margin: 0 0 22px; font-size: 15px; line-height: 1.6; color: var(--muted); max-width: 34ch; }
.device-loading { display: inline-flex; align-items: center; gap: 10px; margin-top: 14px; color: var(--muted); }

.device-flow { list-style: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; margin: 0 0 24px; padding: 0; }
.device-flow li {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 6px 12px; border-radius: 18px;
  font-size: 13px; color: var(--muted); background: color-mix(in srgb, var(--card-solid) 70%, transparent); box-shadow: 0 0 0 .5px var(--line);
}
.device-flow b {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.device-card {
  width: 100%; margin: 6px 0 14px; padding: 16px 18px; border-radius: 22px; text-align: left;
  background: var(--card-solid); box-shadow: 0 0 0 .5px var(--line), 0 4px 16px color-mix(in srgb, var(--shadow) 70%, transparent);
}
.device-card-title { margin: 0 0 10px; font-size: 13px; font-weight: 500; color: var(--muted); }
.device-code-text {
  margin: 0; padding: 12px 14px; border-radius: 14px; background: var(--code);
  font: 500 15px/1.6 var(--mono); letter-spacing: .2px; color: var(--ink);
  word-break: break-all; user-select: all; -webkit-user-select: all; cursor: text;
}
.device-code-text:focus-visible { outline-offset: 0; }
.device-code-missing { margin: 0; font-size: 14px; color: var(--muted); }
.device-code-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.device-expiry { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.device-copy { min-height: 36px; padding: 0 14px; gap: 6px; }
.device-copy.is-copied { color: var(--success); }
.device-code.is-expired .device-code-text { color: var(--faint); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--faint) 60%, transparent); user-select: none; }
.device-code.is-expired .device-expiry { color: var(--danger); }

.device-phone { margin-bottom: 22px; }
.device-path { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 12px; font-size: 14px; }
.device-path span { padding: 3px 9px; border-radius: 8px; background: var(--control); }
.device-path span:last-child { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); font-weight: 600; }
.device-path .device-app { font-weight: 600; }
.device-path svg { color: var(--faint); flex: none; }
.device-steps { margin: 0; padding-left: 22px; display: grid; gap: 6px; font-size: 15px; line-height: 1.5; }
.device-steps li::marker { color: var(--accent); font-weight: 600; }

.device-msg { width: 100%; }
.device-msg:not(:empty) { margin-top: 14px; }
.device-note-body { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.device-note-detail { font-size: 12px; color: var(--muted); font-family: var(--mono); word-break: break-word; }
.device-note-action { flex: none; align-self: center; min-height: 32px; padding: 0 12px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--card-solid); box-shadow: 0 0 0 .5px var(--line); }
.device-info { color: var(--ink); }
.device-info svg { color: var(--muted); }

.device-cancel { margin-top: 10px; min-height: 44px; padding: 0 12px; font-size: 14px; color: var(--muted); display: inline-flex; align-items: center; gap: 8px; }
.device-cancel:hover:not(:disabled) { color: var(--danger); }

.device-done {
  width: 72px; height: 72px; margin: 40px 0 18px; border-radius: 50%; display: grid; place-items: center;
  color: var(--success); background: color-mix(in srgb, var(--success) 12%, transparent);
  animation: auth-pop 260ms var(--ease);
}

@media (max-width: 420px) {
  .device-stage { padding-left: 20px; padding-right: 20px; }
  .device-flow { grid-template-columns: 1fr; }
  .device-flow li { flex-direction: row; justify-content: flex-start; padding: 10px 14px; }
}

@media (max-width: 420px) {
  .otp-cells { gap: 6px; }
  .otp-cells span { height: 54px; font-size: 23px; }
}
@media (prefers-reduced-motion: reduce) {
  .auth-backdrop, .auth-col, .auth-halo .arc, .otp.shake { animation: none !important; }
}
