/* Account and subscription pages (sign-in, sign-up, password reset, plan,
   payment confirmation, account). Built on site.css: same tokens, same
   buttons and fields, a narrower column. */

.account-hero {
  padding: 56px 20px 40px;
}

.account-hero h1 {
  font-size: var(--text-title);
}

.account-hero .lead {
  margin-top: 12px;
  font-size: var(--text-body);
}

@media (min-width: 640px) {
  .account-hero {
    padding: 80px 32px 48px;
  }
}

.account-body {
  width: 100%;
  max-width: 440px;
  margin-inline: auto;
  padding: 0 16px 72px;
}

.account-body.plan {
  max-width: 480px;
}

.account-body .card {
  padding: 24px 20px;
  box-shadow: var(--shadow-sm);
}

@media (min-width: 640px) {
  .account-body {
    padding-bottom: 96px;
  }

  .account-body .card {
    padding: 28px;
  }
}

.account-loading,
.account-closed {
  margin: 0;
  color: var(--ink-secondary);
  text-align: center;
}

.account-loading[data-tone="error"] {
  color: var(--red-ink);
}

.account-closed {
  font-size: var(--text-body);
  line-height: 1.5;
}

.button-block {
  width: 100%;
}

.form .button-block {
  justify-self: stretch;
  height: 48px;
  font-size: 16px;
}

.button-secondary {
  background: var(--fill);
  color: var(--ink);
  box-shadow: none;
}

.button-secondary:hover {
  background: var(--fill-strong);
  color: var(--ink);
}

/* .card p in site.css would otherwise colour and space every line of a card. */
.account-body .hint {
  color: var(--ink-tertiary);
  font-size: var(--text-caption);
}

/* Busy: the label gives way to a spinner, the button keeps its colour. */
.button[aria-busy="true"] {
  position: relative;
  opacity: 1;
  color: transparent;
}

.button[aria-busy="true"] > * {
  visibility: hidden;
}

.button[aria-busy="true"]::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 18px;
  height: 18px;
  margin: auto;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: account-spin 0.7s linear infinite;
}

.button-secondary[aria-busy="true"]::after {
  border-color: rgba(0, 0, 0, 0.15);
  border-top-color: var(--ink);
}

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

.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--brand);
  font: inherit;
  cursor: pointer;
}

.link-button:hover {
  text-decoration: underline;
}

/* Sign-in and sign-up ---------------------------------------------------- */

.auth-providers {
  display: grid;
  gap: 10px;
}

.provider {
  height: 48px;
  gap: 8px;
  font-size: 16px;
}

/* Apple's black button, as its guidelines ask. */
.provider-apple,
.provider-apple:hover {
  background: #000000;
  color: #ffffff;
}

.provider-logo {
  flex: none;
}

.provider-apple .provider-logo {
  margin-top: -3px;
}

.account-body .auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--ink-tertiary);
  font-size: var(--text-caption);
}

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

.field-link {
  justify-self: end;
  font-size: 14px;
}

.auth-card .form-message {
  margin-top: 16px;
}

.auth-switch {
  margin: 20px 0 0;
  color: var(--ink-secondary);
  font-size: 15px;
  text-align: center;
}

/* Plan ------------------------------------------------------------------------ */

.plan-card {
  display: grid;
  gap: 20px;
}

.choice {
  display: grid;
  gap: 8px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.choice legend {
  padding: 0;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* An iOS segmented control made of radios. */
.segmented {
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  gap: 2px;
  padding: 2px;
  border-radius: 10px;
  background: var(--fill);
}

.segmented label {
  position: relative;
  display: block;
  /* The thumb is the feedback; the mobile tap flash would cover it. */
  -webkit-tap-highlight-color: transparent;
}

.segmented input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented span {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 8px;
  border-radius: 8px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 500;
}

.segmented input:checked + span {
  font-weight: 600;
}

/* Without :has(), each checked segment carries its own thumb. */
@supports not selector(:has(*)) {
  .segmented input:checked + span {
    background: var(--bg-card);
    box-shadow:
      0 3px 8px rgba(0, 0, 0, 0.12),
      0 0 0 0.5px rgba(0, 0, 0, 0.04);
  }
}

/* One thumb that slides to the checked segment, like iOS, so the bold label
   and the white pill always move together. --n is the segment count. */
@supports selector(:has(*)) {
  .segmented {
    position: relative;
  }

  .segmented::before {
    content: "";
    position: absolute;
    top: 2px;
    bottom: 2px;
    inset-inline-start: 2px;
    width: calc((100% - 4px - (var(--n) - 1) * 2px) / var(--n));
    border-radius: 8px;
    background: var(--bg-card);
    box-shadow:
      0 3px 8px rgba(0, 0, 0, 0.12),
      0 0 0 0.5px rgba(0, 0, 0, 0.04);
    transform: translateX(calc(var(--i, 0) * (100% + 2px)));
    /* A layer of its own from the start: promoting it only while it slides
       re-renders the labels above it at both ends, which flickers. */
    will-change: transform;
  }

  .segmented:has(label:nth-child(2) input:checked) { --i: 1; }
  .segmented:has(label:nth-child(3) input:checked) { --i: 2; }
  .segmented:has(label:nth-child(4) input:checked) { --i: 3; }
  .segmented:has(label:nth-child(5) input:checked) { --i: 4; }

  /* Only once the page has restored the last choice, so it never slides on load. */
  .is-ready .segmented::before {
    transition: transform 0.3s var(--ease-apple);
  }

  /* The label turns bold as the thumb arrives, not before. */
  .is-ready .segmented span {
    transition: font-weight 0.3s var(--ease-apple);
  }
}

@media (prefers-reduced-motion: reduce) {
  .is-ready .segmented::before,
  .is-ready .segmented span {
    transition: none;
  }
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

.segmented-numbers span {
  font-variant-numeric: tabular-nums;
}

.plan-price {
  min-height: 46px;
}

.account-body .price-line {
  color: var(--ink);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  margin: 0;
}

.price-now {
  font-family: var(--font-display);
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
}

.price-was {
  color: var(--ink-tertiary);
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
}

.price-unit {
  color: var(--ink-secondary);
  font-size: 17px;
}

.account-body .price-detail {
  margin: 4px 0 0;
  color: var(--ink-secondary);
  font-size: 15px;
}

.price-skeleton {
  display: block;
  width: 160px;
  height: 40px;
  border-radius: 8px;
  background: var(--fill);
  animation: account-pulse 1.4s ease-in-out infinite;
}

@keyframes account-pulse {
  50% {
    opacity: 0.5;
  }
}

@media (prefers-reduced-motion: reduce) {
  .price-skeleton {
    animation: none;
  }
}

.plan-failed {
  display: grid;
  justify-items: start;
  gap: 12px;
  margin-top: -8px;
}

/* The country whose App Store prices are shown, found from the visitor's IP. */
.account-body .plan-country {
  margin: -8px 0 0;
  color: var(--ink-secondary);
  font-size: 15px;
}

.account-body .plan-note {
  margin: -8px 0 0;
  color: var(--ink);
  font-size: 15px;
}

.plan-failed p,
.plan-error p {
  margin: 0;
  color: var(--red-ink);
  font-size: 15px;
}

.account-body .plan-trial {
  margin: -8px 0 0;
  color: var(--ink);
  font-size: 15px;
  font-weight: 500;
}

.promo {
  display: grid;
  gap: 8px;
  font-size: 15px;
}

/* A grid item stretches: the link would centre its text across the card. */
.promo > .link-button {
  justify-self: start;
}

.promo-form {
  display: flex;
  gap: 8px;
}

.promo-form input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.promo-form input::placeholder {
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink-tertiary);
}

.promo-form input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.15);
}

.account-body .promo-applied {
  margin: 0;
  color: var(--ink);
  font-weight: 500;
}

.account-body .promo-applied::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-inline-end: 8px;
  border-radius: 50%;
  background: var(--green);
  vertical-align: 1px;
}

.account-body .promo-applied .link-button {
  margin-inline-start: 6px;
  font-weight: 400;
}

.account-body .promo-message {
  margin: 0;
  color: var(--ink-secondary);
}

.account-body .promo-message[data-tone="error"] {
  color: var(--red-ink);
}

.plan-error {
  display: grid;
  justify-items: start;
  gap: 12px;
  margin-top: -8px;
}

.account-body .plan-fine,
.account-body .plan-signed-in {
  margin: -4px 0 0;
  color: var(--ink-tertiary);
  font-size: var(--text-caption);
  line-height: 1.45;
}

.account-body .plan-signed-in {
  margin-top: -12px;
  overflow-wrap: anywhere;
}

/* Account ------------------------------------------------------------------- */

.account-stack {
  display: grid;
  gap: 16px;
}

.identity {
  display: grid;
  gap: 16px;
  margin: 0;
}

.identity dt {
  color: var(--ink-secondary);
  font-size: var(--text-caption);
}

.identity dd {
  margin: 2px 0 0;
  font-size: 17px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.subscription-card {
  display: grid;
  justify-items: start;
  gap: 12px;
}

.subscription-card h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.subscription-card p {
  margin: 0;
  color: var(--ink-secondary);
  font-size: 15px;
  line-height: 1.5;
}

.no-web {
  display: grid;
  justify-items: start;
  gap: 12px;
}

.no-web p {
  color: var(--ink);
}

.sign-out {
  justify-self: center;
}

/* After payment ---------------------------------------------------------- */

.account-body.success {
  padding-top: 56px;
}

.success-card {
  display: grid;
  justify-items: center;
  gap: 16px;
  text-align: center;
}

.success-mark {
  color: var(--green);
}

.success-card h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-title);
  font-weight: 700;
  letter-spacing: -0.025em;
}

.account-body .success-text {
  margin: 0;
  color: var(--ink-secondary);
  font-size: var(--text-body);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.account-body .success-soon {
  margin: 0;
  padding: 12px 16px;
  border-radius: var(--radius-tile);
  background: var(--bg-alt);
  font-weight: 500;
}

.success-manage {
  font-size: 15px;
}

@media (min-width: 640px) {
  .account-body.success {
    padding-top: 96px;
  }
}
