:root {
  --ink: #161616;
  --paper: #f3f3f1;
  --card: #ffffff;
  --line: #e3e3e0;
  --muted: #6b6b66;
  --danger: #c62828;
  --ok: #2e7d32;
  --warn: #ed6c02;
  --tap: 3rem;
  --radius: 14px;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
}

html, body { margin: 0; min-height: 100%; }

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  overflow-x: hidden;
  width: 100%;
  max-width: 100%;
  background:
    radial-gradient(1200px 480px at 50% -10%, #ffffff 0%, transparent 60%),
    var(--paper);
  color: var(--ink);
  font-family: "IBM Plex Sans Arabic", "IBM Plex Sans", Tahoma, sans-serif;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.55;
  padding:
    max(1.25rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(1.5rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
}

.pane {
  width: min(100%, 26rem);
  max-width: 100%;
  min-width: 0;
  background: var(--card);
  border: 1px solid rgba(0, 0, 0, 0.04);
  border-radius: calc(var(--radius) + 6px);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.03), 0 16px 40px rgba(0, 0, 0, 0.06);
  padding: clamp(1.25rem, 4vw, 1.75rem);
}

.pane:has(.profile) {
  width: min(100%, 32rem);
}

.pane:has(.account-shell) {
  width: min(100%, 54rem);
}

.profile .lede {
  margin: 0 0 0.85rem;
  color: var(--muted);
}

.account-hero {
  margin-bottom: 0.35rem;
}

.avatar-editor {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.1rem;
  margin: 0.75rem 0 0.5rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f7f7f5;
}

.avatar-frame {
  position: relative;
  flex: 0 0 auto;
  display: block;
  width: 112px;
  height: 112px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.avatar-frame:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.avatar-preview {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #ebeae6;
  display: grid;
  place-items: center;
}

.avatar-preview img,
.avatar-dialog-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar-fallback {
  font-size: 2.25rem;
  font-weight: 600;
  color: var(--muted);
  line-height: 1;
}

.avatar-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(22, 22, 22, 0.48);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 500;
  opacity: 0;
  transition: opacity 160ms ease;
}

.avatar-frame:hover .avatar-overlay,
.avatar-frame:focus-visible .avatar-overlay {
  opacity: 1;
}

.avatar-fields {
  flex: 1 1 12rem;
  min-width: 0;
}

.avatar-title {
  margin: 0 0 0.2rem;
  font-weight: 500;
}

.avatar-fields .hint {
  margin: 0 0 0.65rem;
}

.avatar-fields button.secondary.avatar-open {
  width: auto;
  margin-top: 0;
  min-height: 2.75rem;
  padding: 0 1rem;
}

.avatar-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
  opacity: 0;
}

.account-layout {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-top: 0.75rem;
  min-width: 0;
  max-width: 100%;
}

.account-nav {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.25rem;
  margin: 0;
  padding: 0.25rem;
  overflow: visible;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f7f7f5;
}

.account-nav-item {
  box-sizing: border-box;
  margin: 0;
  min-width: 0;
  min-height: 2.75rem;
  height: 2.75rem;
  padding: 0 0.55rem;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 500;
  font-size: 0.92rem;
  line-height: 2.75rem;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease;
}

.account-nav-item:hover { color: var(--ink); }

.account-nav-item.is-active,
.account-nav-item[aria-selected="true"] {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.account-panels {
  position: relative;
  min-width: 0;
  display: grid;
}

.account-panel.profile-section {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

/* Stack panels so the content area keeps a stable height across tabs. */
.account-panel {
  grid-area: 1 / 1;
  min-width: 0;
}

.account-panel[hidden] {
  /* Keep in the grid so tab switches do not change pane height. */
  display: block !important;
  visibility: hidden;
  pointer-events: none;
  z-index: 0;
}

.account-panel.is-active {
  visibility: visible;
  pointer-events: auto;
  z-index: 1;
}

.account-divider {
  height: 1px;
  margin: 1.35rem 0 1.1rem;
  background: var(--line);
}

.account-signout {
  margin-top: 1.25rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
}


.verify-methods {
  margin: 0.85rem 0 0.15rem;
  padding: 0;
  border: 0;
}

.verify-methods legend {
  padding: 0;
  font-size: 0.92rem;
  font-weight: 500;
}

.verify-methods ul {
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.verify-methods label {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2.4rem;
  font-weight: 400;
  cursor: pointer;
}

.verify-methods input[type="radio"] {
  width: 1.05rem;
  height: 1.05rem;
  margin: 0;
  accent-color: var(--ink);
}

.profile-section {
  margin-top: 1.35rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--line);
}

.profile-section h2 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
  font-weight: 600;
}

@media (min-width: 768px) {
  .account-layout {
    display: grid;
    grid-template-columns: 12.5rem minmax(0, 1fr);
    gap: 1.5rem;
    align-items: start;
    margin-top: 1rem;
  }

  .account-nav {
    display: flex;
    flex-direction: column;
    overflow: visible;
    position: sticky;
    top: 1rem;
    padding: 0.35rem;
  }

  .account-nav-item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    height: 2.75rem;
    min-height: 2.75rem;
    padding: 0 0.85rem;
    font-size: inherit;
    line-height: 1.2;
    text-align: start;
    overflow: visible;
    text-overflow: clip;
  }
}

.profile textarea {
  width: 100%;
  min-height: 5.5rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafafa;
  color: var(--ink);
  padding: 0.7rem 0.85rem;
  font: inherit;
  resize: vertical;
}

.profile textarea:focus {
  outline: none;
  border-color: var(--ink);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(22, 22, 22, 0.08);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  margin-top: 0.55rem;
}

.action-row form.inline button[type="submit"] {
  width: auto;
  margin-top: 0;
}

.identity-list {
  list-style: none;
  margin: 0.55rem 0 0;
  padding: 0;
}

.identity-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem 0.75rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--line);
}

.identity-label {
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}

.link-code {
  margin-top: 0.85rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f7f7f5;
}

.code-value {
  margin: 0.25rem 0;
  font-size: 1.55rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  font-variant-numeric: tabular-nums;
}

.brand { margin-bottom: 1.35rem; }

/* The wordmark is Latin. Keep it left-to-right even when the page is Farsi. */
.logo-frame {
  direction: ltr;
  unicode-bidi: isolate;
  background: #000;
  border-radius: var(--radius);
  padding: clamp(0.85rem, 3vw, 1.15rem) clamp(0.7rem, 2.5vw, 1rem);
  overflow: hidden;
}

.logo {
  display: block;
  width: 100%;
  height: auto;
  transform: none;
}

.brand-line,
.brand-return {
  margin: 0.9rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  overflow-wrap: anywhere;
  text-align: center;
}

form.lang {
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  align-items: center;
  margin: 0 0 0.35rem;
}

.lang button[type="submit"],
button.quiet {
  background: transparent;
  color: var(--muted);
  border: 0;
  margin: 0.15rem 0 0;
  padding: 0.55rem 0.15rem;
  min-height: 2.75rem;
  width: auto;
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: color 160ms ease;
}

.lang button[type="submit"] {
  margin: 0;
}

.lang button[type="submit"]:hover,
button.quiet:hover { color: var(--ink); }

.lang button[type="submit"]:disabled,
button.quiet:disabled {
  color: var(--muted);
  opacity: 0.55;
  cursor: not-allowed;
}

h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.3rem, 2.6vw, 1.5rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

form {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.15rem;
}

label {
  margin-top: 0.85rem;
  font-size: 0.92rem;
  font-weight: 500;
}

.optional,
.req { font-weight: 400; font-size: 0.82rem; }
.optional { color: var(--muted); }
.req { color: var(--ink); }

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

label.sublabel {
  margin: 0 0 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: 0.25rem;
  margin: 0.95rem 0 0.15rem;
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f7f7f5;
}

.tab {
  margin: 0;
  min-height: 2.6rem;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease;
}

.tab:hover { color: var(--ink); }

.tab.is-active,
.tab[aria-selected="true"] {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.tabs-secondary {
  margin-top: 0.85rem;
  background: #f0f0ed;
}

.tab-panel[hidden],
[data-password-block][hidden] { display: none; }

.contact-row {
  display: flex;
  direction: ltr;
  unicode-bidi: isolate;
  align-items: flex-end;
  gap: 0.4rem;
  margin-top: 0.35rem;
  min-width: 0;
  max-width: 100%;
}

.contact-row .country { flex: 0 0 5.75rem; }

.contact-row input[name="country_code"] { text-align: center; padding-left: 0.4rem; padding-right: 0.4rem; }

.contact-row input[name="phone_number"],
.contact-row input[name="identifier"] {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
}

.field-status {
  display: none;
  align-items: center;
  gap: 0.4rem;
  min-height: 1.35rem;
  margin: 0.25rem 0 0;
  font-size: 0.88rem;
  font-weight: 500;
}

.field-status[data-state] { display: flex; }

.field-status[data-state="ok"] { color: var(--ok); }
.field-status[data-state="bad"] { color: var(--danger); }
.field-status[data-state="warn"] { color: var(--warn); }

.status-icon {
  flex: 0 0 auto;
  width: 1.1rem;
  height: 1.1rem;
  display: inline-grid;
  place-items: center;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  font-size: 0.72rem;
  line-height: 1;
  font-weight: 700;
}

.field-status[data-state="ok"] .status-icon::before { content: "✓"; }
.field-status[data-state="bad"] .status-icon::before { content: "✕"; }

.status-text { min-width: 0; overflow-wrap: anywhere; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
select {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafafa;
  color: var(--ink);
  padding: 0.7rem 0.85rem;
  font: inherit;
  font-size: 1rem;
  appearance: none;
  transition: border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

select {
  max-width: 100%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23161616' d='M1.4 0.6L6 5.2 10.6 0.6 12 2 6 8 0 2z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  background-size: 0.75rem;
  padding-right: 2.25rem;
  cursor: pointer;
}

[dir="rtl"] select {
  background-position: left 0.85rem center;
  padding-right: 0.85rem;
  padding-left: 2.25rem;
}

/* Latin credentials type from the left even when the page is Farsi. */
input[type="email"],
input[type="password"],
input[type="tel"],
input[dir="ltr"] {
  direction: ltr;
  unicode-bidi: isolate;
  text-align: left;
}

input:hover,
select:hover { border-color: #cfcfcb; }

input:focus,
select:focus {
  outline: none;
  border-color: var(--ink);
  background-color: #fff;
  box-shadow: 0 0 0 4px rgba(22, 22, 22, 0.08);
}

input:focus {
  background: #fff;
}

/* Three button styles, used the same way on every page:
   primary   (submit, or .primary): the one main action of a form or section
   secondary (.secondary): alternatives, resend, passkey
   quiet     (.quiet): small inline actions such as Remove or Sign out */
button[type="submit"]:not(.quiet),
button.primary,
button.secondary {
  margin-top: 1.2rem;
  background: var(--ink);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 0.8rem 1.1rem;
  min-height: var(--tap);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

button[type="submit"]:not(.secondary):not(.quiet):hover:not(:disabled),
button.primary:hover:not(:disabled) { background: #000; }

button[type="submit"]:not(.secondary):not(.quiet):active:not(:disabled),
button.primary:active:not(:disabled),
button.secondary:active:not(:disabled) { transform: translateY(1px); }

button[type="submit"]:not(.quiet):disabled,
button.primary:disabled,
button.secondary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

button[type="submit"]:not(.quiet),
button.primary,
button.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
}

button.secondary,
button[type="submit"].secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

button.secondary:hover:not(:disabled) {
  background: #fafafa;
  border-color: #cfcfcb;
}

.btn-icon {
  flex: 0 0 auto;
  display: block;
  width: 1.15rem;
  height: 1.15rem;
}

/* A countdown must not make the button jump in width as digits change. */
button[data-countdown] { font-variant-numeric: tabular-nums; }

/* "or" between the main form and an alternative (passkey sign-in). */
.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.1rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.divider[hidden] { display: none; }

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

/* Stacked full-width buttons with even spacing (passkeys, send code). */
.button-stack {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 1rem;
}

.button-stack[hidden] { display: none; }

.button-stack > button,
.button-stack > form > button { margin-top: 0; }

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 1.1rem;
  margin-top: 0.7rem;
}

.links a {
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

a.button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: var(--tap);
  background: var(--ink);
  color: #fff;
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.8rem 1.1rem;
  font-weight: 500;
  transition: background 160ms ease, border-color 160ms ease;
}

a.button:hover { background: #000; }

a.button.secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

a.button.secondary:hover {
  background: #fafafa;
  border-color: #cfcfcb;
}

.errors,
.errorlist,
.notices {
  margin: 0.4rem 0 0;
  padding: 0;
  list-style: none;
  color: var(--danger);
  overflow-wrap: anywhere;
  font-size: 0.92rem;
}

.notice-success { color: var(--ink); }

[data-server-notices][hidden] { display: none !important; }

.toasts {
  position: fixed;
  z-index: 40;
  inset-inline: 0;
  bottom: max(1rem, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1rem;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  width: min(100%, 24rem);
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.4;
  overflow-wrap: anywhere;
  animation: toast-in 180ms ease;
}

.toast-success {
  border-color: rgba(46, 125, 50, 0.25);
  background: #f3faf3;
  color: var(--ok);
}

.toast-error {
  border-color: rgba(198, 40, 40, 0.22);
  background: #fff5f5;
  color: var(--danger);
}

.toast-warning {
  border-color: rgba(237, 108, 2, 0.25);
  background: #fff8f1;
  color: var(--warn);
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(0.4rem);
  transition: opacity 180ms ease, transform 180ms ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(0.55rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

button.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

button.is-loading > * {
  visibility: hidden;
}

button.is-loading::after {
  content: "";
  position: absolute;
  inset-block-start: 50%;
  inset-inline-start: 50%;
  width: 1.1rem;
  height: 1.1rem;
  margin-block-start: -0.55rem;
  margin-inline-start: -0.55rem;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

button.secondary.is-loading::after,
button.quiet.is-loading::after,
.lang button.is-loading::after {
  border-color: rgba(22, 22, 22, 0.2);
  border-top-color: var(--ink);
}

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

@media (prefers-reduced-motion: reduce) {
  .toast,
  .toast.is-leaving,
  button.is-loading::after {
    animation: none;
    transition: none;
  }
}

form.inline { margin-top: 0.1rem; }

.otp {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  direction: ltr;
  unicode-bidi: isolate;
  gap: 0.4rem;
  width: 100%;
  margin: 0.35rem 0 0;
}

form.otp-form input.otp-digit[type="text"] {
  width: 100%;
  min-width: 0;
  min-height: var(--tap);
  padding: 0;
  text-align: center;
  font-size: 1.25rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

.otp-form button.secondary {
  width: 100%;
  margin-top: 0.55rem;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 420px) {
  .pane {
    border-radius: 18px;
    padding: 1.15rem 1rem 1.35rem;
  }

  .links {
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none;
  }
}

.totp-qr {
  display: block;
  margin: 0.75rem auto;
  padding: 0.5rem;
  background: #fff;
  border-radius: 8px;
}

.backup-codes {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.25rem 1rem;
}

/* Account page: section headers and modal dialog. Kept last so they
   override the shared button rules above. */
/* Section header: title on one side, the section's Save on the other. */
.section-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0 0 0.35rem;
  padding: 0.25rem 0;
  background: var(--card);
}

.profile-section .section-head h2 {
  margin: 0;
  min-width: 0;
}

.section-head > button.section-save[type] {
  flex: 0 0 auto;
  width: auto;
  margin: 0;
  min-height: 2.75rem;
  padding: 0 1.15rem;
}

/* Modal dialog (native <dialog>: focus trap, Esc and inert page for free). */
.modal {
  width: min(calc(100% - 2rem), 26rem);
  max-height: calc(100dvh - 2rem);
  margin: auto;
  padding: 1.1rem 1.25rem 1.25rem;
  border: 0;
  border-radius: calc(var(--radius) + 6px);
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.22);
  overflow: auto;
}

.modal::backdrop {
  background: rgba(22, 22, 22, 0.5);
}

.modal[open] {
  animation: modal-in 200ms ease-out;
}

.modal[open]::backdrop {
  animation: backdrop-in 200ms ease-out;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(0.75rem) scale(0.98); }
  to { opacity: 1; transform: none; }
}

@keyframes backdrop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 0 0 0.75rem;
}

.modal-head h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.modal-close {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  margin: -0.5rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease;
}

.modal-close:hover { background: #f3f3f1; color: var(--ink); }

.modal-close:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.modal-text {
  margin: 0 0 0.25rem;
}

.modal form { margin: 0; }

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.modal-actions > button[type],
.modal-actions > label.button {
  width: auto;
  margin: 0;
  min-height: 2.75rem;
}

/* Destructive action sits apart, on the leading edge. */
.modal-actions > .danger.quiet {
  margin-inline-end: auto;
}

.modal-actions > label.button.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 1rem;
  font-weight: 500;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease;
}

.modal-actions > label.button.secondary:hover {
  background: #fafafa;
  border-color: #cfcfcb;
}

.modal-actions > label.button.secondary:focus-visible,
form:has(.avatar-file-input:focus-visible) [data-avatar-pick] {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.avatar-dialog-preview {
  display: grid;
  place-items: center;
  width: 176px;
  height: 176px;
  margin: 0.25rem auto 0.75rem;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #ebeae6;
  cursor: pointer;
}

.avatar-dialog-preview .avatar-fallback {
  font-size: 3.25rem;
}

.avatar-dialog-hint {
  text-align: center;
  margin: 0;
}

button.danger:not(.quiet) {
  background: var(--danger);
  color: #fff;
}

button[type="submit"].danger:not(.secondary):not(.quiet):hover:not(:disabled) {
  background: #a51f1f;
}

button.quiet.danger { color: var(--danger); }
button.quiet.danger:hover { color: #a51f1f; }

/* Phones: the dialog becomes a bottom sheet within thumb reach. */
@media (max-width: 480px) {
  .modal {
    width: 100%;
    max-width: 100%;
    margin: auto 0 0;
    border-radius: calc(var(--radius) + 6px) calc(var(--radius) + 6px) 0 0;
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
  }

  .modal-actions > button[type],
  .modal-actions > label.button {
    flex: 1 1 auto;
  }

  .modal-actions > .danger.quiet {
    flex-basis: 100%;
    order: 1;
    margin: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .modal[open],
  .modal[open]::backdrop {
    animation: none;
  }
}
