:root {
  --auth-bg: #0b0909;
  --auth-panel: #131012;
  --auth-panel-2: #1b1517;
  --auth-line: rgba(245, 239, 232, 0.12);
  --auth-text: #f5efe8;
  --auth-muted: rgba(245, 239, 232, 0.62);
  --auth-burgundy: #6e1620;
  --auth-burgundy-light: #9c2430;
  --auth-red: #ff3b30;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body.auth-page {
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  background:
    radial-gradient(circle at 50% 32%, rgba(106, 25, 25, 0.22), transparent 48%),
    radial-gradient(circle at 50% 105%, rgba(10, 25, 45, 0.3), transparent 55%),
    var(--auth-bg);
  color: var(--auth-text);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.auth-shell {
  width: 100%;
  max-width: 430px;
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    calc(22px + env(safe-area-inset-top))
    22px
    calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.crest-wrap {
  flex: 0 0 auto;
  width: min(190px, 46vw);
  margin: 0 auto;
  display: grid;
  place-items: center;
  filter: drop-shadow(0 18px 32px rgba(0, 0, 0, 0.55));
}

.crest { display: block; width: 100%; height: auto; overflow: visible; }

.crest-aura {
  transform-origin: 100px 116px;
  animation: crest-pulse 7s ease-in-out infinite;
}

.crest-eye { animation: eye-pulse 7s ease-in-out infinite; }

@keyframes crest-pulse {
  0%, 100% { opacity: 0.22; transform: scale(1); }
  50% { opacity: 0.52; transform: scale(1.05); }
}

@keyframes eye-pulse {
  0%, 100% { opacity: 0.72; }
  50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .crest-aura, .crest-eye { animation: none; }
  .crest-aura { opacity: 0.34; }
  .crest-eye { opacity: 0.95; }
  .auth-btn, .auth-link-button, .password-toggle { transition: none; }
}

.brand { text-align: center; flex: 0 0 auto; }

.brand-title {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(44px, 12vw, 52px);
  font-weight: 600;
  line-height: 1.03;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--auth-text);
  text-shadow: 0 2px 20px rgba(255, 59, 48, 0.18);
}

.brand-tagline {
  margin: 10px 0 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--auth-muted);
}

.brand-subtitle {
  margin: 8px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--auth-muted);
}

.auth-actions {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 2px;
}

.auth-btn,
.auth-link-button {
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--auth-line);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(31, 24, 27, 0.96), rgba(18, 14, 16, 0.96));
  color: var(--auth-text);
  font: 600 15px/1 "Segoe UI", Roboto, Arial, sans-serif;
  letter-spacing: 0.01em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-decoration: none;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease, opacity 140ms ease;
  -webkit-tap-highlight-color: transparent;
}

.auth-btn:hover,
.auth-link-button:hover { border-color: rgba(245, 239, 232, 0.3); }

.auth-btn:active,
.auth-link-button:active { transform: scale(0.98); }

.auth-btn:focus-visible,
.auth-link-button:focus-visible,
.password-toggle:focus-visible,
.auth-footer a:focus-visible,
.auth-inline-link:focus-visible,
.checkbox-row:focus-within {
  outline: 2px solid #e05c52;
  outline-offset: 3px;
}

.auth-btn--primary {
  border-color: rgba(156, 36, 48, 0.75);
  background: linear-gradient(180deg, #8b1d28, #5c1018);
}

.auth-btn--vk { border-color: rgba(110, 150, 210, 0.42); }
.auth-btn--telegram { border-color: rgba(80, 170, 220, 0.4); }
.auth-btn--yandex { border-color: rgba(240, 190, 60, 0.4); }

.auth-btn[disabled],
.auth-link-button[disabled] { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-spinner {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  border: 2px solid rgba(245, 239, 232, 0.3);
  border-top-color: var(--auth-text);
  animation: spin 700ms linear infinite;
}

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

.guest-btn {
  min-height: 42px;
  border-color: transparent;
  background: transparent;
  color: var(--auth-muted);
  font-weight: 500;
  font-size: 13px;
}

.guest-btn:hover { color: var(--auth-text); border-color: transparent; background: rgba(245, 239, 232, 0.04); }

.auth-error {
  min-height: 20px;
  margin: 0;
  color: #ff9c93;
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
}

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

.auth-error button {
  margin-left: 8px;
  border: 0;
  background: none;
  color: var(--auth-text);
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

.auth-footer {
  flex: 0 0 auto;
  padding-top: 6px;
  text-align: center;
  font-size: 13px;
  color: var(--auth-muted);
}

.auth-footer p { margin: 0 0 6px; }

.auth-footer a,
.auth-inline-link {
  color: #e9b8b3;
  text-decoration: none;
  font-weight: 600;
}

.auth-footer-links { display: flex; justify-content: center; gap: 16px; font-size: 12px; }
.auth-footer-links a { color: var(--auth-muted); font-weight: 500; }

.auth-card {
  width: 100%;
  margin-top: auto;
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
  border: 1px solid var(--auth-line);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(24, 19, 21, 0.94), rgba(11, 9, 9, 0.96));
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.auth-card .brand-title { font-size: clamp(32px, 9vw, 40px); }

/* Form screens keep a compact crest so the whole form fits a phone viewport. */
body.auth-page:not([data-page="welcome"]) .crest-wrap {
  width: clamp(80px, 24vw, 112px);
}
body.auth-page:not([data-page="welcome"]) .crest-wrap svg {
  display: block;
}

.auth-form { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

.field { position: relative; }

/* The toggle is positioned against the input only, not the whole field:
   the field also contains the error line, which used to shift the button down. */
.input-wrap { position: relative; }

.field input {
  width: 100%;
  height: 52px;
  padding: 0 46px 0 15px;
  border: 1px solid var(--auth-line);
  border-radius: 14px;
  background: #151113;
  color: var(--auth-text);
  font: 15px/1 "Segoe UI", Roboto, Arial, sans-serif;
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.field input:focus {
  border-color: var(--auth-burgundy-light);
  box-shadow: 0 0 0 3px rgba(156, 36, 48, 0.22);
}

.field input::placeholder { color: rgba(245, 239, 232, 0.36); }
.field input.has-error { border-color: #d9534f; }

.password-toggle {
  position: absolute;
  top: 50%;
  right: 5px;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--auth-muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 140ms ease, background 140ms ease;
}

.password-toggle:hover { color: var(--auth-text); background: rgba(245, 239, 232, 0.06); }

.password-toggle .icon {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.password-toggle .icon-eye-off { display: none; }
.password-toggle[aria-pressed="true"] .icon-eye { display: none; }
.password-toggle[aria-pressed="true"] .icon-eye-off { display: block; }

.field-error {
  display: block;
  min-height: 14px;
  margin: 3px 2px 0;
  color: #ff9c93;
  font-size: 11px;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 4px 2px 2px;
  color: var(--auth-muted);
  font-size: 12px;
  line-height: 1.45;
  border-radius: 8px;
}

/* Native checkboxes render white on Android WebView even with accent-color,
   so draw the control ourselves to keep the dark theme consistent. */
.checkbox-row input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  margin: 1px 0 0;
  display: grid;
  place-items: center;
  border: 1.5px solid rgba(245, 239, 232, 0.5);
  border-radius: 5px;
  background: #151113;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease;
}

.checkbox-row input[type="checkbox"]:checked {
  border-color: #a52734;
  background: #8b1d28;
}

.checkbox-row input[type="checkbox"]:checked::after {
  content: "";
  width: 9px;
  height: 5px;
  margin-top: -2px;
  border-left: 2px solid #fff5f6;
  border-bottom: 2px solid #fff5f6;
  transform: rotate(-45deg);
}

.form-note {
  margin: 4px 0 0;
  color: var(--auth-muted);
  font-size: 12px;
  line-height: 1.45;
  text-align: center;
}

.form-note--ok { color: #9fdfb1; }

.hidden { display: none !important; }

.setup-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 9px;
  margin: 14px 0 4px;
}

.avatar-option {
  aspect-ratio: 1;
  border: 2px solid transparent;
  border-radius: 14px;
  background: #1b1517;
  color: var(--auth-text);
  font-size: 20px;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease;
}

.avatar-option:active { transform: scale(0.98); }
.avatar-option.selected { border-color: #d9534f; box-shadow: 0 0 0 3px rgba(217, 83, 79, 0.18); }

.auth-legal {
  max-width: 620px;
  margin: 0 auto;
  padding: calc(30px + env(safe-area-inset-top)) 22px calc(30px + env(safe-area-inset-bottom));
  line-height: 1.65;
  color: var(--auth-muted);
  font-size: 14px;
}

.auth-legal h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 28px;
  letter-spacing: 0.08em;
  color: var(--auth-text);
  text-transform: uppercase;
}

.auth-legal a { color: #e9b8b3; }

/* Shorter phones: compact the form so the primary action stays reachable.
   Scrolling remains available if the keyboard shrinks the viewport further. */
@media (max-height: 780px) and (orientation: portrait) {
  .auth-shell {
    gap: 12px;
    padding-top: calc(14px + env(safe-area-inset-top));
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }
  .crest-wrap { width: min(120px, 24vw); }
  .brand-tagline { margin-top: 6px; }
  .auth-card {
    margin-top: 12px;
    padding: 14px 14px calc(12px + env(safe-area-inset-bottom));
  }
  .auth-form { gap: 8px; margin-top: 12px; }
  .field input { height: 48px; }
  .field-error { min-height: 12px; margin-top: 2px; }
}

@media (max-height: 620px) {
  body.auth-page { overflow-y: auto; }
  .auth-shell { gap: 10px; }
  .brand-subtitle { margin-top: 4px; }
  .auth-btn, .auth-link-button { min-height: 48px; }
  .guest-btn { min-height: 38px; }
  .auth-card { margin-top: 10px; }
}

@media (orientation: landscape) and (max-height: 620px) {
  body.auth-page { overflow-y: auto; }
  .auth-shell {
    max-width: 900px;
    display: grid;
    grid-template-columns: minmax(180px, 0.85fr) minmax(300px, 1.15fr);
    align-items: center;
    gap: 28px;
  }
  .auth-brand { display: grid; place-items: center; gap: 10px; }
  .crest-wrap { width: clamp(100px, 26vh, 165px); }
  .auth-actions, .auth-card { margin-top: 0; }
  .auth-footer { grid-column: 1 / -1; }
}
