/* S3 (#169): onboarding and authentication in Lantern. The signed-out pages
   (sign in, register, reset, MFA, restore, step-up completion) keep their own
   centred layout, outside the S2 shell. The installation's lockup is the
   headline (#227, web only); the art is drawn from Lantern shapes only, with
   one honey glow behind the mark; the seasonal decoration (#242) sits behind
   the lockup and never on the mark itself. Colours come from tokens.css. */

/* #422: the page's width steps (the band, the phone card, the stacked tabs) are measured in
   the page's own text, not the browser's default size: a media query's rem never grows when
   only the text does (text-only zoom, a reader's own font size), so at 200% the desktop
   columns, the band's lockup and the two tabs kept layouts their words no longer fit. A
   container query's rem is the root's actual size. The frame is the page's full width with
   no padding of its own, so at 100% each step falls where its media query did; a classic
   scrollbar, where the page scrolls, now counts against the width. */
.auth-frame { container: auth / inline-size; }

.auth-shell {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  grid-template-rows: 1fr auto;
  gap: 2rem;
  padding: clamp(1.25rem, 5vw, 4rem);
  place-items: center;
  background: var(--ground);
}

.auth-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 28rem);
  align-items: center;
  gap: clamp(2rem, 7vw, 7rem);
  width: min(100%, 72rem);
}

/* ---- The intro: lockup, art, decoration ---- */

.auth-intro {
  position: relative;
  isolation: isolate;
  display: grid;
  justify-items: center;
  gap: 2rem;
  min-width: 0;
  padding: 1.5rem 1rem;
  text-align: center;
}

.lockup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  min-width: 0;
  max-width: 100%;
}

/* In the intro the lockup leaves the outer columns to the seasonal decoration. */
.auth-intro .lockup { max-width: 76%; }

.lockup-mark {
  position: relative;
  display: block;
  flex: none;
}

/* The one honey glow: behind the mark, never baked into it. On the wide sign-in screen it
   is the lantern's light (Lantern Next L5): wide, soft, and still. */
.lockup-mark::before {
  position: absolute;
  z-index: -1;
  inset: -55%;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--presence) 34%, transparent) 0%, transparent 68%);
  content: "";
}
.auth-intro .lockup-mark::before {
  inset: -190%;
  background: radial-gradient(circle,
    color-mix(in srgb, var(--presence) 36%, transparent) 0%,
    color-mix(in srgb, var(--presence) 14%, transparent) 38%,
    transparent 70%);
}

.lockup-mark img {
  display: block;
  width: 6rem;
  height: 6rem;
  border-radius: 22%;
}

.lockup-text {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
}

.lockup-name {
  margin: 0;
  font-family: var(--display-font);
  font-size: clamp(1.5rem, 11vw, 3.4rem);
  font-weight: 800;
  line-height: 1.04;
  letter-spacing: var(--display-tracking);
  overflow-wrap: break-word;
  text-wrap: balance;
}

.lockup-sub {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--type-label);
  font-weight: 500;
}

/* "on ChitChat" is signed with the one-colour mark (the mark family, #227): a renamed
   installation's own icon and name lead, and ChitChat signs quietly beneath. The mark
   is drawn as a mask in the text's colour, so it follows every scheme; it adds no text.
   Forced colours would repaint the mask's fill as the page's own background and the mark
   would vanish, so there it opts out and takes the system's text colour itself. */
.lockup-sub::before {
  display: inline-block;
  width: 1.05em;
  height: 0.95em;
  margin-inline-end: 0.35em;
  vertical-align: -0.12em;
  background: currentColor;
  content: "";
  -webkit-mask: url("/assets/app-icons/lantern-mark-mono.svg") center / contain no-repeat;
  mask: url("/assets/app-icons/lantern-mark-mono.svg") center / contain no-repeat;
}
@media (forced-colors: active) {
  .lockup-sub::before { forced-color-adjust: none; background: CanvasText; }
}

/* Horizontal: the mark beside the name (narrow screens, Restore, step-up). */
.lockup-horizontal {
  flex-direction: row;
  gap: 0.85rem;
  text-align: start;
}

.lockup-horizontal .lockup-mark img { width: 3rem; height: 3rem; }
.lockup-horizontal .lockup-name { font-size: clamp(1.6rem, 6vw, 2.1rem); }
.lockup-horizontal .lockup-mark::before { inset: -45%; }

.auth-art {
  display: block;
  width: min(100%, 24rem);
}

.auth-band-art { display: none; }

.art-lantern,
.art-pebble { stroke: none; }
.art-h0 { fill: var(--hue-0); }
.art-h1 { fill: var(--hue-1); }
.art-h2 { fill: var(--hue-2); }
.art-h3 { fill: var(--hue-3); }
.art-h4 { fill: var(--hue-4); }
.art-h5 { fill: var(--hue-5); }
.art-h6 { fill: var(--hue-6); }
.art-h7 { fill: var(--hue-7); }
.art-bubble { fill: var(--surface); stroke: var(--line); stroke-width: 1.5; }
.art-bubble-out { fill: var(--outgoing); }
.art-chit { fill: var(--signature); }
.art-dot { fill: var(--presence); }
.art-lines { fill: none; stroke: var(--text-muted); stroke-width: 6; stroke-linecap: round; opacity: 0.6; }
.art-lines-out { fill: none; stroke: var(--on-outgoing); stroke-width: 6; stroke-linecap: round; opacity: 0.55; }

/* The conversation settles into place once, a group at a time (a signature moment, owner
   decision). Transform and opacity only, no loop; when motion isn't welcome these rules
   don't apply and the drawing is simply there. */
@keyframes art-settle {
  from { opacity: 0; transform: translateY(0.6rem); }
}
@media (prefers-reduced-motion: no-preference) {
  .auth-art .art-step { animation: art-settle var(--motion-slow) var(--ease-out) backwards; }
  .auth-art .art-step-1 { animation-delay: 120ms; }
  .auth-art .art-step-2 { animation-delay: 260ms; }
  .auth-art .art-step-3 { animation-delay: 400ms; }
}

/* Seasonal decoration (sign-in-season.js): static drawings around the
   lockup, behind it, out of the way of the name and the card. */
.auth-season {
  position: absolute;
  z-index: -1;
  inset: 0;
  pointer-events: none;
}

.auth-season[hidden] { display: none; }
.auth-season svg { display: block; width: 100%; height: 100%; overflow: visible; }
.season-flake { fill: none; stroke: var(--text-muted); stroke-width: 1.6; stroke-linecap: round; }
.season-petal { fill: var(--hue-6); }
.season-centre { fill: var(--presence); }
.season-slip-0 { fill: var(--hue-0); }
.season-slip-1 { fill: var(--hue-1); }
.season-slip-2 { fill: var(--hue-3); }
.season-slip-3 { fill: var(--hue-5); }
.season-slip-4 { fill: var(--signature); }

@media (forced-colors: active) {
  .auth-season,
  .lockup-mark::before { display: none; }
}

@media print {
  .auth-season,
  .auth-art,
  .auth-band-art,
  .lockup-mark::before { display: none; }
}

/* ---- The card ---- */

.auth-card {
  width: min(100%, 30rem);
  padding: clamp(1.5rem, 3vw, 2.5rem);
  /* The floating level (L5); the transparent border is what forced colours paint. */
  border: 1px solid transparent;
  border-radius: var(--radius-sheet);
  background: var(--surface);
  box-shadow: var(--elev-2);
}

.auth-greeting {
  margin: 0 0 1.25rem;
  font-family: var(--display-font);
  font-size: var(--type-display-m);
  font-weight: 700;
  line-height: var(--leading-display);
  letter-spacing: var(--title-tracking);
}

/* The second sign-in step (L5): one main button. With an authenticator code on offer the
   code is the main action and the passkey an outline button; without one the passkey
   stays the main action. The guest offer waits until the step is finished or cancelled. */
#mfa-login-panel:has(.totp-entry:not([hidden])) #mfa-login-passkey {
  border: 1px solid var(--field-line);
  background: transparent;
  color: var(--text);
  font-weight: 600;
}
#mfa-login-panel:has(.totp-entry:not([hidden])) #mfa-login-passkey:hover:not(:disabled) {
  border-color: var(--text);
  background: color-mix(in srgb, var(--text) 7%, transparent);
}
.auth-card:has(#mfa-login-panel:not(.hidden)) .guest-entry { display: none; }
#mfa-login-title {
  margin: 0;
  font-family: var(--display-font);
  font-size: var(--type-display-m);
  font-weight: 700;
  line-height: var(--leading-display);
  letter-spacing: var(--title-tracking);
}

/* Reset, recovery key and MFA have their own headings. */
.auth-card[data-mode] > .auth-greeting,
.auth-card:has(#mfa-login-panel:not(.hidden)) > .auth-greeting { display: none; }

.auth-lead {
  margin: -0.5rem 0 1.25rem;
  color: var(--text-muted);
}

/* The server's lockdown message and "signed out" lines: one strip each. */
.auth-strip {
  margin: 0 0 1rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid color-mix(in srgb, var(--unsure-line) 55%, var(--line));
  border-radius: 0.8rem;
  background: color-mix(in srgb, var(--unsure-line) 12%, var(--surface));
  color: var(--text);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

/* Sign in / Register: a segmented control (auth-tabs.js keeps the keys). */
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
  padding: 0.25rem;
  border-radius: var(--radius-pill);
  background: var(--raised);
}

.auth-tabs button {
  min-height: 2.75rem;
  padding: 0.6rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
}

/* The chosen tab is the lit thumb (L5): the surface at the resting elevation, in bold.
   Weight and the thumb's shape carry it, not colour; forced colours add a Highlight
   border (accessibility.css). */
.auth-tabs button { color: var(--text-muted); font-weight: 500; }
.auth-tabs button[aria-selected="true"] {
  background: var(--surface);
  box-shadow: var(--elev-1);
  color: var(--text);
  font-weight: 700;
}

/* 16px fields, so phones don't zoom in on focus. */
.auth-card :is(input:not([type="checkbox"]), textarea, select) {
  min-height: 2.9rem;
  font-size: 1rem;
}

/* Pill buttons; one primary per step. */
.auth-card :is(.primary-button, .secondary-button, .provider-button) {
  min-height: 2.9rem;
  border-radius: 999px;
}

.auth-card .password-toggle { border-radius: 999px; }

/* Restore, "Back to sign in": quiet links, still easy to hit. */
.quiet-action {
  justify-self: center;
  display: inline-block;
  min-height: 1.5rem;
  margin-top: 0.5rem;
  padding: 0.35rem 0.5rem;
  color: var(--text-muted);
  font-size: 0.92rem;
  text-align: center;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.quiet-action:hover { color: var(--text); }
.auth-card > .quiet-action { display: block; width: fit-content; margin-inline: auto; }

.guest-entry .guest-entry-lead { font-weight: 600; }

/* Choosing a new username (#164): the name shown meanwhile. */
.choose-username-current { margin: 0; color: var(--text-muted); overflow-wrap: anywhere; }

/* The rules box's reason, inline instead of the browser's bubble (rules.js). */
.field-error {
  margin: 0.35rem 0 0;
  color: var(--error);
  font-size: 0.9rem;
}

/* Restore and step-up completion: lockup above a single card. */
.auth-shell-single {
  grid-template-rows: 1fr auto auto 1fr;
  gap: 1.25rem;
}

.auth-shell-single > .lockup { grid-row: 2; max-width: min(100%, 30rem); }
.auth-shell-single > .auth-card { grid-row: 3; }
.auth-shell-single > .powered-by { grid-row: 4; align-self: end; }

/* ---- Narrower than a desktop: the intro is a band above the card ---- */

@container auth (max-width: 63.99rem) {
  .auth-layout {
    grid-template-columns: minmax(0, 30rem);
    justify-content: center;
    gap: 1rem;
  }

  .auth-intro { padding: 1rem 0.5rem; gap: 0; }
  .auth-intro .lockup {
    flex-direction: row;
    gap: 0.85rem;
    text-align: start;
  }

  .auth-intro .lockup-mark img { width: 3rem; height: 3rem; }
  .auth-intro .lockup-name { font-size: clamp(1.6rem, 6vw, 2.1rem); }
  .auth-intro .lockup-mark::before { inset: -45%; }
  .auth-art { display: none; }

  .auth-band-art {
    position: absolute;
    z-index: -1;
    inset-block-end: 0.25rem;
    inset-inline-end: 0;
    display: block;
    width: 3.5rem;
  }

  /* A season brings its own drawings to the band. */
  .auth-intro:has(.auth-season:not([hidden])) .auth-band-art { display: none; }
}

@container auth (max-width: 34rem) {
  /* #256: the band's pebbles crowded the edge and pulled the lockup off centre; the glow stays. */
  .auth-band-art { display: none; }
  .auth-shell { gap: 1rem; padding: 1rem; }
  .auth-card { padding: 1.35rem; border-radius: 1.25rem; }
  .auth-greeting { font-size: 1.4rem; }
}

/* Sign in / Register stack only where two labels can't share a row: below 320 (#256; a 360
   phone fits both). */
@container auth (max-width: 19.99rem) {
  .auth-tabs { grid-template-columns: 1fr; border-radius: 1.2rem; }
}

@container auth (max-width: 24rem) {
  /* The lockup scales down so the installation's name fits beside its mark. */
  .auth-intro .lockup { gap: 0.6rem; }
  .auth-intro .lockup-mark img { width: 2.25rem; height: 2.25rem; }
  .auth-intro .lockup-name { font-size: clamp(1.1rem, 9vw, 1.6rem); }
  .auth-shell { padding: 0.75rem 0.5rem; }
  .auth-card { padding: 1rem; }
  /* Fields shrink with the card: a date input's built-in minimum width (about 177px) set
     the whole register form's column, wider than the card at 180 CSS px (#256). */
  .auth-card form > *,
  .auth-card :is(label, input, select, .password-field, .password-field-row) { min-width: 0; max-width: 100%; }
  .auth-card input[type="date"] { width: 100%; }
}

/* #256: a field's hint ("at least 12 characters") on its own line under the label, as the
   birth date's already wraps, instead of running into the label. */
.auth-card label .optional-label { display: block; margin-top: 0.15rem; }

/* #417: "Also on Android" under the card, quiet, and apart from the footer line below it. */
.auth-android-app {
  display: grid;
  justify-items: center;
  gap: 0.25rem;
  max-width: 28rem;
  margin: 0;
  color: var(--text-muted);
  font-size: var(--type-label);
  text-align: center;
}
.auth-android-app[hidden] { display: none; }
.auth-android-app .android-app-lead { font-weight: 600; }
