/* Public auth pages (login + signup) — single centered composition.
   Theme selectors may only change colors, borders, shadows, and decorative assets. */

html:has(body.auth-page) {
  min-height: 100%;
  background: #0a0d1c;
}

html:has(body.auth-page[data-theme="light"]),
html:has(body.auth-page.ff-theme-light) {
  background: #f3efff;
}

.auth-page,
.auth-page *,
.auth-page *::before,
.auth-page *::after {
  box-sizing: border-box;
}

.auth-page {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  color: var(--ff-text);
  background-color: #0a0d1c;
  background-image:
    radial-gradient(920px 480px at 18% 12%, rgba(124, 58, 237, 0.28), transparent 58%),
    radial-gradient(760px 420px at 82% 18%, rgba(88, 28, 180, 0.18), transparent 55%),
    linear-gradient(160deg, #0b1024 0%, #12153a 42%, #0a0d1c 100%);
  overflow-x: hidden;
  padding:
    calc(clamp(28px, 8vh, 72px) + env(safe-area-inset-top, 0px))
    16px
    calc(24px + env(safe-area-inset-bottom, 0px));
}

/* Decorative background layers — out of flow */
.auth-page::before,
.auth-page::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-repeat: no-repeat;
  background-size: cover;
}

.auth-page::before {
  background-image: url("/static/fanfic/images/hero/hero-nebula-dark.png");
  background-position: 30% 40%;
  opacity: 0.5;
}

.auth-page::after {
  background-image: url("/static/fanfic/images/hero/hero-stars-dark.png");
  background-position: center;
  opacity: 0.495;
}

/* Shared auth column: topbar + card share one width */
.auth-wrapper {
  position: relative;
  z-index: 1;
  width: min(100% - 32px, 420px);
  display: grid;
  gap: 14px;
  margin: 0 auto;
}

.auth-topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
}

.auth-topbar .ff-shell-brand {
  display: inline-flex;
  align-items: center;
  line-height: 0;
  padding: 0;
}

.auth-topbar .ff-shell-brand .ff-shell-logo-dark,
.auth-topbar .ff-shell-brand .ff-shell-logo-light {
  width: 156px;
  height: auto;
}

.auth-topbar .ff-shell-brand .ff-shell-logo-dark {
  display: block;
}

.auth-topbar .ff-shell-brand .ff-shell-logo-light {
  display: none;
}

body[data-theme="light"] .auth-topbar .ff-shell-brand .ff-shell-logo-dark,
.ff-theme-light .auth-topbar .ff-shell-brand .ff-shell-logo-dark {
  display: none;
}

body[data-theme="light"] .auth-topbar .ff-shell-brand .ff-shell-logo-light,
.ff-theme-light .auth-topbar .ff-shell-brand .ff-shell-logo-light {
  display: block;
}

.auth-controls {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.auth-topbar .ff-shell-language-popover {
  z-index: var(--ff-z-popover);
}

.auth-card {
  position: relative;
  z-index: 1;
  width: 100%;
  display: grid;
  gap: 14px;
  padding: 28px 26px 22px;
  border: 1px solid rgba(167, 139, 250, 0.28);
  border-radius: var(--ff-radius-xl);
  background: linear-gradient(180deg, rgba(17, 21, 40, 0.92), rgba(10, 14, 30, 0.96));
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(14px);
}

.auth-card-header h1 {
  margin: 0;
  color: #f3f0ff;
  font: 500 1.7rem / 1.2 var(--ff-font-serif);
}

.auth-card-header p {
  margin: 8px 0 4px;
  color: #9aa0b8;
  font: 400 0.95rem / 1.45 var(--ff-font-sans);
}

.auth-field > span:first-child {
  color: #c9cee6;
  font: 600 0.82rem / 1.2 var(--ff-font-sans);
}

.auth-input-wrap {
  position: relative;
  display: block;
}

.auth-input-wrap .ff-control {
  min-height: 46px;
  padding-left: 42px;
  padding-right: 44px;
  border-radius: var(--ff-radius-md);
  border-width: 1px;
  border-style: solid;
}

.auth-input-icon,
.auth-error-icon,
.auth-eye {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  pointer-events: none;
}

.auth-field:not(.is-invalid) .auth-error-icon {
  display: none;
}

.auth-input-icon {
  left: 14px;
  color: #8b91ab;
}

.auth-input-icon svg,
.auth-error-icon svg,
.auth-eye svg,
.auth-error-mark svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.auth-eye {
  right: 12px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  color: #a5acc6;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
}

.auth-eye:hover,
.auth-eye:focus-visible {
  color: #ddd6fe;
  background: rgba(124, 58, 237, 0.12);
  outline: 0;
}

.auth-eye-hide {
  display: none;
}

.auth-eye.is-visible .auth-eye-show {
  display: none;
}

.auth-eye.is-visible .auth-eye-hide {
  display: block;
}

.auth-error-icon {
  right: 14px;
  color: #ff4f63;
}

.auth-field.is-invalid .auth-input-wrap .ff-control {
  padding-right: 72px;
  border-color: rgba(244, 140, 148, 0.72);
  background: rgba(88, 28, 40, 0.18);
  box-shadow: none;
}

.auth-field.is-invalid .auth-eye {
  right: 38px;
}

.auth-field.is-invalid .auth-error-icon-password {
  right: 12px;
}

.auth-forgot-row {
  display: flex;
  justify-content: flex-end;
  margin-top: -5px;
  margin-bottom: -3px;
}

.auth-forgot {
  color: #c4b5fd;
  font: 500 0.84rem / 1.2 var(--ff-font-sans);
  text-decoration: none;
}

.auth-forgot:hover,
.auth-forgot:focus-visible {
  color: #ddd6fe;
  text-decoration: underline;
  outline: 0;
}

.auth-page p.auth-error {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 12px;
  border: 1px solid rgba(244, 140, 148, 0.42);
  border-radius: var(--ff-radius-md);
  background: rgba(127, 39, 55, 0.22);
  color: #ff4f63;
  font: 500 0.88rem / 1.45 var(--ff-font-sans);
}

.auth-forgot-row + .auth-error {
  margin-top: 5px;
}

.auth-page .auth-error > span {
  margin: 0;
  color: inherit;
  line-height: inherit;
}

.auth-page .auth-error-mark {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin: 0;
  color: #ff4f63;
  line-height: 0;
}

.auth-error-mark svg {
  display: block;
  width: 18px;
  height: 18px;
  stroke: currentColor;
}

.auth-submit,
.auth-google {
  width: 100%;
  min-height: 46px;
  justify-content: center;
}

/* Signup only: breathe before primary CTA after Confirm password.
   Grid gap (14px) + margin ≈ 18–20px, matching submit → divider spacing. */
#signup-form > .auth-submit {
  margin-top: 6px;
}

.auth-divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  margin: 2px 0;
  color: #8b91ab;
  font: 500 0.78rem / 1 var(--ff-font-sans);
  text-transform: lowercase;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  height: 1px;
  background: rgba(148, 163, 184, 0.22);
}

.auth-google {
  gap: 10px;
  text-decoration: none;
}

.auth-google-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
}

.auth-switch {
  margin: 4px 0 0;
  text-align: center;
  color: #9aa0b8;
  font: 400 0.9rem / 1.4 var(--ff-font-sans);
}

.auth-switch a {
  color: #d8b4fe;
  font-weight: 600;
  text-decoration: none;
}

.auth-switch a:hover,
.auth-switch a:focus-visible {
  color: #efe6ff;
  text-decoration: underline;
  outline: 0;
}

.auth-disclosure {
  margin: 0;
  text-align: center;
  color: #7d849c;
  font-size: 0.75rem;
  line-height: 1.45;
}

.auth-disclosure a {
  color: #b7a0f0;
}

/* Theme tokens only */
body[data-theme="light"].auth-page,
.ff-theme-light.auth-page {
  background-color: #f3efff;
  background-image:
    radial-gradient(820px 420px at 18% 8%, rgba(196, 181, 253, 0.35), transparent 58%),
    radial-gradient(700px 380px at 88% 12%, rgba(253, 186, 116, 0.16), transparent 52%),
    linear-gradient(165deg, #faf8ff 0%, #f3efff 52%, #efe9ff 100%);
  color: #17152b;
}

body[data-theme="light"].auth-page::before,
.ff-theme-light.auth-page::before {
  background-image: url("/static/fanfic/images/hero/hero-nebula-light.png");
  background-position: center right;
  opacity: 0.42;
}

body[data-theme="light"].auth-page::after,
.ff-theme-light.auth-page::after {
  background-image: url("/static/fanfic/images/hero/hero-stars-light.png");
  opacity: 0.405;
}

body[data-theme="light"] .auth-card,
.ff-theme-light .auth-card {
  border-color: #ddd6fe;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 24px 60px rgba(43, 29, 81, 0.12);
}

body[data-theme="light"] .auth-card-header h1,
.ff-theme-light .auth-card-header h1 {
  color: #17152b;
}

body[data-theme="light"] .auth-card-header p,
.ff-theme-light .auth-card-header p {
  color: #68718a;
}

body[data-theme="light"] .auth-field > span:first-child,
.ff-theme-light .auth-field > span:first-child {
  color: #3f4568;
}

body[data-theme="light"] .auth-input-icon,
.ff-theme-light .auth-input-icon {
  color: #8b91ab;
}

body[data-theme="light"] .auth-eye,
.ff-theme-light .auth-eye {
  color: #6b728e;
}

body[data-theme="light"] .auth-eye:hover,
body[data-theme="light"] .auth-eye:focus-visible,
.ff-theme-light .auth-eye:hover,
.ff-theme-light .auth-eye:focus-visible {
  color: #5b21b6;
  background: #f5f1ff;
}

body[data-theme="light"] .auth-field.is-invalid .auth-input-wrap .ff-control,
.ff-theme-light .auth-field.is-invalid .auth-input-wrap .ff-control {
  border-color: #f87171;
  background: #fff5f5;
  box-shadow: none;
}

body[data-theme="light"] .auth-error-icon,
.ff-theme-light .auth-error-icon {
  color: #dc2626;
}

body[data-theme="light"] p.auth-error,
.ff-theme-light p.auth-error {
  border-color: #fecaca;
  background: #fff1f2;
  color: #dc2626;
}

body[data-theme="light"] .auth-error-mark,
.ff-theme-light .auth-error-mark {
  color: #e11d48;
}

body[data-theme="light"] .auth-forgot,
.ff-theme-light .auth-forgot {
  color: #6d28d9;
}

body[data-theme="light"] .auth-forgot:hover,
body[data-theme="light"] .auth-forgot:focus-visible,
.ff-theme-light .auth-forgot:hover,
.ff-theme-light .auth-forgot:focus-visible {
  color: #5b21b6;
}

body[data-theme="light"] .auth-divider,
.ff-theme-light .auth-divider {
  color: #8d94aa;
}

body[data-theme="light"] .auth-divider::before,
body[data-theme="light"] .auth-divider::after,
.ff-theme-light .auth-divider::before,
.ff-theme-light .auth-divider::after {
  background: #e2e4f2;
}

body[data-theme="light"] .auth-switch,
.ff-theme-light .auth-switch {
  color: #656b8e;
}

body[data-theme="light"] .auth-switch a,
.ff-theme-light .auth-switch a {
  color: #6d28d9;
}

body[data-theme="light"] .auth-disclosure,
.ff-theme-light .auth-disclosure {
  color: #8d94aa;
}

body[data-theme="light"] .auth-disclosure a,
.ff-theme-light .auth-disclosure a {
  color: #6d28d9;
}

/* Soften stars near card — visual only */
@media (min-width: 761px) {
  .auth-page::after {
    -webkit-mask-image: radial-gradient(ellipse 52% 56% at 50% 46%, transparent 0%, rgba(0, 0, 0, 0.4) 46%, #000 78%);
    mask-image: radial-gradient(ellipse 52% 56% at 50% 46%, transparent 0%, rgba(0, 0, 0, 0.4) 46%, #000 78%);
  }
}

/* Compact mobile polish — same composition, denser card */
@media (max-width: 760px) {
  .auth-page {
    padding:
      calc(12px + env(safe-area-inset-top, 0px))
      12px
      calc(16px + env(safe-area-inset-bottom, 0px));
  }

  .auth-wrapper {
    width: calc(100% - 24px);
    gap: 12px;
  }

  .auth-topbar {
    min-height: 44px;
    gap: 10px;
  }

  .auth-topbar .ff-shell-brand .ff-shell-logo-dark,
  .auth-topbar .ff-shell-brand .ff-shell-logo-light {
    width: 132px;
  }

  .auth-controls {
    gap: 8px;
  }

  .auth-topbar .ff-shell-language-menu {
    display: block;
  }

  .auth-topbar .ff-shell-language-menu .ff-shell-language {
    display: inline-flex;
    width: 40px;
    min-height: 40px;
    padding: 0;
  }

  .auth-topbar .ff-shell-language-menu .ff-shell-language span,
  .auth-topbar .ff-shell-language-menu .ff-shell-language .ff-shell-chevron {
    display: none;
  }

  .auth-topbar .ff-shell-theme {
    width: 40px;
    min-height: 40px;
  }

  .auth-card {
    gap: 10px;
    padding: 20px 18px 16px;
  }

  .auth-card-header h1 {
    font-size: 1.75rem;
    line-height: 1.15;
  }

  .auth-card-header p {
    margin: 4px 0 0;
    font-size: 0.875rem;
    line-height: 1.4;
  }

  .auth-field.ff-field {
    gap: 5px;
  }

  .auth-input-wrap .ff-control {
    min-height: 44px;
  }

  .auth-forgot-row {
    margin-top: -1px;
    margin-bottom: 2px;
  }

  .auth-forgot {
    font-size: 0.8rem;
  }

  .auth-page p.auth-error {
    margin: 0;
    padding: 10px;
    font-size: 0.82rem;
    line-height: 1.45;
  }

  .auth-forgot-row + .auth-error {
    margin-top: 5px;
  }

  .auth-submit,
  .auth-google {
    min-height: 44px;
  }

  /* Keep Confirm password → CTA in the same 16–20px band when card gap tightens */
  #signup-form > .auth-submit {
    margin-top: 8px;
  }

  .auth-divider {
    margin: 0;
    gap: 10px;
  }

  .auth-switch {
    margin: 0;
    font-size: 0.84rem;
    line-height: 1.35;
  }

  .auth-disclosure,
  .auth-disclosure.ff-helper {
    margin: 0;
    font-size: 0.72rem;
    line-height: 1.4;
  }
}

@media (max-width: 480px) {
  .auth-wrapper {
    width: calc(100% - 24px);
    gap: 10px;
  }

  .auth-topbar .ff-shell-brand .ff-shell-logo-dark,
  .auth-topbar .ff-shell-brand .ff-shell-logo-light {
    width: 128px;
  }

  .auth-card {
    gap: 9px;
    padding: 18px 16px 14px;
  }

  .auth-card-header h1 {
    font-size: 1.7rem;
  }

  .auth-card-header p {
    font-size: 0.84rem;
    line-height: 1.35;
  }
}
