/* The sign-in pages (src/pages/auth.ts) and security settings. Tokens only (assets/site.css): ink and hairlines, the
   mist dot grid as the brand panel's surface, dusk blue for the second voice, pink only as a signal. Light and dark
   follow the same tokens. No layout shift: every state's space is reserved or swapped in place. */

/* `hidden` wins over every display rule below (a hidden provider, badge or state never shows): the selectors are
   more specific than any of them. */
.auth [hidden][hidden],
.sec [hidden][hidden] {
  display: none;
}

.minimal-header {
  position: static;
  border-bottom: 1px solid var(--line);
}

.auth {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  min-height: calc(100dvh - var(--header));
  padding: 40px 16px 64px;
}

.auth-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  width: 100%;
  max-width: 980px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* ---- The brand panel ---- */

.auth-panel {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-width: 0;
  padding: 40px;
  background-color: var(--mist);
  background-image: var(--dots);
  background-size: 14px 14px;
  border-right: 1px solid var(--mist-line);
}

.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--fg);
  font-weight: 600;
  font-size: 1.05rem;
  text-decoration: none;
}

.auth-value {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 500;
  line-height: 1.25;
  letter-spacing: -0.015em;
  color: var(--fg);
  text-wrap: balance;
}

.auth-proof {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--fg-soft);
  font-size: 0.93rem;
}

.auth-proof li {
  position: relative;
  padding-left: 16px;
}

.auth-proof li::before {
  content: "";
  position: absolute;
  top: 0.55em;
  left: 0;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.auth-proof strong {
  color: var(--fg);
  font-weight: 600;
}

.auth-demo {
  margin: 0;
  border: 1px solid var(--mist-line);
  border-radius: var(--radius);
  background: var(--code-bg);
  overflow: hidden;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.6;
}

/* A glimpse, not a reader: clipped and faded at the edges, never a scrollbar. */
.auth-demo pre {
  margin: 0;
  padding: 12px 14px;
  overflow: hidden;
  white-space: pre;
  mask-image: linear-gradient(to right, #000 82%, transparent);
}

.auth-req {
  border-bottom: 1px solid var(--line);
  color: var(--accent-ink);
  text-overflow: ellipsis;
}

.auth-res {
  max-height: 172px;
  mask-image: linear-gradient(to right, #000 82%, transparent), linear-gradient(to bottom, #000 70%, transparent);
  mask-composite: intersect;
}

.auth-logos {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: auto 0 0;
  padding: 0;
  list-style: none;
}

.auth-logos li {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--mist-line);
  border-radius: var(--radius-sm);
  /* The page's own surface, not the white tile: black marks are drawn in ink, which dark mode lightens. */
  background: var(--bg);
}

/* ---- The form ---- */

.auth-main {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  padding: 48px 48px 40px;
}

.auth-main h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.auth-sub {
  margin: 8px 0 24px;
  color: var(--muted);
  font-size: 0.95rem;
}

.auth-h2 {
  margin: 0 0 6px;
  font-size: 1.05rem;
  font-weight: 600;
}

.auth-body {
  margin: 0 0 16px;
  color: var(--fg-soft);
  font-size: 0.95rem;
  line-height: 1.55;
}

.auth-providers {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: 10px;
}

.auth-provider {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-weight: 500;
  font-size: 0.93rem;
  cursor: pointer;
  transition:
    border-color 0.15s,
    background-color 0.15s;
}

.auth-provider:hover {
  border-color: var(--faint);
  background: var(--bg-soft);
}

.auth-provider[disabled] {
  cursor: progress;
  opacity: 0.7;
}

.auth-last {
  position: absolute;
  top: -9px;
  right: 8px;
  padding: 1px 7px;
  border: 1px solid var(--accent-line);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.auth-or {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 22px 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.auth-or::before,
.auth-or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.auth-form {
  display: grid;
  gap: 4px;
}

.auth-field {
  display: grid;
  gap: 6px;
}

.auth-field label {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--fg);
}

.auth-field input,
.sec-form input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 1rem; /* 16px: no zoom on focus in iOS */
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

.auth-field input:hover {
  border-color: var(--faint);
}

.auth-field input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.auth-field input[aria-invalid="true"] {
  border-color: var(--err);
}

.auth-field input[aria-invalid="true"]:focus-visible {
  box-shadow: 0 0 0 3px var(--err-soft);
}

.auth-field input.auth-code,
.sec-form input.auth-code {
  font-family: var(--mono);
  font-size: 1.25rem;
  letter-spacing: 0.35em;
  text-align: center;
}

.auth-pw {
  position: relative;
}

.auth-pw input {
  padding-right: 64px;
}

.auth-pw-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  min-height: 32px;
  padding: 0 8px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
}

.auth-pw-toggle:hover {
  color: var(--fg);
}

/* Reserved: an error appears without moving anything. */
.auth-error {
  min-height: 1.35em;
  margin: 0 0 6px;
  color: var(--err);
  font-size: 0.84rem;
  line-height: 1.35;
}

.auth-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.auth-form-error {
  min-height: 1.4em;
  margin: 10px 0 0;
  color: var(--err);
  font-size: 0.88rem;
  line-height: 1.45;
}

.auth-aside {
  margin: -2px 0 10px;
  font-size: 0.86rem;
}

.auth-aside a,
.auth-link {
  color: var(--accent-ink);
}

.auth-link {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.auth-turnstile:empty {
  display: none;
}

.auth-turnstile {
  margin: 4px 0 12px;
}

.auth-submit {
  position: relative;
  width: 100%;
  min-height: 46px;
  margin-top: 6px;
  font-size: 0.97rem;
}

/* The spinner takes no space until the button is busy, and the label never moves. */
.auth-spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: auth-spin 0.7s linear infinite;
}

[aria-busy="true"] .auth-spinner {
  display: inline-block;
}

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

@media (prefers-reduced-motion: reduce) {
  .auth-spinner {
    animation-duration: 2.4s;
  }

  .auth-provider,
  .auth-field input {
    transition: none;
  }
}

.auth-switch,
.auth-legal {
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.auth-switch a {
  color: var(--fg);
  font-weight: 500;
}

.auth-legal {
  margin-top: 12px;
  font-size: 0.8rem;
}

.auth-legal a {
  color: inherit;
}

.auth-mail-apps {
  display: flex;
  gap: 8px;
  margin: 0 0 16px;
}

.auth-resend {
  width: 100%;
}

.auth-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 12px;
}

.auth-key-list {
  display: grid;
  gap: 8px;
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
}

.auth-key-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}

.auth-key-name {
  grid-column: 1 / -1;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.auth-key-list code {
  overflow-wrap: anywhere;
  font-size: 0.82rem;
}

.auth-sr,
.auth-logos .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---- Phones: one column; the panel shrinks to the mark and the promise ---- */

@media (max-width: 760px) {
  .auth {
    place-items: start center;
    padding: 16px 16px 40px;
  }

  .auth-card {
    grid-template-columns: minmax(0, 1fr);
  }

  .auth-panel {
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-right: 0;
    border-bottom: 1px solid var(--mist-line);
  }

  .auth-brand span {
    display: none;
  }

  .auth-value {
    font-size: 0.95rem;
    font-weight: 500;
  }

  .auth-proof,
  .auth-demo,
  .auth-logos {
    display: none;
  }

  .auth-main {
    padding: 28px 20px 28px;
  }

  .auth-main h1 {
    font-size: 1.4rem;
  }
}

/* ---- /security/ ---- */

.sec {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px 64px;
}

.sec-section {
  padding: 24px 0;
  border-top: 1px solid var(--line);
}

.sec-section h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
  font-weight: 600;
}

.sec-list {
  display: grid;
  gap: 8px;
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
}

.sec-list li {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.sec-form {
  max-width: 420px;
}

.sec-secret {
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  overflow-wrap: anywhere;
}

.sec-reauth {
  width: min(420px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg);
  color: var(--fg);
  box-shadow: var(--shadow-lg);
}

.sec-reauth::backdrop {
  background: var(--backdrop);
}

.sec-reauth h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}
