/* Auth modal: visual hierarchy, responsive sizing and accessible touch targets.
   Layer 1 component styles; brand colours come only from existing design tokens. */

#authModal .authcard {
  box-sizing: border-box;
  width: min(440px, 100%);
  max-height: min(88vh, 780px);
  max-height: min(88dvh, 780px);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  padding: clamp(20px, 4vw, 30px);
  text-align: left;
}

#authModal .auth-head {
  display: flex;
  width: 100%;
  box-sizing: border-box;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 4px 8px 0;
  margin-bottom: 20px;
  text-align: center;
}

#authModal .auth-head h3 {
  margin: 0;
  font-size: clamp(21px, 4.6vw, 25px);
  line-height: 1.2;
  text-align: center;
  text-wrap: balance;
}

#authModal .auth-head .msub {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  margin: 0;
  font-size: 12.5px;
  line-height: 1.4;
  text-align: center;
  text-wrap: pretty;
}

#authModal #regForm,
#authModal #loginForm {
  width: 100%;
  min-width: 0;
  flex-direction: column;
  gap: 12px;
}

#authModal #regForm {
  display: flex;
}

#authModal #loginForm {
  display: none;
}

#authModal .authcard.form label:not(.chk) {
  gap: 7px;
  color: var(--soft);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.35;
  text-transform: none;
}

#authModal .authcard.form input:not([type="checkbox"]),
#authModal .authcard.form select {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  border: var(--modal-input-border, 1.5px solid var(--line));
  border-radius: 13px;
  background: var(--modal-input-bg, #FFFFFF);
  color: var(--modal-input-color, var(--ink));
  padding: 12px 14px;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: normal;
  text-transform: none;
  box-shadow: none;
  transition: border-color .18s ease, box-shadow .18s ease, background-color .18s ease;
}

#authModal .authcard.form input:not([type="checkbox"]):focus,
#authModal .authcard.form select:focus {
  border-color: var(--flame);
  box-shadow: 0 0 0 3px rgba(16, 20, 24, .07);
}

#authModal #regTgBtn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  margin-top: 1px;
  border: 1.5px solid var(--line);
  border-radius: 13px;
  background: var(--panel);
  color: var(--flame);
  padding: 11px 14px;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.35;
  white-space: normal;
  box-shadow: none;
}

#authModal #regTgBtn:hover {
  border-color: var(--flame);
  background: var(--card);
}

#authModal #consentRow {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 2px 0 0;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--soft);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.45;
  text-align: left;
  text-transform: none;
}

#authModal #consentBox {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
  accent-color: var(--flame);
}

#authModal #consentRow a {
  color: var(--flame);
  font-weight: 700;
  text-underline-offset: 2px;
}

#authModal #consentRow:focus-within {
  border-color: var(--flame);
  outline: 3px solid color-mix(in srgb, var(--flame) 28%, transparent);
  outline-offset: 2px;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--flame) 12%, transparent);
}

#authModal #consentBox:focus-visible {
  outline: 3px solid var(--flame);
  outline-offset: 3px;
}

#authModal #regBtn,
#authModal #logBtn {
  width: 100%;
  min-height: 50px;
  margin-top: 2px;
  border-radius: 14px;
  padding: 13px 16px;
  font-size: 14px;
  line-height: 1.3;
}

#authModal .authcard .alt {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 8px;
  margin-top: 2px;
  font-size: 12.5px;
  line-height: 1.45;
}

#authModal .authcard .alt button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 7px 9px;
  border-radius: 9px;
  color: var(--flame);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  text-underline-offset: 3px;
}

#authModal .authcard .alt button:hover {
  background: var(--panel);
  text-decoration: underline;
}


@media (max-width: 560px) {
  .modal#authModal {
    padding: max(8px, env(safe-area-inset-top, 0px)) 10px max(8px, env(safe-area-inset-bottom, 0px));
  }

  #authModal .authcard {
    width: 100%;
    max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    padding: 22px clamp(16px, 5vw, 22px);
    border-radius: var(--modal-radius, 20px);
  }

  #authModal .auth-head {
    padding: 6px 8px 0;
    margin-bottom: 16px;
  }

  #authModal .auth-head .msub {
    font-size: 12px;
  }

  #authModal #regForm,
  #authModal #loginForm {
    gap: 11px;
  }

}

@media (max-height: 560px) {
  .modal#authModal {
    padding: max(8px, env(safe-area-inset-top, 0px)) 10px max(8px, env(safe-area-inset-bottom, 0px));
    align-items: flex-start;
    overflow-y: hidden;
  }

  #authModal .authcard {
    height: auto;
    min-height: min(100%, 0px);
    max-height: calc(100dvh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    margin-block: 0;
    overflow-y: auto;
    scroll-padding-block: 16px;
    overscroll-behavior: contain;
  }

  #authModal .auth-head {
    margin-bottom: 10px;
  }

  #authModal .auth-mode-switch {
    margin-bottom: 10px;
  }

  #authModal #regForm,
  #authModal #loginForm {
    gap: 8px;
  }

  #authModal #regTgBtn,
  #authModal #consentRow {
    min-height: 40px;
    padding-block: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #authModal .authcard,
  #authModal .authcard * {
    scroll-behavior: auto;
    transition-duration: .01ms;
    animation-duration: .01ms;
    animation-iteration-count: 1;
  }
}


/* Auth polish: make the two entry paths explicit and keep status visible. */
#authModal .auth-mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  width: 100%;
  margin: 0 0 16px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}

#authModal .auth-mode-switch button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 42px;
  padding: 9px 12px;
  border-radius: 10px;
  color: var(--soft);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  transition: background-color .18s ease, color .18s ease, box-shadow .18s ease;
}

#authModal .auth-mode-switch [aria-pressed="true"] {
  border: 1px solid var(--flame);
  background: var(--flame);
  color: #FFFFFF;
  box-shadow: 0 2px 6px rgba(16, 20, 24, .16);
}

#authModal .auth-mode-switch [aria-pressed="false"] {
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
}

#authModal .auth-mode-switch [aria-pressed="false"]:hover {
  background: var(--card);
  color: var(--flame);
}

#authModal .auth-mode-switch :focus-visible {
  outline: 3px solid color-mix(in srgb, var(--flame) 30%, transparent);
  outline-offset: 2px;
}

#authModal .auth-help {
  display: block;
  margin: -3px 1px 0;
  color: var(--soft);
  font-size: 11.5px;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: 0;
}

#authModal #logOtpHint {
  margin: -2px 1px 0;
}

#authModal .authcard {
  scroll-padding-block: 24px;
}

#authModal .authcard input:focus {
  scroll-margin-block: 24px;
}

#authModal button[aria-busy="true"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  cursor: progress;
  opacity: .82;
}

#authModal button[aria-busy="true"]::before {
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  content: "";
  border: 2px solid currentColor;
  border-left-color: transparent;
  border-radius: 50%;
  animation: authModalSpin .7s linear infinite;
}

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

@media (max-width: 560px) {
  #authModal .auth-mode-switch {
    margin-bottom: 14px;
  }

  #authModal .auth-mode-switch button {
    min-height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #authModal button[aria-busy="true"]::before {
    animation: none;
  }
}


/* Guest browsing is available from either auth mode, not only from the login form. */
#authModal .auth-guest-action {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

#authModal .auth-guest-action button {
  width: 100%;
  min-height: 44px;
}


/* Desktop scroll containers remain scrollable, but their visual tracks stay hidden. */
@media (hover: hover) and (pointer: fine) {
  #authModal,
  #authModal .authcard {
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  #authModal::-webkit-scrollbar,
  #authModal .authcard::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
  }
}

#authModal #regTgBtn {
  gap: 9px;
}

#authModal .auth-telegram-icon {
  display: block;
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
}

/* Telegram registration feedback: pending, confirmed and timed-out states. */
#authModal #regTgRow.auth-tg-pending,
#authModal #regTgRow.auth-tg-timeout {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
}

#authModal #regTgRow.auth-tg-pending {
  background: var(--panel);
  color: var(--soft);
}

#authModal #regTgRow.auth-tg-timeout {
  border-color: color-mix(in srgb, var(--flame) 30%, var(--line));
  background: var(--panel);
  color: var(--flame);
}


/* Compact phone auth: keep every registration action in view on short screens. */
@media (max-width: 560px) and (max-height: 680px) {
  .modal#authModal {
    padding-top: max(4px, env(safe-area-inset-top, 0px));
    padding-bottom: max(4px, env(safe-area-inset-bottom, 0px));
  }

  #authModal .authcard {
    max-height: calc(100dvh - 8px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    padding-block: 12px;
    padding-inline: 16px;
  }

  #authModal .auth-head {
    gap: 3px;
    padding: 0 8px;
    margin-bottom: 8px;
  }

  #authModal .auth-head h3 {
    font-size: 21px;
  }

  #authModal .auth-head .msub {
    font-size: 11.5px;
  }

  #authModal .auth-mode-switch {
    gap: 3px;
    margin-bottom: 8px;
    padding: 3px;
  }

  #authModal .auth-mode-switch button {
    min-height: 44px;
    padding: 7px 8px;
    font-size: 12px;
  }

  #authModal #regForm,
  #authModal #loginForm {
    gap: 6px;
  }

  #authModal .authcard.form label:not(.chk) {
    gap: 4px;
    font-size: 11px;
  }

  #authModal .authcard.form input:not([type="checkbox"]),
  #authModal .authcard.form select {
    min-height: 44px;
    padding: 8px 10px;
  }

  #authModal #regTgBtn {
    min-height: 44px;
    padding: 8px 10px;
  }

  #authModal #consentRow {
    gap: 8px;
    padding: 8px 10px;
    font-size: 11px;
    line-height: 1.3;
  }

  #authModal #regBtn,
  #authModal #logBtn {
    min-height: 48px;
    margin-top: 0;
    padding: 10px 14px;
  }

  #authModal .auth-help {
    font-size: 10.5px;
    line-height: 1.3;
  }

  #authModal .authcard .alt {
    gap: 2px 6px;
    margin-top: 0;
    line-height: 1.25;
  }

  #authModal .auth-guest-action {
    margin-top: 4px;
    padding-top: 4px;
  }

  #authModal .auth-guest-action button {
    min-height: 44px;
    padding: 6px 8px;
  }
}
