/* ============================================================================
   KuzmaCraft — вход, регистрация и модальное окно авторизации
   ----------------------------------------------------------------------------
   Файл грузится на всех страницах: js/auth-modal.js вставляет разметку окна
   в <body>. Стили страниц /login и /register используют те же поля и кнопки.

   Зависит от tokens.css, base.css.
   ========================================================================= */

/* ------------------------------------------------------ Модальное окно --- */
.auth-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal, 400);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-4);
    background: rgba(8, 0, 15, .84);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--dur) var(--ease), visibility var(--dur) var(--ease);
}

.auth-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.auth-modal {
    position: relative;
    display: flex;
    flex-direction: column;
    width: min(500px, 100%);
    max-height: calc(100vh - 2 * var(--sp-4));
    overflow: hidden;
    border: 1px solid var(--line-2);
    border-radius: var(--r-xl);
    background:
        radial-gradient(120% 90% at 100% 0%, rgba(136, 1, 134, .22) 0%, transparent 55%),
        linear-gradient(165deg, #220536 0%, #12001F 100%);
    box-shadow: 0 40px 90px -40px rgba(0, 0, 0, .95);
    opacity: 0;
    transform: translateY(16px) scale(.99);
    transition: opacity var(--dur) var(--ease-out), transform var(--dur) var(--ease-out);
}

.auth-modal.active {
    opacity: 1;
    transform: none;
}

/* Верхняя акцентная грань */
.auth-modal::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--grad-vice);
}

.auth-modal-header {
    padding: var(--sp-6) var(--sp-6) var(--sp-3);
    text-align: center;
}

.auth-modal-close {
    position: absolute;
    top: var(--sp-3);
    right: var(--sp-3);
    z-index: 2;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--line-1);
    border-radius: var(--r-sm);
    background: rgba(255, 241, 230, .05);
    color: var(--text-3);
    transition:
        color var(--dur-fast) var(--ease),
        background-color var(--dur-fast) var(--ease),
        border-color var(--dur-fast) var(--ease);
}

.auth-modal-close:hover {
    border-color: var(--line-brand);
    background: var(--brand-a10);
    color: var(--brand-300);
}

.auth-modal-logo {
    display: grid;
    place-items: center;
    width: 54px;
    height: 54px;
    margin: 0 auto var(--sp-4);
    border-radius: 16px;
    background: var(--grad-vice);
    box-shadow: 0 12px 30px -12px rgba(255, 43, 144, .7), inset 0 1px 0 rgba(255, 255, 255, .3);
    color: #fff;
    font-family: var(--font-display);
    font-size: var(--fs-md);
    font-weight: 800;
    letter-spacing: -.04em;
    line-height: 1;
}

.auth-modal-title {
    margin-bottom: var(--sp-1);
    font-family: var(--font-display);
    font-size: var(--fs-xl);
    font-weight: 600;
    color: var(--text-1);
}

.auth-modal-subtitle {
    font-size: var(--fs-sm);
    color: var(--text-3);
}

.auth-modal-content {
    padding: 0 var(--sp-6) var(--sp-6);
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* ------------------------------------------------------ Страница входа --- */
.auth-page {
    position: relative;
    padding-block: clamp(36px, 6vw, 80px) clamp(48px, 7vw, 96px);
    overflow: hidden;
}

.auth-page::before {
    content: '';
    position: absolute;
    top: -30%;
    right: -8%;
    width: min(760px, 90vw);
    height: min(760px, 90vw);
    pointer-events: none;
    background:
        radial-gradient(circle, rgba(255, 43, 144, .18) 0%, rgba(62, 95, 206, .08) 40%, transparent 68%);
}

.auth-shell {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1.02fr) minmax(0, .98fr);
    max-width: 1060px;
    margin-inline: auto;
    border: 1px solid var(--line-2);
    border-radius: var(--r-xl);
    background: rgba(18, 0, 31, .72);
    box-shadow: 0 40px 90px -46px rgba(0, 0, 0, .9);
    overflow: hidden;
    animation: auth-shell-in .55s var(--ease-out) both;
}

.auth-aside {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--sp-4);
    padding: clamp(30px, 4.4vw, 56px);
    background:
        radial-gradient(90% 80% at 0% 0%, rgba(136, 1, 134, .34) 0%, transparent 58%),
        linear-gradient(160deg, #2A0742 0%, #170128 70%, #12001F 100%);
    border-right: 1px solid var(--line-1);
    overflow: hidden;
}

.auth-aside::before {
    content: '';
    position: absolute;
    right: -90px;
    bottom: -110px;
    width: 300px;
    height: 300px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(241, 161, 9, .22), transparent 68%);
    pointer-events: none;
}

.auth-aside > * { position: relative; z-index: 1; }

.auth-aside .kicker { margin-bottom: 0; }

.auth-aside h2 {
    font-size: clamp(1.85rem, 3.1vw, 2.7rem);
    font-weight: 700;
    line-height: 1.02;
    letter-spacing: -.035em;
    color: var(--text-1);
}

.auth-aside h2 em {
    display: block;
    font-family: var(--font-serif);
    font-style: italic;
    font-weight: 500;
    letter-spacing: -.02em;
    background: var(--grad-warm);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.auth-aside__lead {
    max-width: 38ch;
    font-size: var(--fs-sm);
    line-height: 1.7;
    color: var(--text-2);
}

.auth-perks {
    display: grid;
    gap: 12px;
    margin-top: var(--sp-2);
}

.auth-perks li {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: var(--fs-sm);
    color: var(--text-2);
}

.auth-perks i {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border: 1px solid var(--line-brand);
    border-radius: 10px;
    background: var(--brand-a10);
    color: var(--brand-300);
    font-size: 13px;
}

.auth-aside__note {
    margin-top: auto;
    padding-top: var(--sp-4);
    border-top: 1px solid var(--line-1);
    font-size: var(--fs-xs);
    line-height: 1.6;
    color: var(--text-3);
}

.auth-panel {
    padding: clamp(28px, 4vw, 52px);
    background: rgba(18, 0, 31, .7);
}

.auth-panel__head { margin-bottom: var(--sp-5); }

.auth-panel__head .kicker { margin-bottom: var(--sp-3); }

.auth-title {
    margin-bottom: var(--sp-2);
    font-family: var(--font-display);
    font-size: clamp(1.75rem, 3vw, 2.35rem);
    font-weight: 600;
    line-height: 1.04;
    letter-spacing: -.035em;
    color: var(--text-1);
}

.auth-lead {
    max-width: 42ch;
    font-size: var(--fs-sm);
    line-height: 1.65;
    color: var(--text-3);
}

.auth-panel > .alert { margin-bottom: var(--sp-4); }

/* ------------------------------------------------------------ Формы --- */
.auth-form {
    animation: auth-form-in .45s var(--ease-out) both;
}

.auth-form .form-group {
    margin-bottom: var(--sp-4);
}

.auth-form .form-label {
    margin-bottom: 8px;
    font-size: var(--fs-xs);
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-2);
}

.auth-form .form-input {
    min-height: 50px;
    background: rgba(10, 0, 19, .55);
}

.auth-form .form-input:focus {
    background: rgba(18, 0, 31, .9);
}

.auth-form .form-hint {
    margin-top: 6px;
    font-size: var(--fs-xs);
    color: var(--text-3);
}

/* Поле пароля: кнопка «глаз» не сужает input и не перекрывает текст. */
.auth-form .password-field .form-input {
    padding-right: 52px;
}

.auth-form .password-toggle {
    right: 8px;
    width: 36px;
    height: 36px;
}

/* Согласия */
.auth-consents {
    display: grid;
    gap: 4px;
    margin-bottom: var(--sp-5);
    padding: var(--sp-4);
    border: 1px solid var(--line-1);
    border-radius: var(--r-md);
    background: rgba(255, 241, 230, .03);
}

.auth-consents .agreement-check {
    padding: 7px 6px;
}

.auth-consents .agreement-text {
    font-size: var(--fs-xs);
    line-height: 1.6;
}

.auth-submit {
    min-height: 52px;
    margin-top: var(--sp-1);
}

/* Переключатель форм */
.auth-switch {
    margin-top: var(--sp-5);
    padding-top: var(--sp-4);
    border-top: 1px solid var(--line-1);
    text-align: center;
}

.auth-switch p {
    font-size: var(--fs-sm);
    color: var(--text-3);
}

.auth-switch a,
.auth-switch-btn {
    padding: 0;
    background: none;
    color: var(--brand-300);
    font-weight: 600;
}

.auth-switch a:hover,
.auth-switch-btn:hover {
    color: var(--brand-200, var(--brand-300));
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* --------------------------------------------------- Ошибки и валидация --- */
.auth-form .form-input.error {
    border-color: var(--danger);
    background: var(--danger-bg);
}

.auth-form .error-message {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    color: var(--danger);
    font-size: var(--fs-xs);
    animation: auth-shake .4s var(--ease);
}

#formContent > .error-message {
    padding: var(--sp-3) var(--sp-4);
    border: 1px solid rgba(255, 92, 122, .4);
    border-left: 3px solid var(--danger);
    border-radius: var(--r-md);
    background: var(--danger-bg);
    font-size: var(--fs-sm);
}

.auth-form .form-input.success {
    border-color: var(--success);
    background: var(--success-bg);
}

/* Загрузка */
.auth-form .btn-primary.loading {
    position: relative;
    color: transparent;
}

.auth-form .btn-primary.loading::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, .35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: auth-spin .8s linear infinite;
}

/* Успешная авторизация */
.auth-success {
    padding: var(--sp-5) 0;
    text-align: center;
}

.auth-success i {
    margin-bottom: var(--sp-4);
    color: var(--success);
    font-size: 56px;
}

.auth-success h3 {
    margin-bottom: var(--sp-2);
    color: var(--text-1);
}

.auth-success p {
    color: var(--text-2);
}

@keyframes auth-shell-in {
    from { opacity: 0; transform: translateY(18px); }
    to   { opacity: 1; transform: none; }
}

@keyframes auth-form-in {
    from { opacity: 0; transform: translateX(12px); }
    to   { opacity: 1; transform: none; }
}

@keyframes auth-shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-4px); }
    40%, 80% { transform: translateX(4px); }
}

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

/* -------------------------------------------------------------- Адаптив --- */
@media (max-width: 900px) {
    .auth-shell {
        grid-template-columns: 1fr;
        max-width: 620px;
    }

    /* На телефоне форма должна быть видна сразу, а не после промо-блока. */
    .auth-panel { order: 1; }
    .auth-aside { order: 2; }

    .auth-aside {
        border-right: 0;
        border-bottom: 1px solid var(--line-1);
        gap: var(--sp-3);
        padding: clamp(26px, 5vw, 40px);
    }

    .auth-aside h2 { font-size: clamp(1.7rem, 5.6vw, 2.2rem); }

    .auth-perks { grid-template-columns: 1fr; }

    .auth-aside__note { margin-top: var(--sp-2); }
}

@media (max-width: 768px) {
    .auth-modal-header {
        padding: var(--sp-5) var(--sp-5) var(--sp-3);
    }

    .auth-modal-content {
        padding: 0 var(--sp-5) var(--sp-5);
    }
}

@media (max-width: 480px) {
    .auth-modal-overlay { padding: var(--sp-2); }

    .auth-modal-title { font-size: var(--fs-lg); }

    .auth-page { padding-block: var(--sp-5) var(--sp-7); }

    .auth-panel { padding: var(--sp-5); }

    .auth-consents { padding: var(--sp-3); }

    .auth-submit { min-height: 50px; }
}

@media (prefers-reduced-motion: reduce) {
    .auth-form,
    .auth-shell { animation: none; }
}
