:root {
  --bg: #ffffff;
  --card: #ffffff;

  --text: #3a2a1f;
  --muted: #6b4f3a;

  --border: rgba(0,0,0,.08);

  --accent: #ff8a1f;
  --accentHover: #ff7a00;
  --accentSoft: rgba(255, 138, 31, .14);
  --accentRing: rgba(255, 138, 31, .18);

  --danger: #e25555;
  --success: #2e8b57;

  --r14: 14px;
  --r22: 22px;

  --shadowSoft: 0 10px 26px rgba(0, 0, 0, 0.08);

  --headerBg: rgba(255,255,255,.90);
  --pillBg: rgba(255,255,255,.35);

  --inputBg: #fff;
  --inputBorder: rgba(0,0,0,.14);

  --icon: rgba(107, 79, 58, .75);

  /* LOGO */
  --headerLogo: 136px;

  /* Header vertical breathing space (prevents iOS clipping) */
  --headerPadY: 18px;
}

html[data-theme="dark"] {
  --bg: #0b0c10;
  --card: #14151a;

  --text: rgba(255,255,255,.92);
  --muted: rgba(255,255,255,.68);

  --border: rgba(255,255,255,.10);

  --accentSoft: rgba(255, 138, 31, .18);
  --accentRing: rgba(255, 138, 31, .22);

  --shadowSoft: 0 14px 34px rgba(0, 0, 0, 0.45);

  --headerBg: rgba(16,17,22,.78);
  --pillBg: rgba(255,255,255,.06);

  --inputBg: rgba(255,255,255,.06);
  --inputBorder: rgba(255,255,255,.14);

  --icon: rgba(255,255,255,.74);
}

* { box-sizing: border-box; }

/* =========================
   iOS scroll stability (INDEX)
   Mirrors /app baseline to prevent scroll jitter
========================= */
html, body { height: 100%; }
html { overscroll-behavior: none; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);

  overscroll-behavior: none;
  overflow-x: hidden;

  /* reduces iOS "scroll/paint jitter" with sticky + blur */
  -webkit-overflow-scrolling: touch;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
  white-space: nowrap;
}

/* =========================
   Header (STANDARD)
========================= */

.header {
  position: sticky;
  top: 0;
  z-index: 20;

  background: var(--headerBg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);

  border-bottom: 1px solid var(--border);

  /* allow large centered logo to render fully */
  overflow: visible;

  /* iOS: promote to its own layer to avoid scroll "jumps" */
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  will-change: transform, background; /* Фикс дергания при смене темы */
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition: background 0.3s ease; /* Плавная смена цвета */
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;

  padding:
    calc(var(--headerPadY) + env(safe-area-inset-top, 0px))
    16px
    var(--headerPadY);

  overflow: visible;
}

.header-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;

  overflow: visible;
}

.header-left { justify-self: start; display: flex; align-items: center; min-width: 0; overflow: visible; }
.header-center { justify-self: center; display: flex; align-items: center; overflow: visible; }
.header-right { justify-self: end; display: flex; align-items: center; justify-content: flex-end; gap: 12px; min-width: 0; overflow: visible; }

.brand {
  display: inline-flex;
  align-items: center;
  user-select: none;
  -webkit-tap-highlight-color: transparent;

  /* prevent iOS line-box quirks */
  line-height: 0;

  overflow: visible;
}

.brand--center { gap: 0; }

/* LOGO: no circular mask (prevents ear/bottom clipping), stable sizing */
.logo {
  width: var(--headerLogo);
  height: auto;
  max-height: var(--headerLogo);
  object-fit: contain;
  display: block;

  /* IMPORTANT: remove circle clipping */
  border-radius: 0;

  /* extra safety */
  max-width: none;

  /* Фикс дергания: плавный transition для смены темы/языка */
  transition: transform 0.3s ease, opacity 0.3s ease;
  will-change: transform;
}

/* Bounce только при ховере, медленнее для заметности */
.logo:hover {
  animation: bounce 0.8s ease-in-out;
}

/* ===== Compact language menu (flag trigger + dropdown) ===== */

.langMenu {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--pillBg);
  padding: 0;
}

.langMenu > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 999px;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.langMenu > summary::-webkit-details-marker { display: none; }

.langMenu[open] > summary {
  background: var(--accentSoft);
}

.langFlag {
  font-size: 22px;
  line-height: 1;
  font-family: "Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji","Twemoji Mozilla",sans-serif;
}
.langFlag.has-flag {
  font-size: 0; /* hide emoji fallback like "RU" on Windows */
  width: 24px;
  height: 18px;
  display: inline-block;
  border-radius: 4px;
  background-image: var(--flag-url, none);
  background-size: cover;
  background-position: center;
  box-shadow: 0 0 0 1px rgba(0,0,0,.08);
}
html[data-theme="dark"] .langFlag.has-flag {
  box-shadow: 0 0 0 1px rgba(255,255,255,.12);
}

.langChevron {
  width: 18px;
  height: 18px;
  opacity: .75;
}

.langMenu:focus-within > summary {
  outline: none;
  box-shadow: 0 0 0 4px var(--accentRing);
}

.langDropdown {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  min-width: 190px;

  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--shadowSoft);
  padding: 8px;
  z-index: 50;
}

.langMenu:not([open]) .langDropdown { display: none; }

.langOption {
  width: 100%;
  border: 0;
  background: transparent;
  cursor: pointer;

  display: flex;
  align-items: center;
  gap: 10px;

  padding: 10px 10px;
  border-radius: 12px;

  color: var(--text);
  font-weight: 900;
  text-align: left;

  -webkit-tap-highlight-color: transparent;
  transition: background .12s ease, transform .08s ease;
}

.langOption:active { transform: translateY(1px); }

.langOption:hover { background: rgba(0,0,0,.03); }
html[data-theme="dark"] .langOption:hover { background: rgba(255,255,255,.06); }

.langOption.active { background: var(--accentSoft); }

.langOptionFlag {
  width: 22px;
  text-align: center;
  font-family: "Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji","Twemoji Mozilla",sans-serif;
}
.langOptionFlag.has-flag {
  font-size: 0; /* hide emoji fallback like "EN" on Windows */
  width: 22px;
  height: 16px;
  display: inline-block;
  border-radius: 4px;
  background-image: var(--flag-url, none);
  background-size: cover;
  background-position: center;
  box-shadow: 0 0 0 1px rgba(0,0,0,.08);
  flex: 0 0 auto;
}
html[data-theme="dark"] .langOptionFlag.has-flag {
  box-shadow: 0 0 0 1px rgba(255,255,255,.12);
}

/* Theme toggle button (only dark <-> light) */
.theme-btn {
  width: 52px;
  height: 48px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--pillBg);
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  -webkit-tap-highlight-color: transparent;
  transition: transform .08s ease, background .12s ease, color .12s ease;
}

.theme-btn:hover { background: var(--accentSoft); color: var(--text); }
.theme-btn:active { transform: translateY(1px); }

.theme-btn .icon { width: 26px; height: 26px; display: none; }

html[data-theme="dark"] .theme-btn .icon-sun { display: block; }
html[data-theme="dark"] .theme-btn .icon-moon { display: none; }
html[data-theme="light"] .theme-btn .icon-moon { display: block; }
html[data-theme="light"] .theme-btn .icon-sun { display: none; }

/* =========================
   Auth Layout
========================= */

.auth {
  padding: 56px 18px;

  /* iOS: give bottom safe-area breathing to avoid weird "snap" on scroll */
  padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));

  /* helps stabilize layout with dynamic viewport bars */
  min-height: 100svh;
}

@supports (height: 100dvh) {
  .auth { min-height: 100dvh; }
}

.auth-container {
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 56px;
  align-items: center;
}

.auth-fox { display: flex; justify-content: center; }
.auth-fox-mascot {
  position: relative;
  width: min(320px, 100%);
  transform-origin: 50% 85%;
  animation: foxBreathing 4.2s ease-in-out infinite;
  will-change: transform;
}

.auth-fox-main,
.auth-fox-blink {
  width: 100%;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.auth-fox-main {
  position: relative;
  z-index: 1;
  height: auto;
}

.auth-fox-blink {
  position: absolute;
  inset: 0;
  z-index: 2;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  will-change: opacity;
}

.auth-fox-mascot.blinking .auth-fox-main {
  opacity: 0;
}

.auth-fox-mascot.blinking .auth-fox-blink {
  opacity: 1;
  visibility: visible;
}

.auth-form {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r22);
  box-shadow: var(--shadowSoft);
  padding: 22px;

  /* Медленный fade-in для формы, чтобы был заметен */
  animation: fadeIn 1.5s ease-in forwards;
}

.auth-form h1 {
  margin: 0 0 8px;
  font-size: 34px;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 16px;
  font-weight: 650;
  line-height: 1.35;
}

form { display: flex; flex-direction: column; gap: 14px; }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 800;
}

input {
  padding: 13px 14px;
  border-radius: var(--r14);
  border: 1px solid var(--inputBorder);
  background: var(--inputBg);
  color: var(--text);
  font-size: 15px;
  transition: box-shadow .12s ease, border-color .12s ease, transform .08s ease;
}

input:focus {
  outline: none;
  border-color: rgba(255, 138, 31, .55);
  box-shadow: 0 0 0 4px var(--accentRing);
}

input.state-valid { border-color: var(--success); }
input.state-valid:focus { border-color: var(--success); box-shadow: 0 0 0 4px rgba(46, 139, 87, .14); }

input.state-invalid { border-color: var(--danger); }
input.state-invalid:focus { border-color: var(--danger); box-shadow: 0 0 0 4px rgba(226, 85, 85, .14); }

button.primary {
  margin-top: 8px;
  padding: 14px;
  border: 0;
  border-radius: var(--r14);
  background: var(--accent);
  color: #ffffff;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 12px 22px rgba(255, 138, 31, .33);
  transition: transform .08s ease, box-shadow .12s ease, background .12s ease;
}

button.primary:hover { background: var(--accentHover); }

button.primary:active {
  transform: translateY(1px);
  box-shadow: 0 10px 18px rgba(255, 138, 31, .28);
}

.secondary { margin-top: 18px; }

.link-button {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  font-weight: 800;
  -webkit-tap-highlight-color: transparent;
}

.link-button:hover { opacity: 0.90; }
.link-button:active { transform: translateY(1px); }

.hidden { display: none; }

.password-wrapper { 
  position: relative;
  width: 100%;
}

/* Fix: поле пароля на полную ширину */
.password-wrapper input {
  width: 100%;
  padding-right: 48px; /* место для иконки глаза */
}

.password-hints {
  margin-top: 8px;
  font-size: 13px;
  color: rgba(0,0,0,.45);
  font-weight: 650;
  line-height: 1.35;
}

html[data-theme="dark"] .password-hints { color: rgba(255,255,255,.50); }

.password-hints div.valid { color: var(--success); font-weight: 800; }

.toggle-password {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--icon);
  -webkit-tap-highlight-color: transparent;
  transition: color .12s ease, transform .08s ease;
}

.toggle-password:hover { color: var(--accent); }
.toggle-password:active { transform: translateY(calc(-50% + 1px)); }

.toggle-password svg { width: 22px; height: 22px; }
.eye-open { display: none; }
.toggle-password.active .eye-open { display: block; }
.toggle-password.active .eye-closed { display: none; }

/* ===== Стили для интерактивных правил пароля (ИНТЕГРИРОВАНО) ===== */
.password-rules {
  margin-top: 0.75rem;
  padding: 1rem;
  background: var(--inputBg);
  border-radius: 0.5rem;
  border: 1px solid var(--inputBorder);
}

.password-rules-title {
  margin: 0 0 0.5rem 0;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--muted);
}

.password-rules-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.password-rules-list li {
  font-size: 0.875rem;
  padding: 0.25rem 0;
  padding-left: 1.75rem;
  position: relative;
  transition: all 0.3s ease;
  color: var(--muted);
}

.password-rules-list li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 1rem;
  height: 1rem;
  background-size: contain;
  background-repeat: no-repeat;
  transition: all 0.3s ease;
}

.password-rules-list li.invalid {
  color: var(--muted);
}

.password-rules-list li.invalid::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='10' stroke='currentColor' stroke-width='2' fill='none' opacity='0.6'/%3E%3C/svg%3E");
}

.password-rules-list li.valid {
  color: var(--success);
  font-weight: 500;
}

.password-rules-list li.valid::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z'/%3E%3C/svg%3E");
}

/* Адаптация для темной темы */
html[data-theme="dark"] .password-rules-list li.invalid::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='10' stroke='rgba(255,255,255,0.5)' stroke-width='2' fill='none'/%3E%3C/svg%3E");
}

@media (max-width: 900px) {
  .auth { padding: 36px 14px; padding-bottom: calc(36px + env(safe-area-inset-bottom, 0px)); }

  .auth-container {
    grid-template-columns: 1fr;
    gap: 22px;
    text-align: center;
  }

  .auth-form { padding: 18px; }
  .auth-fox-mascot { max-width: 220px; }

  .header-inner {
    padding:
      calc(var(--headerPadY) + env(safe-area-inset-top, 0px))
      12px
      var(--headerPadY);
  }

  :root { --headerLogo: 124px; }

  .theme-btn { width: 50px; height: 46px; }
}

@media (max-width: 380px) {
  :root { --headerLogo: 116px; }
}

/* ========================================
   АНИМАЦИИ - Красивые эффекты для всех страниц
======================================== */

/* Fade In - появление элементов */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Slide In From Left */
@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-30px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Slide In From Right */
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Scale In - появление с увеличением */
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

/* Bounce - прыгающий эффект */
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

/* Pulse - пульсация */
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* Shake - встряхивание (для ошибок) */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px); }
  75% { transform: translateX(10px); }
}

/* Rotate - вращение */
@keyframes rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Gradient Shift - плавная смена градиента */
@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* Glow - эффект свечения */
@keyframes glow {
  0%, 100% { box-shadow: 0 0 5px var(--accent), 0 0 10px var(--accent); }
  50% { box-shadow: 0 0 20px var(--accent), 0 0 30px var(--accent); }
}

/* Float - плавающий эффект */
@keyframes foxBreathing {
  0%, 100% { transform: scale(1); }
  50% { transform: scaleX(0.996) scaleY(1.013); }
}

@keyframes foxBlink {
  0%, 42.8%, 45.2%, 66.8%, 69.2%, 88.8%, 91.2%, 100% { opacity: 0; }
  43%, 45%, 67%, 69%, 89%, 91% { opacity: 1; }
}

/* Применение анимаций к элементам */
.auth-form {
  animation: fadeIn 0.6s ease-out forwards;
}

input:focus {
  animation: pulse 0.3s ease-in-out;
}

button.primary:hover {
  animation: pulse 0.5s ease-in-out infinite;
}

.password-rules {
  animation: slideInLeft 0.3s ease-out;
}

.password-rules-list li.valid {
  animation: scaleIn 0.3s ease-out;
}

.auth-error {
  animation: shake 0.5s ease-out, fadeIn 0.3s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .auth-form,
  .auth-fox-mascot,
  .auth-fox-main,
  .auth-fox-blink,
  input:focus,
  button.primary:hover,
  .password-rules,
  .password-rules-list li.valid,
  .auth-error,
  .toast {
    animation: none !important;
    transition: none !important;
  }
}

/* ===== Toast notifications (улучшенный вид) ===== */
.toast-container {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 18px);
  right: 18px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
}

.toast {
  min-width: 280px;
  max-width: 380px;
  padding: 14px 18px;
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadowSoft);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.4;
  pointer-events: auto;
  animation: toastSlideIn 0.3s ease;
}

.toast.success {
  border-left: 4px solid var(--success);
}

.toast.error {
  border-left: 4px solid var(--danger);
}

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ===== Error message под формой ===== */
.auth-error {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--r14);
  background: rgba(226, 85, 85, 0.1);
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: 14px;
  font-weight: 650;
  text-align: center;
  animation: fadeIn 0.3s ease;
}

html[data-theme="dark"] .auth-error {
  background: rgba(226, 85, 85, 0.15);
}

/* ===== Loading state для кнопок ===== */
button.primary:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

button.primary.loading {
  position: relative;
  color: transparent;
}

button.primary.loading::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  top: 50%;
  left: 50%;
  margin-left: -10px;
  margin-top: -10px;
  border: 2px solid transparent;
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (hover: none) and (pointer: coarse) {
  .logo:hover,
  .langOption:hover,
  .theme-btn:hover,
  .link-button:hover,
  .toggle-password:hover {
    animation: none !important;
    transform: none !important;
  }

  button.primary:hover {
    animation: none !important;
    background: var(--accent);
  }
}
