:root {
    --bg: #f5f7fa;
    --card: #ffffff;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --text: #1f2937;
    --muted: #6b7280;
    --error: #ef4444;
    --success: #10b981;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --focus: 0 0 0 3px rgb(37 99 235 / 0.3);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f172a;
        --card: #1e293b;
        --text: #f1f5f9;
        --muted: #94a3b8;
    }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.auth-container { width: 100%; max-width: 400px; }
.auth-card {
    background: var(--card);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

.auth-title {
    font-size: clamp(1.25rem, 3vw, 1.5rem);
    margin-bottom: 1.5rem;
    text-align: center;
}

.step { animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--muted);
}

input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: transparent;
    color: inherit;
    font-size: 1rem;
    margin-bottom: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }

.pass-wrapper { position: relative; margin-bottom: 1rem; }
.pass-toggle {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    opacity: 0.6;
    font-size: 1.1rem;
    padding: 4px;
}
.pass-toggle:hover { opacity: 1; }

.btn {
    width: 100%;
    padding: 0.8rem;
    border: none;
    border-radius: 8px;
    background: var(--primary);
    color: white;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}
.btn:hover { background: var(--primary-hover); }
.btn:active { transform: scale(0.98); }

.btn-link {
    background: none; border: none; color: var(--primary);
    cursor: pointer; font-weight: 500; text-decoration: underline;
}

.auth-switch {
    margin-top: 1.5rem; text-align: center; font-size: 0.9rem; color: var(--muted);
}
.hint { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.8rem; text-align: center; }
.success-msg { color: var(--success); text-align: center; font-weight: 500; margin-bottom: 1rem; }

.error {
    background: #fee2e2; color: #b91c1c; padding: 0.75rem; border-radius: 8px;
    font-size: 0.85rem; margin-top: 1rem; text-align: center;
}

.loader {
    width: 24px; height: 24px; border: 3px solid var(--muted);
    border-top-color: var(--primary); border-radius: 50%;
    animation: spin 0.8s linear infinite; margin: 1rem auto 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* === Плавное переключение шагов (убираем мелькание) === */
.step {
    animation: fadeIn 0.2s ease-out;
    transition: opacity 0.15s ease, transform 0.15s ease;
}
.step[hidden] {
    display: none !important;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === Статус проверки логина === */
.username-status {
    font-size: 0.85rem;
    margin-top: -0.5rem;
    margin-bottom: 0.75rem;
    min-height: 1.2em;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.username-status.info { color: var(--muted); }
.username-status.success { color: var(--success); }
.username-status.error { color: var(--error); }

/* === Индикатор сложности пароля === */
.password-strength {
    height: 4px;
    background: #e5e7eb;
    border-radius: 2px;
    margin: 0.5rem 0 1rem;
    overflow: hidden;
}
.password-strength-bar {
    height: 100%;
    width: 0%;
    background: var(--error);
    transition: width 0.2s, background 0.2s;
}
.password-strength-bar.weak { width: 33%; background: var(--error); }
.password-strength-bar.medium { width: 66%; background: #f59e0b; }
.password-strength-bar.strong { width: 100%; background: var(--success); }

.password-rules {
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 0.5rem;
}
.password-rules li {
    margin: 0.2rem 0;
    list-style: none;
    padding-left: 1.2rem;
    position: relative;
}
.password-rules li::before {
    content: '○';
    position: absolute;
    left: 0;
    color: var(--muted);
}
.password-rules li.valid::before {
    content: '✓';
    color: var(--success);
}
@media (max-width: 480px) {
    .auth-card { padding: 1.5rem; }
    input, .btn { font-size: 16px; } /* iOS zoom fix */
}